yangle
2023-05-24 b129762a4bb5ec2cde5edf16bc9cbda57c73587d
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
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
 
namespace DAL
{
    public  class ClsSc_PPBomChange_K3:DBUtility.ClsXt_BaseBill
    {
        public Model.ClsSc_PPBomChangeMain_K3 omodel = new Model.ClsSc_PPBomChangeMain_K3();
        public List<Model.ClsSc_PPBomChangeSub_K3> DetailColl = new List<Model.ClsSc_PPBomChangeSub_K3>();
 
        public ClsSc_PPBomChange_K3()
        {
            base.MvarItemKeySub = "PPBomChangeEntry";
            base.MvarItemKeySub2 = "";
            base.MvarItemKeySub3 = "";
            base.MvarItemKeySub4 = "";
            base.MvarItemKey="PPBomChange";
            base.MvarReportTitle="生产投料变更单";
            base.BillType = "1002502"; 
        }
 
        #region 固定代码
 
        ~ClsSc_PPBomChange_K3()
        {
            DetailColl = null;
        }
       
        #endregion   自定义方法
        //修改单据
        public override bool ModifyBill(Int64 lngBillKey, ref string sReturn)
        {
            try
            {
                //得到用户ID
                DataSet DsBiller;
                DsBiller = oK3Cn.RunProcReturn("select top 1 fuserid from t_User where fname='" + DBUtility.ClsPub.CurUserName + "'", "t_User");
                if (DsBiller.Tables[0].Rows.Count != 0)
                {
                    omodel.FBillerID = DBUtility.ClsPub.isLong(DsBiller.Tables[0].Rows[0][0]);
                }
                else
                {
                    omodel.FBillerID = 16394;
                }
                omodel.HBillType = this.BillType;
                //
                //DataSet Ds1;
                oCnK3.BeginTran();
                omodel.HInterID = lngBillKey;
                //删除主表
                DeleteBill(lngBillKey, ref sReturn);
                //oCnK3.RunProc("Delete From PPBomChange  where FInterID=" + lngBillKey.ToString());
                //
                //插入子表
                foreach (Model.ClsSc_PPBomChangeSub_K3 oSub in DetailColl)
                {
                    oCnK3.RunProc("INSERT INTO PPBomChangeEntry (" +
                      "FID,FIndex,FICMOInterID,FICMOInterBN,FProductItemID" +
                      ",FUnitID,FAuxQty,FPPBomBillNo,FPPBomEntryID,FChangeFlag" +
                      ",FChangeReason,FItemID,FBomInterID,FMaterielType,FAuxQtyScrap" +
                      ",FItemUnitID,FBOMInPutAuxQTY,FScrap,FAuxQtyLoss,FAuxQtyPick" +
                      ",FAuxQtyMust,FSendItemDate,FStockID,FSPID,FBatchNo,FBackFlush" +
                      ",FOperSN,FOperID,FMachinePos,FAuxStockQty,FPPBOMInterID" +
                      ",FDiscardAuxQty,FLockFlag,FAuxQtySupply,FChangerID,FChangeDate" +
                      ",FMark,FQty,FQtyScrap,FBOMInPutQTY,FQtyLoss,FQtyPick" +
                      ",FQtyMust,FStockQty,FDiscardQty,FQtySupply,FClassID_SRC" +
                      ",FPositionNo,FItemSize,FItemSuite,FNote1,FNote2,FNote3,FPlanMode" +
                        //",FMTONo,FOrderEntryID,FIsRepItem,FICSubsID"+
                        //",FICSubsEntryID,FIsKeyItem,FPriorityID"+
                  ") Values (" +
                  omodel.HInterID.ToString() + "," + oSub.HEntryID.ToString() + "," + oSub.FICMOInterID.ToString() + ",'" + oSub.FICMOInterBN + "'," + oSub.FProductItemID.ToString() +
                  "," + oSub.FProductUnitID.ToString() + "," + oSub.FAuxQty.ToString() + ",'" + oSub.FPPBomBillNo.ToString() + "'," + oSub.FPPBomEntryID.ToString() + ",'" + oSub.FChangeFlag.ToString() +
                  "',''," + oSub.FItemID.ToString() + "," + oSub.FBomInterID.ToString() + ",'" + oSub.FMaterielType.ToString() + "'," + oSub.FQtyScrap.ToString() +
                  "," + oSub.FUnitID.ToString() + "," + oSub.FBOMInPutAuxQTY.ToString() + ",0,0," + oSub.FAuxQtyPick.ToString() +
                  "," + oSub.FAuxQtyMust.ToString() + ",'" + oSub.FSendItemDate.ToShortDateString() + "'," + oSub.FStockID.ToString() + ",0,'" + oSub.FBatchNo + "',1059" +
                  ",0,0,''," + oSub.FAuxStockQty.ToString() + "," + oSub.FPPBomInterID.ToString() +
                  "," + oSub.FDisCardAuxQty.ToString() + ",'0',0,0,null" +
                  ",''," + oSub.FAuxQty.ToString() + "," + oSub.FQtyScrap.ToString() + "," + oSub.FBOMInPutAuxQTY.ToString() + ",0," + oSub.FAuxQtyPick.ToString() +
                  "," + oSub.FAuxQtyMust.ToString() + "," + oSub.FAuxStockQty.ToString() + "," + oSub.FDisCardAuxQty.ToString() + ",0,-88" +
                  ",'','','','','','',14036" +
                  ")");
 
                    //oCnK3.RunProc("update ICMO set FcommitQty=FcommitQty+" + oSub.Fauxqty + ",FAuxcommitQty=FAuxcommitQty+" + oSub.Fauxqty + " where Finterid=" + oSub.FICMOInterID);
                }
                //主表
                oCnK3.RunProc("INSERT INTO PPBomChange(" +
                    "FID,FClassTypeID,FDate,FBillNo,FBillerID" +
                    ",FCheckDate,FCheckFlag,FCheckerID,FBillType,FCheckDateLong" +
                    ") Values (" +
                    omodel.HInterID.ToString() + "," + omodel.HBillType + ",'" + omodel.HDate.ToShortDateString() + "','" + omodel.HBillNo + "'," + omodel.FBillerID.ToString() +
                    ",null,'0',0,1059,null" +
                     ")");
 
                //更新关联数量
                //更新K3关联数量
                //oCnK3.RunProc("EXEC p_UpdateBillRelateData " + this.BillType + "," + omodel.HInterID.ToString() + ",'PPBomChange','PPBomChangeEntry'");
                //oCnK3.RunProc("EXEC h_p_K3_UpdateBillRelateData_ProdIn_New " + omodel.HInterID.ToString() + "," + omodel.HBillerID.ToString());
                sReturn = "修改单据成功!";
                oCnK3.Commit();
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                oCnK3.RollBack();
                throw (e);
            }
        }
        //新增单据
        public override bool AddBill(ref string sReturn)
        {
            try
            {
                //得到用户ID
                DataSet DsBiller;
                //string HSourceBillType = "";
                DsBiller = oK3Cn.RunProcReturn("select top 1 fuserid from t_User where fname='" + DBUtility.ClsPub.CurUserName + "'", "t_User");
 
                if (DsBiller.Tables[0].Rows.Count != 0)
                {
                    omodel.FBillerID = DBUtility.ClsPub.isLong(DsBiller.Tables[0].Rows[0][0]);
                }
                else
                {
                    omodel.FBillerID = 16394;
                }
                omodel.HBillType = this.BillType;
                //
                DataSet Ds1;
                //得到mainid
                Ds1 = oCnK3.RunProcReturn("declare @InterID int set @InterID=0 exec GetICMaxNumOld  'PPBomChange',@InterID output select ltrim(@InterID)", "xt_xtgnb");
                if (Ds1.Tables[0].Rows.Count != 0)
                {
                    omodel.HInterID = DBUtility.ClsPub.isLong(Ds1.Tables[0].Rows[0][0]);
 
                }
                //若MAINDI重复则重新获取
                oCnK3.BeginTran();
 
                //插入子表
                foreach (Model.ClsSc_PPBomChangeSub_K3 oSub in DetailColl)
                {
                    oCnK3.RunProc("INSERT INTO PPBomChangeEntry (" +
                      "FID,FIndex,FICMOInterID,FICMOInterBN,FProductItemID" +
                      ",FUnitID,FAuxQty,FPPBomBillNo,FPPBomEntryID,FChangeFlag" +
                      ",FChangeReason,FItemID,FBomInterID,FMaterielType,FAuxQtyScrap" +
                      ",FItemUnitID,FBOMInPutAuxQTY,FScrap,FAuxQtyLoss,FAuxQtyPick" +
                      ",FAuxQtyMust,FSendItemDate,FStockID,FSPID,FBatchNo,FBackFlush" +
                      ",FOperSN,FOperID,FMachinePos,FAuxStockQty,FPPBOMInterID"+
                      ",FDiscardAuxQty,FLockFlag,FAuxQtySupply,FChangerID,FChangeDate" +
                      ",FMark,FQty,FQtyScrap,FBOMInPutQTY,FQtyLoss,FQtyPick" +
                      ",FQtyMust,FStockQty,FDiscardQty,FQtySupply,FClassID_SRC" +
                      ",FPositionNo,FItemSize,FItemSuite,FNote1,FNote2,FNote3,FPlanMode"+
                      //",FMTONo,FOrderEntryID,FIsRepItem,FICSubsID"+
                      //",FICSubsEntryID,FIsKeyItem,FPriorityID"+
                  ") Values (" +
                  omodel.HInterID.ToString() + "," + oSub.HEntryID.ToString() + "," + oSub.FICMOInterID.ToString() + ",'" + oSub.FICMOInterBN + "'," + oSub.FProductItemID.ToString() +
                  "," + oSub.FProductUnitID.ToString() + "," + oSub.FAuxQty.ToString() + ",'" + oSub.FPPBomBillNo.ToString() + "'," + oSub.FPPBomEntryID.ToString() + ",'" + oSub.FChangeFlag.ToString() +
                  "',''," + oSub.FItemID.ToString() + "," + oSub.FBomInterID.ToString() + ",'" + oSub.FMaterielType.ToString() + "'," + oSub.FQtyScrap.ToString() + 
                  "," + oSub.FUnitID.ToString() + "," + oSub.FBOMInPutAuxQTY.ToString() + ",0,0," + oSub.FAuxQtyPick.ToString() +
                  "," + oSub.FAuxQtyMust.ToString() + ",'" + oSub.FSendItemDate.ToShortDateString() + "'," + oSub.FStockID.ToString() +",0,'"+ oSub.FBatchNo+"',1059"+
                  ",0,0,''," + oSub.FAuxStockQty.ToString() + "," + oSub.FPPBomInterID.ToString() +
                  "," + oSub.FDisCardAuxQty.ToString() +",'0',0,0,null"+
                  ",''," + oSub.FAuxQty.ToString() + "," + oSub.FQtyScrap.ToString() + "," + oSub.FBOMInPutAuxQTY.ToString() + ",0," + oSub.FAuxQtyPick.ToString() +
                  "," + oSub.FAuxQtyMust.ToString() + "," + oSub.FAuxStockQty.ToString() + "," + oSub.FDisCardAuxQty.ToString() + ",0,-88" +
                  ",'','','','','','',14036" + 
                  ")");
 
                    //oCnK3.RunProc("update ICMO set FcommitQty=FcommitQty+" + oSub.Fauxqty + ",FAuxcommitQty=FAuxcommitQty+" + oSub.Fauxqty + " where Finterid=" + oSub.FICMOInterID);
                }
                //主表
                oCnK3.RunProc("INSERT INTO PPBomChange(" +
                    "FID,FClassTypeID,FDate,FBillNo,FBillerID" +
                    ",FCheckDate,FCheckFlag,FCheckerID,FBillType,FCheckDateLong" +
                    ") Values (" +
                    omodel.HInterID.ToString() + "," + omodel.HBillType + ",'" + omodel.HDate.ToShortDateString() + "','" + omodel.HBillNo + "'," + omodel.FBillerID.ToString() + 
                    ",null,'0',0,1059,null" +
                     ")");
 
                ////插入子表
                //foreach (Model.ClsKf_ProductInBillSub_K3 oSub in DetailColl)
                //{
                //    oSub.HInterID = omodel.HInterID;
                //    oCnK3.RunProc(K3_BaseFun.Fun_GetAddBillSubSQL_ProdIn(oSub, DBUtility.ClsPub.VersionNum));
                //    HSourceBillType = oSub.HSourceBillType;
                //}
                ////更新主表
                //oCnK3.RunProc(K3_BaseFun.Fun_GetAddBillMainSQL_ProdIn(omodel, DBUtility.ClsPub.VersionNum));
                //更新K3关联数量
                //oCnK3.RunProc("EXEC p_UpdateBillRelateData " + this.BillType + "," + omodel.HInterID.ToString() + ",'PPBomChange','PPBomChangeEntry'");
                //oCnK3.RunProc("EXEC h_p_K3_UpdateBillRelateData_ProdIn_New " + omodel.HInterID.ToString() + "," + omodel.HBillerID.ToString());
 
                //
                //
 
                sReturn = "新增单据成功!";
                oCnK3.Commit();
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                oCnK3.RollBack();
                throw (e);
            }
        }
        //显示单据
        public override bool ShowBill(Int64 lngBillKey, ref string sReturn)
        {
            try
            {
                //查询主表
                DataSet Ds ;
                SQLHelper.ClsCNK3 oCn = new SQLHelper.ClsCNK3();
                Ds = oCn.RunProcReturn("Select * from PPBomChange Where FID=" + lngBillKey.ToString(), "PPBomChange");
                if(Ds.Tables[0].Rows.Count==0)
                {
                    sReturn = "单据未找到!";
                    return false;
                }
                //赋值
                //omodel.FICMOInterID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FICMOInterID"]);
                //omodel.FOrderBillNo = Ds.Tables[0].Rows[0]["FOrderBillNo"].ToString().Trim();
                omodel.FBillNo = Ds.Tables[0].Rows[0]["FBillNo"].ToString().Trim();
                omodel.FDate = DBUtility.ClsPub.isDate(Ds.Tables[0].Rows[0]["FDate"]);
                //omodel.FItemID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FItemID"]);
                //omodel.FWorkShop = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FWorkShop"]);
                //omodel.FUnitID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FUnitID"]);
                //omodel.FAuxQty = DBUtility.ClsPub.isDoule(Ds.Tables[0].Rows[0]["FAuxQty"]);
                //=================
                omodel.FBillerID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FBillerID"]);
                omodel.FCheckerID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FCheckerID"]);
                omodel.FCheckDate = DBUtility.ClsPub.isDate(Ds.Tables[0].Rows[0]["FCheckDate"]);
                //
                //循环
                DataSet DsSub;
                DsSub = oCn.RunProcReturn("Select * from PPBomChangeEntry Where FID=" + lngBillKey.ToString() + " order by HEntryID ", "PPBomChangeEntry");
                DetailColl.Clear();//清空
                for (int i = 0; i < DsSub.Tables[0].Rows.Count; i++)
                {
                    Model.ClsSc_PPBomChangeSub_K3 oSub = new Model.ClsSc_PPBomChangeSub_K3();
                    oSub.HInterID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["FID"].ToString());
                    oSub.HEntryID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["FIndex"].ToString());
 
                    oSub.FICMOInterID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["FICMOInterID"].ToString());
                    oSub.FICMOInterBN = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["FICMOInterBN"].ToString());
                    oSub.FProductItemID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["FProductItemID"].ToString());
                    oSub.FProductUnitID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["FUnitID"].ToString());
 
                    oSub.FAuxQty = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FAuxQty"].ToString());
                    oSub.FPPBomBillNo = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["FPPBomBillNo"].ToString());
                    oSub.FPPBomInterID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["FPPBomInterID"].ToString());
                    oSub.FPPBomEntryID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["FPPBomEntryID"].ToString());
                    oSub.FChangeFlag = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["FChangeFlag"].ToString());
                    //
                    oSub.FItemID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["FItemID"].ToString());
                    oSub.FMaterielType = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["FMaterielType"].ToString());
                    oSub.FQtyScrap = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FQtyScrap"].ToString());
                    oSub.FUnitID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["FUnitID"].ToString());
                    oSub.FBOMInPutAuxQTY = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FBOMInPutAuxQTY"].ToString());
                    oSub.FScrap = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FScrap"].ToString());
                    oSub.FAuxQtyLoss = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FAuxQtyLoss"].ToString());
                    //oSub.FRealScrap = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FRealScrap"].ToString());
                    oSub.FAuxQtyPick = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FAuxQtyPick"].ToString());
                    oSub.FAuxQtyMust = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FAuxQtyMust"].ToString());
                    oSub.FAuxStockQty = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FAuxStockQty"].ToString());
                    oSub.FDisCardAuxQty = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FDisCardAuxQty"].ToString());
                    oSub.FSendItemDate = DBUtility.ClsPub.isDate(DsSub.Tables[0].Rows[i]["FSendItemDate"].ToString());
 
                    oSub.FStockID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["FStockID"].ToString());
                    oSub.FSPID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["FSPID"].ToString());
                    oSub.FBatchNo = DsSub.Tables[0].Rows[i]["FBatchNo"].ToString().Trim();
                    oSub.FBackFlush = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["FBackFlush"].ToString());
                    oSub.FOPerID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["FOPerID"].ToString());
                    oSub.FMachinePos = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["FMachinePos"].ToString());
                    //oSub.FNote = DsSub.Tables[0].Rows[i]["FNote1"].ToString().Trim();
                    oSub.FAuxQtySupply = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FAuxQtySupply"].ToString());
                    oSub.FOperSN = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["FOperSN"].ToString());
                    oSub.FBomInterID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["FBomInterID"].ToString());
                    oSub.FPositionNo = DsSub.Tables[0].Rows[i]["FPositionNo"].ToString().Trim();
                    oSub.FItemSize = DsSub.Tables[0].Rows[i]["FItemSize"].ToString().Trim();
                    oSub.FItemSuite = DsSub.Tables[0].Rows[i]["FItemSuite"].ToString().Trim();
 
                    DetailColl.Add(oSub);
                }   
                sReturn = "显示单据成功!";
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                throw (e);
            }
        }
        //审核单据
        public bool CheckBill_K3(Int64 lngBillKey, ref string sReturn)
        {
            try
            {
                //得到用户ID
                DataSet DsBiller;
                DsBiller = oK3Cn.RunProcReturn("select top 1 fuserid from t_User where fname='" + DBUtility.ClsPub.CurUserName + "'", "t_User");
                if (DsBiller.Tables[0].Rows.Count != 0)
                {
                    omodel.FBillerID = DBUtility.ClsPub.isLong(DsBiller.Tables[0].Rows[0][0]);
                }
                else
                {
                    omodel.FBillerID = 16394;
                }
                omodel.HBillType = this.BillType;
                omodel.HCheckDate = DateTime.Today.ToShortDateString();
                string date = DateTime.Today.ToString();
                //
                //DataSet Ds1;
                //主表
                oCnK3.BeginTran();
                oCnK3.RunProc("update PPBomChange set FCheckDate='" + omodel.HCheckDate + "',FCheckDateLong='"+date +"',FCheckerID="+ omodel.FBillerID.ToString() +",FCheckFlag='1' where FID=" +lngBillKey.ToString());
                sReturn = "审核单据成功!";
                oCnK3.Commit();
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                oCnK3.RollBack();
                throw (e);
            }
        }
        //反审单据
        public bool AbandonCheck_K3(Int64 lngBillKey, ref string sReturn)
        {
            try
            {
                //得到用户ID
                DataSet DsBiller;
                DsBiller = oK3Cn.RunProcReturn("select top 1 FID from PPBomChangeEntry where FChangeFlag='1' and FID=" + lngBillKey.ToString() , "PPBomChangeEntry");
                if (DsBiller.Tables[0].Rows.Count >= 1)
                {
                    sReturn = "单据已变更,反审核单据失败!";
                    return false;
                }
                else
                {
                    //
                    //DataSet Ds1;
                    //主表PPBomChange
                    oCnK3.BeginTran();
                    oCnK3.RunProc("update PPBomChange set FCheckDate=null,FCheckerID=0,FCheckFlag='0' where FID=" + lngBillKey.ToString());
                    sReturn = "反审核单据成功!";
                    oCnK3.Commit();
                    return true;              
                
                }
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                oCnK3.RollBack();
                throw (e);
            }
        }
        //变更
        public bool ChangeBill_K3(Int64 lngBillKey, ref string sReturn)
        {
            try
            {
                //得到用户ID
                DataSet DsBiller;
                DsBiller = oK3Cn.RunProcReturn("select top 1 fuserid from t_User where fname='" + DBUtility.ClsPub.CurUserName + "'", "t_User");
                DataSet Ds;
                Ds = oK3Cn.RunProcReturn("select top 1 FID from PPBomChangeEntry where FChangeFlag='1' and FID=" + lngBillKey.ToString(), "PPBomChangeEntry");
                if (Ds.Tables[0].Rows.Count >= 1)
                {
                    sReturn = "单据已变更,变更失败!";
                    return false;
                }
                else
                if (DsBiller.Tables[0].Rows.Count != 0)
                {
                    omodel.FBillerID = DBUtility.ClsPub.isLong(DsBiller.Tables[0].Rows[0][0]);
                }
                else
                {
                    omodel.FBillerID = 16394;
                }
                omodel.HBillType = this.BillType;
                omodel.HCheckDate = DateTime.Today.ToShortDateString();
                //
                //DataSet Ds1;
                //主表
                oCnK3.BeginTran();
                oCnK3.RunProc("exec PPBomChangeEntry_update " + lngBillKey.ToString());
                oCnK3.RunProc("update PPBomChangeEntry set FChangeDate='" + omodel.HCheckDate + "',FChangerID=" + omodel.FBillerID.ToString() + ",FChangeFlag='1' where FID=" + lngBillKey.ToString());
                sReturn = "变更成功!";
                oCnK3.Commit();
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                oCnK3.RollBack();
                throw (e);
            }
        }
        //删除单据
        public virtual bool DeleteBill(Int64 lngBillKey, ref string sReturn)
        {
            try
            {
                DataSet Ds;
                oCnK3.BeginTran();
                //
                //Ds = oCnK3.RunProcReturn("select FSourceInterID from  ICStockBillEntry where finterid=" + lngBillKey, "ICStockBillEntry");
                //删除关联 
                //删除明细表 
                oCnK3.RunProc("Delete From  PPBomChangeEntry where FID=" + lngBillKey.ToString());
                //删除主表
                //DeleteBillMain(lngBillKey);
                oCnK3.RunProc("Delete From  PPBomChange where FID=" + lngBillKey.ToString());
                //删除关联
 
                sReturn = "删除单据成功!";
                oCnK3.Commit();
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                oCnK3.RollBack();
                throw (e);
            }
        }
        //单据号是否重复
        public virtual bool IsExistBillNo(ref string sReturn, string sBillNo, DBUtility.ClsPub.Enum_BillStatus oBillStatus, Int64 lngBillKey)
        {
            try
            {
                string sSql = "";
                if (oBillStatus == DBUtility.ClsPub.Enum_BillStatus.BillStatus_AddNew)
                {
                    sSql = "Select FInterID from PPBomChange where FClassTypeID='" + MvarItemKey + "' and FBillNo ='" + sBillNo + "'";
                }
                else
                {
                    sSql = "Select FInterID from PPBomChange where FClassTypeID='" + MvarItemKey + "' and FBillNo ='" + sBillNo + "' and FID<>" + lngBillKey.ToString();
                }
                DataSet Ds;
                Ds = oCnK3.RunProcReturn(sSql, "PPBomChange");
                if (Ds.Tables[0].Rows.Count != 0)
                {
                    sReturn = "单号重复";
                    return true;
                }
                sReturn = "单号未重复";
                return false;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                return false;
            }
        }
       
        
    }
 
}