chenhaozhe
2 天以前 e4f1a927520a98fbc69dd63ef982dd890ba4fbdc
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
473
474
475
476
477
478
479
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.Models;
using SyntacticSugar.constant;
using Newtonsoft.Json;
 
// 组托单/装箱单控制器
namespace WebAPI.Controllers.仓存管理
{
    public class Sc_PackUnionBillMain_SettoPackingController : ApiController
    {
 
        private json objJsonResult = new json();
        public DataSet ds = new DataSet();
        public SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
 
        #region 获取组托单
        /// <summary>
        /// 获取组托单 有分页
        /// </summary>
        /// <returns>组托单列表</returns>
        [Route("Sc_PackUnionBillMain_SettoPackingController/get_PackUnionBill_SettoListPage")]
        [HttpGet]
        public object get_PackUnionBill_SettoListPage(string sWhere, string user, string page, string size)
        {
            try
            {
                List<object> columnNameList = new List<object>();
                if (!DBUtility.ClsPub.Security_Log("Sc_PackUnionBillMain_SettoPacking_Query", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无查看权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
                string swhere = (" and 单据类型 = '组托单'" + sWhere).Replace("'", "''");
                LogService.Write("exec h_p_Sc_PackUnionBillMain_SettoPackingListPage " + page + "," + size + ",N'" + swhere + "'");
                ds = oCN.RunProcReturn("exec h_p_Sc_PackUnionBillMain_SettoPackingListPage " + page + "," + size + ",N'"+ swhere + "'", "h_p_Sc_PackUnionBillMain_SettoPackingListPage");
 
 
                //添加列名
                foreach (DataColumn col in ds.Tables[0].Columns)
                {
                    Type dataType = col.DataType;
                    string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}";
                    columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名
                }
 
                objJsonResult.code = CodeConstant.SUCCEED;
                objJsonResult.count = int.Parse(ds.Tables[1].Rows[0]["count"].ToString());
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                objJsonResult.list = columnNameList;
                return objJsonResult;
            }
            catch (Exception ex)
            {
                objJsonResult.code = CodeConstant.FAIL;
                objJsonResult.count = CountConstant.FAIL;
                objJsonResult.Message = "没有返回任何记录!" + ex.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
 
        #region 获取装箱单
        /// <summary>
        /// 获取装箱单 有分页
        /// </summary>
        /// <returns>装箱单列表</returns>
        [Route("Sc_PackUnionBillMain_SettoPackingController/get_PackUnionBill_PackingListPage")]
        [HttpGet]
        public object get_PackUnionBill_PackingListPage(string sWhere, string user, string page, string size)
        {
            try
            {
                List<object> columnNameList = new List<object>();
                if (!DBUtility.ClsPub.Security_Log("Sc_PackUnionBillMain_SettoPacking_Query", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无查看权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
                string swhere = (" and 单据类型 = '装箱单'" + sWhere).Replace("'", "''");
                LogService.Write("exec h_p_Sc_PackUnionBillMain_SettoPackingListPage " + page + "," + size + ",N'" + swhere + "'");
                ds = oCN.RunProcReturn("exec h_p_Sc_PackUnionBillMain_SettoPackingListPage " + page + "," + size + ",N'" + swhere + "'", "h_p_Sc_PackUnionBillMain_SettoPackingListPage");
 
 
                //添加列名
                foreach (DataColumn col in ds.Tables[0].Columns)
                {
                    Type dataType = col.DataType;
                    string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}";
                    columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名
                }
 
                objJsonResult.code = CodeConstant.SUCCEED;
                objJsonResult.count = int.Parse(ds.Tables[1].Rows[0]["count"].ToString());
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                objJsonResult.list = columnNameList;
                return objJsonResult;
            }
            catch (Exception ex)
            {
                objJsonResult.code = CodeConstant.FAIL;
                objJsonResult.count = CountConstant.FAIL;
                objJsonResult.Message = "没有返回任何记录!" + ex.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
 
        [Route("Sc_PackUnionBillMain_SettoPackingController/AuditPackUnionBill_Packing")]
        [HttpGet]
        public object AuditPackUnionBill_Packing(string HInterID, string user, int Type)
        {
            try
            {
                //判断是否有审核权限
                if (!DBUtility.ClsPub.Security_Log("Sc_PackUnionBillMain_SettoPacking_Check", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无权限审核!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
                if (string.IsNullOrWhiteSpace(HInterID))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "HInterID为空!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
 
                oCN.BeginTran();//开始事务
                ds = oCN.RunProcReturn("select top 1 HInterID,HChecker from Sc_PackUnionBillMain where HInterID=" + HInterID, "Sc_PackUnionBillMain");
                if(ds.Tables.Count < 1)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "单据不存在!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                if (Type == 1)  //审核判断
                {
                    if (string.IsNullOrWhiteSpace(ds.Tables[0].Rows[0]["HChecker"].ToString()) == false)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "单据已审核!不能再次审核!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                if (Type == 2) //反审核判断
                {
                    if (string.IsNullOrWhiteSpace(ds.Tables[0].Rows[0]["HChecker"].ToString()) == true)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "单据未审核!不需要反审核!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
 
                //Type 1 审核  2  反审核
                if (Type == 1)
                {
                    //审核前控制=========================================
                    ds = oCN.RunProcReturn("Exec h_p_Sc_PackUnionBillMain_SettoPacking_BeforeCheckCtrl " + HInterID + ",'" + user + "'", "h_p_Sc_PackUnionBillMain_SettoPacking_BeforeCheckCtrl");
                    if (ds == null)
                    {
                        oCN.RollBack();
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "审核前判断失败!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    if (DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBack"]) != "0")
                    {
                        oCN.RollBack();
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "审核失败!" + DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBackRemark"]);
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    //=========================================================  
                    oCN.RunProc("update Sc_PackUnionBillMain set HChecker=N'" + user + "',HCheckDate=getdate() where HInterID=" + HInterID);
                    
                    //审核后控制=========================================
                    DataSet ds2 = oCN.RunProcReturn("Exec h_p_Sc_PackUnionBillMain_SettoPacking_AfterCheckCtrl " + HInterID + ",'" + user + "'", "h_p_Sc_PackUnionBillMain_SettoPacking_AfterCheckCtrl");
                    if (ds2 == null)
                    {
                        oCN.RollBack();
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "审核后判断失败!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    if (DBUtility.ClsPub.isStrNull(ds2.Tables[0].Rows[0]["HBack"]) != "0")
                    {
                        oCN.RollBack();
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "审核失败!" + DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBackRemark"]);
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    //=========================================================
 
 
                }
                else
                {
                    //反审核前控制=========================================
                    ds = oCN.RunProcReturn("Exec h_p_Sc_PackUnionBillMain_SettoPacking_BeforeUnCheckCtrl " + HInterID + ",'" + user + "'", "h_p_Sc_PackUnionBillMain_SettoPacking_BeforeUnCheckCtrl");
                    if (ds == null)
                    {
                        oCN.RollBack();
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "审核前判断失败!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    if (DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBack"]) != "0")
                    {
                        oCN.RollBack();
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "审核失败!" + DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBackRemark"]);
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    //=========================================================
                    oCN.RunProc("update Sc_PackUnionBillMain set HChecker='',HCheckDate=null where HInterID=" + HInterID);
                    //反审核后控制=========================================
                    DataSet ds2 = oCN.RunProcReturn("Exec h_p_Sc_PackUnionBillMain_SettoPacking_AfterUnCheckCtrl " + HInterID + ",'" + user + "'", "h_p_Sc_PackUnionBillMain_SettoPacking_AfterUnCheckCtrl");
                    if (ds2 == null)
                    {
                        oCN.RollBack();
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "审核后判断失败!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    if (DBUtility.ClsPub.isStrNull(ds2.Tables[0].Rows[0]["HBack"]) != "0")
                    {
                        oCN.RollBack();
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "审核失败!" + DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBackRemark"]);
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    //=========================================================
 
 
                }
 
 
                oCN.Commit();
                objJsonResult.code = "0";
                objJsonResult.count = 1;
                objJsonResult.Message = "执行成功!";
                objJsonResult.data = null;
                return objJsonResult; ;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "执行失败!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
 
        }
 
        [Route("Sc_PackUnionBillMain_SettoPackingController/AuditPackUnionBill_Setto")]
        [HttpGet]
        public object AuditPackUnionBill_Setto(string HInterID, string user, int Type)
        {
            try
            {
                //判断是否有审核权限
                if (!DBUtility.ClsPub.Security_Log("Sc_PackUnionBillMain_SettoPacking_Check", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无权限审核!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
                if (string.IsNullOrWhiteSpace(HInterID))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "HInterID为空!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
 
                oCN.BeginTran();//开始事务
                ds = oCN.RunProcReturn("select top 1 HInterID,HChecker from Sc_PackUnionBillMain where HInterID=" + HInterID, "Sc_PackUnionBillMain");
                if (ds.Tables.Count < 1)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "单据不存在!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                if (Type == 1)  //审核判断
                {
                    if (string.IsNullOrWhiteSpace(ds.Tables[0].Rows[0]["HChecker"].ToString()) == false)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "单据已审核!不能再次审核!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                if (Type == 2) //反审核判断
                {
                    if (string.IsNullOrWhiteSpace(ds.Tables[0].Rows[0]["HChecker"].ToString()) == true)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "单据未审核!不需要反审核!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
 
                //Type 1 审核  2  反审核
                if (Type == 1)
                {
                    //审核前控制=========================================
                    ds = oCN.RunProcReturn("Exec h_p_Sc_PackUnionBillMain_SettoPacking_BeforeCheckCtrl " + HInterID + ",'" + user + "'", "h_p_Sc_PackUnionBillMain_SettoPacking_BeforeCheckCtrl");
                    if (ds == null)
                    {
                        oCN.RollBack();
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "审核前判断失败!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    if (DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBack"]) != "0")
                    {
                        oCN.RollBack();
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "审核失败!" + DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBackRemark"]);
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    //=========================================================  
                    oCN.RunProc("update Sc_PackUnionBillMain set HChecker=N'" + user + "',HCheckDate=getdate() where HInterID=" + HInterID);
 
                    //审核后控制=========================================
                    DataSet ds2 = oCN.RunProcReturn("Exec h_p_Sc_PackUnionBillMain_SettoPacking_AfterCheckCtrl " + HInterID + ",'" + user + "'", "h_p_Sc_PackUnionBillMain_SettoPacking_AfterCheckCtrl");
                    if (ds2 == null)
                    {
                        oCN.RollBack();
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "审核后判断失败!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    if (DBUtility.ClsPub.isStrNull(ds2.Tables[0].Rows[0]["HBack"]) != "0")
                    {
                        oCN.RollBack();
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "审核失败!" + DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBackRemark"]);
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    //=========================================================
 
 
                }
                else
                {
                    //反审核前控制=========================================
                    ds = oCN.RunProcReturn("Exec h_p_Sc_PackUnionBillMain_SettoPacking_BeforeUnCheckCtrl " + HInterID + ",'" + user + "'", "h_p_Sc_PackUnionBillMain_SettoPacking_BeforeUnCheckCtrl");
                    if (ds == null)
                    {
                        oCN.RollBack();
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "审核前判断失败!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    if (DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBack"]) != "0")
                    {
                        oCN.RollBack();
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "审核失败!" + DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBackRemark"]);
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    //=========================================================
                    oCN.RunProc("update Sc_PackUnionBillMain set HChecker='',HCheckDate=null where HInterID=" + HInterID);
                    //反审核后控制=========================================
                    DataSet ds2 = oCN.RunProcReturn("Exec h_p_Sc_PackUnionBillMain_SettoPacking_AfterUnCheckCtrl " + HInterID + ",'" + user + "'", "h_p_Sc_PackUnionBillMain_SettoPacking_AfterUnCheckCtrl");
                    if (ds2 == null)
                    {
                        oCN.RollBack();
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "审核后判断失败!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    if (DBUtility.ClsPub.isStrNull(ds2.Tables[0].Rows[0]["HBack"]) != "0")
                    {
                        oCN.RollBack();
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "审核失败!" + DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBackRemark"]);
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    //=========================================================
 
 
                }
 
 
                oCN.Commit();
                objJsonResult.code = "0";
                objJsonResult.count = 1;
                objJsonResult.Message = "执行成功!";
                objJsonResult.data = null;
                return objJsonResult; ;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "执行失败!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
    }
}