yangle
2023-09-08 6775b696de3ecbdea4201c6dd57103e165ccb7f8
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
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Http;
using WebAPI.Models;
 
namespace WebAPI.Controllers.SCGL
{
    public class Sc_WorkBillSortBillController : ApiController
    {
        private json objJsonResult = new json();    
        public DataSet ds = new DataSet();
        public WebServer webserver = new WebServer();
        SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
        Sc_WorkBillSortBillMain omdelMian = new Sc_WorkBillSortBillMain();
        List<Sc_WorkBillSortBillSub> omodelsub = new List<Sc_WorkBillSortBillSub>();
 
        #region 日计划工单 列表
        [Route("Sc_WorkBillSortBill/Sc_WorkBillSortBillList")]
        [HttpGet]
        public object Sc_WorkBillSortBillList(string sWhere, string user)
        {
            try
            {
                //查看权限
                if (!DBUtility.ClsPub.Security_Log("Sc_WorkBillSortBill_Query", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无查看权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
                ds = oCN.RunProcReturn("select * from  h_v_JIT_Sc_WorkBillSortBillList where 1=1" + sWhere + " order by 单据号 desc ", "h_v_JIT_Sc_WorkBillSortBillList");
 
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
 
        #region 日计划工单  添加/修改
        [Route("Sc_WorkBillSortBill/AddWorkBillSortBillList")]
        [HttpPost]
        public object AddWorkBillSortBillList([FromBody] JObject sMainSub)
        {
            var _value = sMainSub["sMainSub"].ToString();
            string msg1 = _value.ToString();
            oCN.BeginTran();
            //保存主表
            objJsonResult = AddBillMain(msg1);
            if (objJsonResult.code == "0")
            {
                oCN.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = objJsonResult.Message;
                objJsonResult.data = null;
                return objJsonResult;
            }
            oCN.Commit();
            objJsonResult.code = "1";
            objJsonResult.count = 1;
            objJsonResult.Message = "新增单据成功!";
            objJsonResult.data = null;
            return objJsonResult;
        }
 
        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());//数据类型 1添加 3修改
            string user = sArray[3].ToString();
            try
            {
                if (!DBUtility.ClsPub.Security_Log("Sc_WorkBillSortBill_Edit", 1, false, user)) 
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无保存权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
                omdelMian = Newtonsoft.Json.JsonConvert.DeserializeObject<Sc_WorkBillSortBillMain>(msg2);
                string BillType = "4610";
                ds = ds = oCN.RunProcReturn($"select * from  h_v_JIT_Sc_WorkBillSortBillList where hmainid={omdelMian.HInterID} and  单据号='{omdelMian.HBillNo}'", "h_v_JIT_Sc_WorkBillSortBillList");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    OperationType = 3;
                }
 
                if (OperationType == 1)//新增
                {
                    //主表
                    oCN.RunProc("insert into Sc_WorkBillSortBillMain(HInterID,HBillNo,HYear,HPeriod,HBillType" +
                                 ",HBillSubType,HDate,HBillStatus,HMaker,HMakeDate" +
                                 ", HRemark, HPrintQty, HDeptID, HSeOrderBillNo, HSourceQty" +
                                 ", HInStockQty, HMaterID, HMaterName, HMaterModel, HGroupID" +
                                 ", HWorkShopID, HRelationQty, HUnitID, HWorkerID, HSourceID" +
                                 ", HBeginWorkTimes, HInStockOwnerTypeID, HSplitRelationQty, HOrderLev, HWorkQty" +
                                 ", HSplitPlanQty, HOwnerTypeID, HPlanBeginDate, HPlanEndDate, HICMOBillNo" +
                                 ", HOwnerID, HBatchNo, HYX, HProdTimes, HEntrustORGID" +
                                 ", HPlanQty, HPreparatDate, HOrderNeedQty, HOrderCommitDate, HCompleteQty" +
                                 ", HSeOrderBillQty, HICMOInterID, HKTQ, HStockInORGID, HDayPlanSumQty" +
                                 ", HSourceBillNo, HICMOEntryID, HMainInterID, HProdORGID, HLeftPlanQty" +
                                 ", HEmpID, HInStockOwnerID, HICMOEntrySEQ, HICMOBillType, HCloseCount" +
                                 ", HOrderType, HSplitQty, HSourceStockInQty, HPriority, HLocked, HHangUp)" +
                                $"values({omdelMian.HInterID}, '{omdelMian.HBillNo}', {DateTime.Now.Year}, {DateTime.Now.Month}, '{BillType}'" +
                                $", '{BillType}','{omdelMian.HDate}',1, '{omdelMian.HMaker}',GETDATE()," +
                                $"'{omdelMian.HRemark}',{(omdelMian.HPrintQty==null?0: omdelMian.HPrintQty)},{omdelMian.HDeptID}, '{omdelMian.HSeOrderBillNo}', {(omdelMian.HSourceQty==null?0:omdelMian.HSourceQty)}" +
                                $",{(omdelMian.HInStockQty == null ? 0: omdelMian.HInStockQty)},{omdelMian.HMaterID}, '{omdelMian.HMaterName}', '{omdelMian.HMaterModel}', {omdelMian.HGroupID}" +
                                $", {omdelMian.HWorkShopID}, {(omdelMian.HRelationQty == null ? 0: omdelMian.HRelationQty)},{omdelMian.HUnitID},{omdelMian.HWorkerID},{omdelMian.HSourceID}" +
                                $", {(omdelMian.HBeginWorkTimes == null ? 0: omdelMian.HBeginWorkTimes)}, '{omdelMian.HInStockOwnerTypeID}', {(omdelMian.HSplitRelationQty == null ? 0:omdelMian.HSplitRelationQty)}, '{omdelMian.HOrderLev}', {(omdelMian.HWorkQty == null ? 0:omdelMian.HWorkQty)}" +
                                $", {(omdelMian.HSplitPlanQty == null ? 0: omdelMian.HSplitPlanQty)}, '{omdelMian.HOwnerTypeID}', '{omdelMian.HPlanBeginDate}','{omdelMian.HPlanEndDate}', '{omdelMian.HICMOBillNo}'" +
                                $", {omdelMian.HOwnerID}, '{omdelMian.HBatchNo}', {(omdelMian.HYX == null ? 0: omdelMian.HYX)}, {(omdelMian.HProdTimes == null ? 0: omdelMian.HProdTimes)}, {omdelMian.HEntrustORGID}" +
                                $", {(omdelMian.HPlanQty == null ? 0: omdelMian.HPlanQty)},'{omdelMian.HPreparatDate}', {(omdelMian.HOrderNeedQty == null ? 0: omdelMian.HOrderNeedQty)},'{omdelMian.HOrderCommitDate}', {(omdelMian.HCompleteQty == null ? 0: omdelMian.HCompleteQty)}" +
                                $", {(omdelMian.HSeOrderBillQty == null ? 0: omdelMian.HSeOrderBillQty)},{(omdelMian.HICMOInterID == null ? 0: omdelMian.HICMOInterID)},{(omdelMian.HKTQ == null ? 0: omdelMian.HKTQ)},{(omdelMian.HStockInORGID == null ? 0: omdelMian.HStockInORGID)},{(omdelMian.HDayPlanSumQty == null ? 0: omdelMian.HDayPlanSumQty)}," +
                                $"'{omdelMian.HSourceBillNo}', {(omdelMian.HICMOEntryID == null ? 0: omdelMian.HICMOEntryID)}, {(omdelMian.HMainInterID == null ? 0: omdelMian.HMainInterID)},{omdelMian.HProdORGID},{(omdelMian.HLeftPlanQty == null ? 0: omdelMian.HLeftPlanQty)}" +
                                $", {(omdelMian.HEmpID == null ? 0: omdelMian.HEmpID)},{omdelMian.HInStockOwnerID},{(omdelMian.HICMOEntrySEQ == null ? 0: omdelMian.HICMOEntrySEQ)}, '{omdelMian.HICMOBillType}', {(omdelMian.HCloseCount == null ? 0: omdelMian.HCloseCount)}" +
                                $", '{omdelMian.HOrderType}', {(omdelMian.HSplitQty == null ? 0: omdelMian.HSplitQty)}, {(omdelMian.HSourceStockInQty == null ? 0: omdelMian.HSourceStockInQty)}, {(omdelMian.HPriority == null ? 0: omdelMian.HPriority)}, '{(omdelMian.HLocked == true ? 1 : 0)}', '{(omdelMian.HHangUp == true ? 1 : 0)}')");
                }
                else if (OperationType == 3)
                {
 
                    ds = oCN.RunProcReturn($"select * from  Sc_WorkBillSortBillMain where HMainSourceInterID={omdelMian.HMainSourceInterID}" +
                      $" and HMainSourceEntryID={omdelMian.HMainSourceEntryID} and HICMOBillNo='{omdelMian.HICMOBillNo}' and HICMOEntrySEQ={omdelMian.HICMOEntrySEQ} and HSourceID={omdelMian.HSourceID}", "Sc_WorkBillSortBillMain");
                    if ((ds.Tables[0].Rows.Count == 1 && ds.Tables[0].Rows[0]["HInterID"].ToString() != omdelMian.HInterID.ToString()))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "生产资源有重复,请修改!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
 
                    //修改
                    oCN.RunProc($"update Sc_WorkBillSortBillMain set HDate='{omdelMian.HDate}',HUpDater='{omdelMian.HMaker}',HUpDateDate=GETDATE()" +
                                  $", HRemark='{omdelMian.HRemark}', HPrintQty={(omdelMian.HPrintQty == null ? 0 : omdelMian.HPrintQty)}" +
                                  $", HDeptID={omdelMian.HDeptID}, HSeOrderBillNo='{omdelMian.HSeOrderBillNo}', HSourceQty= {(omdelMian.HSourceQty == null ? 0 : omdelMian.HSourceQty)}" +
                                  $", HInStockQty={(omdelMian.HInStockQty == null ? 0 : omdelMian.HInStockQty)}, HMaterID={omdelMian.HMaterID}" +
                                  $", HMaterName= '{omdelMian.HMaterName}', HMaterModel= '{omdelMian.HMaterModel}', HGroupID={omdelMian.HGroupID}" +
                                  $", HWorkShopID={omdelMian.HWorkShopID}, HRelationQty={(omdelMian.HRelationQty == null ? 0 : omdelMian.HRelationQty)}" +
                                  $", HUnitID={omdelMian.HUnitID}, HWorkerID={omdelMian.HWorkerID}, HSourceID={omdelMian.HSourceID}" +
                                  $", HBeginWorkTimes={(omdelMian.HBeginWorkTimes == null ? 0 : omdelMian.HBeginWorkTimes)}, HInStockOwnerTypeID= '{omdelMian.HInStockOwnerTypeID}'" +
                                  $", HSplitRelationQty={(omdelMian.HSplitRelationQty == null ? 0 : omdelMian.HSplitRelationQty)}, HOrderLev='{omdelMian.HOrderLev}'" +
                                  $", HWorkQty={(omdelMian.HWorkQty == null ? 0 : omdelMian.HWorkQty)}" +
                                  $", HSplitPlanQty={(omdelMian.HSplitPlanQty == null ? 0 : omdelMian.HSplitPlanQty)}, HOwnerTypeID='{omdelMian.HOwnerTypeID}'" +
                                  $", HPlanBeginDate= '{omdelMian.HPlanBeginDate}', HPlanEndDate='{omdelMian.HPlanEndDate}', HICMOBillNo='{omdelMian.HICMOBillNo}'" +
                                  $", HOwnerID={omdelMian.HOwnerID}, HBatchNo='{omdelMian.HBatchNo}', HYX={(omdelMian.HYX == null ? 0 : omdelMian.HYX)}" +
                                  $", HProdTimes={(omdelMian.HProdTimes == null ? 0 : omdelMian.HProdTimes)}, HEntrustORGID={omdelMian.HEntrustORGID}" +
                                  $", HPlanQty={(omdelMian.HPlanQty == null ? 0 : omdelMian.HPlanQty)}, HPreparatDate='{omdelMian.HPreparatDate}'" +
                                  $", HOrderNeedQty={(omdelMian.HOrderNeedQty == null ? 0 : omdelMian.HOrderNeedQty)}, HOrderCommitDate='{omdelMian.HOrderCommitDate}'" +
                                  $", HCompleteQty={(omdelMian.HCompleteQty == null ? 0 : omdelMian.HCompleteQty)}" +
                                  $", HSeOrderBillQty={(omdelMian.HSeOrderBillQty == null ? 0 : omdelMian.HSeOrderBillQty)}, HICMOInterID={(omdelMian.HICMOInterID == null ? 0 : omdelMian.HICMOInterID)}" +
                                  $", HKTQ={(omdelMian.HKTQ == null ? 0 : omdelMian.HKTQ)}, HStockInORGID={(omdelMian.HStockInORGID == null ? 0 : omdelMian.HStockInORGID)}" +
                                  $", HDayPlanSumQty={(omdelMian.HDayPlanSumQty == null ? 0 : omdelMian.HDayPlanSumQty)}" +
                                  $", HSourceBillNo='{omdelMian.HSourceBillNo}', HICMOEntryID={(omdelMian.HICMOEntryID == null ? 0 : omdelMian.HICMOEntryID)}" +
                                  $", HMainInterID={(omdelMian.HMainInterID == null ? 0 : omdelMian.HMainInterID)}, HProdORGID={omdelMian.HProdORGID}" +
                                  $", HLeftPlanQty={(omdelMian.HLeftPlanQty == null ? 0 : omdelMian.HLeftPlanQty)}" +
                                  $", HEmpID={(omdelMian.HEmpID == null ? 0 : omdelMian.HEmpID)}, HInStockOwnerID={omdelMian.HInStockOwnerID}, HICMOEntrySEQ={(omdelMian.HICMOEntrySEQ == null ? 0 : omdelMian.HICMOEntrySEQ)}" +
                                  $", HICMOBillType='{omdelMian.HICMOBillType}', HCloseCount={(omdelMian.HCloseCount == null ? 0 : omdelMian.HCloseCount)}" +
                                  $", HOrderType= '{omdelMian.HOrderType}', HSplitQty={(omdelMian.HSplitQty == null ? 0 : omdelMian.HSplitQty)}, HSourceStockInQty={(omdelMian.HSourceStockInQty == null ? 0 : omdelMian.HSourceStockInQty)}" +
                                  $", HPriority={(omdelMian.HPriority == null ? 0 : omdelMian.HPriority)}, HLocked='{(omdelMian.HLocked == true ? 1 : 0)}'" +
                                  $", HHangUp='{(omdelMian.HHangUp == true ? 1 : 0)}' where HInterID={omdelMian.HInterID}");
                }
                //保存子表
                objJsonResult = AddBillSub(msg3);
                if (objJsonResult.code == "0")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = objJsonResult.Message;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = null;
                objJsonResult.data = null;
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
 
        public json AddBillSub(string msg3)
        {
            //删除子表
            oCN.RunProc("delete from Sc_WorkBillSortBillSub where HInterID='" + omdelMian.HInterID.ToString() + "'");
 
            omodelsub = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Sc_WorkBillSortBillSub>>(msg3);
            int i = 1;
            //插入子表
            foreach (Models.Sc_WorkBillSortBillSub oSub in omodelsub)
            {
                oCN.RunProc("insert into Sc_WorkBillSortBillSub(HInterID,HSEQ,HRemark,HMasterDate,HQty" +
                            ", HRptFinishQty, HTimes, HUseTimes, HBTimes, HETimes" +
                            ", HDateSub, HCloseMan, HEntryCloseDate, HCloseTypeSub, HColumn" +
                            ", HLockedSub, HComplete, HStatusTag, HIsHandModify)" +
                            $"values({omdelMian.HInterID}, {i}, '{oSub.HRemark}', '{oSub.HMasterDate}', {(oSub.HQty == null ? 0: oSub.HQty)}" +
                            $", {(oSub.HRptFinishQty == null ? 0: oSub.HRptFinishQty)}, {(oSub.HTimes == null ? 0: oSub.HTimes)}, {(oSub.HUseTimes == null ? 0: oSub.HUseTimes)}, '{oSub.HBTimes}', '{oSub.HETimes}'" +
                            $", '{oSub.HDateSub}', '{oSub.HCloseMan}', '{oSub.HEntryCloseDate}', {(oSub.HCloseTypeSub == true ? 1 : 0)}, '{oSub.HColumn}'" +
                            $", '{(oSub.HLockedSub == true ? 1 : 0)}', '{oSub.HComplete}', '{(oSub.HStatusTag == true ? 1 : 0)}', '{(oSub.HIsHandModify == true ? 1 : 0)}')");
                i++;
            }
 
            objJsonResult.code = "1";
            objJsonResult.count = 1;
            objJsonResult.Message = null;
            objJsonResult.data = null;
            return objJsonResult;
        }
 
        #endregion
 
        #region 日计划工单 删除
        [Route("Sc_WorkBillSortBill/DelWorkBillSortBillList")]
        [HttpGet]
        public object DelWorkBillSortBillList(string HInterID,int DataType, string User)
        {
            try
            {
                //删除权限
                if (!DBUtility.ClsPub.Security_Log_second("Sc_WorkBillSortBill_Drop", 1, false, User))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无权限删除!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                //DataType 1=日计划工单 多选删除   2=日计划平台多选删除
                if (DataType == 1)
                {
                    var NumData = HInterID.Split(',');
 
                    for (int i = 0; i < NumData.Length; i++)
                    {
                        var NumData_T = NumData[i].Split('_');
 
                        ds = oCN.RunProcReturn("select * from h_v_JIT_Sc_WorkBillSortBillList where 1=1 and hmainid=" + NumData_T[0], "h_v_JIT_Sc_WorkBillSortBillList");
 
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            if (ds.Tables[0].Rows[0]["单据状态"].ToString() != "1")
                            {
                                objJsonResult.code = "0";
                                objJsonResult.count = 0;
                                objJsonResult.Message = "当前单据不能删除!";
                                objJsonResult.data = null;
                                return objJsonResult;
                            }
 
                            oCN.BeginTran();//开启事务
 
                            if (ds.Tables[0].Rows.Count == 1)
                            {
                                oCN.RunProc($"delete from Sc_WorkBillSortBillMain where HInterID={ NumData_T[0]}");
                            }
                            oCN.RunProc($"delete from Sc_WorkBillSortBillSub where HInterID={ NumData_T[0]} and HEntryID={ NumData_T[1]}");
 
                            oCN.Commit();//结束事务
                        }
                    }
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除成功!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else if (DataType == 2)
                {
                    var NumData = HInterID.Split(',');
 
                    for (int i = 0; i < NumData.Length; i++)
                    {
                        ds = oCN.RunProcReturn("select * from h_v_JIT_Sc_WorkBillSortBillList where 1=1 and hmainid=" + NumData[i], "h_v_JIT_Sc_WorkBillSortBillList");
 
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            if (ds.Tables[0].Rows[0]["单据状态"].ToString() != "1")
                            {
                                objJsonResult.code = "0";
                                objJsonResult.count = 0;
                                objJsonResult.Message = "当前单据不能删除!";
                                objJsonResult.data = null;
                                return objJsonResult;
                            }
 
                            oCN.BeginTran();//开启事务
 
                            oCN.RunProc($"delete from Sc_WorkBillSortBillSub where HInterID={ NumData[i]}");
                            oCN.RunProc($"delete from Sc_WorkBillSortBillMain where HInterID={ NumData[i]}");
 
                            oCN.Commit();//结束事务
                        }
                    }
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除成功!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "当前单据不存在,无法删除!";
                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;
            }
        }
        #endregion
 
        #region 日计划工单 关闭
        [Route("Sc_WorkBillSortBill/CloseWorkBillSortBillList")]
        [HttpGet]
        public object CloseWorkBillSortBillList(string HInterID, string User)
        {
            try
            {
                //关闭权限
                if (!DBUtility.ClsPub.Security_Log_second("Sc_WorkBillSortBill_Close", 1, false, User))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无权限关闭!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
                ds = oCN.RunProcReturn("select * from h_v_JIT_Sc_WorkBillSortBillList where 1=1 and hmainid=" + HInterID, "h_v_JIT_Sc_WorkBillSortBillList");
 
                if (ds.Tables[0].Rows.Count > 0)
                {
                    if (ds.Tables[0].Rows[0]["单据状态"].ToString() == "3")
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "当前单据已关闭!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
 
                    oCN.BeginTran();//开启事务
 
                    oCN.RunProc($"update Sc_WorkBillSortBillMain set HBillStatus=3,HCloseMan='{User}',HCloseDate=getdate()   where HInterID={HInterID}");
 
                    oCN.Commit();//结束事务
 
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "关闭成功!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "当前单据不存在,无法关闭!";
                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;
            }
        }
        #endregion
 
        #region 日计划工单 反关闭
        [Route("Sc_WorkBillSortBill/CancelCloseBillWorkBillSortBillList")]
        [HttpGet]
        public object CancelCloseBillWorkBillSortBillList(string HInterID, string User)
        {
            try
            {
                //关闭权限
                if (!DBUtility.ClsPub.Security_Log_second("Sc_WorkBillSortBill_Close", 1, false, User))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无权限关闭!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
                ds = oCN.RunProcReturn("select * from h_v_JIT_Sc_WorkBillSortBillList where 1=1 and hmainid=" + HInterID, "h_v_JIT_Sc_WorkBillSortBillList");
 
                if (ds.Tables[0].Rows.Count > 0)
                {
                    if (ds.Tables[0].Rows[0]["单据状态"].ToString() != "3")
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "当前单据没有处于关闭状态!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
 
                    oCN.BeginTran();//开启事务
                    string HBillStatus = ds.Tables[0].Rows[0]["审核人"].ToString() == "" ? "1" : "2";
                    oCN.RunProc("update Sc_WorkBillSortBillMain set HBillStatus='" + HBillStatus + "',HCloseMan='',HCloseDate=null   where HInterID=" + HInterID + "");
 
                    oCN.Commit();//结束事务
 
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "关闭成功!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "当前单据不存在,无法关闭!";
                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;
            }
        }
        #endregion
    }
}