using CarMeterSystem.OptionCls;
using com.hnshituo.core.webapp.vo;
using Common;
using MeterConditionLibrary;
using MeterPlugInLibrary;
using MeterSceneLibrary;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Threading;
using System.Windows.Forms;

namespace CarMeterSystem
{
    public partial class frmOneYardToEnd : Form
    {
        public frmOneYardToEnd()
        {
            InitializeComponent();
        }
        private MeterWorkCarActualFirst firstDb = null;//一次计量数据
        private SceneControl inner = new SceneControl(); //非内倒业务处理
        private Print printClass = new Print();//打印
        private VoicePlay vicPlayClass = new VoicePlay();//语音播放
        private Log lg = Log.GetInstance(); //写日志

        private MeterBaseCarService carService = new MeterBaseCarService(); //复磅操作
        private MeterWorkCarRecoverService carRecoverService = new MeterWorkCarRecoverService(); //复磅操作
        private MeterBaseTermTareDataService termTareDate = new MeterBaseTermTareDataService();//留期限皮操作
        private MeterWorkMonitorService monitor = new MeterWorkMonitorService(); //设备及远程呼叫监控表
        private MeterWorkCarActualFirstService workCarActualFirstService = new MeterWorkCarActualFirstService(); //一次计量数据
        private PreTrackScaleService trackService = new PreTrackScaleService();//查询预报信息
        private MeterBaseMatterInfoService matterInfoService = new MeterBaseMatterInfoService(); //物料信息
        private PreTrackScaleService PreTrackScaleService = new PreTrackScaleService(); 

        private validTermTareCar termTareCar = new validTermTareCar();//验证是否可留期限皮
        private validRecoverInfo recoverInfo = new validRecoverInfo();//验证是否需要复磅以及是否满足复磅条件
        private validPrediction validPred = new validPrediction(); //验证预报信息
        private validUnloadAutomatic unloadAutomatic = new validUnloadAutomatic(); //自动卸货
        private validDataValidity dataValidity = new validDataValidity(); //验证采集的重量是否正常
        private validMatterName validMatterName = new validMatterName(); //物资名称验证与类型类型的关系验证
        private validDoorPost validDoorPost = new validDoorPost(); //验证门岗进厂的数据：返回空则说明已有进厂记录，允许计量
        private validUnitName validUnitName = new validUnitName();//九钢收发货名称的验证 
        private JGLimsInterface limsInterface = new JGLimsInterface(); //九钢检化验提示处理
        private validShipWeight vShipWeight = new validShipWeight(); //本次的提单量+历史已经运输的总量，若大于提单总量，则不允许继续计量了
        private double firstWgt = 0;
        private bool bRailwayActual = true;
        private bool isVoiceDownCar = false;//车上人员请下车播放一次
        private string firstCode = "";//上次扫码编号
        private string TrackCarNo = "";//预报车号
        private string sPreCarNo = "";//摄像头识别车号
        private string limsMsg = "";

        private LED_Control led_controler;

        //lianDaWgt

        //=========== 2021-11-25 eason add ====================
        LianDaMeter lianda = new LianDaMeter();
        int lianDaWgt = Convert.ToInt32(ConfigurationManager.AppSettings["lianDaWgt"]?.ToString() ?? "0");
        string lianDaPointNo = ConfigurationManager.AppSettings["lianDaPointNo"]?.ToString() ?? "00019";
        /// <summary>
        /// 是否是联达物料 0否1是
        /// </summary>
        PbModelDb lianDaQuery = null;
        //=====================================================

        private void frmOneYardToEnd_Load(object sender, EventArgs e)
        {
            try
            {
                if (!string.IsNullOrEmpty(PbCache.sportInfo.ledIp))
                {
                    led_controler = new LED_Control(PbCache.sportInfo.ledIp);
                }

                //不显示重量
                ucWeightCarTJXJG1.setWgtBackColor(true);
                if (PbCache.isTest)
                {
                    btnFH.Enabled = true;
                    btnFH.Visible = true;
                }
                btnTare.Visible = false;
                timer1.Start();
                lbPointName.Text = PbCache.sportInfo.baseSpotName;
                ucCarMeterInfoJisco1.setMeterType(PbCache.bussinessTypeName);
                tableLayoutPanelPromptMsg.CellBorderStyle = (TableLayoutPanelCellBorderStyle)BorderStyle.FixedSingle;
            }
            catch (Exception ex)
            {
                lg.WriteLog(13, PbCache.lockCarNo + "frmCarSalePurchase_Load事件异常：" + ex.Message);
            }
        }


        /// <summary>
        /// 数据保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                    if (PbCache.collect == null) return;
                PbCache.isLockFrm = true;
                PbCache.lockCarNo = PbCache.collect.carno;
                PbCache.lockWgt = PbCache.collect.weight;
                btnSave.Enabled = false;
                lg.WriteLog(15, PbCache.lockCarNo + "点击保存按钮");
                PreTrackScale preTrack = ucCarMeterInfoJisco1._preTrack;
                string strMsg = "";

                #region 红外对射及量程验证
                valid.ValidMethod();
                if (PbCache.range != null && PbCache.range.upperRange < PbCache.collect.weight)
                {
                    //超量程
                    vicPlayClass.GetVoicePlay("已超量程", PbCache.collect.carno);
                    PbCache.ResultMessage = "当前重量已超量程，秤体量程为【" + PbCache.range.upperRange / 1000 + "】T，不允许进行自助计量操作！";
                    PbCache.isLockFrm = false;
                    btnSave.Enabled = true;
                    setMsg(PbCache.ResultMessage);
                    return;
                }
                else if (PbCache.collect.weightStatus == 0 && !PbCache.monitorResult.valid_park_status)
                {
                    //重量稳定，且对射验证不合格
                    vicPlayClass.GetVoicePlay("您的车辆未停到位", PbCache.collect.carno);
                    PbCache.ResultMessage = "您的车辆未停到位，请调整车辆位置，不要遮挡激光检测设备，不允许进行自助计量操作！"; //btnSave_Click
                    PbCache.isLockFrm = false;
                    btnSave.Enabled = true;
                    setMsg(PbCache.ResultMessage);
                    return;
                }
                #endregion 红外对射及量程验证

                //仪表重量验证
                if (!dataValidity.ValidMethod(PbCache.lockWgt)) {
                    PbCache.isLockFrm = false;
                    btnSave.Enabled = true;
                    setMsg(PbCache.ResultMessage);
                    return;
                }
 
                //物资名称验证与类型类型的关系验证；业务类型验证
                if (!validMatterName.ValidMethod(preTrack))
                {
                    PbCache.isLockFrm = false;
                    btnSave.Enabled = true;
                    setMsg(PbCache.ResultMessage);
                    return;
                }

                //九钢收发货名称与计量点区域的验证 
                if (!validUnitName.ValidMethod(preTrack))
                {
                    PbCache.isLockFrm = false;
                    btnSave.Enabled = true;
                    setMsg(PbCache.ResultMessage);
                    return;
                }

                //2021年6月22日 存在需要复磅的数据，不允许进行保存操作
                recoverInfo.ValidAllowSave(PbCache.lockCarNo);
                if (PbCache.isAllowRecover)
                {
                    PbCache.isLockFrm = false;
                    btnSave.Enabled = true;
                    setMsg(PbCache.ResultMessage);
                    return;
                }

                //存在零点禁止计量
                if (PbCache.isZeroAlarm)
                {
                    PbCache.isLockFrm = false;
                    btnSave.Enabled = true;
                    setMsg("秤体存在零点，禁止进行计量操作！请点[语音求助]，联系司秤工处理！");
                    return;
                }

                //本次的提单量+历史已经运输的总量，若大于提单总量，则不允许继续计量了
                //BourneCao暂时屏蔽
                //if (!vShipWeight.ValidMethod(preTrack))
                //{
                //    PbCache.isLockFrm = false;
                //    btnSave.Enabled = true;
                //    setMsg(PbCache.ResultMessage);
                //    return;
                //}

                txtMsgInfo.Text = "称重保存中......";
                //FrmMessage frmMessage = FrmMess("是否确认保存当前计量数据！", "继续保存");


                try
                {
                    //是否在黑名单内
                    MeterBaseCarBlacelistService bService = new MeterBaseCarBlacelistService();
                    RESTfulResult<List<MeterBaseCarBlacelist>> rmB = bService.doQueryWf(new MeterBaseCarBlacelist { carNo = PbCache.lockCarNo, valueFlag = "0" });
                    if (rmB.Succeed)
                    {
                        if (rmB.Data != null && rmB.Data.Count > 0)
                        {
                            PbCache.ResultMessage = string.Format("车辆[{0}在黑名单内，不能计量", PbCache.lockCarNo);
                            lg.WriteLog(3, string.Format("车辆[{0}在黑名单内，不能计量", PbCache.lockCarNo));

                            PbCache.isLockFrm = false;
                            btnSave.Enabled = true;
                            setMsg(PbCache.ResultMessage);
                            return;
                        }
                    }
                    else
                    {
                        PbCache.ResultMessage = "保存失败，获取黑名单数据异常，请稍后再试";
                        lg.WriteLog(3, "获取黑名单数据异常，请稍后再试");

                        PbCache.isLockFrm = false;
                        btnSave.Enabled = true;
                        setMsg(PbCache.ResultMessage);
                        return;
                    }

                    //验证门岗进厂的数据：返回空则说明已有进厂记录，允许计量
                    // BourneCao暂时注释
                    //if (!validDoorPost.ValidMethod(preTrack))
                    //{
                    //    PbCache.isLockFrm = false;
                    //    btnSave.Enabled = true;
                    //    setMsg(PbCache.ResultMessage);
                    //    return;
                    //}

                    // BourneCao暂时注释
                    // 附加重量
                    //PbCache.addWgt = preTrack.addWeightSum == null ? 0 : preTrack.addWeightSum.Value;
                    bool flag = false;

                    //说明：不管是成功还是失败，都在180行有提示信息
                    //if (inner.WeightMeter(preTrack, null, out strMsg))  //meterTypeNo  "001006001","001006002"
                    //{
                    //    flag = true;
                    //    ucWeightCarTJXJG1.setWgtBackColor(true);//称重完成后，显示颜色；

                    //    //票据打印
                    //    //Print1(PbCache.actualFirstNo);  

                    //    //九钢检化验处理
                    //    limsInterface.imsCarLims(preTrack);


                    //    //若不是测试，保存完成后则不能返回，若是测试界面进入的则可点击返回按钮
                    //    if (PbCache.isTest)
                    //    {
                    //        btnFH.Enabled = true;
                    //        btnFH.Visible = true;
                    //    }
                    //}
                    //else
                    //{
                    //    PbCache.isLockFrm = false;
                    //    btnSave.Enabled = true;
                    //}

                    #region 酒钢业务流程判断
                    // 把车号加上-
                    string tempCarNo = PbCache.lockCarNo;
                    RESTfulResult<List<MeterBaseCar>> resCarList = carService.doQueryCarList(new MeterBaseCar { carNo = tempCarNo });
                    RESTfulResult<rtInfo> strRm = new RESTfulResult<rtInfo>();
                    if (resCarList.Succeed)
                    {
                        if (resCarList.Data != null && resCarList.Data.Count == 1)
                        {
                            MeterBaseCar car = resCarList.Data[0];

                            ExecuteMethod em = new ExecuteMethod();


                            // 厂内车辆
                            if (car.carTypeNo == "001004003")
                            {
                                try
                                {
                                    btnSave.Enabled = false;
                                    strRm = em.GetAndExecuteMethod<rtInfo>("MeterSceneLibrary", "InnerCarJISCO", "MeterMethod", new object[] { new PreTrackScale { } });
                                    setMsg(strRm.ResultMessage);
                                    if (!string.IsNullOrEmpty(PbCache.LEDResultMessage))
                                    {
                                        led_controler.setOneLineMsg(PbCache.sportInfo.ledIp, PbCache.LEDResultMessage);
                                    }
                                }
                                catch (Exception exp)
                                {
                                    PbCache.ResultMessage = "获取计量场景信息失败，请点击语音求助";
                                    //这里是未找到方法的情况
                                    lg.WriteLog(3, "获取场景失败！" + strRm.ResultMessage);
                                    setMsg(PbCache.ResultMessage);
                                    if (!string.IsNullOrEmpty(PbCache.LEDResultMessage))
                                    {
                                        led_controler.setOneLineMsg(PbCache.sportInfo.ledIp, PbCache.LEDResultMessage);
                                    }
                                    //break;
                                    return;
                                }
                            }
                            // 厂外车辆
                            else if (car.carTypeNo == "001004002")
                            {
                                try
                                {
                                    btnSave.Enabled = false;
                                    strRm = em.GetAndExecuteMethod<rtInfo>("MeterSceneLibrary", "OuterCarJISCO", "MeterMethod", new object[] { new PreTrackScale { } });
                                    setMsg(strRm.ResultMessage);
                                    if (!string.IsNullOrEmpty(PbCache.LEDResultMessage))
                                    {
                                        led_controler.setOneLineMsg(PbCache.sportInfo.ledIp, PbCache.LEDResultMessage);
                                    }
                                }
                                catch (Exception exp)
                                {
                                    PbCache.ResultMessage = "获取计量场景信息失败，请点击语音求助";
                                    //这里是未找到方法的情况
                                    lg.WriteLog(3, "获取场景失败！" + strRm.ResultMessage);
                                    setMsg(PbCache.ResultMessage);
                                    if (!string.IsNullOrEmpty(PbCache.LEDResultMessage))
                                    {
                                        led_controler.setOneLineMsg(PbCache.sportInfo.ledIp, PbCache.LEDResultMessage);
                                    }
                                    //break;
                                    return;
                                }
                            }

                            if (strRm.Succeed)
                            {
                                if (strRm.Data.isError)
                                {
                                    //如果是报错则直接不执行，并写入信息到界面，同时调用语音播报
                                    vicPlayClass.GetVoicePlay("计量数据保存失败", PbCache.collect.carno);
                                    PbCache.ResultMessage = strRm.Data.resultInfo;
                                    PbCache.monitorResultMessage = strRm.Data.resultInfo;
                                    PbCache.isLockFrm = false;
                                    btnSave.Enabled = true;
                                    setMsg(PbCache.ResultMessage);
                                    Monitor(strRm.Data);
                                    if (!string.IsNullOrEmpty(PbCache.LEDResultMessage))
                                    {
                                        led_controler.setOneLineMsg(PbCache.sportInfo.ledIp, PbCache.LEDResultMessage);
                                    }
                                    return;
                                }

                                if (strRm.Data.result) //说明：标识当前跑了一个场景成功了；场景完成后则返回，不再进行下一个场景的执行操作；
                                {
                                    PbCache.ResultMessage = strRm.Data.resultInfo; //语音提示文件
                                    setMsg(PbCache.ResultMessage);
                                    Monitor(strRm.Data);
                                    if (!string.IsNullOrEmpty(PbCache.LEDResultMessage))
                                    {
                                        led_controler.setOneLineMsg(PbCache.sportInfo.ledIp, PbCache.LEDResultMessage);
                                    }
                                    //return;
                                }
                                else
                                {
                                    //说明：不满足场景的的要求，不能进行return，继续下一个场景，若所有的场景都失败，则提示“未找到计量场景配置信息” 
                                    //ResultMessage = strRm.Data.resultInfo;
                                    //return strRm.Data.result;  //2021-3-18 杨秀东注释；要处理一车联运（多场景）的数据；问题：提示信息会出现问题
                                }
                            }
                            else
                            {
                                vicPlayClass.GetVoicePlay("计量数据保存失败", PbCache.collect.carno);
                                PbCache.ResultMessage = strRm.ResultMessage;
                                PbCache.isLockFrm = false;
                                btnSave.Enabled = true;
                                setMsg(PbCache.ResultMessage);

                                // todo:更新监控表，此秤点求助状态为求助中
                                if (PbCache.monitor.isHelp == "0")
                                {
                                    RESTfulResult<string> rms = monitor.doUpdateWf(new MeterWorkMonitor { pointNo = PbCache.sportInfo.baseSpotNo, isHelp = "1" });
                                    if (!rms.Succeed)
                                    {
                                        lg.WriteLog(3, PbCache.lockCarNo + "求助写入失败");
                                    }
                                }
                                Monitor(strRm.Data);
                                if (!string.IsNullOrEmpty(PbCache.LEDResultMessage))
                                {
                                    led_controler.setOneLineMsg(PbCache.sportInfo.ledIp, PbCache.LEDResultMessage);
                                }
                                return;

                            }
                        }
                        else
                        {
                            if (string.IsNullOrEmpty(tempCarNo))
                            {
                                PbCache.ResultMessage += "车号为空，请联系处理";
                                PbCache.monitorResultMessage = "车号为空，请联系处理";
                            }
                            else
                            {
                                PbCache.ResultMessage += "车号未注册，请联系处理";
                                PbCache.monitorResultMessage = "车号未注册，请联系处理";
                            }
                            PbCache.isLockFrm = false;
                            btnSave.Enabled = true;
                            
                            setMsg(PbCache.ResultMessage);
                            rtInfo rt = new rtInfo();
                            rt.isWarn = true;
                            rt.WarnContent = "carErr";
                            Monitor(rt);
                            if (!string.IsNullOrEmpty(PbCache.LEDResultMessage))
                            {
                                led_controler.setOneLineMsg(PbCache.sportInfo.ledIp, PbCache.LEDResultMessage);
                            }
                            if (!string.IsNullOrEmpty(tempCarNo))
                            {
                                carService.addCar(new MeterBaseCar { carNo = tempCarNo });
                            }
                            return;
                        }
                    }
                    #endregion

                    #region 期限皮显示及保存

                    //留期限皮提醒
                    string sql = @"select base_spot_no   baseSpotNo,
                                       base_spot_name baseSpotName,
                                       warn_time      warnTime,
                                       end_time    endTime,
                                       car_no         carNo
                                  from Meter_Base_Term_Tare_Data
                                  where car_no='" + PbCache.lockCarNo + "' and value_flag='0' order by METER_TIME desc ";
                    PbModelDbService<List<MeterBaseTermTareData>> pbModelDbService = new PbModelDbService<List<MeterBaseTermTareData>>();
                    RESTfulResult<List<MeterBaseTermTareData>> rES = pbModelDbService.executeSqlDataWf(sql);

                    if (rES.Succeed)
                    {
                        if (rES.Data != null && rES.Data.Count > 0)
                        {
                            if (DateTime.Now.CompareTo(rES.Data[0].endTime) >= 0)
                            {
                                PbCache.ResultMessage += "\n\r提醒：期限皮重已过期，请及时留期限皮";
                            }
                            else if (DateTime.Now.CompareTo(rES.Data[0].warnTime) >= 0)
                            {
                                PbCache.ResultMessage += "\n\r提醒：期限皮重将要过期，请及时留期限皮";
                            }
                        }
                    }

                    //语音提醒部分
                    //flag =true表示称重成功
                    if (flag && PbCache.ResultMessage.Contains("请及时留期限皮"))
                    {
                        vicPlayClass.GetVoicePlay("称重完成空车留期限皮", PbCache.lockCarNo);
                    }
                    else
                    {
                        vicPlayClass.GetVoicePlay(strMsg, PbCache.lockCarNo);
                    }

                    //提示信息，
                    //txtMsgInfo.Text = PbCache.ResultMessage;
                    lblog = string.IsNullOrEmpty(PbCache.ResultMessage) ? strMsg : PbCache.ResultMessage;//偶尔出现ResultMessage为空的情况
                    PbCache.ResultMessage = lblog;
                    //queryWeightinfo(preTrack.predictionNo);
                    DoShowlbLog(PbCache.ResultMessage);

                    //期限皮按钮显示
                    if (flag && !btnTare.Visible)
                    {
                        try
                        {
                            //2021年3月15日 杨秀东 期限皮重显示按钮的显示方法修改 isShowBtnTare   ValidMethod
                            if (!string.IsNullOrEmpty(TrackCarNo) && termTareCar.isShowBtnTare(TrackCarNo))
                            {
                                btnTare.Visible = true;
                            }
                        }
                        catch (Exception ex)
                        {
                            lg.WriteLog(13, PbCache.lockCarNo + "期限皮重按钮显示事件异常：" + ex.Message);
                        }
                    }
                    //
                    #endregion 期限皮显示及保存


                    #region LED写入
                    PbCache.ledInfo = string.Format("计量完成，车号：{0}，车重：{1}，物资：{2}", PbCache.lockCarNo, PbCache.lockWgt, preTrack != null ? preTrack.matterName : "");
                    #endregion LED写入

                    //计量完成后，显示毛重或者皮重


                    _ = BeginInvoke(new Action(() =>
                    {
                        if (!PbCache.isActual && !PbCache.isInnerCar)
                        {
                            if (PbCache.isTareWeight)
                                ucWeightCarTJXJG1.setWeightType("皮重");
                            else
                                ucWeightCarTJXJG1.setWeightType("毛重");
                        }
                        
                    }));

                    //图片截取
                    // BourneCao暂时注释
                    _ = BeginInvoke(new Action(() => { shotImage(); }));

                }
                catch (Exception ex)
                {
                    //语音播报
                    vicPlayClass.GetVoicePlay("称重数据保存失败", PbCache.lockCarNo);
                    //提示信息，
                    //txtMsgInfo.Text = "称重数据保存失败";
                    lblog = "称重数据保存失败！" + ex.Message;
                    DoShowlbLog(lblog);
                    lg.WriteLog(3, PbCache.lockCarNo + "称重保存失败：" + ex.Message);
                    PbCache.isLockFrm = false;
                    btnSave.Enabled = true;
                }
            }
            catch (Exception ex)
            {
                lg.WriteLog(13, PbCache.lockCarNo + "保存事件异常：" + ex.Message);
            }
        }

        /// <summary>
        ///  查询重量信息，显示在界面上面
        /// </summary>
        /// <param name="strPredition"></param>
        public void queryWeightinfo(string strPredition)
        {
            try
            {
                string sqls = @"select '毛重：' || t.gross_weight / 1000 || ' T / 皮重：' || t.tare_weight / 1000 || ' T / 净重：' || t.net_weight / 1000 || ' T ' as txt as txt  
                    from meter_work_car_actual t where t.value_flag = '0' and T.Prediction_No = '" + strPredition + @"'";

                PbModelDbService<string> pbp = new PbModelDbService<string>();
                RESTfulResult<string> rmT = pbp.executeSqlDataWf(sqls);
                if (rmT.Succeed && rmT.Data != null && rmT.Data.Length>10)
                {
                    
                }
            }
            catch (Exception ex)
            {
                lg.WriteLog(3, PbCache.lockCarNo + "计量完成，但重量信息提示失败：" + PbCache.actualFirstNo + ex.Message); ;
            }
        }

        /// <summary>
        /// 终端截图
        /// </summary>
        public void shotImage() {
            try
            {
                #region 截取图片信息

                //截取屏幕信息

                Point screenPoint = this.PointToScreen(new Point());
                Rectangle rect = new Rectangle(screenPoint, this.Size);
                Image img = new Bitmap(rect.Width, rect.Height);
                Graphics g = Graphics.FromImage(img);
                g.CopyFromScreen(rect.X - 1, rect.Y - 1, 0, 0, rect.Size);//"D://file/1.jpg"
                img.Save(string.Format("{0}imgShort\\formalImg\\{1}_{2}_{3}.jpg",
                    AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
                    PbCache.sportInfo.baseSpotNo, "C" + PbCache.actualFirstNo, 7), System.Drawing.Imaging.ImageFormat.Jpeg);
                //(PbCache.videoChild.Count + 1)), System.Drawing.Imaging.ImageFormat.Jpeg);

                //*
                //最后进行截图操作
                CameraShotCls cameraShot = new CameraShotCls();
                cameraShot.CapMethod(PbCache.actualFirstNo);
                //*/

                #endregion 截取图片信息
            }
            catch (Exception ex)
            {
                lg.WriteLog(3, "计量完成，但图片截取失败，编号：" + PbCache.actualFirstNo);
            }
        }
        private void btnHelp_Click(object sender, EventArgs e)
        {
            if (PbCache.monitor.isHelp == "0")
            {
                RESTfulResult<string> rms = monitor.doUpdateWf(new MeterWorkMonitor { pointNo = PbCache.sportInfo.baseSpotNo, isHelp = "1" });
                if (!rms.Succeed)
                {
                    lg.WriteLog(3, PbCache.lockCarNo + "求助写入失败");
                }
            }
            lg.WriteLog(15, PbCache.lockCarNo + "点击了语音求助按钮");
        }

        private bool isOverSound = false;

        private bool isCalibration = true;
        private bool bRelation = true;
        private bool isShowRecover = true; //是否需要判断显示复磅按钮

        //验证校秤数据
        private validCalibration vCalib = new validCalibration();
        
        //验证对射
        private validParkStatus valid = new validParkStatus();
        //是否已经播放不验证对射语音
        bool isPlayCalibVoice = false;
        
        //是否已经播放停留超时语音
        bool isPlayOvertimeVoice = false;

        //是否已经播放超量程语音
        bool isPlayRangeVoice = false;

        private validCarno vCarNo = new validCarno();

        private bool bXCStart = false;

        private void timer1_Tick(object sender, EventArgs e)
        {
            

            try
            {
                
                    if (PbCache.collect.weight < 500)
                    {
                        //不显示重量
                        ucWeightCarTJXJG1.setWgtBackColor(false);
                        isCalibration = true;
                        PbCache.addWgt = 0;
                        this.Close();
                    }

                    #region 0.接受远程修改过后的车号并显示
                    //if (PbCache.monitor != null && !string.IsNullOrEmpty(PbCache.monitor.editCar))
                    //{
                    //    PbCache.lockCarNo = PbCache.monitor.editCar;
                    //}
                    #endregion

                    #region 1、求助按钮控制
                    if (PbCache.monitor != null && !string.IsNullOrEmpty(PbCache.monitor.isHelp))
                    {
                        switch (PbCache.monitor.isHelp)
                        {
                            case "0": //未呼叫
                                {
                                    if (btnHelp.Text != "语音求助")
                                    {
                                        btnHelp.BackColor = Color.DodgerBlue;
                                        btnHelp.Text = "语音求助";
                                    }
                                }; break;
                            case "1": //呼叫待接听
                                {
                                    if (btnHelp.Text != "呼叫中")
                                    {
                                        btnHelp.BackColor = Color.Red;
                                        btnHelp.Text = "呼叫中";
                                    }
                                }; break;
                            case "2": //呼叫已接听
                                {
                                    if (btnHelp.Text != "已接听")
                                    {
                                        btnHelp.BackColor = Color.Green;
                                        btnHelp.Text = "已接听";
                                    }
                                }; break;
                        }
                    }
                    #endregion 1、求助按钮控制

                    #region 界面未锁定的情况下，初始设置值<车号、监控界面交互、设置初始的毛皮类型>
                    if (!PbCache.isLockFrm)
                    {
                        //ucWeightT1.setWgt(PbCache.collect.weight);
                        //周俊伶注释
                        //ucWeightT1.setWgt(Math.Round((double)PbCache.collect.weight / 1000, 2)); //2021年5月10日界面显示单位，调整为T
                        //ucWeightT1.setStable(PbCache.collect.weightStatus != 1 ? true : false);
                        //ucWeightT1.setExceed(PbCache.collect.weight > PbCache.range.upperRange ? false : true);

                        //2021年5月10日界面显示单位，调整为T
                        ucWeightCarTJXJG1.setWgt(Math.Round((double)PbCache.collect.weight / 1000, 2));
                        // 修改界面过磅状态红/绿图标
                        ucWeightCarTJXJG1.setStable(PbCache.collect.weightStatus != 1 ? true : false);

                        #region 远程计量交互代码

                        //如果处于远程计量状态，且远程保存完成了，则提示保存完成，让司机知道
                        if (PbCache.monitor != null)// && PbCache.collect.weight > 500)
                        {
                            if (!string.IsNullOrEmpty(PbCache.monitor.isOverWgt) && PbCache.monitor.isTakeOver == "2" && !isOverSound) //&& !PbCache.isLockFrm)
                            {
                                ucWeightCarTJXJG1.setWgtBackColor(true);//称重完成后，显示颜色；
                                txtMsgInfo.Text = "称重完成";
                                vicPlayClass.GetVoicePlay("称重完成", PbCache.collect.carno);
                                isOverSound = true;
                                Print1(PbCache.monitor.isOverWgt);
                                return;
                            }

                            if (PbCache.monitor.isTakeOver == "2" || !string.IsNullOrEmpty(PbCache.monitor.isOverWgt))
                            {
                                btnSave.Visible = false;
                                bRelation = true;
                                lg.WriteLog(14, "车号：" + PbCache.collect.carno + "；远程计量完成后，保存按钮隐藏！");
                                if (!txtMsgInfo.Text.Contains("称重完成") && PbCache.monitor.isTakeOver == "2")
                                {
                                    txtMsgInfo.Text = "司秤工正在远程计量，请等待处理！！";
                                }
                                if (!txtMsgInfo.Text.Contains("称重完成") && !string.IsNullOrEmpty(PbCache.monitor.isOverWgt))
                                {
                                    txtMsgInfo.Text = "本次计量称重已经完成，车辆请下秤！！";
                                }
                                return;
                            }
                        }

                        #endregion 远程计量交互代码

                        if (string.IsNullOrEmpty(TrackCarNo))
                        {
                            txtCarNo.Text = PbCache.collect.carno;
                        }
                        else
                        {
                            txtCarNo.Text = TrackCarNo;

                            if (PbCache.collect != null && !string.IsNullOrEmpty(PbCache.collect.carno))
                            {
                                if (TrackCarNo != PbCache.collect.carno)
                                {
                                    if (PbCache.monitor.carErr != "1") //写入一次车号异常
                                    {
                                        RESTfulResult<string> rms = monitor.doUpdateWf(new MeterWorkMonitor { pointNo = PbCache.sportInfo.baseSpotNo, carErr = "1" });
                                    }
                                }
                                else if (PbCache.monitor.carErr == "1") //若车号相等，但是之前写了一次车号异常，此时要改为车号正常
                                {
                                    RESTfulResult<string> rms = monitor.doUpdateWf(new MeterWorkMonitor { pointNo = PbCache.sportInfo.baseSpotNo, carErr = "0" });
                                }
                            }

                            // ??BourneCao 酒钢不可能预报车号和识别车号不一致
                            vCarNo.ValidMethod(new PreTrackScale { carNo = TrackCarNo });

                            if (TrackCarNo != PbCache.collect.carno && !PbCache.monitorResult.valid_carno)
                            {
                                // 2021年5月11日 未识别到车牌号，进行提示，避免出现重新扫码点保存的情况
                                if (string.IsNullOrEmpty(PbCache.collect.carno))
                                {
                                    txtMsgInfo.Text = string.Format("摄像头未识别到车牌号，不允许进行【保存】操作，请点击语音求助！");
                                    lg.WriteLog(14, "摄像头未识别到车牌号，不允许进行【保存】操作，请点击语音求助！");
                                }
                                else
                                {
                                    txtMsgInfo.Text = string.Format("预报车号【{0}】与摄像头识别车号【{1}】不一致，请点击语音求助", TrackCarNo, PbCache.collect.carno);
                                    lg.WriteLog(14, "车号：" + PbCache.collect.carno + "；预报车号" + TrackCarNo + "与摄像头识别车号" + PbCache.collect.carno + "不一致！");
                                }
                                btnSave.Visible = false;
                                return;
                            }
                            else
                            {
                                if (txtMsgInfo.Text.Contains("摄像头"))
                                {
                                    txtMsgInfo.Text = ""; //将原来的不允许计量的提示给去掉
                                }
                                PbCache.collect.carno = TrackCarNo;

                            }
                        }
                    }

                    #endregion 界面未锁定的情况下，初始设置值<车号、监控界面交互、设置初始的毛皮类型>

                    #region 红外对射及量程验证及停留超时验证
                    valid.ValidMethod();
                    if (PbCache.range != null && PbCache.range.upperRange < PbCache.collect.weight)
                    {
                        //超量程
                        if (!isPlayRangeVoice)
                        {
                            vicPlayClass.GetVoicePlay("已超量程", PbCache.collect.carno);
                            txtMsgInfo.Text = "当前重量已超量程，秤体量程为【" + PbCache.range.upperRange / 1000 + "】T，不允许进行自助计量操作！";
                            isPlayRangeVoice = true;
                        }
                    }
                    if (PbCache.collect.weightStatus == 0 && !PbCache.monitorResult.valid_park_status)
                    {
                        //重量稳定，且对射验证不合格
                        if (!isPlayCalibVoice)
                        {
                            vicPlayClass.GetVoicePlay("您的车辆未停到位", PbCache.collect.carno);
                            txtMsgInfo.Text = "您的车辆未停到位，请调整车辆位置，不要遮挡激光检测设备，不允许进行自助计量操作！";//timer1_Tick
                            isPlayCalibVoice = true;
                        }
                    }
                    if (PbCache.isOvertimeAlarm)
                    {
                        //停留超时提醒，不作为计量卡控的条件
                        if (!isPlayOvertimeVoice && !PbCache.isLockFrm)
                        {
                            vicPlayClass.GetVoicePlay("停留超时", PbCache.collect.carno);
                            //txtMsgInfo.Text = "您的车辆已停留超过三分钟，遇到操作问题请点击【语音求助】联系司秤工处理或继续进行自助计量！";
                            isPlayOvertimeVoice = true;
                            return;
                        }
                    }

                #region 模拟APP
                if (!string.IsNullOrEmpty(PbCache.collect.carno))
                {
                    string sqls = "UPDATE METER_BASE_APP_TEST SET CAR_NO= '"+ PbCache.collect.carno + "' where ID = 1";

                    PbModelDbService<List<PbModelDb>> pbp = new PbModelDbService<List<PbModelDb>>();
                    RESTfulResult<List<PbModelDb>> rmT = pbp.executeSqlDataWf(sqls);
                }
                #endregion

                #endregion 红外对射及量程验证及停留超时验证


                #region 查一次是否校秤，若未校秤则不能计量

                //*
                if (bRelation)
                    {
                        string msgInfo = "";
                        isCalibration = vCalib.ValidMethod(new MeterWorkCalibrationMain { baseSpotNo = PbCache.sportInfo.baseSpotNo, valueFlag = "2" }, out msgInfo);
                        bRelation = false;
                    }

                    if (!isCalibration)
                    {
                        MeterBaseCalibraNumRel calibraNumRel = PbCache.ltBaseCalibraNumRel.Where(s => s.baseSpotNo == PbCache.sportInfo.baseSpotNo).FirstOrDefault();
                        if (calibraNumRel == null || calibraNumRel.isMeter == "否" || PbCache.collect.weight > (calibraNumRel.upWeight == null ? 0 : calibraNumRel.upWeight.Value))
                        {
                            if (!bXCStart)
                            {
                                vicPlayClass.GetVoicePlay("未校秤", "");
                                bXCStart = true;
                            }
                            txtMsgInfo.Text = "未校秤无法计量";
                            return;
                        }
                    }
                    //*/

                    #endregion 查一次是否校秤，若未校秤则不能计量

                    #region 判断是否需要复磅

                    if (isShowRecover && !string.IsNullOrEmpty(txtCarNo.Text))
                    {
                        recoverInfo.ValidMethod(txtCarNo.Text);
                        if (PbCache.isAllowRecover)
                        {
                            btnRecover.Visible = true;
                        }
                        else
                        {
                            btnRecover.Visible = false;
                        }
                        isShowRecover = false;
                    }

                    #endregion 判断是否需要复磅

                    #region 第一次查询，有车号，重量稳定，红外验证通过的情况只查一次

                    //如果没有查过一次，且扫描到车号信息，且重量稳定
                    if ((bRailwayActual || sPreCarNo != TrackCarNo || firstCode != PbCache.strCode) && PbCache.collect.weightStatus == 0 && PbCache.monitorResult.valid_park_status)
                    {
                        firstWgt = 0;
                        sPreCarNo = TrackCarNo;
                        //判断车辆是厂内车还是厂外车
                        RESTfulResult<List<MeterBaseCar>> resCarList = carService.doQueryCarList(new MeterBaseCar { carNo = PbCache.collect.carno });
                        if (resCarList.Succeed)
                        {
                            if (resCarList.Data != null && resCarList.Data.Count == 1)
                            {
                                MeterBaseCar car = resCarList.Data[0];
                                //厂内车辆
                                if (car.carTypeNo == "001004003")
                                {
                                    RESTfulResult<List<PreTrackScale>> rmScale = PreTrackScaleService.doQueryByFlag(new PreTrackScale { carNo = PbCache.collect.carno, lineDesc = "1" });

                                    if (rmScale.Succeed)
                                    {
                                        if (rmScale.Data != null && rmScale.Data.Count == 1)
                                        {
                                            MeterWorkCarActualFirst actualFirst = new MeterWorkCarActualFirst();

                                            firstWgt = rmScale.Data[0].meterWeight == null ? 0 : rmScale.Data[0].meterWeight.Value;

                                            EntityBase<PreTrackScale> entityBase1 = new EntityBase<PreTrackScale>();
                                            actualFirst = entityBase1.format<MeterWorkCarActualFirst>(rmScale.Data[0], actualFirst);

                                            actualFirst.predictionNo = actualFirst.predictionNo.Replace("_", "");
                                            //给用户控件设置值
                                            ucCarMeterInfoJisco1.setFormControlValue(actualFirst);
                                        }
                                    }
                                    bRailwayActual = false;
                                }
                                //厂外车辆
                                else if (car.carTypeNo == "001004002")
                                {
                                    #region 查询一次计量表中是否存在一条未结净的数据，非一车联运情况扫码两次，一车联运的话

                                    RESTfulResult<List<MeterWorkCarActualFirst>> RESTfulResult = workCarActualFirstService.doQueryWf(new MeterWorkCarActualFirst { carNo = PbCache.collect.carno, valueFlag = "1" });
                                    if (RESTfulResult.Succeed)
                                    {
                                        if (RESTfulResult.Data != null && RESTfulResult.Data.Count > 0)
                                        {
                                            if (PbCache.sportInfo.baseSpotNo == lianDaPointNo)
                                            {
                                                bool flag = false;
                                                foreach (MeterWorkCarActualFirst fs in RESTfulResult.Data)
                                                {
                                                    //联达磅过的联达物料
                                                    if (fs.predictionNo.Contains("_"))
                                                    {
                                                        firstWgt = fs.meterWeight.Value;
                                                        firstDb = fs;
                                                        firstDb.predictionNo = firstDb.predictionNo.Replace("_", "");
                                                        //给用户控件设置值
                                                        ucCarMeterInfoJisco1.setFormControlValue(firstDb);
                                                        flag = true;
                                                        break;
                                                    }
                                                }
                                                if (!flag)
                                                {
                                                    firstWgt = RESTfulResult.Data[0].meterWeight.Value;
                                                    firstDb = RESTfulResult.Data[0];
                                                    firstDb.predictionNo = firstDb.predictionNo.Replace("_", "");
                                                    //给用户控件设置值
                                                    ucCarMeterInfoJisco1.setFormControlValue(firstDb);
                                                }
                                            }
                                            else
                                            {
                                                foreach (MeterWorkCarActualFirst fs in RESTfulResult.Data)
                                                {
                                                    if (fs.predictionNo != null && !fs.predictionNo.Contains("_"))
                                                    {
                                                        firstWgt = RESTfulResult.Data[0].meterWeight.Value;
                                                        firstDb = RESTfulResult.Data[0];
                                                        firstDb.predictionNo = firstDb.predictionNo.Replace("_", "");
                                                        //给用户控件设置值
                                                        ucCarMeterInfoJisco1.setFormControlValue(firstDb);
                                                        break;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    #endregion
                                    bRailwayActual = false;
                                }
                            }
                            else
                            {
                                if (string.IsNullOrEmpty(PbCache.collect.carno))
                                {
                                    txtMsgInfo.Text  = "车号为空，请联系处理";
                                    PbCache.monitorResultMessage = "车号为空，请联系处理";
                                }
                                else
                                {
                                    txtMsgInfo.Text  = "车号未注册，请联系处理";
                                    PbCache.monitorResultMessage = "车号未注册，请联系处理";
                                }
                                PbCache.isLockFrm = false;
                                btnSave.Enabled = true;
                                
                                rtInfo rt = new rtInfo();
                                rt.isWarn = true;
                                rt.WarnContent = "carErr";
                                Monitor(rt);

                                if (!string.IsNullOrEmpty(PbCache.collect.carno))
                                {
                                    carService.addCar(new MeterBaseCar { carNo = PbCache.collect.carno });
                                }
                            return;
                            }
                        }
                        #region 查一次是否可留期限皮，可以则显示按钮

                        PbCache.lockWgt = PbCache.collect.weight;

                        //2021年3月15日 期限皮重显示按钮的显示方法修改 isShowBtnTare   ValidMethod
                        if (termTareCar.isShowBtnTare(TrackCarNo))
                        {
                            lg.WriteLog(3, string.Format("9车辆[{0}进入期限皮重显示按钮的显示判断", TrackCarNo));
                            btnTare.Visible = true;
                        }
                        //

                        #endregion 查一次是否可留期限皮，可以则显示按钮
                    }

                    #endregion 第一次查询，有车号，重量稳定，红外验证通过的情况只查一次


                    #region 毛皮净赋值；存在一次重量firstWgt的情况下才赋值毛皮净重

                    if (PbCache.collect.weightStatus == 0 && firstWgt > 500)
                    {
                        if (Math.Abs(firstWgt - PbCache.collect.weight) > AppConfigCache.differenceWgt)
                        {
                            //2021年5月10日界面显示单位，调整为T
                            if (PbCache.collect.weight > firstWgt)
                            {
                                txtGroess.Text = Math.Round((double)PbCache.collect.weight / 1000, 2) + "";
                                txtTare.Text = Math.Round(firstWgt / 1000, 2) + "";
                            }
                            else
                            {
                                txtTare.Text = Math.Round((double)PbCache.collect.weight / 1000, 2) + "";
                                txtGroess.Text = Math.Round(firstWgt / 1000, 2) + "";
                            }
                            txtNet.Text = Math.Round(Math.Abs(PbCache.collect.weight - firstWgt) / 1000, 2) + "";
                        }
                    }

                    #endregion 毛皮净赋值；存在一次重量firstWgt的情况下才赋值毛皮净重

                    #region 界面未锁定的情况下，如果，有车号，重量稳定了,停车线验证通过，完成了扫码验证

                    //没有远程接管，且已查过一次数据，且界面未锁定的情况下，如果，有车号，重量稳定了,停车线验证通过，完成了扫码验证的情况下，则按钮可用
                    if (PbCache.monitor != null && PbCache.monitor.isTakeOver == "0" && !bRailwayActual
                        && PbCache.collect.weightStatus == 0 && ucWeightT1.isGreenWgt)
                    {
                        if (!PbCache.isLockFrm)
                        {
                            if (!btnSave.Visible)//PbCache.isLockFrm
                            {
                                btnSave.Visible = true;
                            }
                            if (!isVoiceDownCar)
                            {
                                isVoiceDownCar = true;
                                vicPlayClass.GetVoicePlay("车上人员请下车", PbCache.collect.carno);
                                //txtMsgInfo.Text = "请核对车号后，扫描您手机中的二维码";
                            }
                            // 如果计量点配置中，设置了秤点计量类型为智能计量（下秤），验证扫码信息是否与识别车号一致。
                            // 如果为是，自动保存
                            //3秒后自动执行保存方法
                            Thread.Sleep(3000);
                            this.btnSave.PerformClick();

                        }
                        else if (PbCache.monitor.validMatClick == "0")
                        {
                            //已锁定 && !PbCache.isLockFrm 
                            if (!btnSave.Enabled)
                            {
                                PbCache.isLockFrm = false;
                                btnSave.Enabled = true;
                            }
                        }

                    }
                    else
                    {
                        //2021年12月30日 添加提示信息
                        if (!PbCache.isLockFrm)
                        {
                            if (PbCache.monitor.isTakeOver == "1")
                            {
                                lblog = "正在进行派位，不允许进行自助计量，请点击【语音求助】，联系司秤工处理!";
                                DoShowlbLog(lblog);
                            }
                            if (PbCache.monitor.isTakeOver == "2")
                            {
                                lblog = "正在进行远程计量，请等待司秤工处理!";
                                DoShowlbLog(lblog);
                            }
                        }

                        if (btnSave.Visible && !PbCache.isLockFrm)
                        {
                            btnSave.Visible = false;
                            lg.WriteLog(14, "车号：" + PbCache.collect.carno + "；对射没对准【" + PbCache.monitorResult.valid_park_status + "】" +
                                "||重量不是绿色【" + ucWeightT1.isGreenWgt + "】" +
                                "||重量不稳定 0:重量稳定; 1:重量不稳定;  2:空磅【" + PbCache.collect.weightStatus + "】" +
                                "||不是智能计量状态【" + PbCache.monitor.isTakeOver + "】" +
                                "||扫码编号为空隐藏【" + firstCode + "】" +
                                "||一次计量数据已经查询完成【" + bRailwayActual + "】" +
                                "||界面已锁定【" + PbCache.isLockFrm + "】，保存按钮隐藏！");
                        }
                    }

                    #endregion 界面未锁定的情况下，如果，有车号，重量稳定了,停车线验证通过，完成了扫码验证

            }
            catch (Exception ex)
            {
                lg.WriteLog(13, "frmOneYardToEnd页面timer1异常！异常信息：" + ex);
            }
        }

        /// <summary>
        /// 是否是联达物料 0否1是
        /// </summary>
        /// <param name="matterNo"></param>
        /// <returns></returns>
        private bool setLianDaMat(string matterNo) 
        {
            if (lianDaQuery == null) 
            {
                RESTfulResult<MeterBaseMatterInfo> result = matterInfoService.doQueryId(matterNo);
                if (result.Succeed)
                {
                    lianDaQuery = new PbModelDb();
                    lianDaQuery.id = matterNo;
                    //是联达的物料
                    if (result.Data != null && result.Data.isLianda == "1")
                    {
                        lianDaQuery.text = "1";
                    }
                    else
                    {
                        lianDaQuery.text = "0";
                    }
                }
                else
                {
                    return false;
                }
            }
            return true;
        }


        #region 信息提示框

        private string lblog;//信息显示

        public string Lblog//信息显示
        {
            get { return lblog; }
            set
            {
                lblog = value;
                DoShowlbLog(value);
            }
        }

        private delegate void ShowlbLog(string lblog);

        private void DoShowlbLog(string _lbLog)
        {
            if (this.txtMsgInfo.InvokeRequired)
            {//在线程里以安全方式调用控件
                ShowlbLog _MyInvokeOne = new ShowlbLog(DoShowlbLog);
                txtMsgInfo.Invoke(_MyInvokeOne, new object[] { _lbLog });
            }
            else
            {
                txtMsgInfo.Text = _lbLog;
            }
            //2021年3月13日；不管是哪一种方式调用界面控件的值，均记录现场日志
            if (!string.IsNullOrEmpty(lblog) && PbCache.collect != null)
            {
                lg.WriteLog(9, "[" + PbCache.collect.carno + "]" + lblog);
            }
        }

        #endregion 信息提示框
            

        #region 打印

        private string strFirstNo = "";

        private class PrintCls
        {
            public int printNum { get; set; }
            public MeterWorkCarActual printDb { get; set; }
            public int iType { get; set; } //0毛 1 皮 2净
            public string qrCode { get; set; }
        }

        private PrintCls printData = new PrintCls();

        private void Print1(string firstNo)
        {
            try
            {
                //lg.WriteLog(1, "打印开始");

                #region 获取打印信息，若需要打印则调用打印操作

                List<PrintCls> prrintC = new List<PrintCls>();

                string sql = @"select actual_no actualNo,
                                   prediction_no predictionNo,
                                   car_no carNo,
                                   matter_no matterNo,
                                   matter_name matterName,
                                   gross_weight grossWeight,
                                   gross_time grossTime,
                                   tare_weight tareWeight,
                                   tare_time tareTime,
                                   net_weight netWeight,
                                   net_Time netTime,
                                   'x' meterTypeNo,
                                   meter_type_name meterTypeName,
                                   spec_name specName,
                                   forwarding_unit_name forwardingUnitName,
                                   receiving_uint_name receivingUintName,
                                   load_point_name loadPointName,
                                   add_weight addWeight,
                                   '1' uploadFlag --1结净数据 0一次表数据
                              from meter_work_car_actual where actual_first1_no = '" + firstNo + @"' or actual_first2_no='" + firstNo + @"'
                            union all
                            select t.actual_first_no      actualNo,
                                   t.prediction_no        predictionNo,
                                   t.car_no               carNo,
                                   t.matter_no            matterNo,
                                   t.matter_name          matterName,
                                   t.meter_weight         grossWeight,
                                   t.create_time          grossTime,
                                   0                      tareWeight,
                                   t.create_time          tareTime,
                                   0                      netWeight,
                                   null                   netTime,
                                   t.weight_type          meterTypeNo, --0毛重 否则皮重
                                   t.meter_type_name      meterTypeName,
                                   t.spec_name            specName,
                                   t.forwarding_unit_name forwardingUnitName,
                                   t.receiving_uint_name  receivingUintName,
                                   t.load_point_name      loadPointName,
                                   t.add_weight addWeight,
                                   '0' uploadFlag
                              from METER_WORK_CAR_ACTUAL_FIRST t
                                where t.actual_first_no = '" + firstNo + "' or  t.actual_first_no = (select max(actual_first2_no) from meter_work_car_actual where actual_first1_no='" + firstNo + "')";
                //查下如果有毛重或者结净数据，则可进入打印判断
                PbModelDbService<List<MeterWorkCarActual>> pbModelDbService = new PbModelDbService<List<MeterWorkCarActual>>();
                RESTfulResult<List<MeterWorkCarActual>> rm = pbModelDbService.executeSqlDataWf(sql);

                //lg.WriteLog(1, "打印第一个sql：" + sql);

                if (rm.Succeed)
                {                  
                    if (rm.Data != null && rm.Data.Count > 0)
                    {
                        //2021年6月26日 对一车联运的进行处理；用一次计量编号查二次计量数据，
                        sql = @"select t3.actual_no actualNo, t3.prediction_no predictionNo, t3.car_no carNo, t3.matter_no matterNo, t3.matter_name matterName,
                                t3.gross_weight grossWeight, t3.gross_time grossTime, t3.tare_weight tareWeight, t3.tare_time tareTime, t3.net_weight netWeight,
                                t3.net_Time netTime, 'x' meterTypeNo, t3.meter_type_name meterTypeName, t3.spec_name specName,
                                t3.forwarding_unit_name forwardingUnitName, t3.receiving_uint_name receivingUintName, t3.load_point_name loadPointName,
                                t3.add_weight addWeight, '1' uploadFlag from meter_work_car_actual_first t2
                                  left join meter_work_car_actual t3 on t2.actual_first_no = t3.actual_first1_no
                                 where t2.prediction_combination in (select t.prediction_combination
                                           from meter_work_car_actual_first t
                                      where t3.value_flag = '0' and t.actual_first_no = '" + firstNo + @"' and
                                            instr(t.prediction_combination, '20') > 0) order by t3.net_time desc";
                        RESTfulResult<List<MeterWorkCarActual>> rmLy = pbModelDbService.executeSqlDataWf(sql);
                        if (rmLy.Succeed && rmLy.Data != null && rmLy.Data.Count == 1)
                        {
                            rm.Data = rmLy.Data; //一车联运，将毛重替换为净重数据
                        }

                        //若有毛重或者净重，找到对应数据的物料信息，若有，那么去找打印配置信息数据
                        List<MeterWorkCarActual> mwa = rm.Data.Where(s => !string.IsNullOrEmpty(s.matterNo) && (s.meterTypeNo == "x" || s.meterTypeNo == "0")).ToList();
                        if (mwa != null && mwa.Count > 0 && !string.IsNullOrEmpty(mwa[0].matterNo))
                        {
                            sql = @"select BASE_SPOT_NO    baseSpotNo,
                                           load_point_no   loadPointNo,
                                           matter_no       matterNo,
                                           METER_TYPE_NO   meterTypeNo,
                                           weight_type_name weightTypeName,
                                           PRINT_NUM       printNum
                                      from METER_BASE_BILL_PRINT
                                     where matter_no = '" + mwa[0].matterNo + @"'
                                       and nvl(METER_TYPE_NO, '" + PbCache.bussinessTypeCode + @"') = '" + PbCache.bussinessTypeCode + @"'
                                       and nvl(BASE_SPOT_NO, '" + PbCache.sportInfo.baseSpotNo + @"') = '" + PbCache.sportInfo.baseSpotNo + @"'
                                       and nvl(load_point_no, '" + (mwa[0].loadPointNo == null ? "1" : mwa[0].loadPointNo) + @"') = '" + (mwa[0].loadPointNo == null ? "1" : mwa[0].loadPointNo) + @"'";

                            //lg.WriteLog(1, "打印第二个sql：" + sql);

                            //and nvl(METER_TYPE_NO, '') = ''
                            PbModelDbService<List<MeterBaseBillPrint>> pbPrintService = new PbModelDbService<List<MeterBaseBillPrint>>();
                            RESTfulResult<List<MeterBaseBillPrint>> rmPint = pbPrintService.executeSqlDataWf(sql);
                            if (rmPint.Succeed)
                            {
                                if (rmPint.Data != null && rmPint.Data.Count > 0)
                                {
                                    //若有净重信息：1毛重时间晚于皮重时间，则打印毛、皮、净重，2毛重早于皮重，打印皮、净
                                    //若只有毛重信息则打印毛重
                                    List<MeterBaseBillPrint> lGrossprint = rmPint.Data.Where(s => s.weightTypeName.Contains("毛")).ToList();
                                    List<MeterBaseBillPrint> lTarePrint = rmPint.Data.Where(s => s.weightTypeName.Contains("皮")).ToList();
                                    List<MeterBaseBillPrint> lNetprint = rmPint.Data.Where(s => s.weightTypeName.Contains("净")).ToList();

                                    List<MeterWorkCarActual> mwaChild = mwa.Where(s => s.meterTypeNo == "x").ToList();
                                    if (mwaChild != null && mwaChild.Count > 0) //若有净重信息
                                    {
                                        if (lTarePrint != null && lTarePrint.Count > 0)
                                        {
                                            //获取非毛，非净重信息如果没有则用的期限皮，此时不打，否则则打印
                                            MeterWorkCarActual mwca = rm.Data.Where(s => s.meterTypeNo != "x" && s.meterTypeNo != "0").FirstOrDefault();
                                            if (mwca != null)
                                            {
                                                PrintCls cls = new PrintCls();
                                                cls.printNum = (int)(lTarePrint[0].printNum == null ? 0 : lTarePrint[0].printNum.Value);
                                                cls.iType = 1;//皮重
                                                cls.printDb = mwca;
                                                prrintC.Add(cls);
                                            }
                                        }
                                        if (lGrossprint != null && lGrossprint.Count > 0)
                                        {
                                            //获取毛重信息
                                            MeterWorkCarActual mwca = rm.Data.Where(s => s.meterTypeNo == "0").FirstOrDefault();
                                            if (mwca != null)
                                            {
                                                PrintCls cls = new PrintCls();
                                                cls.printNum = (int)(lGrossprint[0].printNum == null ? 0 : lGrossprint[0].printNum.Value);
                                                cls.iType = 0;//毛重
                                                cls.printDb = mwca;
                                                prrintC.Add(cls);
                                            }
                                        }
                                        if (lNetprint != null && lNetprint.Count > 0)
                                        {
                                            //获取净重信息
                                            MeterWorkCarActual mwca = rm.Data.Where(s => s.meterTypeNo == "x").FirstOrDefault();
                                            if (mwca != null)
                                            {
                                                PrintCls cls = new PrintCls();
                                                cls.printNum = (int)(lNetprint[0].printNum == null ? 0 : lNetprint[0].printNum.Value);
                                                cls.iType = 2;//净重
                                                cls.printDb = mwca;
                                                prrintC.Add(cls);
                                            }
                                        }
                                    }
                                    else //只有毛重信息则打印毛重
                                    {
                                        if (lGrossprint != null && lGrossprint.Count > 0)
                                        {
                                            //获取毛重信息
                                            MeterWorkCarActual mwca = rm.Data.Where(s => s.meterTypeNo == "0").FirstOrDefault();
                                            if (mwca != null)
                                            {
                                                PrintCls cls = new PrintCls();
                                                cls.printNum = (int)(lGrossprint[0].printNum == null ? 0 : lGrossprint[0].printNum.Value);
                                                cls.iType = 0;//毛重
                                                cls.printDb = mwca;
                                                prrintC.Add(cls);
                                            }
                                        }
                                    }

                                    if (prrintC != null && prrintC.Count > 0)
                                    {
                                        FrmMessage frmMessage = FrmMess("是否打印第【1】张票据！", "打印");
                                        if (frmMessage.ShowDialog(this) == DialogResult.OK)
                                        {
                                            lg.WriteLog(10, "车号【" + PbCache.lockCarNo + "】是否打印选择了【是】");
                                            lg.WriteLog(15, PbCache.lockCarNo + "是否打印选择了【是】");
                                            strFirstNo = firstNo;
                                            //printDocument1.PrinterSettings.PrinterName = PbCache.sportInfo.printerName;//strPntSvrName;
                                            System.Drawing.Printing.PaperSize customSize1 = new System.Drawing.Printing.PaperSize("TestPaper", 398, 433); //101mm*110mm,换算成英寸
                                            printDocument1.DefaultPageSettings.PaperSize = customSize1;//将自定义的Papersize赋给PrintDocument
                                            System.Drawing.Printing.Margins marginss = new System.Drawing.Printing.Margins(0, 0, 0, 0);
                                            printDocument1.DefaultPageSettings.Margins = marginss;
                                            printDocument1.PrintController = new System.Drawing.Printing.StandardPrintController();

                                            foreach (PrintCls db in prrintC)
                                            {
                                                switch (db.printDb.meterTypeNo)
                                                {
                                                    case "0": //毛
                                                        db.qrCode = db.printDb.actualNo + "," + db.printDb.grossWeight + "," + "1";
                                                        break;

                                                    case "x": //净
                                                        db.qrCode = db.printDb.actualNo + "," + db.printDb.netWeight + "," + "2";
                                                        break;

                                                    default: //皮
                                                        db.qrCode = db.printDb.actualNo + "," + db.printDb.grossWeight + "," + "1";
                                                        break;
                                                }
                                                RESTfulResult<string> rQRCode = workCarActualFirstService.doQRCodeWf(db.qrCode);
                                                db.qrCode = rQRCode.Data;

                                                for (int i = 0; i < db.printNum; i++)
                                                {
                                                    if (i == 0)
                                                    {
                                                        printData = db;
                                                        printDocument1.Print();
                                                        lg.WriteLog(10, "当前第" + (i + 1) + "次打印：" + printData.iType + "  车号：" + db.printDb.carNo + ",二维码:" + db.qrCode);
                                                    }
                                                    else
                                                    {
                                                        FrmMessage frmMessageContinue = FrmMess("已打印【" + i + "】张，是否继续打印第【" + (i + 1) + "】张票据！", "打印");
                                                        if (frmMessageContinue.ShowDialog(this) == DialogResult.OK)
                                                        {
                                                            printData = db;
                                                            printDocument1.Print();
                                                            lg.WriteLog(10, "当前第" + (i + 1) + "次打印：" + printData.iType + "  车号：" + db.printDb.carNo + ",二维码:" + db.qrCode);
                                                        }
                                                        else
                                                        {
                                                            lg.WriteLog(10, "车号【" + PbCache.lockCarNo + "】第" + i + "次是否打印，选择了【否】");
                                                        }
                                                    }
                                                    //printData = db;
                                                    //printDocument1.Print();
                                                    //lg.WriteLog(11, "当前打印：" + printData.iType + "  车号：" + db.printDb.carNo);
                                                }
                                            }
                                        }
                                        else
                                        {
                                            lg.WriteLog(10, "车号【" + PbCache.lockCarNo + "】是否打印选择了【否】");
                                            lg.WriteLog(15, PbCache.lockCarNo + "是否打印选择了【否】");
                                        }
                                    }
                                }
                            }
                            else
                            {
                                lg.WriteLog(10, "车号【" + PbCache.lockCarNo + "】获取打印配置数据信息异常sql:【" + sql + "】");
                            }
                        }
                    }
                }
                else
                {
                    lg.WriteLog(10, "车号【" + PbCache.lockCarNo + "】获取计量数据信息异常sql:【" + sql + "】");
                }

                #endregion 获取打印信息，若需要打印则调用打印操作
            }
            catch (Exception ex)
            {
                lg.WriteLog(10, "车号【" + PbCache.lockCarNo + "】打印异常" + ex);
            }
        }

        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            try
            {
                if (printData != null && printData.printDb != null)
                {
                    printClass.PrintAllPage(e, printData.printDb, printData.qrCode);

                    /*
                    //结净打印
                    if (printData.iType == 2)
                    {
                        printClass.PrintPage(e, printData.printDb, PbCache.strQRCode);
                    }
                    else //非结净打印
                    {
                        printClass.PrintWgtPage(e, printData.printDb, PbCache.strQRCode);
                    }
                    //*/
                }
            }
            catch (Exception ex)
            {
                lg.WriteLog(11, "打印异常" + ex);
            }
        }

        #endregion 打印

        private void btnFH_Click(object sender, EventArgs e)
        {
            lg.WriteLog(15, PbCache.lockCarNo + "点击了返回主界面");
            this.Close();
        }

        private static FrmMessage FrmMess(string strMess, string strBtnSaveInfo)
        {
            FrmMessage frmMessage = new FrmMessage();
            frmMessage.StartPosition = FormStartPosition.Manual;
            frmMessage.Location = new Point(350, 450);
            frmMessage.ShowMessage = strMess;
            frmMessage.BtnSaveText = strBtnSaveInfo;
            frmMessage.BtnCancelText = "取消";
            return frmMessage;
        }

        /// <summary>
        /// 期限皮重保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnTare_Click(object sender, EventArgs e)
        {
            try
            {
                if (PbCache.collect == null) return;
                //界面锁定
                PbCache.lockWgt = PbCache.collect.weight;
                if (PbCache.monitor.validCarno == "0")
                {
                    PbCache.collect.carno = TrackCarNo;
                }
                PbCache.lockCarNo = PbCache.collect.carno;
                btnTare.Enabled = false;
                PreTrackScale preTrack = ucCarMeterInfoJisco1._preTrack;
                lg.WriteLog(15, PbCache.lockCarNo + "点击期限皮重按钮");

                //计量已完成，不允许重复保存期限皮重
                if (PbCache.isLockFrm)
                {
                    vicPlayClass.GetVoicePlay("不允许重复保存期限皮重", PbCache.collect.carno);
                    PbCache.ResultMessage = "已经完成计量保存操作，不允许重复保存期限皮重！";
                    btnSave.Enabled = true;
                    setMsg(PbCache.ResultMessage);
                    return;
                }

                #region 红外对射及量程验证
                valid.ValidMethod();
                if (PbCache.range != null && PbCache.range.upperRange < PbCache.collect.weight)
                {
                    //超量程
                    vicPlayClass.GetVoicePlay("已超量程", PbCache.collect.carno);
                    PbCache.ResultMessage = "当前重量已超量程，秤体量程为【" + PbCache.range.upperRange / 1000 + "】T，不允许进行自助计量操作！";
                    btnSave.Enabled = true;
                    setMsg(PbCache.ResultMessage);
                    return;
                }
                else if (PbCache.collect.weightStatus == 0 && !PbCache.monitorResult.valid_park_status)
                {
                    //重量稳定，且对射验证不合格
                    vicPlayClass.GetVoicePlay("您的车辆未停到位", PbCache.collect.carno);
                    PbCache.ResultMessage = "您的车辆未停到位，请调整车辆位置，不要遮挡激光检测设备，不允许进行自助计量操作！";//btnTare_Click
                    btnSave.Enabled = true;
                    setMsg(PbCache.ResultMessage);
                    return;
                }
                #endregion 红外对射及量程验证

                //2021年3月13日 杨秀东新增逻辑，车号为空则不允许进行期限皮重保存操作
                if (string.IsNullOrEmpty(PbCache.lockCarNo))
                {
                    vicPlayClass.GetVoicePlay("不允许进行期限皮重保存", PbCache.lockCarNo);
                    PbCache.ResultMessage = "未抓拍到车牌号，进行期限皮重保存，请点[语音求助]！";
                    setMsg(PbCache.ResultMessage);
                    btnTare.Enabled = true;
                    return;
                }

                //期限皮重业务是否能够保存验证；物资、业务类型、车号验证
                if (!termTareCar.ValidMethodThree(preTrack))
                {
                    vicPlayClass.GetVoicePlay("不允许进行期限皮重保存", PbCache.lockCarNo);
                    setMsg(PbCache.ResultMessage);
                    btnTare.Enabled = true;
                    return;
                }

                //查一次是否可留期限皮;重量验证
                if (!termTareCar.ValidMethod(PbCache.lockCarNo))
                {
                    vicPlayClass.GetVoicePlay("不允许进行期限皮重保存", PbCache.lockCarNo);
                    setMsg(PbCache.ResultMessage);
                    btnTare.Enabled = true;
                    return;
                }
               
                //若存在有效的一次计量数据，则不允许进行期限皮重保存
                if (!termTareCar.ValidActualFirst(preTrack))
                {
                    vicPlayClass.GetVoicePlay("不允许进行期限皮重保存", PbCache.lockCarNo);
                    setMsg(PbCache.ResultMessage);
                    btnTare.Enabled = true;
                    return;
                }

                //暂停取实时数据
                setMsg("称重保存中......");
                FrmMessage frmMessage = FrmMess("是否确认保存期限皮重！", "继续保存");
                if (frmMessage.ShowDialog(this) == DialogResult.Cancel)
                {
                    setMsg("");
                    btnTare.Enabled = true;
                    lg.WriteLog(15, PbCache.lockCarNo + "期限皮重继续保存选择了【否】");
                    return;
                }

                MeterBaseTermTareData mbttd = new MeterBaseTermTareData();
                mbttd.baseSpotNo = PbCache.sportInfo.baseSpotNo;
                mbttd.baseSpotName = PbCache.sportInfo.baseSpotName;
                mbttd.carNo = PbCache.collect.carno;
                mbttd.meterWeight = PbCache.lockWgt;
                mbttd.valueFlag = "0";
                mbttd.createTime = DateTime.Now;
                mbttd.createManNo = PbCache.sportInfo.baseSpotNo;
                mbttd.createManName = PbCache.sportInfo.baseSpotName;
                mbttd.meterTime = mbttd.createTime.Value;
                mbttd.startTime = mbttd.createTime.Value;

                //操作日志
                MeterMonitorNote monitorNote = new MeterMonitorNote();
                monitorNote.baseSpotNo = mbttd.baseSpotNo;
                monitorNote.baseSpotName = mbttd.baseSpotName;
                monitorNote.operationContent = string.Format("保存期限皮重");
                monitorNote.operationTime = mbttd.createTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
                monitorNote.carNo = mbttd.carNo;
                monitorNote.meterNoteSource = "0";

                //期限皮重数据保存
                RESTfulResult<string> RESTfulResult = termTareDate.doSaveWf(mbttd, monitorNote);
                if (RESTfulResult.Succeed && RESTfulResult.Code !="500")
                {
                    PbCache.isLockFrm = true;
                    PbCache.actualFirstNo = RESTfulResult.Data;
                    //称重完成后，显示颜色；
                    _ = BeginInvoke(new Action(() => { ucWeightCarTJXJG1.setWgtBackColor(true); }));
                    
                    //称重完成后，显示重量类型为皮重；
                    _ = BeginInvoke(new Action(() => { ucWeightCarTJXJG1.setWeightType("皮重"); }));

                    //期限皮重成功截图
                    _ = BeginInvoke(new Action(() => { shotImage(); }));

                    //保存成功，语音提示保存成功
                    vicPlayClass.GetVoicePlay("期限皮重保存成功", PbCache.lockCarNo);//播放语音
                    btnTare.Visible = false;
                    lg.WriteLog(3, string.Format("车号[{0}]期限皮重保存成功", PbCache.lockCarNo));
                    setMsg("称重保存成功，请离开秤台！");
                }
                else
                {
                    PbCache.actualFirstNo = RESTfulResult.Data;
                    //期限皮重失败截图
                    _ = BeginInvoke(new Action(() => { shotImage(); }));
                    btnTare.Enabled = true;
                    setMsg(RESTfulResult.ResultMessage);
                    vicPlayClass.GetVoicePlay("期限皮重保存失败", PbCache.lockCarNo);//播放语音
                    lg.WriteLog(3, string.Format("车号[{0}]期限皮重保存失败", PbCache.lockCarNo));
                }
            }
            catch (Exception ex)
            {
                lg.WriteLog(13, PbCache.lockCarNo + "期限皮重事件异常：" + ex.Message);
            }
        }

        /// <summary>
        /// 复磅保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnRecover_Click(object sender, EventArgs e)
        {
            try
            {
                if (PbCache.collect == null) return;
                PbCache.isLockFrm = true;
                PbCache.lockCarNo = PbCache.collect.carno;
                PbCache.lockWgt = PbCache.collect.weight;
                btnRecover.Enabled = false;
                lg.WriteLog(15, PbCache.lockCarNo + "点击【复磅】按钮");

                //仪表重量验证
                if (!dataValidity.ValidMethod(PbCache.lockWgt))
                {
                    txtMsgInfo.Text = PbCache.ResultMessage;
                    return;
                }

                //验证是否满足复磅的条件
                recoverInfo.ValidMethod(PbCache.lockCarNo);
                if (!PbCache.isAllowRecover)
                {
                    PbCache.isLockFrm = false;
                    btnRecover.Enabled = true;
                    setMsg(PbCache.ResultMessage);
                    lg.WriteLog(15, PbCache.lockCarNo + "不满足复磅条件！" + PbCache.ResultMessage);
                    return;
                }

                txtMsgInfo.Text = "复磅保存中......";
                FrmMessage frmMessage = FrmMess("是否确认保存当前复磅重量数据！", "继续保存");
                if (frmMessage.ShowDialog(this) == DialogResult.Cancel)
                {
                    PbCache.isLockFrm = false;
                    btnRecover.Enabled = true;
                    txtMsgInfo.Text = "";
                    lg.WriteLog(15, PbCache.lockCarNo + "【复磅】按钮选择否");
                    return;
                }

                //复磅数据保存
                RESTfulResult<string> RESTfulResult = carRecoverService.doRecover(new MeterWorkCarRecover { carNo = PbCache.lockCarNo, recMeterWeight = PbCache.lockWgt });
                if (RESTfulResult.Succeed)
                {
                    //保存成功，语音提示保存成功
                    vicPlayClass.GetVoicePlay("称重完成", PbCache.lockCarNo);//播放语音
                    btnTare.Visible = false;
                    lg.WriteLog(3, string.Format("车号[{0}]复磅保存成功", PbCache.lockCarNo));
                    setMsg("复磅保存成功，请离开秤台！");
                }
                else
                {
                    PbCache.isLockFrm = false;
                    btnRecover.Enabled = true;
                    setMsg(RESTfulResult.ResultMessage);
                    vicPlayClass.GetVoicePlay("称重数据保存失败", PbCache.lockCarNo);//播放语音
                    lg.WriteLog(3, string.Format("车号[{0}]复磅保存失败" + RESTfulResult.Message, PbCache.lockCarNo));
                }
            }
            catch (Exception ex)
            {
                lg.WriteLog(13, PbCache.lockCarNo + "复磅保存事件异常：" + ex.Message);
            }
        }

        #region 信息提示框

        public void setMsgInfo(string ResultMessage)
        {
            setMsg(ResultMessage);
        }

        private void setMsg(string ResultMessage)
        {
            if (txtMsgInfo.InvokeRequired)
            {
                Action<string> action = new Action<string>(setMsgInfo);
                Invoke(action, new object[] { ResultMessage });
            }
            else
            {
                txtMsgInfo.Text = ResultMessage;
            }
            if (!string.IsNullOrEmpty(ResultMessage) && PbCache.collect != null)
            {
                lg.WriteLog(9, "[" + PbCache.collect.carno + "]" + ResultMessage);
            }
        }

        #endregion 信息提示框

        /// <summary>
        /// 车号改变时，判断是否需要显示复磅按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtCarNo_TextChanged(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// 清空监控表的数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frmOneYardToEnd_FormClosing(object sender, FormClosingEventArgs e)
        {
            try
            {
                //初始化一些线程及数据，并关闭该界面
                if (PbCache.collect != null && !string.IsNullOrEmpty(PbCache.collect.carno))
                {
                    PbCache.collect.carno = "";
                }
                isShowRecover = true;//是否去查询“复磅”按钮的显示与否
                PbCache.strCode = "";
                PbCache.isOvertimeAlarm = false; //是否超时报警
                bRailwayActual = true; //为true时会重新查询一次计量数据
                isShowRecover = true;//是否去查询“复磅”按钮的显示与否
                PbCache.Load();
                //关闭一些线程及定时任务
                timer1.Stop();
                timer1.Dispose();

                #region 清理一次监控表的几个数值，防止上车速度过快导致提示称重完成

                //RESTfulResult<string> rms = monitor.doUpdateWf(new MeterWorkMonitor { pointNo = PbCache.sportInfo.baseSpotNo, isOverWgt = "" });

                RESTfulResult<string> rms = monitor.doUpdateWf(new MeterWorkMonitor
                {
                    pointNo = PbCache.sportInfo.baseSpotNo,
                    validWgt = "1",
                    validCarno = "1",
                    validTareTime = "1",
                    validMatTime = "1",
                    validTimeInterval = "1",
                    validParkStatus = "1",
                    validExceedWgt = "1",
                    validPredictionDiff = "1",
                    validLianda = "1",
                    validMatClick = "1",
                    setCar = "",
                    rfidCar = "",
                    photoCar = "",
                    scanCar = "",
                    editCar = "",
                    carErr = "0",
                    wgtErr = "0",
                    stopOverTime = "0",
                    msgInfo = "",
                    isOverWgt = "",
                    isHelp = "0",
                    wgt = 0
                });
            }
            catch (Exception ex)
            {
                lg.WriteLog(0, "frmCarSalePurchase_FormClosing异常：下秤关闭界面异常！异常信息：" + ex);
            }

            #endregion 清理一次监控表的几个数值，防止上车速度过快导致提示称重完成
        }
        
        /// <summary>
        /// 修改监控表验证状态
        /// </summary>
        public void Monitor(rtInfo rt)
        {
            MeterWorkMonitor meterWorkMonitor = new MeterWorkMonitor();
            meterWorkMonitor.pointNo = PbCache.sportInfo.baseSpotNo;
            RESTfulResult<string> rms = null;
            if (rt.isWarn)
            {
                if (rt.WarnContent == "validIsPre")
                {
                    meterWorkMonitor.validIsPre = "1";
                }
                if(rt.WarnContent == "validWgt")
                {
                    meterWorkMonitor.wgtErr = "1";
                }
                if (rt.WarnContent == "carErr")
                {
                    meterWorkMonitor.carErr = "1";
                }
                rms = monitor.doUpdateWf(meterWorkMonitor);
            }
            if (rt.isHelp)
            {
                meterWorkMonitor.isHelp = "1";
                rms = monitor.doUpdateWf(meterWorkMonitor);
            }
            if (rms == null)
            {
                return;
            }
            if (!rms.Succeed)
            {
                lg.WriteLog(3, PbCache.lockCarNo + "求助写入失败");
            }
        }
    }
}