FrmTestFunction.cs
60.4 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
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MachineDll;
using Dal;
using Comm;
using ZedGraph;
using System.IO;
using System.Xml;
namespace App
{
public partial class FrmTestFunction : App.FrmBase,IReceiveData
{
#region 数据定义
//各数据的数据源
private DataTable DtFilterRawData;
private DataTable DtFilterEnvironmentalData;
private DataTable DtFilterUpperLimit;
private DataTable DtTestRawData;
private DataTable DtTestInfo;
private DataTable DtTestResult;
//测试值
private double k1;
private double kValue;
private double area;//产品面积
private double DEFArea;
private double MILArea;
private double lastValue;//计算后产品上的离子量
private double DEFValue;
private double MILValue;
private double count = 0;//存放初始化数据数量
private double sumInitData = 0;//存放初始化数据总值
private double D0 = 0;//存放初始化数据的平均值
private string m_TestSolvent;//测试溶剂
private string m_TestMode;//测试模式
//判断当前状态
private bool isFilter = false;
private bool isInit = false;
private bool isTest = false;
private DateTime startTime;
//多线程
private delegate void PrepareDataWashDelegate(double rawData);
private delegate void BindtabControlPrepareDelegate();
private delegate void CloseFormDelegate();
private delegate void StartPrepareDelegate();
private delegate void CountDownSplashShowDelegate(int showTextId, int CountDown);
private CountDownSplashShowDelegate countDownSplashShowDelegate;
private delegate void ClosefrmSplash2Delegate();
private delegate void AddDataGridView5Delegate(double rawData);
private AddDataGridView5Delegate addDataGridView5Delegate;
private delegate void AddDataGridView1Delegate();
private delegate void AddZedGraphControl1Delegate();
private delegate void SaveFileQuestionDelegate();
//存放原始数据
private Dictionary<double, double> filterData = new Dictionary<double, double>();//key为时间,value为原始值的倒数
private Dictionary<double, double> cleanData = new Dictionary<double, double>();//key为时间,value为原始值
//拟合的参数AB
private double A;
private double B;
//初始化时显示窗口
private FrmSplash frmSplash2;
//是否过过滤上限
private bool isOverWashLimit;
private readonly string XMLFile = Fuction.m_CurrentDirectory + Const.TestDataRoot + Const.DATACONFIGNAME;
private static readonly byte[] Keys = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
//父窗口
private MetroDynamicTesting parentDynamicForm;
private MetroStaticTesting parentStaticForm;
private TheMachine theMachine;
private bool isStatic;//当前测试模式
private LoginManager _loginManager;
#endregion
public FrmTestFunction(string TestSolvent, string TestMode, LoginManager loginManager)
{
InitializeComponent();
m_TestSolvent = TestSolvent;
m_TestMode = TestMode;
string testModeItemDYNAMIC = "";
switch (Fuction.m_Language)
{
case Const.LANGUAGE_ENGLISH:
testModeItemDYNAMIC = Const.TESTMETHOD_DYNAMIC_EN;
break;
case Const.LANGUAGE_JAPANESE:
testModeItemDYNAMIC = Const.TESTMETHOD_DYNAMIC_JP;
break;
case Const.LANGUAGE_CHINESE:
testModeItemDYNAMIC = Const.TESTMETHOD_DYNAMIC_CH;
break;
default:
break;
}
if (testModeItemDYNAMIC.Equals(TestMode))
{
isStatic = false;
}
else
{
isStatic = true;
}
this._loginManager = loginManager;
SetStyle("Azure");
this.SetLanguage(this);
zgcShowCurve.setLanguage(this.str_LResourse);
Init();
CheckForIllegalCrossThreadCalls = false;
}
private void FrmTestFunction_Load(object sender, EventArgs e)
{
this.tabControlTest.Visible = false;//测试相关tab关闭
this.tabControlFilter.Visible = true;//过滤相关tab开启
this.tabPage5.Text = " " + getMsg("FrmTestManagetabOriginalData") + " ";//测试结果
this.tabPage3.Text = " " + getMsg("FrmTestManagetabTestResult") + " ";//原始数据
this.tabPage1.Text = " " + getMsg("FrmTestManagetabPrePare") + " ";//过滤数据
this.tabPage2.Text = " " + getMsg("TestInfo") + " ";//测试信息
this.tabPage4.Text = " " + getMsg("TestInfo") + " ";//测试信息
this.tabControlTest.Location = this.tabControlFilter.Location;
if (isStatic)
{
parentStaticForm = (MetroStaticTesting)this.TopLevelControl;
}
else //如果是动态测试
{
parentDynamicForm = (MetroDynamicTesting)this.TopLevelControl;
}
if (this.TopLevelControl is MetroStaticTesting)
{
parentStaticForm.showControls();
}
else if (this.TopLevelControl is MetroDynamicTesting)
{
parentDynamicForm.showControls();
}
}
private void Init()
{
try
{
//读取数据读入的间隔时间
double invertal = Convert.ToDouble(fuction.GetParameterByParaName(Const.PARA_INVERTAL, "currency"));
if (invertal == 0 || invertal < 5)
{
invertal = 5;
}
//读取设定的测试时间,如果当前是时间单位是分,则需要转换成秒
string tempTestTime = fuction.GetParameterByParaName(Const.PARA_TESTTIME, "currency");
double testTime = Convert.ToDouble(fuction.ChangeTimeUnit(tempTestTime));
double washUpperLimit = Convert.ToDouble(fuction.GetParameterByParaName(Const.PARA_WASHUPPERLIMIT, "currency"));
washUpperLimit = 1 / washUpperLimit;
double washTime = Convert.ToDouble(fuction.GetParameterByParaName(Const.PARA_WASHTIME, "currency"));
String readDataType = fuction.GetParameterByParaName(Const.PARA_READDATATYPE, "currency");
Fuction.m_ParaTestTime = testTime.ToString();
Fuction.m_ParaWashUpperLimit = washUpperLimit.ToString();
Fuction.m_ParaWashTime = washTime.ToString();
Fuction.m_ParaReadDataType = readDataType;
LOGGER.Info("testTime is " + testTime + "--UpperLimit is " + washUpperLimit + "--washTimem is " + washTime + "--readDataType is " + readDataType);
k1 = (fuction.GetParameterByParaName(Const.PARA_TESTSOLVENT, "currency") == Const.TESTSOLVENT_75IPA) ?
Convert.ToDouble(fuction.GetParameterByParaName(Const.PARA_K75, "currency")) :
Convert.ToDouble(fuction.GetParameterByParaName(Const.PARA_K50, "currency")); ;
kValue = Convert.ToDouble(fuction.GetParameterByParaName(Const.PARA_KVALUE, "currency"));
area = Convert.ToDouble(fuction.GetParameterByParaName(Const.PARA_PRODUCTAREA, "currency")) * 2; ;
MILArea = Convert.ToDouble(fuction.GetParameterByParaName(Const.PARA_PRODUCTAREA, "currency")) * 2 +
Convert.ToDouble(fuction.GetParameterByParaName(Const.PARA_MIL, "currency")); ;
DEFArea = Convert.ToDouble(fuction.GetParameterByParaName(Const.PARA_PRODUCTAREA, "currency")) * 2 *
(1 + Convert.ToDouble(fuction.GetParameterByParaName(Const.PARA_DEF, "currency")));
LOGGER.Info("K75 is " + k1 + "--K is " + kValue + "--area is " + area + "--MILArea is " + MILArea + "--DEFArea is " + DEFArea);
}
catch
{
ShowMessageBox.ShowError(Const.MESSAGEBOX_TITLE_NOTE, "", Const.ERROR_MISSDATA);
this.Close();
}
string port = fuction.GetParameterByParaName(Const.PARA_PORT, "currency");
theMachine = GetMachineFromMe.GetMachine;
SerialPortSetting.PortName = port;
if (theMachine.StartConnection())
{
theMachine.AddClients(this);
InitData();//初始化数据
}
else
{
ShowMessageBox.ShowError(Const.MESSAGEBOX_TITLE_NOTE, "", Const.ERROR_NONE_DATA);
this.Close();
}
}
private void InitData()
{
DtFilterRawData = new DataTable();//存放过滤原始数据
DataColumnCollection columns = DtFilterRawData.Columns;
columns.Add(getMsg("FrmTestManageColTestTime"), typeof(System.String));//时间
columns.Add(getMsg("FrmTestManageColData"), typeof(System.String));//数据
DtFilterEnvironmentalData = new DataTable();//存放过滤环境数据
columns = DtFilterEnvironmentalData.Columns;
columns.Add(" ", typeof(System.String));//空
columns.Add(getMsg("FrmTestManageInformatin"), typeof(System.String));//信息
DtFilterUpperLimit = new DataTable();//存放过滤上限
columns = DtFilterUpperLimit.Columns;
columns.Add(getMsg("FrmTestManageColTestTime"), typeof(System.String));//时间
columns.Add(getMsg("FrmTestManageColData"), typeof(System.String));//数据
DtTestRawData = new DataTable();//存放测试原始数据
columns = DtTestRawData.Columns;
columns.Add(getMsg("FrmTestManageColTestTime"), typeof(System.String));//时间
columns.Add(getMsg("FrmTestManageColData"), typeof(System.String));//数据
DtTestInfo = new DataTable();//存放测试环境数据
columns = DtTestInfo.Columns;
columns.Add(" ", typeof(System.String));//空
columns.Add(getMsg("FrmTestManageInformatin"), typeof(System.String));//信息
DtTestResult = new DataTable(Const.TABLE_NAME);//存放测试信息
columns = DtTestResult.Columns;
columns.Add(" ", typeof(System.String));
columns.Add(getMsg("FrmTestResultColEndData"), typeof(System.String));
columns.Add(getMsg("FrmTestResultNote"), typeof(System.String));
OpenTheMachine();//打开机器
}
private void OpenTheMachine()
{
try
{
if (JudgeIsPass())
{
//先把Y1,Y2打开,D(也就是电导率)读数,其余关
if (("PLC").Equals(Fuction.m_ParaReadDataType))
{
theMachine.GetControllor.CloseY0();
System.Threading.Thread.Sleep(1000);
theMachine.GetControllor.OpenY1();
System.Threading.Thread.Sleep(500);
theMachine.GetControllor.OpenY1();
System.Threading.Thread.Sleep(1000);
theMachine.GetControllor.OpenY2();
System.Threading.Thread.Sleep(500);
theMachine.GetControllor.OpenY2();
System.Threading.Thread.Sleep(1000);
}
else if (("IO").Equals(Fuction.m_ParaReadDataType))
{
theMachine.GetControllor.OpenY1Y2();
}
startTime = DateTime.Now;
isFilter = true;
isInit = false;
isTest = false;
if (("PLC").Equals(Fuction.m_ParaReadDataType))
{
theMachine.StartReading();
}
else if (("IO").Equals(Fuction.m_ParaReadDataType))
{
theMachine.StartReadingIO();
}
}
else
{
this.Close();
}
}
catch (Exception ex)
{
ShowMessageBox.ShowError(Const.MESSAGEBOX_TITLE_NOTE, "", Const.ERROR_NONE_DATA);
LOGGER.Debug("Init data : 无数据读入");
LOGGER.Warn(ex.StackTrace);
Close();
}
}
private bool JudgeIsPass()
{
return true;
//硬件上已将液位过低短路
//bool judgeIsPass = false;
//Thread.Sleep(3000);
//try
//{
// if (!theMachine.GetControllor.ReadX0())
// {
// if (ShowMessageBox.ShowQuestion(Const.MESSAGEBOX_TITLE_NOTE, Const.ERROR_PUTIN_SOLVENT_))
// {
// judgeIsPass = JudgeIsPass();
// }
// }
// else
// {
// judgeIsPass = true;
// }
//}
//catch
//{
// ShowMessageBox.ShowError(Const.MESSAGEBOX_TITLE_NOTE, "", Const.ERROR_NONE_DATA);
//}
//return judgeIsPass;
}
#region 收取数据
public void NewReceiveIOData(double receiveIOData)
{
if (isFilter)
{
JudgeWashUpperLimit(receiveIOData);//过滤
}
else if (isInit)
{
PrepareData(receiveIOData);//初始化
}
else if (isTest)
{
NewGetData(receiveIOData);//测试
}
}
public void NewReceiveData(int receivedCount, Byte[] receiveValue)
{
//从机器返回的数据中截取电导率
double returnValue = double.Parse(SplitData(receiveValue));
if (isInit)
{
JudgeWashUpperLimit(returnValue);//过滤
}
else if (isFilter)
{
PrepareData(returnValue);//初始化
}
else if (isTest)
{
NewGetData(returnValue);//测试
}
}
#endregion
// 若是PLC返回的数据,进行数据拆分
private string SplitData(Byte[] receiveValue)
{
int i = 1;
string receiveData = "";
for (i = 1; i < receiveValue.Length; i++)//0~5
{
if (Convert.ToChar(receiveValue[i]).ToString() == "+")
{
break;
}
receiveData = receiveData + Convert.ToChar(receiveValue[i]);
}
return receiveData;
}
// 将得到的电导率进行数据计算
// 计算公式
// 离子污染度=K75(或K50) * (表头读数 - 初始值 - K*t)/(长*宽*2)
private void CalculationData(double receiveData)
{
double value = k1 * (receiveData - D0 - kValue * double.Parse(Fuction.m_ParaTestTime));
LOGGER.Info(value + " = " + k1 + " * (" + receiveData + " - " + D0 + " - " + kValue + " * " + Fuction.m_ParaTestTime + " )");
lastValue = value / area;
MILValue = value / MILArea;
DEFValue = value / DEFArea;
if (!isStatic)//动态测试比静态测试值大1.1倍
{
lastValue = lastValue * 1.1;
MILValue = MILValue * 1.1;
DEFValue = DEFValue * 1.1;
}
}
#region 初始化
private void Splash2Show(int textId, int countdown)
{
frmSplash2.ShowTextId = textId;
frmSplash2.CountDown = countdown;
//Size size = new Size(208, 138);
//frmSplash.ClientSize = size;
frmSplash2.ShowInTaskbar = false;
frmSplash2.StartPosition = FormStartPosition.CenterScreen;
frmSplash2.Show();
frmSplash2.Activate();
}
private void PrepareData(double returnValue)
{
count = count++;
sumInitData = sumInitData + returnValue;
D0 = sumInitData / count;
}
#endregion
#region 过滤
private void JudgeWashUpperLimit(double rawData)
{
//将数据绘制成曲线
//显示的数据为原始数据的倒数
if (zgcShowCurve.InvokeRequired)//过滤曲线
{
BeginInvoke(new BindtabControlPrepareDelegate(BindtabControlPrepare));
}
//将原始数据显示到DataGridView中
if (dgvFilterRawData.InvokeRequired)//过滤数据
{
BeginInvoke(new PrepareDataWashDelegate(PrepareDataWash), rawData);
}
}
private void PrepareDataWash(double rawData)
{
double showData = 0;
double showTime = 0;
try
{
if (rawData == 0)
{
//tempData = 100;
showData = 0;
}
else
{
showData = 1 / rawData;
}
if (rawData > 100)
{
showData = 100;
}
showTime = (DateTime.Now - startTime).TotalSeconds ;
if (showTime > 0)
{
showTime--;
}
if (!filterData.ContainsKey(showTime))//时间不重复时加入新数据
{
filterData.Add(showTime, showData);
}
for (int i = 0; i < DtFilterUpperLimit.Rows.Count; i++)
{
LOGGER.Debug("1===DtFilterUpperLimit " + DtFilterUpperLimit.Rows[i][getMsg("FrmTestManageColTestTime")] + " DtFilterUpperLimit " + DtFilterUpperLimit.Rows[i][getMsg("FrmTestManageColTestTime")]);
LOGGER.Debug("1===DtFilterRawData " + DtFilterRawData.Rows[i][getMsg("FrmTestManageColTestTime")] + " DtFilterRawData " + DtFilterRawData.Rows[i][getMsg("FrmTestManageColTestTime")]);
}
DataRow filterDataRow;
//每10个数据进行一次方程的拟合
if (DtFilterRawData.Rows.Count != 0 && DtFilterRawData.Rows.Count % 10 == 0)
{
LOGGER.Debug("拟合中");
getlinearAandB();
double[] sortFilterTime = filterData.Keys.ToArray<double>();
DtFilterRawData.Clear();
DtFilterRawData.Columns.Clear();
DtFilterRawData = new DataTable();
DataColumnCollection columns = DtFilterRawData.Columns;
columns.Add(getMsg("FrmTestManageColTestTime"), typeof(System.Double));
columns.Add(getMsg("FrmTestManageColData"), typeof(System.Double));
for (int i = 0; i < sortFilterTime.Length; i++)
{
filterDataRow = DtFilterRawData.NewRow();
filterDataRow[getMsg("FrmTestManageColTestTime")] = Convert.ToInt16(sortFilterTime[i]).ToString();
double result = B * Convert.ToDouble(sortFilterTime[i]) + A;
if (result < 0)
{
result = 0;
}
filterDataRow[getMsg("FrmTestManageColData")] = Math.Round(result, 3).ToString();
DtFilterRawData.Rows.Add(filterDataRow);
}
}
else
{
LOGGER.Debug("//原始数据");
filterDataRow = DtFilterRawData.NewRow();
filterDataRow[getMsg("FrmTestManageColTestTime")] = Convert.ToInt16(showTime).ToString();
showData = Math.Round(showData, 3);
filterDataRow[getMsg("FrmTestManageColData")] = showData.ToString();
DtFilterRawData.Rows.Add(filterDataRow);
}
double washUpperLimit = 1 / double.Parse(Fuction.m_ParaWashUpperLimit);
filterDataRow = null;
filterDataRow = DtFilterUpperLimit.NewRow();
filterDataRow[getMsg("FrmTestManageColTestTime")] = Convert.ToInt16(showTime).ToString();
filterDataRow[getMsg("FrmTestManageColData")] = washUpperLimit.ToString();
DtFilterUpperLimit.Rows.Add(filterDataRow);
for (int i = 0; i < DtFilterUpperLimit.Rows.Count; i++)
{
LOGGER.Debug("2===DtFilterUpperLimit " + DtFilterUpperLimit.Rows[i][getMsg("FrmTestManageColTestTime")] + " DtFilterUpperLimit " + DtFilterUpperLimit.Rows[i][getMsg("FrmTestManageColTestTime")]);
LOGGER.Debug("2===DtFilterRawData " + DtFilterRawData.Rows[i][getMsg("FrmTestManageColTestTime")] + " DtFilterRawData " + DtFilterRawData.Rows[i][getMsg("FrmTestManageColTestTime")]);
}
LOGGER.Debug("DtFilterRawData time is " + showTime + " data is " + showData + " DtFilterUpperLimit time is " + showTime + " data is " + washUpperLimit);
DateTime overUpperLimitTime;//超过过滤上限的时间
if (showData > washUpperLimit && isOverWashLimit)
{
isOverWashLimit = false;
overUpperLimitTime = DateTime.Now;
}
else
{
isOverWashLimit = true;
overUpperLimitTime = DateTime.Now;
}
//过过滤上限时间比记录时间长
double washUpperLimitSeconds = (DateTime.Now - overUpperLimitTime).TotalSeconds;
if (washUpperLimitSeconds >= double.Parse(Fuction.m_ParaWashTime))
{
timerWashToEnd();
}
GetDataGrideValue(dgvFilterRawData, DtFilterRawData);
showTestInfo();
}
catch (Exception ex)
{
ShowMessageBox.ShowError(Const.MESSAGEBOX_TITLE_NOTE, "", Const.ERROR_MISSDATA);
LOGGER.Warn(ex.StackTrace);
Close();
}
}
#endregion
private void showTestInfo()
{
DataRow dr;
if (isFilter)
{
dr = DtFilterEnvironmentalData.NewRow();//测试信息-时间
dr[" "] = getMsg("FrmTestManageColTestTime");
dr[getMsg("FrmTestManageInformatin")] = DateTime.Now.ToShortTimeString();
DtFilterEnvironmentalData.Rows.Add(dr);
dr = DtFilterEnvironmentalData.NewRow();//测试信息-模式
dr[" "] = getMsg("FrmTestManageColTestMode");
dr[getMsg("FrmTestManageInformatin")] = m_TestMode;
DtFilterEnvironmentalData.Rows.Add(dr);
dr = DtFilterEnvironmentalData.NewRow();//测试信息-溶剂
dr[" "] = getMsg("FrmTestManageColTestSolvent");
dr[getMsg("FrmTestManageInformatin")] = m_TestSolvent;
GetDataGrideValue(dgvFilterEnvironmentalData, DtFilterEnvironmentalData);
DtFilterEnvironmentalData.Rows.Add(dr);
DtFilterEnvironmentalData.Columns.Clear();
DtFilterEnvironmentalData.Clear();
DtFilterEnvironmentalData = new DataTable();
DataColumnCollection columns = DtFilterEnvironmentalData.Columns;
columns.Add(" ", typeof(System.String));
columns.Add(getMsg("FrmTestManageInformatin"), typeof(System.String));
GetDataGrideValue(dgvFilterEnvironmentalData, DtFilterEnvironmentalData);
}
else if (isTest)
{
dr = DtTestInfo.NewRow();
double testTime = (DateTime.Now - startTime).TotalSeconds;
dr[" "] = getMsg("FrmTestManageColTestTime");
dr[getMsg("FrmTestManageInformatin")] = Fuction.m_ParaTestTime;//测试总时间
DtTestInfo.Rows.Add(dr);
dr[" "] = getMsg("RemainingTime");
dr[getMsg("FrmTestManageInformatin")] = (double.Parse(Fuction.m_ParaTestTime) - testTime) + "s";//测试剩余时间
dr = DtTestInfo.NewRow();//测试信息-模式
dr[" "] = getMsg("FrmTestManageColTestMode");
dr[getMsg("FrmTestManageInformatin")] = m_TestMode;
DtTestInfo.Rows.Add(dr);
dr = DtTestInfo.NewRow();//测试信息-溶剂
dr[" "] = getMsg("FrmTestManageColTestSolvent");
dr[getMsg("FrmTestManageInformatin")] = m_TestSolvent;
DtTestInfo.Rows.Add(dr);
GetDataGrideValue(dgvTestInfo, DtTestInfo);
DtTestInfo.Columns.Clear();
DtTestInfo.Clear();
DtTestInfo = new DataTable();
DataColumnCollection columns = DtTestInfo.Columns;
columns.Add(" ", typeof(System.String));
columns.Add(getMsg("FrmTestManageInformatin"), typeof(System.String));
GetDataGrideValue(dgvTestInfo,DtTestInfo);
}
}
private void BindtabControlPrepare()
{
//曲线数据源
DataSourcePointList listFilterData = new DataSourcePointList();
listFilterData.DataSource = DtFilterRawData;
listFilterData.XDataMember = getMsg("FrmTestManageColTestTime");
listFilterData.YDataMember = getMsg("FrmTestManageColData");
DataSourcePointList listFilterUpperLimit = new DataSourcePointList();
listFilterUpperLimit.DataSource = DtFilterUpperLimit;
listFilterUpperLimit.XDataMember = getMsg("FrmTestManageColTestTime");
listFilterUpperLimit.YDataMember = getMsg("FrmTestManageColData");
for (int i = 0; i < listFilterData.Count; i++)
{
LOGGER.Debug("listFilterData " + listFilterData[i] + " listFilterUpperLimit " + listFilterUpperLimit[i]);
}
for (int i = 0; i < listFilterData.Count; i++)
{
LOGGER.Debug("DtFilterRawData " + DtFilterUpperLimit.Rows[i][getMsg("FrmTestManageColTestTime")] + " DtFilterUpperLimit " + DtFilterUpperLimit.Rows[i][getMsg("FrmTestManageColTestTime")]);
LOGGER.Debug("DtFilterRawData " + DtFilterRawData.Rows[i][getMsg("FrmTestManageColTestTime")] + " DtFilterRawData " + DtFilterRawData.Rows[i][getMsg("FrmTestManageColTestTime")]);
}
GetZedGraphControlValuePrepare(zgcShowCurve, listFilterData, listFilterUpperLimit);
}
private void GetZedGraphControlValuePrepare(ZedGraphControl zg, DataSourcePointList list1, DataSourcePointList list2)
{
zg.GraphPane.Title.Text = Fuction.m_Language == Const.LANGUAGE_CHINESE
?
"过滤曲线"
:
"Solution Cleanliness";
zg.GraphPane.Title.FontSpec.FontColor = Color.Black;
zg.GraphPane.Title.FontSpec.Family = "微软雅黑";
zg.GraphPane.XAxis.Title.Text = Fuction.m_Language == Const.LANGUAGE_CHINESE
?
"时间(" + Fuction.m_UserTimeUnit + ")"
:
"Time(" + Fuction.m_UserTimeUnit + ")";
zg.GraphPane.XAxis.Title.FontSpec.FontColor = Color.Black;
zg.GraphPane.XAxis.Title.FontSpec.Family = "微软雅黑";
zg.GraphPane.XAxis.Type = AxisType.Ordinal;
//zg.GraphPane.XAxis.Scale.Format = XDate.DefaultFormatStr;
zg.GraphPane.XAxis.MinorGrid.DashOn = 0F;
zg.GraphPane.XAxis.MajorGrid.IsVisible = true;
zg.GraphPane.YAxis.MajorGrid.IsVisible = true;
zg.GraphPane.YAxis.Title.Text = "M.OHM";
zg.GraphPane.YAxis.Title.FontSpec.Family = "微软雅黑";
zg.GraphPane.YAxis.Title.FontSpec.FontColor = Color.Black;
zg.GraphPane.Fill.Color = Color.FromArgb(215, 227, 242);
zg.GraphPane.Chart.Fill.Color = Color.FromArgb(215, 227, 242);
zg.IsShowPointValues = true;
if (DtFilterRawData.Rows.Count > 0)
{
zg.GraphPane.XAxis.Scale.Max = DtFilterRawData.Rows.Count;
}
zg.GraphPane.CurveList.Clear();
LineItem lineItem1 = zg.GraphPane.AddCurve(Fuction.m_Language == Const.LANGUAGE_CHINESE ? "清洗上限" : "Solution Cleanliness Limit", list2, Color.Green, SymbolType.None);
lineItem1.Line.Width = 2;
string label = Fuction.m_Language == Const.LANGUAGE_CHINESE
?
"过滤曲线"
:
"Solution Cleanliness";
LineItem lineItem2 = zg.GraphPane.AddCurve(label, list1, Color.Red, SymbolType.None);
lineItem2.IsOverrideOrdinal = true;
lineItem1.IsOverrideOrdinal = true;
lineItem2.Line.IsSmooth = true;
lineItem1.Line.IsSmooth = true;
zg.AxisChange();
zg.Refresh();
}
private void timerWashToEnd()
{
if (("PLC").Equals(Fuction.m_ParaReadDataType))
{
theMachine.StopReading();
theMachine.GetControllor.CloseY2();
System.Threading.Thread.Sleep(1000);
theMachine.GetControllor.CloseY1();
}
else if (("IO").Equals(Fuction.m_ParaReadDataType))
{
theMachine.StopReading();
theMachine.GetControllor.CloseAll();
LOGGER.Info("IO CloseAll");
}
isFilter = false;
isInit = false;
isTest = false;
//溶剂满足测试要求,点击确认后开始测试!
if (ShowMessageBox.ShowQuestion(Const.MESSAGEBOX_TITLE_NOTE, Const.IF_START_TEST))
{
isInit = true;
countDownSplashShowDelegate = new CountDownSplashShowDelegate(Splash2Show);
frmSplash2 = new FrmSplash();
this.BeginInvoke(new StartPrepareDelegate(StartPrepare));
}
else
{
BeginInvoke(new CloseFormDelegate(closeForm));
}
}
private void StartPrepare()
{
timerInit.Interval = 60000;//原60000
timerInit.Start();
try
{
if (("PLC").Equals(Fuction.m_ParaReadDataType))
{
theMachine.GetControllor.OpenY0();
System.Threading.Thread.Sleep(500);
theMachine.GetControllor.OpenY0();
System.Threading.Thread.Sleep(1000);
theMachine.GetControllor.OpenY2();
System.Threading.Thread.Sleep(500);
theMachine.GetControllor.OpenY2();
System.Threading.Thread.Sleep(1000);
}
else if (("IO").Equals(Fuction.m_ParaReadDataType))
{
theMachine.GetControllor.OpenY0Y2();
}
}
catch (IOException ex)
{
LOGGER.Warn(ex.StackTrace);
}
}
private void timerInit_Tick(object sender, EventArgs e)
{
timerInit.Stop();
ClosefrmSplash2();
isFilter = false;
isInit = false;
isTest = false;
//准备结束,开始放入产品
if (ShowMessageBox.ShowWarning(Const.MESSAGEBOX_TITLE_NOTE, Const.PUTIN_PRODUCT_NEXT))
{
isTest = true;
tabControlTest.Visible = true;
tabControlFilter.Visible = false;
startTime = DateTime.Now;
timerTest.Interval = int.Parse(Fuction.m_ParaTestTime) * 1000;
LOGGER.Info("TEST Interval=" + timerTest.Interval + " Start=" + string.Format("HH:mm:ss", DateTime.Now));
timerTest.Start();
}
else
{
BeginInvoke(new CloseFormDelegate(closeForm));
}
}
private void timerTest_Tick(object sender, EventArgs e)
{
LOGGER.Info("TEST Before Stop=" + string.Format("HH:mm:ss", DateTime.Now));
timerTest.Stop();
LOGGER.Info("TEST After Stop=" + string.Format("HH:mm:ss", DateTime.Now));
theMachine.StopReading();//流程结束
LOGGER.Info("TEST Stop Read=" + string.Format("HH:mm:ss", DateTime.Now));
if (("PLC").Equals(Fuction.m_ParaReadDataType))
{
System.Threading.Thread.Sleep(1000);
theMachine.GetControllor.CloseY2();
System.Threading.Thread.Sleep(1000);
theMachine.GetControllor.CloseY0();
}
else if (("IO").Equals(Fuction.m_ParaReadDataType))
{
theMachine.GetControllor.CloseAll();
LOGGER.Info("IO CloseAll");
}
//readDataTimer.Stop();
CloseRead();
ShowMessageBox.ShowInfo(Const.MESSAGEBOX_TITLE_NOTE, Const.FINISH_GETOUT_PRODUCT);
if (ShowMessageBox.ShowQuestion(Const.MESSAGEBOX_TITLE_NOTE, Const.IS_SAVE_TEST))
{
BeginInvoke(new SaveFileQuestionDelegate(SaveFileQuestion));
}
else
{
BeginInvoke(new CloseFormDelegate(closeForm));
}
}
private void SaveFileQuestion()
{
saveFileDialog1 = new SaveFileDialog();
string directory = Fuction.m_CurrentDirectory + Const.TestDataDataRoot;
saveFileDialog1.InitialDirectory = directory;
saveFileDialog1.Filter = "(*.re)|*.re";
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
SaveFile(saveFileDialog1.FileName);
if (this.ParentForm is MetroDynamicTesting)
{
MetroDynamicTesting parentForm = (MetroDynamicTesting)this.Parent.TopLevelControl;
ParentForm.Close();
}
else if (this.ParentForm is MetroStaticTesting)
{
MetroStaticTesting parentForm = (MetroStaticTesting)this.Parent.TopLevelControl;
ParentForm.Close();
}
MetroTestResult mtr = new MetroTestResult(this._loginManager, saveFileDialog1.FileName);
mtr.ShowInTaskbar = true;
mtr.Show();
mtr.Activate();
}
else
{
closeForm();
}
}
#region 保存数据
public void SaveFile(string directory)
{
int ifExport = Save(directory);
File.Delete(XMLFile);
ShowMessageBox.ShowInfo(Const.MESSAGEBOX_TITLE_NOTE, ifExport);
}
private int Save(string directory)
{
try
{
double[] cleanDataArray = cleanData.Keys.ToArray<double>();
string ResultValue = "";
string endTime = "";
for (int i = 0; i < cleanDataArray.Length; i++)
{
ResultValue = ResultValue +
(Fuction.m_UserResult == Const.RESULT_IN ?
fuction.ReChangeAreaUnit(cleanData[i].ToString()) :
cleanData[i].ToString()
);
endTime = endTime + cleanDataArray[i] + ",";
}
string product = fuction.GetParameterByParaName(Const.PARA_PRODUCT, "currency");
string imgBinary = getImgBinary(product);
fuction.SaveXmlStr(XMLFile, Const.LEAST_SQUARE_METHOD_A, A.ToString());
fuction.SaveXmlStr(XMLFile, Const.LEAST_SQUARE_METHOD_B, B.ToString());
fuction.SaveXmlStr(XMLFile, Const.USER_NAME, Fuction.m_UserName);
fuction.SaveXmlStr(XMLFile, Const.USER_LOGIN, Fuction.m_UserLogin);
fuction.SaveXmlStr(XMLFile, Const.USER_COMP, Fuction.m_UserComp);
fuction.SaveXmlStr(XMLFile, Const.USER_DEP, fuction.GetParameterByParaName(Const.USER_DEP, Fuction.m_UserLogin)); //asa,修改读取部门
fuction.SaveXmlStr(XMLFile, Const.PARA_TESTTIME, Fuction.m_ParaTestTime.ToString());
fuction.SaveXmlStr(XMLFile, Const.PARA_PRODUCT, product);
fuction.SaveXmlStr(XMLFile, Const.PRO_IMAGE, imgBinary);
string tempArea = fuction.GetParameterByParaName(Const.PARA_PRODUCTAREA, "currency");
tempArea = Fuction.m_UserResult == Const.RESULT_IN
? fuction.ChangeAreaUnit(tempArea)
: tempArea;
string tempL = fuction.GetParameterByParaName(Const.PARA_PRODUCTL, "currency");
tempL = Fuction.m_UserResult == Const.RESULT_IN
? fuction.ChangeLUnit(tempL)
: tempL;
string tempW = fuction.GetParameterByParaName(Const.PARA_PRODUCTW, "currency");
tempW = Fuction.m_UserResult == Const.RESULT_IN
? fuction.ChangeLUnit(tempW)
: tempW;
fuction.SaveXmlStr(XMLFile, Const.PARA_PRODUCTAREA, tempArea);
fuction.SaveXmlStr(XMLFile, Const.PARA_PRODUCTL, tempL);
fuction.SaveXmlStr(XMLFile, Const.PARA_PRODUCTW, tempW);
fuction.SaveXmlStr(XMLFile, Const.TEST_STARTTIME, startTime.ToString());
fuction.SaveXmlStr(XMLFile, Const.TEST_ENDTIME, endTime);
fuction.SaveXmlStr(XMLFile, Const.USER_LENGTHUNIT, Fuction.m_UserLengthUnit);
fuction.SaveXmlStr(XMLFile, Const.USER_TIMEUNIT, Fuction.m_UserTimeUnit);
fuction.SaveXmlStr(XMLFile, Const.USER_TEMPUNIT, Fuction.m_UserTempUnit);
fuction.SaveXmlStr(XMLFile, Const.PARA_TEMPSTANDART, fuction.GetParameterByParaName(Const.PARA_TEMPSTANDART, "currency"));
string mil = fuction.GetParameterByParaName(Const.PARA_MIL, "currency");
mil = fuction.ChangeAreaUnit(mil);
fuction.SaveXmlStr(XMLFile, Const.PARA_MIL, mil);
fuction.SaveXmlStr(XMLFile, Const.PARA_DEF, fuction.GetParameterByParaName(Const.PARA_DEF, "currency"));
string tempUserlimit = fuction.GetParameterByParaName(Const.PARA_USERLIMIT, "currency");
tempUserlimit = Fuction.m_UserResult == Const.RESULT_IN
? fuction.ReChangeAreaUnit(tempUserlimit)
: tempUserlimit;
string tempIPC = fuction.GetParameterByParaName(Const.PARA_IPC, "currency");
tempIPC = Fuction.m_UserResult == Const.RESULT_IN
? fuction.ReChangeAreaUnit(tempIPC)
: tempIPC;
fuction.SaveXmlStr(XMLFile, Const.PARA_USERLIMIT, tempUserlimit);
fuction.SaveXmlStr(XMLFile, Const.PARA_IPC, tempIPC);
//fuction.SaveXmlStr(XMLFile, Const.PARA_REVISETYPE, m_ParaReviseType);
//string temp_MaxData = Fuction.m_UserResult == Const.RESULT_IN
// ? fuction.ReChangeAreaUnit(MaxData.ToString())
// : MaxData.ToString();
//string temp_MinData = Fuction.m_UserResult == Const.RESULT_IN
// ? fuction.ReChangeAreaUnit(MinData.ToString())
// : MinData.ToString();
//string temp_AverageData = Fuction.m_UserResult == Const.RESULT_IN
// ? fuction.ReChangeAreaUnit(AverageData.ToString())
// : AverageData.ToString();
//fuction.SaveXmlStr(XMLFile, Const.TEST_MAX, temp_MaxData);
//fuction.SaveXmlStr(XMLFile, Const.TEST_MIN, temp_MinData);
//fuction.SaveXmlStr(XMLFile, Const.TEST_AVERAGE, temp_AverageData);
fuction.SaveXmlStr(XMLFile, Const.TEST_RESULT, ResultValue);
//fuction.SaveXmlStr(XMLFile, Const.PARA_HEATTEMP, m_ReadHeatTemp);
//fuction.SaveXmlStr(XMLFile, Const.PARA_ISHEAT, m_ifHeat);
fuction.SaveXmlStr(XMLFile, Const.PARA_TESTSOLVENT, m_TestSolvent);
fuction.SaveXmlStr(XMLFile, Const.PARA_TESTMODE, m_TestMode);
fuction.SaveXmlStr(XMLFile, Const.PARA_MILRESULT, resultMIL);
fuction.SaveXmlStr(XMLFile, Const.PARA_DEFRESULT, resultDEF);
fuction.SaveXmlStr(XMLFile, Const.PARA_NOTES, fuction.GetParameterByParaName(Const.PARA_NOTES, "currency"));
XMLEncrypt.EncryptData(XMLFile, directory, Keys, Keys);
fuction.SaveProductTest(product, startTime.ToString(), directory, "endValue", "endValue");
return Const.SUCCESS_EXPORT;
}
catch (Exception ex)
{
LOGGER.Warn(ex.StackTrace);
return Const.ERROR_EXPORT_FAILURE;
}
}
public string getImgBinary(string productName)
{
string root = Fuction.m_CurrentDirectory + Const.ProductRoot;
if (File.Exists(root + productName + @"\" + productName + Const.IMAGE + ".xml"))
{
System.IO.MemoryStream sm = new MemoryStream();
XmlDocument doc = new XmlDocument();
doc.Load(root + productName + @"\" + productName + Const.IMAGE + ".xml");
XmlNodeList NodeList = doc.GetElementsByTagName(Const.PRO_IMAGE);//得到节点列表
XmlNode ImageNode = NodeList[0];//得到该节点
string PicByte = ImageNode.InnerXml;//得到节点内的二进制代码
return PicByte;
}
else
{
return null;
}
}
private void ClosefrmSplash2()
{
BeginInvoke(new ClosefrmSplash2Delegate(CloseFrmSplash));
}
private void CloseFrmSplash()
{
frmSplash2.Close();
}
#endregion
#region 清洗
private void NewGetData(double rawData)
{
if(dgvTestRawData.InvokeRequired)
{
BeginInvoke(new AddDataGridView5Delegate(AddDataGridView5), rawData);
}
if (dgvTestResult.InvokeRequired)
{
BeginInvoke(new AddDataGridView1Delegate(AddDataGridView1));
}
if (zgcShowCurve.InvokeRequired)
{
BeginInvoke(new AddZedGraphControl1Delegate(AddZedGraphControl1));
}
}
private void AddDataGridView5(double rawData)
{
double testTime = (DateTime.Now - startTime).TotalSeconds;//当前测试时间
cleanData.Add(testTime,rawData);
DataRow cleanDataRow;
if (cleanData.Count % 10 == 0 && cleanData.Count != 0)
{
getLogestAandB();//获取AB
DtTestRawData.Clear();
DtTestRawData.Columns.Clear();
DtTestRawData = new DataTable();
DataColumnCollection columns = DtFilterRawData.Columns;
columns.Add(getMsg("FrmTestManageColTestTime"), typeof(System.Double));
columns.Add(getMsg("FrmTestManageColData"), typeof(System.Double));
double[] cleanDataKeys = cleanData.Keys.ToArray<double>();
for (int i = 0; i < cleanDataKeys.Length; i++)
{
cleanDataRow = DtFilterRawData.NewRow();
cleanDataRow[getMsg("FrmTestManageColTestTime")] = Convert.ToDouble(cleanDataKeys[i]);
double result = B * Convert.ToDouble(cleanDataKeys[i]) + A;
if (result < 0)
{
result = 0;
}
cleanDataRow[getMsg("FrmTestManageColData")] = Math.Round(result, 3);
DtTestRawData.Rows.Add(cleanDataRow);
}
}
else
{
cleanDataRow = DtTestRawData.NewRow();
cleanDataRow[getMsg("FrmTestManageColTestTime")] = Convert.ToInt32(testTime);
if (rawData < 0 && double.IsNaN(rawData))
{
rawData = 0;
}
cleanDataRow[getMsg("FrmTestManageColData")] = rawData;
}
showTestInfo();
}
private string resultMIL = "";
private string resultDEF = "";
private void AddDataGridView1()
{
double endValue=cleanData[cleanData.Count-1];
DataRow dr;
for (int j = 0; j < 7; j++)
{
dr = DtTestResult.NewRow();
if (j == 0)
{
dr[" "] = getMsg("FrmTestManageColEndData");
dr[getMsg("FrmTestResultNote")] = "";
dr[getMsg("FrmTestResultColEndData")] = endValue;
}
else if (j == 1)
{
dr[" "] = getMsg("frmProductrdBtn_MIL");
dr[getMsg("FrmTestResultNote")] = getMsg("frmProductlbl_MIL") + ":" + fuction.GetParameterByParaName(Const.PARA_MIL, "currency") + Fuction.m_UserLengthUnit + "²";
double mil = Fuction.m_UserResult == Const.RESULT_IN
?
Convert.ToDouble(fuction.ChangeAreaUnit(1.3.ToString()))
:
1.3;
if (MILValue < mil)
{
resultMIL = "pass";
}
else
{
resultMIL = "fail";
}
try
{
dr[getMsg("FrmTestResultColEndData")] = resultMIL;
}
catch (Exception ex)
{
LOGGER.Warn("table2" + ex.StackTrace);
}
}
else if (j == 2)
{
dr[" "] = getMsg("frmProductrdBtn_DEF");
dr[getMsg("FrmTestResultNote")] = getMsg("frmProductlbl_DEF") + ":" + fuction.GetParameterByParaName(Const.PARA_DEF, "currency") + "%";
double def = Fuction.m_UserResult == Const.RESULT_IN
?
Convert.ToDouble(fuction.ChangeAreaUnit(1.5.ToString()))
:
1.5;
if (DEFValue < def)
{
resultDEF = "pass";
}
else
{
resultDEF = "fail";
}
dr[getMsg("FrmTestResultColEndData")] = resultDEF;
}
else if (j == 3)
{
dr[" "] = getMsg("IPC");
dr[getMsg("FrmTestResultNote")] = getMsg("IPC") + ":" + fuction.GetParameterByParaName(Const.PARA_IPC, "currency") + "eq.µgNaCl/" + Fuction.m_UserLengthUnit + "²"; ;
string ParaIPC = fuction.GetParameterByParaName(Const.PARA_IPC, "currency");
ParaIPC = Fuction.m_UserResult == Const.RESULT_IN
? fuction.ChangeAreaUnit(ParaIPC)
: ParaIPC;
string result = "";
if (ParaIPC != "" && endValue < Convert.ToDouble(ParaIPC))
{
result = "pass";
}
else
{
result = "fail";
}
dr[getMsg("FrmTestResultColEndData")] = result;
}
else if (j == 4)
{
dr[" "] = getMsg("frmProductpckb_UserLimit");
dr[getMsg("FrmTestResultNote")] = getMsg("SettingUserLimit") + ":" + fuction.GetParameterByParaName(Const.PARA_USERLIMIT, "currency") + "eq.µgNaCl/" + Fuction.m_UserLengthUnit + "²"; ;
string ParUserLimit = fuction.GetParameterByParaName(Const.PARA_USERLIMIT, "currency");
ParUserLimit = Fuction.m_UserResult == Const.RESULT_IN
? fuction.ChangeAreaUnit(ParUserLimit)
: ParUserLimit;
string result = "";
if (ParUserLimit != "" && endValue < Convert.ToDouble(ParUserLimit))
{
result = "pass";
}
else
{
result = "fail";
}
dr[getMsg("FrmTestResultColEndData")] = result;
}
else if (j == 5)
{
dr[" "] = fuction.GetParameterByParaName(Const.PARA_ECName1, "currency");
dr[getMsg("FrmTestResultNote")] = getMsg("ECIs") + ":" + fuction.GetParameterByParaName(Const.PARA_EC1, "currency");
dr[getMsg("FrmTestResultColEndData")] = Convert.ToDouble(fuction.GetParameterByParaName(Const.PARA_EC1, "currency")) * endValue;
}
else if (j == 6)
{
dr[" "] = fuction.GetParameterByParaName(Const.PARA_ECName2, "currency");
dr[getMsg("FrmTestResultNote")] = getMsg("ECIs") + ":" + fuction.GetParameterByParaName(Const.PARA_EC2, "currency");
dr[getMsg("FrmTestResultColEndData")] = Convert.ToDouble(fuction.GetParameterByParaName(Const.PARA_EC2, "currency")) * endValue;
}
DtTestResult.Rows.Add(dr);
}
GetDataGrideValue(dgvTestInfo, DtTestResult);
}
private void AddZedGraphControl1()
{
DataSourcePointList listCleanData = new DataSourcePointList();
listCleanData.DataSource = DtTestRawData;
listCleanData.XDataMember = getMsg("FrmTestManageColTestTime");
listCleanData.YDataMember = getMsg("FrmTestManageColData");
GetZedGraphControlValue(zgcShowCurve, listCleanData);
}
private void GetDataGrideValue(DataGridView dg, DataTable table)
{
if (dg.Name.Equals("DtTestRawData") || dg.Name.Equals("DtFilterRawData"))//原始数据
{
DataTable dt1 = table.Copy();
for (int i = 0; i < dt1.Rows.Count; i++)
{
dt1.Rows[i][getMsg("FrmTestResultColData")] = Convert.ToDouble(dt1.Rows[i][getMsg("FrmTestResultColData")]).ToString("#0.000");
}
dg.DataSource = dt1;
}
else
{
dg.DataSource = table;
}
if (isTest)
{
DataGridViewCellStyle dataGridViewCellStyle0 = CreatDataGridViewCellStyle();
for (int i = 0; i < dg.Columns.Count; i++)
{
CreatColumn(dg.Columns[i], dataGridViewCellStyle0, table.Columns[i].ColumnName);
if (i == 2)
{
dg.Columns[i].Width = dg.Columns[i].Width + 100;
}
}
}
if (dg.Name.Equals("DtFilterRawData") || dg.Name.Equals("DtTestRawData"))
{
dg.Focus();
dg.CurrentCell = dg.Rows[dg.Rows.Count - 1].Cells[0];
dg.Rows[dg.Rows.Count - 1].Selected = true;
}
}
private void GetZedGraphControlValue(ZedGraphControl zg, DataSourcePointList list1)
{
LineItem myCurce1;
zg.GraphPane.Title.Text = Fuction.m_Language == Const.LANGUAGE_CHINESE
?
"离子污染度"
:
"Ionic Contamination";
zg.GraphPane.Title.FontSpec.FontColor = Color.Black;
zg.GraphPane.Title.FontSpec.Family = "微软雅黑";
zg.GraphPane.XAxis.Title.Text = Fuction.m_Language == Const.LANGUAGE_CHINESE
?
"时间(" + Fuction.m_UserTimeUnit + ")"
:
"Time(" + Fuction.m_UserTimeUnit + ")";
zg.GraphPane.XAxis.Title.FontSpec.FontColor = Color.Black;
zg.GraphPane.XAxis.Title.FontSpec.Family = "微软雅黑";
zg.GraphPane.XAxis.Type = AxisType.Ordinal;
//zg.GraphPane.XAxis.Scale.Format = XDate.DefaultFormatStr;
zg.GraphPane.XAxis.MajorGrid.IsVisible = true;
zg.GraphPane.YAxis.MajorGrid.IsVisible = true;
zg.GraphPane.YAxis.Title.Text = Fuction.m_Language == Const.LANGUAGE_CHINESE
?
"离子污染度(" + Fuction.m_UserResult + ")"
:
"Ionic Contamination(" + Fuction.m_UserResult + ")";
zg.GraphPane.YAxis.Title.FontSpec.FontColor = Color.Black;
zg.GraphPane.YAxis.Title.FontSpec.Family = "微软雅黑";
zg.GraphPane.Fill.Color = Color.FromArgb(215, 227, 242);
zg.GraphPane.Chart.Fill.Color = Color.FromArgb(215, 227, 242);
zg.IsShowPointValues = true;
if (DtTestRawData.Rows.Count > 0)
{
zg.GraphPane.XAxis.Scale.Max = Convert.ToInt32(DtTestRawData.Rows[DtTestRawData.Rows.Count - 1][getMsg("FrmTestManageColTestTime")]);
}
else
{
zg.GraphPane.XAxis.Scale.Max = Convert.ToInt32(DtTestRawData.Rows[0][getMsg("FrmTestManageColTestTime")]);
}
zg.GraphPane.YAxis.Scale.Min = 0;
zg.GraphPane.CurveList.Clear();
string label = Fuction.m_Language == Const.LANGUAGE_CHINESE
?
"污染度曲线"
:
"Contamination Curve";
myCurce1 = zg.GraphPane.AddCurve(label, list1, Color.Red, SymbolType.None);
myCurce1.IsOverrideOrdinal = true;
myCurce1.Line.IsSmooth = true;
zg.AxisChange();
zg.Refresh();
}
private void CreatColumn(DataGridViewColumn Column, DataGridViewCellStyle CellStyle, string Name)
{
Column.DefaultCellStyle = CellStyle;
Column.FillWeight = 40F;
Column.Name = Name;
Column.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
Column.Width = 200;
}
#endregion
#region 拟合获取参数
//获取一次方程拟合参数
private void getlinearAandB()
{
double[] x = new double[filterData.Count];
double[] y = new double[filterData.Count];
//将数据进行排序
double[] sortFilterTime = filterData.Keys.ToArray<double>();
for (int i = 0; i < sortFilterTime.Length; i++)
{
x[i] = Convert.ToDouble(sortFilterTime[i]);
y[i] = filterData[sortFilterTime[i]];
}
double[] ratio = new double[2];
ratio = FittingFunction.linear(y, x);//返回常数,系数
if (double.IsNaN(ratio[0]))
{
A = 1;
B = 1;
}
else
{
A = ratio[0];//常数
B = ratio[1];//系数
}
}
private void getLogestAandB(){
double[] x = new double[cleanData.Count];
double[] y = new double[cleanData.Count];
//将数据进行排序
double[] sortFilterTime = cleanData.Keys.ToArray<double>();
for (int i = 0; i < sortFilterTime.Length; i++)
{
x[i] = Convert.ToDouble(sortFilterTime[i]);
y[i] = filterData[sortFilterTime[i]];
}
double[] ratio = new double[2];
ratio = FittingFunction.Logest(y, x);//返回常数,系数
if (double.IsNaN(ratio[0]))
{
A = 1;
B = 1;
}
else
{
A = ratio[0];//常数
B = ratio[1];//系数
}
}
#endregion
#region 关闭窗口
private void closeForm()
{
CloseRead();
if (this.ParentForm is MetroDynamicTesting)
{
MetroDynamicTesting parentForm = (MetroDynamicTesting)this.Parent.TopLevelControl;
ParentForm.Close();
}
else if (this.ParentForm is MetroStaticTesting)
{
MetroStaticTesting parentForm = (MetroStaticTesting)this.Parent.TopLevelControl;
ParentForm.Close();
}
MetroMDI mm = new MetroMDI(_loginManager);
mm.ShowInTaskbar = true;
mm.Show();
mm.Activate();
}
public void CloseRead()
{
theMachine.RemoveClients(this);
theMachine.CloseConnection();
}
#endregion
public void CutOffTest()
{
//判断其是否开始清洗
timerTest.Stop();
stopReading();
if (isTest)//如果开始测试,结束测试后保存已有数据
{
if (ShowMessageBox.ShowQuestion(Const.MESSAGEBOX_TITLE_NOTE, Const.IS_SAVE_TEST))
{
SaveFileQuestion();
}
else
{
closeForm();
}
}
else
{
closeForm();
}
}
private void stopReading()
{
if (timerTest != null)
{
timerTest.Stop();
}
if (timerInit != null)
{
timerInit.Stop();
}
if (theMachine != null && theMachine.ItsSerialPort != null && theMachine.ItsClietns.Count > 0)
{
theMachine.StopReading();//终止测试
//关闭Y0,Y1,Y2,有Null异常,需要加判断
if (theMachine.GetControllor != null)
{
if (("PLC").Equals(Fuction.m_ParaReadDataType))
{
theMachine.GetControllor.CloseY2();
System.Threading.Thread.Sleep(1500);
theMachine.GetControllor.CloseY1();
System.Threading.Thread.Sleep(1500);
theMachine.GetControllor.CloseY0();
}
else if (("IO").Equals(Fuction.m_ParaReadDataType))
{
theMachine.GetControllor.CloseAll();
LOGGER.Info("IO CloseAll");
}
}
CloseRead();
}
}
}
}