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
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
 
namespace DAL
{
    public class ClsSc_ICMOBill_K3 : DBUtility.ClsXt_BaseBill
    {
        public Model.ClsSc_ICMOBillMain_K3 omodel = new Model.ClsSc_ICMOBillMain_K3();
        //public List<Model.ClsSc_ICMOBill_K3Sub> DetailColl = new List<Model.ClsSc_ICMOBill_K3Sub>();
        
        public ClsSc_ICMOBill_K3()
        {
            base.MvarItemKeySub = "";
            base.MvarItemKeySub2 = "";
            base.MvarItemKeySub3 = "";
            base.MvarItemKeySub4 = "";
            base.MvarItemKey = "ICMO";
            base.MvarReportTitle = "生产任务单";
            base.BillType = "85";
        }
 
        #region 固定代码
 
        ~ClsSc_ICMOBill_K3()
        {
            //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 ICMO where FTranType='" + BillType + "' and FBillNo ='" + sBillNo + "'";
                }
                else
                {
                    sSql = "Select FInterID from ICMO where FTranType='" + BillType + "' and FBillNo ='" + sBillNo + "' and FInterID<>" + lngBillKey.ToString();
                }
                DataSet Ds;
                Ds = oCnK3.RunProcReturn(sSql, "ICMO");
                if (Ds.Tables[0].Rows.Count != 0)
                {
                    sReturn = "单号重复";
                    return true;
                }
                sReturn = "单号未重复";
                return false;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                return false;
            }
        }
 
        //删除主表
        public void DeleteBillMain(Int64 lngBillKey)
        {
            oCnK3.RunProc("Delete From ICMO where FInterID=" + lngBillKey.ToString());
        }
        //删除单据
        public bool DeleteBill(Int64 lngBillKey, ref string sReturn)
        {
            DataSet Ds = new DataSet();
            try
            {
                oCnK3.BeginTran();
                //删除关联
                //DeleteRelation(ref sReturn, lngBillKey);
                //删除明细表 
                //删除主表
                DeleteBillMain(lngBillKey);
                //删除关联
 
                sReturn = "删除单据成功!";
                oCnK3.Commit();
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                oCnK3.RollBack();
                return false;
            }
        }
 
        //修改单据
        public override bool ModifyBill(Int64 lngBillKey, ref string sReturn)
        {
            try
            {
                //得到用户ID
                DataSet DsBiller;
                DsBiller = oCnK3.RunProcReturn("select top 1 fuserid from t_User where fname='" + DBUtility.ClsPub.CurUserName + "'", "t_User");
                if (DsBiller.Tables[0].Rows.Count != 0)
                {
                    omodel.HBillerID = DBUtility.ClsPub.isLong(DsBiller.Tables[0].Rows[0][0]);
                }
                else
                {
                    omodel.HBillerID = 16394;
                }
                omodel.HBillType = this.BillType;
                //
                //得到mainid 
                omodel.HInterID = lngBillKey;
 
                //若MAINDI重复则重新获取 
                oCnK3.BeginTran();
                //主表
                oCnK3.RunProc(K3_BaseFun.Fun_GetAddBillMainSQL_ICMO(omodel, DBUtility.ClsPub.VersionNum));
                //
                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;
                DsBiller = oCnK3.RunProcReturn("select top 1 fuserid from t_User where fname='" + DBUtility.ClsPub.CurUserName + "'", "t_User");
                if (DsBiller.Tables[0].Rows.Count != 0)
                {
                    omodel.HBillerID = DBUtility.ClsPub.isLong(DsBiller.Tables[0].Rows[0][0]);
                }
                else
                {
                    omodel.HBillerID = 16394;
                }
                omodel.HBillType = this.BillType;
                //
                DataSet Ds;
                //得到mainid 
                Ds = oCnK3.RunProcReturn("declare @InterID int set @InterID=0 exec GetICMaxNum 'ICMO', @InterID output, 1, 16394 select ltrim(@InterID)", "GetICMaxNum");
                omodel.HInterID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0][0]);
 
                //若MAINDI重复则重新获取 
                oCnK3.BeginTran();
                //主表
                oCnK3.RunProc(K3_BaseFun.Fun_GetAddBillMainSQL_ICMO(omodel, DBUtility.ClsPub.VersionNum));
                //
                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;
                Ds = oCnK3.RunProcReturn("Select * from ICMO Where FInterID=" + lngBillKey.ToString(), "ICMO");
                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 = DBUtility.ClsPub.isDate(Ds.Tables[0].Rows[0]["FCheckDate"]); 
                //=================
                omodel.HRemark = Ds.Tables[0].Rows[0]["Fnote"].ToString().Trim();
 
                omodel.HBatchNo = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["FGMPBatchNo"]);
                //omodel.HBatchNo = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["FHeadSelfJ0187"]);
                omodel.HSeOrderBillNo = "";
                omodel.HSeOrderInterID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FOrderInterID"]);
                omodel.HSeOrderEntryID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FSourceEntryID"]);
                //omodel.HEmpID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HEmpID"]);
                omodel.HCusID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FCustID"]);
                omodel.HDeptID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FWorkShop"]);
                //omodel.HCenterID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HCenterID"]);
                omodel.HMaterID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FItemID"]);
                omodel.HUnitID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FUnitID"]);
                omodel.HBomID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FBomInterID"]);
                //omodel.HMainBomID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FHeadSelfj0194"]);
                //omodel.HMainBomNumber = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["FHeadSelfj0194"]);
                omodel.HRoutingInterID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["FRoutingID"]);
                //
                //omodel.HLevNum = DBUtility.ClsPub.isInt(Ds.Tables[0].Rows[0]["HLevNum"]);
                //omodel.HReadyQty = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HReadyQty"]);
                omodel.HPlanQty = DBUtility.ClsPub.isDoule(Ds.Tables[0].Rows[0]["Fauxqty"]);
                //omodel.HStockType = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["FHeadSelfJ0187"]);
                //
                omodel.HPlanBeginDate = DBUtility.ClsPub.isDate(Ds.Tables[0].Rows[0]["FPlanCommitDate"]);
                omodel.HPlanEndDate = DBUtility.ClsPub.isDate(Ds.Tables[0].Rows[0]["FPlanFinishDate"]);
                //omodel.HBeginDate = DBUtility.ClsPub.isDate(Ds.Tables[0].Rows[0]["HBeginDate"]);
                //omodel.HEndDate = DBUtility.ClsPub.isDate(Ds.Tables[0].Rows[0]["HEndDate"]);
                //
                omodel.HMaker = Ds.Tables[0].Rows[0]["FBillerID"].ToString().Trim();
                omodel.HMakeDate = Ds.Tables[0].Rows[0]["FCheckDate"].ToString().Trim(); 
               
                sReturn = "显示单据成功!";
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                throw (e);
            }
        }
        /// <summary>
        /// 生成工序计划单
        /// </summary>
        /// <param name="HICMOID"></param>
        /// <param name="sReturn"></param>
        /// <returns></returns>
        public bool ProcessPlanBill_Add(long HICMOID, ref string sReturn)
        {
            try
            {
                DataSet Ds;
                //单据ID
                long HInterID = DBUtility.ClsPub.CreateBillID("3715", ref DBUtility.ClsPub.sExeReturnInfo);
                string sHBillNo = DBUtility.ClsPub.CreateBillCode("3715", ref DBUtility.ClsPub.sExeReturnInfo, true);
                //
                oCn.BeginTran();
                //增加主表
                Ds = oCn.RunProcReturn("exec h_p_Sc_ProcessPlanBill_Add " + HICMOID.ToString() + "," + HInterID.ToString() + ",'" + sHBillNo + "','" + DBUtility.ClsPub.CurUserName + "'", "h_p_Sc_ProcessPlanBill_Add");
                if (Ds == null || Ds.Tables[0].Rows.Count == 0)
                {
                    oCn.RollBack();
                    return false;
                }
                if (DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0][0]) != 9)
                {
                    sReturn = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0][1]);
                    oCn.RollBack();
                    return false;
                }
                //
                oCn.Commit();
                //回填关联数量
                //oCnK3.RunProc("update ICMO set FCardClosed=1 where finterid=" + HICMOID.ToString());
                //
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                oCn.RollBack();
                return false;
            }
        }
 
        /// <summary>
        /// 生成工序计划单
        /// </summary>
        /// <param name="HICMOID"></param>
        /// <param name="sReturn"></param>
        /// <returns></returns>
        public bool ProcessPlanBill_Add(long HICMOID, long HRoutingID, ref string sReturn)
        {
            try
            {
                DataSet Ds;
                //单据ID
                long HInterID = DBUtility.ClsPub.CreateBillID("3715", ref DBUtility.ClsPub.sExeReturnInfo);
                string sHBillNo = DBUtility.ClsPub.CreateBillCode("3715", ref DBUtility.ClsPub.sExeReturnInfo, true);
                //
                oCn.BeginTran();
                //增加主表
                Ds = oCn.RunProcReturn("exec h_p_Sc_ProcessPlanBill_Add2 " + HICMOID.ToString() + "," + HRoutingID.ToString() + "," + HInterID.ToString() + ",'" + sHBillNo + "','" + DBUtility.ClsPub.CurUserName + "'", "h_p_Sc_ProcessPlanBill_Add");
                if (Ds == null || Ds.Tables[0].Rows.Count == 0)
                {
                    oCn.RollBack();
                    return false;
                }
                if (DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0][0]) != 9)
                {
                    sReturn = "工序计划单,单据号:" + sHBillNo + DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0][1]);
                    oCn.RollBack();
                    return false;
                }
                //
                oCn.Commit();
                //回填关联数量
                //oCnK3.RunProc("update ICMO set FCardClosed=1 where finterid=" + HICMOID.ToString());
                //
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                oCn.RollBack();
                return false;
            }
        }
 
        /// <summary>
        /// 得到成本对象
        /// </summary>
        /// <param name="HICMOID"></param>
        /// <param name="sReturn"></param>
        /// <returns></returns>
        public long GetCostObjByHMaterID(long HMaterID)
        {
            DataSet Ds;
            //
            //增加主表
            Ds = oCnK3.RunProcReturn("select cb.FCostObjID HCostObjID from t_icitem m inner join cb_CostObj_Product cb on m.FItemID=cb.FProductID "+
                                                    "where FItemID=" + HMaterID.ToString(), "cb_CostObj_Product");
            if (Ds == null || Ds.Tables[0].Rows.Count == 0)
            {
                return 0;
            }
            long HCostObjID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0][0]);
            return HCostObjID;
        }
 
        /// <summary>
        /// 下达
        /// </summary>
        /// <param name="HMaterID"></param>
        /// <returns></returns>
        public bool CheckICMOBill(Int64 HInterID, ref string sReturn)
        {
            try
            {
                oCn.RunProc("exec h_p_Sc_ICMOCheck_K3  " + HInterID.ToString());
                sReturn = "";
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                throw (e);
            }
        }
 
        /// <summary>
        /// 修改任务单 测试状态
        /// </summary>
        /// <param name="HICMOID"></param>
        /// <param name="sReturn"></param>
        /// <returns></returns>
        public bool UpdateTestStatus(long HICMOID, string sStatus, ref string sReturn)
        {
            try
            {
                oCn.BeginTran();
                //增加主表
                oCn.RunProc("update h_v_K3_ICMOBill set HTestStatus='" + sStatus + "' where HInterID=" + HICMOID.ToString());
                //
                sReturn = "修改状态成功!";
                oCn.Commit();
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                oCn.RollBack();
                return false;
            }
        }
 
    }
 
}