杨乐
2022-02-10 777db38816776abbe4b864d26a6c0381b75e8f9d
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
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
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.Models;
 
namespace WebAPI.Controllers.基础资料.基础资料
{
    public class Gy_StockCheckItemBillController : ApiController
    {
        public DBUtility.ClsPub.Enum_BillStatus BillStatus;//单据状态(新增,修改,浏览,更新单价,变更)
        private json objJsonResult = new json();
        public DataSet ds = new DataSet();
        public SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
        public Models.ClsGy_StockCheckItemBill BillNew0 = new ClsGy_StockCheckItemBill();
 
        #region 盘点方案列表
        [Route("Gy_StockCheckItemBill/Get_StockCheckItemList")]
        [HttpGet]
        public object Get_StockCheckItemList(string sWhere)
        {
            try
            {
                ds = StockCheckItemList(sWhere);
                if (ds == null)
                {
                    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;
            }
        }
 
        public static DataSet StockCheckItemList(string sWhere)
        {
            string sql1 = string.Format(@"select * from h_v_Gy_StockCheckItemList");
            if (sWhere == null || sWhere.Equals(""))
            {
                return new SQLHelper.ClsCN().RunProcReturn(sql1 + sWhere + " order by hitemid desc", "h_v_Gy_StockCheckItemList");
            }
            else
            {
                string sql = sql1 + sWhere + "order by hitemid desc";
                return new SQLHelper.ClsCN().RunProcReturn(sql, "h_v_Gy_StockCheckItemList");
            }
        }
        #endregion
 
        #region [盘点方案删除功能]
        [Route("Gy_StockCheckItemBill/set_DeleteBill")]
        [HttpGet]
        public object set_DeleteBill(string HItemID)
        {
            Int64 lngBillKey = 0;
            lngBillKey = DBUtility.ClsPub.isLong(HItemID);
            if (lngBillKey == 0)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "单据ID为空!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            ds = oCn.RunProcReturn("select * from Gy_StockCheckItem where HItemID=" + lngBillKey, "Gy_StockCheckItem");
            if (ds != null)
            {
                oCn.RunProc("Delete from Gy_StockCheckItem where HItemID=" + lngBillKey);
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "删除成功!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            else
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "此单据不存在,请查看是否重复删除";
                objJsonResult.data = null;
                return objJsonResult;
            }
 
        }
 
        #endregion
 
        #region [编辑显示表头]
        [Route("Gy_StockCheckItemBill/GetStockCheckItemByID")]
        [HttpGet]
        public object GetStockCheckItemByID(string HID)
        {
            Int64 lngBillKey = 0;
            lngBillKey = DBUtility.ClsPub.isLong(HID);
            if (lngBillKey == 0)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "单据ID为空!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            ds = oCn.RunProcReturn("select * from Gy_StockCheckItem where HItemID=" + lngBillKey, "Gy_ConkReason");
            if (ds != null)
            {
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "";
                objJsonResult.data = ds.Tables[0];
                return objJsonResult;
            }
            else
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "此单据不存在";
                objJsonResult.data = null;
                return objJsonResult;
            }
 
        }
 
        #endregion
 
        #region 保存盘点方案
        [Route("Gy_StockCheckItemBill/SaveGy_StockCheckItem")]
        [HttpPost]
        public object SaveGy_StockCheckItem([FromBody] JObject msg)
        {
            var _value = msg["msg"].ToString();
            string msg2 = _value.ToString();
            string[] sArray = msg2.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
            string msg1 = sArray[0].ToString();
            string msg3 = sArray[1].ToString();//当前人
            SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
            ListModels oListModels = new ListModels();
            try
            {
                Models.ClsGy_StockCheckItemBill oBill = new Models.ClsGy_StockCheckItemBill();
                List<Models.ClsGy_StockCheckItemBill> lsmain = new List<Models.ClsGy_StockCheckItemBill>();
                msg1 = msg1.Replace("\\", "");
                msg1 = msg1.Replace("\n", "");  //\n
                lsmain = oListModels.getObjectByJson_Gy_StockCheckItem(msg1);
                foreach (Models.ClsGy_StockCheckItemBill oItem in lsmain)
                {
                    if (oItem.HNumber.Trim() == "")
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "保存失败!代码不能为空!";
                        objJsonResult.data = 1;
                        return objJsonResult;
                    }
                    if (oItem.HName.Trim() == "")
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "保存失败!名称不能为空!";
                        objJsonResult.data = 1;
                        return objJsonResult;
                    }
                    //得到短代码
                    string sShortNumber;
                    sShortNumber = DBUtility.ClsPub.GetShortNumber(oItem.HNumber.Trim());
                    if (sShortNumber.Trim() == "")
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "保存失败!短代码为空!";
                        objJsonResult.data = 1;
                        return objJsonResult;
                    }
                    oItem.HShortNumber = sShortNumber;//短代码
                    oItem.HEndFlag = true;//末级标志
                    oItem.HLevel = DBUtility.ClsPub.GetLevel(oItem.HNumber.Trim()); //等级
                    oBill = oItem;
                }
 
                //保存
                //保存完毕后处理
                if (oBill.HItemID == 0)
                {
                    oCn.RunProc("Insert into Gy_StockCheckItem " +
                    " (HNumber,HName,HHelpCode,HShortNumber,HParentID" +
                    ",HLevel,HEndFlag,HStopflag,HRemark,HUseFlag,HMakeTime,HMakeEmp,HEndDate,HOrgID) " +
                    " Values('" + oBill.HNumber + "','" + oBill.HName + "','" + oBill.HHelpCode + "','" + oBill.HShortNumber + "'," + oBill.HParentID.ToString() +
                    "," + oBill.HLevel.ToString() + "," + Convert.ToString(oBill.HEndFlag ? 1 : 0) + "," + Convert.ToString(oBill.HStopflag ? 1 : 0) + ",'" + oBill.HRemark +
                    "','" + oBill.HUseFlag + "',getdate(),'" + msg3 + "','" + oBill.HEndDate.ToString() + "'," + oBill.HOrgID.ToString()+
                    ")", ref DBUtility.ClsPub.sExeReturnInfo);
                    //修改上级为非末级代码
                    oCn.RunProc("Update Gy_StockCheckItem set HEndflag=0 where HItemID=" + oBill.HParentID, ref DBUtility.ClsPub.sExeReturnInfo);
 
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "保存成功!";
                    //WebAPIController.Add_Log("送货单下推", UserName, "生成送货单");
                    objJsonResult.data = 1;
                    return objJsonResult;
                }
                else
                {
                    oCN.RunProc("UpDate Gy_StockCheckItem set  " +
                    " HNumber='" + oBill.HNumber + "'" +  //固定赋值===============
                    ",HName='" + oBill.HName + "'" +
                    ",HShortNumber='" + oBill.HShortNumber + "'" +
                    ",HHelpCode='" + oBill.HHelpCode + "'" +
                    ",HUseFlag='" + oBill.HUseFlag + "'" +
                    ",HRemark='" + oBill.HRemark + "'" +
                    ",HEndDate='" + oBill.HEndDate + "'" +
                    ",HModifyTime=getdate()" +
                    ",HModifyEmp='" + msg3 + "'" +
                    ",HStopflag=" + Convert.ToString(oBill.HStopflag ? 1 : 0) +
                    " where HItemID=" + oBill.HItemID.ToString());
 
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "修改成功!";
                    objJsonResult.data = 1;
                    return objJsonResult;
                }
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "保存失败!" + e.ToString();
                objJsonResult.data = 1;
                return objJsonResult;
            }
        }
        #endregion
 
        #region 盘点分析列表
        [Route("Gy_StockCheckItemBill/Get_InventoryAnalysisList")]
        [HttpGet]
        public object Get_InventoryAnalysisList(string sWhere,string sID)
        {
            DataSet ds;
            List<object> list = new List<object>();
            string sql;
            try
            {
                SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
                if (sID == null || sID == "")
                {
                    sql = string.Format(@"select * from h_v_Sc_MouldInventoryAnalysisList where " + sWhere+ " order by HItemID desc ");
                }
                else
                {
                    sql = string.Format(@"select * from h_v_Sc_MouldInventoryAnalysisList where " + sWhere + " and HSourceInterID=(select HItemID from Gy_StockCheckItem where HItemID=" + sID + ") and HMakeDate<=(select HEndDate from Gy_StockCheckItem where HItemID=" + sID + ") order by HItemID desc ");
                }
                ds = oCN.RunProcReturn(sql, "Sc_MouldStockBillMain_Temp");
                list.Add(ds.Tables[0]);
                objJsonResult.code = "0";
                objJsonResult.count = 1;
                objJsonResult.Message = "获取信息成功!";
                objJsonResult.list = list;
                return objJsonResult;
            }
            catch (Exception ex)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "查询数据异常,请与管理员联系!" + ex.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
 
        #region 盘点记录列表
        [Route("Gy_StockCheckItemBill/Get_MouldStockBillMainTemp")]
        [HttpGet]
        public object Get_MouldStockBillMainTemp(string sWhere)
        {
            try
            {
                ds = MouldStockBillMainTemp(sWhere);
                if (ds == null)
                {
                    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;
            }
        }
 
        public static DataSet MouldStockBillMainTemp(string sWhere)
        {
            string sql1 = string.Format(@"select * from h_v_Gy_MouldStockBillMainTempList where 1=1 ");
            if (sWhere == null || sWhere.Equals(""))
            {
                return new SQLHelper.ClsCN().RunProcReturn(sql1 + sWhere + " order by hitemid desc", "h_v_Gy_MouldStockBillMainTempList");
            }
            else
            {
                string sql = sql1 + sWhere + "order by hitemid desc";
                return new SQLHelper.ClsCN().RunProcReturn(sql, "h_v_Gy_MouldStockBillMainTempList");
            }
        }
        #endregion
 
        #region [盘点记录删除功能]
        [Route("Gy_StockCheckItemBill/set_DeleteBill_Temp")]
        [HttpGet]
        public object set_DeleteBill_Temp(string HItemID)
        {
            Int64 lngBillKey = 0;
            lngBillKey = DBUtility.ClsPub.isLong(HItemID);
            if (lngBillKey == 0)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "单据ID为空!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            ds = oCn.RunProcReturn("select * from Sc_MouldStockBillMain_Temp where HItemID=" + lngBillKey, "Sc_MouldStockBillMain_Temp");
            if (ds != null)
            {
                oCn.RunProc("Delete from Sc_MouldStockBillMain_Temp where HItemID=" + lngBillKey);
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "删除成功!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            else
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "此单据不存在,请查看是否重复删除";
                objJsonResult.data = null;
                return objJsonResult;
            }
 
        }
 
        #endregion
 
        #region 盘点分析审核
        #region 调拨—直接调拨
        [Route("Gy_StockCheckItemBill/MakeProdMove")]
            [HttpGet]
            public object MakeProdMove(string HBarCode, string user, string userID,string HItemID)
        {
            try
            {
                string HBillNo = "";
                Int64 HInterID = 0;//显示的字段
                DataSet ds1 = new DataSet();
                ds = oCn.RunProcReturn("select * from Gy_MouldFileMain where HBarCode='" + HBarCode + "'", "Gy_MouldFileMain");
                ds1 = oCn.RunProcReturn("select top 1 * from Sc_MouldStockBillMain_Temp where HBarCode='" + HBarCode + "' and HItemID='"+ HItemID+"'", "Sc_MouldStockBillMain_Temp");
                DataRow dr = ds.Tables[0].Rows[0];
                DataRow dr1 = ds1.Tables[0].Rows[0];
                HInterID = DBUtility.ClsPub.CreateBillID("3814", ref DBUtility.ClsPub.sExeReturnInfo);
                HBillNo = DBUtility.ClsPub.CreateBillCode("3814", ref DBUtility.ClsPub.sExeReturnInfo, true);
                
                string sql = "Insert Into Sc_MouldStockBillMain   " +
                "(HBillType,HBillSubType,HInterID,HBillNo,HDate" +
                ",HMaker,HMakeDate" + 
                ",HSupID,HSupTypeID,HWHID,HSCWHID,HEmpID,HManagerID,HSecManagerID" +
                ",HKeeperID,HDeptID,HInnerBillNo,HRedBlueFlag" +
                ") " +
                " values('3814','3814'," + HInterID + ",'" + HBillNo + "','2022-01-02'" +
                ", '" + user + "',getdate()" +
                ", " + dr["HSupID"].ToString() + ", 1," + dr["HNowSupID"].ToString() + ",0,0,0,0" +
                ", 0," + dr["HDeptID"].ToString() + ",' ',0" +
                ") ";
                string sql1 = string.Format(@"Insert Into Sc_MouldStockBillSub   (HInterID,HEntryID,HCloseMan,HEntryCloseDate,HCloseType,HRemark,HSourceInterID,
                HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney,HMaterID,HPropertyID,HSecUnitRate,HSecUnitID,HUnitID,
                HBatchNo,HQtyMust,HQty,HPrice,HMoney,HDesignLife,HLeaveLife,HUseLife,HWHID,HSCWHID,HSPID,HSCSPID,HSPGroupID,HCorrespondentTypeID,HCorrespondentID,
                HStockOrgID,HOWNERID,HOtherOrgID,HOWNERTYPEID) values(" + HInterID + ",1,'',getdate(),0,'',0,0,'',''," +
                "0,0," + dr["HInterID"].ToString() + ",0," + dr["HSecUnitRate"].ToString() + ",0," + dr["HUnitID"].ToString() + ",0," + dr["HProdQty"].ToString() + "," + dr1["HQty"].ToString() + ",0," +
                "0," + dr["HDesignLife"].ToString() + "," + dr["HLeaveLife"].ToString() + "," + dr["HUseLife"].ToString() + "," + dr1["HCorrespondentID"].ToString() + "," + dr["HNowSupID"].ToString() + ",0,0"
                + ",0,0,0," + userID + ",0,100005,'')");
                //主表
 
                oCn.BeginTran();
                oCn.RunProc(sql);
                oCn.RunProc(sql1);
                oCn.RunProc("update Sc_MouldStockBillMain_Temp set HCheckStatus=1 where HitemID=" + HItemID);
                oCn.Commit();
 
                objJsonResult.code = "0";
                objJsonResult.count = 1;
                objJsonResult.Message = "审核成功!";
                //WebAPIController.Add_Log("送货单下推", UserName, "生成送货单");
                objJsonResult.data = 1;
                return objJsonResult;
            }
            catch (Exception e)
            {
                oCn.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = e.Message;
                objJsonResult.data = null;
            }
            return objJsonResult;
 
        }
        #endregion
 
        #region 盘盈—其他入库单
        [Route("Gy_StockCheckItemBill/MakeOtherIn")]
        [HttpGet]
        public object MakeOtherIn(string HBarCode, string user, string userID, string HItemID)
        {
            try
            {
                string HBillNo = "";
                Int64 HInterID = 0;//显示的字段
                DataSet ds1 = new DataSet();
                ds = oCn.RunProcReturn("select * from Gy_MouldFileMain where HBarCode='" + HBarCode + "'", "Gy_MouldFileMain");
                ds1 = oCn.RunProcReturn("select top 1 * from Sc_MouldStockBillMain_Temp where HBarCode='" + HBarCode + "' and HItemID='" + HItemID + "'", "Sc_MouldStockBillMain_Temp");
                DataRow dr = ds.Tables[0].Rows[0];
                DataRow dr1 = ds1.Tables[0].Rows[0];
                HInterID = DBUtility.ClsPub.CreateBillID("3827", ref DBUtility.ClsPub.sExeReturnInfo);
                HBillNo = DBUtility.ClsPub.CreateBillCode("3827", ref DBUtility.ClsPub.sExeReturnInfo, true);
                string sql = "Insert Into Sc_MouldStockBillMain   " +
                "(HBillType,HBillSubType,HInterID,HBillNo,HDate" +
                ",HMaker,HMakeDate" +
                ",HSupID,HSupTypeID,HWHID,HSCWHID,HEmpID,HManagerID,HSecManagerID" +
                ",HKeeperID,HDeptID,HInnerBillNo,HRedBlueFlag" +
                ") " +
                " values('3827','3827'," + HInterID + ",'" + HBillNo + "','2022-01-02'" +
                ", '" + user + "',getdate()" +
                ", " + dr1["HCorrespondentID"].ToString() + ","+ dr1["HCorrespondentTypeID"].ToString() + ","+ dr["HNowSupID"].ToString() + ",0,0,0,0" +
                ", 0," + dr["HDeptID"].ToString() + ",' ',0" +
                ") ";
                string sql1 = string.Format(@"Insert Into Sc_MouldStockBillSub   (HInterID,HEntryID,HCloseMan,HEntryCloseDate,HCloseType,HRemark,HSourceInterID,
                HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney,HMaterID,HPropertyID,HSecUnitRate,HSecUnitID,HUnitID,
                HBatchNo,HQtyMust,HQty,HPrice,HMoney,HDesignLife,HLeaveLife,HUseLife,HWHID,HSCWHID,HSPID,HSCSPID,HSPGroupID,HCorrespondentTypeID,HCorrespondentID,
                HStockOrgID,HOWNERID,HOtherOrgID,HOWNERTYPEID) values(" + HInterID + ",1,'',getdate(),0,'',0,0,'',''," +
                "0,0," + dr["HInterID"].ToString() + ",0," + dr["HSecUnitRate"].ToString() + ",0," + dr["HUnitID"].ToString() + ",0," + dr["HProdQty"].ToString() + "," + dr1["HQty"].ToString() + ",0," +
                "0," + dr["HDesignLife"].ToString() + "," + dr["HLeaveLife"].ToString() + "," + dr["HUseLife"].ToString() + "," + dr1["HCorrespondentID"].ToString() + "," + dr["HNowSupID"].ToString() + ",0,0"
                + ",0,0,0," + userID + ",0,100005,'')");
                //主表
                oCn.BeginTran();
                oCn.RunProc(sql);
                oCn.RunProc(sql1);
                oCn.RunProc("update Sc_MouldStockBillMain_Temp set HCheckStatus=1 where HitemID=" + HItemID);
                oCn.Commit();
 
                objJsonResult.code = "0";
                objJsonResult.count = 1;
                objJsonResult.Message = "审核成功!";
                //WebAPIController.Add_Log("送货单下推", UserName, "生成送货单");
                objJsonResult.data = 1;
                return objJsonResult;
            }
            catch (Exception e)
            {
                oCn.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = e.Message;
                objJsonResult.data = null;
            }
            return objJsonResult;
 
        }
        #endregion
 
        #region 盘亏—处理出库单
        [Route("Gy_StockCheckItemBill/MakeScrapOut")]
        [HttpGet]
        public object MakeScrapOut(string HBarCode, string user, string userID, string HItemID)
        {
            try
            {
                string HBillNo = "";
                Int64 HInterID = 0;//显示的字段
                DataSet ds1 = new DataSet();
                ds = oCn.RunProcReturn("select * from Gy_MouldFileMain where HBarCode='" + HBarCode + "'", "Gy_MouldFileMain");
                ds1 = oCn.RunProcReturn("select top 1 * from Sc_MouldStockBillMain_Temp where HBarCode='" + HBarCode + "' and HItemID='" + HItemID + "'", "Sc_MouldStockBillMain_Temp");
                DataRow dr = ds.Tables[0].Rows[0];
                DataRow dr1 = ds1.Tables[0].Rows[0];
                HInterID = DBUtility.ClsPub.CreateBillID("3832", ref DBUtility.ClsPub.sExeReturnInfo);
                HBillNo = DBUtility.ClsPub.CreateBillCode("3832", ref DBUtility.ClsPub.sExeReturnInfo, true);
 
                string sql = "Insert Into Sc_MouldStockBillMain   " +
                "(HBillType,HBillSubType,HInterID,HBillNo,HDate" +
                ",HMaker,HMakeDate" +
                ",HSupID,HSupTypeID,HWHID,HSCWHID,HEmpID,HManagerID,HSecManagerID" +
                ",HKeeperID,HDeptID,HInnerBillNo,HRedBlueFlag" +
                ") " +
                " values('3832','3832'," + HInterID + ",'" + HBillNo + "','2022-01-02'" +
                ", '" + user + "',getdate()" +
                ", " + dr1["HCorrespondentID"].ToString() + "," + dr1["HCorrespondentTypeID"].ToString() + "," + dr["HNowSupID"].ToString() + ",0,0,0,0" +
                ", 0," + dr["HDeptID"].ToString() + ",' ',0" +
                ") ";
                string sql1 = string.Format(@"Insert Into Sc_MouldStockBillSub   (HInterID,HEntryID,HCloseMan,HEntryCloseDate,HCloseType,HRemark,HSourceInterID,
                HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney,HMaterID,HPropertyID,HSecUnitRate,HSecUnitID,HUnitID,
                HBatchNo,HQtyMust,HQty,HPrice,HMoney,HDesignLife,HLeaveLife,HUseLife,HWHID,HSCWHID,HSPID,HSCSPID,HSPGroupID,HCorrespondentTypeID,HCorrespondentID,
                HStockOrgID,HOWNERID,HOtherOrgID,HOWNERTYPEID) values(" + HInterID + ",1,'',getdate(),0,'',0,0,'',''," +
                "0,0," + dr["HInterID"].ToString() + ",0," + dr["HSecUnitRate"].ToString() + ",0," + dr["HUnitID"].ToString() + ",0," + dr["HProdQty"].ToString() + "," + dr1["HQty"].ToString() + ",0," +
                "0," + dr["HDesignLife"].ToString() + "," + dr["HLeaveLife"].ToString() + "," + dr["HUseLife"].ToString() + "," + dr1["HCorrespondentID"].ToString() + "," + dr["HNowSupID"].ToString() + ",0,0"
                + ",0,0,0," + userID + ",0,100005,'')");
 
                //主表
                oCn.BeginTran();
                oCn.RunProc(sql);
                oCn.RunProc(sql1);
                oCn.RunProc("update Sc_MouldStockBillMain_Temp set HCheckStatus=1 where HitemID=" + HItemID);
                oCn.Commit();
 
                objJsonResult.code = "0";
                objJsonResult.count = 1;
                objJsonResult.Message = "审核成功!";
                //WebAPIController.Add_Log("送货单下推", UserName, "生成送货单");
                objJsonResult.data = 1;
                return objJsonResult;
            }
            catch (Exception e)
            {
                oCn.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = e.Message;
                objJsonResult.data = null;
            }
            return objJsonResult;
 
        }
        #endregion
 
        #region 出库—领用出库单
        [Route("Gy_StockCheckItemBill/MakeProdOut")]
        [HttpGet]
        public object MakeProdOut(string HBarCode, string user, string userID, string HItemID)
        {
            try
            {
                string HBillNo = "";
                Int64 HInterID = 0;//显示的字段
                DataSet ds1 = new DataSet();
                ds = oCn.RunProcReturn("select * from Gy_MouldFileMain where HBarCode='" + HBarCode + "'", "Gy_MouldFileMain");
                ds1 = oCn.RunProcReturn("select top 1 * from Sc_MouldStockBillMain_Temp where HBarCode='" + HBarCode + "' and HItemID='" + HItemID + "'", "Sc_MouldStockBillMain_Temp");
                DataRow dr = ds.Tables[0].Rows[0];
                DataRow dr1 = ds1.Tables[0].Rows[0];
                HInterID = DBUtility.ClsPub.CreateBillID("3802", ref DBUtility.ClsPub.sExeReturnInfo);
                HBillNo = DBUtility.ClsPub.CreateBillCode("3802", ref DBUtility.ClsPub.sExeReturnInfo, true);
 
                string sql = "Insert Into Sc_MouldStockBillMain   " +
                "(HBillType,HBillSubType,HInterID,HBillNo,HDate" +
                ",HMaker,HMakeDate" +
                ",HSupID,HSupTypeID,HWHID,HSCWHID,HEmpID,HManagerID,HSecManagerID" +
                ",HKeeperID,HDeptID,HInnerBillNo,HRedBlueFlag" +
                ") " +
                " values('3802','3802'," + HInterID + ",'" + HBillNo + "','2022-01-02'" +
                ", '" + user + "',getdate()" +
                ", " + dr1["HCorrespondentID"].ToString() + "," + dr1["HCorrespondentTypeID"].ToString() + "," + dr["HNowSupID"].ToString() + ",0,0,0,0" +
                ", 0," + dr["HDeptID"].ToString() + ",' ',0" +
                ") ";
                string sql1 = string.Format(@"Insert Into Sc_MouldStockBillSub   (HInterID,HEntryID,HCloseMan,HEntryCloseDate,HCloseType,HRemark,HSourceInterID,
                HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney,HMaterID,HPropertyID,HSecUnitRate,HSecUnitID,HUnitID,
                HBatchNo,HQtyMust,HQty,HPrice,HMoney,HDesignLife,HLeaveLife,HUseLife,HWHID,HSCWHID,HSPID,HSCSPID,HSPGroupID,HCorrespondentTypeID,HCorrespondentID,
                HStockOrgID,HOWNERID,HOtherOrgID,HOWNERTYPEID) values(" + HInterID + ",1,'',getdate(),0,'',0,0,'',''," +
                "0,0," + dr["HInterID"].ToString() + ",0," + dr["HSecUnitRate"].ToString() + ",0," + dr["HUnitID"].ToString() + ",0," + dr["HProdQty"].ToString() + "," + dr1["HQty"].ToString() + ",0," +
                "0," + dr["HDesignLife"].ToString() + "," + dr["HLeaveLife"].ToString() + "," + dr["HUseLife"].ToString() + ",'1548785'," + dr["HNowSupID"].ToString() + ",0,0"
                + ",0,0,0," + userID + ",0,100005,'')");
                //主表
                oCn.BeginTran();
                oCn.RunProc(sql);
                oCn.RunProc(sql1);
                oCn.RunProc("update Sc_MouldStockBillMain_Temp set HCheckStatus=1 where HitemID=" + HItemID);
                oCn.Commit();
 
                objJsonResult.code = "0";
                objJsonResult.count = 1;
                objJsonResult.Message = "审核成功!";
                //WebAPIController.Add_Log("送货单下推", UserName, "生成送货单");
                objJsonResult.data = 1;
                return objJsonResult;
            }
            catch (Exception e)
            {
                oCn.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = e.Message;
                objJsonResult.data = null;
            }
            return objJsonResult;
 
        }
        #endregion
 
        #region 退库—领用退库单
        [Route("Gy_StockCheckItemBill/MakeProdBack")]
        [HttpGet]
        public object MakeProdBack(string HBarCode, string user, string userID, string HItemID)
        {
            try
            {
                string HBillNo = "";
                Int64 HInterID = 0;//显示的字段
                DataSet ds1 = new DataSet();
                ds = oCn.RunProcReturn("select * from Gy_MouldFileMain where HBarCode='" + HBarCode + "'", "Gy_MouldFileMain");
                ds1 = oCn.RunProcReturn("select top 1 * from Sc_MouldStockBillMain_Temp where HBarCode='" + HBarCode + "' and HItemID='" + HItemID + "'", "Sc_MouldStockBillMain_Temp");
                DataRow dr = ds.Tables[0].Rows[0];
                DataRow dr1 = ds1.Tables[0].Rows[0];
                HInterID = DBUtility.ClsPub.CreateBillID("3803", ref DBUtility.ClsPub.sExeReturnInfo);
                HBillNo = DBUtility.ClsPub.CreateBillCode("3803", ref DBUtility.ClsPub.sExeReturnInfo, true);
 
                string sql = "Insert Into Sc_MouldStockBillMain   " +
                "(HBillType,HBillSubType,HInterID,HBillNo,HDate" +
                ",HMaker,HMakeDate" +
                ",HSupID,HSupTypeID,HWHID,HSCWHID,HEmpID,HManagerID,HSecManagerID" +
                ",HKeeperID,HDeptID,HInnerBillNo,HRedBlueFlag" +
                ") " +
                " values('3803','3803'," + HInterID + ",'" + HBillNo + "','2022-01-02'" +
                ", '" + user + "',getdate()" +
                ", " + dr["HNowSupID"].ToString() + "," + dr["HNowSupTypeID"].ToString() + "," + dr["HNowSupID"].ToString() + ",0,0,0,0" +
                ", 0," + dr["HDeptID"].ToString() + ",' ',0" +
                ") ";
                string sql1 = string.Format(@"Insert Into Sc_MouldStockBillSub   (HInterID,HEntryID,HCloseMan,HEntryCloseDate,HCloseType,HRemark,HSourceInterID,
                HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney,HMaterID,HPropertyID,HSecUnitRate,HSecUnitID,HUnitID,
                HBatchNo,HQtyMust,HQty,HPrice,HMoney,HDesignLife,HLeaveLife,HUseLife,HWHID,HSCWHID,HSPID,HSCSPID,HSPGroupID,HCorrespondentTypeID,HCorrespondentID,
                HStockOrgID,HOWNERID,HOtherOrgID,HOWNERTYPEID) values(" + HInterID + ",1,'',getdate(),0,'',0,0,'',''," +
                "0,0," + dr["HInterID"].ToString() + ",0," + dr["HSecUnitRate"].ToString() + ",0," + dr["HUnitID"].ToString() + ",0," + dr["HProdQty"].ToString() + "," + dr1["HQty"].ToString() + ",0," +
                "0," + dr["HDesignLife"].ToString() + "," + dr["HLeaveLife"].ToString() + "," + dr["HUseLife"].ToString() + "," + dr1["HCorrespondentID"].ToString() + ","+ dr["HNowSupID"].ToString() + ",0,0"
                + ",0,0,0," + userID + ",0,100005,'')");
 
                //主表
                oCn.BeginTran();
                oCn.RunProc(sql);
                oCn.RunProc(sql1);
                oCn.RunProc("update Sc_MouldStockBillMain_Temp set HCheckStatus=1 where HitemID=" + HItemID);
                oCn.Commit();
 
                objJsonResult.code = "0";
                objJsonResult.count = 1;
                objJsonResult.Message = "审核成功!";
                //WebAPIController.Add_Log("送货单下推", UserName, "生成送货单");
                objJsonResult.data = 1;
                return objJsonResult;
            }
            catch (Exception e)
            {
                oCn.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = e.Message;
                objJsonResult.data = null;
            }
            return objJsonResult;
 
        }
        #endregion
 
        #region 先领用退库再领用出库
        [Route("Gy_StockCheckItemBill/MakeProdOutBack")]
        [HttpGet]
        public object MakeProdOutBack(string HBarCode, string user, string userID, string HItemID)
        {
            MakeProdBack(HBarCode, user, userID, HItemID);
            MakeProdOut(HBarCode, user, userID, HItemID);
            objJsonResult.code = "0";
            objJsonResult.count = 1;
            objJsonResult.Message = "审核成功!";
            //WebAPIController.Add_Log("送货单下推", UserName, "生成送货单");
            objJsonResult.data = 1;
            return objJsonResult;
        }
        #endregion
 
 
        #endregion
    }
}