FrmAdjustQuotiety.cs 51.8 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 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155
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 FrmAdjustQuotiety : 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 bool isLoadTesting = false;//是否加载过测试界面
        private LoginManager _loginManager;

        private string readDataType;//读取数据类型

        private static Fuction fuction = new Fuction();
        public FrmAdjustQuotiety(string adjustQ,LoginManager loginManager)
        {
            InitializeComponent();
            Control.CheckForIllegalCrossThreadCalls = false;
            this.SetLanguage(this);
            zedGraphControl1.setLanguage(this.str_LResourse);
            //m_ParaAdjustQuotiety = adjustQ;
            //txt_AdjustQ.Text = adjustQ;
            this.WindowState = FormWindowState.Maximized;
            this._loginManager = loginManager;
            LOGGER.Debug("1、into FrmAdjustingQuotiety time:" + DateTime.Now);
            Init();
            LOGGER.Debug("2、into FrmAdjustingQuotiety time:" + DateTime.Now);
        }
        #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.BtnStartTest.Text = getMsg("FrmMDItabStart");
            //this.label9.Text = getMsg("addStandard");
            //this.label10.Text = getMsg("Verification");
            this.btnStopAdjusting.Text = getMsg("stopAdjusting");

            this.lblD1.Text = getMsg("D1");
            this.lblD2.Text = getMsg("D2");
            this.lblProductWeight.Text = getMsg("SampleWeight");
            this.lblActualErrorRang.Text = getMsg("ActualErrorRange");
            this.lblAdjustingTime.Text = getMsg("CalibrationTime");
            this.lblErrorRang.Text = getMsg("ErrorRange");
            this.lblSolution.Text = getMsg("CalibrationSolutionConcentration");
            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.btnCoefficientSetting.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.btnAutoCalibration.Text = getMsg("autoCalibration");

            this.rdStaticCali.Text = "静态校准";
            this.rdDynamicCali.Text = "动态校准";
            this.addStandandPanel.Text = "建立基准";
            this.checkPanel.Text = "验证";
            this.btnFinishCalibration.Text = "应用";

        }
        //private void SetHeightVisible(bool visible)
        //{
        //    txt_Height.Visible = visible;
        //    lbl_Height.Visible = visible;
        //    lbl_LengthUnit2.Visible = visible;
        //}
        private void GetData()
        {
            readDataType = fuction.GetParameterByParaName(Const.PARA_READDATATYPE, "currency");

            //if (Fuction.m_UserTimeUnit == Const.TIMEUNIT_MIN)
            //{
            //    this.cmbWTime.Items.Clear();
            //    this.cmbWTime.Items.Add("");
            //    this.cmbWTime.Items.Add("0.5");
            //    this.cmbWTime.Items.Add("1");
            //}
            //else
            //{
            //    this.cmbWTime.Items.Clear();
            //    this.cmbWTime.Items.Add("");
            //    this.cmbWTime.Items.Add("30");
            //    this.cmbWTime.Items.Add("60");
            //}
            //switch (fuction.GetParameterByParaName(Const.PARA_WASHTIME, "currency"))
            //{
            //    case "0.5":
            //    case "30": this.cmbWTime.SelectedIndex = 1; break;
            //    case "1":
            //    case "60": this.cmbWTime.SelectedIndex = 2; break;
            //    default: this.cmbWTime.SelectedIndex = 0; break;
            //}
            txtWTime.Text = fuction.GetParameterByParaName(Const.PARA_WASHTIME, "currency");

            txtWashULimit.Text = fuction.GetParameterByParaName(Const.PARA_WASHUPPERLIMIT, "currency");
            string height = fuction.GetParameterByParaName(Const.PARA_Height, "currency"); //高
            if (height=="")
            {
                //rb_IsUserInput.Checked = true;
                //SetHeightVisible(false);
            }
            else
            {
                //rb_IsUserInput.Checked = false;
                //SetHeightVisible(true);
                //txt_Height.Text = height;
            }
            txt_KValue.Text = fuction.GetParameterByParaName(Const.PARA_KVALUE, "currency"); //K值
            txt_K75.Text = fuction.GetParameterByParaName(Const.PARA_K75, "currency"); //K75
            txt_K50.Text = fuction.GetParameterByParaName(Const.PARA_K50, "currency"); //K50
            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名称
            if (Fuction.m_UserTimeUnit == Const.TIMEUNIT_MIN)
            {
                txtAdjustingTime.Text = fuction.ReChangeTimeUnit(fuction.GetParameterByParaName(Const.PARA_AdjustingTime, "currency"));//校准时间
            }
            else
            {
                txtAdjustingTime.Text = fuction.GetParameterByParaName(Const.PARA_AdjustingTime, "currency");//校准时间
            }
            //txtAdjustingTime.Text = fuction.GetParameterByParaName(Const.PARA_AdjustingTime);//校准时间
            txtErrorRang.Text = fuction.GetParameterByParaName(Const.PARA_ErrorRang, "currency");//误差范围
            txtSolution.Text = fuction.GetParameterByParaName(Const.PARA_Solution, "currency");//校准溶液浓度
            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.lblRangUnit.Text = "%";
            this.lblActualErrorRangUnit.Text = "%";
            this.lblProductWeightUnit.Text = "g";
            this.label2.Text = "g/L";
            //lbl_LengthUnit1.Text = Fuction.m_UserLengthUnit;
            //lbl_LengthUnit2.Text = Fuction.m_UserLengthUnit;
            //lbl_LengthUnit3.Text = Fuction.m_UserLengthUnit;
        }
#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_ParaKValue = txt_KValue.Text; //K值
            m_ParaK75 = txt_K75.Text; //k75
            m_ParaK50 = txt_K50.Text;//k50
            m_ParaEC1 = txtECValue1.Text;//EC1
            m_ParaEC2 = txtECValue2.Text;//EC2
            m_ParaECName1 = txtECName1.Text;//EC1名称
            m_ParaECName2 = txtECName2.Text;//EC2名称
            m_ParaAdjustingTime = txtAdjustingTime.Text;//校准时间
            m_ParaErrorRang = txtErrorRang.Text;//误差范围
            m_ParaSolution = txtSolution.Text;//校准溶液浓度
            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_AdjustQuotiety.Text, txt_AdjustQ) ||
            //   !CheckNumber(lbl_AdjustQuotiety.Text, txt_AdjustQ))
            //    return false;
            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(lbl_KValue.Text, txt_KValue) ||
                !CheckNumber(lbl_KValue.Text, txt_KValue))
                return false;
            if (!CheckNull(lbl_Delay1.Text, txt_K75) ||
                !CheckNumber(lbl_Delay1.Text, txt_K75))
                return false;
            if (!CheckNull(lbl_Delay2.Text, txt_K50) ||
                !CheckNumber(lbl_Delay2.Text, txt_K50))
                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(lblAdjustingTime.Text, txtAdjustingTime) ||
                !CheckNumber(lblAdjustingTime.Text, txtAdjustingTime))
                return false;
            if (!CheckNull(lblErrorRang.Text, txtErrorRang) ||
                !CheckNumber(lblErrorRang.Text, txtErrorRang))
                return false;
            if (!CheckNull(lblSolution.Text, txtSolution) ||
                !CheckNumber(lblEquivalentCoefficient2.Text, txtSolution))
                return false;
            if (!CheckNull(lblMachineModel.Text, txtMachineModel))
                return false;
            if (!CheckNull(lblSerialNumber.Text, txtSerialNumber))
                return false;
            if (!CheckNull(lblCalibrationDate.Text, dtCalibrationDate))
                return false;
            return true;           
        }
        #region 上一步
        private void btn_Cancel_Click(object sender, EventArgs e)
        {
            if (isTesting)//判断是否在测试
            {
                if (ShowMessageBox.ShowQuestion(Const.MESSAGEBOX_TITLE_NOTE, Const.Cut_Off_Test))
                {
                    //txtDataTimer.Stop();
                    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.StopReading();
                    theMachine.CloseConnection();
                    theMachine._ItsSerialPort = null;
                    theMachine = null;
                }
                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文件|*.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)
                {
                    //if (Fuction.m_UserTimeUnit == Const.TIMEUNIT_MIN)
                    //{
                    //    this.cmbWTime.Items.Clear();
                    //    this.cmbWTime.Items.Add("0.5");
                    //    this.cmbWTime.Items.Add("1");
                    //}
                    //else
                    //{
                    //    this.cmbWTime.Items.Clear();
                    //    this.cmbWTime.Items.Add("30");
                    //    this.cmbWTime.Items.Add("60");
                    //}
                    //switch (listData[1])//清洗时长
                    //{
                    //    case"0.5":
                    //    case "30": this.cmbWTime.SelectedIndex = 1; break;
                    //    case"1":
                    //    case "60": this.cmbWTime.SelectedIndex = 2; break;
                    //    default: this.cmbWTime.SelectedIndex = 0; break;
                    //}
                    txtWTime.Text = listData[1];
                    txtWashULimit.Text = listData[2];

                    txt_KValue.Text=listData[3] ; //K值
                    txt_K75.Text=listData[4] ; //K75
                    txt_K50.Text = listData[5];//K50
                    txtECValue1.Text = listData[6];//EC1
                    txtECValue2.Text = listData[7];//EC2
                    txtECName1.Text = listData[8];//EC1名称
                    txtECName2.Text = listData[9];//EC2名称
                    if (Fuction.m_UserTimeUnit == Const.TIMEUNIT_MIN)
                    {
                        txtAdjustingTime.Text = fuction.ReChangeTimeUnit(listData[10]);//校准时间
                    }
                    else
                    {
                        txtAdjustingTime.Text = listData[10];//校准时间
                    }
                    
                    txtErrorRang.Text = listData[11];//误差范围
                    txtSolution.Text = listData[12];//校准溶液浓度
                    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文件|*.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[3, 1] = txt_KValue.Text; //K值
                NodeStr[4, 1] = txt_K75.Text; //延时1
                NodeStr[5, 1] = txt_K50.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[10, 1] = txtAdjustingTime.Text;//校准时间
                NodeStr[11, 1] = txtErrorRang.Text;//误差范围
                NodeStr[12, 1] = txtSolution.Text;//校准溶液浓度
                NodeStr[13, 1] = txtMachineModel.Text;//机器型号
                NodeStr[14, 1] = txtSerialNumber.Text;//序列号
                NodeStr[15, 1] = 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 rb_IsUserInput_CheckedChanged_1(object sender, EventArgs e)
        {
            //SetHeightVisible(!rb_IsUserInput.Checked);
        }

        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)
        {
            //this.groupBox1.Width = this.ribbonPanel2.Width / 2 - 4;
            //this.groupBox2.Width = this.ribbonPanel2.Width / 2 - 4;
            //this.groupBox1.Location=new System.Drawing.Point(this.ribbonPanel2.Location.X,this.ribbonPanel2.Location.Y-this.panel1.Location.Y-10);
            //this.groupBox2.Location = new System.Drawing.Point(this.ribbonPanel2.Location.X - groupBox2.Width - 4, this.groupBox1.Location.Y);
            //this.PanelCoefficientSetting.Location = new Point(this.ribbonPanel2.Location.X-20 + (this.ribbonPanel2.Width / 2 - this.PanelCoefficientSetting.Width / 2), this.ribbonPanel2.Location.Y  + (this.ribbonPanel2.Height / 2 - this.PanelCoefficientSetting.Height / 2));
            //this.panelTesting.Location = new Point(this.ribbonPanel2.Location.X - 20 + (this.ribbonPanel2.Width / 2 - this.PanelCoefficientSetting.Width / 2), this.ribbonPanel2.Location.Y  + (this.ribbonPanel2.Height / 2 - this.PanelCoefficientSetting.Height / 2));
            this.btnCoefficientSetting.Enabled = false;
            this.btnTesting.Enabled = true;
            this.panelTesting.Visible = false;//测试界面隐藏
            this.PanelCoefficientSetting.Visible = true;//设置界面显示
            //判断是否显示自动化校准
            if (Fuction.m_ParaIsCalibration == "true")
            {
                //显示自动化校准界面
                this.btnAutoCalibration.Visible = true;
                this.Panelcalibration.Visible = true;
                this.rdStaticCali.Checked = true;
                isStatic = true;
                this.panelDynamic.Visible = false;
                this.panelStatic.Visible = true;
            }
            else
            {
                //不显示自动化校准界面
                this.btnAutoCalibration.Visible = false;
                this.Panelcalibration.Visible = false;
                this.btn_Cancel.Location = this.btnAutoCalibration.Location;
            }
        }



        private System.Timers.Timer InputValueTimer;
        //int time = 0;
        bool isTesting = false;
        //点击过滤
        private void btnFilter_Click(object sender, EventArgs e)
        {
            try
            {
                if (InputValueTimer != null)
                {
                    InputValueTimer.Stop();
                }
                this.btnClean.Enabled = false;
                this.btnFilter.Enabled = false;
                this.btnCoefficientSetting.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 != null)
                {
                    setTheMachineNull();
                }
                theMachine = GetMachineFromMe.GetMachine;
                SerialPortSetting.PortName = fuction.GetParameterByParaName(Const.PARA_PORT, "currency"); ;//读连接的COMS

                if (theMachine.StartConnection())
                {
                    mcrd = new MachineCheckReceiveData(this.txtData);
                    theMachine.AddClients(mcrd);
                    if (("PLC").Equals(readDataType))
                    {
                        theMachine.GetControllor.OpenY1();
                        System.Threading.Thread.Sleep(1500);
                        theMachine.GetControllor.OpenY2();
                        System.Threading.Thread.Sleep(1500);
                        theMachine.GetControllor.CloseY0();
                        if (!theMachine.StartReading())
                        {
                            this.Close();
                        }
                    }
                    else if (("IO").Equals(readDataType))
                    {
                        theMachine.GetControllor.OpenY1Y2();
                        System.Threading.Thread.Sleep(1000);
                        if (!theMachine.StartReadingIO())
                        {
                            this.Close();
                        }
                    }
                }
                else
                {
                    if (InputValueTimer != null)
                    {
                        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);
                if (InputValueTimer != null)
                {
                    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 setTheMachineNull()
        {
            checkReturnValueTimer.Stop();
            theMachine.StopReading();
            theMachine.RemoveClients(mcrd);

            theMachine.CloseConnection();
            theMachine._ItsSerialPort = null;
            theMachine = null;
        }

        //private void showGroupBox(object source, System.Timers.ElapsedEventArgs e)
        //{
        //    if (returnValue != -100)
        //    {
        //        this.txtData.Text = returnValue.ToString("#0.000");
        //        returnValue = -100;
        //        this.textBox2.Text = time++.ToString();
        //    }
        //    else
        //    {
        //        //this.txtData.Text = "";
        //    }
        //}

        public static double returnValue=-100;
        private class MachineCheckReceiveData : IReceiveData
        {
            private System.Windows.Forms.TextBox txtData;
            public MachineCheckReceiveData(System.Windows.Forms.TextBox txtdata)
            {
                this.txtData = txtdata;
            }
            private Byte[] _ReceiveValue;
            public void NewReceiveData(int receivedCount, Byte[] receiveValue)
            {
                fuction.CreateParaConfig("", "currency", Const.PARA_READDATATYPE, "PLC");
                _ReceiveValue = receiveValue;
                string temp = "";
                int index = 6;
                for (int i = 1; i < _ReceiveValue.Length; i++)//0~5
                {
                    if (Convert.ToChar(_ReceiveValue[i]).ToString() == "+")
                    {
                        index = i;
                        break;
                    }
                    temp = temp + Convert.ToChar(_ReceiveValue[i]);
                }
                LOGGER.Debug("tmp data is:" + temp);
                double.TryParse(temp, out returnValue);
                this.txtData.Text = returnValue.ToString("#0.000");
            }
            public void NewReceiveIOData(double receiveValue)
            {
                //LOGGER.Debug("FrmAdjustQuotiety receive Value is "+ receiveValue);
                fuction.CreateParaConfig("", "currency", Const.PARA_READDATATYPE, "IO");
                returnValue = receiveValue;
                this.txtData.Text = receiveValue.ToString("#0.000");
            }
        }
        //点击校准系数按钮
        private void btnCoefficientSetting_Click(object sender, EventArgs e)
        {
            //校准系数按钮不可用
            this.btnCoefficientSetting.Enabled = false;
            //测试按钮可用
            this.btnTesting.Enabled = true;
            //显示校准系数panel
            this.PanelCoefficientSetting.Visible = true;
            //隐藏测试panel
            this.panelTesting.Visible = false;
            this.Panelcalibration.Visible = false;
            //if (txtDataTimer != null)
            //{
            //    txtDataTimer.Stop();
            //}

        }

        private System.Timers.Timer checkReturnValueTimer;
        TheMachine theMachine;
        MachineCheckReceiveData mcrd;
        public void checkMachineState()
        {
            if (!isReadData)//没有读到数据
            {
                theMachine = GetMachineFromMe.GetMachine;
                SerialPortSetting.PortName = theMachine.TestConnection();//读连接的COM
                if (SerialPortSetting.PortName == "")//端口未连接(USB口)
                {
                    //unPassCheck(1);
                    MessageBox.Show(getMsg("CheckUSB"), getMsg("msg-Information"), MessageBoxButtons.OK);//请确认USB口与计算机是否连接!
                    this.BtnReConnect.Enabled = true;
                    this.btnFilter.Enabled = false;
                    this.btnClean.Enabled = false;
                    return;
                }
                string portName = fuction.GetParameterByParaName(Const.PARA_PORT,"currency");//读保存的COM口
                LOGGER.Debug("port is " + SerialPortSetting.PortName.Trim());
                if (!(SerialPortSetting.PortName.Trim().Contains(portName)))
                {
                    //unPassCheck(2);//端口设置有问题
                    MessageBox.Show(getMsg("CheckSettingPort"), getMsg("msg-Information"), MessageBoxButtons.OK);//请确认端口设置是否正确!
                    this.btnFilter.Enabled = false;
                    this.btnClean.Enabled = false;
                    this.BtnReConnect.Enabled = true;
                    return;
                }
                else
                {
                    SerialPortSetting.PortName = portName;
                }
                theMachine._ItsSerialPort = null;
                if (theMachine.StartConnection())//判断串口是否连接
                {
                    Checking();
                    mcrd = new MachineCheckReceiveData(this.txtData);
                    theMachine.AddClients(mcrd);
                    if (("PLC").Equals(readDataType))
                    {
                        theMachine.StartReading();
                    }
                    else if (("IO").Equals(readDataType))
                    {
                        theMachine.StartReadingIO();
                    }
                    else if (("0").Equals(readDataType) || ("").Equals(readDataType) || readDataType == null)//尚未记录何种类型数据读取方式
                    {
                        theMachine.StartReadingIO();
                    }
                    if (checkReturnValueTimer == null) {
                        checkReturnValueTimer = new System.Timers.Timer();
                        checkReturnValueTimer.Elapsed += new System.Timers.ElapsedEventHandler(checkData);//2秒后检测是否有数据读入
                        checkReturnValueTimer.Interval = 2000;
                    }
                    
                    checkReturnValueTimer.Start();
                }
            }
        }
        private void Checking()//检查中5
        {
            //this.btnStartTesting.Enabled = false;
            this.btnClean.Enabled = false;
            this.btnFilter.Enabled = false;
            this.btnStopTesting.Enabled = false;
        }
        public void checkData(object source, System.Timers.ElapsedEventArgs e)
        {
            checkReturnValueTimer.Stop();
            if (returnValue != -100)//读到数据,串口连接着
            {
                LOGGER.Debug("判断机器状态结束,读到数据");
                this.btnStopTesting.Enabled = false;
                this.btnFilter.Enabled = true;
                this.btnClean.Enabled = true;
                isReadData = true;
                //returnValue = -100;
                this.txtData.Text = "";
                
                //this.txtData.Text = returnValue.ToString("#0.000");
                //txtDataTimer = new System.Timers.Timer();
                //txtDataTimer.Elapsed += new System.Timers.ElapsedEventHandler(checkTxtData);//每秒检测是否有数据读入
                //txtDataTimer.Interval = 1000;
                //txtDataTimer.AutoReset = true;
                //txtDataTimer.Start();
            }
            else//未收到数据,串口未连接
            {
                if (("0").Equals(readDataType) || ("").Equals(readDataType) || readDataType == null)//尚未记录何种类型数据读取方式
                {
                    fuction.CreateParaConfig("", "currency", Const.PARA_READDATATYPE, "NotCheckedOut");//未查检出读取数据类型,所以此刻串口与设备未连接或者设备未上电
                    theMachine.StartReading();
                    checkReturnValueTimer.Start();
                    return;
                }
                LOGGER.Debug("判断机器状态结束,未读到数据");
                checkReturnValueTimer.Stop();
                theMachine.StopReading();
                theMachine.RemoveClients(mcrd);
                this.BtnReConnect.Enabled = true;
                this.btnStopTesting.Enabled = false;
                this.btnFilter.Enabled = false;
                this.btnClean.Enabled = false;
                isReadData = false;
                //this.txtData.Text = "";
                MessageBox.Show(getMsg("CheckSerialPort"), getMsg("msg-Information"), MessageBoxButtons.OK);//请确认串口与机器是否连接!
                //unPassCheck(3);

                theMachine.CloseConnection();
                theMachine._ItsSerialPort = null;
                theMachine = null;
            }
        }
        //System.Timers.Timer txtDataTimer;
        //点击测试按钮
        private void btnSetting_Click(object sender, EventArgs e)
        {
            loadTestingPanel();
        }
        
        private void loadTestingPanel()
        {
            //isReadData = true;
            //测试按钮不可用
            this.btnTesting.Enabled = false;
            //校准系数按钮可用
            this.btnCoefficientSetting.Enabled = true;
            //隐藏校准系数panel
            this.PanelCoefficientSetting.Visible = false;
            this.Panelcalibration.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;
            if (theMachine != null)
            {
                setTheMachineNull();
            }
            //进行状态判断
            checkMachineState();
        }
        private bool isReadData = false;
        public void checkTxtData(object source, System.Timers.ElapsedEventArgs e)
        {
            LOGGER.Debug("Now returnValuead is:" + returnValue);
            if (returnValue==-100)//未读到数据
            {
                LOGGER.Debug("1、returnValue is "+returnValue);
                this.txtData.Text = "";
                //txtDataTimer.Stop();//停下计时器
                this.btnClean.Enabled = false;
                this.btnFilter.Enabled = false;
                this.BtnReConnect.Enabled = true;//显示重新连接
                isReadData = false;
                checkMachineState();
            }
            else//读到数据
            {
                LOGGER.Debug("2、returnValue is " + returnValue);
                this.txtData.Text = returnValue.ToString("#0.000");
                if (!isTesting)
                {
                    LOGGER.Debug("not into testing");
                    returnValue = -100;
                }
                isReadData = true;
                this.BtnReConnect.Enabled = false;
            }
        }

        //点击开始测试
        private void btnStartTesting_Click(object sender, EventArgs e)
        {
            //this.btnStartTesting.Enabled = false;
            
            //this.groupBox3.Enabled = true;ad
        }
        //点击终止测试
        private void btnStopTesting_Click(object sender, EventArgs e)
        {
            closeMachine();
            //this.btnStartTesting.Enabled = true;
            this.btnFilter.Enabled = true;
            this.btnClean.Enabled = true;
            this.btnCoefficientSetting.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()
        {
            if (this.theMachine != null)
            {
                theMachine.StopReading();
                if (("PLC").Equals(readDataType))
                {
                    theMachine.GetControllor.CloseY0();
                    System.Threading.Thread.Sleep(1500);
                    theMachine.GetControllor.CloseY2();
                    System.Threading.Thread.Sleep(1500);
                    theMachine.GetControllor.CloseY1();
                }
                else if (("IO").Equals(readDataType))
                {
                    theMachine.GetControllor.CloseAll();
                    LOGGER.Info("IO CloseAll");
                }
                theMachine.RemoveClients(mcrd);
                theMachine.CloseConnection();
                theMachine._ItsSerialPort = null;
                theMachine = null;
                //isStop = true;
            }
        }
        //点击清洗
        private void btnClean_Click(object sender, EventArgs e)
        {
            if (InputValueTimer != null)
            {
                InputValueTimer.Stop();
            }
            this.btnClean.Enabled = false;
            this.btnFilter.Enabled = false;
            this.btnCoefficientSetting.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");
                if (theMachine != null)
                {
                    setTheMachineNull();
                }
                theMachine = GetMachineFromMe.GetMachine;
                SerialPortSetting.PortName = fuction.GetParameterByParaName(Const.PARA_PORT,"currency");
                if (theMachine.StartConnection())
                {
                    mcrd = new MachineCheckReceiveData(this.txtData);
                    theMachine.AddClients(mcrd);
                    if (("PLC").Equals(readDataType))
                    {
                        theMachine.GetControllor.OpenY0();
                        System.Threading.Thread.Sleep(1500);
                        theMachine.GetControllor.OpenY2();
                        System.Threading.Thread.Sleep(1500);
                        theMachine.GetControllor.CloseY1();
                        System.Threading.Thread.Sleep(1000);
                        if (!theMachine.StartReading())
                        {
                            this.Close();
                        }
                    }
                    else if (("IO").Equals(readDataType))
                    {
                        theMachine.GetControllor.OpenY0Y2();
                        System.Threading.Thread.Sleep(1000);
                        if (!theMachine.StartReadingIO())
                        {
                            this.Close();
                        }
                    }
                }
                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");
                }
                //time = 0;
                //InputValueTimer = new System.Timers.Timer();
                //InputValueTimer.Elapsed += new System.Timers.ElapsedEventHandler(showGroupBox);//1秒后将数据显示在textbox
                //InputValueTimer.Interval = 1000;
                //InputValueTimer.AutoReset = true;
                //InputValueTimer.Start();
            }
            catch (Exception ex)
            {
                LOGGER.Debug(ex.StackTrace);
                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();
            }
        }
        private void loadCalibrationPanel()
        {
            //显示自动校准界面
            this.Panelcalibration.Visible = true;
            //隐藏校准系数、测试界面
            this.panelTesting.Visible = false;
            this.PanelCoefficientSetting.Visible = false;
            this.isStatic = true;
            this.btnCoefficientSetting.Enabled = true;
            this.btnTesting.Enabled = true;
            this.btnAutoCalibration.Enabled = false;
            this.panelStatic.Visible = true;
            this.panelDynamic.Visible = false;
            this.rdStaticCali.Checked = true;
        }

        private bool isCalibration = false;
        private ReceiveMachineData rmd;
        //点击开始校准
        private void BtnStartTest_Click(object sender, EventArgs e)
        {
            isCalibration = true;
            this.BtnStartTest.Enabled = false;
            this.btnStopAdjusting.Enabled = true;
            this.btnCoefficientSetting.Enabled = false;
            this.btnTesting.Enabled = false;
            this.btnAutoCalibration.Enabled = false;
            if (isStatic)
            {
                rmd = new ReceiveMachineData(1, this.txtD1, this.txtD2, this.txtProductWeight, this.txtActualErrorRang,
                    this.zedGraphControl1, this.addStandandPanel, this.checkPanel, this.BtnStartTest, this,
                    btnFinishCalibration, isStatic, btnStopAdjusting);//静态
            }
            else
            {
                rmd = new ReceiveMachineData(1, this.txtD1, this.txtD2, this.txtProductWeight, this.txtActualErrorRang,
                    this.zedGraphControl1, this.button1, this.button2, this.button3, this.BtnStartTest, this,
                    btnFinishCalibration, isStatic, btnStopAdjusting);//动态
            }
            //rmd = new ReceiveMachineData(1, this);
        }
        //点击终止校准
        private void btnStopAdjusting_Click(object sender, EventArgs e)
        {
            isCalibration = false;
            this.btnStopAdjusting.Enabled = false;
            this.BtnStartTest.Enabled = true;
            //询问是否结束校准
            if (ShowMessageBox.ShowQuestion(Const.MESSAGEBOX_TITLE_NOTE, Const.Cut_Off_Calibration))
            {//结束校准
                rmd.closeMachine();
            }

        }
        #endregion
        //应用标准
        private void btnFinishCalibration_Click(object sender, EventArgs e)
        {
            rmd.save();
            //更新校准日期
            dtCalibrationDate.Value = Convert.ToDateTime(DateTime.Now.ToShortDateString());
            m_ParaCalibrationDate = dtCalibrationDate.Value.Year.ToString() + "-" + dtCalibrationDate.Value.Month.ToString() + "-" + dtCalibrationDate.Value.Day.ToString();//校准日期
            fuction.CreateParaConfig("", "currency", Const.PARA_CALIBRATIONDATE, m_ParaCalibrationDate);
            ShowMessageBox.ShowInfo(Const.MESSAGEBOX_TITLE_NOTE, Const.SUCCESS_OPERATION);
        }
        private bool isStatic;
        private void rdDynamicCali_CheckedChanged(object sender, EventArgs e)
        {
            if (this.rdDynamicCali.Checked)
            {
                this.rdStaticCali.Checked = false;
                isStatic = false;
            }
            this.panelDynamic.Visible = true;
            this.panelStatic.Visible = false;
        }

        private void rdStaticCali_CheckedChanged(object sender, EventArgs e)
        {
            if (this.rdStaticCali.Checked)
            {
                this.rdDynamicCali.Checked = false;
                isStatic = true;
            }
            this.panelStatic.Visible = true;
            this.panelDynamic.Visible = false;
        }

    }
}