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
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 SQLHelper;
 
namespace WorkM
{
    public partial class Sc_ProcessExchangeBill_DH : Form
    {
        public Sc_ProcessExchangeBill_DH()
        {
            InitializeComponent();
        }
        //定义列
        public const Int16 HSnoCol = 0;                    // 序号
        public const Int16 HICMOInterIDCol = 1;           // 生产订单内码
        public const Int16 HICMOEntryIDCol = 2;           // 生产订单子内码
        public const Int16 HICMOBillNoCol = 3;            // 生产订单号
        public const Int16 HWorkShopIDCol = 4;            // 生产车间
        public const Int16 HMaterIDCol = 5;               // HMaterID
        public const Int16 HMaterNumberCol = 6;           // 物料代码
        public const Int16 HMaterNameCol = 7;             // 物料名称
        public const Int16 HMaterModelCol = 8;            // 规格型号
        public const Int16 HQtyCol = 9;                   // 订单总数
        public const Int16 HProQtyCol = 10;               // 流转卡数量
        public const Int16 HBatchNoCol = 11;              // 批次号
        public const Int16 HProjectNumCol = 12;           // 项目编号
        public const Int16 HMateOutBatchNoCol = 13;       // 原料批次
        public const Int16 HMouldNumCol = 14;             // 模穴号
        public const Int16 HGroupNumberCol = 15;          // 班组
        public const Int16 HBatchManagerCol = 16;         // 启用批次
        public const Int16 HRoutingInterIDCol = 17;       // 工艺路线内码
        public const Int16 HRoutingNameCol = 18;          // 工艺路线
        public const Int16 HRoutingNumberCol = 19;          // 工艺路线
        public const Int16 HDateCol = 20;                 // 流转卡日期
        public const Int16 HInterIDCol = 21;              // 流转卡内码
        public const Int16 HBillNoCol = 22;               // 流转卡号
        public const Int16 HEditCol = 23;
 
 
        // 总列数
        public const Int16 TotalColumnCount = 24;
 
 
     
        //
        public const string ModName = "3772";                   //单据类型
        public string ModCaption = "工序流转卡";          //单据名称
        public const string ModRightName = "Sc_ProcessExchangeBill";
        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 DAL.ClsSc_ProcessExchangeBill BillNew = new DAL.ClsSc_ProcessExchangeBill();   //对应单据类
        public DAL.ClsSc_ProcessExchangeBill BillOld = new DAL.ClsSc_ProcessExchangeBill();   //对应单据类
        ClsGridViewSum oSumGrid = new ClsGridViewSum();
        public DataSet oXT;
        public string CampanyName = ""; //客户定制化名称
        DateTime dt = DateTime.Now;
        SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
        DataSet ds;
        // 添加属性来接收选中的订单ID
        public List<string> SelectedOrderIds { get; set; }
        public string HSouceBillType { get; set; }
        //-------------------------------------------------------------------------
 
        #region 固定代码
 
 
        //清空界面
        public void Sub_ClearBill()
        {           
            txtHMaker.Text = ClsPub.CurUserName;
            txtHMakeDate.Text = "";
            txtHChecker.Text = "";
            txtHCheckDate.Text = "";
            txtHCloseMan.Text = "";
            txtHCloseDate.Text = "";
            txtHDeleteMan.Text = "";
            txtHDeleteDate.Text = "";
            txtHUpDater.Text = "";
            txtHUpDateDate.Text = "";
            initGrid();
        }
       
        //保存列宽
        private void bclk_Click(object sender, EventArgs e)
        {
            DBUtility.Xt_BaseBillFun.SaveGrid(grdMain, this.Name);
        }
        //增行按钮  
        private void AddRow_Click(object sender, EventArgs e)
        {
            if (grdMain.CurrentRow == null)
            {
                return;
            }
            if (DBUtility.ClsPub.isBool(grdMain.Rows[grdMain.CurrentRow.Index].Cells[HEditCol].Value) == false)
            {
                DBUtility.Xt_BaseBillFun.AddRow(oSumGrid);
            }
        }
        //删行按纽  
        private void DelRow_Click(object sender, EventArgs e)
        {
            if (grdMain.CurrentRow == null)
            {
                return;
            }
            if (DBUtility.ClsPub.isBool(grdMain.Rows[grdMain.CurrentRow.Index].Cells[HEditCol].Value) == false)
            {
                DBUtility.Xt_BaseBillFun.DelRow(oSumGrid);
            }
        }
        private void mrlk_Click(object sender, EventArgs e)
        {
            DBUtility.Xt_BaseBillFun.DefaultGridView(grdMain, this.Name);
        }
     
        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_AddBill();
                }
            }
        }
        private void Sc_ProcessExchangeBill_Paint(object sender, PaintEventArgs e)//画线
        {          
        }
        //控件位置
        private void Sub_ControlLocation()
        {
        }
 
        //窗体加载
        private void Sc_ProcessExchangeBill_Load(object sender, EventArgs e)
        {
            //打印初始化        
            oSumGrid.NoCol = HSnoCol;
            oSumGrid.ogrdMain = grdMain;
            oSumGrid.oGridsum = grdSum;
            //
            this.Text = ModCaption;     //命名窗体标题
            this.lblCaption.Text = ModCaption;//命名单据标题
        }     
        //保存按钮
        private void bc_Click(object sender, EventArgs e)
        {
            this.Sub_SaveBill();
        }
        //放弃按钮
        private void fq_Click(object sender, EventArgs e)
        {
            this.Sub_AbandonBill();
        }      
        //退出按钮
        private void tc_Click(object sender, EventArgs e)
        {
            this.Close();
        }
 
        //根据编辑状态 设置 控件是否允许录入    
        private void Sub_LrtextStatus(bool TextEnabled)
        {
            if (TextEnabled == true)
            {
                //控件全部有效             
                grdMain.BackColor = ClsPub.EditColor;
 
            }
            else
            {   //控件全部无效
                grdMain.BackColor = ClsPub.ViewColor;
            }
        }           
        //timer
        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            Sub_ControlLocation();
            if (BillStatus == DBUtility.ClsPub.Enum_BillStatus.BillStatus_View)
            {
              
            }
            else
            {
                this.Sub_AddBill();
                DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid);
            }
            // 如果有选中的订单ID,直接查询并显示数据
            if (SelectedOrderIds != null && SelectedOrderIds.Count > 0)
            {
                LoadAndDisplaySelectedOrders();
            }
            else if (oXT != null)
            {
                Sub_WriteInForm(oXT.Tables[0], 0);
            }
 
        }
        //窗体卸载
        private void Sc_ProcessExchangeBill_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_ProcessExchangeBill();
            this.BillOld = new DAL.ClsSc_ProcessExchangeBill();
            this.BillStatus = DBUtility.ClsPub.Enum_BillStatus.BillStatus_AddNew;
            this.Sub_OperStatus();//设置TOOLBAR
            this.Sub_ClearBill();//清空界面                    
        }
        //TOOLBAR状态  按钮是否灰度
        public void Sub_OperStatus()
        {
            switch (BillStatus)
            {                
                case DBUtility.ClsPub.Enum_BillStatus.BillStatus_AddNew:
                    //新增状态
                    yl.Enabled = false;
                    dy.Enabled = false;                
                    AddRow.Enabled = true;
                    DelRow.Enabled = true;
                    bc.Enabled = true;
                    fq.Enabled = true;                  
                    tc.Enabled = true;
                    Sub_LrtextStatus(true);
                    grdStatus = true;                   
                    pic1.Visible = false;
                    pic1.Image = null;
                    //
                    break;            
            }
 
        }
        #endregion  
 
        #region  读写类
        //单据完整性判断       
        private bool Sub_AllowSave()
        {         
            //获取系统参数
            Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter();
            if (oSystemParameter.ShowBill(ref DBUtility.ClsPub.sExeReturnInfo) == false)
            {
                DBUtility.ClsPub.sExeReturnInfo = "保存失败,获取系统参数失败! " + DBUtility.ClsPub.sExeReturnInfo;
                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()
        {
            try
            {               
                bool bResult = true;
                BillNew = new DAL.ClsSc_ProcessExchangeBill();
                //失去焦点
                lblCaption.Focus();
                if (!Sub_AllowSave())//单据完整性判断
                    return false;
 
                for (int i = 0; i < grdMain.Rows.Count; i++)
                {
                    if (IsNullRow(i)) continue;
 
                    var row = grdMain.Rows[i];
 
                    // 获取关键值
                    Int64 HICMOInterID = DBUtility.ClsPub.isLong(row.Cells[HICMOInterIDCol].Value);
                    Int64 HICMOEntryID = DBUtility.ClsPub.isLong(row.Cells[HICMOEntryIDCol].Value);
                    Int64 HRoutingInterID = DBUtility.ClsPub.isLong(row.Cells[HRoutingInterIDCol].Value);
                    Int64 HQty = DBUtility.ClsPub.isLong(row.Cells[HQtyCol].Value);
                    Int64 HProQty = DBUtility.ClsPub.isLong(row.Cells[HProQtyCol].Value);
                    Int64 HMaterID = DBUtility.ClsPub.isLong(row.Cells[HMaterIDCol].Value);
                    string HICMOBillNo = row.Cells[HICMOBillNoCol].Value?.ToString() ?? "";
 
                    // 日期处理
                    DateTime HDateValue;
                    if (!DateTime.TryParse(row.Cells[HDateCol].Value?.ToString(), out HDateValue))
                    {
                        HDateValue = DateTime.Now;
                    }
 
                    string HBatchNo = row.Cells[HBatchNoCol].Value?.ToString() ?? "";
                    string HProjectNum = row.Cells[HProjectNumCol].Value?.ToString() ?? "";
                    string HMateOutBatchNo = row.Cells[HMateOutBatchNoCol].Value?.ToString() ?? "";
                    string HMouldNum = row.Cells[HMouldNumCol].Value?.ToString() ?? "0#";
                    string HGroupNumber = row.Cells[HGroupNumberCol].Value?.ToString() ?? "";
                    Int64 HInterID = DBUtility.ClsPub.isLong(row.Cells[HInterIDCol].Value);
                    string HBillNo = row.Cells[HBillNoCol].Value?.ToString() ?? "";
 
                    // 查询获取完整数据
                    string sql = "select * from h_v_Sc_ProcessExchangeBill_BatchSplit where hmainid = " + HICMOInterID + " and hentryid = "
                                 + HICMOEntryID + " and HRoutingID = " + HRoutingInterID.ToString();
                    ds = oCn.RunProcReturn(sql, "h_v_Sc_ProcessExchangeBill_BatchSplit");
 
                    // 主表赋值
                    if (ds.Tables[0].Rows.Count > 0 && ds != null)
                    {
                        BillNew.omodel.HInterID = HInterID;
                        BillNew.omodel.HBillNo = HBillNo;
                        BillNew.omodel.HBillSubType = "3772";
                        BillNew.omodel.HMainSourceBillSubType = "3710";
                        BillNew.omodel.HDate = DateTime.Now.Date;
                        BillNew.omodel.HMaker = ClsPub.CurUserName;
                        BillNew.omodel.HMakeDate = DateTime.Now.ToString("G");
                        BillNew.omodel.HPrevMainSourceInterID = 0;
                        BillNew.omodel.HYear = HDateValue.Year;
                        BillNew.omodel.HPeriod = HDateValue.Month;
                        BillNew.omodel.HRemark = "";
                        BillNew.omodel.HBatchNo = HBatchNo;
                        BillNew.omodel.HProjectNum = HProjectNum;
                        BillNew.omodel.HMateOutBatchNo = HMateOutBatchNo;
                        BillNew.omodel.HMouldNum = HMouldNum;
                        BillNew.omodel.HMainMaterID = 0;
                        BillNew.omodel.HKeyMaterID = 0;
                        BillNew.omodel.HNo = 0;
                        BillNew.omodel.HOrderProcNO = ds.Tables[0].Rows[0]["HPlanOrderProcNo"].ToString();
                        BillNew.omodel.HWWOrderInterID = 0;
                        BillNew.omodel.HWWOrderEntryID = 0;
                        BillNew.omodel.HWWOrderBillNo = "";
                        BillNew.omodel.HEquipMentID = 0;
                        BillNew.omodel.HICMOBillNo = HICMOBillNo;
                        BillNew.omodel.HMaterID = HMaterID;
                        BillNew.omodel.HMaterNumber = ds.Tables[0].Rows[0]["HMaterNumber"].ToString();
                        BillNew.omodel.HUnitID = Pub_Class.ClsPub.isLong(ds.Tables[0].Rows[0]["HUnitID"]);
                        BillNew.omodel.HUnitNumber = ds.Tables[0].Rows[0]["HUnitNumber"].ToString();
                        BillNew.omodel.HMaterID2 = HMaterID;
                        BillNew.omodel.HPlanQty = HQty;
                        BillNew.omodel.HQty = HProQty;
                        BillNew.omodel.HPlanBeginDate = Convert.ToDateTime(dt.ToShortDateString());
                        BillNew.omodel.HPlanEndDate = Convert.ToDateTime(dt.ToShortDateString());
                        BillNew.omodel.HExplanation = "";
                        BillNew.omodel.HInnerBillNo = "";
                        BillNew.omodel.HSupID = 0;
                        BillNew.omodel.HWorkShopID = Pub_Class.ClsPub.isLong(ds.Tables[0].Rows[0]["HDeptID"]);
                        BillNew.omodel.HWorkTypeNum = "";
                        BillNew.omodel.HProdMaterCode = "";
                        BillNew.omodel.HSeOrderBillNo = ds.Tables[0].Rows[0]["HSeOrderBillNo"].ToString();
                        BillNew.omodel.HCusShortName = "";
                        BillNew.omodel.HCusNeedMaterial = "";
                        BillNew.omodel.HPlanSendGoodsDate = dt.ToShortDateString();
                        BillNew.omodel.HProdMaterName = "";
                        BillNew.omodel.HCusName = "";
                        BillNew.omodel.HWorkRemark = "";
                        BillNew.omodel.HImportNote = "";
                        BillNew.omodel.HMaterNumber_A = "";
                        BillNew.omodel.HMaterNumber_B = "";
                        BillNew.omodel.HMaterNumber_C = "";
                        BillNew.omodel.HMaterNumber_D = "";
                        BillNew.omodel.HProdType = "";
                        BillNew.omodel.HMaterShortName = "";
                        BillNew.omodel.HMaterIDA = "";
                        BillNew.omodel.HMaterIDB = "";
                        BillNew.omodel.HMaterIDC = "";
                        BillNew.omodel.HMaterIDD = "";
                        BillNew.omodel.HICMOInterID = HICMOInterID;
                        BillNew.omodel.HICMOEntryID = HICMOEntryID;
                        BillNew.omodel.HPicNumVer = ds.Tables[0].Rows[0]["HPicNumVer"].ToString();
                        BillNew.omodel.HPicNumAssemble = ds.Tables[0].Rows[0]["HPicNumAssemble"].ToString();
                        BillNew.omodel.HMaterTexture = ds.Tables[0].Rows[0]["HMaterTexture"].ToString();
                        BillNew.omodel.HProductNum = ds.Tables[0].Rows[0]["HProductNum"].ToString();
                        BillNew.omodel.HVerNum = ds.Tables[0].Rows[0]["HVerNum"].ToString();
                        BillNew.omodel.HPRDORGID = DBUtility.ClsPub.HOrgID;
                        BillNew.omodel.HBLFlag = false;
                        BillNew.omodel.HCusNumber = "";
                        BillNew.omodel.HPickLabel = "";
                        BillNew.omodel.HPickLabelNumber = "";
                        BillNew.omodel.HXTNumber = "";
                        BillNew.omodel.HXTModel = "";
                        BillNew.omodel.HWorkBillSortNo = "";
                        BillNew.omodel.HRoutingBillID = HRoutingInterID.ToString();
                        BillNew.omodel.HMaterModel = ds.Tables[0].Rows[0]["HMaterModel"].ToString();
                        BillNew.omodel.HWidth = 0;
                        BillNew.omodel.HWeight = 0;
                        BillNew.omodel.HAuxQty = 0;
                        BillNew.omodel.HAuxUnit = 0;
                        BillNew.omodel.HAuxQty2 = 0;
                        BillNew.omodel.HAuxUnit2 = 0;
                        BillNew.omodel.HSplitNo = 0;
                        BillNew.omodel.HHeight = "";
                        BillNew.omodel.HInches = "";
                        BillNew.omodel.HAl1Long = "";
                        BillNew.omodel.HDensity = "";
                        BillNew.omodel.HTela = "";
                        BillNew.omodel.HUnderTela = "";
                        BillNew.omodel.HSizing = "";
                        BillNew.omodel.HSellDate = dt.ToShortDateString();
                        BillNew.omodel.HRemark2 = "批量拆分下推";
                        BillNew.omodel.HRemark3 = "";
                        BillNew.omodel.HEmpID = 0;
                        BillNew.omodel.HCusID = 0;
                        BillNew.omodel.HColorRemark = "";
                        BillNew.omodel.HSplitSumQty = 0;
                        BillNew.omodel.HSplitColorQty = 0;
                        BillNew.omodel.HMachineLine = "";
                        BillNew.omodel.HMainSourceInterID = 0;
                        BillNew.omodel.HMainSourceEntryID = 0;
                        BillNew.omodel.HMainSourceBillNo = "";
                        BillNew.omodel.HOrderLevID = 0;
                        BillNew.omodel.HWidth_New = 0;
                        BillNew.omodel.HRemark_New = "";
                        BillNew.omodel.HWeight_New = 0;
                        BillNew.omodel.HPlanOrderProcNo = ds.Tables[0].Rows[0]["HPlanOrderProcNo"].ToString();
                    }
 
                    // 子表赋值                 
                    for (int j = 0; j < ds.Tables[0].Rows.Count; j++)
                    {
                        Model.ClsSc_ProcessExchangeBillSub oBillSub = new Model.ClsSc_ProcessExchangeBillSub();
                        oBillSub.HEntryID = j + 1;
                        oBillSub.HBillNo_bak = HBillNo;
                        oBillSub.HCloseMan = "";
                        oBillSub.HEntryCloseDate = Convert.ToDateTime(dt.ToShortDateString());
                        oBillSub.HCloseType = false;
                        oBillSub.HRemark = "";
                        oBillSub.HSourceInterID = HICMOInterID;
                        oBillSub.HSourceEntryID = HICMOEntryID;
                        oBillSub.HSourceBillNo = HICMOBillNo;
                        oBillSub.HSourceBillType = "3710";
                        oBillSub.HRelationQty = 0;
                        oBillSub.HRelationMoney = 0;
                        oBillSub.HRelationQty_In = 0;
                        oBillSub.HRelationQty_Out = 0;
                        oBillSub.HRelationQty_WWOrder = 0;
                        oBillSub.HRelationQty_Bad = 0;
                        oBillSub.HProcNo = Pub_Class.ClsPub.isLong(ds.Tables[0].Rows[j]["HProcNo"]);
                        oBillSub.HProcID = Pub_Class.ClsPub.isLong(ds.Tables[0].Rows[j]["HProcID"]);
                        oBillSub.HProcNumber = ds.Tables[0].Rows[j]["HProcNumber"].ToString();
                        oBillSub.HWorkRemark = "";
                        oBillSub.HCenterID = Pub_Class.ClsPub.isLong(ds.Tables[0].Rows[j]["HCenterID"]);
                        oBillSub.HDeptID = Pub_Class.ClsPub.isLong(ds.Tables[0].Rows[j]["HDeptID"]);
                        oBillSub.HDeptNumber = ds.Tables[0].Rows[j]["HDeptNumber"].ToString();
                        oBillSub.HGroupID = 0;
                        oBillSub.HGroupNumber = HGroupNumber;
                        oBillSub.HWorkerID = 0;
                        oBillSub.HWorkerNumber = "";
                        oBillSub.HSourceID = 0;
                        oBillSub.HQty = HProQty;
                        oBillSub.HTimeUnit = "";
                        oBillSub.HPlanWorkTimes = 0;
                        oBillSub.HPlanBeginDate = Convert.ToDateTime(dt.ToShortDateString());
                        oBillSub.HPlanEndDate = Convert.ToDateTime(dt.ToShortDateString());
                        oBillSub.HRelBeginDate = Convert.ToDateTime(dt.ToShortDateString());
                        oBillSub.HRelEndDate = Convert.ToDateTime(dt.ToShortDateString());
                        oBillSub.HReadyTime = 0;
                        oBillSub.HQueueTime = 0;
                        oBillSub.HMoveTime = 0;
                        oBillSub.HBeginDayQty = 0;
                        oBillSub.HBeginFixQty = 0;
                        oBillSub.HFixWorkDays = 0;
                        oBillSub.HTrunWorkDays = 0;
                        oBillSub.HReadyTimes = 0;
                        oBillSub.HMyWorkDays = 0;
                        oBillSub.HOutPrice = 0;
                        oBillSub.HOutMoney = 0;
                        oBillSub.HPassRate = 0;
                        oBillSub.HLastProc = "";
                        oBillSub.HKeyProc = "";
                        oBillSub.HFstProc = "";
                        oBillSub.HICMOInterID = HICMOInterID;
                        oBillSub.HICMOBillNo = HICMOBillNo;
                        oBillSub.HWWOrderInterID = 0;
                        oBillSub.HWWOrderEntryID = 0;
                        oBillSub.HWWOrderBillNo = "";
                        oBillSub.HReportQty = 0;
                        oBillSub.HBackProc = false;
                        oBillSub.HSupID = Pub_Class.ClsPub.isLong(ds.Tables[0].Rows[j]["HSupID"]);
                        oBillSub.HSupFlag = DBUtility.ClsPub.isBool(ds.Tables[0].Rows[j]["HSupFlag"]);
                        oBillSub.HOverRate = 0;
                        oBillSub.HMaxQty = 0;
                        oBillSub.HTechnologyParameter = ds.Tables[0].Rows[j]["HTechnologyParameter"].ToString();
                        oBillSub.HProcCheckNote = "";
                        oBillSub.HPicNum = ds.Tables[0].Rows[j]["HPicNum"].ToString();
                        oBillSub.HMouldNo = ds.Tables[0].Rows[j]["HMouldNo"].ToString();
                        oBillSub.HProcWorkNum = ds.Tables[0].Rows[j]["HProcWorkNum"].ToString();
                        oBillSub.HSeOrderInterID = 0;
                        oBillSub.HSeOrderEntryID = 0;
                        oBillSub.HSNCtrl = false;
                        oBillSub.HRoutingBillMainID = Pub_Class.ClsPub.isLong(ds.Tables[0].Rows[j]["HRoutingID"]);
                        oBillSub.HRoutingBillEntryID = Pub_Class.ClsPub.isLong(ds.Tables[0].Rows[j]["HRoutingEntryID"]);
 
                        BillNew.DetailColl.Add(oBillSub);//添加明细行值                
                    }
 
                    //调用保存方法
                    bResult = BillNew.AddBill(ref ClsPub.sExeReturnInfo);
                    BillNew.DetailColl.Clear();//清空明细行值
                    if (!bResult)
                    {
                        break;
                    }                   
                }
                if (bResult)
                {
                    BillChange = true;
                    MessageBox.Show("单据保存完毕!", "提示");                                      
                    this.Sub_OperStatus();
                    return true;
                }
                else
                {
                    MessageBox.Show("保存失败!原因:" + ClsPub.sExeReturnInfo, "提示");
                    return false;
                }
            }
            catch(Exception e1)
            {
                MessageBox.Show(ClsPub.sExeReturnInfo + e1.Message);
                return false;
            }
        }
        #endregion 
 
 
        #region 窗体处理方法
        //初始化GRID
        private void initGrid()
        {
 
            //
            grdMain.ColumnCount = 24;                       //总列数
            DBUtility.Xt_BaseBillFun.initGridFst(grdMain, this.Name);
            //
            grdMain.RowsDefaultCellStyle.WrapMode = DataGridViewTriState.True;
            grdMain.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing;  //标题行高 调整模式
            grdMain.RowHeadersVisible = true;
            grdMain.AllowUserToResizeRows = true;           //允许调整行高--否
 
 
            // 设置列标题和属性
            // 序号列(自动编号)
            grdMain.Columns[HSnoCol].HeaderText = "序号";
            grdMain.Columns[HSnoCol].Width = 100;
            grdMain.Columns[HSnoCol].ReadOnly = true;
 
            // 生产订单内码 - 隐藏
            grdMain.Columns[HICMOInterIDCol].HeaderText = "生产订单内码";
            grdMain.Columns[HICMOInterIDCol].Width = 100;
            grdMain.Columns[HICMOInterIDCol].Visible = false;
 
            // 生产订单子内码 - 隐藏
            grdMain.Columns[HICMOEntryIDCol].HeaderText = "生产订单子内码";
            grdMain.Columns[HICMOEntryIDCol].Width = 100;
            grdMain.Columns[HICMOEntryIDCol].Visible = false;
 
            // 生产订单号
            grdMain.Columns[HICMOBillNoCol].HeaderText = "生产订单号";
            grdMain.Columns[HICMOBillNoCol].Width = 120;
            grdMain.Columns[HICMOBillNoCol].ReadOnly = true;
 
            // 生产车间 - 隐藏
            grdMain.Columns[HWorkShopIDCol].HeaderText = "生产车间";
            grdMain.Columns[HWorkShopIDCol].Width = 100;
            grdMain.Columns[HWorkShopIDCol].Visible = false;
 
            // HMaterID - 隐藏
            grdMain.Columns[HMaterIDCol].HeaderText = "HMaterID";
            grdMain.Columns[HMaterIDCol].Width = 100;
            grdMain.Columns[HMaterIDCol].Visible = false;
 
            // 物料代码
            grdMain.Columns[HMaterNumberCol].HeaderText = "物料代码";
            grdMain.Columns[HMaterNumberCol].Width = 150;
            grdMain.Columns[HMaterNumberCol].ReadOnly = true;
 
            // 物料名称
            grdMain.Columns[HMaterNameCol].HeaderText = "物料名称";
            grdMain.Columns[HMaterNameCol].Width = 150;
            grdMain.Columns[HMaterNameCol].ReadOnly = true;
 
            // 规格型号 - 隐藏
            grdMain.Columns[HMaterModelCol].HeaderText = "规格型号";
            grdMain.Columns[HMaterModelCol].Width = 100;
            grdMain.Columns[HMaterModelCol].Visible = false;
 
            // 订单总数
            grdMain.Columns[HQtyCol].HeaderText = "订单总数";
            grdMain.Columns[HQtyCol].Width = 110;
            grdMain.Columns[HQtyCol].ReadOnly = true;
 
            // 流转卡数量 - 可编辑
            grdMain.Columns[HProQtyCol].HeaderText = "流转卡数量";
            grdMain.Columns[HProQtyCol].Width = 110;
            grdMain.Columns[HProQtyCol].ReadOnly = false;
 
            // 批次号 - 隐藏
            grdMain.Columns[HBatchNoCol].HeaderText = "批次号";
            grdMain.Columns[HBatchNoCol].Width = 110;
            grdMain.Columns[HBatchNoCol].Visible = false;
            grdMain.Columns[HBatchNoCol].ReadOnly = false;
 
            // 项目编号 - 隐藏
            grdMain.Columns[HProjectNumCol].HeaderText = "项目编号";
            grdMain.Columns[HProjectNumCol].Width = 110;
            grdMain.Columns[HProjectNumCol].Visible = false;
            grdMain.Columns[HProjectNumCol].ReadOnly = false;
 
            // 原料批次 - 隐藏
            grdMain.Columns[HMateOutBatchNoCol].HeaderText = "原料批次";
            grdMain.Columns[HMateOutBatchNoCol].Width = 110;
            grdMain.Columns[HMateOutBatchNoCol].Visible = false;
            grdMain.Columns[HMateOutBatchNoCol].ReadOnly = false;
 
            // 模穴号 - 隐藏
            grdMain.Columns[HMouldNumCol].HeaderText = "模穴号";
            grdMain.Columns[HMouldNumCol].Width = 110;
            grdMain.Columns[HMouldNumCol].Visible = false;
 
            // 班组 - 隐藏
            grdMain.Columns[HGroupNumberCol].HeaderText = "班组";
            grdMain.Columns[HGroupNumberCol].Width = 110;
            grdMain.Columns[HGroupNumberCol].Visible = false;
            grdMain.Columns[HGroupNumberCol].ReadOnly = false;
 
            // 启用批次 - 隐藏
            grdMain.Columns[HBatchManagerCol].HeaderText = "启用批次";
            grdMain.Columns[HBatchManagerCol].Width = 110;
            grdMain.Columns[HBatchManagerCol].Visible = false;
 
            // 工艺路线内码 - 隐藏
            grdMain.Columns[HRoutingInterIDCol].HeaderText = "工艺路线内码";
            grdMain.Columns[HRoutingInterIDCol].Width = 150;
            grdMain.Columns[HRoutingInterIDCol].Visible = false;
 
            // 工艺路线代码
            grdMain.Columns[HRoutingNumberCol].HeaderText = "工艺路线代码";
            grdMain.Columns[HRoutingNumberCol].Width = 170;
            grdMain.Columns[HRoutingNumberCol].ReadOnly = true;
 
            // 工艺路线
            grdMain.Columns[HRoutingNameCol].HeaderText = "工艺路线";
            grdMain.Columns[HRoutingNameCol].Width = 170;
            grdMain.Columns[HRoutingNameCol].ReadOnly = true;
 
            // 流转卡日期 - 可编辑
            grdMain.Columns[HDateCol].HeaderText = "流转卡日期";
            grdMain.Columns[HDateCol].Width = 120;
            grdMain.Columns[HDateCol].ReadOnly = false;
 
            // 流转卡内码 - 隐藏
            grdMain.Columns[HInterIDCol].HeaderText = "流转卡内码";
            grdMain.Columns[HInterIDCol].Width = 130;
            grdMain.Columns[HInterIDCol].Visible = false;
 
            grdMain.Columns[HEditCol].HeaderText = "不可编辑";
            grdMain.Columns[HEditCol].Visible = false;
            // 流转卡号
            grdMain.Columns[HBillNoCol].HeaderText = "流转卡号";
            grdMain.Columns[HBillNoCol].Width = 170;
            grdMain.Columns[HBillNoCol].ReadOnly = true;
 
            // 设置可编辑列
            string sAllowCol = HProQtyCol.ToString() + "," +
                              HBatchNoCol.ToString() + "," +
                              HProjectNumCol.ToString() + "," +
                              HMateOutBatchNoCol.ToString() + "," +
                              HGroupNumberCol.ToString() + "," +                            
                              HDateCol.ToString();
 
            // 设置合计列
            string sTotalCol = HQtyCol.ToString() + "," + HProQtyCol.ToString();
 
            for (int i = 0; i < grdMain.Rows.Count; i++)
            {               
                DataGridViewCheckBoxCell oCell2 = new DataGridViewCheckBoxCell();
                oCell2.ThreeState = false;
                oCell2.Value = 0;
                oCell2.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
                grdMain.Rows[i].Cells[HEditCol] = oCell2;               
            }
            //格式化网格
            DBUtility.Xt_BaseBillFun.initGridLast(sAllowCol, sTotalCol, oSumGrid);
            
            oSumGrid.SetGridMain();
            
            DBUtility.ClsPub.HideGridView(grdMain, Name, ClsPub.AppPath);//设置隐藏列
        }
 
        //公式重算
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sRow"></param>
        /// <param name="sTag"> </param>
        public void Sub_RowCount(int sRow, int sCol)
        {
            if (IsNullRow(sRow))
                return;
           
            if (sCol == 0)
            {
              
            }
            else
            {
 
            }
        }
 
 
        //重算全部行
        public void ReCountAllRow()
        {
            for (int i = 0; i < grdMain.Rows.Count; i++)
            {              
            }
        }
 
 
 
 
 
        //核对选择的内容
        public bool CheckGridCell(Cell oCell)
        {
            int Row;
            int Col;
            Row = oCell.Row;
            Col = oCell.Col;          
            oSumGrid.EditStatus = false;
            return true;
        }
 
 
        //'判断网格行的录入是否正确
        private bool CheckGridRow(int Row)
        {
            Cell oCell = new Cell();
            int c = 0;          
            return true;
        }
        //帮助函数
        private void Sub_GridKey(int sKeyCode, int sRow, int sCol, DataGridViewTextBoxEditingControl oEdit)
        {           
            if (!grdStatus)
            {
                return;
            }
            oSumGrid.EditStatus = true;
            switch (sKeyCode)
            {               
                default:
                    break;
            }
        }
 
 
 
        #region  基本不变
 
        //是否是空行
        private bool IsNullRow(int Row)
        {
            return DBUtility.Xt_BaseBillFun.IsNullRow(Row, HICMOInterIDCol, grdMain);
        }
 
 
        //网格编辑前判断
        private void grdMain_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
        {
            int i = grdMain.CurrentCell.ColumnIndex;
            if (DBUtility.ClsPub.isBool(grdMain.Rows[grdMain.CurrentRow.Index].Cells[HEditCol].Value) == true)
            {
                e.Cancel = true;
            }
            if (DBUtility.Xt_BaseBillFun.AllowEdit(grdStatus, oSumGrid, i))
            {
                e.Cancel = true;
            }
        }
 
        private void grdMain_Scroll(object sender, ScrollEventArgs e)
        {
            DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid);
            oSumGrid.DisplayCurRow();
        }
 
        //网格编辑后处理
        private void grdMain_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid);
            Sub_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 (!CheckGridRow(oSumGrid.OldCell.Row))
                return;
        }
 
 
        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_ColumnWidthChanged(object sender, DataGridViewColumnEventArgs e)
        {
            DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid);
        }
 
        #endregion
 
        #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()// 
        {
            try
            {
                //Report.FieldByName("流转卡编号").AsString = txtHBillNo.Text;
                //Report.FieldByName("流转卡数量").AsString = txtHQty.Text;
                //Report.FieldByName("产品代码").AsString = txtHMaterNumber2.Text;
                //Report.FieldByName("产品名称").AsString = txtHMaterID2.Text;
                //Report.FieldByName("计划开工日期").AsString = dtpHPlanBeginDate.Value.ToShortDateString();
                //Report.FieldByName("计划完工日期").AsString = dtpHPlanEndDate.Value.ToShortDateString();
                //Report.FieldByName("订单跟踪号").AsString = txtHOrderProcNO.Text;
                //Report.FieldByName("原料批次").AsString = txtHMateOutBatchNo.Text;
                //Report.FieldByName("模具设备").AsString = txtHEquipMentID.Text;
                //Report.FieldByName("项目号").AsString = txtHProjectNum.Text;
                //Report.FieldByName("图号版本").AsString = textHPicNumVer.Text;
                //Report.FieldByName("总装图号").AsString = textHPicNumAssemble.Text;
                //Report.FieldByName("材质").AsString = textHMaterTexture.Text;
                //Report.FieldByName("成品编号").AsString = textHProductNum.Text;
                //Report.FieldByName("版本").AsString = textHVerNum.Text;
            }
            catch (Exception e)
            {
                MessageBox.Show("打印失败,[项目号],[流转卡编号],[流转卡数量],[产品代码],[产品名称],[计划开工日期],[计划完工日期],[订单跟踪号],[原料批次],[模具设备],[图号版本],[总装图号],[材质],[成品编号],[版本]." + e.Message);
            }
 
        }
        //赋值表体
        private void ReportFetchRecordByDataTable()
        {
            DataTable oDt = new DataTable();
            BLL.Utility.FillRecordToReport(Report, grdMain, oDt, HBillNoCol);
        }
        //打印设置
        private void set_Click(object sender, EventArgs e)
        {
            // 
            BLL.Gy_OpenTmp oFrm = new BLL.Gy_OpenTmp();
            oFrm.sBillName = ModName;
            oFrm.sBillModel = ModCaption;
            oFrm.ShowDialog();
        }
        //打印
        private void dy_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);
                BillOld.Set_PrintQty(DBUtility.ClsPub.isLong(BillOld.omodel.HInterID));
                Report.Print(true);
            }
        }
 
        #endregion
 
 
 
        #region  源单处理
      
        #endregion
 
        private void yc_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);//设置隐藏列
        }
       
        private void 隐藏列设置ToolStripMenuItem_Click(object sender, EventArgs e)
        {
 
        }
       
        private void grdMain_KeyDown(object sender, KeyEventArgs e)
        {            
        }
 
        private void grdMain_MouseUp(object sender, MouseEventArgs e)
        {
 
            if (grdMain.CurrentRow == null)
                return;           
        }
 
 
 
 
        //显示库存
        private void ShowStockQty(int sRow)
        {          
        }
 
        private void tm_Click(object sender, EventArgs e)
        {
            Sub_ShowBill_Sub();
        }
 
        //显示单据 条码
        public void Sub_ShowBill_Sub()
        {
            DAL.ClsIF_Warehouse_View oWare = new DAL.ClsIF_Warehouse_View();
            DAL.ClsIF_Material_View oMater = new DAL.ClsIF_Material_View();           
            //加载表体
            int i = 0;            
        }
 
        private void cmdSourceBillNo_Click(object sender, EventArgs e)
        {          
            DAL.Cls_S_IF_ICMOBillList oYD = new DAL.Cls_S_IF_ICMOBillList();
            string sWhere = " ";
            if (oYD.Refresh(sWhere))  //选择原单
            {
                FillSelectData(oYD.oBillSelectColl);
                //为什么这里是0
            }
        }
 
 
        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 == "85")
                {
                    grdMain.Rows.Add();
                    Application.DoEvents();
                    //得到信息
                    Ds = oCn.RunProcReturn("select * from h_v_S_Sc_ICMOBillList where hmainid=" + oSelectRow.BillMainID, "h_v_S_Sc_ICMOBillList");
                    //写入信息
                    Sub_WriteInForm(Ds.Tables[0], i);
                    Application.DoEvents();
                }
            }
            //
            oSumGrid.Changelock = false;
            DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid);
        }
 
        //根据TABLE写入界面
        public void Sub_WriteInForm(DataTable oTable, int j)
        {
            DataSet Ds;
            SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
            string sNo = "";
            int row = oTable.Rows.Count - 1;
 
            // 用于记录当前的生产订单和对应的流转卡信息
            string currentSourceInterID = "";
            string currentSourceEntryID = "";
            string baseBillNo = "";
            int k = 1; // 序号计数器
 
            for (int i = 0; i <= oTable.Rows.Count - 1; i++)
            {
                if (i >= grdMain.RowCount - 1)
                    grdMain.Rows.Add();
 
                string icmoInterID = oTable.Rows[i]["HICMOInterID"].ToString();
                string icmoEntryID = oTable.Rows[i]["HICMOEntryID"].ToString();
 
                string hInterID = "0"; // 默认内码为0
                string hBillNo = "";   // 流转卡号
 
                if (i == 0)
                {
                    // 首次进入,获取基础流转卡单号
                    baseBillNo = ClsPub.CreateBillCode_Prod("3772", ref ClsPub.sExeReturnInfo, true);
                    hBillNo = baseBillNo + "-" + k.ToString().PadLeft(2, '0');
                    currentSourceInterID = icmoInterID;
                    currentSourceEntryID = icmoEntryID;
                }
                else if (currentSourceInterID == icmoInterID && currentSourceEntryID == icmoEntryID)
                {
                    // 同一个生产订单,递增序号
                    k++;
                    hBillNo = baseBillNo + "-" + k.ToString().PadLeft(2, '0');
                }
                else
                {
                    // 新的生产订单,重置序号和基础单号
                    baseBillNo = ClsPub.CreateBillCode_Prod("3772", ref ClsPub.sExeReturnInfo, true);
                    k = 1;
                    hBillNo = baseBillNo + "-" + k.ToString().PadLeft(2, '0');
                    currentSourceInterID = icmoInterID;
                    currentSourceEntryID = icmoEntryID;
                }
 
                // 加载表体数据到新定义的列
                grdMain.Rows[i].Cells[HICMOInterIDCol].Value = oTable.Rows[i]["HICMOInterID"].ToString();
                grdMain.Rows[i].Cells[HICMOEntryIDCol].Value = oTable.Rows[i]["HICMOEntryID"].ToString();
                grdMain.Rows[i].Cells[HICMOBillNoCol].Value = oTable.Rows[i]["HICMOBillNo"].ToString();
                grdMain.Rows[i].Cells[HWorkShopIDCol].Value = oTable.Rows[i]["HWorkShopID"].ToString();
                grdMain.Rows[i].Cells[HMaterIDCol].Value = oTable.Rows[i]["HMaterID"].ToString();
                grdMain.Rows[i].Cells[HMaterNumberCol].Value = oTable.Rows[i]["物料代码"].ToString();
                grdMain.Rows[i].Cells[HMaterNameCol].Value = oTable.Rows[i]["物料名称"].ToString();
                grdMain.Rows[i].Cells[HMaterModelCol].Value = oTable.Rows[i]["规格型号"].ToString();
                grdMain.Rows[i].Cells[HQtyCol].Value = DBUtility.ClsPub.isDoule(oTable.Rows[i]["HQty"], 0);
                grdMain.Rows[i].Cells[HProQtyCol].Value = DBUtility.ClsPub.isDoule(oTable.Rows[i]["HProQty"], 0);
 
                grdMain.Rows[i].Cells[HBatchNoCol].Value = oTable.Rows[i]["HBatchNo"].ToString();
                grdMain.Rows[i].Cells[HProjectNumCol].Value = "";
                grdMain.Rows[i].Cells[HMateOutBatchNoCol].Value = "";
                grdMain.Rows[i].Cells[HMouldNumCol].Value = "0#";
                grdMain.Rows[i].Cells[HGroupNumberCol].Value = "";
                grdMain.Rows[i].Cells[HBatchManagerCol].Value = oTable.Rows[i]["是否启用批次"].ToString();
                grdMain.Rows[i].Cells[HRoutingInterIDCol].Value = oTable.Rows[i]["HRoutingInterID"].ToString();
                grdMain.Rows[i].Cells[HRoutingNumberCol].Value = oTable.Rows[i]["HRoutingNumber"].ToString();
                grdMain.Rows[i].Cells[HRoutingNameCol].Value = oTable.Rows[i]["HRoutingName"].ToString();
                grdMain.Rows[i].Cells[HDateCol].Value = oTable.Rows[i]["HDate"].ToString();
                grdMain.Rows[i].Cells[HInterIDCol].Value = hInterID; // 默认为0,保存时再生成实际内码
                grdMain.Rows[i].Cells[HBillNoCol].Value = hBillNo;
                grdMain.Rows[i].Cells[HEditCol].Value = false; // 明确设置为可编辑
 
            }
        }
       
        private void yc_Click_1(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);//设置隐藏列
        }
 
        private void Sc_ProcessExchangeBill_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Modifiers == Keys.Control && e.KeyCode == Keys.S) //按Ctrl+ S触发
            {
                this.Sub_SaveBill();
            }
 
        }
 
        private void cmdWorkType_Click(object sender, EventArgs e)
        {
            
        }
 
      
        private void txtHPlanQty_TextChanged(object sender, EventArgs e)
        {
 
        }
 
       
 
        
 
        private void 隐藏列设置ToolStripMenuItem_Click_1(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);//设置隐藏列
        }
 
        private void grdMain_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
 
        }
        // 新增方法:根据选中的订单ID查询并显示数据
        private void LoadAndDisplaySelectedOrders()
        {
            try
            {
                ClsCN oCn = new ClsCN();
                DataTable combinedTable = null;
 
                foreach (string orderId in SelectedOrderIds)
                {
                    // 解析订单ID格式:主内码@子内码
                    string[] parts = orderId.Split('@');
                    if (parts.Length != 2) continue;
 
                    Int64 HICMOID = DBUtility.ClsPub.isLong(parts[0]);
                    Int64 HEntryID = DBUtility.ClsPub.isLong(parts[1]);
                    string sql = "exec h_p_Sc_ProcessExchange_DH '" + HICMOID + "','" + HEntryID + "'";
                    DataSet Ds = oCn.RunProcReturn(sql, "h_p_Sc_ProcessExchange_DH");
 
                    if (Ds != null && Ds.Tables[0].Rows.Count > 0)
                    {
                        if (combinedTable == null)
                        {
                            combinedTable = Ds.Tables[0].Copy();
                        }
                        else
                        {
                            // 合并数据
                            combinedTable.Merge(Ds.Tables[0]);
                        }
                    }
                }
 
                if (combinedTable != null && combinedTable.Rows.Count > 0)
                {
                    // 直接调用现有的写入方法显示数据到明细页签
                    Sub_WriteInForm(combinedTable, 0);
                }
                else
                {
                    MessageBox.Show("未能加载选中的生产订单数据!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("加载订单数据失败:" + ex.Message);
            }
        }
    }
}