雅琪诺MES智能条码管理系统
jhz
2022-06-30 0d3b2bd4edaa7385e4ff96370c877be237af054b
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using gregn6Lib;
using Pub_Class;
using System.Threading;
using System.IO.Ports;
 
namespace SCM
{
    public partial class Sc_PackUnionBill : Form
    {
        public Sc_PackUnionBill()
        {
            InitializeComponent();
        }
 
        public frmBillQueryCondition_Base frmCondition;
        public string ModCaption = "包装单";
        public string ModName = "Sc_PackUnionBill";
        public Int64 HInterID = 0;          //单据ID
        public string HBillNo = "";         //单据号
        public string HBillType = "3783";   //单据类型
        public string HMaker = "";          //制单人
        public string HSourceBillTypeID = "";
        public string HSourceBillType = "";
        public string HSourceBillNo = "";
        public Int64 HSourceInterID = 0;
        public Int64 HSourceEntryID = 0;
        public int HTMCol = 0;
        public int HMaterIDCol = 1;
        public string HOrgNumber = "1001";
        public Int64 HOrgID = 1;
        public string HBarCode = "";
        public Model.ClsSc_PackUnionBillMain omodel = new Model.ClsSc_PackUnionBillMain();
        Pub_Class.ClsGridListSum oSumGrid = new Pub_Class.ClsGridListSum();
        public Int32 iTopRow = 0;//画横线
        SCM.WMSWeb.WebService1 oWeb = new SCM.WMSWeb.WebService1();
        private static string repeatData = string.Empty;
        //
 
        #region  固定代码
 
        //清空界面
        public void Sub_ClearBill()
        {
            Int64 sGroupID = DBUtility.ClsPub.isLong(txtHGroupID.Tag);
            string sGroupName = DBUtility.ClsPub.isStrNull(txtHGroupID.Text);
            Int64 sEmpID = DBUtility.ClsPub.isLong(txtHEmpID.Tag);
            string sEmpName = DBUtility.ClsPub.isStrNull(txtHEmpID.Text);
            Int64 sEmpID2 = DBUtility.ClsPub.isLong(txtHEmpID2.Tag);
            string sEmpName2 = DBUtility.ClsPub.isStrNull(txtHEmpID2.Text);
 
            //清空界面
            ClsPub1.Sub_ClearBill(groupBox4);
            ClsPub1.Sub_ClearBill1(tabPage3);
            ClsPub1.Sub_ClearBill1(tabPage1);
            //ClsPub1.Sub_ClearBill1(tabPage4);    
            txtHGroupID.Tag = sGroupID;
            txtHGroupID.Text = sGroupName;
            txtHEmpID.Tag = sEmpID;
            txtHEmpID.Text = sEmpName;
            txtHEmpID2.Tag = sEmpID2;
            txtHEmpID2.Text = sEmpName2; 
            //从服务器  获得单据号ID和单据号
            string s = "";
            if (oWeb.get_MaxBillNoAndID(HBillType, ref HBillNo, ref HInterID, ref s))
            {
                txtHBillNo.Tag = HInterID.ToString();
                txtHBillNo.Text = HBillNo;
            }
            else
            {
                MessageBox.Show("得到单据号失败!" + s);
                this.Close();
            }
            //
            HMaker = DBUtility.ClsPub.CurUserName;
            txtHMaker.Text = HMaker;
            HOrgID = ClsPub1.HOrgID;
 
            DataSet Ds1 = oWeb.getDataSetBySQL("select * from Xt_ORGANIZATIONS with(nolock) where HItemID=" + HOrgID, "Xt_ORGANIZATIONS", ref DBUtility.ClsPub.sExeReturnInfo);
            if (Ds1.Tables[0].Rows.Count != 0)
            {
                HOrgNumber = DBUtility.ClsPub.isStrNull(Ds1.Tables[0].Rows[0]["HNumber"]);
                txtHOWNERID.Tag = HOrgID;
                txtHOWNERID.Text = DBUtility.ClsPub.isStrNull(Ds1.Tables[0].Rows[0]["HName"]);
            }
            initGrid();
            //刷新表体
            DisBillEntryList_Webs();
            //
            txtHMSourceBillNo.Enabled = true;
            txtHZBarCode.Enabled = true;
            cmdHSaveBill.Enabled = true;
            txtHMSourceBillNo.Focus();
        }
 
        private void Sc_PackUnionBill_Load(object sender, EventArgs e)
        {
            //设置动态URL
            oWeb.Url = SCM.ClsPub1.WEBSURL;
            //
            frmCondition = new frmBillQueryCondition_Base();
            this.Text = ModCaption; 
            oSumGrid.ogrdMain = grdMain;  //初始化 new
            oSumGrid.oGridsum = grdSum;
            initGrid();
            cmbDYMB.Items.Add(this.Text);
            cmbDYMB.SelectedIndex = 0;
        }
 
        //初始化网格
        private void initGrid()
        {
            ClsPub1.initGridList(grdMain, this.Name);
            grdMain.RowTemplate.Height = 30;
            grdMain.RowTemplate.MinimumHeight = 30;
            grdMain.RowsDefaultCellStyle.Font = new Font("宋体", 15);
            grdMain.ReadOnly = true;
            //DBUtility.Xt_BaseBillFun.initGridList(grdMain, this.Name);
        }
 
        //时间控件
        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Enabled=false;
            Sub_ClearBill();
        }
 
        private void timer2_Tick(object sender, EventArgs e)
        {
            timer2.Enabled = false;
            //
            if (ClsIni.ReadIni("COMINFO", "txtPortName", DBUtility.ClsPub.AppPath + @"/HXERP.ini").Contains("没有找到")==false)
            {
                txtPortName.Text = ClsIni.ReadIni("COMINFO", "txtPortName", DBUtility.ClsPub.AppPath + @"/HXERP.ini");
                txtBaudRate.Text = ClsIni.ReadIni("COMINFO", "txtBaudRate", DBUtility.ClsPub.AppPath + @"/HXERP.ini");
                cmbParity.Text = ClsIni.ReadIni("COMINFO", "cmbParity", DBUtility.ClsPub.AppPath + @"/HXERP.ini");
                txtDataBits.Text = ClsIni.ReadIni("COMINFO", "txtDataBits", DBUtility.ClsPub.AppPath + @"/HXERP.ini");
                cmbStopBits.Text = ClsIni.ReadIni("COMINFO", "cmbStopBits", DBUtility.ClsPub.AppPath + @"/HXERP.ini");
                txtHSend0.Text = ClsIni.ReadIni("COMINFO", "txtHSend0", DBUtility.ClsPub.AppPath + @"/HXERP.ini");
                txtHSend.Text = ClsIni.ReadIni("COMINFO", "txtHSend", DBUtility.ClsPub.AppPath + @"/HXERP.ini");
            }
 
            //初始化串口
            ComDevice = new SerialPort();
            ComDevice.DataReceived += new SerialDataReceivedEventHandler(Com_DataReceived);//绑定事件
            string[] PortNames = SerialPort.GetPortNames();
            //打开串口
            OpenCom();
        }
 
        private void grdMain_Paint(object sender, PaintEventArgs e)
        {
            GraphicsGrid();
        }
 
        private void GraphicsGrid()
        {
            //画底线
            DBUtility.Xt_BaseBillFun.GraphicsGrid(grdMain);
            //画横线
            DBUtility.Xt_BaseBillFun.GraphicsRowGrid(grdMain, iTopRow, iTopRow + 50, Fun_GetCol("hmainid"));
        }
 
        private Int32 Fun_GetCol(string sCol)
        {
            return DBUtility.Xt_BaseBillFun.Fun_GetCol(sCol, grdMain);
        }
 
        //保存列宽
        private void bclk_Click(object sender, EventArgs e)
        {
            DBUtility.Xt_BaseBillFun.SaveGrid(grdMain, this.Name);
        }
 
        //默认列宽
        private void mrlk_Click(object sender, EventArgs e)
        {
            DBUtility.Xt_BaseBillFun.DefaultGridView(grdMain, this.Name);
        }
        //是否是空行
        private bool IsNullRow(int Row)
        {
            return DBUtility.Xt_BaseBillFun.IsNullRow(Row, HMaterIDCol, grdMain);
        }
 
        #endregion
 
 
        #region 功能控件
 
        //退出
        private void cmdCancel_Click(object sender, EventArgs e)
        {
            CloseCom();
            Thread.Sleep(300);
            this.Close();
        }
 
        //新增
        private void cmdHAdd_Click(object sender, EventArgs e)
        {
            Sub_ClearBill();//清空界面
        }
 
        //保存 并生成打印条码
        private void cmdHSaveBill_Click(object sender, EventArgs e)
        {
            //判断是否数据完整 
            if (AllowLoadData() == false)
            {
                return;
            }
            SaveBill();
        }
 
        //上传前判断
        private bool AllowLoadData()
        {
            if (HInterID == 0)
            {
                MessageBox.Show("错误的单据内码!");
                return false;
            }
            if (txtHBillNo.Text.Trim() == "")
            {
                MessageBox.Show("错误的单据号!");
                return false;
            }
            if (DBUtility.ClsPub.isLong(txtHEmpID.Tag) == 0 || DBUtility.ClsPub.isLong(txtHEmpID2.Tag) == 0)
            {
                MessageBox.Show("职员1或者职员2没有选择!");
                cmdHSaveBill.Enabled = true;
                return false;
            }
            if (DBUtility.ClsPub.isLong(txtHGroupID.Tag) == 0)
            {
                MessageBox.Show("班组没有选择!");
                cmdHSaveBill.Enabled = true;
                return false;
            }
            //判断是否存在数量0的明细记录 (至少 扫描一条记录)
            bool b = false;
            for (int i = 0; i < grdMain.RowCount; i++)
            {
                if (ClsPub.isDoule(grdMain.Rows[i].Cells["数量"].Value) == 0)
                {
                    b = false;
                }
                else
                {
                    b = true;
                    break;
                }
            }
            if (!b)
            {
                MessageBox.Show("没有子件条码扫描记录!");
                return false;
            }
            return true;
        }
 
        //写入包装单、条码档案
        public bool SaveBill()
        {
            try
            {
                //判断会计期是否合理
                string s = "";
                int sYear = 0;
                int sPeriod = 0;
                //if (DBUtility.Xt_BaseBillFun.Fun_AllowYearPeriod(dtpHDate.Value, ref sYear, ref sPeriod, ref s) == false)
                //{
                //    MessageBox.Show(s, "提示");
                //    return false;
                //}
                omodel.HYear = sYear;
                omodel.HPeriod = sPeriod;
                omodel.HInterID = HInterID;
                omodel.HDate = dtpHDate.Value;
                omodel.HBillNo = HBillNo;
                omodel.HRemark = "";
                omodel.HICMOInterID = ClsPub.isLong(this.txtHSourceBillNo.Tag);
                omodel.HICMOBillNo = ClsPub.isStrNull(this.txtHSourceBillNo.Text);
                omodel.HBarCode_Pack = ClsPub.isStrNull(this.txHBarCode_Pack.Text);
                omodel.HMaterID = 0;
                omodel.HUnitID = 0;
                omodel.HWeight = ClsPub.isSingle(this.txtHWeight.Text);
                omodel.HPWeight = ClsPub.isSingle(this.txtHPWeight.Text);
                omodel.HProdOrgID = ClsPub.isLong(this.txtHOWNERID.Tag);
                omodel.HDeptID = ClsPub.isLong(this.txtHDeptID.Tag);
                omodel.HEmpID = ClsPub.isLong(this.txtHEmpID.Tag);
 
                //插入主表
                oWeb.getRunProc("Insert Into Sc_PackUnionBillMain   " +
                "(HYear,HPeriod,HBillType,HInterID" +
                ",HDate,HBillNo,HBillStatus,HRemark,HICMOInterID" +
                ",HICMOBillNo,HBarCode_Pack,HMaterID,HUnitID" +
                ",HWeight,HPWeight,HProdOrgID,HDeptID,HEmpID" +
                ",HMaker,HMakeDate" +
                ") " +
                " values(" + omodel.HYear + "," + omodel.HPeriod + ",'" + this.HBillType + "'," + omodel.HInterID +
                ",'" + omodel.HDate + "','" + omodel.HBillNo.ToString() + "'," + omodel.HBillStatus + ",'" + omodel.HRemark + "'," + omodel.HICMOInterID +
                ",'" + omodel.HICMOBillNo.ToString() + "','" + omodel.HBarCode_Pack.ToString() + "'," + omodel.HMaterID + "," + omodel.HUnitID +
                ", " + omodel.HWeight + "," + omodel.HPWeight + "," + omodel.HProdOrgID + "," + omodel.HDeptID + "," + omodel.HEmpID +
                ",'" + DBUtility.ClsPub.CurUserName + "','" + DBUtility.ClsPub.GetServerDate(-1) + "'" +
                ") ", ref DBUtility.ClsPub.sExeReturnInfo);
 
                //插入子表
                oWeb.getRunProc("EXEC h_p_Sc_PackUnionBillSub_Insert " + omodel.HInterID + ",'" + omodel.HBillNo.ToString() + "'", ref DBUtility.ClsPub.sExeReturnInfo);
 
                //将托条码写入条码档案
                string TM = "";             //条码
                double HQty = DBUtility.ClsPub.isDoule(txtHWeight.Text);           //数量
                string sDate = "";          //日期
                //
                string HWei = "";      //尾数
                HBarCode = "";
                string HBarCodeType = "";
                Int64 HMaterID = 0;
                Int64 HAuxPropID = 0;
                Int64 HUnitID = 0;
                double HQty2 = DBUtility.ClsPub.isDoule(txtHWeight.Text);
                string HBatchNo2 = "";
                Int64 HSupID = 0;
                Int64 HGroupID = 0;
                int HPrintQty = 0;
                Int64 HBarcodeNo = 0;       //托号
                Int64 HBarcodeQtys = 0;     //总托数
                Int64 HDeptID = 0;
                Int64 HWhID = 0;
                Int64 HSPID = 0;
                string HRemark = "";
                string HMaterName = "";
                string HMaterModel = "";
                string HPinfan = "";
                string HMTONo = "";
                Int64 HCusID = 0;
                string HCusType = "";
                DateTime HEndDate;
                string HWorkLineName = "";
                DateTime HBeginDate;
                string HSeOrderBillNo = "";
                string HJiaYe2 = "";
                string HPressModel = "";
                string HCusModel = "";
                string HMaterialModel = "";
                string HColor = "";
                string HLogo = "";
                string HPackageSize = "";
                double HMaterialJQty = DBUtility.ClsPub.isDoule(txtHWeight.Text);
                double HMaterialMQty = DBUtility.ClsPub.isDoule(lblHBWeight.Text);
                string HCustomBatchNo = "";
                string HGBBarCode = "";
                string POOrderBillNo = "";
                //
                HBarCode = txHBarCode_Pack.Text;
                HBarCodeType = "托盘条码";
 
                HMaterID = 0;
                HAuxPropID = 0;
                //HUnitID = DBUtility.ClsPub.isLong(txtHUnitName.Tag);
                HQty2 = HQty;
                HBatchNo2 = "";
                HBarcodeQtys = 0;
                HBarcodeNo = 1;
                HSupID = 0;
                HDeptID = 0;
                HWhID = 0;
                HSPID = 0;
                HRemark = "";
                HMaterName = "";
                HMaterModel = "";
                HPinfan = "";
                HMTONo = "";
                HCusID = 0;
                HCusType = "";
                HEndDate = dtpHDate.Value;
                HWorkLineName = DBUtility.ClsPub.isStrNull(txtHEmpID.Text) + ";" + DBUtility.ClsPub.isStrNull(txtHEmpID2.Text) + "";
                HBeginDate = dtpHDate.Value;
                HSeOrderBillNo = "";
                HGroupID = DBUtility.ClsPub.isLong(txtHGroupID.Tag);
                HJiaYe2 = DBUtility.ClsPub.isLong(txtHEmpID.Tag).ToString() + ";" + DBUtility.ClsPub.isLong(txtHEmpID2.Tag).ToString() + "";
                HPressModel = "";
                HCusModel = "";
                HMaterialModel = "";
                HColor = "";
                HLogo = "";
                HPackageSize = "";
                HMaterialJQty = DBUtility.ClsPub.isDoule(txtHWeight.Text);
                HMaterialMQty = DBUtility.ClsPub.isDoule(lblHBWeight.Text);
                HCustomBatchNo = "";
                HGBBarCode = "";
                POOrderBillNo = "";
                string sSQLMul = " insert into Gy_BarCodeBill (HBarCode,HBarCodeType,HMaterID,HUnitID,HQty" +
                            ",HBatchNo,HSupID,HGroupID,HMaker,HMakeDate,HPrintQty,HinitQty" +
                            ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HEndQty " +
                            ",HBarcodeQtys,HBarcodeNo,HDeptID,HWhID,HSPID,HRemark " +
                            ",HCusID,HCusType,HEndDate,HWorkLineName,HJiaYe " +
                            ",HPressModel,HCusModel,HMaterialModel,HColor,HBarCodeDate " +
                            ",HLogo,HPackageSize,HMaterialJQty,HMaterialMQty,HCustomBatchNo " +
                            ",HSTOCKORGID,HOWNERID,HBeginDate,HSeOrderBillNo,HGBBarCode " +
                            ",POOrderBillNo " +
                            ",HMaterName,HMaterModel,HPinfan,HAuxPropID,HMTONo,HInterID " +
                            ") values ("
                            + "'" + HBarCode + "','" + HBarCodeType + "'," + HMaterID.ToString() + "," + HUnitID.ToString() + "," + HQty2.ToString()
                            + ",'" + HBatchNo2 + "'," + HSupID.ToString() + "," + HGroupID.ToString() + ",'" + ClsPub.CurUserName + "',getdate()," + HPrintQty.ToString() + "," + HQty2.ToString()
                            + ", " + HSourceInterID.ToString() + "," + HSourceEntryID.ToString() + ",'" + HSourceBillNo + "','" + HSourceBillTypeID + "','" + HWei + "'"
                            + ", " + HBarcodeQtys.ToString() + "," + HBarcodeNo.ToString() + "," + HDeptID.ToString() + "," + HWhID.ToString() + "," + HSPID.ToString() + ",'" + HRemark + "'"
                            + ", " + HCusID.ToString() + ",'" + HCusType + "','" + HEndDate.ToShortDateString() + "','" + HWorkLineName + "','" + HJiaYe2 + "'"
                            + ",'" + HPressModel + "','" + HCusModel + "','" + HMaterialModel + "','" + HColor + "','" + sDate + "'"
                            + ",'" + HLogo + "','" + HPackageSize + "'," + HMaterialJQty.ToString() + "," + HMaterialMQty.ToString() + ",'" + HCustomBatchNo + "'"
                            + ", " + HOrgID.ToString() + "," + HOrgID.ToString() + ",'" + HBeginDate.ToShortDateString() + "','" + HSeOrderBillNo + "','" + HGBBarCode + "'"
                            + ",'" + POOrderBillNo + "'"
                            + ",'" + HMaterName + "','" + HMaterModel + "','" + HPinfan + "'," + HAuxPropID.ToString() + ",'" + HMTONo + "',"+ omodel.HInterID + ")";
                oWeb.getRunProc(sSQLMul, ref DBUtility.ClsPub.sExeReturnInfo);
 
                //将包装时间反写 销售订单
                if (HSourceInterID > 100000000 && HSourceInterID < 200000000)
                {
                    oWeb.getRunProc("EXEC h_p_IFCLD_DataBackToSeOrderPickTime_New  " + HSourceInterID.ToString() + "," + HSourceEntryID.ToString() + ",'" + HSourceBillNo + "'," + omodel.HInterID.ToString() + ",'" + ClsPub.CurUserName + "'", ref DBUtility.ClsPub.sExeReturnInfo);
                }
                else if (HSourceInterID > 200000000 && HSourceInterID < 300000000)
                {
                    oWeb.getRunProc("EXEC h_p_IFCLD_DataBackToOtherOutPickTime_New  " + HSourceInterID.ToString() + "," + HSourceEntryID.ToString() + ",'" + HSourceBillNo + "'," + omodel.HInterID.ToString() + ",'" + ClsPub.CurUserName + "'", ref DBUtility.ClsPub.sExeReturnInfo);
                }
                else if (HSourceInterID > 300000000 && HSourceInterID < 400000000)
                {
                    oWeb.getRunProc("EXEC h_p_IFCLD_DataBackToPICKMTRLPickTime_New  " + HSourceInterID.ToString() + "," + HSourceEntryID.ToString() + ",'" + HSourceBillNo + "'," + omodel.HInterID.ToString() + ",'" + ClsPub.CurUserName + "'", ref DBUtility.ClsPub.sExeReturnInfo);
                }
                else if (HSourceInterID > 400000000 && HSourceInterID < 500000000)
                {
                    oWeb.getRunProc("EXEC h_p_IFCLD_DataBackToMoveStockPickTime_New  " + HSourceInterID.ToString() + "," + HSourceEntryID.ToString() + ",'" + HSourceBillNo + "'," + omodel.HInterID.ToString() + ",'" + ClsPub.CurUserName + "'", ref DBUtility.ClsPub.sExeReturnInfo);
                }
                else
                {
                    //
                }
                //刷新界面
                DisBillEntryList_Webs();
                //DisplaySub();  
                //根据界面选择打印模板,打印条形码
                //根据销售订单的客户,找到对应的打印模板;
                string HLogoName = "";
                //根据源单号找到客户编号前四位
                DataSet DS;
                if (HSourceInterID > 200000000  )
                {
                    HLogoName = "";
                }
                else
                {
                    DS = oWeb.getDataSetBySQL("exec h_p_FindCustTopFour  '" + HSourceBillNo + "'", "h_p_FindCustTopFour", ref DBUtility.ClsPub.sExeReturnInfo);
                    if (DS == null || DS.Tables[0].Rows.Count == 0)
                    {
                        MessageBox.Show("获取打印模板失败,请前往包装单列表补打条码!");
                        cmdHSaveBill.Enabled = false;
                        txtHZBarCode.Enabled = false;
                        cmdHAdd.Enabled = false;
                        return false;
                    }
                    else
                    {
                        string Cust = ClsPub.isStrNull(DS.Tables[0].Rows[0][0]);
                        HLogoName = "-" + Cust;
                    }
                }
                //
                Sub_SetReport(cmbDYMB.Text + HLogoName);
                 
                if (DBUtility.ClsPub.isStrNull(DBUtility.ClsPub.CurUserName).ToLower() == "admin")
                {
                    Report.PrintPreview(false);
                }
                else
                {
                    Report.Print(false);
                }
                Thread.Sleep(500);
                cmdHSaveBill.Enabled = false;
                txtHZBarCode.Enabled = false;
                return true;
            }
            catch (Exception e1)
            {
                MessageBox.Show("保存失败!" + e1.Message);
                cmdHSaveBill.Enabled = true;
                txtHZBarCode.Enabled = false;
                return false;
            }
        }
 
        #region  //打印设置
 
        GridppReport Report;
        string sBarCode = "";
 
        //预览
        int CurRows = 0;
 
        private void Sub_SetReport(string sOpenTmp)
        {
            //增加判断:如果子表行 实际数量为0 则不打印出来
            for (int i = 0; i < grdMain.RowCount; i++)
            {
                if (ClsPub.isDoule(grdMain.Rows[i].Cells["数量"].Value) != 0)
                {
                    grdMain.Rows[i].Cells[0].Value = "*";
                }
            }
            Report = new GridppReport();
            Report.LoadFromFile(DBUtility.ClsPub.AppPath + @"\" + sOpenTmp + ".grf");  //here .
            Report.BeforePostRecord += new _IGridppReportEvents_BeforePostRecordEventHandler(ReportBeforePostRecord);
            Report.FetchRecord += new _IGridppReportEvents_FetchRecordEventHandler(ReportFetchRecordByDataTable);
            //Report.PrintEnd += new _IGridppReportEvents_PrintEndEventHandler(ReportPrintEnd);
        }
 
        //填入单据表头信息
        private void ReportBeforePostRecord()// 
        {
            try
            {
                Report.FieldByName("条码编号").AsString = ClsPub.isStrNull(txHBarCode_Pack.Text);
                Report.FieldByName("总重量").AsString = ClsPub.isStrNull(txtHWeight.Text);
                Report.FieldByName("客户").AsString = ClsPub.isStrNull(txtHCusName.Text);
                Report.FieldByName("源单单号").AsString = ClsPub.isStrNull(txtHSourceBillNo.Text);
                Report.FieldByName("联系方式").AsString = ClsPub.isStrNull(txtHLinkMan.Text)+ "-" +  ClsPub.isStrNull(txtHLinkPhone.Text);
                Report.FieldByName("地址").AsString = ClsPub.isStrNull(txtHAddress.Text);
                Report.FieldByName("物流方式").AsString = ClsPub.isStrNull(txtHConveyCompName.Text);
                string HWeight = ClsPub.isStrNull(txtHWeight.Text);
                if (HWeight==null || HWeight.Equals(""))
                {
                    HWeight = "0";
                }
                Report.FieldByName("总重量").AsString = HWeight;
            }
            catch (Exception e)
            {
                MessageBox.Show("打印失败!表头:" + e.Message);
            }
        }
 
        private void ReportFetchRecordByDataTable()
        {
            try
            {
                DataTable ds = new DataTable();
                //BLL.Utility.FillRecordToReport(Report, grdMain, ds, Fun_GetCol("选择")); 
                SCM.Utility.FillRecordToReport(Report, grdMain, ds, Fun_GetCol("选择"));
            }
            catch (Exception e)
            {
                MessageBox.Show("打印失败!表体:" + e.Message);
            }
        }
 
        #endregion
 
        //删行
        private void btnBLSH_Click(object sender, EventArgs e)
        {
 
        }
 
        //清空
        private void btnBLBD_Click(object sender, EventArgs e)
        {
 
        }
 
        #endregion
 
 
        #region 扫描源单条码、子件条码
 
        //扫描源单
        private void txtHMSourceBillNo_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Return)
            {
                //明细表是否为零行
                bool b = false;
                for (int i = 0; i < grdMain.RowCount; i++)
                {
                    if (!IsNullRow(i))
                    {
                        b = true;
                        break;
                    }
                }
                if (b == true)
                {
                    if (MessageBox.Show("已存在源单记录,确定要清空重新扫码?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                    {
                        SetBillTilte_Webs();
                        txtHMSourceBillNo.Enabled = false;
                        txtHZBarCode.Focus();
                    }
                }
                else
                {
                    SetBillTilte_Webs();
                    txtHMSourceBillNo.Enabled = false;
                    txtHZBarCode.Focus();
                }
            }
        }
 
        private void SetBillTilte_Webs()
        {
            string sTMNumber = "";      //条码自定义前缀
            int LSH = 0;                //流水号
 
            HSourceBillNo = txtHMSourceBillNo.Text.Trim();
            HSourceBillType = "3710";
            //先同步 
            oWeb.getRunProc("exec h_p_IFCLD_ERPSourceBillToLocal_SEOrderToICMO '" + HSourceBillNo + "'", ref DBUtility.ClsPub.sExeReturnInfo);
            //获取源单信息,并将源单信息存入临时表
 
            DataSet DS = oWeb.getDataSetBySQL("exec h_p_IF_SourceBill_Check_Add_PackUnion  " + HInterID + ",'" + HBillNo + "','" + HBillType + "','" + HSourceBillNo + "','" + HSourceBillType + "','" + HMaker + "'", "h_p_IF_SourceBill_Check_Add_PackUnion", ref DBUtility.ClsPub.sExeReturnInfo);
 
            if (DBUtility.ClsPub.isLong(DS.Tables[0].Rows[0][0]) == 0)
            {
                //加载源单信息
                txtHSourceBillNo.Text = HSourceBillNo;
                HSourceInterID = DBUtility.ClsPub.isLong(DS.Tables[1].Rows[0]["HSourceInterID"]);
 
 
 
                //获取托条码
                //条码前缀 = 组织代码 + 源单单号
                sTMNumber = HOrgNumber + DBUtility.ClsPub.isStrNull(txtHSourceBillNo.Text);
 
                DataSet Ds2 = oWeb.getDataSetBySQL("exec h_p_WMS_GetMaxNo  '" + sTMNumber + "'", "h_p_WMS_GetMaxNo", ref DBUtility.ClsPub.sExeReturnInfo);//获取最大流水号
                LSH = ClsPub.isInt(Ds2.Tables[0].Rows[0][0]);
                //托条码 = 条码前缀 + 流水号
                txHBarCode_Pack.Text = sTMNumber + LSH;
                //
                string sSQLNoMul = " exec h_p_WMS_SetMaxNo '" + sTMNumber + "' ";
                oWeb.getRunProc(sSQLNoMul, ref DBUtility.ClsPub.sExeReturnInfo);
            }
            else
            {
                MessageBox.Show(DBUtility.ClsPub.isStrNull(DS.Tables[0].Rows[0]["HRemark"]) + "," + DBUtility.ClsPub.sExeReturnInfo);
                return;
            }
            //刷新表体
            DisBillEntryList_Webs();
        }
 
        //扫描子件条码
        private void txtHZBarCode_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Return)
            {
                SetZBarCode_Webs(txtHZBarCode.Text);
                txtHZBarCode.Text = "";
                txtHZBarCode.Focus();
            }
        }
        private void SetZBarCode_Webs(string sZCode)
        {
            //将子件条码信息存入临时表
            DataSet DS = oWeb.getDataSetBySQL("exec h_p_KF_PonderationBillMain_Temp_Add_PackUnion  " + HInterID + ",'" + HBillNo + "','" + HBillType + "','" + HMaker + "','" + sZCode + "','" + txHBarCode_Pack.Text + "'," + HOrgID, "h_p_KF_PonderationBillMain_Temp_Add_PackUnion", ref DBUtility.ClsPub.sExeReturnInfo);
 
            if (DBUtility.ClsPub.isLong(DS.Tables[0].Rows[0][0]) == 0)
            {
                //刷新表体同步
                DisBillEntryList_Webs();
            }
            else
            {
                MessageBox.Show(DBUtility.ClsPub.isStrNull(DS.Tables[0].Rows[0]["HRemark"]) + "," + DBUtility.ClsPub.sExeReturnInfo);
                return;
            }
        }
 
        //刷新子表
        private void DisBillEntryList_Webs()
        {
            //得到信息
            DataSet DSet = oWeb.getDataSetBySQL("exec h_p_KF_GetPonderationBillMain_TempList_PackUnion " + HInterID + ",'" + HBillNo + "','" + HBillType + "'", "h_p_KF_GetPonderationBillMain_TempList_PackUnion", ref DBUtility.ClsPub.sExeReturnInfo);
 
            //生成首行标题
            if (DSet == null)
            {
                return;
            }
            if (DSet.Tables[1].Rows.Count > 0)
            {
                //写入主表信息
                txtHCusName.Text = DBUtility.ClsPub.isStrNull(DSet.Tables[1].Rows[0]["客户"]);
                txtHConveyCompName.Text = DBUtility.ClsPub.isStrNull(DSet.Tables[1].Rows[0]["运输公司"]);
                txtHLinkMan.Text = DBUtility.ClsPub.isStrNull(DSet.Tables[1].Rows[0]["联系人"]);
                txtHLinkPhone.Text = DBUtility.ClsPub.isStrNull(DSet.Tables[1].Rows[0]["联系电话"]);
                txtHAddress.Text = DBUtility.ClsPub.isStrNull(DSet.Tables[1].Rows[0]["收件地址"]);
                txtHSourceBillNo.Text = DBUtility.ClsPub.isStrNull(DSet.Tables[1].Rows[0]["源单单号"]);
                txtHPackRemark.Text = DBUtility.ClsPub.isStrNull(DSet.Tables[1].Rows[0]["外包备注"]);
                txtHBillRemark.Text = DBUtility.ClsPub.isStrNull(DSet.Tables[1].Rows[0]["整单摘要"]);
            }
            //
            grdMain.DataSource = DSet.Tables[0].DefaultView;
 
            ////设置合计列
            //string sTotalCol = "";
            //sTotalCol = DBUtility.Gy_BaseFun.GetTotalCols(DSet);
            //string[] sT;
            //sT = sTotalCol.Split(Convert.ToChar(","));
            //oSumGrid.BuildTotalCols(sT);
            //冻结
            int FrCol = DBUtility.ClsPub.isInt(frmCondition.txtFrozenCol.Text);
            string s = frmCondition.cmbHComplete.Text;
            ClsPub1.DisplayGrid(grdMain, this.Name, s, FrCol);
            //扫描过的变黄色
            //int HMustQtyCol = Fun_GetCol("应发数量");
            int HRelQtyCol = Fun_GetCol("数量");
            for (int i = 0; i < grdMain.Rows.Count; i++)
            {
                if(DBUtility.ClsPub.isDoule(grdMain.Rows[i].Cells[HRelQtyCol].Value)>0)
                {
                    grdMain.Rows[i].DefaultCellStyle.BackColor = Color.Yellow;
                }
                else
                {
                    grdMain.Rows[i].DefaultCellStyle.BackColor = Color.White;
                }
            }
            //画线
            //GraphLine();
            //Total();
        }
 
        #endregion
 
 
        #region 界面基础资料控件处理
 
        //班组
        private void cmdHGroupID_Click(object sender, EventArgs e)
        {
            SCM.ClsGy_Group_View oGroup = new SCM.ClsGy_Group_View();
            string sWhere = "";
            if (oGroup.RefreshView(sWhere))
            {
                this.txtHGroupID.Text = oGroup.oModel.HName;
                this.txtHGroupID.Tag = oGroup.oModel.HItemID.ToString();
            }
            else
            {
                this.txtHGroupID.Text = "";
            }
        }
 
        private void txtHGroupID_TextChanged(object sender, EventArgs e)
        {
            BLL.ClsPub_BLL.Sub_ClearText(txtHGroupID);
        }
 
        //生产资源
        private void cmdHSourceID_Click(object sender, EventArgs e)
        {
            SCM.ClsIF_Source_View oSource = new SCM.ClsIF_Source_View();
            string sWhere = "";
            if (oSource.RefreshView(sWhere))
            {
                this.txtHSourceID.Text = oSource.oModel.HName;
                this.txtHSourceID.Tag = oSource.oModel.HItemID.ToString();
            }
            else
            {
                this.txtHSourceID.Text = "";
            }
        }
 
        private void txtHSourceID_TextChanged(object sender, EventArgs e)
        {
            BLL.ClsPub_BLL.Sub_ClearText(txtHSourceID);
        }
 
        //工序
        private void cmdHProcessID_Click(object sender, EventArgs e)
        {
            SCM.ClsIF_Process_View oProcess = new SCM.ClsIF_Process_View();
            string sWhere = "";
            if (oProcess.RefreshView(sWhere))
            {
                this.txtHProcessID.Text = oProcess.oModel.HName;
                this.txtHProcessID.Tag = oProcess.oModel.HItemID.ToString();
            }
            else
            {
                this.txtHProcessID.Text = "";
            }
        }
 
        private void txtHProcessID_TextChanged(object sender, EventArgs e)
        {
            BLL.ClsPub_BLL.Sub_ClearText(txtHProcessID);
        }
 
        //车间
        private void cmdHDeptID_Click(object sender, EventArgs e)
        {
            SCM.ClsIF_Department_View oDept = new SCM.ClsIF_Department_View();
            string sWhere = "";
            if (oDept.RefreshView(sWhere))
            {
                this.txtHDeptID.Text = oDept.oModel.HName;
                this.txtHDeptID.Tag = oDept.oModel.HItemID.ToString();
            }
            else
            {
                this.txtHDeptID.Text = "";
            }
        }
 
        private void txtHDeptID_TextChanged(object sender, EventArgs e)
        {
            BLL.ClsPub_BLL.Sub_ClearText(txtHDeptID);
        }
 
        //操作员
        private void cmdHEmpID_Click(object sender, EventArgs e)
        {
            SCM.ClsIF_Employee_View oEmp = new SCM.ClsIF_Employee_View();
            string sWhere = "";
            if (oEmp.RefreshView(sWhere))
            {
                this.txtHEmpID.Text = oEmp.oModel.HName;
                this.txtHEmpID.Tag = oEmp.oModel.HItemID.ToString();
            }
            else
            {
                this.txtHEmpID.Text = "";
            }
        }
 
        private void txtHEmpID_TextChanged(object sender, EventArgs e)
        {
            BLL.ClsPub_BLL.Sub_ClearText(txtHEmpID);
        }
 
        //工作中心
        private void cmdHWorkCenterID_Click(object sender, EventArgs e)
        {
            SCM.ClsIF_WorkCenter_View oWorkCenter = new SCM.ClsIF_WorkCenter_View();
            string sWhere = "";
            if (oWorkCenter.RefreshView(sWhere))
            {
                this.txtHWorkCenterID.Text = oWorkCenter.oModel.HName;
                this.txtHWorkCenterID.Tag = oWorkCenter.oModel.HItemID.ToString();
            }
            else
            {
                this.txtHWorkCenterID.Text = "";
            }
        }
 
        private void txtHWorkCenterID_TextChanged(object sender, EventArgs e)
        {
            BLL.ClsPub_BLL.Sub_ClearText(txtHWorkCenterID);
        }
 
        //组织
        private void cmdHOWNERID_Click(object sender, EventArgs e)
        {
            SCM.ClsXt_ORGANIZATIONS_View oOR = new SCM.ClsXt_ORGANIZATIONS_View();
            string sWhere = "";
            if (oOR.RefreshView(sWhere))
            {
                this.txtHOWNERID.Text = oOR.oModel.HName;
                this.txtHOWNERID.Tag = oOR.oModel.HItemID.ToString();
                HOrgID = oOR.oModel.HItemID;
                HOrgNumber = oOR.oModel.HNumber;
            }
            else
            {
                this.txtHOWNERID.Text = "";
            }
        }
 
        private void txtHOWNERID_TextChanged(object sender, EventArgs e)
        {
            BLL.ClsPub_BLL.Sub_ClearText(txtHOWNERID);
        }
 
        #endregion
 
 
        private SerialPort ComDevice = null;
 
        //打开串口
        private void cmdOpenCom_Click(object sender, EventArgs e)
        {
            OpenCom();
        }
 
        public void OpenCom()
        {
            if (!ComDevice.IsOpen)
            {
                
                try
                {
                    ComDevice.PortName = txtPortName.Text;
                    ComDevice.BaudRate = int.Parse(txtBaudRate.Text);
                    switch (cmbParity.SelectedItem.ToString())
                    {
                        case "0":
                            ComDevice.Parity = Parity.None;
                            break;
                        case "1":
                            ComDevice.Parity = Parity.Odd;
                            break;
                        case "2":
                            ComDevice.Parity = Parity.Even;
                            break;
                        case "3":
                            ComDevice.Parity = Parity.Mark;
                            break;
                        case "4":
                            ComDevice.Parity = Parity.Space;
                            break;
                        default:
                            break;
                    }
                  
                    ComDevice.DataBits = int.Parse(txtDataBits.Text);
                    switch (cmbStopBits.SelectedItem.ToString())
                    {
                        case "0":
                            ComDevice.StopBits = StopBits.None;
                            break;
                        case "1":
                            ComDevice.StopBits = StopBits.One;
                            break;
                        case "2":
                            ComDevice.StopBits = StopBits.Two;
                            break;
                        case "1.5":
                            ComDevice.StopBits = StopBits.OnePointFive;
                            break;
                        default:
                            break;
                    }
                    
                    ComDevice.Open(); 
                    lblComStatus.Text = "串口状态:开启";
                    timer3.Enabled = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("打开串口失败!" + ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); 
                    return;
                }
            }
            else
            {
                //try
                //{
                //    ComDevice.Close();
                //    textBox3.Enabled = true;
                //    textBox4.Enabled = true;
                //    textBox5.Enabled = true;
                //    comboBox1.Enabled = true;
                //    comboBox2.Enabled = true;
                //    AddContent($"串口已关闭");
                //    button1.Enabled = false;
                //    btnPush.Text = "开启串口";
                //}
                //catch (Exception ex)
                //{
                //    MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //    AddContent($"串口关闭失败:{ex.Message}");
                //    return;
                //}
            }
        }
 
        //关闭串口
        private void cmdCloseCom_Click(object sender, EventArgs e)
        {
            CloseCom();
        }
 
        public void CloseCom()
        {
            if (!ComDevice.IsOpen)
            {
                 
            }
            else
            {
                try
                {
                    timer3.Enabled = false;
                    Thread.Sleep(300);
                    ComDevice.Close(); 
                    lblComStatus.Text = "串口状态:关闭";
                    
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); 
                    return;
                }
            }
        }
 
        /// <summary>
        /// 字符串转换16进制字节数组
        /// </summary>
        /// <param name="hexString"></param>
        /// <returns></returns>
        private byte[] strToHexByte(string hexString)
        {
            hexString = hexString.Replace(" ", "");
            if ((hexString.Length % 2) != 0)
                hexString += " ";
            byte[] returnBytes = new byte[hexString.Length / 2];
            for (int i = 0; i < returnBytes.Length; i++)
                returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2).Replace(" ", ""), 16);
            return returnBytes;
        }
        
        /// <summary>
        /// 发送数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="data"></param>
        public bool SendData(byte[] data)
        { 
            if (ComDevice.IsOpen)
            {
                try
                {
                    ComDevice.Write(data, 0, data.Length);//发送数据 
                    return true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); 
                }
                finally
                {
                    //cmdHSetZero.Enabled = true;
                }
            }
            else
            {
                MessageBox.Show("串口未打开", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); 
            }
            return false;
        }
 
        private void timer3_Tick(object sender, EventArgs e)
        {
            //if (!ComDevice.IsOpen)
            //{
            //    return;
            //}
            //byte[] sendData = strToHexByte(txtHSend.Text);
            //SendData(sendData);
 
        }
 
        /// <summary>
        /// 接收数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Com_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            //if (!ComDevice.IsOpen)
            //{
            //    return;
            //}
            //Thread.Sleep(100);
            byte[] ReDatas = new byte[ComDevice.BytesToRead];
            ComDevice.Read(ReDatas, 0, ReDatas.Length);//读取数据
            this.AddData(ReDatas);//输出数据
        }
 
        /// <summary>
        /// 添加数据
        /// </summary>
        /// <param name="data">字节数组</param>
        public void AddData(byte[] data)
        {
            //Thread.Sleep(100);
            StringBuilder sb = new StringBuilder();
            sb.Append(Encoding.ASCII.GetString(data));
            var str = sb.ToString().ToUpper();
            if (str != repeatData)
            {
                repeatData = str;
                var newStr = new StringBuilder();
                var strArray = str.ToCharArray();
                for (int i = 0; i < strArray.Length; i++)
                {
                    var charStr = strArray[i];
                    if (charStr == '+' || charStr == ' ' || charStr == 'K' || charStr == 'G')
                        continue;
                    newStr.Append(strArray[i]);
                }
                double ret = 0;
                if (double.TryParse(newStr.ToString(), out ret))//判断是否是数字
                {
                    //AddContent($"接收数据-{DateTime.Now}:{newStr.ToString()}");
                    lblHBWeight.Text = newStr.ToString();
                    txtHWeight.Text = DBUtility.ClsPub.isDoule(DBUtility.ClsPub.isDoule(lblHBWeight.Text) - DBUtility.ClsPub.isDoule(txtHPWeight.Text), 2);
                }
            } 
        }
 
        //保存参数
        private void cmdHSaveInfo_Click(object sender, EventArgs e)
        { 
            ClsIni.WriteIni("COMINFO", "txtPortName", DBUtility.ClsPub.isStrNull(txtPortName.Text), DBUtility.ClsPub.AppPath + @"/HXERP.ini");
            ClsIni.WriteIni("COMINFO", "txtBaudRate", DBUtility.ClsPub.isStrNull(txtBaudRate.Text), DBUtility.ClsPub.AppPath + @"/HXERP.ini");
            ClsIni.WriteIni("COMINFO", "cmbParity", DBUtility.ClsPub.isStrNull(cmbParity.Text), DBUtility.ClsPub.AppPath + @"/HXERP.ini");
            ClsIni.WriteIni("COMINFO", "txtDataBits", DBUtility.ClsPub.isStrNull(txtDataBits.Text), DBUtility.ClsPub.AppPath + @"/HXERP.ini");
            ClsIni.WriteIni("COMINFO", "cmbStopBits", DBUtility.ClsPub.isStrNull(cmbStopBits.Text), DBUtility.ClsPub.AppPath + @"/HXERP.ini");
            ClsIni.WriteIni("COMINFO", "txtHSend0", DBUtility.ClsPub.isStrNull(txtHSend0.Text), DBUtility.ClsPub.AppPath + @"/HXERP.ini");
            ClsIni.WriteIni("COMINFO", "txtHSend", DBUtility.ClsPub.isStrNull(txtHSend.Text), DBUtility.ClsPub.AppPath + @"/HXERP.ini"); 
        }
 
        private void cmdHEmp2_Click(object sender, EventArgs e)
        {
            SCM.ClsIF_Employee_View oEmp = new SCM.ClsIF_Employee_View();
            string sWhere = "";
            if (oEmp.RefreshView(sWhere))
            {
                this.txtHEmpID2.Text = oEmp.oModel.HName;
                this.txtHEmpID2.Tag = oEmp.oModel.HItemID.ToString();
            }
            else
            {
                this.txtHEmpID2.Text = "";
            }
        }
    }
}