using com.hnshituo.core.webapp.vo;
using Common;
using iCore.Rtdb.RtdbTable;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;

namespace MeterModuleLibrary.uc
{
    public delegate void EventVoice(object o, string e);

    public delegate void EventOpenMsg(string e);

    public partial class ucCarMonitoring : UserControl
    {
        public string strCollectNo = "";

        public ucCarMonitoring()
        {
            InitializeComponent();
        }

        //public DhCameraShot cameraShotMain;

        private Log lg = Log.GetInstance();
        private MemoryTableDataSocket MemoClass = null;//内存表
        private PbModelDbService<object> PbModelDbService = new PbModelDbService<object>();
        private MeterMonitorNoteService noteService = new MeterMonitorNoteService(); //MemoryTableDataSocket

        public event EventOpenMsg openMsg;

        public DbHelper db = null;

        /// <summary>
        /// 主界面调用的按钮事件
        /// </summary>
        public event EventHandler ucMonitoringEvent;

        /// <summary>
        /// 主界面调用的提示音播放
        /// </summary>
        public event EventVoice evoice;

        private List<sModel> lm = new List<sModel>();

        public class sModel
        {
            public string key { get; set; }
            public bool flag { get; set; }
        }

        /// <summary>
        /// 计量点
        /// </summary>
        public string sPoint = "", sPointName = "";

        /// <summary>
        /// 登录人的姓名
        /// </summary>
        public string sUserId = "", sName = "";

        /// <summary>
        /// 新增的计量表监控数据
        /// </summary>
        public MeterWorkMonitor drOldData = null, rowPointInfo = null;

        /// <summary>
        /// 是否打开了语音
        /// </summary>
        public bool bOpenVoice = false;

        /// <summary>
        /// 用于防止跳闪选中
        /// </summary>
        private bool chkFlag = false;

        public string sWgt = "";

        public bool isNcFlag = false;

        #region 设置语音播报

        private void setVoice(Button bcBtn)
        {
            List<sModel> lsm = lm.Where(s => s.key == bcBtn.Name).ToList();
            if (bcBtn.BackColor == Color.Red)
            {
                if (lsm == null || lsm.Count == 0)
                {
                    lm.Add(new sModel { key = bcBtn.Name, flag = false });
                    evoice(this, sPoint);
                    evoice(this, bcBtn.Text.Trim());
                    lg.WriteLog(4, sPoint + "=====语音报警===【" + bcBtn.Text.Trim() + "】===");
                }
                else
                {
                    if (lsm[0].flag)
                    {
                        foreach (sModel sm in lm)
                        {
                            if (sm.key == bcBtn.Name)
                            {
                                sm.flag = false;
                            }
                        }

                        evoice(this, sPoint);
                        evoice(this, bcBtn.Text.Trim());
                    }
                }
            }
            else
            {
                if (lsm != null && lsm.Count > 0)
                {
                    foreach (sModel sm in lm)
                    {
                        if (sm.key == bcBtn.Name)
                        {
                            sm.flag = true;
                        }
                    }
                }
            }
        }

        #endregion 设置语音播报

        /// <summary>
        /// 设置按钮值
        /// </summary>
        public void setBtnVoiceText(string value)
        {
            if (value == "挂断")
            {
                btnIpVoice.BackColor = Color.Red;
            }
            else if (value == "对讲")
            {
                btnIpVoice.BackColor = Color.DodgerBlue;
            }

            btnIpVoice.Text = value;
            btnVoiceText = value;
        }

        public string btnVoiceText = "对讲";

        #region 远程计量

        private MeterWorkMonitorService monitorService = new MeterWorkMonitorService();

        private void btnYc_Click(object sender, EventArgs e)
        {
            if (btnYc.Text == "远程计量")
            {
                UpdateCarijeg(new MeterWorkMonitor { pointNo = sPoint, isTakeOver = "1", userNo = "", isRemote = "1" }, "写入远程计量信息：" + btnYc.Text.Trim());
                btnYc.Text = "智能计量";
                btnYc.BackColor = Color.Red;
            }
            else
            {
                if (rowPointInfo.isTakeOver != "2")
                {
                    UpdateCarijeg(new MeterWorkMonitor { pointNo = sPoint, isTakeOver = "0", userNo = "", isRemote = "0" }, "远程计量切回智能计量：" + btnYc.Text.Trim());
                    btnYc.Text = "远程计量";
                    btnYc.BackColor = Color.DodgerBlue;
                }
                else
                {
                    MessageBox.Show("已远程接管，需先取消接管");
                }
            }
        }

        #endregion 远程计量

        /// <summary>
        /// 打开视频界面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSee_Click(object sender, EventArgs e)
        {
            //将这边的事件回发到主窗口调用
            EventArgs arg = new EventArgs();
            if (ucMonitoringEvent != null)
            {
                ucMonitoringEvent(sender, arg);
            }
        }

        #region 控制开关
        private void chkVALID_LIANDA_Click(object sender, EventArgs e)
        {
            chkFlag = true;
            chkEvent((CheckBox)sender);
        }

        private void chkVALID_MAT_TIME_Click(object sender, EventArgs e)
        {
            chkFlag = true;
            chkEvent((CheckBox)sender);
        }

        private void chkVALID_PARK_STATUS_CheckedChanged(object sender, EventArgs e)
        {
            chkFlag = true;
            chkEvent((CheckBox)sender);
        }

        private void chkVALID_CARNO_CheckedChanged(object sender, EventArgs e)
        {
            chkFlag = true;
            chkEvent((CheckBox)sender);
        }

        private void chkVALID_TARE_TIME_CheckedChanged(object sender, EventArgs e)
        {
            chkFlag = true;
            chkEvent((CheckBox)sender);
        }

        private void chkVALID_TIME_INTERVAL_CheckedChanged(object sender, EventArgs e)
        {
            chkFlag = true;
            chkEvent((CheckBox)sender);
        }

        private void chkVALID_PREDICTION_DIFF_CheckedChanged(object sender, EventArgs e)
        {
            chkFlag = true;
            chkEvent((CheckBox)sender);
        }

        private void chkVALID_EXCEED_WGT_CheckedChanged(object sender, EventArgs e)
        {
            chkFlag = true;
            chkEvent((CheckBox)sender);
        }

        private void chkVALID_WGT_CheckedChanged(object sender, EventArgs e)
        {
            chkFlag = true;
            chkEvent((CheckBox)sender);
        }

        private void chkEvent_CheckedChanged(object sender, EventArgs e)
        {
            chkFlag = true;
            chkEvent((CheckBox)sender);
        }

        private void chkVALID_MAT_CLICK_Click(object sender, EventArgs e)
        {
            chkFlag = true;
            chkEvent((CheckBox)sender);
        }

        /// <summary>
        /// 不验证计量区域
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void chkVALID_METER_AREA_Click_Click(object sender, EventArgs e)
        {
            chkFlag = true;
            chkEvent((CheckBox)sender);
        }


        private void chkEvent(CheckBox chk)
        {
            //chk.Checked = !chk.Checked;

            string str = "取消勾选";
            if (chk.Checked)
            {
                str = "勾选";
            }
            string car_No = cbCarNo.Text.Trim() + txtRfidCarNo.Text.Trim();

            string sql = string.Format("update METER_WORK_MONITOR set {0} = '{1}' where POINT_NO='{2}'", chk.Name.Replace("chk", ""), chk.Checked ? "0" : "1", sPoint);
            RESTfulResult<object> rm = PbModelDbService.executeSqlDataWf(sql);
            if (rm.Succeed)
            {
                WriteMonitorNote(str + chk.Text);
            }
        }

        #endregion 控制开关

        #region button按钮事件

        private void btnZero_Click(object sender, EventArgs e)
        {
            //*
            if (DialogResult.Yes == MessageBox.Show("确实要执行清零操作吗？", "提示", MessageBoxButtons.YesNo))
            {
                if (txtWeight.Text.Contains("kg"))
                {
                    if (!string.IsNullOrEmpty(txtWeight.Text.Replace("kg", "")))
                    {
                        int iValue = Convert.ToInt32(txtWeight.Text.Replace("kg", ""));
                        MeterBaseScaleRange mbsr = PbCacheMonitor.ltRange.Where(s => s.baseSpotNo == sPoint).FirstOrDefault();
                        if (mbsr != null)
                        {
                            if (mbsr.upperLimitClearZero < iValue || mbsr.lowerLimitClearZero > iValue)
                            {
                                MessageBox.Show("当前清零值不在允许范围");
                                return;
                            }
                        }
                    }
                    string msgInfo = "";
                    //九江远程清零指令 5a
                    MemoClass.writeWarnInfo(rowPointInfo.collectionCode, "ClearZero", "5a", sUserId, out msgInfo);
                    MessageBox.Show(msgInfo != "" ? msgInfo : "清零成功");
                    WriteMonitorNote(sPoint + "执行清零操作，执行" + (msgInfo != "" ? "失败" + msgInfo : "清零成功"));
                }
                if (txtWeight.Text.Contains("T"))
                {
                    if (!string.IsNullOrEmpty(txtWeight.Text.Replace("T", "")))
                    {
                        int iValue = Convert.ToInt32(txtWeight.Text.Replace("T", ""));
                        MeterBaseScaleRange mbsr = PbCacheMonitor.ltRange.Where(s => s.baseSpotNo == sPoint).FirstOrDefault();
                        if (mbsr != null)
                        {
                            if (mbsr.upperLimitClearZero < iValue * 1000 || mbsr.lowerLimitClearZero > iValue * 1000)
                            {
                                MessageBox.Show("当前清零值不在允许范围");
                                return;
                            }
                        }
                    }
                    string msgInfo = "";
                    MemoClass.writeWarnInfo(rowPointInfo.collectionCode, "ClearZero", "5a", sUserId, out msgInfo);
                    MessageBox.Show(msgInfo != "" ? msgInfo : "清零成功");
                    WriteMonitorNote(sPoint + "执行清零操作，执行" + (msgInfo != "" ? "失败" + msgInfo : "清零成功"));
                }
            }
            //*/
        }

        private void btnIpVoice_Click(object sender, EventArgs e)
        {
            //将这边的事件回发到主窗口调用
            EventArgs arg = new EventArgs();
            if (ucMonitoringEvent != null)
            {
                ucMonitoringEvent(sender, arg);
            }
        }

        #endregion button按钮事件

        #region Timer事件

        /// <summary>
        /// 记录终端是否掉线
        /// </summary>
        private int iTimeCnt = 0;

        /// <summary>
        /// 未接听超40秒未接听则挂断
        /// 已接听5分钟还未挂断则自动挂断
        /// </summary>
        private int iOverTimeClose = 0, iOverFiveTimeClose = 0;

        /// <summary>
        /// 初始载入一次数据
        /// </summary>
        private bool flagLoad = true;

        private int iCheck = 0;
        private int iHPage = 0;

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (sPointName != "" && flagLoad)
            {
                lbPntName.Text = sPointName;
                flagLoad = false;
            }

            if (rowPointInfo != null)
            {
                if (drOldData != null && rowPointInfo.lastTime == drOldData.lastTime)
                {
                    iTimeCnt++;
                    if (iTimeCnt > 30)
                    {
                        setButtonColor(bcZD, "2");//终端掉线
                        setLoadBtnColor();
                        if (iTimeCnt < 32)
                        {
                            //清理一次监控表数据
                            MeterWorkMonitor mwm = new MeterWorkMonitor
                            {
                                pointNo = sPoint,
                                setCar = "",
                                rfidCar = "",
                                photoCar = "",
                                scanCar = "",
                                editCar = "",
                                carErr = "0",
                                wgtErr = "0",
                                stopOverTime = "0",
                                msgInfo = "",
                                isTakeOver = "0",
                                userNo = "",
                                isHelp = "0",
                                wgt = 0,
                                ledWriter = ""
                            };
                            UpdateCarijegs(mwm, sPoint + "终端掉线后重置一次数据");
                        }
                        iTimeCnt = 32;
                    }
                }
                else
                {
                    iTimeCnt = 0;
                    setButtonColor(bcZD, "1");
                }
                drOldData = rowPointInfo;

                if (chkFlag)
                {
                    iCheck++;
                }
                if (iCheck > 1)
                {
                    chkFlag = false;
                    iCheck = 0;
                }

                List<LiveData> ll = MemoClass.getWarnInfo(rowPointInfo.collectionCode);
                if (ll != null)
                {
                    foreach (LiveData lv in ll)
                    {
                        string value = lv.Value == null ? "" : lv.Value.ToString().Trim();
                        switch (lv.Tagname.Replace(rowPointInfo.collectionCode, ""))
                        {
                            case "StaticStatus"://车辆检测	"0、东西方向激光均无报警；否则报警
                                setButtonColor(bcAreaWarm, ((lv.Value ?? "0") + "") == "0" ? "1" : "2");
                                break;

                            case "SwitchLight"://PLC红绿灯控制模式状态	"PLC有三种控制模式：1、自动、2、远控；3、检修
                                setButtonColor(btnTakrOver, ((lv.Value ?? "1") + "") == "1" ? "0" : "2");
                                break;

                            case "LightWest"://红绿灯：1、为绿灯；2、为红灯；"
                                setButtonColor(btnRedLight, ((lv.Value ?? "1") + "") == "1" ? "2" : "0");
                                setButtonColor(btnGreenLight, ((lv.Value ?? "1") + "") == "1" ? "0" : "2");
                                break;

                            case "ZeroWeightStatus": //0、其它，1、零点报警，红绿灯变红，
                                setButtonColor(bcZeroWarn, ((lv.Value ?? "0") + "") != "1" ? "1" : "2");
                                break;
                        }
                    }
                }

                //txtWeight.Text = rowPointInfo.wgt == null ? "0kg" : rowPointInfo.wgt.Value + "kg";
                txtWeight.Text = rowPointInfo.wgt == null ? "0T" : Math.Round((double)rowPointInfo.wgt.Value / 1000, 2) + "T";
                if (rowPointInfo.wgt == null || rowPointInfo.wgt.Value < 500)
                {
                    cbCarNo.Text = "";
                    txtCarNo.Text = "";
                }

                /*
                JArray jArray = MemoClass.TrackTable(rowPointInfo.collectionCode);
                if (jArray != null) //正常采集，若为null则重量采集线程中断了
                {
                    txtWeight.Text = jArray[3].ToString() + "kg";
                }
                //*/

                if (!chkFlag)
                {
                    chkVALID_WGT.Checked = rowPointInfo.validWgt == "1" ? false : true;
                    chkVALID_TIME_INTERVAL.Checked = rowPointInfo.validTimeInterval == "1" ? false : true;
                    chkVALID_PREDICTION_DIFF.Checked = rowPointInfo.validPredictionDiff == "1" ? false : true;
                    chkVALID_PARK_STATUS.Checked = rowPointInfo.validParkStatus == "1" ? false : true;
                    chkVALID_CARNO.Checked = rowPointInfo.validCarno == "1" ? false : true;
                    chkVALID_TARE_TIME.Checked = rowPointInfo.validTareTime == "1" ? false : true;
                    chkVALID_EXCEED_WGT.Checked = rowPointInfo.validExceedWgt == "1" ? false : true;

                    chkLED_KEEP.Checked = rowPointInfo.ledKeep == "1" ? true : false;

                    chkVALID_LIANDA.Checked= rowPointInfo.validLianda == "1" ? false : true;
                    chkVALID_MAT_CLICK.Checked = rowPointInfo.validMatClick == "1" ? false : true;
                    chkVALID_METER_AREA.Checked = rowPointInfo.validMeterArea == "1" ? false : true;
                }

                if (!string.IsNullOrEmpty(rowPointInfo.setCar) && txtCarNo.Text.Trim() == "")
                {
                    cbCarNo.Text = rowPointInfo.setCar.Substring(0, 1);
                    if (rowPointInfo.setCar.Length > 1)
                        txtCarNo.Text = rowPointInfo.setCar.Substring(1, rowPointInfo.setCar.Length - 1);
                }

                txtMsgInfo.Text = rowPointInfo.msgInfo;

                #region 换纸控制不跳闪

                if (!txtReplacePaper.Focused) //焦点在外面
                {
                    if (iHPage > 10) iHPage = 4;
                    if (iHPage > 3)
                    {
                        txtReplacePaper.Value = rowPointInfo.printNum == null ? 0 : (rowPointInfo.printNum.Value < 0 ? 0 : rowPointInfo.printNum.Value);
                    }
                    iHPage++;
                }
                else //焦点在里面
                {
                    iHPage = 0;
                }

                #endregion 换纸控制不跳闪

                txtRfidCarNo.Text = rowPointInfo.rfidCar;
                txtPhotoCarNo.Text = rowPointInfo.photoCar;
                txtScanCarNo.Text = rowPointInfo.scanCar;
                txtEditCarNo.Text = rowPointInfo.editCar;
                setButtonColor(bcCarWarm, rowPointInfo.carErr == "1" ? "2" : "1");//车号异常
                setButtonColor(bcWgtWarm, rowPointInfo.wgtErr == "1" ? "2" : "1");//重量异常
                setButtonColor(bcTimed, rowPointInfo.stopOverTime == "1" ? "2" : "1");//停留超时

                if (rowPointInfo.isHelp == "1") //0未呼叫，1呼叫待接听，2呼叫已接听
                {
                    MeterWorkMonitor mwm = new MeterWorkMonitor();
                    mwm.pointNo = sPoint;

                    iOverTimeClose++;
                    iOverFiveTimeClose = 0;
                    setButtonColor(bcHelpWarm, "2");//现场求助
                    setButtonColor(bcIpVoice, "2");//IP语音

                    //==============================================
                    openMsg(sPointName);//回调主界面方法
                    //==============================================

                    if (iOverTimeClose > 40)
                    {
                        mwm.isHelp = "0";
                        if (rowPointInfo.isTakeOver == "1")
                        {
                            mwm.isTakeOver = "0";
                        }
                        UpdateCarijegs(mwm, sPoint + "呼叫超40秒自动挂断");
                    }
                }
                else if (rowPointInfo.isHelp == "2")
                {
                    iOverFiveTimeClose++;
                    //setButtonColor(bcHelpWarm, "3");//现场求助
                    setButtonColor(bcIpVoice, "3");//IP语音

                    if (iOverFiveTimeClose > 300)
                    {
                        UpdateCarijegs(new MeterWorkMonitor { pointNo = sPoint, isHelp = "0" }, sPoint + "通话超5分钟自动挂断");
                    }
                }
                else
                {
                    iOverTimeClose = 0;
                    iOverFiveTimeClose = 0;
                    setButtonColor(bcHelpWarm, "1");//现场求助
                    setButtonColor(bcIpVoice, "1");//IP语音
                }

                if (rowPointInfo.isTakeOver == "0")
                {
                    setButtonColor(bcAutoState, "3");//终端计量
                    setButtonColor(bcYcStatWarm, "1");//远程计量
                    setButtonColor(btnYc, "0");
                    btnYc.Text = "远程计量";
                    //setButtonColor(btnPW, "0");
                }
                else if (rowPointInfo.isTakeOver == "1" || rowPointInfo.isTakeOver == "2")
                {
                    //setButtonColor(btnPW, "2");
                    if (string.IsNullOrEmpty(rowPointInfo.userNo))
                    {
                        setButtonColor(bcAutoState, "3");//终端计量
                        setButtonColor(bcYcStatWarm, "1");//远程计量
                    }
                    else
                    {
                        setButtonColor(bcAutoState, "1");//终端计量
                        setButtonColor(bcYcStatWarm, "3");//远程计量
                    }
                    setButtonColor(btnYc, "2");
                    btnYc.Text = "智能计量";
                }
                /*
                else if (rowPointInfo.isTakeOver == "2")
                {
                    setButtonColor(bcAutoState, "1");//终端计量
                    setButtonColor(bcYcStatWarm, "3");//远程计量
                    setButtonColor(btnYc, "2");
                    //setButtonColor(btnPW, "0");
                }
                //*/
                else
                {
                    setButtonColor(bcAutoState, "1");//终端计量
                    setButtonColor(bcYcStatWarm, "1");//远程计量
                    setButtonColor(btnYc, "0");
                    btnYc.Text = "远程计量";
                    //setButtonColor(btnPW, "0");
                }
            }
        }

        private void setLoadBtnColor()
        {
            bcZeroWarn.BackColor = Color.Green;
            bcWgtWarn.BackColor = Color.Green;

            foreach (Control cn in groupBox3.Controls)
            {
                if (cn.Name.Contains("bc"))
                {
                    if (cn.Name != "bcZD")
                    {
                        cn.BackColor = Color.Green;
                    }
                }
            }

            /*
            btnIpVoice.BackColor = Color.DodgerBlue;
            btnRedLight.BackColor = Color.DodgerBlue;
            btnGreenLight.BackColor = Color.DodgerBlue;
            //*/
        }

        /// <summary>
        /// 按钮颜色设置
        /// </summary>
        /// <param name="button">按钮</param>
        /// <param name="sColor">0：DodgerBlue 1：Green  2：Red</param>
        private void setButtonColor(Button button, string sColor)
        {
            switch (sColor)
            {
                case "0":
                    button.BackColor = Color.DodgerBlue;
                    break;

                case "1":
                    button.BackColor = Color.Green;
                    break;

                case "2":
                    button.BackColor = Color.Red;
                    break;

                case "3":
                    button.BackColor = Color.Orange;
                    break;
            }
        }

        #endregion Timer事件

        /// <summary>
        /// LED发送
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSend_Click(object sender, EventArgs e)
        {
            UpdateCarijeg(new MeterWorkMonitor { pointNo = sPoint, ledWriter = txtLed.Text.Trim() }, "写入LED信息：" + txtLed.Text.Trim());
        }

        /// <summary>
        /// 换纸
        /// </summary>
        private void btnReplacePaper_Click(object sender, EventArgs e)
        {
            UpdateCarijeg(new MeterWorkMonitor { pointNo = sPoint, printNum = Convert.ToInt32(txtReplacePaper.Value) }, "换纸：" + txtReplacePaper.Value);
        }

        private void UpdateCarijeg(MeterWorkMonitor monitor, string content)
        {
            if (DialogResult.Yes == MessageBox.Show("确实要进行该操作吗？", "提示", MessageBoxButtons.YesNo))
            {
                RESTfulResult<string> rm = monitorService.doUpdateWf(monitor);
                if (rm.Succeed)
                {
                    WriteMonitorNote(content);
                    MessageBox.Show("操作成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else
                {
                    MessageBox.Show("操作失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
            }
        }

        private void UpdateCarijegs(MeterWorkMonitor monitor, string content)
        {
            RESTfulResult<string> rm = monitorService.doUpdateWf(monitor);
            if (rm.Succeed)
            {
                WriteMonitorNote(content);
            }
            else
            {
                lg.WriteLog(4, "修改异常：" + content);
            }
        }

        private void btnTakrOver_Click(object sender, EventArgs e)
        {
            string strError = "";
            string sTagName = sPoint.Replace("CAR", "HMI");

            string sValue = "2";
            if (btnTakrOver.BackColor == Color.Red)
            {
                sValue = "1";
            }
            //切换为远程控制
            if (MemoClass.writeWarnInfo(rowPointInfo.collectionCode, "SwitchLight", sValue, sUserId, out strError))
            {
                WriteMonitorNote(sPoint + "设置远程接管");
            }
        }

        private void ucCarMonitoring_Load(object sender, EventArgs e)
        {
            MemoClass = new MemoryTableDataSocket(strCollectNo);
        }

        private void btnPW_Click(object sender, EventArgs e)
        {
            /*
            if (btnYc.BackColor != Color.Red)
            {
                if (btnPW.BackColor == Color.DodgerBlue)
                {
                    UpdateCarijeg(new MeterWorkMonitor { pointNo = sPoint, isTakeOver = "1" }, "进行派位处理");
                    btnPW.BackColor = Color.Red;
                }
                else
                {
                    UpdateCarijeg(new MeterWorkMonitor { pointNo = sPoint, isTakeOver = "0" }, "取消派位处理");
                    btnPW.BackColor = Color.DodgerBlue;
                }
            }
            else
            {
                MessageBox.Show("请先释放远程终端接管");
            }
            //*/
        }

        private void btnRedLight_Click(object sender, EventArgs e)
        {
            string strError = "";
            string sTagName = sPoint.Replace("CAR", "HMI");

            //红灯
            if (MemoClass.writeWarnInfo(rowPointInfo.collectionCode, "LightWest", "1", sUserId, out strError) && MemoClass.writeWarnInfo(rowPointInfo.collectionCode, "LightEast", "1", sUserId, out strError))
            {
                WriteMonitorNote(sPoint + "设置红绿灯为红灯");
            }
        }

        private void btnGreenLight_Click(object sender, EventArgs e)
        {
            string strError = "";
            string sTagName = sPoint.Replace("CAR", "HMI");

            //绿灯
            if (MemoClass.writeWarnInfo(rowPointInfo.collectionCode, "LightWest", "2", sUserId, out strError) && MemoClass.writeWarnInfo(rowPointInfo.collectionCode, "LightEast", "2", sUserId, out strError))
            {
                WriteMonitorNote(sPoint + "设置红绿灯为绿灯");
            }
        }

        private void WriteMonitorNote(string content)
        {
            RESTfulResult<string> rm = noteService.doAddWf(new MeterMonitorNote
            {
                baseSpotNo = sPoint,
                baseSpotName = sPointName,
                operationContent = content,//str + chk.Text,
                carNo = cbCarNo.Text.Trim() + txtRfidCarNo.Text.Trim(),
                meterManNo = sUserId,
                meterManName = sName,
                meterNoteSource = "2"
            });
            if (!rm.Succeed)
            {
                lg.WriteLog(4, "写入操作日志异常：" + content);
            }
        }

        /// <summary>
        /// 车号重置
        /// </summary>
        private void btnCarSet_Click(object sender, EventArgs e)
        {
            UpdateCarijeg(new MeterWorkMonitor { pointNo = sPoint, setCar = cbCarNo.Text + txtCarNo.Text.Trim() }, "重置车号为：" + cbCarNo.Text.Trim() + txtCarNo.Text.Trim());
        }
    }
}