zgq
2021-02-18 6da3110d95c36696e537af3eeb6b8d52b54e8798
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
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Web.Http;
using WebAPI.Models;
namespace WebAPI.Controllers
{
    /**
     * 找货单单
     */
    public class LookingForBillController : ApiController
    {
        private json objJsonResult = new json();
        public DataSet ds = new DataSet();
        public WebServer webserver = new WebServer();
        /// <summary>
        /// 根据包装单 返回此包装单内的相关信息
        /// </summary>
        /// <returns></returns>
        [Route("LookingFor/getPackUnionBillList")]
        [HttpGet]
        public object getPackUnionBillList(string HBarCode_Pack)
        {
            try
            {
                ds = getPackUnionBillList_s(HBarCode_Pack);
                if (ds == null || Pub_Class.ClsPub.isLong(ds.Tables[0].Rows[0][0]) == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = ds.Tables[0].Rows[0][1].ToString();
                    objJsonResult.data = ds.Tables[0];
                    return objJsonResult;
                }
                else
                { 
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "扫码成功!";
                    objJsonResult.data = ds.Tables[0];
                    return objJsonResult; 
                }
            }
            catch (Exception ex)
            { 
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "没有返回任何记录!" + ex.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
 
        /// <summary>
        /// 根据实物条码验证状态
        /// </summary>
        /// <returns></returns>
        [Route("LookingFor/getPackUnionBillListDetailed")]
        [HttpGet]
        public object getPackUnionBillListDetailed(string HBarCode)
        {
            try
            {
                ds = getPackUnionBillListDetailed_s(HBarCode);
                if (ds == null || Pub_Class.ClsPub.isLong(ds.Tables[0].Rows[0][0]) == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = ds.Tables[0].Rows[0][1].ToString();
                    objJsonResult.data = ds.Tables[0];
                    return objJsonResult;
                }
                else
                {
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = ds.Tables[0].Rows[0][1].ToString();
                    objJsonResult.data = ds.Tables[0];
                    return objJsonResult;
                }
            }
            catch (Exception ex)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "没有返回任何记录!" + ex.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
 
        /// <summary>
        /// 根据销售订单 返回此销售订单内的相关信息
        /// </summary>
        /// <returns></returns>
        [Route("LookingFor/getSellOrderList")]
        [HttpGet]
        public object getSellOrderList(string HSourceBillNo)
        {
            try
            {
                string sWhere = " Where HSourceBillNo = '" + HSourceBillNo.Trim() + "'";
                ds = getSellOrderList_s(sWhere);
                if (ds == null || ds.Tables[0].Rows.Count <= 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "没有返回任何记录!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
                {
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "返回记录成功!";
                    objJsonResult.data = ds.Tables[0];
                    return objJsonResult;
                }
            }
            catch (Exception ex)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "没有返回任何记录!" + ex.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
 
        /// <summary>
        /// 根据实物条码 返回相关信息
        /// </summary>
        /// <returns></returns>
        [Route("LookingFor/getBarCodeDetails")]
        [HttpGet]
        public object getBarCodeDetails(string HBarCode)
        {
            try
            {
                string sWhere = " Where HBarCode = '" + HBarCode.Trim() + "'";
                ds = getBarCodeDetails_s(sWhere);
                if (ds == null || ds.Tables[0].Rows.Count <= 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "没有返回任何记录!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
                {
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "返回记录成功!";
                    objJsonResult.data = ds.Tables[0];
                    return objJsonResult;
                }
            }
            catch (Exception ex)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "没有返回任何记录!" + ex.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
 
        /// <summary>
        /// 生成下架找货单
        /// </summary>
        /// <returns></returns>
        [Route("LookingFor/set_SaveLookingForBill_Json")]
        [HttpPost]
        public object set_SaveLookingForBill_Json([FromBody]JObject oMain)
        {
            string oMainData = oMain["oMain"].ToString();
            oMainData = oMainData.Substring(8,oMainData.Length-9);
            SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
            try
            {
                List<LookingForBill> lsmain = new List<LookingForBill>();
                ListModels oListModels = new ListModels();
                List<LookingForBill> list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<LookingForBill>>(oMainData);
                oCN.BeginTran();
                var mainSql = "Insert Into LookingForBillMain " +
                    "(HInterID,HBillNo,HSourceInterID,HSourceBillNo,HCreateBy)" +
                    " values" +
                    "(" + list[0].HInterID + ",'" + list[0].HBillNo + "'," + list[0].HSourceInterID + ",'" + list[0].HSourceBillNo + "','" + list[0].HMaker + "')";
                oCN.RunProc(mainSql);
                for (int i = 0; i < list.Count; i++)
                {
                    var subSql = "Insert Into LookingForBillSub " +
                    "(HWHID,HWHName,HSPID,HSPName,HBillType,HMTONo,HQty,HMaterID,HMaterName,HMaterNumber,HMaterModel,HBarCode,HGroupID,HGroup,HSourceID,HSource,HIsStatus,HStatus,HCreateBy,HMainItemID)" +
                    " values" +
                    "(" + list[i].HWHID + ",'" + list[i].HWHName + "'," + list[i].HSPID + ",'" + list[i].HSPName + "','1253','" + list[i].HMTONo + "',"+ list[i].HQty + ","
                    + list[i].HMaterID + ",'"+ list[i].HMaterName + "','"+ list[i].HMaterNumber + "','"+ list[i].HMaterModel + "','" + list[i].HBarCode + "',"
                    + list[i].HGroupID + ",'"+ list[i].HGroup + "',"+ list[i].HSourceID + ",'" + list[i].HSource + "',' ',' ','"+ list[i].HMaker + "',(select HItemID from LookingForBillMain where HBillNo = '"+ list[i].HBillNo + "'))";
                    oCN.RunProc(subSql);
                    var barCodeSql = "update Gy_BarCodeBill set HStatus='裁切中-" + list[i].HSource + "' where HBarCode = '"+ list[i].HBarCode + "'";
                    oCN.RunProc(barCodeSql);
                }
                oCN.Commit();
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "生成找货单成功!单据号为:" + list[0].HBillNo;
                objJsonResult.data = null;
                return objJsonResult;
            }
            catch (Exception e)
            {
                oCN.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "上传失败!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
 
        /// <summary>
        /// 生成上架归还单
        /// </summary>
        /// <returns></returns>
        [Route("LookingFor/set_SaveLookingForReturnBill_Json")]
        [HttpPost]
        public object set_SaveLookingForReturnBill_Json([FromBody] JObject oMain)
        {
            string oMainData = oMain["oMain"].ToString();
            oMainData = oMainData.Substring(8, oMainData.Length - 9);
            SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
            try
            {
                List<LookingForBill> lsmain = new List<LookingForBill>();
                ListModels oListModels = new ListModels();
                List<LookingForBill> list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<LookingForBill>>(oMainData);
                oCN.BeginTran();
                var mainSql = "Insert Into LookingForBillMain " +
                    "(HInterID,HBillNo,HSourceInterID,HSourceBillNo,HCreateBy)" +
                    " values" +
                    "(" + list[0].HInterID + ",'" + list[0].HBillNo + "'," + list[0].HSourceInterID + ",'" + list[0].HSourceBillNo + "','" + list[0].HMaker + "')";
                oCN.RunProc(mainSql);
                for (int i = 0; i < list.Count; i++)
                {
                    var subSql = "Insert Into LookingForBillSub " +
                    "(HWHID,HWHName,HSPID,HSPName,HBillType,HMTONo,HQty,HMaterID,HMaterName,HMaterNumber,HMaterModel,HBarCode,HGroupID,HGroup,HSourceID,HSource,HIsStatus,HStatus,HCreateBy,HMainItemID)" +
                    " values" +
                    "(" + list[i].HWHID + ",'" + list[i].HWHName + "'," + list[i].HSPID + ",'" + list[i].HSPName + "','1252','" + list[i].HMTONo + "'," + list[i].HQty + ","
                    + list[i].HMaterID + ",'" + list[i].HMaterName + "','" + list[i].HMaterNumber + "','" + list[i].HMaterModel + "','" + list[i].HBarCode + "',"
                    + list[i].HGroupID + ",'" + list[i].HGroup + "'," + list[i].HSourceID + ",'" + list[i].HSource + "',' ',' ','" + list[i].HMaker + "',(select HItemID from LookingForBillMain where HBillNo = '" + list[i].HBillNo + "'))";
                    oCN.RunProc(subSql);
                    var barCodeSql = "update Gy_BarCodeBill set HStatus='在库' where HBarCode = '" + list[i].HBarCode + "'";
                    oCN.RunProc(barCodeSql);
                }
                oCN.Commit();
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "生成归还单成功!单据号为:" + list[0].HBillNo;
                objJsonResult.data = null;
                return objJsonResult;
            }
            catch (Exception e)
            {
                oCN.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "上传失败!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
 
        /// <summary>
        /// 根据仓位二维码带出仓库仓位相关信息
        /// </summary>
        /// <returns></returns>
        [Route("LookingFor/getSpName_Json")]
        [HttpGet]
        public object getSpName_Json(string HBarCode)
        {
            try
            {
                string[] sArray = HBarCode.Remove(0, 3).Split(';');
                long HSpID = DBUtility.ClsPub.isLong(sArray[1]);
                long HWHID = DBUtility.ClsPub.isLong(sArray[0]);
                string sWhere = " Where HWHID = " + HWHID + " and HItemID = "+ HSpID + "";
                ds = getSpName_Json_s(sWhere);
                if (ds == null || ds.Tables[0].Rows.Count <= 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "没有返回任何记录!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
                {
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "返回记录成功!";
                    objJsonResult.data = ds.Tables[0];
                    return objJsonResult;
                }
            }
            catch (Exception ex)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "没有返回任何记录!" + ex.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
 
 
        #region sql语句
 
        public static DataSet getPackUnionBillList_s(string HBarCode_Pack)
        {
            return new SQLHelper.ClsCN().RunProcReturn("EXEC h_p_Kf_getPackUnionBillList " + "'"+HBarCode_Pack+"'", "h_p_Kf_getPackUnionBillList");
        }
 
        public static DataSet getPackUnionBillListDetailed_s(string HBarCode)
        {
            return new SQLHelper.ClsCN().RunProcReturn("EXEC h_p_Kf_getPackUnionBillListDetailed " + "'" + HBarCode + "'", "h_p_Kf_getPackUnionBillListDetailed");
        }
 
        public static DataSet getSellOrderList_s(string sWhere)
        {
            return new SQLHelper.ClsCN().RunProcReturn("select * from h_v_getSellOrderList_s " + sWhere, "h_v_getSellOrderList_s");
        }
 
        public static DataSet getBarCodeDetails_s(string sWhere)
        {
            return new SQLHelper.ClsCN().RunProcReturn("select * from h_v_getBarCodeDetails_s " + sWhere, "h_v_getBarCodeDetails_s");
        }
 
        public static DataSet getSpName_Json_s(string sWhere)
        {
            return new SQLHelper.ClsCN().RunProcReturn("select * from h_v_IF_StockPlace " + sWhere, "h_v_IF_StockPlace");
        }
 
        #endregion
 
    }
}