YL
2022-01-10 c6313bfb75192d133696bea2a60a18e8e23b663f
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
using DBUtility;
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 System.Web.Script.Serialization;
using ViewAPI;
using WebAPI.Models;
 
namespace WebAPI.Controllers.博日自动扫码线
{
    public class ScanlineAPIController : ApiController
    {
        private jsonScanline objJsonResult = new jsonScanline();
        public DataSet ds = new DataSet();
        public DataSet ds0 = new DataSet();
        SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
 
        #region 生成箱码接口
        [Route("packagebarcode/create")]
        [HttpGet]
        public object create(int num)
        {
            try
            {
                objJsonResult.data = new List<barcode>();
                for (int i = 0; i < num; i++)
                {
                    barcode jsn = new barcode();
                    //string prefix = "ZM"; 
                    //string date = DateTime.Now.ToString("yyMMddhh"); 
                    //string custom = "12"; 
                    //int nm = i; 
                    //string result = prefix + date + custom + nm.ToString().PadLeft(4, '0');
 
                    //条码前缀 = 箱码前缀 + 年 + 月 + 日
                    string sDate = DateTime.Now.ToString("yyyy-MM-dd");
                    string sYear = ClsPub.isDate(sDate).Year.ToString().Substring(2, 2);
                    string sPeriod = "0" + ClsPub.isDate(sDate).Month.ToString();
                    sPeriod = sPeriod.Substring(sPeriod.Length - 2, 2);
                    string sDay = "0" + ClsPub.isDate(sDate).Day.ToString();
                    sDay = sDay.Substring(sDay.Length - 2, 2);
                    string  sTMNumber ="ZX"+ sYear + sPeriod + sDay;
                    ds = oCN.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");    //获取最大流水号
                    int LSH = ClsPub.isInt(ds.Tables[0].Rows[0][0])+1;  //流水号加1
                    string TM = sTMNumber + LSH;
                    jsn.packagebarcode = TM;
                    oCN.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
                    objJsonResult.data.Add(jsn);
                }
                objJsonResult.status = 0;
                objJsonResult.msg = "查询数据成功!";
                objJsonResult.data =objJsonResult.data;
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.status =-1;
                objJsonResult.msg = "生成箱条码失败!";
                objJsonResult.data =null;
                return objJsonResult;
            }
        }
        #endregion
 
        #region 箱条码绑定关系提交接口
        [Route("packagebarcode/pack")]
        [HttpPost]
        public object pack([FromBody] JObject msg)
        {
            try
            {
                Log.LogInfo(msg.ToString()); //记录提交数据
                JavaScriptSerializer js = new JavaScriptSerializer();   //实例化一个能够序列化数据的类
                ScanLineCode list = js.Deserialize<ScanLineCode>(msg.ToString());    //将json数据转化为对象类型并赋值给list
                if (list.billno != "" && list.billno != null)  //任务单号,非必须,非空则校验barcodes里barcode是否由此任务单制作生成的
                {
                    ds = oCN.RunProcReturn("Select HBarCode barcode,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType from Gy_BarCodeBill where HSourceBillNo='" + list.billno.ToString().Trim()+"'  Order by HItemID ", "Gy_BarCodeBill");
                    if (ds == null || ds.Tables[0].Rows.Count == 0)
                    {
                        objJsonResult.status = -1;
                        objJsonResult.msg = "当前订单无绑定条码!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    List<string> NameList = (from r in ds.Tables[0].AsEnumerable() select r.Field<string>("barcode")).ToList();
                    List<string> NameList1= list.barcodes.Select(t => t.barcode).ToList();
                    var strList = NameList1.Except(NameList).ToList();  //判断提交数据中条码是否存在于订单中
                    if (strList.Count > 0) 
                    {
                        string Str=String.Join(",", strList.ToArray());
                        objJsonResult.status = -1;
                        objJsonResult.msg = "条码:"+ Str.ToString()+" 不包含在订单:"+list.billno+"中!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }                
                }
                DLL.ClsSc_PackUnionBill oBill = new DLL.ClsSc_PackUnionBill();
                //判断箱码是否存在
                bool IsBarCodePack = oBill.IsBarCodePack(list.packagebarcode);
                if (IsBarCodePack == false) 
                {
                    objJsonResult.status = -1;
                    objJsonResult.msg = "箱码已存在,不能重复绑定!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                ds = oCN.RunProcReturn("Select * from Gy_BarCodeBill where HBarCode='" + list.packagebarcode.ToString().Trim() + "' and HStopflag='1'", "Gy_BarCodeBill");
                if (ds != null && ds.Tables[0].Rows.Count > 0)
                {
                    objJsonResult.status = -1;
                    objJsonResult.msg = "此箱条码已作废";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
                Models.ClsSc_PackUnionBillMain oItem = new ClsSc_PackUnionBillMain();
                oItem.HYear = DBUtility.ClsPub.isLong(DateTime.Now.Year);
                oItem.HPeriod = DBUtility.ClsPub.isLong(DateTime.Now.Month);
                oItem.HBillType = "3783";
                oItem.HBillSubType = "3783";
                oItem.HDate= DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
                oItem.HBillNo = DBUtility.ClsPub.CreateBillCode(oItem.HBillType, ref DBUtility.ClsPub.sExeReturnInfo, true);
                oItem.HBillStatus = 1;
                oItem.HCheckItemNowID = 0;
                oItem.HCheckItemNextID = 0;
                oItem.HCheckFlowID = 0;
                oItem.HRemark = "自动包装线生成箱条码";
                oItem.HBacker = "";
                oItem.HBackDate = "";
                oItem.HMaker = "";
                oItem.HMakeDate = DBUtility.ClsPub.isStrNull(DateTime.Now.ToString("yyyy-MM-dd"));
                oItem.HChecker = "";
                oItem.HCheckDate = "";
                oItem.HUpDater = "";
                oItem.HUpDateDate = "";
                oItem.HCloseMan = "";
                oItem.HCloseDate = "";
                oItem.HCloseType = false;
                oItem.HDeleteMan = "";
                oItem.HDeleteDate = "";
                oItem.HICMOInterID = 0;
                oItem.HICMOBillNo = "";
                oItem.HBarCode_Pack= list.packagebarcode;
                oItem.HMaterID = 0;
                oItem.HUnitID = 0;
                oItem.HUseFlag =false;   //有效状态
                oBill.omodel = oItem;
                for (int i = 0; i < list.barcodes.Count; i++)
                {
                    //判断条码是否存在
                    bool IsBarCode = oBill.IsBarCodePack(list.barcodes[i].barcode);
                    if (IsBarCodePack == false)
                    {
                        objJsonResult.status = -1;
                        objJsonResult.msg = "条码已存在,不能重复绑定!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    Models.ClsSc_PackUnionBillSub oItemSub = new ClsSc_PackUnionBillSub();
                    ds0 = oCN.RunProcReturn("Select HBarCode,HMaterID,HUnitID,HQty,HSourceID,HGroupID,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType from Gy_BarCodeBill where HSourceBillNo='" + list.billno.ToString().Trim() + "' and HBarCode='" + list.barcodes[i].barcode + "'  Order by HItemID ", "Gy_BarCodeBill");
                    oItemSub.HEntryID = i+1;
                    oItemSub.HMaterID = DBUtility.ClsPub.isLong(ds0.Tables[0].Rows[0]["HMaterID"].ToString());
                    oItemSub.HUnitID = DBUtility.ClsPub.isLong(ds0.Tables[0].Rows[0]["HUnitID"].ToString());
                    oItemSub.HQty = DBUtility.ClsPub.isDoule(ds0.Tables[0].Rows[0]["HQty"].ToString());
                    oItemSub.HSourceID = DBUtility.ClsPub.isLong(ds0.Tables[0].Rows[0]["HSourceID"].ToString());
                    oItemSub.HEquipID = 0;
                    oItemSub.HGroupID = DBUtility.ClsPub.isLong(ds0.Tables[0].Rows[0]["HGroupID"].ToString());
                    oItemSub.HWorkerID = 0; 
                    oItemSub.HBarCode = list.barcodes[i].barcode;
                    oItemSub.HBarCode_Pack = list.packagebarcode;
                    oItemSub.HCloseMan = "";
                    oItemSub.HCloseType = false;
                    oItemSub.HRemark = "";
                    oItemSub.HSourceInterID = DBUtility.ClsPub.isLong(ds0.Tables[0].Rows[0]["HSourceInterID"].ToString());
                    oItemSub.HSourceEntryID = DBUtility.ClsPub.isLong(ds0.Tables[0].Rows[0]["HSourceEntryID"].ToString());
                    oItemSub.HSourceBillNo = DBUtility.ClsPub.isStrNull(ds0.Tables[0].Rows[0]["HSourceBillNo"].ToString());
                    oItemSub.HSourceBillType = DBUtility.ClsPub.isStrNull(ds0.Tables[0].Rows[0]["HSourceBillType"].ToString());
                    oItemSub.HRelationQty = 0;
                    oItemSub.HRelationMoney = 0;
                    oBill.DetailColl.Add(oItemSub);
                }
                //保存
                //保存完毕后处理
                bool bResult;
                if (oBill.omodel.HInterID == 0)
                {
                    // bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
                    bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
                }
                else
                {
                    bResult = oBill.ModifyBill(oBill.omodel.HInterID, ref DBUtility.ClsPub.sExeReturnInfo);
                }
                if (bResult)
                {
                    objJsonResult.status = 0;
                    objJsonResult.msg = "success";
                    objJsonResult.data = null;
                    Log.LogSaveInfo("提交成功箱条码:"+ list.packagebarcode); //记录提交数据
                    return objJsonResult;
                }
                else
                {
                    objJsonResult.status = -1;
                    objJsonResult.msg = "保存失败!" + DBUtility.ClsPub.sExeReturnInfo;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
            }
            catch (Exception e)
            {
                objJsonResult.status =-1;
                objJsonResult.msg = e.Message;
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
 
        #region 箱条码取消绑定关系
        [Route("packagebarcode/cancel")]
        [HttpPost]
        public object cancel(string packagebarcode)
        {
            try
            {
                //判断是否入库 
                ds = oCN.RunProcReturn("select * from Sc_ScanLineInStock where HBarCode_Pack='" + packagebarcode + "'", "Sc_ScanLineInStock");
                if (ds!= null && ds.Tables[0].Rows.Count>0)
                {
                    objJsonResult.status = -1;
                    objJsonResult.msg = "该箱条码已入库不允许取消!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
                ds = oCN.RunProcReturn("Select 1 from Gy_BarCodeBill where HBarCode='" + packagebarcode.ToString().Trim() + "'", "Gy_BarCodeBill");
                if (ds == null && ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.status = -1;
                    objJsonResult.msg = "无效箱条码";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                ds = oCN.RunProcReturn("Select 1 from Gy_BarCodeBill where HBarCode='" + packagebarcode.ToString().Trim() + "' and HStopflag='1'", "Gy_BarCodeBill");
                if (ds != null && ds.Tables[0].Rows.Count>0)
                {
                    objJsonResult.status = -1;
                    objJsonResult.msg = "此箱条码已作废";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
                //
                oCN.BeginTran();
                //删除SUM主表
                oCN.RunProc("Delete From Sc_PackUnionBillSub_Sum  where HBarCode_Pack='" + packagebarcode.ToString() + "'");
                //删除子表
                oCN.RunProc("Delete From Sc_PackUnionBillSub  where HBarCode_Pack='"+ packagebarcode.ToString() + "'");
                //删除主表
                oCN.RunProc("Delete From Sc_PackUnionBillMain  where HBarCode_Pack='" + packagebarcode.ToString() + "'");
                //作废条码档案表
                oCN.RunProc("Update  Gy_BarCodeBill set HStopflag='1'  where HBarCode='"+ packagebarcode.ToString()+ "'");
 
                oCN.Commit();
 
                objJsonResult.status = 0;
                objJsonResult.msg = "success";
                objJsonResult.data = null;
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.status = -1;
                objJsonResult.msg = e.Message;
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
 
 
        [Route("packagebarcode/week")]
        [HttpPost]
        public object week(string tim)
        {
            try
            {
                GetWeekList list = new GetWeekList();
                //string aa=list.getWeek(Convert.ToDateTime(tim));
                string aa = list.GetCodeDateStr(Convert.ToDateTime(tim));
                objJsonResult.status = 0;
                objJsonResult.msg =aa.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.status = -1;
                objJsonResult.msg = e.Message;
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
    }
}