1
wangbin
2024-07-08 4548e24916ac5f63eef736cabdcd634864f8de16
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
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using WebAPI;
using WebAPI.Models;
 
namespace WebAPI.Controllers
{
    public class Sc_AssemblyBillController : ApiController
    {
        public Int64 HInterID;                  //本单ID
        public string HBillNo;                  //本单单号
        public string HBillType = "3727";       //单据类型
        public WebServer webserver =new WebServer();
        public DataSet ds =new DataSet();
        string sBillNo = "";
        Int64 sInterID = 0;
        string sICMOBillNo = "";
        string sCPBarCode = "";
        Int64 sCPMaterID = 0;
        string sCPMaterName = "";
        private json objjson = new json();
        SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
 
        //扫描成品条码
        [Route("Assembly/Get_Assembly_CPBarCode_Json")]
        [HttpGet]
        public object Get_Assembly_CPBarCode_Json(string sBarCode,string sBillType)
        {
            try
            {
                DataTable dt_Main = new DataTable("Json");
                dt_Main.Columns.Add("sICMOBillNo", typeof(string));
                dt_Main.Columns.Add("sCPBarCode", typeof(string));
                dt_Main.Columns.Add("sCPMaterID", typeof(Int64));
                dt_Main.Columns.Add("sCPMaterName", typeof(string));
                dt_Main.Columns.Add("sInterID", typeof(Int64));
                dt_Main.Columns.Add("sBillNo", typeof(string));
 
 
 
                if (webserver.Get_Assembly_CPBarCode(sBarCode, sBillType, ref sICMOBillNo, ref sCPBarCode, ref sCPMaterID, ref sCPMaterName, ref sBillNo, ref sInterID, ref DBUtility.ClsPub.sErrInfo))
                {
                    //---------创建新行------------------------
                    DataRow dr_main = dt_Main.NewRow();//创建新行 
                    dt_Main.Rows.Add(dr_main);//将新行加入到表中
                    dr_main["sICMOBillNo"] = DBUtility.ClsPub.isStrNull(sICMOBillNo);
                    dr_main["sCPBarCode"] = DBUtility.ClsPub.isStrNull(sCPBarCode);
                    dr_main["sCPMaterID"] = DBUtility.ClsPub.isLong(sCPMaterID);
                    dr_main["sCPMaterName"] = DBUtility.ClsPub.isStrNull(sCPMaterName);
                    dr_main["sInterID"] = DBUtility.ClsPub.isLong(sInterID);
                    dr_main["sBillNo"] = DBUtility.ClsPub.isStrNull(sBillNo);
 
                    objjson.code = "0";
                    objjson.count = 1;
                    objjson.Message = "获取成功";
                    objjson.data = dt_Main;
                    return objjson;
                }
                else
                {
                    objjson.code = "0";
                    objjson.count = 0;
                    objjson.Message = "获取失败" + DBUtility.ClsPub.sErrInfo;
                    objjson.data = null;
                    return objjson;
                }
            }
            catch (Exception e)
            {
 
                objjson.code = "0";
                objjson.count = 0;
                objjson.Message = "获取失败" + e.ToString();
                objjson.data = null;
                return objjson;
            }
               
        }
        //扫描配件条码
        [Route("Assembly/Get_Assembly_PJBarCode_Json")]
        [HttpGet]
        public object Get_Assembly_PJBarCode_Json(string sPJCode, string sCPCode, long sInterID, string sBillNo, string sMaker, long HWorkerID, string HSNNumber)
        {
            try
            {
                DataTable dt_Main = new DataTable("Json");
                dt_Main.Columns.Add("sPJCode", typeof(string));
                dt_Main.Columns.Add("sCPCode", typeof(string));
                dt_Main.Columns.Add("sInterID", typeof(Int64));
                dt_Main.Columns.Add("sBillNo", typeof(string));
                dt_Main.Columns.Add("sMaker", typeof(string));
                dt_Main.Columns.Add("HWorkerID", typeof(Int64));
                dt_Main.Columns.Add("HSNNumber", typeof(string));
 
                if (webserver.Get_Assembly_PJBarCode(sPJCode, sCPCode, sInterID, sBillNo, sMaker, HWorkerID, HSNNumber, ref DBUtility.ClsPub.sErrInfo))
                {
                    //---------创建新行------------------------
                    DataRow dr_main = dt_Main.NewRow();//创建新行 
                    dt_Main.Rows.Add(dr_main);//将新行加入到表中
                    dr_main["sPJCode"] = DBUtility.ClsPub.isStrNull(sPJCode);
                    dr_main["sCPCode"] = DBUtility.ClsPub.isStrNull(sCPCode);
                    dr_main["sInterID"] = DBUtility.ClsPub.isLong(sInterID);
                    dr_main["sBillNo"] = DBUtility.ClsPub.isStrNull(sBillNo);
                    dr_main["sMaker"] = DBUtility.ClsPub.isStrNull(sMaker);
                    dr_main["HWorkerID"] = DBUtility.ClsPub.isLong(HWorkerID);
                    dr_main["HSNNumber"] = DBUtility.ClsPub.isStrNull(HSNNumber);
 
                    objjson.code = "0";
                    objjson.count = 1;
                    objjson.Message = "获取成功";
                    objjson.data = dt_Main;
                    return objjson;
                }
                else
                {
                    objjson.code = "0";
                    objjson.count = 0;
                    objjson.Message = "获取失败" + DBUtility.ClsPub.sErrInfo;
                    objjson.data = null;
                    return objjson;
                }
            }
            catch (Exception e)
            {
 
                objjson.code = "0";
                objjson.count = 0;
                objjson.Message = "获取失败" + e.ToString();
                objjson.data = null;
                return objjson;
            }
               
        }
 
        [Route("Assembly/DisBillEntryList_Mate_Webs_Json")]
        [HttpGet]
        public object DisBillEntryList_Mate_Webs_Json(long HInterID, string sBillType, string sWhere)
        {
            try
            {
                ds = webserver.GetSc_AssemblyBill(HInterID, sBillType, sWhere);
                if (ds == null || ds.Tables[0].Rows.Count <= 0)
                {
 
                    objjson.code = "0";
                    objjson.count = 0;
                    objjson.Message = "没有返回任何记录!";
                    objjson.data = null;
                    return objjson;
                    //DBUtility.ClsPub.MessageBeep((int)DBUtility.ClsPub.BeepType.Warning);
                }
                else
                {
                    objjson.code = "0";
                    objjson.count = 1;
                    objjson.Message = "获取信息成功!";
                    objjson.data = ds.Tables[0];
                    return objjson;
                }
            }
            catch (Exception e)
            {
 
                objjson.code = "0";
                objjson.count = 0;
                objjson.Message = "没有返回任何记录!" + e.ToString();
                objjson.data = null;
                return objjson;
            }
        }
 
 
        #region  产线组装追溯单
        [Route("Sc_AssemblyBill/HBardCodeList")]
        [HttpGet]
        public object HBardCodeList(string HBarCode, string user,string HICMOBillNo)
        {
            try
            {
                //查看权限
                if (!DBUtility.ClsPub.Security_Log("Sc_AssemblyBill_Edit", 1, false, user))
                {
                    objjson.code = "0";
                    objjson.count = 0;
                    objjson.Message = "无保存权限!";
                    objjson.data = null;
                    return objjson;
                }
                if (HICMOBillNo == "" || HICMOBillNo == null)
                {
                    ds = oCN.RunProcReturn(@"select  bard.HSourceInterID,bard.HSourceEntryID,b.FMUSTQTY,a.FMOBILLNO,FERPCLSID,t5.FNAME HMaterName_z,t5.FSPECIFICATION HMaterModel_z ,m.HItemID,b.FMATERIALID,m.HName HMaterName,m.HNumber HMaterNumber,m.HModel HMaterModel,m1.HItemID HMaterID
from AIS20210811135644..T_PRD_PPBOM a
join AIS20210811135644..T_PRD_PPBOMENTRY b on a.FID = b.FID
join AIS20210811135644..T_BD_MATERIAL t3 on a.FMATERIALID = t3.FMATERIALID
join AIS20210811135644..T_BD_MATERIAL t31 on b.FMATERIALID = t31.FMATERIALID
join AIS20210811135644..T_BD_MATERIAL_L t5 on b.FMATERIALID = t5.FMATERIALID and FLOCALEID=2052
join AIS20210811135644..t_BD_MaterialBase t4 on t5.FMATERIALID = t4.FMATERIALID
join Gy_BarCodeBill bard on a.FMOBILLNO=bard.HSourceBillNo 
join Gy_Material m on bard.HMaterID=m.HItemID and t3.FNUMBER=m.HNumber
join Gy_Material m1 on t31.FNUMBER=m1.HNumber and t31.FUSEORGID=m1.HUSEORGID
where bard.HBarCode='" + HBarCode + "'  AND t4.FERPCLSID in ('1', '3')", "Gy_BarCodeBill");
                    if (ds.Tables[0].Rows.Count == 0)
                    {
                        objjson.code = "0";
                        objjson.count = 0;
                        objjson.Message = "请先扫产品条码!";
                        objjson.data = null;
                        return objjson;
                    }
                    else
                    {
                        objjson.code = "1";
                        objjson.count = 1;
                        objjson.Message = "";
                        objjson.data = ds.Tables[0];
                    }
                }
                else
                {
                    ds = oCN.RunProcReturn(@"select  a.FMOBILLNO,FERPCLSID ,t4.FMATERIALID, a.FMATERIALID from AIS20210811135644..T_PRD_PPBOM a
                    join AIS20210811135644..T_PRD_PPBOMENTRY b on a.FID=b.FID
                    JOIN AIS20210811135644..T_BD_MATERIAL T6 ON b.FMATERIALID = T6.FMATERIALID
                    join AIS20210811135644..t_BD_MaterialBase t4 on b.FMATERIALID = t4.FMATERIALID
                    left join Gy_Material m on t6.FNUMBER=m.HNumber and m.HUSEORGID=a.FPRDORGID
                    where a.FMOBILLNO ='" + HICMOBillNo + "' and m.HItemID=(select HMaterID from Gy_BarCodeBill where HBarCode = '" + HBarCode + "' )", "ds2");
 
                    if (ds.Tables[0].Rows.Count == 0)
                    {
                        objjson.code = "0";
                        objjson.count = 0;
                        objjson.Message = "配件不属于该生产订单!";
                        objjson.data = null;
                        return objjson;
                    }
 
                    ds = oCN.RunProcReturn(@"select  HQty,HSourceBillNo,m.HName HMaterName,m.HItemID HMaterID from Gy_BarCodeBill bard
join Gy_Material m on bard.HMaterID=m.HItemID 
where  HBarCode='" + HBarCode + "'", "ds3");
 
                    objjson.code = "1";
                    objjson.count = 1;
                    objjson.Message = "";
                    objjson.data = ds.Tables[0];
                }
                return objjson;
            }
            catch (Exception e)
            {
 
                objjson.code = "0";
                objjson.count = 0;
                objjson.Message = "没有返回任何记录!" + e.ToString();
                objjson.data = null;
                return objjson;
            }
        }
        #endregion
 
        #region 产线组装追溯单保存
        [Route("Sc_AssemblyBill/AddBill")]
        [HttpPost]
        public object AddBill([FromBody] JObject sMainSub)
        {
            var _value = sMainSub["sMainSub"].ToString();
            string msg1 = _value.ToString();
            oCN.BeginTran();
            //保存主表
            objjson = AddBillMain(msg1);
            if (objjson.code == "0")
            {
                oCN.RollBack();
                objjson.code = "0";
                objjson.count = 0;
                objjson.Message = objjson.Message;
                objjson.data = null;
                return objjson;
            }
            oCN.Commit();
            objjson.code = "1";
            objjson.count = 1;
            objjson.Message = "新增单据成功!";
            objjson.data = null;
            return objjson;
        }
        Models.ClsSc_AssemblyBillMain omodel = new Models.ClsSc_AssemblyBillMain();//基本资料
        public json AddBillMain(string msg1)
        {
            string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
            string msg2 = sArray[0].ToString();
            string msg3 = sArray[1].ToString();
            int OperationType = int.Parse(sArray[2].ToString());//类型
            string user = sArray[3].ToString();//用户名
 
            try
            {
                //判断是否有编辑权限
                if (!DBUtility.ClsPub.Security_Log("Sc_AssemblyBill_Edit", 1, false, user))
                {
                    objjson.code = "0";
                    objjson.count = 0;
                    objjson.Message = "无权限编辑!";
                    objjson.data = null;
                    return objjson;
                }
                omodel = Newtonsoft.Json.JsonConvert.DeserializeObject<ClsSc_AssemblyBillMain>(msg2);
                //JSON序列化转换字典集合
                List<Dictionary<string, string>> list = new List<Dictionary<string, string>>();
                List<object> jb = JsonConvert.DeserializeObject<List<object>>(msg3);
                foreach (JObject item in jb)
                {
                    Dictionary<string, string> dic = new Dictionary<string, string>();
                    foreach (var itm in item.Properties())
                    {
                        dic.Add(itm.Name, itm.Value.ToString());
                    }
                    list.Add(dic);
                }
 
                if (OperationType == 1)//新增临时表源单表
                {
                    for (int i = 0; i < list.Count; i++)
                    {
                        //临时配件表
                        oCN.RunProc("Insert Into Sc_AssemblyBill_BindSourceTemp   " +
                        "(HInterID,HEntryID,HBillNo_bak,HSourceBillNo,HSourceInterID,HMaterID" +
                        ",HQtyMust,HProdOrgID,HSourceEntryID,HSourceBillType,HAuxPropID,HProcID,HQty,HBatchNo,HMTONo,HPlanMode) " +
                        " values(" + omodel.HInterID.ToString() + "," + (i+1) + ",'" + omodel.HBillNo.ToString() + "','" + omodel.HICMOBillNo.ToString() + "',0," + list[i]["HMaterID"].ToString() +
                        ",'" + list[i]["HQty"].ToString() + "','" + list[i]["HPRDORGID"].ToString() + "',0,'',0,0,0,'','','') ");
                    }
                }
                else if (OperationType == 2)//新增配件扫码表
                {
                    for (int i = 0; i < list.Count; i++)
                    {
                        if (list[i]["HBarCode"].ToString() != "")
                        {
                            ds = oCN.RunProcReturn("select * from Sc_AssemblyBill_BindBarCodeTemp where HSourceBillNo='" + omodel.HICMOBillNo.ToString() + "' and HBarCode='" + list[i]["HBarCode"].ToString() + "' and HBillNo_bak='" + omodel.HBillNo.ToString() + "'", "Sc_AssemblyBill_BindBarCodeTemp");
                            if (ds.Tables[0].Rows.Count > 0) {
                                objjson.code = "0";
                                objjson.count = 0;
                                objjson.Message ="该条码已扫入,无须再扫!";
                                objjson.data = null;
                                return objjson;
                            }
                            //临时记录表
                            oCN.RunProc("Insert Into Sc_AssemblyBill_BindBarCodeTemp   " +
                            "(HInterID,HEntryID,HBillNo_bak,HSourceBillNo,HSourceInterID,HMaterID" +
                            ",HBarCode,HQty,HProdOrgID,HSourceEntryID,HSourceBillType,HAuxPropID,HProcID,HBatchNo,HMTONo,HPlanMode) " +
                            " values(" + omodel.HInterID.ToString() + "," + (i + 1) + ",'" + omodel.HBillNo.ToString() + "','" + omodel.HICMOBillNo.ToString() + "',0," + list[i]["HMaterID"].ToString() +
                            ",'" + list[i]["HBarCode"].ToString() + "','" + list[i]["HEQty"].ToString() + "','" + list[i]["HPRDORGID"].ToString() + "',0,'',0,0,'','','') ");
                        }
                    }
                }
                else if (OperationType == 3)//新增主子表
                {
                    //保存生产组装单主表
                    string sql = $@"Insert Into Sc_AssemblyBillMain(HYear,HPeriod,HBillType,HBillSubType,HInterID,HDate
,HBillNo,HBillStatus,HMaker,HMakeDate,HMainSourceInterID,HMainSourceEntryID,HMainSourceBillNo
,HICMOInterID,HICMOBillNo,HBarCode_P,HMaterID,HUnitID,HAssemblyStatus,HProdOrgID)
values('{DateTime.Now.Year}','{DateTime.Now.Month}','3727','3727',{omodel.HInterID.ToString()},getdate()
,'{omodel.HBillNo.ToString()}','1','{user}',getdate(),{omodel.HICMOInterID.ToString()},{omodel.HICMOEntryID.ToString()},'{omodel.HICMOBillNo.ToString()}'
,{omodel.HICMOInterID.ToString()},'{omodel.HICMOBillNo.ToString()}','{omodel.HBarCode_P.ToString()}',{omodel.HMaterID},0,'{omodel.HAssemblyStatus}',{omodel.HProdOrgID})";
                    oCN.RunProc(sql);
 
                    ds = oCN.RunProcReturn("select * from Sc_AssemblyBill_BindBarCodeTemp where HSourceBillNo='" + omodel.HICMOBillNo.ToString() + "' and HInterID='" + omodel.HInterID + "' and HBillNo_bak='" + omodel.HBillNo.ToString() + "'", "Sc_AssemblyBill_BindBarCodeTemp");
 
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        int HMaterID = int.Parse(ds.Tables[0].Rows[i]["HMaterID"].ToString());
                        double HQty = double.Parse(ds.Tables[0].Rows[i]["HQty"].ToString());
                        string HBarCode = ds.Tables[0].Rows[i]["HBarCode"].ToString();
                        string sq2 = $@"Insert Into Sc_AssemblyBillSub(HInterID,HBillNo_bak,HEntryID,HSourceInterID,HSourceEntryID,HSourceBillNo
,HSourceBillType,HMaterID,HSourceID,HEquipID,HUnitID,HQty
,HGroupID,HWorkerID,HScanDate,HBarCode,HBarCode_P,HSNNumber)
values({omodel.HInterID},'{omodel.HBillNo}',{(i + 1)},0,0,''
,'',{HMaterID},0,0,0,{HQty}
,0,0,getdate(),'{HBarCode}','{omodel.HBarCode_P}','') ";
                        oCN.RunProc(sq2);
                    }
                }
 
                objjson.code = "1";
                objjson.count = 1;
                objjson.Message = null;
                objjson.data = null;
                return objjson;
            }
            catch (Exception e)
            {
                objjson.code = "0";
                objjson.count = 0;
                objjson.Message = "Exception!" + e.ToString();
                objjson.data = null;
                return objjson;
            }
        }
        #endregion
 
        #region 产线组装追溯单 查询
        [Route("Sc_AssemblyBill/Sc_AssemblyBillAddList")]
        [HttpGet]
        public object Sc_AssemblyBillAddList(string sWhere)
        {
            try
            {
                ds = oCN.RunProcReturn(@"select * from  h_v_Sc_AssemblyBillList where 1=1  " + sWhere, "h_v_Sc_AssemblyBillList");
 
                objjson.code = "1";
                objjson.count = 1;
                objjson.Message = "";
                objjson.data = ds.Tables[0];
                return objjson;
            }
            catch (Exception e)
            {
 
                objjson.code = "0";
                objjson.count = 0;
                objjson.Message = "没有返回任何记录!" + e.ToString();
                objjson.data = null;
                return objjson;
            }
        }
        #endregion
 
        [Route("Assembly/Delete_Json")]
        [HttpGet]
        public object Delete_Json(long sInterID,string sBarCode)
        {
            string sErrMsg=string.Empty;
            try
            {
                if (webserver.set_DelSc_AssemblyBill(sInterID, sBarCode,ref sErrMsg))
                {
                    objjson.code = "0";
                    objjson.count = 1;
                    objjson.Message = "删除成功!";
                    objjson.data = null;
                    return objjson;
                }
                else
                {
                    objjson.code = "0";
                    objjson.count = 0;
                    objjson.Message = "删除失败!";
                    objjson.data = null;
                    return objjson;
                }
            }
            catch (Exception)
            {
 
                objjson.code = "0";
                objjson.count = 0;
                objjson.Message = "删除失败!";
                objjson.data = null;
                return objjson;
            }
 
        }
 
    }
 
 
}