1
zrg
2025-03-10 192bd758abd0dbadff721b3f58700e95cf1ee230
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
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.IO;
 
namespace WarM
{
    public partial class Sc_MESNowWorkBill_Fast : Form
    {
        //BLL.BardCodeHooK BarCode = new BLL.BardCodeHooK();
        public Sc_MESNowWorkBill_Fast()
        {
            InitializeComponent();
            //BarCode.BarCodeEvent += new BLL.BardCodeHooK.BardCodeDeletegate(BarCode_BarCodeEvent);
        }
        //定义列
        public const Int16 HTagCol = 0;
        public const Int16 HSnoCol = 1;
        public const Int16 HProcIDCol = 2;
        public const Int16 HProcNumberCol = 3;
        public const Int16 HProcNameCol = 4;
        public const Int16 HMaterIDCol = 5;
        public const Int16 HMaterNumberCol = 6;
        public const Int16 HMaterNameCol = 7;
        public const Int16 HEmpIDCol = 8;
        public const Int16 HEmpNumberCol = 9;
        public const Int16 HEmpNameCol = 10;
        public const Int16 HGroupIDCol = 11;
        public const Int16 HGroupNumberCol = 12;
        public const Int16 HGroupNameCol = 13;
        public const Int16 HSourceIDCol = 14;
        public const Int16 HSourceNumberCol = 15;
        public const Int16 HSourceNameCol = 16;
        public const Int16 HBadBarCodeCol = 17;
        public const Int16 HBadReasonIDCol = 18;
        public const Int16 HBadReasonNumberCol = 19;
        public const Int16 HBadReasonNameCol = 20;
        public const Int16 HBadCountCol = 21;
        public const Int16 HBadPrirceCol = 22;
        public const Int16 HBadMoneyCol = 23;
        public const Int16 HCheckEmpIDCol = 24;
        public const Int16 HCheckEmpNumberCol = 25;
        public const Int16 HCheckEmpNameCol = 26;
        public const Int16 HICMOInterIDCol = 27;
        public const Int16 HICMOBillNoCol = 28;
        public const Int16 HWWOrderInterIDCol = 29;
        public const Int16 HWWOrderEntryIDCol = 30;
        public const Int16 HWWOrderBillNoCol = 31;
        public const Int16 HSeOrderInterIDCol = 32;
        public const Int16 HSeOrderEntryIDCol = 33;
        public const Int16 HSeOrderBillNoCol = 34;
        public const Int16 HProcExchInterIDCol = 35;
        public const Int16 HProcExchEntryIDCol = 36;
        public const Int16 HProcExchBillNoCol = 37;
        public const Int16 HProcExchReportInterIDCol = 38;
        public const Int16 HProcExchReportEntryIDCol = 39;
        public const Int16 HProcExchReportBillNoCol = 40;
 
        public const Int16 HEntryIDCol = 41;
        public const Int16 HCloseManCol = 42;
        public const Int16 HEntryCloseDateCol = 43;
        public const Int16 HCloseTypeCol = 44;
        public const Int16 HRemarkCol = 45;
        public const Int16 HSourceInterIDCol = 46;
        public const Int16 HSourceEntryIDCol = 47;
        public const Int16 HSourceBillNoCol = 48;
        public const Int16 HSourceBillTypeCol = 49;
        public const Int16 HRelationQtyCol = 50;
        public const Int16 HRelationMoneyCol = 51;
        //
        //
        //表2
        public const Int16 SecHTagCol = 0;
        public const Int16 SecHSnoCol = 1;
        public const Int16 SecHMaterIDCol = 2;
        public const Int16 SecHMaterNumberCol = 3;
        public const Int16 SecHMaterNameCol = 4;
        public const Int16 SecHMaterModelCol = 5;
        public const Int16 SecHBarCodeCol = 6;
        public const Int16 SecHQtyCol = 7;
        public const Int16 SecHWhIDCol = 8;
        public const Int16 SecHWhNumberCol = 9;
        public const Int16 SecHWhNameCol = 10;
        public const Int16 SecHSourceInterIDCol = 11;
        public const Int16 SecHSourceEntryIDCol = 12;
        public const Int16 SecHSourceBillTypeCol = 13;
        public const Int16 SecHSourceBillNoCol = 14;
        //
        public const string ModName = "3787";                   //单据类型
        public string ModCaption = "工位作业指导书";          //单据名称
        public const string ModRightName = "Sc_MESBeginWorkBill";
        public const string ModRightNameEdit = ModRightName + "_Edit";
        public const string ModRightNameCheck = ModRightName + "_Check";
        public const string ModRightNameClose = ModRightName + "_Close";
        public const string ModRightNameDelete = ModRightName + "_Delete";
        public const string ModRightNameMoney = ModRightName + "_Money";
        public const string ModRightNameQty = ModRightName + "_Qty";
        public bool BillChange;                                 //单据修改状态
        //
        public DBUtility.ClsPub.Enum_BillStatus BillStatus;     //单据状态(新增,修改,浏览,更新单价,变更)
        public Int64 KeyID;                                     //单据主内码
        public bool  grdStatus;                                 //网格状态(不可编辑,可编辑)
        public long HICMOInterID = 0;
        public string HICMOBillNo = "";
        public long HMaterID = 0;
        public string HBatchNo = "";
        public DAL.ClsSc_MESBeginWorkBill BillNew =new  DAL.ClsSc_MESBeginWorkBill();   //对应单据类
        public DAL.ClsSc_MESBeginWorkBill BillOld = new DAL.ClsSc_MESBeginWorkBill();   //对应单据类
        Pub_Class.ClsGridListSum oSumGrid = new Pub_Class.ClsGridListSum();
        //-------------------------------------------------------------------------
 
        #region 固定代码
 
         
        //清空界面
        public void Sub_ClearBill()
        { 
            DBUtility.Xt_BaseBillFun.Sub_ClearBill(gbUp);
            //
        }
 
        //窗体加载
        private void Sc_MESNowWorkBill_Fast_Load(object sender, EventArgs e)
        {
            //打印初始化        
            //
            //oSumGrid_Sub.NoCol = SecHSnoCol;
            //oSumGrid_Sub.ogrdMain = grdSub;
            //oSumGrid_Sub.oGridsum = grdSumSub;
            this.Text = ModCaption;     //命名窗体标题
            this.lblCaption.Text = ModCaption;//命名单据标题
            //
            //BarCode.Start();
        }
 
        //首张
        private void Sub_First()
        {
            BillStatus =DBUtility.ClsPub.Enum_BillStatus.BillStatus_View;
            BillOld = new DAL.ClsSc_MESBeginWorkBill();
            if (BillOld.GetFirstBill(ref  ClsPub.sExeReturnInfo))
            {
                this.Sub_ShowBill();
            }
            else  //没有找到则 变为新增状态
            {
                this.Sub_AddBill();
            }
        }
 
        //上张
        private void Sub_Prev()
        {
            BillStatus = DBUtility.ClsPub.Enum_BillStatus.BillStatus_View;
            if (BillOld.GetPrevousBill(ref  ClsPub.sExeReturnInfo,txtHBillNo.Text))
            {
                this.Sub_ShowBill();
            }
        }
 
        //下张
        private void Sub_Next()
        {
            BillStatus = DBUtility.ClsPub.Enum_BillStatus.BillStatus_View;
            if (BillOld.GetNextBill(ref  ClsPub.sExeReturnInfo, txtHBillNo.Text))
            {
                this.Sub_ShowBill();
            }
        }
 
        //末张
        private void Sub_Last()
        {
            BillStatus = DBUtility.ClsPub.Enum_BillStatus.BillStatus_View;
            BillOld = new DAL.ClsSc_MESBeginWorkBill();
            if (BillOld.GetLastBill(ref  ClsPub.sExeReturnInfo))
            {
                this.Sub_ShowBill();
            }
        }
 
        //审核单据
        private void Sub_CheckBill()
        {
            //判断权限
            if (!ClsPub.Security_Log(ModRightNameCheck, 1, true,DBUtility.ClsPub.CurUserName))
            {
                return;
            }
 
            string s = "";
            if (!DBUtility.Xt_BaseBillFun.Fun_AllowCheckBill(BillOld, ref s))
            {
                MessageBox.Show(s + ",不允许审核", "提示");
                return;
            }
            if (BillOld.CheckBill(BillOld.omodel.HInterID, ref ClsPub.sExeReturnInfo) == true)
            {
                BillChange = true; 
                this.Sub_ShowBill(); 
            }
            else
            {
                MessageBox.Show("审核失败!原因:" + ClsPub.sExeReturnInfo, "提示");
            }
        }
        //反审单据
        private void Sub_AbandonCheck()
        {
            //判断权限
            if (!ClsPub.Security_Log(ModRightNameCheck, 1, true, DBUtility.ClsPub.CurUserName))
            {
                return;
            }
            //
            string s = "";
            if (DBUtility.Xt_BaseBillFun.Fun_AllowAbandonCheckBill(BillOld.omodel.HChecker, ref s) == false)
            {
                MessageBox.Show("当前操作员与审核人不一致,不允许反审核!", "提示");
                return;
            }
            if (BillOld.AbandonCheck(BillOld.omodel.HInterID, ref ClsPub.sExeReturnInfo) == true)
            {
                BillChange = true; 
                this.Sub_ShowBill(); 
            }
            else
            {
                MessageBox.Show("反审核失败!原因:" + ClsPub.sExeReturnInfo, "提示");
            }
        }
        //关闭单据
        private void Sub_CloseBill()
        {
            //判断权限
            if (!ClsPub.Security_Log(ModRightNameClose, 1, true, DBUtility.ClsPub.CurUserName))
            {
                return;
            }
            string s = "";
            if (!DBUtility.Xt_BaseBillFun.Fun_AllowCloseBill(BillOld, ref s))
            {
                MessageBox.Show(s + ",不允许关闭", "提示");
                return;
            }
            if (BillOld.CloseBill(BillOld.omodel.HInterID, ref ClsPub.sExeReturnInfo) == true)
            {
                BillChange = true;
                this.Sub_ShowBill(); 
            }
            else
            {
                MessageBox.Show("关闭失败!原因:" + ClsPub.sExeReturnInfo, "提示");
            }
        }
        //反关闭单据
        private void Sub_Cancel()
        {
            //判断权限
            if (!ClsPub.Security_Log(ModRightNameClose, 1, true, DBUtility.ClsPub.CurUserName))
            {
                return;
            }
            string s = "";
            if (!DBUtility.Xt_BaseBillFun.Fun_AllowCancelBill(BillOld, ref s))
            {
                MessageBox.Show(s + ",不允许恢复", "提示");
                return;
            }
            if (BillOld.CancelClose(BillOld.omodel.HInterID, ref ClsPub.sExeReturnInfo) == true)
            {
                BillChange = true;
                this.Sub_ShowBill(); 
            }
            else
            {
                MessageBox.Show("恢复失败!原因:" + ClsPub.sExeReturnInfo, "提示");
            }
        }
        //作废单据
        private void Sub_Cancelltion()
        {
            //判断权限
            if (!ClsPub.Security_Log(ModRightNameDelete, 1, true, DBUtility.ClsPub.CurUserName))
            {
                return;
            }
            string s = "";
            if (!DBUtility.Xt_BaseBillFun.Fun_AllowCancelltionBill(BillOld, ref s))
            {
                MessageBox.Show(s + ",不允许作废", "提示");
                return;
            }
            if (BillOld.Cancelltion(BillOld.omodel.HInterID, ref ClsPub.sExeReturnInfo) == true)
            {
                BillChange = true;
                this.Sub_ShowBill(); 
            }
            else
            {
                MessageBox.Show("作废失败!原因:" + ClsPub.sExeReturnInfo, "提示");
            }
        }
        //反作废
        private void Sub_AbandonCancelltion()
        {
            //判断权限
            if (!ClsPub.Security_Log(ModRightNameDelete, 1, true, DBUtility.ClsPub.CurUserName))
            {
                return;
            }
            string s = "";
            if (!DBUtility.Xt_BaseBillFun.Fun_AllowAbandonCancelltionBill(BillOld, ref s))
            {
                MessageBox.Show(s + ",不允许恢复正常", "提示");
                return;
            }
            if (BillOld.AbandonCancelltion(BillOld.omodel.HInterID, ref ClsPub.sExeReturnInfo) == true)
            {
                BillChange = true;
                this.Sub_ShowBill(); 
            }
            else
            {
                MessageBox.Show("作废失败!原因:" + ClsPub.sExeReturnInfo, "提示");
            }
        }
        //新增按纽
        private void xz_Click(object sender, EventArgs e)
        {
            //cmbSourceBillType.Items.Clear();
            //cmbSourceBillType.Items.Add("发货通知单");
            //cmbSourceBillType.Items.Add("手工录入");
            //cmbSourceBillType.SelectedIndex = 0;
            redblue.Checked = false;
            this.Sub_AddBill();
        }
        //修改按纽
        private void xg_Click(object sender, EventArgs e)
        {
 
        }
        //删除按钮
        private void sc_Click(object sender, EventArgs e)
        {
 
        }
        //保存按钮
        private void bc_Click(object sender, EventArgs e)
        {
 
        }
        //放弃按钮
        private void fq_Click(object sender, EventArgs e)
        {
 
        }
        //审核按钮
        private void sh_Click(object sender, EventArgs e)
        {
 
        }
        //放弃审核按钮
        private void qsh_Click(object sender, EventArgs e)
        {
 
        }
        //关闭按钮
        private void gb_Click(object sender, EventArgs e)
        {
 
        }
        //恢复按钮
        private void hf_Click(object sender, EventArgs e)
        {
 
        }
        //作废按钮
        private void zf_Click(object sender, EventArgs e)
        {
 
        }
        //反作废按钮
        private void zc_Click(object sender, EventArgs e)
        {
 
        }
        //首张单据按钮
        private void sz_Click(object sender, EventArgs e)
        {
 
        }
        //上一张按钮
        private void syz_Click(object sender, EventArgs e)
        {
 
        }
        //下一张按钮
        private void xyz_Click(object sender, EventArgs e)
        {
 
        }
        //末张按钮
        private void mz_Click(object sender, EventArgs e)
        {
 
        }
        //退出按钮
        private void tc_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        
        //根据编辑状态 设置 控件是否允许录入    
        private void Sub_LrtextStatus(bool TextEnabled)
        {
            if (TextEnabled == true)
            {
                //控件全部有效
                gbUp.Enabled = true;
 
 
            }
            else
            {   //控件全部无效
                gbUp.Enabled = false;
 
            }
        }
        //复制单据
        private void Sub_CopyBill()
        {
            this.BillStatus =DBUtility.ClsPub.Enum_BillStatus.BillStatus_AddNew;
            this.Sub_OperStatus();//设置TOOLBAR
            this.txtHBillNo.Text = ClsPub.CreateBillCode(BillNew.BillType, ref ClsPub.sExeReturnInfo, true);//得到新单号 
            this.txtHBillNo.Enabled = true;
            //this.txtHBillNo.Focus();
 
            //清空GIRD 源单信息
            //DBUtility.Xt_BaseBillFun.SetDataGrid(grdMain, 0, HPOOrderEntryIDCol, grdMain.Rows.Count - 1, HCloseTypeCol, "");
        }
        //复制按钮
        private void fz_Click(object sender, EventArgs e)
        {
            Sub_CopyBill();
        }
        //timer
        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            //DAL.ClsK3_Material_View oMater = new DAL.ClsK3_Material_View();
            this.Sub_AddBill();
            this.ShowPic();
            //txtHICMOBillNo.Text = HICMOBillNo;
            //txtHBatchNo.Text = HBatchNo;
            //if (oMater.GetInfoByID(HMaterID))
            //{
            //    txtHMaterID.Text = oMater.omodel.HNumber;
            //    txtHName.Text = oMater.omodel.HName;
            //    txtHModel.Text = oMater.omodel.HModel;
            //}
        }
 
        //窗体卸载
        private void Sc_MESNowWorkBill_Fast_FormClosing(object sender, FormClosingEventArgs e)
        {
            BillStatus = DBUtility.ClsPub.Enum_BillStatus.BillStatus_AddNew;
 
        }
        //新增单据
        private void Sub_AddBill()
        {
            //this.BillNew = new DAL.ClsSc_MESBeginWorkBill();
            //this.BillOld = new DAL.ClsSc_MESBeginWorkBill();
            this.BillStatus = DBUtility.ClsPub.Enum_BillStatus.BillStatus_AddNew;
            this.Sub_OperStatus();//设置TOOLBAR
            this.Sub_ClearBill();//清空界面
            //this.txtHBillNo.Text = ClsPub.CreateBillCode(BillNew.BillType, ref ClsPub.sExeReturnInfo, true);//得到新单号
            //this.txtHBillNo.Enabled = true;
            this.txtHICMOBillNo.Focus();
            //灰度源单类型
            //cmbSourceBillType.Enabled = true;
            //txtHBeginWorkTime.Text = DBUtility.ClsPub.GetServerDate(-1);
        }
        //TOOLBAR状态  按钮是否灰度
        public void Sub_OperStatus()
        {
            switch (BillStatus)
            {
                case DBUtility.ClsPub.Enum_BillStatus.BillStatus_View:
                    //浏览状态
                    dy.Enabled = true;
                    yl.Enabled = true;
                    xz.Enabled = true;
                    xg.Enabled = true;
                    sc.Enabled = true;
                    AddRow.Enabled = false;
                    DelRow.Enabled = false;
                    bc.Enabled = false;
                    fq.Enabled = false;
                    sz.Enabled = true;
                    syz.Enabled = true;
                    xyz.Enabled = true;
                    mz.Enabled = true;
                    tc.Enabled = true;
                    redblue.Enabled = false;
                    //未审核
 
                    Sub_LrtextStatus(false);
                    grdStatus = false;
                    break;
                case DBUtility.ClsPub.Enum_BillStatus.BillStatus_AddNew:
                    //新增状态
                    dy.Enabled = false;
                    yl.Enabled = false;
                    xz.Enabled = false;
                    xg.Enabled = false;
                    sc.Enabled = false;
                    AddRow.Enabled = true;
                    DelRow.Enabled = true;
                    bc.Enabled = true;
                    fq.Enabled = true;
                    sh.Enabled = false;
                    qsh.Enabled = false;
                    //gb.Enabled = false;
                    //hf.Enabled = false;
                    //zf.Enabled = false;
                    //zc.Enabled = false;
                    sz.Enabled = false;
                    syz.Enabled = false;
                    xyz.Enabled = false;
                    mz.Enabled = false;
                    tc.Enabled = true;
                    Sub_LrtextStatus(true);
                    grdStatus = true;
                    redblue.Enabled = true;
                    //未审核
                    pic1.Visible = false;
                    pic1.Image = null;
                    //
                    break;
                case DBUtility.ClsPub.Enum_BillStatus.BillStatus_Modify:
                    //修改状态
                    dy.Enabled = false;
                    yl.Enabled = false;
                    xz.Enabled = false;
                    xg.Enabled = false;
                    sc.Enabled = false;
                    AddRow.Enabled = true;
                    DelRow.Enabled = true;
                    bc.Enabled = true;
                    fq.Enabled = true;
                    sh.Enabled = false;
                    qsh.Enabled = false;
                    //gb.Enabled = false;
                    //hf.Enabled = false;
                    //zf.Enabled = false;
                    //zc.Enabled = false;
                    sz.Enabled = false;
                    syz.Enabled = false;
                    xyz.Enabled = false;
                    mz.Enabled = false;
                    tc.Enabled = true;
                    Sub_LrtextStatus(true);
                    grdStatus = true;
                    redblue.Enabled = true;
                    //未审核
                    pic1.Visible = false;
                    pic1.Image = null;
                    //
                    break;
            }
 
        }
        #endregion  
 
        #region  读写类
        //显示单据
        public void Sub_ShowBill()
        {
            //DAL.ClsK3_Department_View oDept = new DAL.ClsK3_Department_View();
            //DAL.ClsGy_Group_View oGroup = new DAL.ClsGy_Group_View();//班组
            //DAL.ClsK3_Unit_View oUnit = new DAL.ClsK3_Unit_View();
            //DAL.ClsK3_Process_View oPro = new DAL.ClsK3_Process_View();//工序
            //DAL.ClsK3_Material_View oMater = new DAL.ClsK3_Material_View();
            //DAL.ClsK3_Employee_View oEmp = new DAL.ClsK3_Employee_View();
            //DAL.ClsGy_Source_View oSource = new DAL.ClsGy_Source_View();//生产资源
            ////判断是否存在单据
            //if (BillOld.ShowBill(BillOld.omodel.HInterID, ref  ClsPub.sExeReturnInfo) == false)
            //{
            //    MessageBox.Show(ClsPub.sExeReturnInfo, "提示");
            //    return;
            //}
            ////清空
            //Sub_ClearBill();
            ////加载表头
            //if (oDept.GetInfoByID(BillOld.omodel.HDeptID))
            //{
            //    this.txtHDeptID.Tag = oDept.omodel.HItemID.ToString().Trim();
            //    this.txtHDeptID.Text = oDept.omodel.HName;
            //    //this.txtHDeptNumber.Text = oDept.omodel.HNumber;
            //}
            //else
            //{
            //    this.txtHDeptID.Text = "";
            //    //this.txtHDeptNumber.Text = "";
            //}
            ////
            //if (oMater.GetInfoByID(BillOld.omodel.HMaterID))
            //{
            //    this.txtHMaterID.Tag = oMater.omodel.HItemID.ToString().Trim();
            //    this.txtHMaterID.Text = oMater.omodel.HNumber;
            //    this.txtHName.Text = oMater.omodel.HName;
            //    this.txtHModel.Text = oMater.omodel.HModel;
            //}
            //else
            //{
            //    this.txtHMaterID.Text = "";
            //    this.txtHName.Text = "";
            //    this.txtHModel.Text = "";
            //}
            ////
            ////if (oUnit.GetInfoByID(BillOld.omodel.HUnitID))
            ////{
            ////    this.txtHUnitID.Tag = oUnit.omodel.HItemID.ToString().Trim();
            ////    this.txtHUnitID.Text = oUnit.omodel.HName;
            ////    //this.txtHUnitNumber.Text = oUnit.omodel.HNumber;
            ////}
            ////else
            ////{
            ////    this.txtHUnitID.Text = "";
            ////    //this.txtHUnitNumber.Text = "";
            ////}
            ////
            //if (oPro.GetInfoByID(BillOld.omodel.HProcID))
            //{
            //    this.txtHProcID.Tag = oPro.omodel.HItemID.ToString().Trim();
            //    this.txtHProcID.Text = oPro.omodel.HName;
            //}
            //else
            //{
            //    this.txtHProcID.Text = "";
            //}
            ////
            //if (oSource.GetInfoByID(BillOld.omodel.HSourceID))
            //{
            //    this.txtHSourceID.Tag = oSource.omodel.HItemID.ToString().Trim();
            //    this.txtHSourceID.Text = oSource.omodel.HName;
            //}
            //else
            //{
            //    this.txtHSourceID.Text = "";
            //}
            ////
            //if (oEmp.GetInfoByID(BillOld.omodel.HEmpID))
            //{
            //    this.txtHWorkEmpID.Tag = oEmp.omodel.HItemID.ToString().Trim();
            //    this.txtHWorkEmpID.Text = oEmp.omodel.HName;
            //}
            //else
            //{
            //    this.txtHWorkEmpID.Text = "";
            //}
            ////
            //if (oGroup.GetInfoByID(BillOld.omodel.HGroupID))
            //{
            //    this.txtHGroupID.Tag = oGroup.omodel.HItemID.ToString().Trim();
            //    this.txtHGroupID.Text = oGroup.omodel.HName;
            //}
            //else
            //{
            //    this.txtHGroupID.Text = "";
            //}
            ////============================================================
            ////单据固定赋值
            //this.dtpHDate.Value = BillOld.omodel.HDate;
            //this.txtHBillNo.Text = BillOld.omodel.HBillNo;
            //this.txtHRemark.Text = BillOld.omodel.HRemark;
 
            ////
            //this.txtHICMOBillNo.Tag = BillOld.omodel.HICMOInterID.ToString();
            //this.txtHICMOBillNo.Text = BillOld.omodel.HICMOBillNo;
            //this.txtHBatchNo.Text = BillOld.omodel.HBatchNo;
            //this.txtHBeginWorkTime.Text = BillOld.omodel.HBeginWorkTime.ToString();
            ////this.txtHProcExchInterID.Text = BillOld.omodel.HProcExchInterID.ToString().Trim();
            ////this.txtHProcExchEntryID.Text = BillOld.omodel.HProcExchEntryID.ToString().Trim();
            ////this.txtHProcExchBillNo.Text = BillOld.omodel.HProcExchBillNo;
 
            //////加载表体
            ////initGrid();
            //////initGrid_Sub();
            ////int i = 0;
            ////foreach (Model.ClsSc_MESBeginWorkBillSub oSub in BillOld.DetailColl)
            ////{
            ////    if (i >= grdMain.RowCount - 1)
            ////        grdMain.Rows.Add();
            ////    //单据固定赋值
            ////    grdMain.Rows[i].Cells[HTagCol].Value = "*";
            ////    grdMain.Rows[i].Cells[HEntryIDCol].Value = oSub.HEntryID.ToString();
            ////    grdMain.Rows[i].Cells[HRemarkCol].Value = oSub.HRemark;
            ////    grdMain.Rows[i].Cells[HCloseManCol].Value = oSub.HCloseMan;
            ////    grdMain.Rows[i].Cells[HEntryCloseDateCol].Value = oSub.HEntryCloseDate;
            ////    grdMain.Rows[i].Cells[HCloseTypeCol].Value = oSub.HCloseType;
            ////    grdMain.Rows[i].Cells[HSourceBillNoCol].Value = oSub.HSourceBillNo;
            ////    grdMain.Rows[i].Cells[HSourceInterIDCol].Value = oSub.HSourceInterID.ToString();
            ////    grdMain.Rows[i].Cells[HSourceEntryIDCol].Value = oSub.HSourceEntryID.ToString();
            ////    grdMain.Rows[i].Cells[HSourceBillTypeCol].Value = oSub.HSourceBillType.Trim();
            ////    grdMain.Rows[i].Cells[HRelationQtyCol].Value = oSub.HRelationQty.ToString();
            ////    grdMain.Rows[i].Cells[HRelationMoneyCol].Value = oSub.HRelationMoney.ToString();
            ////    //======================================================================================
            ////    //
            ////    grdMain.Rows[i].Cells[HProcIDCol].Value = oSub.HProcID.ToString();
            ////    if (oPro.GetInfoByID(oSub.HProcID))
            ////    {
            ////        grdMain.Rows[i].Cells[HProcNumberCol].Value = oPro.omodel.HNumber;
            ////        grdMain.Rows[i].Cells[HProcNameCol].Value = oPro.omodel.HName;
 
            ////    }
            ////    else
            ////    {
            ////        grdMain.Rows[i].Cells[HProcNumberCol].Value = "";
            ////        grdMain.Rows[i].Cells[HProcNameCol].Value = "";
            ////    }
            ////    //
            ////    grdMain.Rows[i].Cells[HMaterIDCol].Value = oSub.HMaterID.ToString();
            ////    if (oMater.GetInfoByID(oSub.HMaterID))
            ////    {
            ////        grdMain.Rows[i].Cells[HMaterNumberCol].Value = oMater.omodel.HNumber;
            ////        grdMain.Rows[i].Cells[HMaterNameCol].Value = oMater.omodel.HName;
 
            ////    }
            ////    else
            ////    {
            ////        grdMain.Rows[i].Cells[HMaterNumberCol].Value = "";
            ////        grdMain.Rows[i].Cells[HMaterNameCol].Value = "";
            ////    }
            ////    //
            ////    grdMain.Rows[i].Cells[HEmpIDCol].Value = oSub.HEmpID.ToString();
            ////    if (oEmp.GetInfoByID(oSub.HEmpID))
            ////    {
            ////        grdMain.Rows[i].Cells[HEmpNumberCol].Value = oEmp.omodel.HNumber;
            ////        grdMain.Rows[i].Cells[HEmpNameCol].Value = oEmp.omodel.HName;
 
            ////    }
            ////    else
            ////    {
            ////        grdMain.Rows[i].Cells[HEmpNumberCol].Value = "";
            ////        grdMain.Rows[i].Cells[HEmpNameCol].Value = "";
            ////    }
            ////    //
            ////    grdMain.Rows[i].Cells[HGroupIDCol].Value = oSub.HGroupID.ToString();
            ////    if (oGroup.GetInfoByID(oSub.HGroupID))
            ////    {
            ////        grdMain.Rows[i].Cells[HGroupNumberCol].Value = oGroup.omodel.HNumber;
            ////        grdMain.Rows[i].Cells[HGroupNameCol].Value = oGroup.omodel.HName;
 
            ////    }
            ////    else
            ////    {
            ////        grdMain.Rows[i].Cells[HGroupNumberCol].Value = "";
            ////        grdMain.Rows[i].Cells[HGroupNameCol].Value = "";
            ////    }
            ////    //
            ////    grdMain.Rows[i].Cells[HSourceIDCol].Value = oSub.HSourceID.ToString();
            ////    if (oSource.GetInfoByID(oSub.HSourceID))
            ////    {
            ////        grdMain.Rows[i].Cells[HSourceNumberCol].Value = oSource.omodel.HNumber;
            ////        grdMain.Rows[i].Cells[HSourceNameCol].Value = oSource.omodel.HName;
 
            ////    }
            ////    else
            ////    {
            ////        grdMain.Rows[i].Cells[HSourceNumberCol].Value = "";
            ////        grdMain.Rows[i].Cells[HSourceNameCol].Value = "";
            ////    }
            ////    //
            ////    grdMain.Rows[i].Cells[HBadReasonIDCol].Value = oSub.HBadReasonID.ToString();
            ////    if (oBad.GetInfoByID(oSub.HBadReasonID))
            ////    {
            ////        grdMain.Rows[i].Cells[HBadReasonNumberCol].Value = oBad.omodel.HNumber;
            ////        grdMain.Rows[i].Cells[HBadReasonNameCol].Value = oBad.omodel.HName;
 
            ////    }
            ////    else
            ////    {
            ////        grdMain.Rows[i].Cells[HBadReasonNumberCol].Value = "";
            ////        grdMain.Rows[i].Cells[HBadReasonNameCol].Value = "";
            ////    }
            ////    //
            ////    grdMain.Rows[i].Cells[HCheckEmpIDCol].Value = oSub.HCheckEmpID.ToString();
            ////    if (oEmp.GetInfoByID(oSub.HCheckEmpID))
            ////    {
            ////        grdMain.Rows[i].Cells[HCheckEmpNumberCol].Value = oEmp.omodel.HNumber;
            ////        grdMain.Rows[i].Cells[HCheckEmpNameCol].Value = oEmp.omodel.HName;
 
            ////    }
            ////    else
            ////    {
            ////        grdMain.Rows[i].Cells[HCheckEmpNumberCol].Value = "";
            ////        grdMain.Rows[i].Cells[HCheckEmpNameCol].Value = "";
            ////    }
            ////    //
            ////    grdMain.Rows[i].Cells[HBadBarCodeCol].Value = oSub.HBadBarCode.ToString();
            ////    grdMain.Rows[i].Cells[HBadCountCol].Value = oSub.HBadCount.ToString();
            ////    grdMain.Rows[i].Cells[HBadPrirceCol].Value = oSub.HBadPrirce.ToString();
            ////    grdMain.Rows[i].Cells[HBadMoneyCol].Value = oSub.HBadMoney.ToString();
            ////    grdMain.Rows[i].Cells[HICMOInterIDCol].Value = oSub.HICMOInterID.ToString();
            ////    grdMain.Rows[i].Cells[HICMOBillNoCol].Value = oSub.HICMOBillNo;
            ////    grdMain.Rows[i].Cells[HWWOrderInterIDCol].Value = oSub.HWWOrderInterID.ToString();
            ////    grdMain.Rows[i].Cells[HWWOrderEntryIDCol].Value = oSub.HWWOrderEntryID.ToString();
            ////    grdMain.Rows[i].Cells[HWWOrderBillNoCol].Value = oSub.HWWOrderBillNo;
            ////    grdMain.Rows[i].Cells[HSeOrderInterIDCol].Value = oSub.HSeOrderInterID.ToString();
            ////    grdMain.Rows[i].Cells[HSeOrderEntryIDCol].Value = oSub.HSeOrderEntryID.ToString();
            ////    grdMain.Rows[i].Cells[HSeOrderBillNoCol].Value = oSub.HSeOrderBillNo;
            ////    grdMain.Rows[i].Cells[HProcExchInterIDCol].Value = oSub.HProcExchInterID.ToString();
            ////    grdMain.Rows[i].Cells[HProcExchEntryIDCol].Value = oSub.HProcExchEntryID.ToString();
            ////    grdMain.Rows[i].Cells[HProcExchBillNoCol].Value = oSub.HProcExchBillNo;
            ////    grdMain.Rows[i].Cells[HProcExchReportInterIDCol].Value = oSub.HProcExchReportInterID.ToString();
            ////    grdMain.Rows[i].Cells[HProcExchReportEntryIDCol].Value = oSub.HProcExchReportEntryID.ToString();
            ////    grdMain.Rows[i].Cells[HProcExchReportBillNoCol].Value = oSub.HProcExchReportBillNo;
               
            ////    i = i + 1;
            //}
            ////GRID允许刷新 
            //DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid);
            ////
            //Sub_OperStatus();
            ////灰度源单类型
            ////cmbSourceBillType.Enabled = false;
        }
 
        //单据完整性判断          未完成
        private bool Sub_AllowSave()
        {
            //必输项目是否为空
            //if (DBUtility.ClsPub.isDoule(txtHQty.Text) <= 0)
            //{
            //    MessageBox.Show("实做数量不能为0!", "提示");
            //    return false;
            //}
            if (DBUtility.ClsPub.isLong(txtHProcID.Tag) == 0)
            {
                MessageBox.Show("工序没有选择!", "提示");
                return false;
            }
            if (DBUtility.ClsPub.isLong(txtHMaterID.Tag) == 0)
            {
                MessageBox.Show("产品没有选择!", "提示");
                return false;
            }
            //if (DBUtility.ClsPub.isLong(txtHUnitID.Tag) == 0)
            //{
            //    MessageBox.Show("单位没有选择!", "提示");
            //    return false;
            //}
            //单据号是否重复
            if (BillNew.IsExistBillNo(ref ClsPub.sExeReturnInfo, txtHBillNo.Text.Trim(), BillStatus, BillOld.omodel.HInterID))
            {
                MessageBox.Show("单据号重复!不允许保存!", "提示");
                return false;
            }
            ////明细表是否为零行
            //bool b = false;
            //for (int i = 0; i < grdMain.RowCount; i++)
            //{
            //    if (!IsNullRow(i))
            //    {
            //        b = true;
            //        break;
            //    }
            //}
            //if (b == false)
            //{
            //    MessageBox.Show("表体明细行不存在!请录入!", "提示");
            //    return false;
            //}
            return true;
        }
        //保存单据
        private bool Sub_SaveBill()
        {
            //Model.ClsSc_MESBeginWorkBillSub oBillSub = new Model.ClsSc_MESBeginWorkBillSub();
            ////判断权限
            ////if (!ClsPub.Security_Log(ModRightNameEdit, 1, true, DBUtility.ClsPub.CurUserName))
            ////{
            return false;
            ////}
            ////
            //Int32 i;
            //bool bResult;
            //BillNew = new DAL.ClsSc_MESBeginWorkBill();
            ////失去焦点
            //lblCaption.Focus();
            //if (!Sub_AllowSave())//单据完整性判断
            //    return false;
            ////赋值ID
            //if (BillStatus ==DBUtility.ClsPub.Enum_BillStatus.BillStatus_Modify)
            //    BillNew.omodel.HInterID = BillOld.omodel.HInterID;
            //else if (BillStatus == DBUtility.ClsPub.Enum_BillStatus.BillStatus_UpdatePrice)
            //    BillNew.omodel.HInterID = BillOld.omodel.HInterID;
            ////主类赋值
            ////判断会计期是否合理
            //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;
            //}
            ////源单信息
            ////BillNew.omodel.HMainSourceBillType = cmbSourceBillType.Text;
            ////
            //BillNew.omodel.HYear = sYear;
            //BillNew.omodel.HPeriod = sPeriod;
            ////固定赋值=================================
            //BillNew.omodel.HBillNo = this.txtHBillNo.Text.Trim();  //在赋值类前就处理好字符串和数字
            //BillNew.omodel.HDate = this.dtpHDate.Value;
            //BillNew.omodel.HRemark = this.txtHRemark.Text.Trim();
            ////====================================================
            //BillNew.omodel.HICMOInterID = ClsPub.isLong(this.txtHICMOBillNo.Tag);
            //BillNew.omodel.HICMOBillNo = ClsPub.isStrNull(this.txtHICMOBillNo.Text);
            //BillNew.omodel.HDeptID = ClsPub.isLong(this.txtHDeptID.Tag);
            //BillNew.omodel.HGroupID = ClsPub.isLong(this.txtHGroupID.Tag);
            //BillNew.omodel.HSourceID = ClsPub.isLong(this.txtHSourceID.Tag);
            //BillNew.omodel.HProcID = ClsPub.isLong(this.txtHProcID.Tag);
            //BillNew.omodel.HMaterID = ClsPub.isLong(this.txtHMaterID.Tag);
            //BillNew.omodel.HBatchNo = ClsPub.isStrNull(this.txtHBatchNo.Text);
            //BillNew.omodel.HBeginWorkTime = ClsPub.isDate(this.txtHBeginWorkTime.Text);
            //BillNew.omodel.HBarCodeMakeDate = ClsPub.isDate("1900-01-01");
            ////BillNew.omodel.HPlanQty = ClsPub.isDoule(this.txtHPlanQty.Text);
            ////明细类赋值
            ////BillNew.DetailColl=new List<Model.ClsSc_MESBeginWorkBillSub>();
            ////Model.ClsSc_MESBeginWorkBillSub oSub = new Model.ClsSc_MESBeginWorkBillSub();
            //////固定赋值========================================
            ////oSub.HEntryID = 1;
            ////oSub.HRemark = this.txtHRemark.Text.Trim();
            ////oSub.HSourceInterID = 0;
            ////oSub.HSourceEntryID = 0;
            ////oSub.HSourceBillType = "";
            ////oSub.HSourceBillNo = "";
            ////oSub.HRelationQty = 0;
            ////oSub.HRelationMoney = 0;
            ////oSub.HCloseMan = "";
            ////oSub.HEntryCloseDate = ClsPub.isDate("1900-10-10");
            ////oSub.HCloseType = false;
            //////=============================
            ////BillNew.DetailColl.Add(oSub);
            ////保存完毕后处理
            //if (BillStatus == DBUtility.ClsPub.Enum_BillStatus.BillStatus_AddNew)
            //{
            //    bResult = BillNew.AddBill(ref ClsPub.sExeReturnInfo );
            //}
            //else
            //{
            //    bResult = BillNew.ModifyBill(BillNew.omodel.HInterID, ref ClsPub.sExeReturnInfo);
            //}
            ////提示
            //if (bResult == true)
            //{
            //    BillChange = true;
            //    //MessageBox.Show("单据存盘完毕!单据号:" + this.txtHBillNo.Text.Trim(), "提示");
            //    if (BillStatus == DBUtility.ClsPub.Enum_BillStatus.BillStatus_AddNew)
            //    {
            //        BillStatus = DBUtility.ClsPub.Enum_BillStatus.BillStatus_View;
            //        BillOld.omodel.HInterID = BillNew.omodel.HInterID;
            //        this.Sub_ShowBill();
            //    }
            //    else if (BillStatus == DBUtility.ClsPub.Enum_BillStatus.BillStatus_Modify)
            //    {
            //        BillStatus = DBUtility.ClsPub.Enum_BillStatus.BillStatus_View;
            //        this.Sub_ShowBill();
            //    }
            //    this.Sub_OperStatus();
            //    return true;
            //}
            //else
            //{
            //    MessageBox.Show("保存失败!原因:" + ClsPub.sExeReturnInfo, "提示");
            //    return false;
            //}
        }
        #endregion 
 
 
        #region 窗体处理方法
        //初始化GRID
 
 
        private void cmdHDeptID_Click(object sender, EventArgs e)
        {
            //DAL.ClsK3_Department_View oDep = new DAL.ClsK3_Department_View();
            //if (oDep.RefreshView())
            //{
            //    this.txtHDeptID.Text = oDep.oModel.HName;
            //    this.txtHDeptID.Tag = oDep.oModel.HItemID.ToString();
            //    //this.txtHDeptNumber.Text = oDep.oModel.HNumber;
            //}
            //else
            //{
            //    this.txtHDeptID.Text = "";
            //    //this.txtHDeptNumber.Text = "";
            //}
 
        }
 
        private void txtHDeptID_TextChanged(object sender, EventArgs e)
        {
            if (txtHDeptID.Text.Trim() == "")
            {
                txtHDeptID.Tag = "0";
            }
        }
 
 
 
        #endregion
 
 
 
        #region  源单处理
        //
        private void FillSelectData(List<DBUtility.BillSelect> oList)
        {
            DataSet Ds;
            SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
            oSumGrid.Changelock = true;
            //initGrid();
            int i = -1;
            foreach (DBUtility.BillSelect oSelectRow in oList)
            {
                i = i + 1;
                if (oSelectRow.BillType == "3710")//生产任务单
                {
                    //grdMain.Rows.Add();
                    //grdMain.Rows[i].Cells[HTagCol].Value = "*";
                    //得到信息
                    Ds = oCn.RunProcReturn("select * from h_v_K3_ICMOBillList where hmainid=" + oSelectRow.BillMainID + " and hsubid=" + oSelectRow.BillSubID, "h_v_K3_ICMOBillList");
                    //写入信息
                    Sub_WriteInForm_SM(Ds.Tables[0], i);
                }
            }
            //
            oSumGrid.Changelock = false;
            //DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid);
        }
 
 
        //private void Sub_ChangeSourceBill()
        //{
        //    if (BillStatus == DBUtility.ClsPub.Enum_BillStatus.BillStatus_AddNew || BillStatus == DBUtility.ClsPub.Enum_BillStatus.BillStatus_Modify)
        //    {
        //        if (MessageBox.Show("单据尚未保存,确定要更换红蓝字?", "提示", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
        //        {
        //            if (redblue.Checked == true)
        //            {
        //                redblue.Checked = false;
        //            }
        //            else
        //            {
        //                redblue.Checked = true;
        //            }
        //            return;
        //        } 
        //        if (redblue.Checked == false)//当蓝字被选中
        //        {
        //            //得到对应源单信息
        //            BLL.ClsPub_BLL.GetBillSource(ModName, redblue.Checked, cmbSourceBillType);
        //            cmbSourceBillType.SelectedIndex = 0;
 
 
        //        }
        //        else if (redblue.Checked == true)
        //        {
        //            //得到对应源单信息
        //            BLL.ClsPub_BLL.GetBillSource(ModName, redblue.Checked, cmbSourceBillType);
        //            cmbSourceBillType.SelectedIndex = 0;
 
        //        }
        //        else
        //        {
 
        //        }
        //        Sub_AddBill();
        //    }
        //}
 
        //private void redblue_Click(object sender, EventArgs e)
        //{
        //    if (redblue.Checked == true)
        //    {
        //        redblue.Checked = false;
        //    }
        //    else
        //    {
        //        redblue.Checked = true;
        //    }
        //    Sub_ChangeSourceBill();
        //}
 
        #endregion
 
        private void yc_Click(object sender, EventArgs e)
        {
 
        }
 
        private void 反审核ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Sub_AbandonCheck();
        }
 
        private void 关闭ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Sub_CloseBill();
        }
 
        private void 审核ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Sub_CheckBill();
        }
 
        private void 反关闭ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Sub_Cancel();
        }
 
        private void 作废ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Sub_Cancelltion();
        }
 
        private void 撤销作废ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Sub_AbandonCancelltion();
        }
        private void 隐藏列设置ToolStripMenuItem_Click(object sender, EventArgs e)
        {
 
        }
 
        private void cmdHProcID_Click(object sender, EventArgs e)
        {
            //DAL.ClsK3_Process_View oProc = new DAL.ClsK3_Process_View();
            //if (oProc.RefreshView())
            //{
            //    this.txtHProcNo.Text = oProc.oModel.HNumber;
            //    this.txtHProcID.Text = oProc.oModel.HName;
            //    this.txtHProcID.Tag = oProc.oModel.HItemID.ToString();
            //    //this.txtHICMOBillNo.Focus();
            //}
            //else
            //{
            //    this.txtHProcNo.Text = "";
            //    this.txtHProcID.Text = "";
            //    this.txtHProcID.Tag = 0;
            //}
        }
 
        private void txtHProcID_TextChanged(object sender, EventArgs e)
        {
            if (txtHProcID.Text.Trim() == "")
            {
                txtHProcID.Tag = "0";
            }
        }
 
        private void cmdSM_Click(object sender, EventArgs e)
        {
            //if (DBUtility.ClsPub.isInt(txtHProcID.Tag) == 0)
            //{
            //    MessageBox.Show("请先选择汇报工序!");
            //    return;
            //}
            //DataSet Ds;
            //SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
            //long HInterID = 19623;
 
            ////得到信息
            //Ds = oCn.RunProcReturn("select * from h_v_Sc_ProcessExchangeBillList  where hmainid=" + HInterID + " and HProcID=" + txtHProcID.Tag, "h_v_Sc_ProcessExchangeBillList");
            ////写入信息
            //if (Ds == null || Ds.Tables[0].Rows.Count == 0)
            //{
            //    return;
            //}
            //for (int i = 0; i < Ds.Tables[0].Rows.Count; i++)
            //{
            //    Sub_WriteInForm_SM(Ds.Tables[0], i);
            //}
        }
 
 
 
        //根据TABLE写入界面
        private void Sub_WriteInForm_SM(DataTable oTable, int i)
        {
            //
            //this.txtHICMOBillNo.Tag = oTable.Rows[0]["HMainID"].ToString();
            //this.txtHICMOBillNo.Text = oTable.Rows[0]["单据号"].ToString();
            //this.txtHMaterID.Tag = oTable.Rows[0]["HMaterID"].ToString();
            //this.txtHMaterID.Text = oTable.Rows[0]["物料代码"].ToString();
            //this.txtHName.Text = oTable.Rows[0]["物料名称"].ToString();
            //this.txtHModel.Text = oTable.Rows[0]["规格型号"].ToString();
            //this.txtHBatchNo.Text = oTable.Rows[0]["批号"].ToString();
            //this.txtHUnitID.Tag = oTable.Rows[0]["HUnitID"].ToString();
            //this.txtHUnitID.Text = oTable.Rows[0]["计量单位"].ToString();
            //this.txtHDeptID.Tag = oTable.Rows[0]["HDeptID"].ToString();
            //this.txtHDeptID.Text = oTable.Rows[0]["部门"].ToString();
            ////this.txtHQty.Text = DBUtility.ClsPub.isDoule(oTable.Rows[0]["计划数量"], 0);
            ////this.txtHPlanQty.Text = DBUtility.ClsPub.isDoule(oTable.Rows[0]["计划数量"], 0);
            ////this.txtHWorkEmpID.Tag = oTable.Rows[0]["HWorkerID"].ToString();
            ////this.txtHWorkEmpID.Text = oTable.Rows[0]["操作工"].ToString();
            //this.dtpHPlanBeginDate.Value = ClsPub.isDate(oTable.Rows[0]["计划开工日期"]);
            //this.dtpHPlanEndDate.Value = ClsPub.isDate(oTable.Rows[0]["计划完工日期"]);
            ////
            //long sProcID = 0;
            //string sProcNo = "";
            //string sProcName = "";
            //if (BillOld.GetICMOProc(DBUtility.ClsPub.isLong(oTable.Rows[0]["HMainID"]), ref sProcID, ref sProcNo, ref sProcName, ref ClsPub.sExeReturnInfo))
            //{
            //    txtHProcID.Tag = sProcID.ToString();
            //    txtHProcID.Text = sProcName;
            //    txtHProcNo.Text = sProcNo;
            //}
        }
 
        //根据TABLE写入界面
        private void Sub_WriteInForm_SM2(DataTable oTable, int i)
        {
            //DAL.ClsK3_Material_View oMater = new DAL.ClsK3_Material_View();
 
            //this.txtHProcExchInterID.Text = oTable.Rows[0]["hmainid"].ToString();
            //this.txtHProcExchEntryID.Text = oTable.Rows[0]["hsubid"].ToString();
            ////
            //this.txtHProcID.Tag = oTable.Rows[0]["HProcID"].ToString();
            //this.txtHProcID.Text = oTable.Rows[0]["工序"].ToString();
            //this.txtHDeptID.Tag = oTable.Rows[0]["HDeptID"].ToString();
            //this.txtHDeptID.Text = oTable.Rows[0]["加工车间"].ToString();
            //this.txtHGroupID.Tag = oTable.Rows[0]["HGroupID"].ToString();
            //this.txtHGroupID.Text = oTable.Rows[0]["班组"].ToString();
            ////this.txtHWorkEmpID.Tag = oTable.Rows[0]["HWorkerID"].ToString();
            ////this.txtHWorkEmpID.Text = oTable.Rows[0]["操作工"].ToString();
            //this.txtHSourceID.Tag = oTable.Rows[0]["HSourceID"].ToString();
            //this.txtHSourceID.Text = oTable.Rows[0]["生产资源"].ToString();
        }
 
        private void cmdHGroupID_Click(object sender, EventArgs e)
        {
            //DAL.ClsK3_Group_View oGroup = new DAL.ClsK3_Group_View();
            //if (oGroup.RefreshView())
            //{
            //    this.txtHGroupID.Text = oGroup.oModel.HName;
            //    this.txtHGroupID.Tag = oGroup.oModel.HItemID.ToString();
            //}
            //else
            //{
            //    this.txtHGroupID.Text = "";
            //    this.txtHGroupID.Tag = 0;
            //}
        }
 
        private void txtHGroupID_TextChanged(object sender, EventArgs e)
        {
            if (txtHGroupID.Text.Trim() == "")
            {
                txtHGroupID.Tag = "0";
            }
        }
 
        private void cmdHWorkEmpID_Click(object sender, EventArgs e)
        {
            //DAL.ClsK3_Employee_View oEmp = new DAL.ClsK3_Employee_View();
            //if (oEmp.RefreshView())
            //{
            //    this.txtHWorkEmpID.Text = oEmp.oModel.HName;
            //    this.txtHWorkEmpID.Tag = oEmp.oModel.HItemID.ToString();
            //}
            //else
            //{
            //    this.txtHWorkEmpID.Text = "";
            //    this.txtHWorkEmpID.Tag = 0;
            //}
        }
 
        private void txtHWorkEmpID_TextChanged(object sender, EventArgs e)
        {
            if (txtHWorkEmpID.Text.Trim() == "")
            {
                txtHWorkEmpID.Tag = "0";
            }
        }
 
        private void cmdHSourceID_Click(object sender, EventArgs e)
        {
            DAL.ClsGy_Source_View oSource = new DAL.ClsGy_Source_View();
            if (oSource.RefreshView())
            {
                this.txtHSourceID.Text = oSource.oModel.HName;
                this.txtHSourceID.Tag = oSource.oModel.HItemID.ToString();
            }
            else
            {
                this.txtHSourceID.Text = "";
                this.txtHSourceID.Tag = 0;
            }
        }
 
        private void txtHSourceID_TextChanged(object sender, EventArgs e)
        {
            if (txtHSourceID.Text.Trim() == "")
            {
                txtHSourceID.Tag = "0";
            }
        }
 
        private void txtHProcExchBillNo_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Return)
            {
                if (txtHProcExchBillNo.Text.Trim() == "")
                {
                    MessageBox.Show("工序流转卡卡号,不能为空!");
                    return;
                }
                //if (DBUtility.ClsPub.isLong(txtHProcID.Tag) == 0)
                //{
                //    MessageBox.Show("请先选择汇报工序!");
                //    return;
                //}
 
                DataSet Ds;
                SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
                string sBillNo = txtHProcExchBillNo.Text.Trim();
 
                //得到信息
                Ds = oCn.RunProcReturn("select top 1 * from h_v_Sc_ProcessExchangeBillList  where 单据号= '" + sBillNo + "'", "h_v_Sc_ProcessExchangeBillList");
                //写入信息
                if (Ds == null || Ds.Tables[0].Rows.Count == 0)
                {
                    txtHProcExchBillNo.Text = "";
                    MessageBox.Show("未查询到流转卡信息!");
                    return;
                }
                for (int i = 0; i < Ds.Tables[0].Rows.Count; i++)
                {
                    Sub_WriteInForm_SM(Ds.Tables[0], i);
                }
                Sub_ShowBill();
                txtHProcNo.Focus();
            }
        }
 
        //private delegate void ShowInfoDelegate(BLL.BardCodeHooK.BarCodes barCode);
        //private void ShowInfo(BLL.BardCodeHooK.BarCodes barCode)
        //{
        //    if (this.InvokeRequired)
        //    {
        //        this.BeginInvoke(new ShowInfoDelegate(ShowInfo), new object[] { barCode });
        //    }
        //    else
        //    {
        //        if (BillStatus == DBUtility.ClsPub.Enum_BillStatus.BillStatus_View)
        //        {
        //            if (barCode.KeyName == "Enter")
        //            {
        //                this.Sub_AddBill();
        //            }
        //        }
        //        txtHProcExchBillNo.Text = barCode.IsValid ? barCode.BarCode : txtHProcExchBillNo.Text;//是否为扫描枪输入,如果为true则是 否则为键盘输入
        //    }
        //}
 
        //void BarCode_BarCodeEvent(BLL.BardCodeHooK.BarCodes barCode)
        //{
        //    ShowInfo(barCode);
        //}
 
        private void txtHQty_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Return)
            {
                Sub_SaveBill();
            }
        }
 
        private void txtHProcNo_TextChanged(object sender, EventArgs e)
        {
            if (txtHProcNo.Text.Trim() == "")
            {
                txtHProcID.Tag = "0";
                txtHProcID.Text = "";
            }
        }
 
        private void txtHWorkEmpNo_TextChanged(object sender, EventArgs e)
        {
            if (txtHWorkEmpNo.Text.Trim() == "")
            {
                txtHWorkEmpID.Tag = "0";
                txtHWorkEmpID.Text = "";
            }
        }
 
        private void txtHProcNo_KeyDown(object sender, KeyEventArgs e)
        {
            //DataSet Ds;
            //SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
            //string sProcNo = txtHProcNo.Text.Trim();
            //string sBillNo = txtHProcExchBillNo.Text.Trim();
            //if (e.KeyCode == Keys.Return)
            //{
            //    //得到信息
            //    Ds = oCn.RunProcReturn("select * from h_v_Sc_ProcessExchangeBillList  where 单据号= '" + sBillNo + "' and 工序号='" + sProcNo + "'", "h_v_Sc_ProcessExchangeBillList");
            //    //写入信息
            //    if (Ds == null || Ds.Tables[0].Rows.Count == 0)
            //    {
            //        txtHProcNo.Text = "";
            //        MessageBox.Show("工序号错误,请重新输入!");
            //        return;
            //    }
            //    for (int i = 0; i < Ds.Tables[0].Rows.Count; i++)
            //    {
            //        Sub_WriteInForm_SM2(Ds.Tables[0], i);
            //    }
            //    txtHWorkEmpNo.Focus();
            //}
        }
 
        private void txtHWorkEmpNo_KeyDown(object sender, KeyEventArgs e)
        {
            //DAL.ClsK3_Employee_View oEmp = new DAL.ClsK3_Employee_View();
            //string sEmp = txtHWorkEmpNo.Text.Trim();
            //if (e.KeyCode == Keys.Return)
            //{
            //    if (oEmp.GetInfoByEmpNo(sEmp))
            //    {
            //        txtHWorkEmpID.Tag = oEmp.omodel.HItemID;
            //        txtHWorkEmpID.Text = oEmp.omodel.HName;
            //    }
            //    else
            //    {
            //        txtHWorkEmpNo.Text = "";
            //        MessageBox.Show("员工工号错误,请重新输入!");
            //        return;
            //    }
            //}
        }
 
        private void tabControl1_KeyDown(object sender, KeyEventArgs e)
        {
            if (BillStatus == DBUtility.ClsPub.Enum_BillStatus.BillStatus_View)
            {
                if (e.KeyCode == Keys.Return)
                {
                    this.Sub_AddBill();
                    txtHProcExchBillNo.Focus();
                }
            }
        }
 
        private void timer2_Tick(object sender, EventArgs e)
        {
            //if (BillStatus == DBUtility.ClsPub.Enum_BillStatus.BillStatus_View)
            //{
            //    tabControl1.Focus();
            //}
            //else
            //{
            //    if (txtHProcExchBillNo.Text.Trim() == "")
            //    {
            //        txtHProcExchBillNo.Focus();
            //    }
            //}
        }
 
        private void cmdHICMOBillNo_Click(object sender, EventArgs e)
        {
            //DAL.Cls_S_K3_ICMOBill oICMOBill = new DAL.Cls_S_K3_ICMOBill();
            //string sWhere = " ";
            //if (oICMOBill.Refresh(sWhere))  //选择原单
            //{
            //    FillSelectData(oICMOBill.oBillSelectColl);
            //}
        }
 
        private void txtHICMOBillNo_KeyDown(object sender, KeyEventArgs e)
        {
            //DataSet Ds;
            //SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
            //long sICMOInterID = DBUtility.ClsPub.isLong(txtHICMOBillNo.Text.Trim());
            //if (e.KeyCode == Keys.Return)
            //{
            //    //得到信息
            //    Ds = oCn.RunProcReturn("select * from h_v_K3_ICMOBillList where hmainid=" + sICMOInterID.ToString() + " and hsubid=0", "h_v_K3_ICMOBillList");
            //    //写入信息
            //    if (Ds == null || Ds.Tables[0].Rows.Count == 0)
            //    {
            //        txtHICMOBillNo.Text = "";
            //        MessageBox.Show("任务单内码错误,请重新扫描!");
            //        return;
            //    }
            //    for (int i = 0; i < Ds.Tables[0].Rows.Count; i++)
            //    {
            //        Sub_WriteInForm_SM(Ds.Tables[0], i);
            //    }
            //}
        }
        private int ImageCount;
        private List<string> ImagePaths;
        private int nowCount = 0;
 
        private void ShowPic()
        {
            //FolderBrowserDialog oDialog = new FolderBrowserDialog();
            //oDialog.SelectedPath = Pub_Class.ClsPub.AppPath + @"\" + "PT" + @"\";
            ImagePaths = new List<string>();
            nowCount = 0;
            //if (oDialog.ShowDialog() == DialogResult.OK)
            //{
                foreach (string Path in Directory.GetFiles(Pub_Class.ClsPub.AppPath + @"\" + "PT" + @"\EV30G-7"))
                {
                    ImagePaths.Add(Path);
                }
                if (ImagePaths.Count != 0)
                {
                    ImageCount = ImagePaths.Count;
                }
            //}
            if (nowCount < ImageCount)
            {
                this.pictureBox1.Image = Bitmap.FromFile(ImagePaths[nowCount]);
            }
        }
 
        private void Select_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog oDialog = new FolderBrowserDialog();
            oDialog.SelectedPath = Pub_Class.ClsPub.AppPath + @"\" + "PT" + @"\";
            ImagePaths = new List<string>();
            nowCount = 0;
            if (oDialog.ShowDialog() == DialogResult.OK)
            {
                foreach (string Path in Directory.GetFiles(oDialog.SelectedPath))
                {
                    ImagePaths.Add(Path);
                }
                if (ImagePaths.Count != 0)
                {
                    ImageCount = ImagePaths.Count;
                }
            }
            if (nowCount < ImageCount)
            {
                this.pictureBox1.Image = Bitmap.FromFile(ImagePaths[nowCount]);
            }
        }
 
        private void cmbBack_Click(object sender, EventArgs e)
        {
            nowCount--;
            if (nowCount < 0)
            {
                nowCount = 0;
            }
            if (nowCount < ImageCount && nowCount>=0)
            {
                this.pictureBox1.Image = Bitmap.FromFile(ImagePaths[nowCount]);
            }
        }
 
        private void cmdNext_Click(object sender, EventArgs e)
        {
            nowCount++;
            if (nowCount > ImageCount)
            {
                nowCount = ImageCount - 1;
            }
            if (nowCount < ImageCount && nowCount >= 0)
            {
                this.pictureBox1.Image = Bitmap.FromFile(ImagePaths[nowCount]);
            }
        }
 
 
 
    }
}