FrmAdjustQuotiety2.cs 28.3 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Comm;
using Dal;
using MachineDll;
using log4net;
using System.Reflection;
using System.Threading;
using System.Linq;
using System.IO;
using ZedGraph;
namespace App
{
    public partial class FrmAdjustQuotiety2 : App.FrmBase
    {
        private string m_ParaAdjustQuotiety; //校准系数
        private string m_ParaWashTime; //清洗时长
        private string m_ParaWashUpperLimit; //清洗上限
        private string m_ParaLong; //长
        private string m_ParaWidth; //宽
        private string m_ParaHeight; //高
        private string m_ParaKValue; //K值
        private string m_ParaK75; //K75
        private string m_ParaK50; //K50
        private string m_ParaEC1;//等效系数1值
        private string m_ParaEC2;//等效系数2值
        private string m_ParaECName1;//等效系数1名称
        private string m_ParaECName2;//等效系数2名称
        private string m_ParaAdjustingTime;//校准时间
        private string m_ParaErrorRang;//误差范围
        private string m_ParaSolution;//校准溶液浓度
        private string m_ParaMachineModel;//产品型号
        private string m_ParaSerialNumber;//序列号
        private string m_ParaCalibrationDate;//校准日期
                
        private LoginManager _loginManager;
        private System.Windows.Forms.Timer InputValueTimer;
        private string readDataType;//读取数据类型
        Dictionary<string, Control> btn = new Dictionary<string, Control>();
        Dictionary<string, Control> pal = new Dictionary<string, Control>();

        public FrmAdjustQuotiety2(string adjustQ,LoginManager loginManager)
        {
            InitializeComponent();
            if (DesignMode)
                return;
            this.SetLanguage(this);
            this.WindowState = FormWindowState.Maximized;
            this._loginManager = loginManager;

            

            LOGGER.Debug("1、into FrmAdjustingQuotiety time:" + DateTime.Now);
            Init();
            LOGGER.Debug("2、into FrmAdjustingQuotiety time:" + DateTime.Now);
            checkMachineState();
            InputValueTimer = new System.Windows.Forms.Timer();
            InputValueTimer.Interval = 1000;
            InputValueTimer.Stop();
            InputValueTimer.Tick += InputValueTimer_Tick;
            
            btn.Add("Setting", btnSetting);
            btn.Add("Testing", btnTesting);
            btn.Add("Calibration", btnCalibration);

            pal.Add("Testing", panelTesting);
            pal.Add("Setting", PanelSetting);
            pal.Add("Calibration", panelCalibration);
            panelCalibration.theMachine = theMachine;


            btnCalibration.Visible = false;
        }

        private void InputValueTimer_Tick(object sender, EventArgs e)
        {
            var d = theMachine.GetData();
            txtData.Text = d.ToString("0.0000");
            isReadData = d>0;
        }
        #region 初始化
        private void Init()
        {
            GetUnit();
            GetData();
            this.Text = getMsg("frmLoginManageckb_AMMaintenance4");
            //this.panel1.Location = new Point((this.Width - panel1.Width) / 2, 2);
            this.lblEquivalentCoefficient1.Text = getMsg("EC1");
            this.lblEquivalentCoefficient2.Text = getMsg("EC2");
            this.btn_Cancel.Text = getMsg("back");

            this.lblECName1.Text = getMsg("Name");
            this.lblECName2.Text = getMsg("Name");
            this.lblECValue1.Text = getMsg("Value");
            this.lblECValue2.Text = getMsg("Value");
            this.lblMachineModel.Text = getMsg("MachineModel");
            this.lblSerialNumber.Text = getMsg("SerialNumber");
            this.lblCalibrationDate.Text = getMsg("CalibrationDate");

            this.lbl_WashUpperLimitUnit.Text = "M.OHM";

            this.btnSetting.Text = getMsg("FrmMDIAuth_6040");//校准系数
            this.btnTesting.Text = getMsg("Check");//测试
            //this.btnStartTesting.Text = getMsg("FrmMDIAuth_2010");//开始测试
            this.btnStopTesting.Text = getMsg("FrmMDIAuth_2020");//终止测试
            this.label3.Text = getMsg("Conductivity");//data-label3
            //this.label1.Text = getMsg("FrmTestManageColDate");//time-label1
            this.label4.Text = getMsg("ElectronicValve");//电子阀-label4
            this.lblY0.Text = getMsg("Y0");//Y0
            this.lblY1.Text = getMsg("Y1");//Y1
            this.lblY2.Text = getMsg("Y2");//Y2
            this.btnFilter.Text = getMsg("LiquidCleanliness");//过滤
            this.btnClean.Text = getMsg("Wash");//清洗
            this.filterStata.Text = getMsg("NonWork");//工作中
            this.cleanState.Text = getMsg("NonWork");//非工作中
            this.BtnReConnect.Text = getMsg("Reconnect");//重新连接
            this.btnCalibration.Text = getMsg("Calibration"); //"校准";//getMsg("autoCalibration");

            lbl_WashUpperLimit.Text = getMsg("WashUpperLimit");//"过滤上限";//
            lbl_WashTime.Text = getMsg("WashTime");//"过滤时间";//


            var PortName = fuction.GetParameterByParaName(Const.PARA_PORT, "currency"); //读连接的COMS
            theMachine = GetMachineFromMe.NewMachine(PortName,readDataType);
            theMachine.IsDebug = Program.IsDebug;
        }

        private void GetData()
        {

            readDataType = fuction.GetParameterByParaName(Const.PARA_READDATATYPE, "currency");
            txtWTime.Text = fuction.GetParameterByParaName(Const.PARA_WASHTIME, "currency");

            txtWashULimit.Text = fuction.GetParameterByParaName(Const.PARA_WASHUPPERLIMIT, "currency");

            txtECValue1.Text = fuction.GetParameterByParaName(Const.PARA_EC1, "currency");//EC1值
            txtECValue2.Text = fuction.GetParameterByParaName(Const.PARA_EC2, "currency");//EC2值
            txtECName1.Text = fuction.GetParameterByParaName(Const.PARA_ECName1, "currency");//EC1名称
            txtECName2.Text = fuction.GetParameterByParaName(Const.PARA_ECName2, "currency");//EC2名称

            txtMachineModel.Text = fuction.GetParameterByParaName(Const.PARA_MachineModel, "currency");//设备型号
            txtSerialNumber.Text = fuction.GetParameterByParaName(Const.PARA_SERIALNUMBER, "currency");//序列号
            string CalibrationDate = fuction.GetParameterByParaName(Const.PARA_CALIBRATIONDATE, "currency");//校准日期
            if ("0".Equals(CalibrationDate))
            {
                dtCalibrationDate.Value = Convert.ToDateTime(DateTime.Now.ToShortDateString());
            }
            else
            {
                dtCalibrationDate.Value = Convert.ToDateTime(CalibrationDate);
            }
        }
        private void GetUnit()
        {
            lbl_TimeUnit1.Text = Fuction.m_UserTimeUnit;
            this.label13.Text = Fuction.m_UserTimeUnit;
            this.label2.Text = "g/L";
        }
#endregion

        #region 保存数据
        private void btn_OK_Click(object sender, EventArgs e)
        {
            if (!Check())
                return;
            //m_ParaAdjustQuotiety = txt_AdjustQ.Text; //校准系数
            m_ParaWashTime = txtWTime.Text; //清洗时长
            m_ParaWashUpperLimit = txtWashULimit.Text; //清洗上限            

            m_ParaEC1 = txtECValue1.Text;//EC1
            m_ParaEC2 = txtECValue2.Text;//EC2
            m_ParaECName1 = txtECName1.Text;//EC1名称
            m_ParaECName2 = txtECName2.Text;//EC2名称
            m_ParaMachineModel = txtMachineModel.Text;//产品型号
            m_ParaSerialNumber = txtSerialNumber.Text;//序列号
            m_ParaCalibrationDate = dtCalibrationDate.Value.Year.ToString() + "-" + dtCalibrationDate.Value.Month.ToString() + "-" + dtCalibrationDate.Value.Day.ToString();//校准日期

            bool ifOpera = 
                //fuction.CreateParaConfig("", Fuction.m_UserLogin, Const.PARA_ADJUSTQUOTIETY, m_ParaAdjustQuotiety) &&
                //fuction.CreateParaConfig("", Fuction.m_UserLogin, Const.PARA_WASHTIME, m_ParaWashTime) &&
                //fuction.CreateParaConfig("", Fuction.m_UserLogin, Const.PARA_WASHUPPERLIMIT, m_ParaWashUpperLimit) &&
                //fuction.CreateParaConfig("", Fuction.m_UserLogin, Const.PARA_Height, m_ParaHeight) &&
                //fuction.CreateParaConfig("", Fuction.m_UserLogin, Const.PARA_Long, m_ParaLong) &&
                //fuction.CreateParaConfig("", Fuction.m_UserLogin, Const.PARA_Width, m_ParaWidth) &&
                //fuction.CreateParaConfig("", Fuction.m_UserLogin, Const.PARA_KVALUE, m_ParaKValue) &&
                //fuction.CreateParaConfig("", Fuction.m_UserLogin, Const.PARA_K75, m_ParaK75) &&
                //fuction.CreateParaConfig("", Fuction.m_UserLogin, Const.PARA_K50, m_ParaK50)&&
                //fuction.CreateParaConfig("", Fuction.m_UserLogin, Const.PARA_EC1, m_ParaEC1)&&
                //fuction.CreateParaConfig("", Fuction.m_UserLogin, Const.PARA_EC2, m_ParaEC2)&&

                //fuction.CreateParaConfig("", Fuction.m_UserLogin, Const.PARA_ECName1, m_ParaECName1) &&
                //fuction.CreateParaConfig("", Fuction.m_UserLogin, Const.PARA_ECName2, m_ParaECName2) &&
                //fuction.CreateParaConfig("", Fuction.m_UserLogin, Const.PARA_AdjustingTime, m_ParaAdjustingTime) &&
                //fuction.CreateParaConfig("", Fuction.m_UserLogin, Const.PARA_ErrorRang, m_ParaErrorRang) &&
                //fuction.CreateParaConfig("", Fuction.m_UserLogin, Const.PARA_Solution, m_ParaSolution)&&
                //fuction.CreateParaConfig("", Fuction.m_UserLogin, Const.PARA_MachineModel, m_ParaMachineModel) &&
                //fuction.CreateParaConfig("", Fuction.m_UserLogin, Const.PARA_SERIALNUMBER, m_ParaSerialNumber) &&
                fuction.CreateParaConfig("", Fuction.m_UserLogin, Const.PARA_CALIBRATIONDATE, m_ParaCalibrationDate)&&
                //fuction.CreateParaConfig("",Fuction.m_UserLogin,Const.PARA_INVERTAL,"5");
                fuction.CreateParaConfig("", "currency", Const.PARA_WASHTIME, m_ParaWashTime) &&
                fuction.CreateParaConfig("", "currency", Const.PARA_WASHUPPERLIMIT, m_ParaWashUpperLimit) &&
                fuction.CreateParaConfig("", "currency", Const.PARA_Height, m_ParaHeight) &&
                fuction.CreateParaConfig("", "currency", Const.PARA_Long, m_ParaLong) &&
                fuction.CreateParaConfig("", "currency", Const.PARA_Width, m_ParaWidth) &&
                fuction.CreateParaConfig("", "currency", Const.PARA_KVALUE, m_ParaKValue) &&
                fuction.CreateParaConfig("", "currency", Const.PARA_K75, m_ParaK75) &&
                fuction.CreateParaConfig("", "currency", Const.PARA_K50, m_ParaK50) &&
                fuction.CreateParaConfig("", "currency", Const.PARA_EC1, m_ParaEC1) &&
                fuction.CreateParaConfig("", "currency", Const.PARA_EC2, m_ParaEC2) &&

                fuction.CreateParaConfig("", "currency", Const.PARA_ECName1, m_ParaECName1) &&
                fuction.CreateParaConfig("", "currency", Const.PARA_ECName2, m_ParaECName2) &&
                fuction.CreateParaConfig("", "currency", Const.PARA_AdjustingTime, m_ParaAdjustingTime) &&
                fuction.CreateParaConfig("", "currency", Const.PARA_ErrorRang, m_ParaErrorRang) &&
                fuction.CreateParaConfig("", "currency", Const.PARA_Solution, m_ParaSolution) &&
                fuction.CreateParaConfig("", "currency", Const.PARA_MachineModel, m_ParaMachineModel) &&
                fuction.CreateParaConfig("", "currency", Const.PARA_SERIALNUMBER, m_ParaSerialNumber) &&
                fuction.CreateParaConfig("", "currency", Const.PARA_CALIBRATIONDATE, m_ParaCalibrationDate) &&
                fuction.CreateParaConfig("", "currency", Const.PARA_INVERTAL, "5");
            if (ifOpera)
                ShowMessageBox.ShowInfo(Const.MESSAGEBOX_TITLE_NOTE, Const.SUCCESS_OPERATION);
            else
                ShowMessageBox.ShowError(Const.MESSAGEBOX_TITLE_NOTE, "", Const.ERROR_OPERATION);
            this.Close();
        }
        #endregion

        private bool Check()
        {
            if (!CheckNull(lbl_WashTime.Text, txtWTime) ||
                !CheckNumber(lbl_WashTime.Text, txtWTime))
                return false;
            if (!CheckNull(lbl_WashUpperLimit.Text, txtWashULimit) ||
                !CheckNumber(lbl_WashUpperLimit.Text, txtWashULimit))
                return false;
            if (!CheckNull(lblEquivalentCoefficient1.Text, txtECValue1) ||
                !CheckNumber(lblEquivalentCoefficient1.Text, txtECValue1))
                return false;
            if (!CheckNull(lblEquivalentCoefficient2.Text, txtECValue2) ||
                !CheckNumber(lblEquivalentCoefficient2.Text, txtECValue2))
                return false;

            if (!CheckNull(lblECName1.Text, txtECName1))
                return false;
            if (!CheckNull(lblECName2.Text, txtECName2))
                return false;
            if (!CheckNull(lblMachineModel.Text, txtMachineModel))
                return false;
            if (!CheckNull(lblSerialNumber.Text, txtSerialNumber))
                return false;
            return true;           
        }
        #region 上一步
        private void btn_Cancel_Click(object sender, EventArgs e)
        {
            InputValueTimer.Stop();
            if (isTesting)//判断是否在测试
            {
                if (ShowMessageBox.ShowQuestion(Const.MESSAGEBOX_TITLE_NOTE, Const.Cut_Off_Test))
                {
                    closeMachine();
                    this.Close();
                }
            }
            else if (isCalibration) //判断是否在校准
            {
                //询问是否结束校准
                if (ShowMessageBox.ShowQuestion(Const.MESSAGEBOX_TITLE_NOTE, Const.Cut_Off_Calibration))
                {//结束校准
                    closeMachine();
                    this.Close();
                }
            }
            else
            {
                if (theMachine != null)
                {
                    theMachine.CloseConnection();
                }
                this.Close();
            }
            //MetroMDI mm = new MetroMDI(_loginManager);
            //mm.Show();
        }
        #endregion

        #region 导入数据
        private void btn_Input_Click(object sender, EventArgs e)
        {
            string[] listData;
            openFileDialog1.DefaultExt = "xml";
            openFileDialog1.Filter = "xml file|*.xml";
            openFileDialog1.FileName = Const.ADJUSTCONFIGNAME;
            string directory = Fuction.m_CurrentDirectory + Const.AdjustRoot;
            openFileDialog1.InitialDirectory = directory;
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                listData = fuction.ReadXmlAdjust(openFileDialog1.FileName);

                if (listData.Length > 0)
                {
                    txtWTime.Text = listData[1];
                    txtWashULimit.Text = listData[2];
                    txtECValue1.Text = listData[6];//EC1
                    txtECValue2.Text = listData[7];//EC2
                    txtECName1.Text = listData[8];//EC1名称
                    txtECName2.Text = listData[9];//EC2名称

                    txtMachineModel.Text = listData[13];//机器型号
                    txtSerialNumber.Text = listData[14];//序列号
                    dtCalibrationDate.Value = Convert.ToDateTime(listData[15]);//校准日期
                }
            }
        }
        #endregion

        #region 导出数据
        private void btn_Export_Click(object sender, EventArgs e)
        {
            if (!Check())
                return;

            saveFileDialog1.DefaultExt = "xml";
            saveFileDialog1.Filter = "xml file|*.xml";
            saveFileDialog1.FileName = Const.ADJUSTCONFIGNAME;
            string directory = Fuction.m_CurrentDirectory + Const.AdjustRoot;
            saveFileDialog1.InitialDirectory = directory;
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string[,] NodeStr = new string[16,2];

                NodeStr[0, 0] = Const.PARA_ADJUSTQUOTIETY ;
                NodeStr[1, 0] = Const.PARA_WASHTIME;
                NodeStr[2, 0] = Const.PARA_WASHUPPERLIMIT;
                NodeStr[3, 0] = Const.PARA_KVALUE;
                NodeStr[4, 0] = Const.PARA_K75;
                NodeStr[5, 0] = Const.PARA_K50;
                NodeStr[6, 0] = Const.PARA_EC1;
                NodeStr[7, 0] = Const.PARA_EC2;
                NodeStr[8, 0] = Const.PARA_ECName1;
                NodeStr[9, 0] = Const.PARA_ECName2;
                NodeStr[10, 0] = Const.PARA_AdjustingTime;
                NodeStr[11, 0] = Const.PARA_ErrorRang;
                NodeStr[12, 0] = Const.PARA_Solution;
                NodeStr[13, 0] = Const.PARA_MachineModel;
                NodeStr[14, 0] = Const.PARA_SERIALNUMBER;
                NodeStr[15, 0] = Const.PARA_CALIBRATIONDATE;

                NodeStr[0, 1] = "";// txt_AdjustQ.Text; //校准系数
                NodeStr[1, 1] = txtWTime.Text; //清洗时长
                NodeStr[2, 1] = txtWashULimit.Text; //清洗上限
                NodeStr[6, 1] = txtECValue1.Text; //EC1
                NodeStr[7, 1] = txtECValue2.Text; //EC2
                NodeStr[8, 1] = txtECName1.Text;//EC1名称
                NodeStr[9, 1] = txtECName2.Text;//EC2名称
                NodeStr[13, 1] = txtMachineModel.Text;//机器型号
                NodeStr[14, 1] = txtSerialNumber.Text;//序列号
                NodeStr[15, 1] = DateTime.Now.ToString("yyyy-MM-dd");//dtCalibrationDate.Value.Year.ToString() + "-" + dtCalibrationDate.Value.Month.ToString() + "-" + dtCalibrationDate.Value.Day.ToString();//校准日期
                //if (rb_IsUserInput.Checked)
                //{
                //    NodeStr[8, 1] = ""; //高
                //}
                //else
                //{
                //    NodeStr[8, 1] = fuction.ChangeLUnit(txt_Height.Text); //高
                //}
                int int_lastSlash = saveFileDialog1.FileName.LastIndexOf(@"\");
                int int_lastPoint = saveFileDialog1.FileName.LastIndexOf(@".");

                string fileName = saveFileDialog1.FileName.Substring(int_lastSlash + 1, int_lastPoint - int_lastSlash-1);
                bool ifOpera = fuction.SaveXmlAdjust(saveFileDialog1.FileName, Const.PARA_ADJUSTQUOTIETY + fileName, NodeStr);
                if (ifOpera)
                    ShowMessageBox.ShowInfo(Const.MESSAGEBOX_TITLE_NOTE, Const.SUCCESS_OPERATION);
                else
                    ShowMessageBox.ShowError(Const.MESSAGEBOX_TITLE_NOTE, "", Const.ERROR_OPERATION);

            }
        }
        #endregion

        private void FrmAdjustQuotiety_Shown(object sender, EventArgs e)
        {
            //ResizeForm();
        }

        private void FrmAdjustQuotiety_FormClosed(object sender, FormClosedEventArgs e)
        {
            MetroMDI mm = new MetroMDI(_loginManager);
            mm.ShowInTaskbar = true;
            mm.Show();
        }

        
        private void FrmAdjustQuotiety_Load(object sender, EventArgs e)
        {
            ShowPanel("Setting");
        }
        void ShowPanel(string key)
        {
            pal[key].Location = new Point(227, 115);
            btn.Values.ToList().ForEach(x => x.Enabled = true);
            pal.Values.ToList().ForEach(x => x.Visible = false);
            pal[key].Visible = true;
            btn[key].Enabled = false;
            
        }


        
        //int time = 0;
        bool isTesting = false;
        //点击过滤
        private void btnFilter_Click(object sender, EventArgs e)
        {
            try
            {
                InputValueTimer.Stop();

                this.btnClean.Enabled = false;
                this.btnFilter.Enabled = false;
                this.btnSetting.Enabled = false;
                this.btnStopTesting.Enabled = true;
                this.filterStata.Text = getMsg("AtWork");
                this.filterStata.ForeColor = Color.Green;
                this.cleanState.Text = getMsg("NonWork");
                this.cleanState.ForeColor = Color.Red;
                this.lblY1.ForeColor = Color.Green;
                this.lblY2.ForeColor = Color.Green;
                this.lblY0.ForeColor = Color.Red;
                isTesting = true;
                LOGGER.Debug("click filter button,isTesting is true");

                
                if (theMachine.StartConnection())
                {
                    theMachine.Close();
                    Thread.Sleep(1000);
                    theMachine.OpenFilter();
                    InputValueTimer.Start();
                }
                else
                {
                    InputValueTimer.Stop();

                    this.lblY1.ForeColor = Color.Red;
                    this.lblY2.ForeColor = Color.Red;
                    this.filterStata.ForeColor = Color.Red;
                    this.filterStata.Text = getMsg("NonWork");
                    isTesting = false;
                    //LOGGER.Debug("click filter button,the machine isnot connect,isTesting is false");
                }
            }
            catch (Exception ex)
            {
                LOGGER.Debug("空引用异常:" + ex.StackTrace);

                InputValueTimer.Stop();

                this.lblY1.ForeColor = Color.Red;
                this.lblY2.ForeColor = Color.Red;
                this.filterStata.ForeColor = Color.Red;
                this.filterStata.Text = getMsg("NonWork");
                isTesting = false;
                //LOGGER.Debug("click filter button,into catch ,isTesting is false");
            }
        }

        //点击校准系数按钮
        private void btnCoefficientSetting_Click(object sender, EventArgs e)
        {
            loadTestingPanel();
            ShowPanel("Setting");
        }

        TheMachine theMachine;
        public void checkMachineState()
        {
            if (Program.IsDebug)
            {
                Checking();
                return;
            }

            if (!isReadData)//没有读到数据
            {
                var PortName = fuction.GetParameterByParaName(Const.PARA_PORT, "currency");
                LOGGER.Debug("port is " + SerialPortSetting.PortName.Trim() );
                
                theMachine = GetMachineFromMe.NewMachine(PortName,readDataType);

                if (theMachine.StartConnection())//判断串口是否连接
                {
                    Checking();
                }
            }
        }
        private void Checking()//检查中5
        {
            //this.btnStartTesting.Enabled = false;
            this.btnClean.Enabled = true;
            this.btnFilter.Enabled = true;
            this.btnStopTesting.Enabled = false;
        }
        private void btnSetting_Click(object sender, EventArgs e)
        {
            loadTestingPanel();
            ShowPanel("Testing");
            InputValueTimer.Start();
        }
        
        private void loadTestingPanel()
        {
            //isReadData = true;
            //测试按钮不可用
            this.btnTesting.Enabled = false;
            //校准系数按钮可用
            this.btnSetting.Enabled = true;
            //隐藏校准系数panel
            this.PanelSetting.Visible = false;
            //重新连接按钮不可用
            this.BtnReConnect.Enabled = false;
            //终止测试不可用
            this.btnStopTesting.Enabled = false;
            //显示测试panel
            this.panelTesting.Visible = true;
            //过滤不可用
            this.btnFilter.Enabled = false;
            //清洗不可用
            this.btnClean.Enabled = false;
            //this.txtData.Text = "";
            isReadData = false;
            //进行状态判断
            checkMachineState();
        }
        private bool isReadData = false;
        
        //点击终止测试
        private void btnStopTesting_Click(object sender, EventArgs e)
        {
            closeMachine();
            //this.btnStartTesting.Enabled = true;
            this.btnFilter.Enabled = true;
            this.btnClean.Enabled = true;
            this.btnSetting.Enabled = true;
            this.filterStata.Text = getMsg("NonWork");
            this.cleanState.Text = getMsg("NonWork");
            this.filterStata.ForeColor = Color.Red;
            this.cleanState.ForeColor = Color.Red;
            this.lblY0.ForeColor = Color.Red;
            this.lblY1.ForeColor = Color.Red;
            this.lblY2.ForeColor = Color.Red;
            this.btnStopTesting.Enabled = false;
            this.isTesting = false;
            LOGGER.Debug("click stop button,isTesting is false");
            checkMachineState();
            //this.txtData.Text = "";
            //this.groupBox3.Enabled = false;
        }
        private void closeMachine()
        {
            InputValueTimer.Stop();
            theMachine.Close();
            theMachine.CloseConnection();
        }
        //点击清洗
        private void btnClean_Click(object sender, EventArgs e)
        {

            InputValueTimer.Stop();
            
            this.btnClean.Enabled = false;
            this.btnFilter.Enabled = false;
            this.btnSetting.Enabled = false;
            this.btnStopTesting.Enabled = true;
            this.cleanState.Text = getMsg("AtWork");
            this.cleanState.ForeColor = Color.Green;
            this.filterStata.Text = getMsg("NonWork");
            this.filterStata.ForeColor = Color.Red;
            this.lblY0.ForeColor = Color.Green;
            this.lblY2.ForeColor = Color.Green;
            this.lblY1.ForeColor = Color.Red;
            try
            {
                isTesting = true;
                LOGGER.Debug("click clean button,isTesting is true");
                SerialPortSetting.PortName = fuction.GetParameterByParaName(Const.PARA_PORT,"currency");
                if (theMachine.StartConnection())
                {
                    theMachine.Close();
                    Thread.Sleep(1000);
                    theMachine.OpenWash();
                    InputValueTimer.Start();
                }
                else
                {
                    this.lblY0.ForeColor = Color.Red;
                    this.lblY2.ForeColor = Color.Red;
                    this.cleanState.Text = getMsg("NonWork");
                    this.cleanState.ForeColor = Color.Red;
                    this.isTesting = false;
                    LOGGER.Debug("click clean button,the machine isnot connect,isTesting is false");
                }

            }
            catch (Exception ex)
            {
                LOGGER.Debug(ex.ToString());
                this.lblY0.ForeColor = Color.Red;
                this.lblY2.ForeColor = Color.Red;
                this.cleanState.Text = getMsg("NonWork");
                this.cleanState.ForeColor = Color.Red;
                isTesting = false;
                LOGGER.Debug("click clean button,into catch,isTesting is false");
            }
        }
        //重新连接
        private void button1_Click(object sender, EventArgs e)
        {
            this.BtnReConnect.Enabled = false;
            //this.txtData.Text = "";
            this.isReadData = false;
            checkMachineState();
        }
        #region 自动校准
        //点击自动校准
        //点击自动校准
        private void btnAutoCalibration_Click(object sender, EventArgs e)
        {
            //判断是否有在测试
            if (isCalibration)
            {
                //询问是否结束测试
                if (ShowMessageBox.ShowQuestion(Const.MESSAGEBOX_TITLE_NOTE, Const.Cut_Off_Test))
                {//结束校准
                    closeMachine();
                    loadCalibrationPanel();
                }
            }
            else
            {
                loadCalibrationPanel();
            }
            ShowPanel("Calibration");
        }
        private void loadCalibrationPanel()
        {
            //隐藏校准系数、测试界面
            this.panelTesting.Visible = false;
            this.PanelSetting.Visible = false;
            this.btnSetting.Enabled = true;
            this.btnTesting.Enabled = true;
            this.btnCalibration.Enabled = false;
        }

        private bool isCalibration = false;

        private void panelCalibration_Load(object sender, EventArgs e)
        {

        }


        #endregion
        //应用标准


    }
}