11
pzy
2024-09-03 25472b14d98f52e711827f866d43d245e02d6c3a
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
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;
 
namespace WorkM
{
    public partial class Sc_MaterDownBill : Form
    {
        public Sc_MaterDownBill()
        {
            InitializeComponent();
        }
        //定义网格列
        public const Int16 HTagCol = 0;   //标识列
        public const Int16 HSnoCol = 1;     //序号列
        public const Int16 HDateCol = 2;
        public const Int16 HEmpIDCol = 3;
        public const Int16 HEmpNumberCol = 4;
        public const Int16 HEmpNameCol = 5;
        public const Int16 HSourceIDCol = 6;
        public const Int16 HSourceNumberCol = 7;
        public const Int16 HSourceNameCol = 8;
        public const Int16 HMaterIDCol = 9;
        public const Int16 HMaterNumberCol = 10;
        public const Int16 HMaterNameCol = 11;
        public const Int16 HMaterModelCol = 12;
        public const Int16 HBatchNoCol = 13;
        public const Int16 HQtyCol = 14;
        public const Int16 HWeightCol = 15;
        public const Int16 HSumWeightCol = 16;
        public const Int16 HPackNumCol = 17;
        public const Int16 HRemarkCol = 18;
        public const Int16 HCloseManCol = 19;
        public const Int16 HCloseTypeCol = 20;
        public const Int16 HSourceInterIDCol = 21;
        public const Int16 HSourceEntryIDCol = 22;
        public const Int16 HSourceBillNoCol = 23;
        public const Int16 HSourceBillTypeCol = 24;
        public const Int16 HRelationQtyCol = 25;
        public const Int16 HRelationMoneyCol = 26;
        //
        public  string ModName = "8503";
        public  string ModCaption = "卸料记录单";
        public bool BillChange;   //
        public string HInnerBillNo = "";
 
        public DBUtility.ClsPub.Enum_BillStatus BillStatus;   //单据状态(新增,修改,视图)
        public Int64 KeyID;          //作废
        public bool  grdStatus;              //网格状态(编辑,视图)
        public DAL.ClsSc_MaterDownBill BillNew = new  DAL.ClsSc_MaterDownBill();   //单据类
        public DAL.ClsSc_MaterDownBill BillOld = new DAL.ClsSc_MaterDownBill();   //单据类
        ClsGridViewSum oSumGrid = new ClsGridViewSum();
        //-------------------------------------------------------------------------
        #region 固定代码
 
         
        //清空界面
        public void Sub_ClearBill()
        {
            DBUtility.Xt_BaseBillFun.Sub_ClearBill(gbUp);
            //
            txtHMaker.Text = ClsPub.CurUserName;
            txtHMakeDate.Text = "";
            txtHChecker.Text = "";
            txtHCheckDate.Text = "";
            txtHCloseMan.Text = "";
            txtHCloseDate.Text = "";
            txtHDeleteMan.Text = "";
            txtHDeleteDate.Text = "";
            txtHUpDater.Text = "";
            txtHUpDateDate.Text = "";
            txtHBacker.Text = "";
            txtHBackDate.Text = "";
            initGrid();
        }
        //编辑单据
        private void Sub_EditBill()
        {
            string s = "";
            if (BillOld.ShowBill(BillOld.omodel.HInterID, ref s) == false)
            {
                MessageBox.Show("此单据有错误!", "提示");
                return;
            }
            if (BillOld.omodel.HChecker != "")
            {
                MessageBox.Show("此单据已经被审核,不允许修改", "提示");
                return;
            }
            this.BillStatus = DBUtility.ClsPub.Enum_BillStatus.BillStatus_Modify;
            this.Sub_OperStatus();
 
            txtHUpDater.Text = ClsPub.CurUserName;
            txtHBillNo.Enabled = false;
        }
        //删除单据
        private void Sub_DeleteBill()
        {
            string s = "";
            if (BillOld.ShowBill(BillOld.omodel.HInterID, ref s) == false)
            {
                MessageBox.Show("此单据有错误!", "提示");
                return;
            }
            if (BillOld.omodel.HChecker != "")
            {
                MessageBox.Show("此单据已经被审核,不允许审核", "提示");
                return;
            }
            if (MessageBox.Show("确定要删除当前单据?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {
                if (BillOld.DeleteBill(BillOld.omodel.HInterID, ref ClsPub.sExeReturnInfo) != true)
                {
                    BillChange = true;
                    MessageBox.Show("删除失败,原因:" + ClsPub.sExeReturnInfo, "提示");
                    return;
                }
                MessageBox.Show("删除成功", "提示");
                BillOld = new DAL.ClsSc_MaterDownBill();
                this.Sub_Next();  //显示下一张单据
                if (BillOld.omodel.HInterID == 0)//若找不到下一张,则显示上一张
                {
                    this.Sub_Prev();
                }
                if (BillOld.omodel.HInterID == 0)//若找不到上一张,清空
                {
                    this.Sub_ClearBill();
                }
                BillStatus =DBUtility.ClsPub.Enum_BillStatus.BillStatus_View;
                this.Sub_OperStatus();
            }
 
        }
        private void bclk_Click(object sender, EventArgs e)
        {
            //保存列宽
            DBUtility.Xt_BaseBillFun.SaveGrid(grdMain, this.Name);
        }
        //增行按钮  
        private void AddRow_Click(object sender, EventArgs e)
        {
            DBUtility.Xt_BaseBillFun.AddRow(oSumGrid);
        }
        //删行按纽  
        private void DelRow_Click(object sender, EventArgs e)
        {
            DBUtility.Xt_BaseBillFun.DelRow(oSumGrid);
        }
        private void mrlk_Click(object sender, EventArgs e)
        {
            DBUtility.Xt_BaseBillFun.DefaultGridView(grdMain, this.Name);
        }
        //离开单元格
 
        private void grdMain_LeaveCell(object sender, EventArgs e)
        {
            oSumGrid.LeaveCell();
        }
 
        //网格单元格变化事件
        private void grdMain_RowColChange(object sender, EventArgs e)
        {
            //
            if (!grdStatus)
            {
                return;
            }
            DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid);
            //
            //if (oSumGrid.Changelock)
            //    return;
            //if(oSumGrid.EditStatus)
            //{
                if (!CheckGridRow(oSumGrid.OldCell.Row))
                    return;
            //}
            
        }
        //放弃 编辑
        private void Sub_AbandonBill()
        {
            if (BillStatus ==DBUtility.ClsPub.Enum_BillStatus.BillStatus_AddNew || BillStatus ==DBUtility.ClsPub.Enum_BillStatus.BillStatus_Modify)
            {
                if (MessageBox.Show("单据尚未保存,是否放弃?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                {
                    //显示第一张单据
                    this.Sub_First();
                }
            }
        }
        private void Sc_MaterDownBill_Paint(object sender, PaintEventArgs e)//画线
        {
            Graphics g = this.panel2.CreateGraphics();
            Pen p = new Pen(Color.Gray);
            p.Width = 1;
            g.DrawLine(p, new Point(txtHMaker.Left, txtHMaker.Top + txtHMaker.Height), new Point(txtHMaker.Left + txtHMaker.Width, txtHMaker.Top + txtHMaker.Height));
            g.DrawLine(p, new Point(txtHMakeDate.Left, txtHMakeDate.Top + txtHMakeDate.Height), new Point(txtHMakeDate.Left + txtHMakeDate.Width, txtHMakeDate.Top + txtHMakeDate.Height));
            //
            g.DrawLine(p, new Point(txtHChecker.Left, txtHChecker.Top + txtHChecker.Height), new Point(txtHChecker.Left + txtHChecker.Width, txtHChecker.Top + txtHChecker.Height));
            g.DrawLine(p, new Point(txtHCheckDate.Left, txtHCheckDate.Top + txtHCheckDate.Height), new Point(txtHCheckDate.Left + txtHCheckDate.Width, txtHCheckDate.Top + txtHCheckDate.Height));
            //
            g.DrawLine(p, new Point(txtHCloseMan.Left, txtHCloseMan.Top + txtHCloseMan.Height), new Point(txtHCloseMan.Left + txtHCloseMan.Width, txtHCloseMan.Top + txtHCloseMan.Height));
            g.DrawLine(p, new Point(txtHCloseDate.Left, txtHCloseDate.Top + txtHCloseDate.Height), new Point(txtHCloseDate.Left + txtHCloseDate.Width, txtHCloseDate.Top + txtHCloseDate.Height));
            //
            g.DrawLine(p, new Point(this.txtHDeleteMan.Left, txtHDeleteMan.Top + txtHDeleteMan.Height), new Point(txtHDeleteMan.Left + txtHDeleteMan.Width, txtHDeleteMan.Top + txtHDeleteMan.Height));
            g.DrawLine(p, new Point(txtHDeleteDate.Left, txtHDeleteDate.Top + txtHDeleteDate.Height), new Point(txtHDeleteDate.Left + txtHDeleteDate.Width, txtHDeleteDate.Top + txtHDeleteDate.Height));
            //
            g.DrawLine(p, new Point(this.txtHUpDater.Left, txtHUpDater.Top + txtHUpDater.Height), new Point(txtHUpDater.Left + txtHUpDater.Width, txtHUpDater.Top + txtHUpDater.Height));
            g.DrawLine(p, new Point(txtHUpDateDate.Left, txtHUpDateDate.Top + txtHUpDateDate.Height), new Point(txtHUpDateDate.Left + txtHUpDateDate.Width, txtHUpDateDate.Top + txtHUpDateDate.Height));
            //
            g.DrawLine(p, new Point(this.txtHBacker.Left, txtHBacker.Top + txtHBacker.Height), new Point(txtHBacker.Left + txtHBacker.Width, txtHBacker.Top + txtHBacker.Height));
            g.DrawLine(p, new Point(txtHBackDate.Left, txtHBackDate.Top + txtHBackDate.Height), new Point(txtHBackDate.Left + txtHBackDate.Width, txtHBackDate.Top + txtHBackDate.Height));
            //控件位置设置
 
        }
        //控件位置
        private void Sub_ControlLocation()
        {
             
        }
        //窗体加载
        private void Sc_MaterDownBill_Load(object sender, EventArgs e)
        {
            //打印初始化       
            dtpHDate.Value = DateTime.Today;
            oSumGrid.NoCol = HSnoCol;
            oSumGrid.ogrdMain = grdMain;
            oSumGrid.oGridsum = grdSum;
            this.Text = ModCaption;
            this.lblCaption.Text = ModCaption;
        }
        //首张
        private void Sub_First()
        {
            BillStatus =DBUtility.ClsPub.Enum_BillStatus.BillStatus_View;
            BillOld = new DAL.ClsSc_MaterDownBill();
            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_MaterDownBill();
            if (BillOld.GetLastBill(ref  ClsPub.sExeReturnInfo))
            {
                this.Sub_ShowBill();
            }
        }
        //审核单据
        private void Sub_CheckBill()
        {
            if (BillOld.CheckBill(BillOld.omodel.HInterID, ref ClsPub.sExeReturnInfo) == true)
            {
                BillChange = true;
                txtHChecker.Text = ClsPub.CurUserName;
                txtHCheckDate.Text = BillOld.omodel.HCheckDate;
                this.Sub_OperStatus();//刷新TOOL按钮
            }
            else
            {
                MessageBox.Show("审核失败!原因:" + ClsPub.sExeReturnInfo, "提示");
            }
        }
        //反审单据
        private void Sub_AbandonCheck()
        {
            if (BillOld.AbandonCheck(BillOld.omodel.HInterID, ref ClsPub.sExeReturnInfo) == true)
            {
                BillChange = true;
                txtHChecker.Text = "";
                txtHCheckDate.Text = "";
                this.Sub_OperStatus();//刷新TOOL按钮
            }
            else
            {
                MessageBox.Show("反审核失败!原因:" + ClsPub.sExeReturnInfo, "提示");
            }
        }
        //关闭单据
        private void Sub_CloseBill()
        {
            if (BillOld.CloseBill(BillOld.omodel.HInterID, ref ClsPub.sExeReturnInfo) == true)
            {
                BillChange = true;
                txtHCloseMan.Text = ClsPub.CurUserName;
                txtHCloseDate.Text = BillOld.omodel.HCloseDate;
                this.Sub_OperStatus();//刷新TOOL按钮
            }
            else
            {
                MessageBox.Show("关闭失败!原因:" + ClsPub.sExeReturnInfo, "提示");
            }
        }
        //反关闭单据
        private void Sub_Cancel()
        {
            if (BillOld.CancelClose(BillOld.omodel.HInterID, ref ClsPub.sExeReturnInfo) == true)
            {
                BillChange = true;
                txtHCloseMan.Text = "";
                txtHCloseDate.Text = "";
                this.Sub_OperStatus();//刷新TOOL按钮
            }
            else
            {
                MessageBox.Show("恢复失败!原因:" + ClsPub.sExeReturnInfo, "提示");
            }
        }
        //作废单据
        private void Sub_Cancelltion()
        {
            if (BillOld.Cancelltion(BillOld.omodel.HInterID, ref ClsPub.sExeReturnInfo) == true)
            {
                BillChange = true;
                this.txtHDeleteMan.Text = ClsPub.CurUserName;
                this.txtHDeleteDate.Text = BillOld.omodel.HDeleteDate;
                this.Sub_OperStatus();//刷新TOOL按钮
            }
            else
            {
                MessageBox.Show("作废失败!原因:" + ClsPub.sExeReturnInfo, "提示");
            }
        }
        //反作废
        private void Sub_AbandonCancelltion()
        {
            if (BillOld.AbandonCancelltion(BillOld.omodel.HInterID, ref ClsPub.sExeReturnInfo) == true)
            {
                BillChange = true;
                this.txtHDeleteMan.Text = "";
                this.txtHDeleteDate.Text = "";
                this.Sub_OperStatus();//刷新TOOL按钮
            }
            else
            {
                MessageBox.Show("作废失败!原因:" + ClsPub.sExeReturnInfo, "提示");
            }
        }
        //新增按纽
        private void xz_Click(object sender, EventArgs e)
        {
            this.Sub_AddBill();
        }
        //修改按纽
        private void xg_Click(object sender, EventArgs e)
        {
            this.Sub_EditBill();
        }
        //删除按钮
        private void sc_Click(object sender, EventArgs e)
        {
            this.Sub_DeleteBill();
        }
        //保存按钮
        private void bc_Click(object sender, EventArgs e)
        {
            this.Sub_SaveBill();
        }
        //放弃按钮
        private void fq_Click(object sender, EventArgs e)
        {
            this.Sub_AbandonBill();
        }
        //审核按钮
        private void sh_Click(object sender, EventArgs e)
        {
            this.Sub_CheckBill();
        }
        //放弃审核按钮
        private void qsh_Click(object sender, EventArgs e)
        {
            this.Sub_AbandonCheck();
        }
        //关闭按钮
        private void gb_Click(object sender, EventArgs e)
        {
            this.Sub_CloseBill();
        }
        //恢复按钮
        private void hf_Click(object sender, EventArgs e)
        {
            this.Sub_Cancel();
        }
        //作废按钮
        private void zf_Click(object sender, EventArgs e)
        {
            this.Sub_Cancelltion();
        }
        //反作废按钮
        private void zc_Click(object sender, EventArgs e)
        {
            this.Sub_AbandonCancelltion();
        }
        //首张单据按钮
        private void sz_Click(object sender, EventArgs e)
        {
            this.Sub_First();
        }
        //上一张按钮
        private void syz_Click(object sender, EventArgs e)
        {
            this.Sub_Prev();
        }
        //下一张按钮
        private void xyz_Click(object sender, EventArgs e)
        {
            this.Sub_Next();
        }
        //末张按钮
        private void mz_Click(object sender, EventArgs e)
        {
            this.Sub_Last();
        }
        //退出按钮
        private void tc_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        //窗体尺寸变化时
        private void Sc_MaterDownBill_Resize(object sender, EventArgs e)
        {
            //Sub_ControlLocation();
        }
        
        
        //根据编辑状态 设置 控件是否允许录入    
        private void Sub_LrtextStatus(bool TextEnabled)
        {
            if (TextEnabled == true)
            {
                //控件全部有效
                gbUp.Enabled = true;
                grdMain.BackColor = ClsPub.EditColor;
 
            }
            else
            {   //控件全部无效
                gbUp.Enabled = false;
                grdMain.BackColor = ClsPub.ViewColor;
            }
        }
        //复制单据
        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();
            this.txtHMaker.Text = ClsPub.CurUserName;
            this.txtHMakeDate.Text = ClsPub.GetServerDate(-1);
            this.txtHChecker.Text = "";
            this.txtHCloseDate.Text = "";
            this.txtHCloseMan.Text = "";
            this.txtHCloseDate.Text = "";
            this.txtHDeleteMan.Text = "";
            this.txtHDeleteDate.Text = "";
            this.txtHUpDater.Text = "";
            this.txtHUpDateDate.Text = "";
            this.txtHBacker.Text = "";
            this.txtHBackDate.Text = "";
        }
        //复制按钮
        private void fz_Click(object sender, EventArgs e)
        {
            Sub_CopyBill();
        }
        //timer
        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            Sub_ControlLocation();
            if (BillStatus == DBUtility.ClsPub.Enum_BillStatus.BillStatus_View)
            {
                this.Sub_ShowBill();
            }
            else
            {
                this.Sub_AddBill();
            }
            DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid);
 
        }
        //窗体卸载
        private void Sc_MaterDownBill_FormClosing(object sender, FormClosingEventArgs e)
        {
            BillStatus = DBUtility.ClsPub.Enum_BillStatus.BillStatus_AddNew;
            DBUtility.Xt_BaseBillFun.SaveGrid(grdMain, this.Name);
        }
        //新增单据
        private void Sub_AddBill()
        {
            this.BillNew = new DAL.ClsSc_MaterDownBill();
            this.BillOld = new DAL.ClsSc_MaterDownBill();
            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.txtHBillNo.Focus();
            this.txtHInnerBillNo.Text = HInnerBillNo;
        }
        //TOOLBAR状态  按钮是否灰度
        public void Sub_OperStatus()
        {
            switch (BillStatus)
            {
                case DBUtility.ClsPub.Enum_BillStatus.BillStatus_View:
                    //浏览状态
                    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;
                    fz.Enabled = true;
                    //未审核
                    if (txtHChecker.Text.Trim() == "")
                    {
                        sh.Enabled = true;
                        qsh.Enabled = false;
                        //gb.Enabled = false;
                        //hf.Enabled = false;
                        xg.Enabled = true;
                        sc.Enabled = true;
                        //未审核
                        pic1.Visible = false;
                        pic1.Image = null;
                        //
                    }
                    else if (txtHCloseMan.Text.Trim() == "" && txtHChecker.Text.Trim() != "")//审核未关闭
                    {
                        sh.Enabled = false;
                        qsh.Enabled = true;
                        //gb.Enabled = true;
                        //hf.Enabled = false;
                        xg.Enabled = false;
                        sc.Enabled = false;
                        //
                        pic1.Visible = true;
                        pic1.Image = System.Drawing.Image.FromFile(ClsPub.AppPath + @"/Pic/Checked.jpg");
                        //
                    }
                    else//已关闭
                    {
                        sh.Enabled = false;
                        qsh.Enabled = false;
                        //gb.Enabled = false;
                        //hf.Enabled = true;
                        xg.Enabled = false;
                        sc.Enabled = false;
                        //
                        pic1.Visible = true;
                        pic1.Image = System.Drawing.Image.FromFile(ClsPub.AppPath + @"/Pic/Closed.jpg");
                        //
                    }
                    if (txtHDeleteMan.Text.Trim() == "")
                    {
                        //zf.Enabled = true;
                        //zc.Enabled = false;
                    }
                    else //已作废
                    {
                        //zf.Enabled = false;
                        //zc.Enabled = true;
                        xg.Enabled = false;
                        sc.Enabled = false;
                        AddRow.Enabled = false;
                        DelRow.Enabled = false;
                        bc.Enabled = false;
                        fq.Enabled = false;
                        sh.Enabled = false;
                        qsh.Enabled = false;
                        //gb.Enabled = false;
                        //hf.Enabled = false;
                        //
                        pic1.Visible = true;
                        pic1.Image = System.Drawing.Image.FromFile(ClsPub.AppPath + @"/Pic/Deleted.jpg");
                        //
                    }
                    Sub_LrtextStatus(false);
                    grdStatus = false;
                    break;
                case DBUtility.ClsPub.Enum_BillStatus.BillStatus_AddNew:
                    //新增状态
                    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;
                    fz.Enabled = false;
                    //未审核
                    pic1.Visible = false;
                    pic1.Image = null;
                    //
                    break;
                case DBUtility.ClsPub.Enum_BillStatus.BillStatus_Modify:
                    //修改状态
                    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;
                    fz.Enabled = false;
                    //未审核
                    pic1.Visible = false;
                    pic1.Image = null;
                    //
                    break;
            }
 
        }
        #endregion
 
        #region  读写类
        //显示单据
        public void Sub_ShowBill()
        {
            //定义所有用到的基础资料
            DAL.ClsGy_Department_View oDep = new DAL.ClsGy_Department_View();
            DAL.ClsGy_Material_View oMater = new DAL.ClsGy_Material_View();
            DAL.ClsGy_Employee_View oEmp = new DAL.ClsGy_Employee_View();
            DAL.ClsGy_Source_View oSour = new DAL.ClsGy_Source_View();
            //判断是否存在单据
            if(BillOld.ShowBill(BillOld.omodel.HInterID,ref  ClsPub.sExeReturnInfo)==false )
            {
                MessageBox.Show(ClsPub.sExeReturnInfo, "提示");
                return;
            }
            //清空
            Sub_ClearBill();
            //grid禁止刷新 
            //加载表头
            if (oDep.GetInfoByID(BillOld.omodel.HDeptID))
            {
                this.txtHDeptID.Tag = oDep.omodel.HItemID.ToString();
                this.txtHDeptID.Text = oDep.omodel.HName;
            }
            else
            {
                this.txtHDeptID.Text = "";
                this.txtHDeptID.Tag = "0";
            }
            //
            if (oMater.GetInfoByID(BillOld.omodel.HMaterID))
            {
                this.txtHMaterID.Text = oMater.omodel.HNumber;
                this.txtHMaterID.Tag = oMater.omodel.HItemID.ToString();
                this.txtHMaterName.Text = oMater.omodel.HName;
                this.txtHMaterModel.Text = oMater.omodel.HModel;
            }
            else
            {
                this.txtHMaterID.Text = "";
                this.txtHMaterID.Tag = "0";
                this.txtHMaterName.Text = "";
                this.txtHMaterModel.Text = "";
            }
            //
            txtHPackNum.Text = BillOld.omodel.HPackNum;
            //
            this.dtpHDate.Value = BillOld.omodel.HDate;
            this.txtHBillNo.Text = BillOld.omodel.HBillNo;
            this.txtHRemark.Text = BillOld.omodel.HRemark;
            //
            this.txtHBacker.Text = BillOld.omodel.HBacker;
            this.txtHBackDate.Text = BillOld.omodel.HBackDate;
            this.txtHChecker.Text = BillOld.omodel.HChecker;
            this.txtHCheckDate.Text = BillOld.omodel.HCheckDate;
            this.txtHMaker.Text = BillOld.omodel.HMaker;
            this.txtHMakeDate.Text = BillOld.omodel.HMakeDate;
            this.txtHUpDater.Text = BillOld.omodel.HUpDater;
            this.txtHUpDateDate.Text = BillOld.omodel.HUpDateDate;
            this.txtHCloseMan.Text = BillOld.omodel.HCloseMan;
            this.txtHCloseDate.Text = BillOld.omodel.HCloseDate;
            this.txtHDeleteMan.Text = BillOld.omodel.HDeleteMan;
            this.txtHDeleteDate.Text = BillOld.omodel.HDeleteDate;
            //加载表体
            int i = 0;
            foreach (Model.ClsSc_MaterDownBillSub oSub in BillOld.DetailColl)
            {
                if (i >= grdMain.RowCount - 1)
                    grdMain.Rows.Add();
                grdMain.Rows[i].Cells[HTagCol].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[HSourceIDCol].Value = oSub.HSourceID.ToString();
                if (oSour.GetInfoByID(oSub.HSourceID))
                {
                    grdMain.Rows[i].Cells[HSourceNumberCol].Value = oSour.omodel.HNumber;
                    grdMain.Rows[i].Cells[HSourceNameCol].Value = oSour.omodel.HName;
                }
                else
                {
                    grdMain.Rows[i].Cells[HSourceNumberCol].Value = "";
                    grdMain.Rows[i].Cells[HSourceNameCol].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;
                    grdMain.Rows[i].Cells[HMaterModelCol].Value = oMater.omodel.HModel;
                }
                else
                {
                    grdMain.Rows[i].Cells[HMaterNumberCol].Value = "";
                    grdMain.Rows[i].Cells[HMaterNameCol].Value = "";
                    grdMain.Rows[i].Cells[HMaterModelCol].Value = "";
                }
                //
                grdMain.Rows[i].Cells[HDateCol].Value = oSub.HDate.ToShortDateString();
                grdMain.Rows[i].Cells[HBatchNoCol].Value = oSub.HBatchNo;
                grdMain.Rows[i].Cells[HQtyCol].Value = oSub.HQty.ToString();
                grdMain.Rows[i].Cells[HWeightCol].Value = oSub.HWeight.ToString();
                grdMain.Rows[i].Cells[HSumWeightCol].Value = oSub.HSumWeight.ToString();
                grdMain.Rows[i].Cells[HPackNumCol].Value = oSub.HPackNum;
                grdMain.Rows[i].Cells[HRemarkCol].Value = oSub.HRemark;
                //
                grdMain.Rows[i].Cells[HCloseManCol].Value = oSub.HCloseMan;
                //grdMain.Rows[i].Cells[HCloseTypeCol].Value =  oSub.HCloseType  ;
                grdMain.Rows[i].Cells[HSourceInterIDCol].Value = oSub.HSourceInterID.ToString();
                grdMain.Rows[i].Cells[HSourceEntryIDCol].Value = oSub.HSourceEntryID.ToString();
                grdMain.Rows[i].Cells[HSourceBillNoCol].Value = oSub.HSourceBillNo;
                grdMain.Rows[i].Cells[HSourceBillTypeCol].Value = oSub.HSourceBillType;
                grdMain.Rows[i].Cells[HRelationQtyCol].Value = oSub.HRelationQty.ToString();
                grdMain.Rows[i].Cells[HRelationMoneyCol].Value = oSub.HRelationMoney.ToString();
                i = i + 1;
            }
            //GRID允许刷新 
            DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid);
            //
            Sub_OperStatus();
        }
 
        //单据完整性判断          未完成
        private bool Sub_AllowSave()
        {
            //必输项目是否为空
            if (ClsPub.isLong(txtHDeptID.Tag) == 0)
            {
                MessageBox.Show("车间没有选择!", "提示");
                return false;
            }
            if (ClsPub.isLong(txtHMaterID.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_MaterDownBillSub oBillSub = new Model.ClsSc_MaterDownBillSub();
            Int32 i;
            bool bResult;
            //网格失去焦点
 
            lblCaption.Focus(); 
            //
            BillNew = new DAL.ClsSc_MaterDownBill();
            if (!Sub_AllowSave())//单据完整性判断
                return false;
            //赋值ID
            if (BillStatus ==DBUtility.ClsPub.Enum_BillStatus.BillStatus_Modify)
                BillNew.omodel.HInterID = BillOld.omodel.HInterID;
            //主类赋值
            BillNew.omodel.HYear = 2011;
            BillNew.omodel.HPeriod = 1;
            BillNew.omodel.HInnerBillNo = "";
            BillNew.omodel.HBillNo = this.txtHBillNo.Text.Trim();  //在赋值类前就处理好字符串和数字
            BillNew.omodel.HDate = this.dtpHDate.Value;
            BillNew.omodel.HDeptID = ClsPub.isLong(this.txtHDeptID.Tag);
            BillNew.omodel.HMaterID = ClsPub.isLong(this.txtHMaterID.Tag);
            BillNew.omodel.HPackNum = this.txtHPackNum.Text.Trim();
            BillNew.omodel.HRemark = this.txtHRemark.Text.Trim();
            //明细类赋值
            BillNew.DetailColl = new List<Model.ClsSc_MaterDownBillSub>();
            for (i = 0; i <= grdMain.RowCount - 1; i++)
            {
                if (ClsPub.isLong( grdMain.Rows[i].Cells[HMaterIDCol].Value) != 0  )
                {
                    Model.ClsSc_MaterDownBillSub oSub = new Model.ClsSc_MaterDownBillSub();
                    oSub.HEntryID = i + 1;
                    //
                    oSub.HDate = DBUtility.ClsPub.isDate(grdMain.Rows[i].Cells[HDateCol].Value);
                    oSub.HEmpID = DBUtility.ClsPub.isLong(grdMain.Rows[i].Cells[HEmpIDCol].Value);
                    oSub.HSourceID = DBUtility.ClsPub.isLong(grdMain.Rows[i].Cells[HSourceIDCol].Value);
                    oSub.HMaterID = DBUtility.ClsPub.isLong(grdMain.Rows[i].Cells[HMaterIDCol].Value);
                    oSub.HBatchNo = DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[HBatchNoCol].Value);
                    oSub.HQty = DBUtility.ClsPub.isDoule(grdMain.Rows[i].Cells[HQtyCol].Value);
                    oSub.HWeight = DBUtility.ClsPub.isDoule(grdMain.Rows[i].Cells[HWeightCol].Value);
                    oSub.HSumWeight = DBUtility.ClsPub.isDoule(grdMain.Rows[i].Cells[HSumWeightCol].Value);
                    oSub.HPackNum = DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[HPackNumCol].Value);
                    oSub.HRemark = DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[HRemarkCol].Value);
                    oSub.HBillNo_bak = this.txtHBillNo.Text.Trim();
                    //
                    oSub.HCloseMan = DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[HCloseManCol].Value);
                    oSub.HCloseType = DBUtility.ClsPub.isBool(grdMain.Rows[i].Cells[HCloseTypeCol].Value);
                    oSub.HSourceInterID = DBUtility.ClsPub.isLong(grdMain.Rows[i].Cells[HSourceInterIDCol].Value);
                    oSub.HSourceEntryID = DBUtility.ClsPub.isLong(grdMain.Rows[i].Cells[HSourceEntryIDCol].Value);
                    oSub.HSourceBillType = DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[HSourceBillTypeCol].Value);
                    oSub.HSourceBillNo = DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[HSourceBillNoCol].Value); 
                    oSub.HRelationQty = DBUtility.ClsPub.isDoule(grdMain.Rows[i].Cells[HRelationQtyCol].Value);
                    oSub.HRelationMoney = DBUtility.ClsPub.isDoule(grdMain.Rows[i].Cells[HRelationMoneyCol].Value); 
                    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 initGrid()
        {
            grdMain.RowCount = 0;
            grdMain.ColumnCount = 27;                       //总列数
            DBUtility.Xt_BaseBillFun.initGridFst(grdMain, this.Name); 
            ////
            grdMain.Columns[HSnoCol].HeaderText = "序号";
            grdMain.Columns[HRemarkCol].HeaderText = "备注";
            //
            grdMain.Columns[HDateCol].HeaderText = "日期";
            grdMain.Columns[HEmpNumberCol].HeaderText = "操作员代码";
            grdMain.Columns[HEmpNameCol].HeaderText = "操作员";
            grdMain.Columns[HSourceNumberCol].HeaderText = "机台号代码";
            grdMain.Columns[HSourceNameCol].HeaderText = "机台号";
            grdMain.Columns[HMaterNumberCol].HeaderText = "喂料物料代码";
            grdMain.Columns[HMaterNameCol].HeaderText = "喂料物料名称";
            grdMain.Columns[HMaterModelCol].HeaderText = "规格型号";
            grdMain.Columns[HBatchNoCol].HeaderText = "喂料批次号";
            grdMain.Columns[HQtyCol].HeaderText = "碎料次数";
            grdMain.Columns[HWeightCol].HeaderText = "重量KG";
            grdMain.Columns[HSumWeightCol].HeaderText = "累计重量KG";
            grdMain.Columns[HPackNumCol].HeaderText = "容器号";
            //
            grdMain.Columns[HCloseManCol].HeaderText = "行关闭";
            grdMain.Columns[HCloseTypeCol].HeaderText = "关闭类型";
            grdMain.Columns[HSourceInterIDCol].HeaderText = "源单主内码";
            grdMain.Columns[HSourceEntryIDCol].HeaderText = "源单子内码";
            grdMain.Columns[HSourceBillNoCol].HeaderText = "源单单号";
            grdMain.Columns[HSourceBillTypeCol].HeaderText = "源单类型";
            grdMain.Columns[HRelationQtyCol].HeaderText = "关联数量";
            grdMain.Columns[HRelationMoneyCol].HeaderText = "关联金额";
            //格式化 
            grdMain.Columns[HTagCol].Visible = false;                           //隐藏列 
            grdMain.Columns[HEmpIDCol].Visible = false;
            grdMain.Columns[HSourceIDCol].Visible = false;
            grdMain.Columns[HMaterIDCol].Visible = false;
            grdMain.Columns[HCloseManCol].Visible = false;
            grdMain.Columns[HCloseTypeCol].Visible = false;
            grdMain.Columns[HSourceInterIDCol].Visible = false;
            grdMain.Columns[HSourceEntryIDCol].Visible = false;
            grdMain.Columns[HSourceBillNoCol].Visible = false;
            grdMain.Columns[HSourceBillTypeCol].Visible = false;
            grdMain.Columns[HRelationQtyCol].Visible = false;
            grdMain.Columns[HRelationMoneyCol].Visible = false;
            //设置可编辑列
            string sAllowCol = HDateCol.ToString() +
                            "," + HEmpNumberCol.ToString() +
                            "," + HSourceNumberCol.ToString() +
                            "," + HMaterNumberCol.ToString() +
                            "," + HBatchNoCol.ToString() +
                            "," + HQtyCol.ToString() +
                            "," + HWeightCol.ToString() +
                            "," + HSumWeightCol.ToString() +
                            "," + HPackNumCol.ToString() +
                            "," + HRemarkCol.ToString();
            //设置合计列
            string sTotalCol = HQtyCol.ToString();
            //
            DBUtility.Xt_BaseBillFun.initGridLast(sAllowCol, sTotalCol,oSumGrid);
        }
        
        //公式重算
        private void RowCount(int sRow, int sTag)
        {
            if (sTag == 0)
            {
                //金额列=数量*单价
                //double sMoney = 0;
                //sMoney = ClsPub.isDoule(grdMain.get_TextMatrix(sRow, HPriceCol)) * ClsPub.isDoule(grdMain.get_TextMatrix(sRow, HQtyCol));
                //grdMain.set_TextMatrix(sRow, HMoneyCol, sMoney.ToString());
                //grdMain.Rows[sRow].Cells[HQtyCol].Value = ClsPub.isDoule(grdMain.Rows[sRow].Cells[HQtyCol].Value, DBUtility.ClsPub.isInt(grdMain.Rows[sRow].Cells[HQtyDecimalCol].Value));
            }
            else
            {
                //单价列=金额/数量
                double sMoney = 0;
            }
        }
 
        //核对选择的内容
        public bool CheckGridCell(Cell oCell)
        {
            int Row;
            int Col;
            Row = oCell.Row;
            Col = oCell.Col;
            //if (ClsPub.isStrNull(grdMain.get_TextMatrix(Row, HTagCol)) != "*")
            //{
            //    return true;
            //}
            //grdMain.Redraw = VSFlex7.RedrawSettings.flexRDNone;
            //判断选中列
            if (Col == HMaterIDCol)  // 
            {
                //ClsGy_MaterialHlp oMate = new ClsGy_MaterialHlp();
                //if (oMate.GetInfoByID(ClsPub.isLong(grdMain.Rows[Row].Cells[HMaterIDCol].Value)))
                //{
                //    grdMain.Rows[Row].Cells[HMaterIDCol].Value = oMate.HItemID.ToString();
                //    grdMain.Rows[Row].Cells[HMaterNumberCol].Value = oMate.HNumber;
                //    grdMain.Rows[Row].Cells[HMaterNameCol].Value = oMate.HName;
                //    //grdMain.Rows[Row].Cells[HMaterModelCol].Value = oMate.HModel;
                //}
                //else
                //{
                //    grdMain.Rows[Row].Cells[HMaterIDCol].Value = "";
                //    grdMain.Rows[Row].Cells[HMaterNumberCol].Value = "";
                //    grdMain.Rows[Row].Cells[HMaterNameCol].Value = "";
                //    //grdMain.Rows[Row].Cells[HMaterModelCol].Value = "";
                return false;
                //}
            }
            //else if (Col == HEmpIDCol)  // 
            //{
                //ClsGy_UnitHlp oUn = new ClsGy_UnitHlp();
                //if (oUn.GetInfoByID(ClsPub.isLong(grdMain.Rows[Row].Cells[HUnitIDCol])))
                //{
                //    grdMain.Rows[Row].Cells[HUnitIDCol].Value = oUn.HItemID.ToString();
                //    grdMain.Rows[Row].Cells[HUnitNameCol].Value = oUn.HName;
                //}
                //else
                //{
                //    grdMain.Rows[Row].Cells[HUnitIDCol].Value = "";
                //    grdMain.Rows[Row].Cells[HUnitNameCol].Value = "";
                    //return false;
                //}
            //}
            else //其他列
            {
            }
            // 
            //
            grdMain.Rows[Row].Cells[HTagCol].Value = "*";
            oSumGrid.EditStatus = false;
            return true;
        }
        //是否是空行
        private bool IsNullRow(int Row)
        {
            return DBUtility.Xt_BaseBillFun.IsNullRow(Row, HMaterIDCol, grdMain);
        }
        //'判断网格行的录入是否正确
        private bool CheckGridRow(int Row)
        {
            Cell oCell = new Cell();
            int c = 0;
            //if (ClsPub.isStrNull(grdMain.get_TextMatrix(Row, HTagCol)) != "*")
            //{
            //    return true;
            //}
            //
            for (c = 0; c < grdMain.ColumnCount; c++)
            {
                oCell.Row = Row;
                oCell.Col = c;
                //if (!CheckGridCell(oCell))
                //    return false;
 
            }
            return true;
        }
        //帮助函数
        private void Sub_GridKey(int sKeyCode, int sRow, int sCol, DataGridViewTextBoxEditingControl oEdit)
        {
            //定义基础资料类
 
            string sWhere = "";
            if (!grdStatus)
            {
                return;
            }
            //if (oSumGrid.FindAllowEditCol(sCol))
            //{
            oSumGrid.EditStatus = true;
            //}
            //else
            //{
            //    return;
            //}
            switch (sKeyCode)
            {
                case 118:          //F7
                    {
                        switch (sCol)
                        {
                            case HDateCol:
                                BLL.ClsPub_BLL.Sub_SelectDate(grdMain, sRow, HDateCol);
                                oEdit.Text = DBUtility.ClsPub.isStrNull(grdMain.Rows[sRow].Cells[HDateCol].Value);
                                break;
 
                            case HEmpNumberCol:
                                BLL.ClsBaseSelect.SetGridByEmp(grdMain, sRow, HEmpIDCol, HEmpNumberCol, HEmpNameCol);
                                oEdit.Text = DBUtility.ClsPub.isStrNull(grdMain.Rows[sRow].Cells[HEmpNumberCol].Value);
                                break;
 
                            case HSourceNumberCol:
                                BLL.ClsBaseSelect.SetGridBySource(grdMain, sRow, HSourceIDCol, HSourceNumberCol, HSourceNameCol);
                                oEdit.Text = DBUtility.ClsPub.isStrNull(grdMain.Rows[sRow].Cells[HSourceNumberCol].Value);
                                break;
 
                            case HMaterNumberCol:
                                BLL.ClsBaseSelect.SetGridByMaterial(grdMain, sRow, HMaterIDCol, HMaterNumberCol, HMaterNameCol, HMaterModelCol);
                                oEdit.Text = DBUtility.ClsPub.isStrNull(grdMain.Rows[sRow].Cells[HMaterNumberCol].Value);
                                break;
 
                            default:
                                break;
                        }
                        break;
                    }
                case 117:  //F6
                    {
                        switch (sCol)
                        {
                            
                           
                            default:
                                break;
                        }
                        break;
                    }
                default:
                    break;
            }
        }
 
        //网格编辑前判断
        private void grdMain_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
        {
            int i = grdMain.CurrentCell.ColumnIndex;
            if (DBUtility.Xt_BaseBillFun.AllowEdit(grdStatus, oSumGrid,i))
            {
                e.Cancel = true;
            }
        }
 
        //网格编辑后处理
        private void grdMain_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid);
            RowCount(e.RowIndex, 0);  //计算 金额 单价
            //
            if (this.EditingControl != null)      //释放事件
            {
                EditingControl.KeyDown -= new KeyEventHandler(this.EditingControl_KeyDown);
                this.EditingControl = null;
            }
        }
        DataGridViewTextBoxEditingControl EditingControl;
 
        private void grdMain_CellLeave(object sender, DataGridViewCellEventArgs e)
        {
            //
            if (!grdStatus)
            {
                return;
            }
            DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid);
            //
            //if (oSumGrid.Changelock)
            //    return;
            //if(oSumGrid.EditStatus)
            //{
            if (!CheckGridRow(oSumGrid.OldCell.Row))
                return;
            //}
        }
 
        private void grdMain_ColumnWidthChanged(object sender, DataGridViewColumnEventArgs e)
        {
            DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid);
        }
 
        private void grdMain_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            if (grdMain.CurrentCell != null)
            {
                if (e.Control is DataGridViewTextBoxEditingControl)
                {
                    this.EditingControl = (DataGridViewTextBoxEditingControl)e.Control;
                    //增加委托处理 
                    this.EditingControl.KeyDown += new KeyEventHandler(this.EditingControl_KeyDown);
                }
            }
        }
        private void EditingControl_KeyDown(object sender, KeyEventArgs e)
        {
            //业务处理 
            Sub_GridKey(e.KeyValue, grdMain.CurrentRow.Index, grdMain.CurrentCell.ColumnIndex, EditingControl);
        }
        private void grdMain_RowHeadersWidthChanged(object sender, EventArgs e)
        {
            DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid);
        }
 
        private void grdMain_Scroll(object sender, ScrollEventArgs e)
        {
            DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid);
            oSumGrid.DisplayCurRow();
        }
 
        #endregion
 
 
        #region  //打印设置
 
        GridppReport Report;
 
        //预览
        private void yl_Click(object sender, EventArgs e)
        {
            //选择打印模板
            BLL.Gy_OpenTmp oFrm = new BLL.Gy_OpenTmp();
            oFrm.sBillName = ModName;
            oFrm.sBillModel = ModCaption;
            oFrm.ShowDialog();
            if (oFrm.OKTag == Pub_Class.ClsPub.Enum_OKTag.OKTag_OK)
            {
                //
                Sub_SetReport(oFrm.sOpenTmp);
                Report.PrintPreview(true);
            }
        }
 
        private void Sub_SetReport(string sOpenTmp)
        {
            //
            Report = new GridppReport();
            Report.LoadFromFile(ClsPub.AppPath + @"\" + sOpenTmp + ".grf");  //here .
            Report.BeforePostRecord += new _IGridppReportEvents_BeforePostRecordEventHandler(ReportBeforePostRecord);
            Report.FetchRecord += new _IGridppReportEvents_FetchRecordEventHandler(ReportFetchRecordByDataTable);
        }
 
        private void ReportBeforePostRecord()// 
        {
            Report.FieldByName("单据号").AsString = txtHBillNo.Text;
            Report.FieldByName("日期").AsString = dtpHDate.Value.ToString(); 
            Report.FieldByName("业务员").AsString = txtHDeptID.Text; 
            Report.FieldByName("内部单据号").AsString = txtHInnerBillNo.Text;
            Report.FieldByName("表头备注").AsString = txtHRemark.Text;
        }
 
        private void ReportFetchRecordByDataTable()
        {
            //BLL.Utility.FillRecordToReport(Report, grdMain, grdPrint, HProcIDCol);
        }
 
        #endregion
 
 
        #region  //表头基础资料选择
 
        private void cmdHDeptID_Click(object sender, EventArgs e)
        {
            DAL.ClsGy_Department_View oDep = new DAL.ClsGy_Department_View();
            if (oDep.RefreshView())
            {
                this.txtHDeptID.Text = oDep.oModel.HName;
                this.txtHDeptID.Tag = oDep.oModel.HItemID.ToString();
            }
            else
            {
                this.txtHDeptID.Tag = "0";
                this.txtHDeptID.Text = "";
            }
        }
 
        private void txtHDeptID_TextChanged(object sender, EventArgs e)
        {
            if (txtHDeptID.Text.Trim() == "")
            {
                txtHDeptID.Tag = "0";
                txtHDeptID.Text = "";
            }
        }
 
        private void cmdHMaterID_Click(object sender, EventArgs e)
        {
            DAL.ClsGy_Material_View oMater = new DAL.ClsGy_Material_View();
            if (oMater.RefreshViewMul())
            {
                this.txtHMaterID.Text = oMater.omodel.HNumber;
                this.txtHMaterID.Tag = oMater.omodel.HItemID.ToString();
                this.txtHMaterName.Text = oMater.omodel.HName;
                this.txtHMaterModel.Text = oMater.omodel.HModel;
            }
            else
            {
                this.txtHMaterID.Tag = "0";
                this.txtHMaterID.Text = "";
                this.txtHMaterName.Text = "";
                this.txtHMaterModel.Text = "";
            }
        }
 
        private void txtHMaterID_TextChanged_1(object sender, EventArgs e)
        {
            if (txtHMaterID.Text.Trim() == "")
            {
                txtHMaterID.Tag = "0";
                txtHMaterID.Text = "";
                txtHMaterName.Text = "";
                txtHMaterModel.Text = "";
            }
        }
 
        #endregion
 
 
 
        private void 关闭ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Sub_CloseBill();
        }
        private void 反关闭ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Sub_Cancel();
        }
        private void 审核ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Sub_CheckBill();
        }
        private void 反审核ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Sub_AbandonCheck();
        }
        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)
        {
            BLL.Gy_GridView_Hide oHide = new BLL.Gy_GridView_Hide();
            oHide.KeyItem = this.Name;
            oHide.oGrd = grdMain;
            oHide.ShowDialog();
            //
            DBUtility.ClsPub.HideGridView(grdMain, Name, ClsPub.AppPath);//设置隐藏列
 
        }
 
       
       
 
        
 
        
       
 
        
 
    }
}