杨乐
2022-01-13 8b5b510f27ac7be8a7e92f90dcb7752850e7e466
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
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
 
namespace DAL
{
    public class ClsWeb_BarCodeBill : DBUtility.ClsXt_BaseBill
    {
        public Model.ClsCg_POInStockBillMain_K3 omodel = new Model.ClsCg_POInStockBillMain_K3();
 
        public ClsWeb_BarCodeBill()
        {
            base.MvarItemKeyForWeb = "h_v_K3_POInStockBillMain_ForWeb";
            base.MvarItemKeySubForWeb = "h_v_K3_POInStockBillSub_ForWeb";
            base.MvarItemKeySubForWeb2 = "h_v_Web_BarCodeBill_ForWeb";
            base.MvarItemKeySub = "POInStockEntry";
            base.MvarItemKeySub2 = "";
            base.MvarItemKeySub3 = "";
            base.MvarItemKeySub4 = "";
            base.MvarItemKey = "POInStock";
            base.MvarReportTitle = "收料通知单";
            base.BillType = "72";
        }
 
        #region 固定代码
 
        ~ClsWeb_BarCodeBill()
        {
            //DetailColl = null;
        }
 
        #endregion   自定义方法
 
        //单据号是否重复
        public 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 POInStock where FTranType='" + BillType + "' and FBillNo ='" + sBillNo + "'";
                }
                else
                {
                    sSql = "Select FInterID from POInStock where FTranType='" + BillType + "' and FBillNo ='" + sBillNo + "' and FInterID<>" + lngBillKey.ToString();
                }
                DataSet Ds;
                Ds = oK3Cn.RunProcReturn(sSql, "POInStock");
                if (Ds.Tables[0].Rows.Count != 0)
                {
                    sReturn = "单号重复";
                    return true;
                }
                sReturn = "单号未重复";
                return false;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                return false;
            }
        }
 
        //删除子表
        public void DeleteBillSub(Int64 lngBillKey)
        {
            oK3Cn.RunProc("Delete From POInStockEntry where FInterID=" + lngBillKey.ToString());
        }
        //删除主表
        public void DeleteBillMain(Int64 lngBillKey)
        {
            oK3Cn.RunProc("Delete From POInStock where FInterID=" + lngBillKey.ToString());
        }
        //删除单据
        public bool DeleteBill(Int64 lngBillKey, ref string sReturn)
        {
            DataSet Ds = new DataSet();
            try
            {
                oK3Cn.BeginTran();
                //删除关联
                //DeleteRelation(ref sReturn, lngBillKey);
                //删除明细表
                DeleteBillSub(lngBillKey);
                //删除主表
                DeleteBillMain(lngBillKey);
                //删除关联
 
                sReturn = "删除单据成功!";
                oK3Cn.Commit();
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                oK3Cn.RollBack();
                return false;
            }
        }
 
        //修改单据
        public override bool ModifyBill(Int64 lngBillKey, ref string sReturn)
        {
            //try
            //{
            //    oK3Cn.BeginTran();
            //    //删除主表
            //    DeleteBillMain(lngBillKey);
            //    //删除子表
            //    DeleteBillSub(lngBillKey);
            //    //
            //    //更新主表
            //    oK3Cn.RunProc("Insert Into POInStock " +
            //    "(FInterID,FBillNo,FBrNo,FTranType,FCancellation,FStatus" +
            //    ",FSupplyID,Fdate,FCurrencyID" +
            //    ",FCheckDate,FMangerID,FDeptID,FEmpID,FBillerID" +
            //    ",FExchangeRateType,FExchangeRate,FPOStyle,FRelateBrID,FMultiCheckDate1,FMultiCheckDate2" +
            //    ",FMultiCheckDate3,FMultiCheckDate4,FMultiCheckDate5,FMultiCheckDate6" +
            //    ",FSelTranType,FBrID,FExplanation" +
            //    ",FSettleID,FSettleDate,FAreaPS,FPOOrdBillNo,FManageType,FSysStatus" +
            //    ",FValidaterName,FConsignee,FVersionNo,FChangeDate,FChangeUser" +
            //    ",FChangeCauses,FChangeMark,FPrintCount,FDeliveryPlace" +
            //    ") " +
            //    " values(" + lngBillKey.ToString() + ",'" + omodel.HBillNo + "','0'," + this.BillType + ",0,0" +
            //    "," + omodel.HCusID.ToString() + ",'" + omodel.HDate.ToShortDateString() + "'," + omodel.HCurID.ToString() +
            //    ",null," + omodel.HMangerID.ToString() + "," + omodel.HDeptID.ToString() + "," + omodel.HEmpID.ToString() + ",16394" +
            //    ",1," + omodel.HExRate.ToString() + "252,0,null,null" +
            //    ",null,null,null,null" +
            //    ",70,0,"  +omodel.HExplanation +
            //    ",0,'" + DBUtility.ClsPub.GetServerDate(-1) + "',20302,'',0,0" +
            //    ",'',0,'000',Null,0" +
            //    ",'','',0,''" +
            //    ") ");
            //    //插入子表
            //    foreach (Model.ClsCg_POInStockBillSub_K3 oSub in DetailColl)
            //    {
            //        oK3Cn.RunProc("Insert into POInStockEntry " +
            //          " (FInterID,FEntryID,FBrNo,FMapNumber,FMapName,FItemID" +
            //          ",FAuxPropID,FQty,FUnitID,Fauxqty,FSecCoefficient,FSecQty" +
            //          ",Fauxprice,FAuxTaxPrice,Famount,FTaxRate,FAuxPriceDiscount,FDescount,FCess" +
            //          ",FTaxAmount,FAllAmount,Fdate,Fnote" +
            //          ",FSourceBillNo,FSourceTranType,FSourceInterId,FSourceEntryID" +
            //          ",FContractBillNo,FContractInterID,FContractEntryID" +
            //          ",FAuxQtyInvoice,FSecInvoiceQty,FQtyInvoice,FMrpLockFlag" +
            //          ",FReceiveAmountFor_Commit,FPlanMode,FMTONo" +
            //          ") values("
            //          + lngBillKey.ToString() + "," + oSub.HEntryID.ToString() + ",'0','',''," + oSub.HMaterID.ToString() +
            //          ",0," + oSub.HQty.ToString() + "," + oSub.HUnitID.ToString() + "," + oSub.HQty.ToString() + ",0,0" +
            //          "," + oSub.HPrice.ToString() + "," + oSub.HTaxPrice.ToString() + "," + oSub.HMoney.ToString() + "," + oSub.HTaxRate.ToString() + ",0,0,17" +
            //          "," + oSub.HTaxMoney.ToString() + "," + oSub.HlineTotal.ToString() + ",'" + oSub.HDate.ToShortDateString() + "','" + oSub.HRemark +
            //          ",'" + oSub.HSourceBillNo + "','" + oSub.HSourceBillType + "'," + oSub.HSourceInterID.ToString() + "," + oSub.HSourceEntryID.ToString() +
            //          ",'',0,0" +
            //          ",0,0,0,0" +
            //          ",0,14036,''" +
            //          ") ");
            //    }
            //    sReturn = "修改单据成功!";
            //    oK3Cn.Commit();
            return true;
            //}
            //catch (Exception e)
            //{
            //    sReturn = e.Message;
            //    oK3Cn.RollBack();
            //    throw (e);
            //}
        }
        //新增单据
        public override bool AddBill(ref string sReturn)
        {
            //try
            //{
            //    DataSet Ds;
            //    //得到mainid
            //    Ds = oK3Cn.RunProcReturn("declare @InterID int set @InterID=0 exec GetICMaxNum 'POInStock', @InterID output, 1, 16394 select ltrim(@InterID)", "GetICMaxNum");
            //    omodel.HInterID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0][0]);
            //    //若MAINDI重复则重新获取
            //    oK3Cn.BeginTran();
            //    //主表
            //    oK3Cn.RunProc("Insert Into POInStock " +
            //    "(FInterID,FBillNo,FBrNo,FTranType,FCancellation,FStatus" +
            //    ",FSupplyID,Fdate,FCurrencyID" +
            //    ",FCheckDate,FMangerID,FDeptID,FEmpID,FBillerID" +
            //    ",FExchangeRateType,FExchangeRate,FPOStyle,FRelateBrID,FMultiCheckDate1,FMultiCheckDate2" +
            //    ",FMultiCheckDate3,FMultiCheckDate4,FMultiCheckDate5,FMultiCheckDate6" +
            //    ",FSelTranType,FBrID,FExplanation" +
            //    ",FSettleID,FSettleDate,FAreaPS,FPOOrdBillNo,FManageType,FSysStatus" +
            //    ",FValidaterName,FConsignee,FVersionNo,FChangeDate,FChangeUser" +
            //    ",FChangeCauses,FChangeMark,FPrintCount,FDeliveryPlace" +
            //    ") " +
            //    " values(" + omodel.HInterID.ToString() + ",'" + omodel.HBillNo + "','0'," + this.BillType + ",0,0" +
            //    "," + omodel.HCusID.ToString() + ",'" + omodel.HDate.ToShortDateString() + "'," + omodel.HCurID.ToString() +
            //    ",null," + omodel.HMangerID.ToString() + "," + omodel.HDeptID.ToString() + "," + omodel.HEmpID.ToString() + ",16394" +
            //    ",1," + omodel.HExRate.ToString() + ",252,0,null,null" +
            //    ",null,null,null,null" +
            //    ",70,0,'自动导入'" +
            //    ",0,'" + omodel.HDate.ToShortDateString() + "',20302,'',0,2" +
            //    ",'',0,'000',Null,0" +
            //    ",'','',0,''" +
            //    ") ");
            //    //插入子表
            //    foreach (Model.ClsCg_POInStockBillSub_K3 oSub in DetailColl)
            //    {
            //        oK3Cn.RunProc("Insert into POInStockEntry " +
            //          " (FInterID,FEntryID,FBrNo,FMapNumber,FMapName,FItemID" +
            //          ",FAuxPropID,FQty,FUnitID,Fauxqty,FSecCoefficient,FSecQty" +
            //          ",Fauxprice,FAuxTaxPrice,Famount,FTaxRate,FAuxPriceDiscount,FDescount,FCess" +
            //          ",FTaxAmount,FAllAmount,Fdate,Fnote" +
            //          ",FSourceBillNo,FSourceTranType,FSourceInterId,FSourceEntryID" +
            //          ",FContractBillNo,FContractInterID,FContractEntryID" +
            //          ",FAuxQtyInvoice,FSecInvoiceQty,FQtyInvoice,FMrpLockFlag" +
            //          ",FReceiveAmountFor_Commit,FPlanMode,FMTONo" +
            //          ") values("
            //          + omodel.HInterID.ToString() + "," + oSub.HEntryID.ToString() + ",'0','',''," + oSub.HMaterID.ToString() +
            //          ",0," + oSub.HQty.ToString() + "," + oSub.HUnitID.ToString() + "," + oSub.HQty.ToString() + ",0,0" +
            //          "," + oSub.HPrice.ToString() + "," + oSub.HTaxPrice.ToString() + "," + oSub.HMoney.ToString() + "," + oSub.HTaxRate.ToString() + ",0,0,17" +
            //          "," + oSub.HTaxMoney.ToString() + "," + oSub.HlineTotal.ToString() + ",'" + oSub.HDate.ToShortDateString() + "','" + oSub.HRemark +
            //          "','" + oSub.HSourceBillNo + "'," + oSub.HSourceBillType + "," + oSub.HSourceInterID.ToString() + "," + oSub.HSourceEntryID.ToString() +
            //          ",'',0,0" +
            //          ",0,0,0,0" +
            //          ",0,14036,''" +
            //          ") ");
            //        //更新申请单关联数量
            //        oK3Cn.RunProc("EXEC p_UpdateBillRelateData " + this.BillType + "," + omodel.HInterID.ToString() + ",'POInStock','POInStockEntry'");
 
            //        oK3Cn.RunProc("update porequestentry set fcommitqty=Fqty,fauxcommitqty=Fauxqty,FMRPClosed=1 where FMRPClosed<>1 and Fitemid=" + oSub.HMaterID);
            //    }
            //    //更新申请单关闭标志
 
            //    oK3Cn.RunProc("EXEC h_p_Cg_POInStockToUpdate_K3 "+ omodel.HInterID.ToString());
 
            //    //oK3Cn.RunProc("UPDATE T1 SET T1.FStatus=CASE WHEN NOT EXISTS(SELECT 1 FROM POrequestEntry WHERE FInterID=T1.FInterID AND FCommitQty<>0) THEN 1 " +
            //    //               "WHEN NOT EXISTS (SELECT 1 FROM POrequestEntry WHERE FInterID=T1.FInterID AND FQty>FCommitQty) THEN 3 ELSE 2 END," +
            //    //               "T1.FCLOSED=CASE WHEN NOT EXISTS (SELECT 1 FROM POrequestEntry WHERE FInterID=T1.FInterID AND FQty>FCommitQty) THEN 1 ELSE 0 END " +
            //    //               "FROM POrequest T1 where T1.FStatus in (1,2)");
 
 
            //    sReturn = "新增单据成功!";
            //    oK3Cn.Commit();
            return true;
            //}
            //catch (Exception e)
            //{
            //    sReturn = e.Message;
            //    oK3Cn.RollBack();
            //    throw (e);
            //}
        }
        //显示单据
        public override bool ShowBill(Int64 lngBillKey, ref string sReturn)
        {
            //try
            //{
            //    //查询主表
            //    DataSet Ds;
            //    Ds = oK3Cn.RunProcReturn("Select * from POInStock Where FInterID=" + lngBillKey.ToString(), "POInStock");
            //    if (Ds.Tables[0].Rows.Count == 0)
            //    {
            //        sReturn = "单据未找到!";
            //        return false;
            //    }
            //    //赋值
            //    omodel.HInterID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FInterID"]);
            //    omodel.HBillNo = Ds.Tables[0].Rows[0]["FBillNo"].ToString().Trim();
            //    omodel.HDate = Convert.ToDateTime(Ds.Tables[0].Rows[0]["Fdate"].ToString().Trim());
            //    omodel.HExplanation = Ds.Tables[0].Rows[0]["FExplanation"].ToString().Trim();
            //    //
            //    omodel.HCusID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FCustID"]);
            //    omodel.HCurID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FCurrencyID"]);
            //    omodel.HDeptID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FDeptID"]);
            //    omodel.HEmpID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FEmpID"]);
            //    omodel.HMangerID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FMangerID"]);
            //    omodel.HSSID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FSettleID"]);
            //    //
            //    omodel.HExRate = DBUtility.ClsPub.isDoule(Ds.Tables[0].Rows[0]["FExchangeRate"]);
            //    omodel.HAddress = Ds.Tables[0].Rows[0]["FFetchAdd"].ToString().Trim();
            //    //
            //    omodel.HMaker = Ds.Tables[0].Rows[0]["FBillerID"].ToString().Trim();
            //    omodel.HMakeDate = Ds.Tables[0].Rows[0]["Fdate"].ToString().Trim();
            //    //omodel.HUpDater = Ds.Tables[0].Rows[0]["FOperatorID"].ToString().Trim();
            //    //omodel.HUpDateDate = Ds.Tables[0].Rows[0]["FEntertime"].ToString().Trim();
            //    //omodel.HBackDate = Ds.Tables[0].Rows[0]["HBackDate"].ToString().Trim();
            //    //omodel.HBacker = Ds.Tables[0].Rows[0]["HBacker"].ToString().Trim();
            //    //omodel.HChecker = Ds.Tables[0].Rows[0]["FCheckerID"].ToString().Trim();
            //    //omodel.HCheckDate = Ds.Tables[0].Rows[0]["FCheckDate"].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();
            //    //循环
            //    DataSet DsSub;
            //    DsSub = oK3Cn.RunProcReturn("Select * from POInStockEntry Where FInterID=" + lngBillKey.ToString() + " order by HEntryID ", "POInStockEntry");
            //    DetailColl.Clear();//清空
            //    for (int i = 0; i < DsSub.Tables[0].Rows.Count; i++)
            //    {
            //        Model.ClsCg_POInStockBillSub_K3 oSub = new Model.ClsCg_POInStockBillSub_K3();
            //        oSub.HInterID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["FInterID"].ToString());
            //        oSub.HEntryID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["FEntryID"].ToString());
            //        oSub.HMaterID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["FItemID"].ToString());
            //        oSub.HUnitID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["FUnitID"].ToString());
 
            //        oSub.HQty = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["Fauxqty"].ToString());
            //        oSub.HPrice = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["Fauxprice"].ToString());
            //        oSub.HTaxPrice = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FAuxTaxPrice"].ToString());
            //        oSub.HMoney = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["Famount"].ToString());
            //        oSub.HTaxRate = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FCess"].ToString());
            //        oSub.HTaxMoney = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FTaxAmount"].ToString());
            //        oSub.HlineTotal = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["FAllAmount"].ToString());
 
            //        //oSub.HCloseMan = DsSub.Tables[0].Rows[i]["HCloseMan"].ToString().Trim();
            //        //oSub.HCloseType = (bool)DsSub.Tables[0].Rows[i]["HCloseType"];
            //        oSub.HDate = Convert.ToDateTime(DsSub.Tables[0].Rows[i]["FDate"].ToString().Trim());
            //        oSub.HRemark = DsSub.Tables[0].Rows[i]["Fnote"].ToString().Trim();
            //        //
            //        oSub.HSourceInterID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["FSourceInterID"].ToString());
            //        oSub.HSourceEntryID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["FSourceEntryID"].ToString());
            //        oSub.HSourceBillType = DsSub.Tables[0].Rows[i]["FSourceTranType"].ToString().Trim();
            //        oSub.HSourceBillNo = DsSub.Tables[0].Rows[i]["FSourceBillNo"].ToString().Trim();
            //        //oSub.HRelationQty = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["HRelationQty"].ToString());
            //        //oSub.HRelationMoney = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["HRelationMoney"].ToString());
            //        DetailColl.Add(oSub);
            //    }
            //    sReturn = "显示单据成功!";
            return true;
            //}
            //catch (Exception e)
            //{
            //    sReturn = e.Message;
            //    throw (e);
            //}
        }
 
        //删除单据
        public bool CheckBill(Int64 lngBillKey, Int64 HBillerID, ref string sReturn)
        {
            SQLHelper.ClsCNK3 oCnK3 = new SQLHelper.ClsCNK3();
            try
            {
                DataSet Ds;
                oCnK3.BeginTran();
                //
                oCnK3.RunProc("exec h_p_K3_Cg_POInStockBill_Check " + lngBillKey.ToString() + "," + HBillerID.ToString());
 
                sReturn = "审核单据成功!";
                oCnK3.Commit();
                oCnK3.CnDispose();
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                oCnK3.RollBack();
                throw (e);
            }
        }
 
        //生成条码
        public bool SaveBarCode(Int64 HMaterID, Int64 HUnitID, Int64 HQty, Int64 HMinQty, Int64 HSourceInterID, Int64 HSourceEntryID, string HSourceBillNo, string HSourceBillType)
        {
            SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
            oCn.RunProc("exec h_p_Web_BarCodeBill " + HMaterID + "," + HUnitID + "," + HQty + "," + HMinQty + "," + HSourceInterID + "," + HSourceEntryID + ",'" + HSourceBillNo + "','" + HSourceBillType+"'");
            return true;
        }
        //检查是否已经生成条码
        public bool CheckBarCode(Int64 HSourceInterID, Int64 HSourceEntryID)
        {
            SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
            DataSet Ds;
            Ds = oCn.RunProcReturn("select * from Gy_BarCodeBill where HSourceInterID=" + HSourceInterID + " and HSourceEntryID=" + HSourceEntryID, "Gy_BarCodeBill");
            if (Ds == null)
            {
                return false;
            }
            if (Ds.Tables[0].Rows.Count == 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
 
    }
}