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
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Pub_Class;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Web.Http;
using WebAPI.Models;
 
namespace WebAPI.Controllers.CJGL
{
    public class Cj_SingleStationController : ApiController
    {
        private json objJsonResult = new json();
        SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
        DataSet ds;
 
        #region 工序单品不良采集  用户查询关联字段
        [Route("Cj_SingleStation/Cj_CollectionOfSingleProductDefectsUserList")]
        [HttpGet]
        public object Cj_CollectionOfSingleProductDefectsUserList(string sWhere, string user)
        {
            try
            {
 
                if (sWhere == null || sWhere.Equals(""))
                {
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "Sucess!";
                    objJsonResult.data = new DataTable();
                    return objJsonResult;
                }
 
                ds = oCN.RunProcReturn("select * from h_v_Cj_UserAssociationList where 1=1 "+sWhere, "h_v_Cj_UserAssociationList");
 
                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("Cj_SingleStation/HBardCodeList")]
        [HttpGet]
        public object HBardCodeList(string HBarCode, string user)
        {
            try
            {
                ds = oCN.RunProcReturn("select * from gy_czygl where czymc='" + user + "'", "gy_czygl");
                string HProcID = ds.Tables[0].Rows[0]["HProcID"].ToString();
 
                ds = oCN.RunProcReturn(@"select * from h_v_Gy_BarCodeBillHICOMProcessExchange where 条码='" + HBarCode + "' ", "h_v_Gy_BarCodeBillHICOMProcessExchange");
 
                if (ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "条码查无数据!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
                if (ds.Tables[0].Rows[0]["HProcID"].ToString() != HProcID)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "当前条码与当前工序不匹配!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
                if (ds.Tables[0].Rows[0]["HStatus"].ToString() != "正常")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "当前条码状态为" + ds.Tables[0].Rows[0]["HStatus"].ToString() + "!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
 
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "";
                objJsonResult.data = ds.Tables[0];
                return objJsonResult;
            }
            catch (Exception e)
            {
 
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "没有返回任何记录!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
 
        #region 工序单品不良采集 保存
        [Route("Cj_SingleStation/ProcessBLSave")]
        [HttpPost]
        public object ProcessBLSave([FromBody] JObject sMainSub)
        {
            var _value = sMainSub["sMainSub"].ToString();
            string msg1 = _value.ToString();
            string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
            string msg2 = sArray[0].ToString(); //主表数据
            string HResult = sArray[1].ToString();
            string user = sArray[2].ToString();
            string linterid = sArray[3].ToString();
 
            try
            {
                var msg3 = msg2.ToString();
                msg2 = "[" + msg2.ToString() + "]";
                List<Model.ClsSc_QualityReportBillMain> mainList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Model.ClsSc_QualityReportBillMain>>(msg2);
 
                long HInterID = mainList[0].HInterID;//递入type得到的单据ID
                string HBillNo = mainList[0].HBillNo;//递入type得到的单据号
                DateTime HDate = DateTime.Now;//日期
                string HRemark = mainList[0].HRemark;//备注
                long HEmpID = mainList[0].HEmpID;//质检员
                long HGroupID = mainList[0].HGroupID;//班组
                long HDeptID = mainList[0].HDeptID;//车间
                string HMaker = user;//制单人
                long HMainSourceInterID = mainList[0].HICMOInterID;
                long HMainSourceEntryID = mainList[0].HICMOEntryID;
                string HMainSourceBillNo = mainList[0].HICMOBillNo;
 
                ds = oCN.RunProcReturn("select * from Sc_QualityReportBillMain where HInterID=" + HInterID + " and HBillNo='" + HBillNo + "'", "Sc_QualityReportBillMain");
                if (ds.Tables[0].Rows.Count != 0) {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "单据已存在!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
                oCN.BeginTran();
 
                if (ds.Tables[0].Rows.Count == 0)//新增
                {
                    //主表
                    oCN.RunProc(@"Insert Into Sc_QualityReportBillMain   
(HBillType,HBillSubType,HBillStatus,HInterID,HBillNo,HDate
,HYear,HPeriod,HRemark,HMaker,HMakeDate
,HEmpID,HGroupID,HDeptID,HMainSourceInterID,HMainSourceEntryID,HMainSourceBillNo)
                        values('3717','3717',1," + HInterID + ",'" + HBillNo + "','" + HDate + "'" +
                    "," + DateTime.Now.Year + "," + DateTime.Now.Month + ",'" + HRemark + "','" + HMaker + "',getdate()" +
                    ",'" + HEmpID + "'," + HGroupID + "," + HDeptID + "," + HMainSourceInterID + "," + HMainSourceEntryID + ",'" + HMainSourceBillNo + "') ");
 
                }
               
                //保存子表
                objJsonResult = AddBillSub_NoTable(msg3, HInterID, HResult, linterid);
 
                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 = 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_NoTable(string msg3, long HInterID, string HResult,string linterid)
        {
           Model.ClsSc_QualityReportBillSub oSub = Newtonsoft.Json.JsonConvert.DeserializeObject<Model.ClsSc_QualityReportBillSub>(msg3);
 
            if (oSub.HMaterID == 0)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "物料不能为空";
                objJsonResult.data = null;
                return objJsonResult;
            }
 
            oCN.RunProc($@"Insert into Sc_QualityReportBillSub 
(HInterID,HENTRYID,HBillNo_bak,HEmpID,HBarCode,HBadReasonID,HAddr,HMaker,HMakeDate
,HMaterID,HUnitID,HRemark,HSourceID,HICMOInterID,HICMOEntryID,HICMOBillNo,HReportType
,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney
,HQty,HResult,HProcExchInterID,HProcExchEntryID,HProcExchBillNo) 
values({HInterID},1,'{oSub.HBillNo_bak}',{oSub.HEmpID},'{oSub.HBarCode}',{oSub.HBadReasonID},'','{oSub.HMaker}','{oSub.HMakeDate}'
,{oSub.HMaterID},{oSub.HUnitID},'{oSub.HRemark}',{oSub.HSourceID},{oSub.HICMOInterID},{oSub.HICMOEntryID},'{oSub.HICMOBillNo}',{oSub.HReportType}
,0,0,'','',0,0
,0,'{HResult}',{oSub.HProcExchInterID},{oSub.HProcExchEntryID},'{oSub.HProcExchBillNo}')");
 
            //修改条码表的状态
            oCN.RunProc("update Gy_BarCodeBill set HStatus='"+ HResult + "' where HBarCode='"+ oSub.HBarCode + "'");
 
            //修改出站单的 不良 报废数量
            if (HResult == "不良") {
                oCN.RunProc("update Sc_StationOutBillMain set HBadCount+=1  where HProcExchBillNo='" + oSub.HProcExchBillNo + "' and HProcID=" + oSub.HProcID + " and HInterID=" + linterid);
            }
            else if (HResult == "报废")
            {
                oCN.RunProc("update Sc_StationOutBillMain set HWasterQty+=1  where HProcExchBillNo='" + oSub.HProcExchBillNo + "' and HProcID=" + oSub.HProcID + " and HInterID=" + linterid);
            }
 
            objJsonResult.code = "1";
            objJsonResult.count = 1;
            objJsonResult.Message = null;
            objJsonResult.data = null;
            return objJsonResult;
        }
        #endregion
 
        #region  工序单品过站 流转卡查询关键件清单
        [Route("Cj_SingleStation/HBardCodeBomList")]
        [HttpGet]
        public object HBardCodeBomList(string HBarCode, string user)
        {
            try
            {
                ds = oCN.RunProcReturn("select * from gy_czygl where czymc='" + user + "'", "gy_czygl");
 
                ds = oCN.RunProcReturn(@"exec h_p_Gy_BarCodeBillBomList '" + HBarCode + "'," + ds.Tables[0].Rows[0]["HProcID"].ToString(), "h_p_Gy_BarCodeBillBomList");
                if (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 e)
            {
 
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "没有返回任何记录!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
 
        #region  工序单品过站 扫流转卡保存关键件清单
        [Route("Cj_SingleStation/AddBomTempList")]
        [HttpPost]
        public object AddBomTempList([FromBody] JObject sMainSub)
        {
            try
            {
                var _value = sMainSub["sMainSub"].ToString();
                string msg = _value.ToString();
                string[] sArray = msg.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                string msg1 = sArray[0].ToString();
                string HInterID = sArray[1].ToString();
                string HBillNo = sArray[2].ToString();
                string user = sArray[3].ToString();
                string HBillType = sArray[4].ToString();
                string HOrgID = sArray[5].ToString();
 
                oCN.BeginTran();
 
                List<Model.Sc_AssemblyBill_BindSourceTemp> tempList = new List<Model.Sc_AssemblyBill_BindSourceTemp>();
                tempList = JsonConvert.DeserializeObject<List<Model.Sc_AssemblyBill_BindSourceTemp>>(msg1);
 
                if (tempList.Count == 0) {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无数据!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
                ds = oCN.RunProcReturn("select * from gy_czygl where czymc='" + user + "'", "gy_czygl");
                string HProcID = ds.Tables[0].Rows[0]["HProcID"].ToString();
 
                oCN.RunProc("delete from  Sc_AssemblyBill_BindSourceTemp where HInterID =" + HInterID + "  and HBillNo_bak='" + HBillNo + "'");
                for (int i = 0; i < tempList.Count; i++)
                {
                    //临时配件表
                    oCN.RunProc("Insert Into Sc_AssemblyBill_BindSourceTemp   " +
                    "(HInterID,HEntryID,HBillNo_bak,HSourceBillNo,HSourceInterID,HSourceEntryID,HMaterID" +
                    ",HQtyMust,HProdOrgID,HSourceBillType,HAuxPropID,HProcID,HQty,HBatchNo,HMTONo,HPlanMode) " +
                    " values(" + HInterID + "," + (i + 1) + ",'" + HBillNo + "','" + tempList[i].HProcExchBillNo + "',"+ tempList[i].HProcExchInterID + "," + tempList[i].HProcExchEntryID +","+ tempList[i].HMaterID+
                    ",'0','" + HOrgID + "','',0,"+ HProcID + ","+ tempList[i].HQty + ",'" + tempList[i].HBatchNo + "','','') ");
                }
 
                oCN.Commit();
 
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                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("Cj_SingleStation/DelBomTempList")]
        [HttpGet]
        public object DelBomTempList(int HInterID, int HEntryID, string user)
        {
            try
            {
                ds = oCN.RunProcReturn("select * from Sc_AssemblyBill_BindSourceTemp  where HInterID = " + HInterID, "Sc_AssemblyBill_BindSourceTemp");
 
                if (ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "查无数据!";
                    objJsonResult.data = null;
                }
 
                oCN.BeginTran();
 
                string sql = "delete from Sc_AssemblyBill_BindSourceTemp where HInterID = " + HInterID + " and HEntryID=" + HEntryID;
                oCN.RunProc(sql);
 
                oCN.Commit();
 
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                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  工序单品过站 扫SN码保存到组装追溯单
        [Route("Cj_SingleStation/AddAssemblyBillList")]
        [HttpPost]
        public object AddAssemblyBill([FromBody] JObject sMainSub)
        {
            try
            {
                var _value = sMainSub["sMainSub"].ToString();
                string msg = _value.ToString();
                string[] sArray = msg.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                string sMainStr = sArray[0].ToString();
                string sSubStr = sArray[1].ToString();
                string user = sArray[2].ToString();
 
                oCN.BeginTran();
 
                ClsSc_AssemblyBillMain omodel = new ClsSc_AssemblyBillMain();
                omodel = JsonConvert.DeserializeObject<ClsSc_AssemblyBillMain>(sMainStr);
 
                List<Model.ClsSc_AssemblyBillSub> sub = new List<Model.ClsSc_AssemblyBillSub>();
                sub = JsonConvert.DeserializeObject<List<Model.ClsSc_AssemblyBillSub>>(sSubStr);
 
 
                Int64 HInterID1 = DBUtility.ClsPub.CreateBillID("3727", ref DBUtility.ClsPub.sExeReturnInfo);
                string HBillNo1 = DBUtility.ClsPub.CreateBillCode("3727", ref DBUtility.ClsPub.sExeReturnInfo, true);
                //保存生产组装单主表
                string sql = $@"Insert Into Sc_AssemblyBillMain(HYear,HPeriod,HBillType,HBillSubType,HInterID,HDate
,HBillNo,HBillStatus,HMaker,HMakeDate,HMainSourceInterID,HMainSourceEntryID,HMainSourceBillNo
,HICMOInterID,HICMOBillNo,HBarCode_P,HMaterID,HUnitID,HAssemblyStatus,HProdOrgID)
values('{DateTime.Now.Year}','{DateTime.Now.Month}','3727','3727',{HInterID1},getdate()
,'{HBillNo1}','1','{user}',getdate(),{omodel.HProcExchInterID.ToString()},{omodel.HProcExchEntryID.ToString()},'{omodel.HProcExchBillNo.ToString()}'
,{omodel.HICMOInterID.ToString()},'{omodel.HICMOBillNo.ToString()}','{omodel.HBarCode_P.ToString()}',{omodel.HMaterID},0,'汇报',{omodel.HProdOrgID})";
                oCN.RunProc(sql);
 
                for (int i = 0; i < sub.Count; i++)
                {
                    //子表存储
                    string sq2 = $@"Insert Into Sc_AssemblyBillSub(HInterID,HBillNo_bak,HEntryID,HSourceInterID,HSourceEntryID,HSourceBillNo
,HSourceBillType,HMaterID,HSourceID,HEquipID,HUnitID,HQty
,HGroupID,HWorkerID,HScanDate,HBarCode,HBarCode_P,HSNNumber)
values({HInterID1},'{HBillNo1}',{(i + 1)},0,0,''
,'',{sub[i].HMaterID},0,0,0,{sub[i].HQty}
,0,0,getdate(),'{sub[i].HBarCode}','{omodel.HBarCode_P}','') ";
                    oCN.RunProc(sq2);
                }
 
                sMainStr = "[" + sMainStr + "]";
                List<StationBill> list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<StationBill>>(sMainStr);
                long HMainInterID = 0;
                string BillType = "3791";
                string HBillSubType = "3791";
                long HInterID = list[0].HInterID;//递入type得到的单据ID
                string HBillNo = list[0].HBillNo;//递入type得到的单据号
                int HBillStatus = 1;
                string HMaker = user;//制单人
                string HMouldNum = list[0].HMouldNum;//模穴号
                int HYear = DateTime.Now.Year;
                double HPeriod = DateTime.Now.Month;
                string HRemark = list[0].HRemark;//备注
                string HSourceName = list[0].HSourceName;//生产资源名称
                double HPieceQty = list[0].HPieceQty;//进站PCS数
                double HWasterQty = 0;//报废数量
                double HPlanPieceQty = 0;//进站PNL数
                double HBadPNL = 0;//报废PNL数
                long HICMOInterID = list[0].HICMOInterID;//任务单ID
                long HICMOEntryID = list[0].HICMOEntryID;//任务单ID
                string HICMOBillNo = list[0].HICMOBillNo;//任务单
                int HProcPlanInterID = 0;
                int HProcPlanEntryID = 0;
                string HProcPlanBillNo = "";
                long HProcExchInterID = list[0].HProcExchInterID;
                long HProcExchEntryID = list[0].HProcExchEntryID;
                string HProcExchBillNo = list[0].HProcExchBillNo;//流转卡
                long HMaterID = list[0].HMaterID;//产品ID
                long HProcID = list[0].HProcID;//当前工序ID
                double HICMOQty = list[0].HICMOQty;//任务单数量
                double HPlanQty = list[0].HICMOQty;//移交PNL数
                DateTime HStationOutTime = DateTime.Now;//汇报时间
                long HSourceID = list[0].HSourceID;//生产资源ID
                long HPayProcID = 0;//核算工序ID
                long HGroupID = list[0].HGroupID;//班组ID
                long HDeptID = list[0].HDeptID;
                long HEmpID = list[0].HEmpID;//操作员ID
                long HEmpID2 = list[0].HEmpID2;////操作员2ID
                string HBarCode = list[0].HProcExchBillNo;//条形码
                string HAddr = "";
                string HBarCodeMaker = "";
                long HSourceID2 = 0;//生产资源2ID
                long HSourceID3 = 0;//生产资源3ID
                long HSourceID4 = 0;//生产资源4ID
                long HSourceID5 = 0;//生产资源5ID
                long HSupID = 0;
                double HQty = list[0].HQty;//合格数量
                double HPrice = 0;
                double HMoney = 0;
                double HBadCount = list[0].HBadCount;//不良数量
                long HCenterID = list[0].HCenterID;//工作中心ID
                string HProcNo = list[0].HProcNo;//流水号
                string HOrderProcNO = list[0].HOrderProcNO;//订单跟踪号
                string HSourceNameList = list[0].HSourceNameList;//设备清单
                long HMainSourceInterID = list[0].HInterID;//递入type得到的单据ID
                string HMainSourceBillNo = list[0].HBillNo;//递入type得到的单据号
                string HMainSourceBillType = "3790";
                bool HLastSubProc = list[0].HLastSubProc;//转下工序
                long HEmpID3 = 0;//操作员3ID
                long HEmpID4 = 0;//操作员4ID
                long HEmpID5 = 0;//操作员5ID
                double HDSQty = 0;//折弯刀数
                double HChongQty = 0;//NCT冲次数
                double HPriceRate = 0;//系数
                double HWorkTimes = 0;//工时
                long HQCCheckID = list[0].HEmpID;//检验员ID
                long HPRDOrgID = omodel.HProdOrgID;//组织ID
                double HmaterOutqty = 0;//白坯发布
                double HProcPriceRate = 0;//工价系数
                int HTemporaryAreaID = 0;//暂放区
 
                ds = oCN.RunProcReturn("select  * from Sc_StationOutBillMain a left join  Sc_StationOutBillSub_SN sn on a.HInterID=sn.HInterID where a.HInterID=" + HInterID + " and HBillNo='" + HBillNo + "'", "Sc_StationOutBillMain");
 
                if (ds.Tables[0].Rows.Count == 0)
                {
                    oCN.RunProc("Insert Into Sc_StationOutBillMain " +
                    "(HBillType,HBillSubType,HInterID,HBillNo,HBillStatus,HDate,HMaker,HMakeDate,HMouldNum" +
                    ",HYear,HPeriod,HRemark,HSourceName,HPieceQty,HWasterQty,HPlanPieceQty,HBadPNL" +
                    ",HICMOInterID,HICMOBillNo,HProcPlanInterID,HProcPlanEntryID,HProcPlanBillNo,HProcExchInterID,HProcExchEntryID" +
                    ",HProcExchBillNo,HMaterID,HProcID,HICMOQty,HPlanQty,HStationOutTime,HSourceID,HPayProcID" +
                    ",HGroupID,HDeptID,HEmpID,HBarCode,HAddr,HBarCodeMaker,HBarCodeMakeDate,HSourceID2,HSourceID3,HSourceID4,HSourceID5" +
                    ",HSupID,HQty,HPrice,HMoney,HBadCount,HCenterID,HProcNo,HOrderProcNO,HSourceNameList" +
                    ",HMainSourceInterID,HMainSourceBillNo,HMainSourceBillType,HLastSubProc" +
                    ",HEmpID2,HEmpID3,HEmpID4,HEmpID5,HDSQty,HChongQty,HPriceRate,HWorkTimes,HQCCheckID,HMainInterID,HPRDOrgID" +
                        ",HmaterOutqty,HProcPriceRate,HTemporaryAreaID" +
                    ") " +
                    " values('" + BillType + "','"+ HBillSubType + "'," + HInterID + ",'" + HBillNo + "'," + HBillStatus + ",getdate(),'" + HMaker + "',getdate(),'" + HMouldNum + "'" +
                    "," + HYear + "," + HPeriod + ",'" + HRemark + "','" + HSourceName + "'," + HPieceQty + "," + HWasterQty + "," + HPlanPieceQty + "," + HBadPNL +
                    "," + HICMOInterID + ",'" + HICMOBillNo + "'," + HProcPlanInterID + "," + HProcPlanEntryID + ",'" + HProcPlanBillNo + "'," + HProcExchInterID + "," + HProcExchEntryID +
                    ",'" + HProcExchBillNo + "'," + HMaterID + "," + HProcID + "," + HICMOQty + "," + HPlanQty + ",getdate()," + HSourceID + "," + HPayProcID +
                    "," + HGroupID + "," + HDeptID + "," + HEmpID + ",'" + HBarCode + "','" + HAddr + "','" + HBarCodeMaker + "',getdate()" + "," + HSourceID2 + "," + HSourceID3 + "," + HSourceID4 + "," + HSourceID5 +
                    "," + HSupID + "," + HQty + "," + HPrice + "," + HMoney + "," + HBadCount + "," + HCenterID + "," + HProcNo + ",'" + HOrderProcNO + "'" + ",'" + HSourceNameList + "'" +
                    "," + HMainSourceInterID + ",'" + HMainSourceBillNo + "','" + HMainSourceBillType + "'," + Convert.ToString(HLastSubProc ? 1 : 0) +
                    "," + HEmpID2 + "," + HEmpID3 + "," + HEmpID4 + "," + HEmpID5 + "," + HDSQty + "," + HChongQty + "," + HPriceRate + "," + HWorkTimes + "," + HQCCheckID + "," + HMainInterID + "," + HPRDOrgID +
                  "," + HmaterOutqty + "," + HProcPriceRate + "," + HTemporaryAreaID + ") ");
                }
 
                oCN.RunProc($@"insert into Sc_StationOutBillSub_SN(HInterID,HBillNo_bak,HEntryID,HBarCode,HBarCodeQty,HMakeTime,HRemark,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney)
values({omodel.HInterID}, '{omodel.HBillNo}', {ds.Tables[0].Rows.Count + 1}, '{omodel.HBarCode_P}', 1, GETDATE(), '', 0, 0, '', '', 0, 0)");
 
                //反写工序出站单的合格数量
                oCN.RunProc("update Sc_StationOutBillMain set HQty+=1  where HProcExchInterID='" + HProcExchInterID + "' and HProcExchEntryID=" + HProcExchEntryID);
 
                oCN.Commit();
 
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                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("Cj_SingleStation/HBardCodeAccessoryList")]
        [HttpGet]
        public object HBardCodeAccessoryList(string HBarCode, string user)
        {
            try
            {
 
                ds = oCN.RunProcReturn(@"select * from h_v_Gy_BarCodeBill where HBarCode='" + HBarCode + "'", "h_v_Gy_BarCodeBill");
                if (ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "SN码查无数据!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
                {
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "";
                    objJsonResult.data = ds.Tables[0];
                }
 
                return objJsonResult;
            }
            catch (Exception e)
            {
 
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "没有返回任何记录!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
 
        #region  工序单品过站 扫SN码查询
        [Route("Cj_SingleStation/HBardCodeSNList")]
        [HttpGet]
        public object HBardCodeSNList(string HBarCode, string user)
        {
            try
            {
 
                ds = oCN.RunProcReturn("select * from gy_czygl where czymc='" + user + "'", "gy_czygl");
                string HProcID = ds.Tables[0].Rows[0]["HProcID"].ToString();
 
                ds = oCN.RunProcReturn(@"select * from h_v_Gy_BarCodeBillHICOMProcessExchange where 条码='" + HBarCode + "' ", "h_v_Gy_BarCodeBillHICOMProcessExchange");
 
                if (ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "条码查无数据!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
                if (ds.Tables[0].Rows[0]["HProcID"].ToString() != HProcID)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "当前条码与当前工序不匹配!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
                if (ds.Tables[0].Rows[0]["HStatus"].ToString() != "正常") {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "当前条码状态为"+ ds.Tables[0].Rows[0]["HStatus"].ToString() + "!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "";
                objJsonResult.data = ds.Tables[0];
                return objJsonResult;
            }
            catch (Exception e)
            {
 
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "没有返回任何记录!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
 
        #region  工序单品过站 查询不良记录
        [Route("Cj_SingleStation/BadRecordsList")]
        [HttpGet]
        public object BadRecordsList(string HBarCode, string user)
        {
            try
            {
 
                ds = oCN.RunProcReturn(@"select * from h_v_Gy_BadRecordsList where HProcExchBillNo='" + HBarCode + "'", "h_v_Gy_BadRecordsList");
 
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "";
                objJsonResult.data = ds.Tables[0];
                return objJsonResult;
            }
            catch (Exception e)
            {
 
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "没有返回任何记录!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
 
        #region  工序单品过站 查询合格记录
        [Route("Cj_SingleStation/HGRecordsList")]
        [HttpGet]
        public object HGRecordsList(string sWhere, string user)
        {
            try
            {
 
                ds = oCN.RunProcReturn(@"select * from h_v_Gy_QualifiedRecordsList where 1=1"+ sWhere, "h_v_Gy_QualifiedRecordsList");
 
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "";
                objJsonResult.data = ds.Tables[0];
                return objJsonResult;
            }
            catch (Exception e)
            {
 
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "没有返回任何记录!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
 
        #region 工序单品过站 删除不良记录
        [Route("Cj_SingleStation/DelBadRecords")]
        [HttpGet]
        public object DelBadRecords(int HInterID, int HEntryID, string user,int HProcID)
        {
            try
            {
                ds = oCN.RunProcReturn("select * from h_v_Gy_BadRecordsList  where HInterID = " + HInterID, "h_v_Gy_BadRecordsList");
 
                if (ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "查无数据!";
                    objJsonResult.data = null;
                }
 
                oCN.BeginTran();
 
                string sql = "";
                sql = "delete from Sc_QualityReportBillMain where HInterID = " + HInterID;
                oCN.RunProc(sql);
                sql = "delete from Sc_QualityReportBillSub where HInterID = " + HInterID + " and HEntryID = " + HEntryID;
                oCN.RunProc(sql);
                string HProcExchInterID = ds.Tables[0].Rows[0]["HProcExchInterID"].ToString();
                string HProcExchEntryID = ds.Tables[0].Rows[0]["HProcExchEntryID"].ToString();
                //反写工序出站单的不良数量
                oCN.RunProc("update Sc_StationOutBillMain set HBadCount-=1  where HProcExchInterID='" + HProcExchInterID + "' and HProcExchEntryID=" + HProcExchEntryID);
 
 
                oCN.Commit();
 
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            catch (Exception e)
            {
                oCN.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
 
        #region 工序单品过站 删除合格记录
        [Route("Cj_SingleStation/DelQualifiedRecords")]
        [HttpGet]
        public object DelQualifiedRecords(int HInterID, int HEntryID, string user)
        {
            try
            {
                ds = oCN.RunProcReturn("select * from h_v_Gy_QualifiedRecordsList  where hmainid = " + HInterID, "h_v_Gy_QualifiedRecordsList");
 
                if (ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "查无数据!";
                    objJsonResult.data = null;
                }
 
                oCN.BeginTran();
 
                string sql = "";
                if (ds.Tables[0].Rows.Count == 1) {
                    sql = "delete from Sc_StationOutBillMain where HInterID = " + HInterID;
                    oCN.RunProc(sql);
                }
                sql = "delete from Sc_StationOutBillSub_SN where HInterID = " + HInterID + " and HEntryID = " + HEntryID;
                oCN.RunProc(sql);
                string HProcExchInterID = ds.Tables[0].Rows[0]["HProcExchInterID"].ToString();
                string HProcExchEntryID = ds.Tables[0].Rows[0]["HProcExchEntryID"].ToString();
                //反写工序出站单的合格数量
                oCN.RunProc("update Sc_StationOutBillMain set HBadCount-=1  where HProcExchInterID='" + HProcExchInterID + "' and HProcExchEntryID=" + HProcExchEntryID);
 
 
                oCN.Commit();
 
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            catch (Exception e)
            {
                oCN.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
 
        #region  工序单品返修台 扫码查询
        [Route("Cj_SingleStation/HFBardCodeList")]
        [HttpGet]
        public object HFBardCodeList(string HBarCode, string user)
        {
            try
            {
                ds = oCN.RunProcReturn("select * from gy_czygl where czymc='" + user + "'", "gy_czygl");
                string HProcID = ds.Tables[0].Rows[0]["HProcID"].ToString();
 
                ds = oCN.RunProcReturn(@"select * from h_v_Gy_BarCodeBillHICOMProcessExchange where 条码='" + HBarCode + "' ", "h_v_Gy_BarCodeBillHICOMProcessExchange");
 
                if (ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "条码查无数据!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
                if (ds.Tables[0].Rows[0]["HProcID"].ToString() != HProcID)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "当前条码与当前工序不匹配!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
                if (ds.Tables[0].Rows[0]["HStatus"].ToString() != "不良")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "当前条码状态为" + ds.Tables[0].Rows[0]["HStatus"].ToString() + "!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
 
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "";
                objJsonResult.data = ds.Tables[0];
                return objJsonResult;
            }
            catch (Exception e)
            {
 
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "没有返回任何记录!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
 
        #region 工序单品返修台 获取表格数据
        [Route("Cj_SingleStation/ProcessItemRepair")]
        [HttpGet]
        public object ProcessItemRepair( string sWhere, string user)
        {
            try
            {
                List<object> columnNameList = new List<object>();
 
                string sql = @"select * from h_v_Cj_BarCodeProcessItemRepair  where  1=1 " + sWhere + " order by 日期 desc, HInterID desc, HEntryID desc";
                ds = oCN.RunProcReturn(sql, "h_v_Cj_BarCodeProcessItemRepair");
 
                //添加列名
                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 = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                objJsonResult.list = columnNameList;
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
 
        #region 工序单品返修台 保存
        [Route("Cj_SingleStation/HFXAddRepairBill")]
        [HttpPost]
        public object HFXAddRepairBill([FromBody] JObject sMainSub)
        {
            try
            {
                var _value = sMainSub["sMainSub"].ToString();
                string msg = _value.ToString();
                string[] sArray = msg.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                string sMainStr = sArray[0].ToString();
                string sSubStr = sArray[1].ToString();
                string user = sArray[2].ToString();
                string HResult = sArray[3].ToString();
 
                oCN.BeginTran();
                if (HResult == "配件")
                {
                    Model.ClsSc_SourceLineRepairBillMain model = new Model.ClsSc_SourceLineRepairBillMain();
                    model = JsonConvert.DeserializeObject<Model.ClsSc_SourceLineRepairBillMain>(sMainStr);
 
                    Model.Sc_AssemblyBill_BindSourceTemp temp = new Model.Sc_AssemblyBill_BindSourceTemp();
                    temp = JsonConvert.DeserializeObject<Model.Sc_AssemblyBill_BindSourceTemp>(sSubStr);
 
                    ds = oCN.RunProcReturn("select * from Sc_SourceLineRepairBillSub_Mater where HInterID=" + model.HInterID+ " order by HEntryID  desc", "Sc_SourceLineRepairBillSub_Mater");
 
                    oCN.RunProc($@"insert into Sc_SourceLineRepairBillSub_Mater
(HInterID,HEntryID,HBillNo_bak,HRemark,HSourceInterID
,HSourceEntryID,HSourceBillNo,HSourceBillType,HMaterID
,HUnitID,HBarCode,HBatchNo )values
({model.HInterID},{(ds.Tables[0].Rows.Count == 0 ? 1 : int.Parse(ds.Tables[0].Rows[0]["HEntryID"].ToString()) + 1)},'{model.HBillNo}','',{temp.HProcExchInterID}
,{temp.HProcExchEntryID},'{temp.HProcExchBillNo}','',{temp.HMaterID},0,'{temp.HBarCode}','{temp.HBatchNo}')");
 
                    //修改配件绑定清单绑定的条码批号
                    oCN.RunProc("exec h_p_AssemblyBill_Temp '" + temp.HProcExchBillNo + "'," + model.HProcess + "," + temp.HMaterID + ",'" + temp.HBatchNo + "'");
                }
                else if (HResult == "NG"|| HResult == "OK") {
                    Model.ClsSc_SourceLineRepairBillMain model = new Model.ClsSc_SourceLineRepairBillMain();
                    model = JsonConvert.DeserializeObject<Model.ClsSc_SourceLineRepairBillMain>(sMainStr);
 
                    oCN.RunProc($@"insert into Sc_SourceLineRepairBillMain(HYear, HPeriod, HBillType, HBillSubType, HInterID,
HDate, HBillNo, HBillStatus, HRemark, HEmpID, HDeptID, HSourceID, HProdOrgID, HMaterID, HWorkStationID,
HProcess, HIPAddr, HMacAddr, HProdMac, HBarCode,HMaker,HMakeDate,HMainSourceInterID,HMainSourceEntryID,HMainSourceBillNo)
values('{DateTime.Now.Year}','{DateTime.Now.Month}','3748','3748',{model.HInterID}
,getdate(),'{model.HBillNo}','1','{HResult}',{model.HEmpID},{model.HDeptID},{model.HSourceID},{model.HProdOrgID},{model.HMaterID},0
,{model.HProcess},'','','','{model.HBarCode}','{user}',getdate(),{model.HICMOInterID},{model.HICMOEntryID},'{model.HICMOBillNo}')");
 
                    List<Model.ClsSc_SourceLineRepairBillSub> subLsit = new List<Model.ClsSc_SourceLineRepairBillSub>();
                    sMainStr = "[" + sMainStr + "]";
                    subLsit = JsonConvert.DeserializeObject<List<Model.ClsSc_SourceLineRepairBillSub>>(sMainStr);
 
                    oCN.RunProc($@"insert into Sc_SourceLineRepairBillSub
(HInterID,HEntryID,HBillNo_bak,HRemark,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType
,HBadReasonID,HBadTypeID,HBadResultID,HBadProcID,HRepairResult,HCreator,HCreateDate)
values({model.HInterID},1,'{model.HBillNo}','',{subLsit[0].HProcExchInterID},{subLsit[0].HProcExchEntryID},'{subLsit[0].HProcExchBillNo}',''
,{subLsit[0].HBadReasonID},{subLsit[0].HBadTypeID},{subLsit[0].HBadResultID},{model.HProcess},'{HResult}','{subLsit[0].HCreator}',getdate())");
 
                    if (HResult == "OK")
                    {
                        oCN.RunProc("update Gy_BarCodeBill set HStatus='' where HBarCode='" + model.HBarCode + "'");
                    }
                }
                else {
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "Sucess!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
 
                oCN.Commit();
 
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            catch (Exception e)
            {
                oCN.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
 
        #region 工序单品返修台 删除返修单
        [Route("Cj_SingleStation/ProcessItemRepairDel")]
        [HttpGet]
        public object ProcessItemRepairDel(int HInterID,int HEntryID,string user,string HBill)
        {
            try
            {
                ds = oCN.RunProcReturn("select * from Sc_SourceLineRepairBillMain  where HInterID = " + HInterID, "Sc_SourceLineRepairBillMain");
 
                if (ds.Tables[0].Rows.Count == 0) {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "查无数据!";
                    objJsonResult.data = null;
                }
 
                oCN.BeginTran();
 
                string sql = "";
                if (HBill == "ZB")
                {
                    sql = "delete from Sc_SourceLineRepairBillMain where HInterID = " + HInterID;
                    oCN.RunProc(sql);
                    sql = "delete from Sc_SourceLineRepairBillSub where HInterID = " + HInterID + " and HEntryID = " + HEntryID;
                    oCN.RunProc(sql);
                }
 
                if (HBill == "PJ")
                {
                    sql = "delete from Sc_SourceLineRepairBillSub_Mater where HInterID = " + HInterID + " and HEntryID = " + HEntryID;
                    oCN.RunProc(sql);
                }
                else
                {
                    sql = "delete from Sc_SourceLineRepairBillSub_Mater where HInterID = " + HInterID;
                    oCN.RunProc(sql);
                }
             
                oCN.Commit();
 
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data =null;
                return objJsonResult;
            }
            catch (Exception e)
            {
                oCN.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
 
        #region 工序单品返修台--配件更换 查询更换记录
        [Route("Cj_SingleStation/Sc_SourceLineRepairBillSub_MaterList")]
        [HttpGet]
        public object Sc_SourceLineRepairBillSub_MaterList(string sWhere, string user)
        {
            try
            {
                string sql = @"select * from h_v_Sc_SourceLineRepairBillList  where  1=1 " + sWhere + " order by   HInterID desc";
                ds = oCN.RunProcReturn(sql, "h_v_Sc_SourceLineRepairBillList");
 
                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
 
    }
}