llj
16 小时以前 a91fdba94705dd25cecccc7a4a5dcc2b3f2c09a6
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
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
 
namespace DAL
{
    public  class ClsGy_RoutingBill:DBUtility.ClsXt_BaseBill
    {
        public Model.ClsGy_RoutingBillMain omodel = new Model.ClsGy_RoutingBillMain();
        public List<Model.ClsGy_RoutingBillSub> DetailColl = new List<Model.ClsGy_RoutingBillSub>();
 
        public ClsGy_RoutingBill()
        {
            base.MvarItemKeySub = "Gy_RoutingBillSub";
            base.MvarItemKeySub2 = "";
            base.MvarItemKeySub3 = "";
            base.MvarItemKeySub4 = "";
            base.MvarItemKey="Gy_RoutingBillMain";
            base.MvarReportTitle="工艺路线";
            base.BillType="3301"; 
        }
 
        #region 固定代码
 
        ~ClsGy_RoutingBill()
        {
            DetailColl = null;
        }
       
        #endregion   自定义方法
        //修改单据
        public override bool ModifyBill(Int64 lngBillKey, ref string sReturn)
        {
            try
            {
                //
                oCn.BeginTran();
                //更新主表
                oCn.RunProc("UpDate Gy_RoutingBillMain set  " +
                " HPRDORGID=" + omodel.HORGID.ToString() +
                ",HName='" + omodel.HName + "'" +
                ",HBillNo='" + omodel.HBillNo + "'" +
                ",HMaterTypeID=" + omodel.HMaterTypeID.ToString() +
                ",HMaterID=" + omodel.HMaterID.ToString() +
                ",HMaterNumber='" + omodel.HMaterNumber + "'" +
                ",HUnitID=" + omodel.HUnitID.ToString() +
                ",HUnitNumber='" + omodel.HUnitNumber + "'" +
                ",HRoutingGroupID=" + omodel.HRoutingGroupID.ToString() +
                ",HStandard=" + DBUtility.ClsPub.BoolToString(omodel.HStandard) +
                ",HDate='" + omodel.HDate + "'" +
                ",HYear=" + omodel.HYear.ToString() + "" +
                ",HPeriod=" + omodel.HPeriod.ToString() + "" +
                ",HRemark='" + omodel.HRemark + "'" +
                ",HUpDater='" + DBUtility.ClsPub.CurUserName + "'" +
                ",HUpDateDate=getdate()" +
 
                ",HMainGroupID=" + omodel.HMainGroupID.ToString() +
                ",HMainProcID=" + omodel.HMainProcID.ToString() +
                ",HMainCenterID=" + omodel.HMainCenterID.ToString() +
                ",HMainTimeUnit='" + omodel.HMainTimeUnit + "'" +
                ",HMainUnitTime=" + omodel.HMainUnitTime.ToString() +
                ",HMainWorkQty=" + omodel.HMainWorkQty.ToString() +
                ",HMainPrice=" + omodel.HMainPrice.ToString() +
                ",HStdSourceQty=" + omodel.HStdSourceQty.ToString() +
                ",HAddSourceRate=" + omodel.HAddSourceRate.ToString() +
                ",HDelSourceRate=" + omodel.HDelSourceRate.ToString() +
                ",HPicNumVer='" + omodel.HPicNumVer + "'" +
                ",HPicNumAssemble='" + omodel.HPicNumAssemble + "'" +
                ",HMaterTexture='" + omodel.HMaterTexture + "'" +
                ",HProductNum='" + omodel.HProductNum + "'" +
                ",HVerNum='" + omodel.HVerNum + "'" +
                ",HORGID=" + omodel.HORGID.ToString() +
 
                " where HInterID=" + lngBillKey.ToString());
                //删除关联
                DeleteRelation(ref sReturn, lngBillKey);
                //删除子表
                DeleteBillSub(lngBillKey);
                //插入子表
                omodel.HInterID = lngBillKey;
                foreach (Model.ClsGy_RoutingBillSub oSub in DetailColl)
                {
                    oCn.RunProc("Insert into Gy_RoutingBillSub " +
                      "(HInterID,HEntryID,HProcID,HProcNO,HSupID,HSupFlag" +
                      ",HWorkQty,HCenterID,HTimeUnit,HUnitTime" +
                      ",HReadyTime,HQueueTime,HMoveTime" +
                      ",HCloseMan,HCloseType,HRemark,HProcType,HNextProcFlag,HFlowProc" +
                      ",HFixPrice,HProcPrice,HBadPrice,HWasterPrice,HStdFlag,HBeginDayQty,HBeginFixQty"+
                      ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney,HAutoTrunFlag" +
                      ",HFixWorkDays,HTrunWorkDays,HReadyTimes,HICMOReadyTimes,HSubStdEmpQty,HSubCanUseSourceQty" +
                      ",HProcID_S,HCenterID_S,HWorkQty_S,HSubStdEmpQty_S,HMouldNo,HChangeMould" +
                      ",HPackStd,HPack,HPutArea,HMyWorkDays,HMyFixWorkDays,HPassRate" +
                      ",HTechnologyParameter,HPicNum,HProcCheckNote" +
                      ",HOverRate,HWorkTimes_S,HSNCtrl" +
                      ") values("
                      + omodel.HInterID.ToString() + "," + oSub.HEntryID.ToString() + "," + oSub.HProcID.ToString() + "," + oSub.HProcNo.ToString() + "," + oSub.HSupID.ToString() + "," + Convert.ToString(oSub.HSupFlag ? 1 : 0) + "" +
                      "," + oSub.HWorkQty.ToString() + "," + oSub.HCenterID.ToString() + ",'" + oSub.HTimeUnit.ToString() + "'," + oSub.HUnitTime.ToString() +
                      "," + oSub.HReadyTime.ToString() + "," + oSub.HQueueTime.ToString() + "," + oSub.HMoveTime.ToString() +
                      ",'" + oSub.HCloseMan + "'," + Convert.ToString(oSub.HCloseType ? 1 : 0) + ",'" + oSub.HRemark + "','" + oSub.HProcType + "'," + Convert.ToString(oSub.HNextProcFlag ? 1 : 0) + "," + Convert.ToString(oSub.HFlowProc ? 1 : 0) +
                      "," + oSub.HFixPrice.ToString() + "," + oSub.HProcPrice.ToString() + "," + oSub.HBadPrice.ToString() + "," + oSub.HWasterPrice.ToString() + "," + Convert.ToString(oSub.HStdFlag ? 1 : 0) + "," + oSub.HBeginDayQty.ToString() + "," + oSub.HBeginFixQty.ToString() +
                      "," + oSub.HSourceInterID.ToString() + "," + oSub.HSourceEntryID.ToString() + ",'" + oSub.HSourceBillNo + "','" + oSub.HSourceBillType + "'," + oSub.HRelationQty.ToString() + "," + oSub.HRelationMoney.ToString() + "," + Convert.ToString(oSub.HAutoTrunFlag ? 1 : 0) +
                     "," + oSub.HFixWorkDays.ToString() + "," + oSub.HTrunWorkDays.ToString() + "," + oSub.HReadyTimes.ToString() + "," + oSub.HICMOReadyTimes.ToString() + "," + oSub.HSubStdEmpQty.ToString() + "," + oSub.HSubCanUseSourceQty.ToString() +
                     "," + oSub.HProcID_S.ToString() + "," + oSub.HCenterID_S.ToString() + "," + oSub.HWorkQty_S.ToString() + "," + oSub.HSubStdEmpQty_S.ToString() + ",'" + oSub.HMouldNo + "'," + oSub.HChangeMould.ToString() +
                     ",'" + oSub.HPackStd + "','" + oSub.HPack + "','" + oSub.HPutArea + "'," + oSub.HMyWorkDays.ToString() + "," + oSub.HMyFixWorkDays.ToString() + "," + oSub.HPassRate.ToString() + 
                     ",'" + oSub.HTechnologyParameter.ToString() + "','" + oSub.HPicNum.ToString() + "','" + oSub.HProcCheckNote.ToString() +
                     "', " + oSub.HOverRate.ToString() + "," + oSub.HWorkTimes_S.ToString() + "," + Convert.ToString(oSub.HSNCtrl ? 1 : 0) +
                      ") ");
                }
                //
                oCn.RunProc("exec h_p_Gy_RoutingBillCheck " + omodel.HInterID.ToString() + ",'" + DBUtility.ClsPub.CurUserName + "'");  //设置默认工艺路线
                //oCn.RunProc("exec h_p_Sc_ProcessExchangeBillSetUpdate " + omodel.HInterID.ToString());  //设置首道末道 流转标记 等 字段。
                //
                //判断是否重复工序号
                DataSet ds = oCn.RunProcReturn("exec h_p_Gy_RoutingCtrl " + omodel.HInterID.ToString(), "h_p_Gy_RoutingCtrl");
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    sReturn = "判断重复工序号失败!";
                    oCn.RollBack();
                    return false;
                }
                else
                {
                    if (DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0][0]) == "2")
                    {
                        sReturn = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0][1]);
                        oCn.RollBack();
                        return false;
                    }
                }
                sReturn = "修改单据成功!";
                oCn.Commit();
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                oCn.RollBack();
                throw (e);
            }
        }
        //新增单据
        public override bool AddBill(ref string sReturn)
        {
            try
            {
                string orgid = DBUtility.ClsPub.HOrgID.ToString();
                //得到mainid
                omodel.HInterID = DBUtility.ClsPub.CreateBillID(BillType, ref DBUtility.ClsPub.sExeReturnInfo);
                //若MAINDI重复则重新获取
                oCn.BeginTran();
                //string BillType1 = this.BillType;
                //string HInterID = omodel.HInterID.ToString();
                //string HBillNo = omodel.HBillNo;
                //DateTime HDate = omodel.HDate;
                //string HYear = omodel.HYear.ToString();
                //string HPeriod = omodel.HPeriod.ToString();
                //string HRemark = omodel.HRemark;
                //string CurUserName = DBUtility.ClsPub.CurUserName;
                //string HMaterID = omodel.HMaterID.ToString();
                //string HName = omodel.HName;
                //string HMaterTypeID = omodel.HMaterTypeID.ToString();
                //string HRoutingGroupID = omodel.HRoutingGroupID.ToString();
                //string HUnitID = omodel.HUnitID.ToString();
                //string HMaterNumber = omodel.HMaterNumber;
                //string HUnitNumber = omodel.HUnitNumber;
                //string HStandard = DBUtility.ClsPub.BoolToString(omodel.HStandard);
                //string HMainGroupID = omodel.HMainGroupID.ToString();
                //string HMainProcID = omodel.HMainProcID.ToString();
                //string HMainCenterID = omodel.HMainCenterID.ToString();
                //string HMainTimeUnit = omodel.HMainTimeUnit;
                //string HMainUnitTime = omodel.HMainUnitTime.ToString();
                //string HMainWorkQty = omodel.HMainWorkQty.ToString();
                //string HMainPrice = omodel.HMainPrice.ToString();
                //string HStdSourceQty = omodel.HStdSourceQty.ToString();
                //string HAddSourceRate = omodel.HAddSourceRate.ToString();
                //string HDelSourceRate = omodel.HDelSourceRate.ToString();
                //string HPicNumVer = omodel.HPicNumVer.ToString();
                //string HPicNumAssemble = omodel.HPicNumAssemble.ToString();
                //string HMaterTexture = omodel.HMaterTexture.ToString();
                //string HProductNum = omodel.HProductNum.ToString();
                //string HVerNum = omodel.HVerNum.ToString();
                //主表
                //oCn.RunProc("Insert Into Gy_RoutingBillMain   " +
                //"(HBillType,HInterID,HBillNo,HDate" +
                //",HYear,HPeriod,HRemark,HMaker,Hmakedate,HMaterID,HName,HMaterTypeID" +
                //",HRoutingGroupID,HUnitID,HMaterNumber,HUnitNumber,HStandard" +
                //",HMainGroupID,HMainProcID,HMainCenterID,HMainTimeUnit,HMainUnitTime,HMainWorkQty" +
                //",HMainPrice,HStdSourceQty,HAddSourceRate,HDelSourceRate" +
                //",HPicNumVer,HPicNumAssemble,HMaterTexture,HProductNum,HPRDORGID,HVerNum" +
                //") " +
                //" values('" + this.BillType + "'," + omodel.HInterID.ToString() + ",'" + omodel.HBillNo + "','" + omodel.HDate + "'" +
                //"," + omodel.HYear.ToString() + "," + omodel.HPeriod.ToString() + ",'" + omodel.HRemark + "','" + DBUtility.ClsPub.CurUserName + "',getdate()," + omodel.HMaterID.ToString() + ",'" + omodel.HName + "'," + omodel.HMaterTypeID.ToString() +
                //",'" + omodel.HRoutingGroupID.ToString() + "'," + omodel.HUnitID.ToString() + ",'" + omodel.HMaterNumber + "','" + omodel.HUnitNumber + "'," + DBUtility.ClsPub.BoolToString(omodel.HStandard) +
                //"," + omodel.HMainGroupID.ToString() + "," + omodel.HMainProcID.ToString() + "," + omodel.HMainCenterID.ToString() + ",'" + omodel.HMainTimeUnit + "'," + omodel.HMainUnitTime.ToString() + "," + omodel.HMainWorkQty.ToString() +
                //"," + omodel.HMainPrice.ToString() + "," + omodel.HStdSourceQty.ToString() + "," + omodel.HAddSourceRate + "," + omodel.HDelSourceRate.ToString() +
                //",'" + omodel.HPicNumVer.ToString() + "','" + omodel.HPicNumAssemble.ToString() + "','" + omodel.HMaterTexture.ToString() + "','" + omodel.HProductNum.ToString() + "','"+omodel.HPRDORGID.ToString()+"','" + omodel.HVerNum.ToString() + "'"+
                //") ");
 
                oCn.RunProc("Insert Into Gy_RoutingBillMain   " +
                "(HBillType,HInterID,HBillNo,HDate" +
                ",HYear,HPeriod,HRemark,HMaker,Hmakedate,HMaterID,HName,HMaterTypeID" +
                ",HRoutingGroupID,HUnitID,HMaterNumber,HUnitNumber,HStandard" +
                ",HMainGroupID,HMainProcID,HMainCenterID,HMainTimeUnit,HMainUnitTime,HMainWorkQty" +
                ",HMainPrice,HStdSourceQty,HAddSourceRate,HDelSourceRate" +
                ",HPicNumVer,HPicNumAssemble,HMaterTexture,HProductNum,HPRDORGID,HORGID,HVerNum" +
                ") " +
                " values('" + this.BillType + "'," + omodel.HInterID.ToString() + ",'" + omodel.HBillNo + "','" + omodel.HDate + "'" +
                "," + omodel.HYear.ToString() + "," + omodel.HPeriod.ToString() + ",'" + omodel.HRemark + "','" + DBUtility.ClsPub.CurUserName + "',getdate()," + omodel.HMaterID.ToString() + ",'" + omodel.HName + "'," + omodel.HMaterTypeID.ToString() +
                ",'" + omodel.HRoutingGroupID.ToString() + "'," + omodel.HUnitID.ToString() + ",'" + omodel.HMaterNumber + "','" + omodel.HUnitNumber + "'," + DBUtility.ClsPub.BoolToString(omodel.HStandard) +
                "," + omodel.HMainGroupID.ToString() + "," + omodel.HMainProcID.ToString() + "," + omodel.HMainCenterID.ToString() + ",'" + omodel.HMainTimeUnit + "'," + omodel.HMainUnitTime.ToString() + "," + omodel.HMainWorkQty.ToString() +
                "," + omodel.HMainPrice.ToString() + "," + omodel.HStdSourceQty.ToString() + "," + omodel.HAddSourceRate + "," + omodel.HDelSourceRate.ToString() +
                ",'" + omodel.HPicNumVer + "','" + omodel.HPicNumAssemble + "','" + omodel.HMaterTexture + "','" + omodel.HProductNum + "'," + omodel.HORGID.ToString() + "," + omodel.HORGID.ToString() + ",'" + omodel.HVerNum + "'" +
                ") ");
                //插入子表
                foreach (Model.ClsGy_RoutingBillSub oSub in DetailColl)
                {
                    oCn.RunProc("Insert into Gy_RoutingBillSub " +
                      "(HInterID,HEntryID,HProcID,HProcNO,HSupID,HSupFlag" +
                      ",HWorkQty,HCenterID,HTimeUnit,HUnitTime" +
                      ",HReadyTime,HQueueTime,HMoveTime" +
                      ",HCloseMan,HCloseType,HRemark,HProcType,HNextProcFlag,HFlowProc" +
                      ",HFixPrice,HProcPrice,HBadPrice,HWasterPrice,HStdFlag,HBeginDayQty,HBeginFixQty" +
                      ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney,HAutoTrunFlag" +
                      ",HFixWorkDays,HTrunWorkDays,HReadyTimes,HICMOReadyTimes,HSubStdEmpQty,HSubCanUseSourceQty" +
                      ",HProcID_S,HCenterID_S,HWorkQty_S,HSubStdEmpQty_S,HMouldNo,HChangeMould" +
                      ",HPackStd,HPack,HPutArea,HMyWorkDays,HMyFixWorkDays,HPassRate" +
                      ",HTechnologyParameter,HPicNum,HProcCheckNote" +
                      ",HOverRate,HProcWorkNum,HWorkTimes_S,HSNCtrl" +
                      ") values("
                      + omodel.HInterID.ToString() + "," + oSub.HEntryID.ToString() + "," + oSub.HProcID.ToString() + "," + oSub.HProcNo.ToString() + "," + oSub.HSupID.ToString() + "," + Convert.ToString(oSub.HSupFlag ? 1 : 0) + "" +
                      "," + oSub.HWorkQty.ToString() + "," + oSub.HCenterID.ToString() + ",'" + oSub.HTimeUnit.ToString() + "'," + oSub.HUnitTime.ToString() +
                      "," + oSub.HReadyTime.ToString() + "," + oSub.HQueueTime.ToString() + "," + oSub.HMoveTime.ToString() +
                      ",'" + oSub.HCloseMan + "'," + Convert.ToString(oSub.HCloseType ? 1 : 0) + ",'" + oSub.HRemark + "','" + oSub.HProcType + "'," + Convert.ToString(oSub.HNextProcFlag ? 1 : 0) + "," + Convert.ToString(oSub.HFlowProc ? 1 : 0) +
                      "," + oSub.HFixPrice.ToString() + "," + oSub.HProcPrice.ToString() + "," + oSub.HBadPrice.ToString() + "," + oSub.HWasterPrice.ToString() + "," + Convert.ToString(oSub.HStdFlag ? 1 : 0) + "," + oSub.HBeginDayQty.ToString() + "," + oSub.HBeginFixQty.ToString() +
                      "," + oSub.HSourceInterID.ToString() + "," + oSub.HSourceEntryID.ToString() + ",'" + oSub.HSourceBillNo + "','" + oSub.HSourceBillType + "'," + oSub.HRelationQty.ToString() + "," + oSub.HRelationMoney.ToString() + "," + Convert.ToString(oSub.HAutoTrunFlag ? 1 : 0) +
                     "," + oSub.HFixWorkDays.ToString() + "," + oSub.HTrunWorkDays.ToString() + "," + oSub.HReadyTimes.ToString() + "," + oSub.HICMOReadyTimes.ToString() + "," + oSub.HSubStdEmpQty.ToString() + "," + oSub.HSubCanUseSourceQty.ToString() +
                     "," + oSub.HProcID_S.ToString() + "," + oSub.HCenterID_S.ToString() + "," + oSub.HWorkQty_S.ToString() + ", " + oSub.HSubStdEmpQty_S.ToString() + ",'" + oSub.HMouldNo + "'," + oSub.HChangeMould.ToString() +
                     ",'" + oSub.HPackStd + "','" + oSub.HPack + "','" + oSub.HPutArea + "'," + oSub.HMyWorkDays.ToString() + "," + oSub.HMyFixWorkDays.ToString() + "," + oSub.HPassRate.ToString() +
                     ",'"+ oSub.HTechnologyParameter.ToString() + "','" + oSub.HPicNum.ToString() + "','" + oSub.HProcCheckNote.ToString() +
                     "', " + oSub.HOverRate.ToString() + ",'" + oSub.HProcWorkNum.ToString() + "'," + oSub.HWorkTimes_S.ToString() + "," + Convert.ToString(oSub.HSNCtrl ? 1 : 0) +
                      ") ");
                }
                //
                oCn.RunProc("exec h_p_Gy_RoutingBillCheck " + omodel.HInterID.ToString() + ",'" + DBUtility.ClsPub.CurUserName + "'");  //设置默认工艺路线
                //oCn.RunProc("exec h_p_Sc_ProcessExchangeBillSetUpdate " + omodel.HInterID.ToString());  //设置首道末道 流转标记 等 字段。
                //
                //判断是否重复工序号
                DataSet ds = oCn.RunProcReturn("exec h_p_Gy_RoutingCtrl " + omodel.HInterID.ToString(), "h_p_Gy_RoutingCtrl");
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    sReturn = "判断重复工序号失败!";
                    oCn.RollBack();
                    return false;
                }
                else
                {
                    if (DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0][0]) == "2")
                    {
                        sReturn = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0][1]);
                        oCn.RollBack();
                        return false;
                    }
                }
                sReturn = "新增单据成功!";
                oCn.Commit();
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                oCn.RollBack();
                throw (e);
            }
        }
        //显示单据
        public override bool ShowBill(Int64 lngBillKey, ref string sReturn)
        {
            try
            {
                //查询主表
                DataSet Ds ;
                Ds = oCn.RunProcReturn("Select * from Gy_RoutingBillMain Where HInterID=" + lngBillKey.ToString(), "Gy_RoutingBillMain");
                if(Ds.Tables[0].Rows.Count==0)
                {
                    sReturn = "单据未找到!";
                    return false;
                }
                //赋值
                omodel.HInterID =DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HInterID"].ToString());
                omodel.HBillStatus = DBUtility.ClsPub.isInt(Ds.Tables[0].Rows[0]["HBillStatus"].ToString());
 
                omodel.HBillNo = Ds.Tables[0].Rows[0]["HBillNo"].ToString().Trim();
                omodel.HName = Ds.Tables[0].Rows[0]["HName"].ToString().Trim();
                omodel.HDate = Convert.ToDateTime(Ds.Tables[0].Rows[0]["HDate"].ToString().Trim());
                omodel.HYear = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HYear"].ToString());
                omodel.HPeriod = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HPeriod"].ToString());
                omodel.HRemark = Ds.Tables[0].Rows[0]["HRemark"].ToString().Trim();
 
                omodel.HUseFlag = DBUtility.ClsPub.GridToBool(Ds.Tables[0].Rows[0]["HUseFlag"]);
                omodel.HStandard = DBUtility.ClsPub.GridToBool(Ds.Tables[0].Rows[0]["HStandard"]);
                omodel.HMaterNumber = Ds.Tables[0].Rows[0]["HMaterNumber"].ToString().Trim();
                omodel.HUnitNumber = Ds.Tables[0].Rows[0]["HUnitNumber"].ToString().Trim();
                omodel.HMaterTypeID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HMaterTypeID"].ToString());
                omodel.HMaterID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HMaterID"].ToString());
                omodel.HUnitID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HUnitID"].ToString());
                omodel.HRoutingGroupID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HRoutingGroupID"].ToString());
                omodel.HMainGroupID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HMainGroupID"].ToString());
                //
                omodel.HMaker = Ds.Tables[0].Rows[0]["HMaker"].ToString().Trim();
                omodel.HMakeDate = Ds.Tables[0].Rows[0]["HMakeDate"].ToString().Trim();
                omodel.HBackDate = Ds.Tables[0].Rows[0]["HBackDate"].ToString().Trim();
                omodel.HBacker = Ds.Tables[0].Rows[0]["HBacker"].ToString().Trim();
                omodel.HUpDateDate = Ds.Tables[0].Rows[0]["HUpDateDate"].ToString().Trim();
                omodel.HUpDater = Ds.Tables[0].Rows[0]["HUpDater"].ToString().Trim();
                omodel.HCheckDate = Ds.Tables[0].Rows[0]["HCheckDate"].ToString().Trim();
                omodel.HChecker = Ds.Tables[0].Rows[0]["HChecker"].ToString().Trim();
                omodel.HCloseDate = Ds.Tables[0].Rows[0]["HCloseDate"].ToString().Trim();
                omodel.HCloseMan = Ds.Tables[0].Rows[0]["HCloseMan"].ToString().Trim();
                omodel.HDeleteDate = Ds.Tables[0].Rows[0]["HDeleteDate"].ToString().Trim();
                omodel.HDeleteMan = Ds.Tables[0].Rows[0]["HDeleteMan"].ToString().Trim();
                omodel.HUseDate = DBUtility.ClsPub.isDate(Ds.Tables[0].Rows[0]["HUseDate"]);
                omodel.HUseMan = Ds.Tables[0].Rows[0]["HUseMan"].ToString().Trim();
 
                omodel.HMainProcID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HMainProcID"].ToString());
                omodel.HMainCenterID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HMainCenterID"].ToString());
                omodel.HMainTimeUnit = Ds.Tables[0].Rows[0]["HMainTimeUnit"].ToString().Trim();
                omodel.HMainUnitTime = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HMainUnitTime"].ToString());
                omodel.HMainWorkQty = DBUtility.ClsPub.isSingle(Ds.Tables[0].Rows[0]["HMainWorkQty"].ToString());
                omodel.HMainPrice = DBUtility.ClsPub.isSingle(Ds.Tables[0].Rows[0]["HMainPrice"].ToString());
                omodel.HStdSourceQty = DBUtility.ClsPub.isSingle(Ds.Tables[0].Rows[0]["HStdSourceQty"].ToString());
                omodel.HAddSourceRate = DBUtility.ClsPub.isSingle(Ds.Tables[0].Rows[0]["HAddSourceRate"].ToString());
                omodel.HDelSourceRate = DBUtility.ClsPub.isSingle(Ds.Tables[0].Rows[0]["HDelSourceRate"].ToString());
                omodel.HPicNumVer = Ds.Tables[0].Rows[0]["HPicNumVer"].ToString().Trim();
                omodel.HPicNumAssemble = Ds.Tables[0].Rows[0]["HPicNumAssemble"].ToString().Trim();
                omodel.HMaterTexture = Ds.Tables[0].Rows[0]["HMaterTexture"].ToString().Trim();
                omodel.HProductNum = Ds.Tables[0].Rows[0]["HProductNum"].ToString().Trim();
                omodel.HVerNum = Ds.Tables[0].Rows[0]["HVerNum"].ToString().Trim();
                omodel.HPRDORGID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HPRDORGID"].ToString());
                omodel.HORGID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HORGID"].ToString());
                //循环
                DataSet DsSub ;
                DsSub = oCn.RunProcReturn("Select * from Gy_RoutingBillSub Where HInterID=" + lngBillKey.ToString() + " Order by HEntryID ", "Gy_RoutingBillSub");
                DetailColl.Clear();//清空
                for (int i = 0; i < DsSub.Tables[0].Rows.Count; i++)
                {
                    Model.ClsGy_RoutingBillSub oSub = new Model.ClsGy_RoutingBillSub();
                    oSub.HInterID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HInterID"]);
                    oSub.HEntryID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HEntryID"]);
                    //
                    oSub.HProcID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HProcID"]);
                    oSub.HCenterID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HCenterID"]);
                    oSub.HProcNo = DBUtility.ClsPub.isInt(DsSub.Tables[0].Rows[i]["HProcNo"]);
                    oSub.HUnitTime = DBUtility.ClsPub.isInt(DsSub.Tables[0].Rows[i]["HUnitTime"]);
                    oSub.HWorkQty = DBUtility.ClsPub.isSingle(DsSub.Tables[0].Rows[i]["HWorkQty"]);
                    oSub.HRemark = DsSub.Tables[0].Rows[i]["HRemark"].ToString().Trim();
                    oSub.HTimeUnit = DsSub.Tables[0].Rows[i]["HTimeUnit"].ToString().Trim();
                    oSub.HReadyTime = DBUtility.ClsPub.isSingle(DsSub.Tables[0].Rows[i]["HReadyTime"]);
                    oSub.HQueueTime = DBUtility.ClsPub.isSingle(DsSub.Tables[0].Rows[i]["HQueueTime"]);
                    oSub.HMoveTime = DBUtility.ClsPub.isSingle(DsSub.Tables[0].Rows[i]["HMoveTime"]);
                    //
                    oSub.HProcID_S = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HProcID_S"]);
                    oSub.HCenterID_S = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HCenterID_S"]);
                    oSub.HMouldNo = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["HMouldNo"]);
                    oSub.HPackStd = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["HPackStd"]);
                    oSub.HPack = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["HPack"]);
                    oSub.HPutArea = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["HPutArea"]);
 
                    oSub.HWorkQty_S = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["HWorkQty_S"]);
                    oSub.HSubStdEmpQty_S = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["HSubStdEmpQty_S"]);
                    oSub.HChangeMould = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["HChangeMould"]);
                    oSub.HMyWorkDays = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["HMyWorkDays"]);
                    oSub.HMyFixWorkDays = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["HMyFixWorkDays"]);
                    //
                    oSub.HCloseMan = DsSub.Tables[0].Rows[i]["HCloseMan"].ToString().Trim();
                    oSub.HCloseType =DBUtility.ClsPub.isBool( DsSub.Tables[0].Rows[i]["HCloseType"]);
                    oSub.HSourceInterID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HSourceInterID"]);
                    oSub.HSourceEntryID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HSourceEntryID"]);
                    oSub.HSourceBillType = DsSub.Tables[0].Rows[i]["HSourceBillType"].ToString().Trim();
                    oSub.HSourceBillNo = DsSub.Tables[0].Rows[i]["HSourceBillNo"].ToString().Trim();
                    oSub.HRelationQty = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["HRelationQty"]);
                    oSub.HRelationMoney = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["HRelationMoney"]);
 
                    oSub.HFixPrice = DBUtility.ClsPub.isSingle(DsSub.Tables[0].Rows[i]["HFixPrice"]);
                    oSub.HProcPrice = DBUtility.ClsPub.isSingle(DsSub.Tables[0].Rows[i]["HProcPrice"]);
                    oSub.HBadPrice = DBUtility.ClsPub.isSingle(DsSub.Tables[0].Rows[i]["HBadPrice"]);
                    oSub.HWasterPrice = DBUtility.ClsPub.isSingle(DsSub.Tables[0].Rows[i]["HWasterPrice"]);
                    oSub.HStdFlag = DBUtility.ClsPub.isBool(DsSub.Tables[0].Rows[i]["HStdFlag"]);
                    oSub.HBeginDayQty = DBUtility.ClsPub.isSingle(DsSub.Tables[0].Rows[i]["HBeginDayQty"]);
                    oSub.HBeginFixQty = DBUtility.ClsPub.isSingle(DsSub.Tables[0].Rows[i]["HBeginFixQty"]);
                    oSub.HAutoTrunFlag = DBUtility.ClsPub.isBool(DsSub.Tables[0].Rows[i]["HAutoTrunFlag"]);
                    oSub.HFixWorkDays = DBUtility.ClsPub.isSingle(DsSub.Tables[0].Rows[i]["HFixWorkDays"]);
                    oSub.HTrunWorkDays = DBUtility.ClsPub.isSingle(DsSub.Tables[0].Rows[i]["HTrunWorkDays"]);
                    oSub.HReadyTimes = DBUtility.ClsPub.isSingle(DsSub.Tables[0].Rows[i]["HReadyTimes"]);
                    oSub.HICMOReadyTimes = DBUtility.ClsPub.isSingle(DsSub.Tables[0].Rows[i]["HICMOReadyTimes"]);
 
                    oSub.HSubStdEmpQty = DBUtility.ClsPub.isSingle(DsSub.Tables[0].Rows[i]["HSubStdEmpQty"]);
                    oSub.HSubCanUseSourceQty = DBUtility.ClsPub.isSingle(DsSub.Tables[0].Rows[i]["HSubCanUseSourceQty"]);
                    oSub.HProcType = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["HProcType"]);
                    oSub.HPassRate = DBUtility.ClsPub.isSingle(DsSub.Tables[0].Rows[i]["HPassRate"]);
                    oSub.HSumPassRate = DBUtility.ClsPub.isSingle(DsSub.Tables[0].Rows[i]["HSumPassRate"]);
                    oSub.HSupID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HSupID"]);
                    oSub.HSupFlag = DBUtility.ClsPub.isBool(DsSub.Tables[0].Rows[i]["HSupFlag"]);
                    oSub.HNextProcFlag = DBUtility.ClsPub.isBool(DsSub.Tables[0].Rows[i]["HNextProcFlag"]);
                    oSub.HFlowProc = DBUtility.ClsPub.isBool(DsSub.Tables[0].Rows[i]["HFlowProc"]);
                    oSub.HTechnologyParameter = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["HTechnologyParameter"]);
                    oSub.HPicNum = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["HPicNum"]);
                    oSub.HProcCheckNote = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["HProcCheckNote"]);
                    oSub.HOverRate = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["HOverRate"]);
                    oSub.HWorkTimes_S = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["HWorkTimes_S"]);
                    oSub.HSNCtrl = DBUtility.ClsPub.isBool(DsSub.Tables[0].Rows[i]["HSNCtrl"]);
                    DetailColl.Add(oSub);
                }
                sReturn = "显示单据成功!";
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                throw (e);
            }
        }
 
        //驳回
        public override bool RejectCheckFlowProgress(Int64 lngBillKey, string HBillNo, string sUser, ref string sReturn)
        {
 
            if (isUse(lngBillKey, ref sReturn))
            {
                return false;
            }
            try
            {
                //开启事务
                oCn.BeginTran();
 
                //判断是否存在审核过的项目
                //string sql0 = "select * from Xt_BillCheckFlowStatus where HBillInterID = " + lngBillKey + " and HBillTypeID = '" + this.BillType + "' and ISNULL(HChecker,'') <> ''";
                //DataSet ds0 = oCn.RunProcReturn(sql0, "Xt_BillCheckFlowStatus");
                //if (ds0 != null && ds0.Tables[0].Rows.Count == 0)
                //{
                //    sReturn = "单据不存在已经审核的项目!";
                //    return false;
                //}
 
                //获取需要驳回的审核项目
                string sql0 = "select c.* from Xt_CheckFlowMain as a " +
                              "inner join Xt_CheckFlowSub as b on a.HInterID = b.HInterID " +
                              "inner join Xt_BillCheckFlowStatus as c on a.HBillTypeID = c.HBillTypeID and b.HCheckItemID = c.HCheckItemID " +
                              "where c.HBillTypeID = '" + this.BillType + "' and c.HBillInterID = " + lngBillKey + " " +
                              "order by b.HFlowNo asc";
                DataSet ds0 = oCn.RunProcReturn(sql0, "Xt_BillCheckFlowStatus");
                if (ds0 == null || ds0.Tables[0].Rows.Count == 0)
                {
                    sReturn = "驳回失败!原因:未发起审批!!";
                    return false;
                }
                //获取当前审核项目
                string HCheckFlowID = ds0.Tables[0].Rows[0]["HCheckFlowID"].ToString();             //审批流内码
                sql0 = "select * from " + MvarItemKey + " where HInterID = " + lngBillKey;
                ds0 = oCn.RunProcReturn(sql0, MvarItemKey);
                string HCheckItemNowID = ds0.Tables[0].Rows[0]["HCheckItemNowID"].ToString();       //当前审批项目内码
                //查找是否有权限
                string sql01 = "select * from Xt_CheckUserRight where HUserID = '" + sUser + "' and HCheckFlowInterID = " + HCheckFlowID + " and HCheckItemID = " + HCheckItemNowID + "";
                DataSet ds01 = oCn.RunProcReturn(sql01, "Xt_CheckUserRight");
                //获取用户名称
                DataSet DsUser = new DataSet();
                DsUser = oCn.RunProcReturn("select * from gy_czygl where czybm='" + sUser.Trim() + "'", "gy_czygl");
                if(DsUser.Tables[0].Rows.Count == 0)
                {
                    sReturn = "无法找到该用户!";
                    return false;
                }
                string userName = DsUser.Tables[0].Rows[0]["czymc"].ToString();
 
                if (ds01.Tables[0].Rows.Count == 0 && !DBUtility.ClsPub.Security_Log_second("Gy_RoutingBill_Check", 1, false, userName))//单据原审核权限为多级审核驳回权限
                {
                    sReturn = "无权限!";
                    return false;
                }
                //更新 驳回删除审核流状态表
                string sql02 = "Delete Xt_BillCheckFlowStatus where HBillTypeID = '" + this.BillType + "' and HBillInterID=" + lngBillKey + " and HCheckFlowID=" + HCheckFlowID;
                oCn.RunProc(sql02);
                oCn.RunProc(" Update " + MvarItemKey + " set HChecker='',HCheckDate=null,HBillStatus=5,HCheckItemNowID = 0,HCheckItemNextID = 0 Where HInterID=" + lngBillKey.ToString());
 
                //写入日志
                string WorkList = "驳回单据,单据号:" + HBillNo;
                string SystemName = "LMES-" + MvarReportTitle + "模块";
                oCn.RunProc("Insert into  System_Log(GeginDate,userid,WorkstationName,WorkList,SystemName,NetUserName,State) values " +
                    "(getdate(),'" + sUser + "','" + "111" + "','" + WorkList + "','" + SystemName + "','" + "1111" + "','驳回')"
                    );
 
                sReturn = "反审核单据成功!";
                oCn.Commit();
                return true;
            }
            catch (Exception e)
            {
                oCn.RollBack();
                sReturn = e.Message;
                throw (e);
            }
        }
 
 
        //启用工艺路线
        public bool Sub_RoutingCheckAndUsed(Int64 HInterID)
        {
            try
            {
                string HChecker = DBUtility.ClsPub.CurUserName;
                oCn.RunProc("EXEC h_p_Gy_RoutingCheckAndUsed " + HInterID.ToString() + ",'" + HChecker + "'");
                return true;
            }
            catch (Exception e)
            {
                throw (e);
            }
        }
 
        //反启用工艺路线
        public bool Sub_RoutingUsed_Back(Int64 HInterID)
        {
            try
            {
                oCn.RunProc("EXEC h_p_Gy_RoutingUsed_Back " + HInterID.ToString());
                return true;
            }
            catch (Exception e)
            {
                throw (e);
            }
        }
 
        //产品是否已存在工艺路线
        public bool IsExistRouting(Int64 HMaterID)
        {
            DataSet Ds = new DataSet();
            Ds = oCn.RunProcReturn("select * from Gy_RoutingBillMain where hmaterid=" + HMaterID, "Gy_RoutingBillMain");
            if (Ds.Tables[0].Rows.Count > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
 
        //根据产品内码 删除工艺
        public bool DeleteByMaterID(Int64 HMaterID)
        {
            try
            {
                oCn.RunProc("Delete from Gy_RoutingBillMain where HMaterID=" + HMaterID.ToString());
                return true;
            }
            catch (Exception e)
            {
                return false;
            }
        }
    }
 
}