Newer
Older
RbFreqStand / RbFreqStandMeasure / home / HomeCtrlForm.cs
yxw on 1 Jun 2021 39 KB 20210601合并测试
using Casic.Birmm.RbFreqStandMeasure.home;
using Casic.Birmm.RbFreqStandMeasure.R_DataBase.Dto;
using Casic.Birmm.RbFreqStandMeasure.R_DataBase.Model;
using Casic.Birmm.RbFreqStandMeasure.R_DataBase.Service;
using Casic.Birmm.RbFreqStandMeasure.R_DataBase.Service.Impl;
using Casic.Birmm.RbFreqStandMeasure.tools;
using Casic.Birmm.RbFreqStandMeasure.Tools;
using DevComponents.DotNetBar.Controls;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.IO.Ports;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Timers;
using System.Windows.Forms;

namespace Casic.Birmm.RbFreqStandMeasure
{
    public partial class HomeCtrlForm : UserControl
    {
        public static HomeCtrlForm homeCtrlForm;
        public int totalCount = 0;
        public int currentPage = 1;
        public int pageCount = 0;
        public int limitCount = 4;
        DataTable devToBeTestedTable = null;
        DataTable channelsTable = null;
        DeviceService deviceService = new DeviceServiceImpl();
        List<DeviceView> listChannelStatus = new List<DeviceView>();
        DetectionItemService detectionItemService = new DetectionItemServiceImpl();
        public static Hashtable stoppedItemIdTable = new Hashtable();
        public static List<string> channelFreeList = new List<string>();
        private readonly object obj = new object();

        #region 样式常量定影
        private readonly Color titleBackColor = Color.FromArgb(63, 132, 215); // #3F84D7
        private readonly Font titleFont = new Font("微软雅黑", 14F, FontStyle.Regular, GraphicsUnit.Pixel, 134);
        #endregion
        
        public HomeCtrlForm()
        {
            InitializeComponent();
            homeCtrlForm = this;


            // 设置双缓冲
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);

            // 跨线程访问控件
            CheckForIllegalCrossThreadCalls = false;

            StatusCtrlForm statusForm = new StatusCtrlForm();
            if (!FreshStatus.isStarted)
            {
                // 开始获取原子钟状态的timer
                FreshStatus.startClockFresh();
            }
            // 开始获取卫星数据
            StatusCtrlForm.statusCtrlForm.timer1.Start();

            lock (obj)
            {
               
                label_clockStatus.Text = FreshStatus.clockStatus;
                label_receiverStatus.Text = StatusCtrlForm.receiverStatus;
            }
            

        }

        private void HomeCtrlForm_Load(object sender, EventArgs e)
        {
            // 初始化表格标题栏
            InitTableDevList();

            // 加载待检测列表
            LoadDevToBeTested();

            // 初始化各通道样式
            InitTableChannel();
            LoadChannelStatus();
        }

        #region 待测仪器列表
        private void InitTableDevList()
        {
            tableToBeTested.Columns.Clear();
            tableToBeTested.Rows.Clear();

            // 添加标题栏
            Panel tableHeader = new Panel
            {
                BackColor = Color.White,
                Size = new Size(764, 32),
                Location = new Point(0, 0)
            };
            tableHeader.BackColor = titleBackColor;
            tableToBeTested.Controls.Add(tableHeader);

            // 仪器名称
            Label colDevName = new Label
            {
                Font = titleFont,
                ForeColor = Color.White,
                TextAlign = ContentAlignment.MiddleCenter,
                BackColor = titleBackColor,
                AutoSize = false,
                Text = "仪器名称",
                Location = new Point(20, 0),
                Size = new Size(100, 32)
            };
            tableToBeTested.Controls.Add(colDevName);
            colDevName.BringToFront();

            // 仪器类型
            Label colDevType = new Label
            {
                Font = titleFont,
                ForeColor = Color.White,
                TextAlign = ContentAlignment.MiddleCenter,
                BackColor = titleBackColor,
                AutoSize = false,
                Text = "仪器类型",
                Location = new Point(160, 0),
                Size = new Size(100, 32)
            };
            tableToBeTested.Controls.Add(colDevType);
            colDevType.BringToFront();

            // 仪器编号
            Label colDevNo = new Label
            {
                Font = titleFont,
                ForeColor = Color.White,
                TextAlign = ContentAlignment.MiddleCenter,
                BackColor = titleBackColor,
                AutoSize = false,
                Text = "仪器编号",
                Location = new Point(300, 0),
                Size = new Size(100, 32)
            };
            tableToBeTested.Controls.Add(colDevNo);
            colDevNo.BringToFront();

            // 客户名称
            Label colCustomName = new Label
            {
                Font = titleFont,
                ForeColor = Color.White,
                TextAlign = ContentAlignment.MiddleCenter,
                BackColor = titleBackColor,
                AutoSize = false,
                Text = "联系人",
                Location = new Point(444, 0),
                Size = new Size(100, 32)
            };
            tableToBeTested.Controls.Add(colCustomName);
            colCustomName.BringToFront();

            // 客户单位
            Label colCustomComp = new Label
            {
                Font = titleFont,
                ForeColor = Color.White,
                TextAlign = ContentAlignment.MiddleCenter,
                BackColor = titleBackColor,
                AutoSize = false,
                Text = "送检单位",
                Location = new Point(602, 0),
                Size = new Size(120, 32)
            };
            tableToBeTested.Controls.Add(colCustomComp);
            colCustomComp.BringToFront();                       

            totalCount = 0;
            currentPage = 1;
            pageCount = 0;
            limitCount = 4;
            devToBeTestedTable = new DataTable();
            devToBeTestedTable.Columns.Add("id", Type.GetType("System.String"));
            devToBeTestedTable.Columns.Add("devName", Type.GetType("System.String"));
            devToBeTestedTable.Columns.Add("devTypeName", Type.GetType("System.String"));
            devToBeTestedTable.Columns.Add("devCode", Type.GetType("System.String"));
            devToBeTestedTable.Columns.Add("customerName", Type.GetType("System.String"));
            devToBeTestedTable.Columns.Add("customerDev", Type.GetType("System.String"));
        }
        public void LoadDevToBeTested()
        {
            devToBeTestedTable.Rows.Clear();
            // 获取数据
            // 获取待检测设备的总条数
            totalCount = deviceService.getTotalCount("", "", "", "", "", "1");

            // 获取当前页的数据
            List<DeviceDto> queryList = deviceService.searchPage("", "", "", "", "", "1", currentPage, limitCount);
            if (null != queryList && queryList.Count > 0)
            {
                // 重新计算页码数据
                pageCount = totalCount / limitCount;
                int ys = totalCount % limitCount;
                if (ys != 0)
                    pageCount++;
                setPageLabel();

                foreach (DeviceDto device in queryList)
                {
                    devToBeTestedTable.Rows.Add(device.Id, device.DevName, device.DevTypeName, device.DevCode, device.CustomerName, device.CustomerDev);                    
                }
                //tableToBeTested.Columns[0].Visible = false;
                //tableToBeTested.Columns[0].Visible = false;

                tableToBeTested.Visible = true;
                labelNodata.Visible = false;

                tableToBeTested.DataSource = devToBeTestedTable;

                tableToBeTested.Columns[0].Visible = false;
                // width=984px
                tableToBeTested.Columns[1].Width = 140;
                tableToBeTested.Columns[2].Width = 140;
                tableToBeTested.Columns[3].Width = 140;
                tableToBeTested.Columns[4].Width = 140;
                tableToBeTested.Columns[5].Width = 200;

                tableToBeTested.Columns[0].ReadOnly = true;
                tableToBeTested.Columns[1].ReadOnly = true;
                tableToBeTested.Columns[2].ReadOnly = true;
                tableToBeTested.Columns[3].ReadOnly = true;
                tableToBeTested.Columns[4].ReadOnly = true;
                tableToBeTested.Columns[5].ReadOnly = true;


            }
            else
            {
                tableToBeTested.Visible = false;
                labelNodata.Visible = true;
            }

        }

        private void tableToBeTested_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            int rowIndex = tableToBeTested.CurrentCell.RowIndex;
            int colIndex = tableToBeTested.CurrentCell.ColumnIndex;


            SetDevTestDlg devTestDlg = new SetDevTestDlg();
            devTestDlg.deviceId = Convert.ToInt32(tableToBeTested.Rows[rowIndex].Cells[0].Value);
            devTestDlg.text_customerDev.Text = tableToBeTested.Rows[rowIndex].Cells[5].Value.ToString();
            devTestDlg.text_devName.Text = tableToBeTested.Rows[rowIndex].Cells[1].Value.ToString();
            devTestDlg.text_devCode.Text = tableToBeTested.Rows[rowIndex].Cells[3].Value.ToString();
            devTestDlg.text_customerName.Text = tableToBeTested.Rows[rowIndex].Cells[4].Value.ToString();
            devTestDlg.text_devType.Text = tableToBeTested.Rows[rowIndex].Cells[2].Value.ToString();
            
            ((ComboBox)devTestDlg.Controls.Find("comboBox_channelNo", true)[0]).DataSource = channelFreeList;
            if (channelFreeList.Count > 0)
            {
                devTestDlg.Controls.Find("groupBox2", true)[0].Enabled = true;
                devTestDlg.Controls.Find("btnSave", true)[0].Enabled = true;
                devTestDlg.Controls.Find("timePicker_startTime", true)[0].Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            }
            else
            {
                ((TextBoxX)devTestDlg.Controls.Find("text_channelNo", true)[0]).WatermarkText = "无空闲通道";
            }
           
            devTestDlg.HideMaskAction += () =>
            {
                this.HideMask();
            };
            this.ShowMask();
            devTestDlg.StartPosition = FormStartPosition.CenterParent; // 指定窗口弹出在父窗口的中间位置
            devTestDlg.ShowDialog();

        }

        private void setPageLabel()
        {
            label_pageInfo.Text = "共" + totalCount + "条,每页" + limitCount + "条,共" + pageCount + "页";
            textBoxPage.Text = currentPage.ToString();
        }

        private void btnPre_Click(object sender, EventArgs e)
        {
            if (Convert.ToInt16(textBoxPage.Text) > 1)
            {
                currentPage = Convert.ToInt16(textBoxPage.Text) - 1;
                LoadDevToBeTested();
            }
        }

        private void btnNext_Click(object sender, EventArgs e)
        {
            if (Convert.ToInt16(textBoxPage.Text) < pageCount)
            {
                currentPage = Convert.ToInt16(textBoxPage.Text) + 1;
                LoadDevToBeTested();
            }
        }
        #endregion



        #region 通道列表

        private void InitTableChannel()
        {
            try
            {
                lock (obj)
                {
                    dataGridView_Channel.Columns.Clear();
                    dataGridView_Channel.Rows.Clear();

                    // 添加标题栏
                    Panel tableHeader = new Panel
                    {
                        BackColor = Color.White,
                        Size = new Size(984, 30),
                        Location = new Point(0, 0)
                    };
                    tableHeader.BackColor = titleBackColor;
                    dataGridView_Channel.Controls.Add(tableHeader);

                    // 通道
                    Label colChannelNo = new Label
                    {
                        Font = titleFont,
                        ForeColor = Color.White,
                        TextAlign = ContentAlignment.MiddleCenter,
                        BackColor = titleBackColor,
                        AutoSize = false,
                        Text = "通道",
                        Location = new Point(0, 0),
                        Size = new Size(70, 30)
                    };
                    dataGridView_Channel.Controls.Add(colChannelNo);
                    colChannelNo.BringToFront();

                    // 仪器名称
                    Label colDevName = new Label
                    {
                        Font = titleFont,
                        ForeColor = Color.White,
                        TextAlign = ContentAlignment.MiddleCenter,
                        BackColor = titleBackColor,
                        AutoSize = false,
                        Text = "仪器名称",
                        Location = new Point(70, 0),
                        Size = new Size(110, 30)
                    };
                    dataGridView_Channel.Controls.Add(colDevName);
                    colDevName.BringToFront();

                    // 仪器编号
                    Label colDevNo = new Label
                    {
                        Font = titleFont,
                        ForeColor = Color.White,
                        TextAlign = ContentAlignment.MiddleCenter,
                        BackColor = titleBackColor,
                        AutoSize = false,
                        Text = "仪器编号",
                        Location = new Point(180, 0),
                        Size = new Size(120, 30)
                    };
                    dataGridView_Channel.Controls.Add(colDevNo);
                    colDevNo.BringToFront();

                    // 客户名称
                    Label colCustomName = new Label
                    {
                        Font = titleFont,
                        ForeColor = Color.White,
                        TextAlign = ContentAlignment.MiddleCenter,
                        BackColor = titleBackColor,
                        AutoSize = false,
                        Text = "送检单位",
                        Location = new Point(300, 0),
                        Size = new Size(120, 30)
                    };
                    dataGridView_Channel.Controls.Add(colCustomName);
                    colCustomName.BringToFront();

                    // 开始时间
                    Label colStartTime = new Label
                    {
                        Font = titleFont,
                        ForeColor = Color.White,
                        TextAlign = ContentAlignment.MiddleCenter,
                        BackColor = titleBackColor,
                        AutoSize = false,
                        Text = "开始时间",
                        Location = new Point(420, 0),
                        Size = new Size(100, 30)
                    };
                    dataGridView_Channel.Controls.Add(colStartTime);
                    colStartTime.BringToFront();

                    // 结束时间
                    Label colEndTime = new Label
                    {
                        Font = titleFont,
                        ForeColor = Color.White,
                        TextAlign = ContentAlignment.MiddleCenter,
                        BackColor = titleBackColor,
                        AutoSize = false,
                        Text = "结束时间",
                        Location = new Point(520, 0),
                        Size = new Size(100, 30)
                    };
                    dataGridView_Channel.Controls.Add(colEndTime);
                    colEndTime.BringToFront();

                    // 状态
                    Label colStatus = new Label
                    {
                        Font = titleFont,
                        ForeColor = Color.White,
                        TextAlign = ContentAlignment.MiddleCenter,
                        BackColor = titleBackColor,
                        AutoSize = false,
                        Text = "状态",
                        Location = new Point(620, 0),
                        Size = new Size(64, 30)
                    };
                    dataGridView_Channel.Controls.Add(colStatus);
                    colStatus.BringToFront();

                    // 频率稳定度
                    Label colStablility = new Label
                    {
                        Font = titleFont,
                        ForeColor = Color.White,
                        TextAlign = ContentAlignment.MiddleCenter,
                        BackColor = titleBackColor,
                        AutoSize = false,
                        Text = "稳定度",

                        Location = new Point(684, 0),
                        Size = new Size(75, 30)
                    };
                    dataGridView_Channel.Controls.Add(colStablility);
                    colStablility.BringToFront();

                    // 频率准确度
                    Label colAccuracy = new Label
                    {
                        Font = titleFont,
                        ForeColor = Color.White,
                        TextAlign = ContentAlignment.MiddleCenter,
                        BackColor = titleBackColor,
                        AutoSize = false,
                        Text = "准确度",
                        Location = new Point(754, 0),
                        Size = new Size(75, 30)
                    };
                    dataGridView_Channel.Controls.Add(colAccuracy);
                    colAccuracy.BringToFront();

                    // 开机特性
                    Label colStartup = new Label
                    {
                        Font = titleFont,
                        ForeColor = Color.White,
                        TextAlign = ContentAlignment.MiddleCenter,
                        BackColor = titleBackColor,
                        AutoSize = false,
                        Text = "开机特性",

                        Location = new Point(824, 0),

                        Size = new Size(75, 30)
                    };
                    dataGridView_Channel.Controls.Add(colStartup);
                    colStartup.BringToFront();

                    // 日老化率
                    Label colAgingRate = new Label
                    {
                        Font = titleFont,
                        ForeColor = Color.White,
                        TextAlign = ContentAlignment.MiddleCenter,
                        BackColor = titleBackColor,
                        AutoSize = false,
                        Text = "日老化率",
                        Location = new Point(899, 0),
                        Size = new Size(75, 30)
                    };


                    dataGridView_Channel.Controls.Add(colAgingRate);
                    colAgingRate.BringToFront();
                }


               

                
            }
            catch (Exception ex)
            {
                LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "InitTableChannel 错误:" + ex.Message);

            }
        }

        public void refreshChannelList()
        {
            try
            {
                lock (obj)
                {
                   // lock (channelFreeList)
                    {
                        channelFreeList.Clear();
                        channelFreeList.Add("1");
                        channelFreeList.Add("2");
                        channelFreeList.Add("3");
                        channelFreeList.Add("4");
                        channelFreeList.Add("5");

                        listChannelStatus = deviceService.getDeviceByChannel();
                        if (listChannelStatus != null && listChannelStatus.Count > 0)
                        {
                            foreach (DeviceView device in listChannelStatus)
                            {
                                channelFreeList.Remove(device.Channel);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "refreshChannelList 错误:" + ex.Message);

            }
        }
        public void LoadChannelStatus()
        {
            try
            {
                //Invoke(new MethodInvoker(delegate ()
                {
                    lock (obj)
                    {
                        //lock(channelFreeList)
                        {
                            channelsTable = new DataTable();

                            channelsTable.Columns.Add("channelNo", Type.GetType("System.String"));
                            channelsTable.Columns.Add("devName", Type.GetType("System.String"));
                            channelsTable.Columns.Add("devCode", Type.GetType("System.String"));
                            channelsTable.Columns.Add("customComp", Type.GetType("System.String"));
                            channelsTable.Columns.Add("startTime", Type.GetType("System.String"));
                            channelsTable.Columns.Add("endTime", Type.GetType("System.String"));
                            channelsTable.Columns.Add("channelStatus", Type.GetType("System.String"));
                            channelsTable.Columns.Add("stablility", Type.GetType("System.String"));
                            channelsTable.Columns.Add("accuracy", Type.GetType("System.String"));
                            channelsTable.Columns.Add("startup", Type.GetType("System.String"));
                            channelsTable.Columns.Add("agingRate", Type.GetType("System.String"));
                            channelsTable.Columns.Add("deviceId", Type.GetType("System.Int64"));
                            channelsTable.Columns.Add("deviceItemId", Type.GetType("System.Int64"));

                            listChannelStatus = deviceService.getDeviceByChannel();


                            channelsTable.Rows.Add(channelsTable.NewRow());
                            channelsTable.Rows.Add(channelsTable.NewRow());
                            channelsTable.Rows.Add(channelsTable.NewRow());
                            channelsTable.Rows.Add(channelsTable.NewRow());
                            channelsTable.Rows.Add(channelsTable.NewRow());
                            channelFreeList.Clear();
                            channelFreeList.Add("1");
                            channelFreeList.Add("2");
                            channelFreeList.Add("3");
                            channelFreeList.Add("4");
                            channelFreeList.Add("5");

                            if (listChannelStatus != null && listChannelStatus.Count > 0)
                            {  
                                foreach (DeviceView device in listChannelStatus)
                                {
                                    if (String.IsNullOrEmpty(device.Channel)) continue;
                                    channelFreeList.Remove(device.Channel);
                                    int index = Convert.ToInt32(device.Channel) - 1;
                                    channelsTable.Rows[index]["channelNo"] = device.Channel;
                                    channelsTable.Rows[index]["devName"] = device.DevName;
                                    channelsTable.Rows[index]["devCode"] = device.DevCode;
                                    channelsTable.Rows[index]["customComp"] = device.CustomerDev;
                                    channelsTable.Rows[index]["startTime"] = device.StartTime;
                                    channelsTable.Rows[index]["endTime"] = device.EndTime;
                                    channelsTable.Rows[index]["channelStatus"] = "占用";
                                    channelsTable.Rows[index]["deviceId"] = device.Id;
                                    channelsTable.Rows[index]["deviceItemId"] = device.DetectionItemId;

                                    if (device.Stability.Equals("-3")) this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line;
                                    else if (device.Stability.Equals("-2")) this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray;
                                    else if (device.Stability.Equals("-1")) this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange;
                                    else this.Controls.Find("pic_stability_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green;

                                    if (device.Accuracy.Equals("-3")) this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line;
                                    else if (device.Accuracy.Equals("-2")) this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray;
                                    else if (device.Accuracy.Equals("-1")) this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange;
                                    else this.Controls.Find("pic_accuracy_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green;

                                    if (device.AgeRate.Equals("-3")) this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line;
                                    else if (device.AgeRate.Equals("-2")) this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray;
                                    else if (device.AgeRate.Equals("-1")) this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange;
                                    else this.Controls.Find("pic_ageRate_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green;

                                    if (device.BootFeature.Equals("-3")) this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.line;
                                    else if (device.BootFeature.Equals("-2")) this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_gray;
                                    else if (device.BootFeature.Equals("-1")) this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_orange;
                                    else this.Controls.Find("pic_bootFeature_" + device.Channel, true)[0].BackgroundImage = Properties.Resources.dot_green;


                                }
                            }
                            else
                            {
                                channelsTable.Rows.Clear();
                                channelsTable.Rows.Add("1", "", "", "", "", "", "空闲", "", "");
                                channelsTable.Rows.Add("2", "", "", "", "", "", "空闲", "", "");
                                channelsTable.Rows.Add("3", "", "", "", "", "", "空闲", "", "");
                                channelsTable.Rows.Add("4", "", "", "", "", "", "空闲", "", "");
                                channelsTable.Rows.Add("5", "", "", "", "", "", "空闲", "", "");
                            }

                            foreach (string no in channelFreeList)
                            {
                                channelsTable.Rows[Convert.ToInt32(no) - 1]["channelNo"] = no;
                                channelsTable.Rows[Convert.ToInt32(no) - 1]["channelStatus"] = "空闲";
                            }


                            dataGridView_Channel.DataSource = channelsTable;

                            // width=764px
                            dataGridView_Channel.Columns[11].Visible = false;
                            dataGridView_Channel.Columns[12].Visible = false;
                            dataGridView_Channel.Columns[0].Width = 70;
                            dataGridView_Channel.Columns[1].Width = 110;
                            dataGridView_Channel.Columns[2].Width = 120;
                            dataGridView_Channel.Columns[3].Width = 120;
                            dataGridView_Channel.Columns[4].Width = 100; //starttime
                            dataGridView_Channel.Columns[5].Width = 100; //endtime
                            dataGridView_Channel.Columns[6].Width = 64;
                            dataGridView_Channel.Columns[7].Width = 75;
                            dataGridView_Channel.Columns[8].Width = 75;
                            dataGridView_Channel.Columns[9].Width = 75;
                            dataGridView_Channel.Columns[10].Width = 75;

                            dataGridView_Channel.Columns[0].ReadOnly = true;
                            dataGridView_Channel.Columns[1].ReadOnly = true;
                            dataGridView_Channel.Columns[2].ReadOnly = true;
                            dataGridView_Channel.Columns[3].ReadOnly = true;
                            dataGridView_Channel.Columns[4].ReadOnly = true;
                            dataGridView_Channel.Columns[5].ReadOnly = true;
                            dataGridView_Channel.Columns[6].ReadOnly = true;
                            dataGridView_Channel.Columns[7].ReadOnly = true;
                            dataGridView_Channel.Columns[8].ReadOnly = true;
                            dataGridView_Channel.Columns[9].ReadOnly = true;
                            dataGridView_Channel.Columns[10].ReadOnly = true;
                        }
                    }
                    //}));
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "LoadChannelStatus 错误:" + ex.Message);

            }
        }

        private void dataGridView_Channel_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            try
            {
                lock (obj)
                {
                    LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "11111111");

                    dataGridView_Channel.ClearSelection();

                    LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "222222");
                    int channelNo = e.RowIndex + 1;

                    LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "333333");
                    if (channelFreeList.Contains(channelNo + ""))
                    {

                        LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "44444");
                        dataGridView_Channel.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.FromArgb(232, 234, 238);
                        panel_channelList.Controls.Find("panel" + channelNo, true)[0].Visible = false;

                        LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "5555555555");
                    }
                    else
                    {

                        LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "66666666666");
                        dataGridView_Channel.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.FromArgb(201, 203, 208);
                        panel_channelList.Controls.Find("panel" + channelNo, true)[0].Visible = true;

                        LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "777777777");
                    }
                    foreach (string no in channelFreeList.ToArray())
                    {
                        dataGridView_Channel.Rows[Convert.ToInt32(no) - 1].DefaultCellStyle.BackColor = Color.FromArgb(232, 234, 238);
                        panel_channelList.Controls.Find("panel" + no, true)[0].Visible = false;
                    }

                    LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "88888888");
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "dataGridView_Channel_RowPostPaint 错误:" + ex.Message);

            }
        }


        private void dataGridView_Channel_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            
            cellDoubleClick(e.RowIndex);
        }

        #endregion

        private MaskForm maskForm;

        private void ShowMask()
        {
            maskForm = new MaskForm(this.Parent.Parent.Location, this.Parent.Parent.Size);
            maskForm.Show();
        }

        private void HideMask()
        {
            if (maskForm != null)
            {
                maskForm.Close();
            }
        }

        private void panel1_DoubleClick(object sender, EventArgs e)
        {
            cellDoubleClick(0);
        }

        private void panel2_DoubleClick(object sender, EventArgs e)
        {
            cellDoubleClick(1);
        }

        private void panel3_DoubleClick(object sender, EventArgs e)
        {
            cellDoubleClick(2);
        }

        private void panel4_DoubleClick(object sender, EventArgs e)
        {
            cellDoubleClick(3);
        }
        private void panel5_DoubleClick(object sender, EventArgs e)
        {
            cellDoubleClick(4);
        }

        private void cellDoubleClick(int rowIndex)
        {
            if (dataGridView_Channel.Rows[rowIndex].Cells[6].Value.ToString().Equals("占用"))
            {
                if (MessageBox.Show("该通道有正在检测的仪器,确定要停止检测?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
                    == DialogResult.Yes)
                {
                    try
                    {
                        long deviceId = (long)dataGridView_Channel.Rows[rowIndex].Cells[11].Value;
                        long deviceItemId = (long)dataGridView_Channel.Rows[rowIndex].Cells[12].Value;
                        string startTime = "";
                        string endTime = "";
                        if (dataGridView_Channel.Rows[rowIndex].Cells[4].Value != null)
                        { startTime = dataGridView_Channel.Rows[rowIndex].Cells[4].Value.ToString(); }
                        if (dataGridView_Channel.Rows[rowIndex].Cells[5].Value != null)
                        { endTime = dataGridView_Channel.Rows[rowIndex].Cells[5].Value.ToString(); }
                        if (startTime.Equals("") && endTime.Equals(""))
                        {
                            return;
                        }
                        
                        DialogResult dialogResult = MessageBox.Show("是否保存此次检测的数据?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                        if (dialogResult == DialogResult.Yes)
                        {
                            detectionItemService.stopDetection(deviceId, deviceItemId, startTime, endTime, false);                           
                        }
                        else
                        {
                            detectionItemService.stopDetection(deviceId, deviceItemId, startTime, endTime, true);
                        }

                        if (stoppedItemIdTable.Contains(rowIndex + 1)) stoppedItemIdTable.Remove(rowIndex + 1);

                        stoppedItemIdTable.Add(rowIndex + 1, deviceItemId);
                        LoadChannelStatus();
                        currentPage = 1;
                        LoadDevToBeTested();
                    }
                    catch(Exception ex)
                    {
                        LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "cellDoubleClick 错误:" + ex.Message);
                    }
                    return;
                }
                else
                {
                    return;
                }
            }
            SetDevChannelDlg channelDlg = new SetDevChannelDlg(rowIndex + 1);
            //channelDlg.deviceId = Convert.ToInt32(dataGridView_Channel.Rows[rowIndex].Cells[11].Value);
            //channelDlg.text_devCode.Text = dataGridView_Channel.Rows[rowIndex].Cells[2].Value.ToString();
            //channelDlg.text_devName.Text = dataGridView_Channel.Rows[rowIndex].Cells[1].Value.ToString();
            //channelDlg.text_devType.Text = dataGridView_Channel.Rows[rowIndex].Cells[12].Value.ToString();
            //channelDlg.text_devModel.Text = dataGridView_Channel.Rows[rowIndex].Cells[13].Value.ToString();
            //channelDlg.text_customerDev.Text = dataGridView_Channel.Rows[rowIndex].Cells[14].Value.ToString();
            //channelDlg.text_customerName.Text = dataGridView_Channel.Rows[rowIndex].Cells[3].Value.ToString();
            channelDlg.HideMaskAction += () =>
            {
                this.HideMask();
            };
            this.ShowMask();
            channelDlg.StartPosition = FormStartPosition.CenterParent; // 指定窗口弹出在父窗口的中间位置
            channelDlg.ShowDialog();
        }

        private void dataGridView_Channel_CellDoubleClick_1(object sender, DataGridViewCellEventArgs e)
        {
            cellDoubleClick(e.RowIndex);
        }

        private void dataGridView_Channel_RowPostPaint_1(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            try
            {
                lock (obj)
                {                   
                    dataGridView_Channel.ClearSelection();

                    int channelNo = e.RowIndex + 1;

                    if (channelFreeList.Contains(channelNo + ""))
                    {
                         dataGridView_Channel.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.FromArgb(232, 234, 238);
                        panel_channelList.Controls.Find("panel" + channelNo, true)[0].Visible = false;

                        //LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "5555555555");
                    }
                    else
                    {

                        //LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "66666666666");
                        dataGridView_Channel.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.FromArgb(201, 203, 208);
                        panel_channelList.Controls.Find("panel" + channelNo, true)[0].Visible = true;

                        //LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "777777777");
                    }
                    foreach (string no in channelFreeList.ToArray())
                    {
                        dataGridView_Channel.Rows[Convert.ToInt32(no) - 1].DefaultCellStyle.BackColor = Color.FromArgb(232, 234, 238);
                        panel_channelList.Controls.Find("panel" + no, true)[0].Visible = false;
                    }

                    //LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "88888888");
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "dataGridView_Channel_RowPostPaint 错误:" + ex.Message);

            }
        }
    }
}