随笔 - 16  文章 - 0  评论 - 11  阅读 - 28254 

简单介绍一下项目背景:

大家喜爱的葡萄酒需要经过原料选择→分选→去梗→破碎→消毒→前发酵→压榨→调整酒度→后发酵→贮藏→沉清过滤→装瓶、杀菌这几个过程,

保温发酵控制系统是其中重要一环,葡萄酒经过前期工艺后,在发酵罐常期进行发酵,温度必须保证在一定范围,温度高时需要制冷。温度高了需要

进行搅拌,不至于结冰。往复的过程。

在项目中运用到数据库、多线程、现场采集、液位显示等。

动态显示每个发酵罐或者保温罐相关信息与参数,可以设定制定控制还是手动控制。

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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ZedGraph;
 
namespace work
{
    public partial class FormDisplay : Form
    {
        // Starting time in milliseconds
        int tickStart = 0;
        string obj_gh;
        string device;
        public DataSet ds;
        private System.Windows.Forms.DataGridTableStyle ts;
        public FormDisplay(string gh)
        {
            obj_gh = gh;
        
            InitializeComponent();
        }
        private void FillData(string gh)
        {
            DataSet dsmatno;
            string selectmatno = " select mname from matno ";
            selectmatno = selectmatno + " order by matnoid desc";
            dsmatno = Narnu.GetDataSetByOleDbString(selectmatno);
            cb_pm.DataSource = dsmatno.Tables[0];
            cb_pm.DisplayMember = "mname";
            datagrid.TableStyles.Clear();
            ts = new DataGridTableStyle();
            ts.RowHeadersVisible = false;
 
            DataSet ds;
            string selectgh = " select * from wd ";
            selectgh =selectgh + " where gh = '" + gh.ToString()+  "'" + " order by tkdat1 desc";
            ds = Narnu.GetDataSetByOleDbString(selectgh);
 
            ts.MappingName = ds.Tables[0].TableName;
            //ts.AlternatingBackColor = Color.LightSkyBlue;
            ts.AllowSorting = false;
            //id, palno, addre, addre_desc, trans, trans_ssj, trans_ddj, deviceno,
            //xd, statu, deviceno_desc, port, port_desc, ssj, ddj, pri, error, fflag, tkdat
            setcolumn("gh", "罐号", 120);
            setcolumn("op", "操作", 120);
            setcolumn("sdwd", "设定温度", 120);
            setcolumn("sjwd1", "高位温度", 120);
            setcolumn("sjwd2", "低位温度", 120);
            setcolumn("tkdat1", "时间", 120);
            setcolumn("deviceno", "设备号", 40);
            setcolumn("trans", "电报", 150);
            setcolumn("statu", "状态", 50);
            setcolumn("error", "故障信息", 150);
            setcolumn("tkdat", "产生时间", 120);
            setcolumn("xd", "巷道", 50);
            setcolumn("port", "口地址", 50);
            setcolumn("if_do", "状态", 40);
            setcolumn("alock", "锁定状态", 40);
            setcolumn("sectn", "库区", 40);
 
 
            datagrid.TableStyles.Add(ts);
            this.datagrid.DataSource = ds.Tables[0];
            this.dataGridView1.DataSource = ds.Tables[0];
        }
        private void FillDataTk(string gh,DateTime tk)
        {
 
            datagrid.TableStyles.Clear();
            ts = new DataGridTableStyle();
            ts.RowHeadersVisible = false;
 
            DataSet ds;
            string selectgh = " select * from wd ";
            selectgh = selectgh + " where gh = '" + gh.ToString() + "'" + " and tkdat1>=Cdate('" + tk + "')" + " order by tkdat1 desc";
          
            ds = Narnu.GetDataSetByOleDbString(selectgh);
 
            ts.MappingName = ds.Tables[0].TableName;
            //ts.AlternatingBackColor = Color.LightSkyBlue;
            ts.AllowSorting = false;
            //id, palno, addre, addre_desc, trans, trans_ssj, trans_ddj, deviceno,
            //xd, statu, deviceno_desc, port, port_desc, ssj, ddj, pri, error, fflag, tkdat
            setcolumn("sdwd", "设定温度", 120);
            setcolumn("sjwd1", "高位温度", 120);
            setcolumn("sjwd2", "低位温度", 120);
            setcolumn("gh", "罐号", 120);
            setcolumn("op", "操作", 120);
            setcolumn("tkdat1", "时间", 120);
            setcolumn("deviceno", "设备号", 40);
            setcolumn("trans", "电报", 150);
            setcolumn("statu", "状态", 50);
            setcolumn("error", "故障信息", 150);
            setcolumn("tkdat", "产生时间", 120);
            setcolumn("xd", "巷道", 50);
            setcolumn("port", "口地址", 50);
            setcolumn("if_do", "状态", 40);
            setcolumn("alock", "锁定状态", 40);
            setcolumn("sectn", "库区", 40);
 
 
            datagrid.TableStyles.Add(ts);
            this.datagrid.DataSource = ds.Tables[0];
            this.dataGridView1.DataSource = ds.Tables[0];
        }
        private void setcolumn(string name, string text, int width)
        {
            DataGridTextBoxColumn C = new DataGridTextBoxColumn();
            //          DataGridColumnStyle CStyle = new DataGridColumnStyle();
            //youFirstFieldName是你的Table里的某个字段名 
            C.MappingName = name;
            //youHeaderName是你希望将上面这个字段显示在DataGrid里时的标题
            C.HeaderText = text;
            C.Width = width;
            C.Alignment = HorizontalAlignment.Center;
            //响应鼠标单击与双击事件
            //          C.TextBox.MouseDown += new MouseEventHandler(TextBoxMouseDownHandler);
 
            ts.GridColumnStyles.Add(C);
            C.Dispose();
        }
 
        private void Form1_Load( object sender, EventArgs e )
        {
            // TODO: 这行代码将数据加载到表“bookShopDataSet.wd”中。您可以根据需要移动或移除它。
            //this.wdTableAdapter.Fill(this.bookShopDataSet.wd);
            //foreach (Form froms in this)//检查窗体是否存在
            //{
            //    if (froms is work.FormDisplay)
            //    {
            //        froms.Focus();//获得焦点
            //        return;//退出过程
            //    }
            //}
           // MessageBox.Show(obj_gh);
            dateTimePicker1.Value = DateTime.Now.AddDays(-1);
            string gh = "";
            lb_gh.Text = obj_gh.Substring(0, 4).ToUpper() ;
            gh = obj_gh.Substring(0, 4).ToUpper();
            device = obj_gh.Substring(5, 2);
           // MessageBox.Show(device);
            GraphPane myPane = zedGraphControl1.GraphPane;
            myPane.Title.Text = "温度实时曲线\n";
            myPane.XAxis.Title.Text = "时间, 秒";
            myPane.YAxis.Title.Text = "温度";
            old_wd.Text = MainForm.pMainWin.sdwd[Convert.ToInt32(device) - 1];
            sd_wd.Text = MainForm.pMainWin.sdwd[Convert.ToInt32(device) - 1];
            // Save 1200 points.  At 50 ms sample rate, this is one minute
            // The RollingPointPairList is an efficient storage class that always
            // keeps a rolling set of point data without needing to shift any data values
            //设置1200个点,假设每50毫秒更新一次,刚好检测1分钟
            //一旦构造后将不能更改这个值
            RollingPointPairList list = new RollingPointPairList( 1200 );
 
            // Initially, a curve is added with no data points (list is empty)
            // Color is blue, and there will be no symbols
            //开始,增加的线是没有数据点的(也就是list为空)
            //增加一条名称:Voltage,颜色Color.Bule,无符号,无数据的空线条
            LineItem curve = myPane.AddCurve( "温度", list, Color.Blue, SymbolType.None );
 
            // Sample at 50ms intervals
            //设置timer控件的间隔为50毫秒
 
            timer1.Interval = 50;
            timer1.Enabled = true;
            timer1.Start();
 
            // Just manually control the X axis range so it scrolls continuously
            // instead of discrete step-sized jumps
            myPane.XAxis.Scale.Min = 0;
            //X轴最小值0
            myPane.XAxis.Scale.Max = 30;
            //X轴最大30
            myPane.XAxis.Scale.MinorStep = 1;
            //X轴小步长1,也就是小间隔
            myPane.XAxis.Scale.MajorStep = 5;
            //X轴大步长为5,也就是显示文字的大间隔
 
            // Scale the axes
            //改变轴的刻度
            zedGraphControl1.AxisChange();
     
            // Save the beginning time for reference
            //保存开始时间
            tickStart = Environment.TickCount;
 
            //
            DataSet ds;
            string selectgh = " select * from gh where gh = '" + gh + "'" + " and finish='" + "1" + "' order by tkdat1 desc";
            ds = Narnu.GetDataSetByOleDbString(selectgh);
            if (ds.Tables["gh"].Rows.Count == 0)
            {
                cb_pm.Text = "";
                tb_batch.Text = "";
                bt_st.Enabled = true;
                bt_com.Enabled = false;
                //cb_pm
            }
            else
            {
                cb_pm.Text = ds.Tables["gh"].Rows[0][6].ToString();
                tb_batch.Text = ds.Tables["gh"].Rows[0][5].ToString();
                bt_st.Enabled = false;
                bt_com.Enabled = true;
            }
            FillData(gh.ToString());
            //string gh = "";
            lb_gh.Text = obj_gh.Substring(0, 4).ToUpper();
            gh = obj_gh.Substring(0, 4).ToUpper();
            device = obj_gh.Substring(5, 2);
            DateTime tk;
            //DataSet ds;
            tk = Convert.ToDateTime(dateTimePicker1.Value);
            // selectgh = " select * from gh where gh = '" + gh + "'" + " and tkdat1>=Cdate('" + tk + "')" + " and finish='" + "1" + "' order by tkdat1 desc";
            //ds = Narnu.GetDataSetByOleDbString(selectgh);
            //if (ds.Tables["gh"].Rows.Count == 0)
            //{
            //    cb_pm.Text = "";
            //    tb_batch.Text = "";
            //    bt_st.Enabled = true;
            //    bt_com.Enabled = false;
            //    //cb_pm
            //}
            //else
            //{
            //    cb_pm.Text = ds.Tables["gh"].Rows[0][6].ToString();
            //    tb_batch.Text = ds.Tables["gh"].Rows[0][5].ToString();
            //    bt_st.Enabled = false;
            //    bt_com.Enabled = true;
            //}
            FillDataTk(gh.ToString(), tk);
                 
        }
 
        private void timer1_Tick( object sender, EventArgs e )
        {
            if (MainForm.pMainWin.zhileng[Convert.ToInt32(device)-1] == 1)
            {
                if (sg22_17_01.State != LBSoft.IndustrialCtrls.Leds.LBLed.LedState.Blink)
                {
                    sg22_17_01.State = LBSoft.IndustrialCtrls.Leds.LBLed.LedState.Blink;
                }
            }
            if (MainForm.pMainWin.zhileng[Convert.ToInt32(device)-1] == 0)
            {
                sg22_17_01.State = LBSoft.IndustrialCtrls.Leds.LBLed.LedState.Off;
                //LBSoft.IndustrialCtrls.Leds.LBLed.LedState.Off; ;
            }
            if (MainForm.pMainWin.jiaoban[Convert.ToInt32(device)-1] == 1)
            {
                if (sf09_12_dj.State != LBSoft.IndustrialCtrls.Leds.LBLed.LedState.Blink)
                {
                    sf09_12_dj.State = LBSoft.IndustrialCtrls.Leds.LBLed.LedState.Blink;
                }
            }
            if (MainForm.pMainWin.jiaoban[Convert.ToInt32(device)-1] == 0)
            {
                sf09_12_dj.State = LBSoft.IndustrialCtrls.Leds.LBLed.LedState.Off;
            }
            // Make sure that the curvelist has at least one curve
            //确保CurveList不为空
            double var=3;
            var = Convert.ToDouble(MainForm.pMainWin.sjwd1[Convert.ToInt32(device)-1]);
            if ( zedGraphControl1.GraphPane.CurveList.Count <= 0 )
                return;
 
            // Get the first CurveItem in the graph
            //取Graph第一个曲线,也就是第一步:在GraphPane.CurveList集合中查找CurveItem
            LineItem curve = zedGraphControl1.GraphPane.CurveList[0] as LineItem;
            if ( curve == null )
                return;
 
            // Get the PointPairList
            //第二步:在CurveItem中访问PointPairList(或者其它的IPointList),根据自己的需要增加新数据或修改已存在的数据
            IPointListEdit list = curve.Points as IPointListEdit;
            // If this is null, it means the reference at curve.Points does not
            // support IPointListEdit, so we won't be able to modify it
            if ( list == null )
                return;
 
            // Time is measured in seconds
            double time = ( Environment.TickCount - tickStart ) / 10000.0;
 
            // 3 seconds per cycle
            //list.Add( time, Math.Sin( 2.0 * Math.PI * time / 3.0 ) );
            list.Add(time,var);
            //var = MainForm.pMainWin.
            // Keep the X scale at a rolling 30 second interval, with one
            // major step between the max X value and the end of the axis
            Scale xScale = zedGraphControl1.GraphPane.XAxis.Scale;
            if ( time > xScale.Max - xScale.MajorStep )
            {
                xScale.Max = time + xScale.MajorStep;
                xScale.Min = xScale.Max - 30.0;
            }
 
            // Make sure the Y axis is rescaled to accommodate actual data
            //第三步:调用ZedGraphControl.AxisChange()方法更新X和Y轴的范围
            zedGraphControl1.AxisChange();
            // Force a redraw
            //第四步:调用Form.Invalidate()方法更新图表
            zedGraphControl1.Invalidate();
        }
 
        private void Form1_Resize( object sender, EventArgs e )
        {
            //SetSize();
        }
 
        // Set the size and location of the ZedGraphControl
        private void SetSize()
        {
           
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            string device_write="";
            int deviceno;
            deviceno = Convert.ToInt32(device);
            
            if (deviceno == 1)
            {
                device_write = "64";
            }
            if (deviceno == 2)
            {
                device_write = "65";
            }
            if (deviceno == 3)
            {
                device_write = "66";
            }
            if (deviceno == 4)
            {
                device_write = "67";
            }
 
            if (deviceno == 5)
            {
                device_write = "44";
            }
            if (deviceno == 6)
            {
                device_write = "45";
            }
            if (deviceno == 7)
            {
                device_write = "46";
            }
            if (deviceno == 8)
            {
                device_write = "47";
            }
 
            if (deviceno == 9)
            {
                device_write = "52";
            }
            if (deviceno == 10)
            {
                device_write = "53";
            }
            if (deviceno == 11)
            {
                device_write = "54";
            }
            if (deviceno == 12)
            {
                device_write = "55";
            }
 
            if (deviceno == 13)
            {
                device_write = "60";
            }
            if (deviceno == 14)
            {
                device_write = "61";
            }
            if (deviceno == 15)
            {
                device_write = "62";
            }
            if (deviceno == 16)
            {
                device_write = "63";
            }
 
            if (deviceno == 17)
            {
                device_write = "68";
            }
            if (deviceno == 18)
            {
                device_write = "69";
            }
            if (deviceno == 19)
            {
                device_write = "70";
            }
            if (deviceno == 20)
            {
                device_write = "71";
            }
           
            DialogResult result = MainForm.pMainWin.ls_IniFile.ShowDeleteAlert("是否关闭电磁阀" + "\r");
            if (result == DialogResult.No)
            {
                return;
            }
            MainForm.pMainWin.objPlc1.Writeplc(device_write, "0");
 
            string tkdat1 = "";
            string tkdat2 = "";
            string userid = "admin";
            string pm = "";
            string batch = "";
            string gh = "";
            string SetValue;
            string insertgh;
            string sdwd_t = "";
            string sjwd1_t = "";
            string sjwd2_t = "";
            string yali_t = "";
            string op_t = "";
            op_t ="关闭电磁阀";
            //string updategh = "update gh set " + "pm ='" + pm + "'," + "gh='" + gh + "'," + "batch='" + batch + "'," + "tkdat1='" + tkdat1 + "'," + "tkdat2='" + tkdat2 + "'," + "userid='" + userid + "' where gh ='" +gh + "'";
              tkdat1 = DateTime.Now.ToString();
                tkdat2 = DateTime.Now.ToString();
                gh = obj_gh.Substring(0, 4).ToUpper();
                yali_t = MainForm.pMainWin.yl[Convert.ToInt32(device) - 1]; ;
                sdwd_t = MainForm.pMainWin.sdwd[Convert.ToInt32(device) - 1]; ;
                sjwd1_t = MainForm.pMainWin.sjwd1[Convert.ToInt32(device) - 1]; ;
                sjwd2_t = MainForm.pMainWin.sjwd2[Convert.ToInt32(device) - 1]; ;
                 
                SetValue = "('" + pm + "','" + gh + "','" + batch + "','" + tkdat1 + "','" + tkdat2 + "','" + userid + "','" + "1" + "','" + yali_t + "','" + sdwd_t + "','" + sjwd1_t + "','"+ op_t + "','" + sjwd2_t + "')";
                insertgh = "insert into wd (pm,gh,batch,tkdat1,tkdat2,userid,finish,yl,sdwd,sjwd1,op,sjwd2) values " + SetValue;
                try
                {
                    Narnu.DoOleDbString(insertgh);
 
                }
                catch (Exception ex)
                {
 
                    MainForm.pMainWin.ls_IniFile.WriteLog("write1", ex.Message.ToString());
                    return;
                }
           
        }
 
        private void button5_Click(object sender, EventArgs e)
        {
            string device_write = "";
            int deviceno;
            deviceno = Convert.ToInt32(device);
 
            if (deviceno == 1)
            {
                device_write = "64";
            }
            if (deviceno == 2)
            {
                device_write = "65";
            }
            if (deviceno == 3)
            {
                device_write = "66";
            }
            if (deviceno == 4)
            {
                device_write = "67";
            }
 
            if (deviceno == 5)
            {
                device_write = "44";
            }
            if (deviceno == 6)
            {
                device_write = "45";
            }
            if (deviceno == 7)
            {
                device_write = "46";
            }
            if (deviceno == 8)
            {
                device_write = "47";
            }
 
            if (deviceno == 9)
            {
                device_write = "52";
            }
            if (deviceno == 10)
            {
                device_write = "53";
            }
            if (deviceno == 11)
            {
                device_write = "54";
            }
            if (deviceno == 12)
            {
                device_write = "55";
            }
 
            if (deviceno == 13)
            {
                device_write = "60";
            }
            if (deviceno == 14)
            {
                device_write = "61";
            }
            if (deviceno == 15)
            {
                device_write = "62";
            }
            if (deviceno == 16)
            {
                device_write = "63";
            }
 
            if (deviceno == 17)
            {
                device_write = "68";
            }
            if (deviceno == 18)
            {
                device_write = "69";
            }
            if (deviceno == 19)
            {
                device_write = "70";
            }
            if (deviceno == 20)
            {
                device_write = "71";
            }
            //device
            //zhileng[0] = Convert.ToInt32(objPlc1.ReadPlc("64"));
            //MessageBox.Show(zhileng[0].ToString());
            //zhileng[1] = Convert.ToInt32(objPlc1.ReadPlc("65"));
            //zhileng[2] = Convert.ToInt32(objPlc1.ReadPlc("66"));
            //zhileng[3] = Convert.ToInt32(objPlc1.ReadPlc("67"));
 
            //zhileng[4] = Convert.ToInt32(objPlc1.ReadPlc("44"));
            //zhileng[5] = Convert.ToInt32(objPlc1.ReadPlc("45"));
            //zhileng[6] = Convert.ToInt32(objPlc1.ReadPlc("46"));
            //zhileng[7] = Convert.ToInt32(objPlc1.ReadPlc("47"));
 
            //zhileng[8] = Convert.ToInt32(objPlc1.ReadPlc("52"));
            //zhileng[9] = Convert.ToInt32(objPlc1.ReadPlc("53"));
            //zhileng[10] = Convert.ToInt32(objPlc1.ReadPlc("54"));
            //zhileng[11] = Convert.ToInt32(objPlc1.ReadPlc("55"));
 
            //zhileng[12] = Convert.ToInt32(objPlc1.ReadPlc("60"));
            //zhileng[13] = Convert.ToInt32(objPlc1.ReadPlc("61"));
            //zhileng[14] = Convert.ToInt32(objPlc1.ReadPlc("62"));
            //zhileng[15] = Convert.ToInt32(objPlc1.ReadPlc("63"));
 
            //zhileng[16] = Convert.ToInt32(objPlc1.ReadPlc("68"));
            //zhileng[17] = Convert.ToInt32(objPlc1.ReadPlc("69"));
            //zhileng[18] = Convert.ToInt32(objPlc1.ReadPlc("70"));
            //zhileng[19] = Convert.ToInt32(objPlc1.ReadPlc("71"));
            DialogResult result = MainForm.pMainWin.ls_IniFile.ShowDeleteAlert("是否开启电磁阀" + "\r");
            if (result == DialogResult.No)
            {
                return;
            }
            MainForm.pMainWin.objPlc1.Writeplc(device_write, "1");
 
            string tkdat1 = "";
            string tkdat2 = "";
            string userid = "admin";
            string pm = "";
            string batch = "";
            string gh = "";
            string SetValue;
            string insertgh;
            string sdwd_t = "";
            string sjwd1_t = "";
            string sjwd2_t = "";
            string yali_t = "";
            string op_t = "";
            op_t = "开启电磁阀";
            //string updategh = "update gh set " + "pm ='" + pm + "'," + "gh='" + gh + "'," + "batch='" + batch + "'," + "tkdat1='" + tkdat1 + "'," + "tkdat2='" + tkdat2 + "'," + "userid='" + userid + "' where gh ='" +gh + "'";
            tkdat1 = DateTime.Now.ToString();
            tkdat2 = DateTime.Now.ToString();
            gh = obj_gh.Substring(0, 4).ToUpper();
            yali_t = MainForm.pMainWin.yl[Convert.ToInt32(device) - 1]; ;
            sdwd_t = MainForm.pMainWin.sdwd[Convert.ToInt32(device) - 1]; ;
            sjwd1_t = MainForm.pMainWin.sjwd1[Convert.ToInt32(device) - 1]; ;
            sjwd2_t = MainForm.pMainWin.sjwd2[Convert.ToInt32(device) - 1]; ;
 
            SetValue = "('" + pm + "','" + gh + "','" + batch + "','" + tkdat1 + "','" + tkdat2 + "','" + userid + "','" + "1" + "','" + yali_t + "','" + sdwd_t + "','" + sjwd1_t + "','" + op_t + "','" + sjwd2_t + "')";
            insertgh = "insert into wd (pm,gh,batch,tkdat1,tkdat2,userid,finish,yl,sdwd,sjwd1,op,sjwd2) values " + SetValue;
            try
            {
                Narnu.DoOleDbString(insertgh);
 
            }
            catch (Exception ex)
            {
 
                MainForm.pMainWin.ls_IniFile.WriteLog("write1", ex.Message.ToString());
                return;
            }
        }
 
        private void button4_Click(object sender, EventArgs e)
        {
            string device_write="";
            int deviceno;
            deviceno = Convert.ToInt32(device);
            if (deviceno == 1)
            {
                device_write="30";
            }
            if (deviceno == 2)
            {
                device_write="31";
            }
            if (deviceno == 3)
            {
                device_write="32";
            }
            if (deviceno == 4)
            {
                device_write="33";
            }
            if (deviceno == 5)
            {
                device_write="34";
            }
            if (deviceno == 6)
            {
                device_write="35";
            }
            if (deviceno == 7)
            {
                device_write = "36";
            }
            if (deviceno == 8)
            {
                device_write="37";
            }
 
            if (deviceno ==9)
            {
                device_write="40";
            }
            if (deviceno == 10)
            {
                device_write="41";
            }
            if (deviceno == 11)
            {
                device_write = "42";
            }
            if (deviceno == 12)
            {
                device_write = "43";
            }
 
            if (deviceno == 13)
            {
                device_write = "48";
            }
            if (deviceno == 14)
            {
                device_write = "49";
            }
            if (deviceno == 15)
            {
                device_write = "50";
            }
            if (deviceno == 16)
            {
                device_write = "51";
            }
 
            if (deviceno == 17)
            {
                device_write = "56";
            }
            if (deviceno == 18)
            {
                device_write = "57";
            }
            if (deviceno == 19)
            {
                device_write = "58";
            }
            if (deviceno == 20)
            {
                device_write = "59";
            }
            //device
            //jiaoban[0] = Convert.ToInt32(objPlc1.ReadPlc("30"));
            //jiaoban[1] = Convert.ToInt32(objPlc1.ReadPlc("31"));
            //jiaoban[2] = Convert.ToInt32(objPlc1.ReadPlc("32"));
            //jiaoban[3] = Convert.ToInt32(objPlc1.ReadPlc("33"));
            //jiaoban[4] = Convert.ToInt32(objPlc1.ReadPlc("34"));
            //jiaoban[5] = Convert.ToInt32(objPlc1.ReadPlc("35"));
            //jiaoban[6] = Convert.ToInt32(objPlc1.ReadPlc("36"));
            //jiaoban[7] = Convert.ToInt32(objPlc1.ReadPlc("37"));
 
            //jiaoban[8] = Convert.ToInt32(objPlc1.ReadPlc("40"));
            //jiaoban[9] = Convert.ToInt32(objPlc1.ReadPlc("41"));
            //jiaoban[10] = Convert.ToInt32(objPlc1.ReadPlc("42"));
            //jiaoban[11] = Convert.ToInt32(objPlc1.ReadPlc("43"));
 
            //jiaoban[12] = Convert.ToInt32(objPlc1.ReadPlc("48"));
            //jiaoban[14] = Convert.ToInt32(objPlc1.ReadPlc("50"));
            //jiaoban[15] = Convert.ToInt32(objPlc1.ReadPlc("51"));
 
            //jiaoban[16] = Convert.ToInt32(objPlc1.ReadPlc("56"));
            //jiaoban[17] = Convert.ToInt32(objPlc1.ReadPlc("57"));
            //jiaoban[18] = Convert.ToInt32(objPlc1.ReadPlc("58"));
            //jiaoban[19] = Convert.ToInt32(objPlc1.ReadPlc("59"));
            DialogResult result = MainForm.pMainWin.ls_IniFile.ShowDeleteAlert("是否关闭搅拌" + "\r");
            if (result == DialogResult.No)
            {
                return;
            }
            MainForm.pMainWin.objPlc1.Writeplc(device_write, "0");
 
            string tkdat1 = "";
            string tkdat2 = "";
            string userid = "admin";
            string pm = "";
            string batch = "";
            string gh = "";
            string SetValue;
            string insertgh;
            string sdwd_t = "";
            string sjwd1_t = "";
            string sjwd2_t = "";
            string yali_t = "";
            string op_t = "";
            op_t = "关闭搅拌";
            //string updategh = "update gh set " + "pm ='" + pm + "'," + "gh='" + gh + "'," + "batch='" + batch + "'," + "tkdat1='" + tkdat1 + "'," + "tkdat2='" + tkdat2 + "'," + "userid='" + userid + "' where gh ='" +gh + "'";
            tkdat1 = DateTime.Now.ToString();
            tkdat2 = DateTime.Now.ToString();
            gh = obj_gh.Substring(0, 4).ToUpper();
            yali_t = MainForm.pMainWin.yl[Convert.ToInt32(device) - 1]; ;
            sdwd_t = MainForm.pMainWin.sdwd[Convert.ToInt32(device) - 1]; ;
            sjwd1_t = MainForm.pMainWin.sjwd1[Convert.ToInt32(device) - 1]; ;
            sjwd2_t = MainForm.pMainWin.sjwd2[Convert.ToInt32(device) - 1]; ;
 
            SetValue = "('" + pm + "','" + gh + "','" + batch + "','" + tkdat1 + "','" + tkdat2 + "','" + userid + "','" + "1" + "','" + yali_t + "','" + sdwd_t + "','" + sjwd1_t + "','" + op_t + "','" + sjwd2_t + "')";
            insertgh = "insert into wd (pm,gh,batch,tkdat1,tkdat2,userid,finish,yl,sdwd,sjwd1,op,sjwd2) values " + SetValue;
            try
            {
                Narnu.DoOleDbString(insertgh);
 
            }
            catch (Exception ex)
            {
 
                MainForm.pMainWin.ls_IniFile.WriteLog("write1", ex.Message.ToString());
                return;
            }
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
            string device_write="";
            int deviceno;
            deviceno = Convert.ToInt32(device);
            if (deviceno == 1)
            {
                device_write = "30";
            }
            if (deviceno == 2)
            {
                device_write = "31";
            }
            if (deviceno == 3)
            {
                device_write = "32";
            }
            if (deviceno == 4)
            {
                device_write = "33";
            }
            if (deviceno == 5)
            {
                device_write = "34";
            }
            if (deviceno == 6)
            {
                device_write = "35";
            }
            if (deviceno == 7)
            {
                device_write = "36";
            }
            if (deviceno == 8)
            {
                device_write = "37";
            }
 
            if (deviceno == 9)
            {
                device_write = "40";
            }
            if (deviceno == 10)
            {
                device_write = "41";
            }
            if (deviceno == 11)
            {
                device_write = "42";
            }
            if (deviceno == 12)
            {
                device_write = "43";
            }
 
            if (deviceno == 13)
            {
                device_write = "48";
            }
            if (deviceno == 14)
            {
                device_write = "49";
            }
            if (deviceno == 15)
            {
                device_write = "50";
            }
            if (deviceno == 16)
            {
                device_write = "51";
            }
 
            if (deviceno == 17)
            {
                device_write = "56";
            }
            if (deviceno == 18)
            {
                device_write = "57";
            }
            if (deviceno == 19)
            {
                device_write = "58";
            }
            if (deviceno == 20)
            {
                device_write = "59";
            }
            //device
            //jiaoban[0] = Convert.ToInt32(objPlc1.ReadPlc("30"));
            //jiaoban[1] = Convert.ToInt32(objPlc1.ReadPlc("31"));
            //jiaoban[2] = Convert.ToInt32(objPlc1.ReadPlc("32"));
            //jiaoban[3] = Convert.ToInt32(objPlc1.ReadPlc("33"));
            //jiaoban[4] = Convert.ToInt32(objPlc1.ReadPlc("34"));
            //jiaoban[5] = Convert.ToInt32(objPlc1.ReadPlc("35"));
            //jiaoban[6] = Convert.ToInt32(objPlc1.ReadPlc("36"));
            //jiaoban[7] = Convert.ToInt32(objPlc1.ReadPlc("37"));
 
            //jiaoban[8] = Convert.ToInt32(objPlc1.ReadPlc("40"));
            //jiaoban[9] = Convert.ToInt32(objPlc1.ReadPlc("41"));
            //jiaoban[10] = Convert.ToInt32(objPlc1.ReadPlc("42"));
            //jiaoban[11] = Convert.ToInt32(objPlc1.ReadPlc("43"));
 
            //jiaoban[12] = Convert.ToInt32(objPlc1.ReadPlc("48"));
            //jiaoban[14] = Convert.ToInt32(objPlc1.ReadPlc("50"));
            //jiaoban[15] = Convert.ToInt32(objPlc1.ReadPlc("51"));
 
            //jiaoban[16] = Convert.ToInt32(objPlc1.ReadPlc("56"));
            //jiaoban[17] = Convert.ToInt32(objPlc1.ReadPlc("57"));
            //jiaoban[18] = Convert.ToInt32(objPlc1.ReadPlc("58"));
            //jiaoban[19] = Convert.ToInt32(objPlc1.ReadPlc("59"));
            DialogResult result = MainForm.pMainWin.ls_IniFile.ShowDeleteAlert("是否开启搅拌" + "\r");
            if (result == DialogResult.No)
            {
                return;
            }
            MainForm.pMainWin.objPlc1.Writeplc(device_write, "1");
            string tkdat1 = "";
            string tkdat2 = "";
            string userid = "admin";
            string pm = "";
            string batch = "";
            string gh = "";
            string SetValue;
            string insertgh;
            string sdwd_t = "";
            string sjwd1_t = "";
            string sjwd2_t = "";
            string yali_t = "";
            string op_t = "";
            op_t = "开启搅拌";
            //string updategh = "update gh set " + "pm ='" + pm + "'," + "gh='" + gh + "'," + "batch='" + batch + "'," + "tkdat1='" + tkdat1 + "'," + "tkdat2='" + tkdat2 + "'," + "userid='" + userid + "' where gh ='" +gh + "'";
            tkdat1 = DateTime.Now.ToString();
            tkdat2 = DateTime.Now.ToString();
            gh = obj_gh.Substring(0, 4).ToUpper();
            yali_t = MainForm.pMainWin.yl[Convert.ToInt32(device) - 1]; ;
            sdwd_t = MainForm.pMainWin.sdwd[Convert.ToInt32(device) - 1]; ;
            sjwd1_t = MainForm.pMainWin.sjwd1[Convert.ToInt32(device) - 1]; ;
            sjwd2_t = MainForm.pMainWin.sjwd2[Convert.ToInt32(device) - 1]; ;
 
            SetValue = "('" + pm + "','" + gh + "','" + batch + "','" + tkdat1 + "','" + tkdat2 + "','" + userid + "','" + "1" + "','" + yali_t + "','" + sdwd_t + "','" + sjwd1_t + "','" + op_t + "','" + sjwd2_t + "')";
            insertgh = "insert into wd (pm,gh,batch,tkdat1,tkdat2,userid,finish,yl,sdwd,sjwd1,op,sjwd2) values " + SetValue;
            try
            {
                Narnu.DoOleDbString(insertgh);
 
            }
            catch (Exception ex)
            {
 
                MainForm.pMainWin.ls_IniFile.WriteLog("write1", ex.Message.ToString());
                return;
            }
        }
 
        private void button3_Click(object sender, EventArgs e)
        {
            string op_t = "";
     
            DialogResult result = MainForm.pMainWin.ls_IniFile.ShowDeleteAlert("是否执行操作" + "\r");
            if (result == DialogResult.No)
            {
                return;
            }
            if (rb_auto.Checked)
            {
                MainForm.pMainWin.op[Convert.ToInt32(device) - 1] = 1;
                MainForm.pMainWin.start[Convert.ToInt32(device) - 1] = 1;
                op_t = "开启自动";
 
            }
            if (rb_man.Checked)
            {
                MainForm.pMainWin.op[Convert.ToInt32(device) - 1] = 0;
                MainForm.pMainWin.start[Convert.ToInt32(device) - 1] = 0;
                op_t = "开启手动";
               
            }
            string tkdat1 = "";
            string tkdat2 = "";
            string userid = "admin";
            string pm = "";
            string batch = "";
            string gh = "";
            string SetValue;
            string insertgh;
            string sdwd_t = "";
            string sjwd1_t = "";
            string sjwd2_t = "";
            string yali_t = "";
            
            //string updategh = "update gh set " + "pm ='" + pm + "'," + "gh='" + gh + "'," + "batch='" + batch + "'," + "tkdat1='" + tkdat1 + "'," + "tkdat2='" + tkdat2 + "'," + "userid='" + userid + "' where gh ='" +gh + "'";
            tkdat1 = DateTime.Now.ToString();
            tkdat2 = DateTime.Now.ToString();
            gh = obj_gh.Substring(0, 4).ToUpper();
            yali_t = MainForm.pMainWin.yl[Convert.ToInt32(device) - 1];
            sdwd_t = MainForm.pMainWin.sdwd[Convert.ToInt32(device) - 1];
            sjwd1_t = MainForm.pMainWin.sjwd1[Convert.ToInt32(device) - 1];
            sjwd2_t = MainForm.pMainWin.sjwd2[Convert.ToInt32(device) - 1];
             
            SetValue = "('" + pm + "','" + gh + "','" + batch + "','" + tkdat1 + "','" + tkdat2 + "','" + userid + "','" + "1" + "','" + yali_t + "','" + sdwd_t + "','" + sjwd1_t + "','" + op_t + "','" + sjwd2_t + "')";
            insertgh = "insert into wd (pm,gh,batch,tkdat1,tkdat2,userid,finish,yl,sdwd,sjwd1,op,sjwd2) values " + SetValue;
            try
            {
                Narnu.DoOleDbString(insertgh);
 
            }
            catch (Exception ex)
            {
 
                MainForm.pMainWin.ls_IniFile.WriteLog("write1", ex.Message.ToString());
                return;
            }
        }
 
        private void button6_Click(object sender, EventArgs e)
        {
            DialogResult result = MainForm.pMainWin.ls_IniFile.ShowDeleteAlert("是否执行操作" + "\r");
            if (result == DialogResult.No)
            {
                return;
            }
            MainForm.pMainWin.sdwd[Convert.ToInt32(device) - 1] = sd_wd.Text;
        }
 
        private void pictureBox1_Click(object sender, EventArgs e)
        {
 
        }
 
        private void button7_Click(object sender, EventArgs e)
        {
            string tkdat1 = DateTime.Now.ToString();
            string tkdat2 = DateTime.Now.ToString();
            string userid = "admin";
            string pm = cb_pm.Text;
            string batch = tb_batch.Text;
            string gh = obj_gh.Substring(0, 4).ToUpper();
            string SetValue = "('" +pm+"','"+gh+"','"+batch+"','"+tkdat1+"','"+tkdat2+"','"+userid+"','"+"1"+ "')"; ;
            string insertgh = "insert into gh (pm,gh,batch,tkdat1,tkdat2,userid,finish) values " + SetValue;
            //string updategh = "update gh set " + "pm ='" + pm + "'," + "gh='" + gh + "'," + "batch='" + batch + "'," + "tkdat1='" + tkdat1 + "'," + "tkdat2='" + tkdat2 + "'," + "userid='" + userid + "' where gh ='" +gh + "'";
            string updategh = "update gh set tkdat2='" + tkdat2 + "'," + " finish ='0',"+ "userid='" + userid + "' where gh ='" + gh + "'";
            string selectgh = " select count(gh) from gh where gh = '" + gh + "'" + " and finish='" +"1"+ "'";
            
            string count="";
            DialogResult result = MainForm.pMainWin.ls_IniFile.ShowDeleteAlert("是否执行操作" + "\r");
            if (result == DialogResult.No)
            {
                return;
            }
            try
            {
                count = Narnu.GetObjectByOleDbString(selectgh).ToString();
            }
            catch(Exception ex)
            {
                MessageBox.Show("出错!" +ex.ToString());
                return;
            }
          //  MessageBox.Show(count.ToString());
            if (count == "0")
            {
                try
                {
                    Narnu.DoOleDbString(insertgh);
 
                }
                catch (Exception ex)
                {
 
                    MessageBox.Show("保存数据出现错误0!" + ex.ToString());
                    return;
                }
            }
            else
            {
                try
                {
                    Narnu.DoOleDbString(updategh);
 
                }
                catch (Exception ex)
                {
 
                    MessageBox.Show("保存数据出现错误1!" + ex.ToString());
                    return;
                }
 
                try
                {
                    Narnu.DoOleDbString(insertgh);
 
                }
                catch (Exception ex)
                {
 
                    MessageBox.Show("保存数据出现错误2!" + ex.ToString());
                    return;
                }
            }
            MessageBox.Show("操作成功!");
        }
 
        private void bt_com_Click(object sender, EventArgs e)
        {
            string tkdat1 = DateTime.Now.ToString();
            string tkdat2 = DateTime.Now.ToString();
            string userid = "admin";
            string pm = cb_pm.Text;
            string batch = tb_batch.Text;
            string gh = obj_gh.Substring(0, 4).ToUpper();
            string SetValue = "('" + pm + "','" + gh + "','" + batch + "','" + tkdat1 + "','" + tkdat2 + "','" + userid + "','" + "1" + "')"; ;
            string insertgh = "insert into gh (pm,gh,batch,tkdat1,tkdat2,userid,finish) values " + SetValue;
            //string updategh = "update gh set " + "pm ='" + pm + "'," + "gh='" + gh + "'," + "batch='" + batch + "'," + "tkdat1='" + tkdat1 + "'," + "tkdat2='" + tkdat2 + "'," + "userid='" + userid + "' where gh ='" +gh + "'";
            string updategh = "update gh set tkdat2='" + tkdat2 + "'," + " finish ='0'," + "userid='" + userid + "' where gh ='" + gh + "'";
            string selectgh = " select count(gh) from gh where gh = '" + gh + "'" + " and finish='" + "1" + "'";
            
            DialogResult result = MainForm.pMainWin.ls_IniFile.ShowDeleteAlert("是否执行操作" + "\r");
            if (result == DialogResult.No)
            {
                return;
            }
 
            try
            {
                Narnu.DoOleDbString(updategh);
 
            }
            catch (Exception ex)
            {
 
                MessageBox.Show("保存数据出现错误1!" + ex.ToString());
                return;
            }
            MessageBox.Show("操作成功!");
        }
 
        private void button7_Click_1(object sender, EventArgs e)
        {
            
            string gh = "";
            lb_gh.Text = obj_gh.Substring(0, 4).ToUpper();
            gh = obj_gh.Substring(0, 4).ToUpper();
            device = obj_gh.Substring(5, 2);
            DateTime tk;
            DataSet ds;
            tk = Convert.ToDateTime(dateTimePicker1.Value);
            string selectgh = " select * from gh where gh = '" + gh + "'" + " and tkdat1>=Cdate('" +tk  +"')"+ " and finish='" + "1" + "' order by tkdat1 desc";
            ds = Narnu.GetDataSetByOleDbString(selectgh);
            if (ds.Tables["gh"].Rows.Count == 0)
            {
                cb_pm.Text = "";
                tb_batch.Text = "";
                bt_st.Enabled = true;
                bt_com.Enabled = false;
                //cb_pm
            }
            else
            {
                cb_pm.Text = ds.Tables["gh"].Rows[0][6].ToString();
                tb_batch.Text = ds.Tables["gh"].Rows[0][5].ToString();
                bt_st.Enabled = false;
                bt_com.Enabled = true;
            }
            FillDataTk(gh.ToString(),tk);
        }
 
        private void button8_Click(object sender, EventArgs e)
        {
            PrintDGV.Print_DataGridView(this.dataGridView1);
        }
    }
}

主要控制程序部分

复制代码
  1 using System;
  2 using System.Collections.Generic;
  3 using System.ComponentModel;
  4 using System.Data;
  5 using System.Drawing;
  6 using System.Linq;
  7 using System.Text;
  8 using System.Windows.Forms;
  9 using System.Net;
 10 using System.Net.Sockets;
 11 using System.Data.SqlClient;
 12 using System.Data.Sql;
 13 using System.Data.OleDb;
 14 using System.Reflection;
 15 using System.Threading;
 16 using System.Runtime.InteropServices;
 17 using LBSoft.IndustrialCtrls;
 18 using LBSoft.IndustrialCtrls.Meters;
 19 using LBSoft.IndustrialCtrls.Utils;
 20 
 21 
 22 namespace work
 23 {
 24     public partial class FormNew : Form
 25     {
 26         public static FormNew pMainWin = null;
 27 
 28         public Plc objPlc = new Plc();
 29         public PlcSyn objPlc1 = new PlcSyn();
 30         public IniFile ls_IniFile = new IniFile(Environment.CurrentDirectory + "\\log.ini");
 31         public Data objData = new Data();
 32         public Mutex mutex;
 33         public string ddj1read = "";
 34         public Thread objThread;
 35 
 36         public string[] sdwd = new string[12];//设定
 37         public string[] sjwd1 = new string[12];//高位
 38         public string[] sjwd2 = new string[12];//低位
 39         public string[] yl = new string[12];//压力
 40         public int[] k_dj = new int[3];
 41         public int[] guzhangshuru = new int[12];
 42         public int[] jiaoban = new int[19];//
 43         public int[] zhileng = new int[12];//制冷
 44         public int[] zhuangtai = new int[12];
 45         public int[] chishu = new int[12];
 46         public int[] op = new int[12];
 47         public string[] opdesc = new string[12];
 48         public Thread objReadwdThread;
 49         public Thread objReadkzThread;
 50         public Thread objFlashztThread;
 51         public int[] jb_time = new int[12];
 52         public int[] sdjb_time = new int[12];
 53 
 54         public int[] zl_time = new int[12];
 55         public int[] flag_30 = new int[12];
 56         public int[] flag_60 = new int[12];
 57         public int[] flag_180 = new int[12];
 58         public int[] flag_10 = new int[12];
 59         public int[] time = new int[12];
 60         public int[] time_flag = new int[12];
 61         public int[] time_zl = new int[12];
 62         public int[] time_zl_flag = new int[12];
 63         public int[] start = new int[12];
 64         public int[] opplc = new int[12];
 65         public int flag42;
 66         public int flag43;
 67         public int flag44;
 68         public string[] pm = new string[12];//压力
 69         public string[] batch = new string[12];//压力
 70         public string[] tkdat = new string[12];//压力
 71         public string gs_userid = "";
 72         public int[] zhileng_temp = new int[12];//制冷
 73 
 74         public int[] op_jb_flag = new int[12];
 75         public int[] op_jb_time = new int[12];
 76         public FormNew(string userid)
 77         {
 78             
 79             InitializeComponent();
 80             pMainWin = this;
 81             mutex = new Mutex(false, "SINGLE_INSTANCE_MUTEX");
 82             if (!mutex.WaitOne(0, false))
 83             {
 84                 mutex.Close();
 85                 mutex = null;
 86             }
 87             this.gs_userid = userid;
 88         }
 89         //判断一个子窗体是否存在
 90         private bool checkChildFrmExist(string childFrmName)
 91         {
 92             foreach (Form childFrm in this.MdiChildren)
 93             {
 94                 //用子窗体的Name进行判断,如果已经存在则将他激活
 95                 if (childFrm.Name == childFrmName)
 96                 {
 97                     if (childFrm.WindowState == FormWindowState.Minimized)
 98                         childFrm.WindowState = FormWindowState.Normal;
 99                     childFrm.Activate();
100                     return true;
101                 }
102             }
103             return false;
104         }
105         public void readwd()
106         {
107             int device = 0;
108             string dev_desc = "";
109             while (true)
110             {
111 
112                 try
113                 {
114                     for (int i = 0; i < 11; i++)
115                     {
116                         device = 57 + i * 2;
117 
118                         if (i == 11)
119                         {
120                             sjwd1[i] = (Convert.ToDouble(objPlc1.ReadPlc(device.ToString())) / 65535 * 50 - 20 + 0.5).ToString("F2");
121                         }
122                         if (i == 13)
123                         {
124                             sjwd1[i] = (Convert.ToDouble(objPlc1.ReadPlc(device.ToString())) / 65535 * 50 - 20 + 0.5).ToString("F2");
125                         }
126                         if (i == 14)
127                         {
128                             sjwd1[i] = (Convert.ToDouble(objPlc1.ReadPlc(device.ToString())) / 65535 * 50 - 20 + 0.5).ToString("F2");
129                         }
130                         else
131                         {
132                             sjwd1[i] = (Convert.ToDouble(objPlc1.ReadPlc(device.ToString())) / 65535 * 50 - 20 + 0.2).ToString("F2");
133                         }
134                         if (i < 9)
135                         {
136                             dev_desc = "0" + (i + 1).ToString();
137                             // ii01_011.Text = sjwd1[0];
138                         }
139                         else
140                         {
141                             dev_desc = (i + 1).ToString();
142                         }
143                         if (op[i] == 0)
144                         {
145                             opdesc[i] = "手动";
146                         }
147                         if (op[i] == 1)
148                         {
149                             opdesc[i] = "自动";
150                         }
151                         if (op[i] == 2)
152                         {
153                             opdesc[i] = "澄清";
154                         }
155                         if (op[i] == 3)
156                         {
157                             opdesc[i] = "发酵";
158                         }
159                         ii01_014.Text = opdesc[0];
160                         ii02_024.Text = opdesc[1];
161                         ii03_034.Text = opdesc[2];
162                         ii04_044.Text = opdesc[3];
163                         ii05_054.Text = opdesc[4];
164                         ii06_064.Text = opdesc[5];
165                         ii07_074.Text = opdesc[6];
166                         ii08_084.Text = opdesc[7];
167                         ii09_094.Text = opdesc[8];
168                         ii10_104.Text = opdesc[9];
169                         ii11_114.Text = opdesc[10];
170                    
171 
172                         ii01_012.Text = sjwd1[0];
173                         ii02_022.Text = sjwd1[1];
174                         ii03_032.Text = sjwd1[2];
175                         ii04_042.Text = sjwd1[3];
176                         ii05_052.Text = sjwd1[4];
177                         ii06_062.Text = sjwd1[5];
178                         ii07_072.Text = sjwd1[6];
179                         ii08_082.Text = sjwd1[7];
180                         ii09_092.Text = sjwd1[8];
181                         ii10_102.Text = sjwd1[9];
182                         ii11_112.Text = sjwd1[10];
183                        
184                         //
185                         ii01_011.Text = sdwd[0];
186                         ii02_021.Text = sdwd[1];
187                         ii03_031.Text = sdwd[2];
188                         ii04_041.Text = sdwd[3];
189                         ii05_051.Text = sdwd[4];
190                         ii06_061.Text = sdwd[5];
191                         ii07_071.Text = sdwd[6];
192                         ii08_081.Text = sdwd[7];
193                         ii09_091.Text = sdwd[8];
194                         ii10_101.Text = sdwd[9];
195                         ii11_111.Text = sdwd[10];
196                         
197                         //System.Windows.Forms.TextBox tb = (System.Windows.Forms.TextBox);
198                         //FormDisplay FormDisplay = new FormDisplay(pb.Name);
199                         //FormDisplay.Show();
200                         // sf01_011.Text = sdwd[0].ToString();
201                         //  sf01_012.Text = sjwd1[0].ToString();
202                         //sf01_013.Text = sjwd2[0].ToString();
203                         // sf01_014.Text = yl[0].ToString();
204                     }
205 
206                     for (int j = 0; j < 11; j++)
207                     {
208                         device = 58 + j * 2;
209                         yl[j] = ((Convert.ToDouble(objPlc1.ReadPlc(device.ToString())) * 3.8/ 65535) * 5).ToString("F2");
210                         if ((Convert.ToDouble(objPlc1.ReadPlc(device.ToString())) * 3.9 / 65535) > 4.1)
211                         {
212                             yl[j] = ((Convert.ToDouble(objPlc1.ReadPlc(device.ToString())) * 3.8/ 65535 - 3.9) * 5 / 4 + 3.8 * 5).ToString("F2");
213                         }
214                         else
215                         {
216                             yl[j] = ((Convert.ToDouble(objPlc1.ReadPlc(device.ToString())) * 3.8 / 65535) * 5).ToString("F2");
217                         }
218 
219                         //
220                         //if ((Convert.ToDouble(objPlc1.ReadPlc("77")) * 13 / 65535) > 11)
221                         //{
222                         //    yl[1] = (((Convert.ToDouble(objPlc1.ReadPlc("77")) * 13 / 65535) - 11) * 20 / 3 + 11 * 23.2 + 0.4).ToString("F2");
223                         //}
224                         //else
225                         //{
226                         //    yl[1] = ((Convert.ToDouble(objPlc1.ReadPlc("77")) * 13 / 65535) * 23.2 + 0.4).ToString("F2");
227                         //}
228                         //if (j == 0)
229                         //{
230                         //    yl[j] = ((Convert.ToDouble(objPlc1.ReadPlc(device.ToString())) * 4.1 / 65535) * 5.51).ToString("F2");
231                         //}
232 
233                         //if (j == 25)
234                         //{
235                         //    if ((Convert.ToDouble(objPlc1.ReadPlc(device.ToString())) * 4.5 / 65535) > 11)
236                         //    {
237                         //        yl[j] = ((Convert.ToDouble(objPlc1.ReadPlc(device.ToString())) * 4.5 / 65535) * 5.61).ToString("F2");
238                         //    }
239                         //}
240 
241                         //if (j == 26)
242                         //{
243                         //    yl[j] = ((Convert.ToDouble(objPlc1.ReadPlc(device.ToString())) * 4.5 / 65535) * 5.5).ToString("F2");
244                         //}
245                         //if (j == 35)
246                         //{                        //    yl[j] = ((Convert.ToDouble(objPlc1.ReadPlc(device.ToString())) * 4.5 / 65535) * 5.5).ToString("F2");
247                         //}
248                         ii01_013.Text = yl[0];
249                         ii02_023.Text = yl[1];
250                         ii03_033.Text = yl[2];
251                         ii04_043.Text = yl[3];
252                         ii05_053.Text = yl[4];
253                         ii06_063.Text = yl[5];
254                         ii07_073.Text = yl[6];
255                         ii08_083.Text = yl[7];
256                         ii09_093.Text = yl[8];
257                         ii10_103.Text = yl[9];
258                         ii11_113.Text = yl[10];
259                       
260                     }
261 
262                     for (int k = 0; k < 11; k++)
263                     {
264                         device = 19 + k;
265                         zhileng[k] = Convert.ToInt32(objPlc1.ReadPlc(device.ToString()));
266                     }
267 
268                     for (int m = 0; m < 18; m++)
269                     {
270                         device = 1 + m;
271                         jiaoban[m] = Convert.ToInt32(objPlc1.ReadPlc(device.ToString()));
272                     }
273 
274                     //for (int n = 0; n < 41; n++)
275                     //{
276                     //    device = 89 + n;
277                     //    guzhangshuru[n] = Convert.ToInt32(objPlc1.ReadPlc(device.ToString()));
278                     //}
279                     //for (int n = 0; n < 3; n++)
280                     //{
281                     //    device = 83 + n;
282                     //    k_dj[n] = Convert.ToInt32(objPlc1.ReadPlc(device.ToString()));
283                     //}      
284                     Thread.Sleep(200);
285                 }
286                 catch (Exception e)
287                 {
288                     //ls_IniFile.WriteLog("ReadData12", e.Message.ToString());
289                     continue;
290                 }
291 
292             }
293         }
294         private string DateDiff(DateTime DateTime1, DateTime DateTime2)
295         {
296             string dateDiff = null;
297             try
298             {
299                 TimeSpan ts1 = new TimeSpan(DateTime1.Ticks);
300                 TimeSpan ts2 = new TimeSpan(DateTime2.Ticks);
301                 TimeSpan ts = ts1.Subtract(ts2).Duration();
302                 dateDiff = ts.Days.ToString() + ""
303                 + ts.Hours.ToString() + ""
304                 + ts.Minutes.ToString() + "";
305                 //+ ts.Seconds.ToString() + "秒";
306             }
307             catch
308             {
309 
310             }
311             return dateDiff;
312         }
复制代码

 仪表显示控件源码 https://files.cnblogs.com/files/meslog/LBIndustrialCtrls_src.zip qq 1153755352

posted on   meslog  阅读(1303)  评论(2编辑  收藏  举报
编辑推荐:
· Linux glibc自带哈希表的用例及性能测试
· 深入理解 Mybatis 分库分表执行原理
· 如何打造一个高并发系统?
· .NET Core GC压缩(compact_phase)底层原理浅谈
· 现代计算机视觉入门之:什么是图片特征编码
阅读排行:
· 手把手教你在本地部署DeepSeek R1,搭建web-ui ,建议收藏!
· Spring AI + Ollama 实现 deepseek-r1 的API服务和调用
· 数据库服务器 SQL Server 版本升级公告
· C#/.NET/.NET Core技术前沿周刊 | 第 23 期(2025年1.20-1.26)
· 程序员常用高效实用工具推荐,办公效率提升利器!
点击右上角即可分享
微信分享提示