1
zrg
2025-06-10 5dc617f5cd10ad344ee877f73257b43c51db5201
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
using DBUtility;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Pub_Class;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;
using WebAPI.Controllers.SCGL.日计划管理;
using WebAPI.Models;
 
namespace WebAPI.Controllers.生产管理.客户标签
{
    public class Sc_CustomerTagController : ApiController
    {
        private json objJsonResult = new json();
        SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
        DataSet ds;
        public DAL.ClsSc_CustomerTagInfo BillOld = new DAL.ClsSc_CustomerTagInfo();
 
        #region 客户标签信息 查询-分页
        [Route("Sc_CustomerTagInfo/PageList")]
        [HttpGet]
        public object PageList(string sWhere, string user, string Organization, int page, int size)
        {
            try
            {
                List<object> columnNameList = new List<object>();  //定义声明变量 ,把通过 new List<object>()创建的 实例,赋值给变量
                //判断是否有查询权限
                if (!DBUtility.ClsPub.Security_Log("Sc_CustomerTagInfo_Query", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无权限查询!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
                if (sWhere == null || sWhere.Equals(""))
                {
                    ds = oCN.RunProcReturn("exec h_p_Sc_CustomerTagInfoList " + page + "," + size + ",'" + Organization + "'," + "''", "h_p_Sc_CustomerTagInfoList");
                }
                else
                {
                    sWhere = sWhere.Replace("'", "''");
                    ds = oCN.RunProcReturn("exec h_p_Sc_CustomerTagInfoList " + page + "," + size + ",'" + Organization + "','" + sWhere + "'", "h_p_Sc_CustomerTagInfoList");
                }
 
                //添加列名
                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 = int.Parse(ds.Tables[1].Rows[0]["count"].ToString());
                objJsonResult.Message = "Sucess!";
                objJsonResult.list = columnNameList;
                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_CustomerTagInfo/EditCX")]
        [HttpGet]
        public object EditCX(long HInterID)
        {
            try
            {
 
                ds = oCN.RunProcReturn("select * from h_v_Sc_CustomerTagInfoEdit where hmainid=" + HInterID, "h_v_Sc_CustomerTagInfoEdit");
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "false!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
                {
                    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_CustomerTagInfo/SaveCustomerTagInfo")]
        [HttpPost]
        public object SaveCustomerTagInfo([FromBody] JObject msg)
        {
            var _value = msg["msg"].ToString();
            string msg1 = _value.ToString();
            string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
            string msg2 = sArray[0].ToString();
            string msg3 = sArray[1].ToString();
            string user = sArray[2].ToString();
            string OperationType = sArray[3].ToString();
 
            ListModels oListModels = new ListModels();
            try
            {
                //判断权限
                if (!DBUtility.ClsPub.Security_Log("Sc_CustomerTagInfo_Edit", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无保存权限";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                DAL.ClsSc_CustomerTagInfo oBill = new DAL.ClsSc_CustomerTagInfo();
                List<Model.ClsSc_CustomerTagInfoMain> lsmain = new List<Model.ClsSc_CustomerTagInfoMain>();
                msg2 = msg2.Replace("\\", "");
                msg2 = msg2.Replace("\n", "");  //\n
                lsmain = oListModels.getCustomerTagInfoMainByJson(msg2);
                foreach (Model.ClsSc_CustomerTagInfoMain oItem in lsmain)
                {
                    oItem.HMaker = user;
                    oItem.HUpDater = user;
 
                    if (DBUtility.ClsPub.isStrNull(oItem.HDate) == "")
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "保存失败!没有单据日期,无法保存!";
                        objJsonResult.data = 1;
                        return objJsonResult;
                    }
                    oBill.omodel = oItem;
                }
                //表体数据
                //按 },{来拆分数组 //去掉【和】
                msg3 = msg3.Substring(1, msg3.Length - 2);
                msg3 = msg3.Replace("\\", "");
                msg3 = msg3.Replace("\n", "");  //\n
                List<Model.ClsSc_CustomerTagInfoSub> ls = new List<Model.ClsSc_CustomerTagInfoSub>();
                ls = oListModels.getCustomerTagInfoSubByJson(msg3);
                int i = 0;
                foreach (Model.ClsSc_CustomerTagInfoSub oItemSub in ls)
                {
                    i++;
                    oItemSub.HEntryID = i;
                    oItemSub.HEntryCloseDate = DBUtility.ClsPub.isDate(DateTime.Now);
                    oItemSub.HCloseType = false;
                    oItemSub.HCloseMan = "";
                    oBill.DetailColl.Add(oItemSub);
                }
 
                //进行 会计期间 结账 的判断和控制
                string s = "";
                int sYear = 0;
                int sPeriod = 0;
                DateTime HDate = DateTime.Now;
                if (DBUtility.Xt_BaseBillFun.Fun_AllowYearPeriod(HDate, ref sYear, ref sPeriod, ref s) == false)
                {
                    objJsonResult.Message = s;
                    return objJsonResult;
                }
 
                //保存
                //保存完毕后处理
                bool bResult;
                if (Convert.ToInt32(OperationType) == 1)                                //新增保存
                {
                    bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
                }
                else if (Convert.ToInt32(OperationType) == 4)                          //下推保存
                {
                    bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
                }
                else                                                                    //编辑保存
                {
                    if (BillOld.ShowBill(lsmain[0].HInterID, ref s) == false)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "此单据有误!";
                        objJsonResult.data = 1;
                        return objJsonResult;
                    }
                    //判断是否可编辑
                    if (BillOld.omodel.HChecker != "" && BillOld.omodel.HChecker != null)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "此单据已经被审核,不允许修改!";
                        objJsonResult.data = 1;
                        return objJsonResult;
                    }
                    if (BillOld.omodel.HBillStatus > 1)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "此单据处于不可编辑状态,不允许修改!";
                        objJsonResult.data = 1;
                        return objJsonResult;
                    }
                    if (!DBUtility.Xt_BaseBillFun.Fun_AllowEditBill(BillOld, ref s))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = s + ",不允许修改";
                        objJsonResult.data = 1;
                        return objJsonResult;
                    }
 
                    bResult = oBill.ModifyBill(oBill.omodel.HInterID, ref DBUtility.ClsPub.sExeReturnInfo);
                }
 
                if (bResult)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "保存成功!";
                    objJsonResult.data = 1;
                    return objJsonResult;
                }
                else
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "保存失败!" + DBUtility.ClsPub.sExeReturnInfo;
                    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("Sc_CustomerTagInfo/Sc_CustomerTagInfo_Excel")]
        [HttpPost]
        public object Sc_CustomerTagInfo_Excel()
        {
            try
            {
                //获取文件名称
                var file = HttpContext.Current.Request.Files[0];
                //获取文件物理路径
                string ExcelPath = HttpContext.Current.Server.MapPath("~/" + file.FileName);
                //保存文件
                file.SaveAs(ExcelPath);
 
                NpoiHelper np = new NpoiHelper();
                DataSet ExcelDs = np.ReadExcel(ExcelPath, 1, 1, "0");
 
                //删除文件
                File.Delete(ExcelPath);
 
                //创建临时表
                DataTable tb2 = new DataTable("dt2");
 
                //添加列名
                for (int i = 0; i < ExcelDs.Tables[0].Columns.Count; i++)
                {
                    tb2.Columns.Add(ExcelDs.Tables[0].Rows[0][i].ToString());
                }
 
                //模板缺少列 但需要从数据库中查询出来显示在页面的字段
                tb2.Columns.Add("HMaterID", typeof(Int32));//物料ID
                tb2.Columns.Add("HCustID", typeof(Int32));//客户ID
 
                //添加数据
                for (int i = 1; i < ExcelDs.Tables[0].Rows.Count; i++)
                {
                    DataRow row = tb2.NewRow();
                    for (int j = 0; j < ExcelDs.Tables[0].Columns.Count; j++)
                    {
                        row[j] = ExcelDs.Tables[0].Rows[i][j].ToString();
                    }
                    //如果表格第i行的第一列为空,则判断为这一行的数据为空,跳出循环并且不把数据写入 tb2
                    if (ExcelDs.Tables[0].Rows[i][0].ToString() == "")
                    {
                        continue;
                    }
                    else
                    {
                        tb2.Rows.Add(row);
                    }
                }
 
                var error = "";
 
                //查询工序工价没有的列
                if (!tb2.Columns.Contains("物料代码"))
                    error += "没有找到【物料代码】的标题,";
 
                if (!tb2.Columns.Contains("物料名称"))
                    error += "没有找到【物料名称】的标题,";
 
                if (!tb2.Columns.Contains("客户代码"))
                    error += "没有找到【客户代码】的标题,";
 
                if (!tb2.Columns.Contains("客户名称"))
                    error += "没有找到【客户名称】的标题,";
 
                if (!tb2.Columns.Contains("EPE%"))
                    error += "没有找到【EPE%】的标题,";
 
                if (!tb2.Columns.Contains("PU%"))
                    error += "没有找到【PU%】的标题,";
 
                if (!tb2.Columns.Contains("SKU"))
                    error += "没有找到【SKU】的标题,";
 
                if (!tb2.Columns.Contains("SIZE1"))
                    error += "没有找到【SIZE1】的标题,";
 
                if (!tb2.Columns.Contains("SIZE2"))
                    error += "没有找到【SIZE2】的标题,";
 
                if (!tb2.Columns.Contains("LBS"))
                    error += "没有找到【LBS】的标题,";
 
                if (!tb2.Columns.Contains("OZ"))
                    error += "没有找到【OZ】的标题,";
 
                if (!tb2.Columns.Contains("UPC A"))
                    error += "没有找到【UPC A】的标题,";
 
                if (!tb2.Columns.Contains("SKU2"))
                    error += "没有找到【SKU2】的标题,";
 
                if (!tb2.Columns.Contains("FABRIC"))
                    error += "没有找到【FABRIC】的标题,";
 
                if (!tb2.Columns.Contains("SN号"))
                    error += "没有找到【SN号】的标题,";
 
                if (!tb2.Columns.Contains("尺寸"))
                    error += "没有找到【尺寸】的标题,";
 
                if (!tb2.Columns.Contains("客户指定代码"))
                    error += "没有找到【客户指定代码】的标题,";
 
                if (!tb2.Columns.Contains("客户指定名称"))
                    error += "没有找到【客户指定名称】的标题,";
 
                if (!tb2.Columns.Contains("客户指定规格"))
                    error += "没有找到【客户指定规格】的标题,";
            
 
                if (error.Length > 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = $"Excel模板存在错误,{error}\r\n";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
                for (int i = 0; i <= tb2.Rows.Count - 1; i++)
                {
                    string HMaterNumber = "";
                    string HMaterName = "";
                    string HCustNumber = "";
                    string HCustName = "";
                    string HEPE = "";
                    string HPU = "";
                    string HSKU = "";
                    string HSIZE1 = "";
                    string HSIZE2 = "";
                    string HLBS = "";
                    string HOZ = "";
                    string HUPC = "";
                    string HSKU2 = "";
                    string HFABRIC = "";
                    string HSN = "";
                    string HSize = "";
                    string HCustMaterNumber = "";
                    string HCustMaterName = "";
                    string HCustMaterModel = "";
                   
 
                    HMaterNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["物料代码"].ToString());
                    HMaterName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["物料名称"].ToString());
                    HCustNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["客户代码"].ToString());
                    HCustName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["客户名称"].ToString());
                    HEPE = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["EPE%"].ToString());
                    HPU = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["PU%"].ToString());
                    HSKU = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["SKU"].ToString());
                    HSIZE1 = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["SIZE1"].ToString());
                    HSIZE2 = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["SIZE2"].ToString());
                    HLBS = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["LBS"].ToString());
                    HOZ = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["OZ"].ToString());
                    HUPC = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["UPC A"].ToString());
                    HSKU2 = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["SKU2"].ToString());
                    HFABRIC = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["FABRIC"].ToString());
                    HSN = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["SN号"].ToString());
                    HSize = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["尺寸"].ToString());
                    HCustMaterNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["客户指定代码"].ToString());
                    HCustMaterName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["客户指定名称"].ToString());
                    HCustMaterModel = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["客户指定规格"].ToString());
 
 
                    //检查表格数据
                    int index = i + 1;
 
                    if (HMaterNumber != "" && HMaterName != "")
                    {
                        //查询物料
                        ds = oCN.RunProcReturn("select HItemID,HNumber,HName,HModel from Gy_Material with(nolock) where  HNumber='" + HMaterNumber + "' and HName='" + HMaterName + "'", "Gy_Material");
 
                        if (ds.Tables[0].Rows.Count == 0)
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "第" + index + "行,物料不存在!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        else
                        {
                            tb2.Rows[i]["HMaterID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
                        }
 
                        //查询客户
                        ds = oCN.RunProcReturn("select HItemID,HNumber,HName from Gy_Customer with(nolock) where  HNumber='" + HCustNumber + "'", "Gy_Process");
 
                        if (ds.Tables[0].Rows.Count == 0)
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "第" + index + "行,客户不存在!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        else
                        {
                            tb2.Rows[i]["HCustID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
                        }
                    }
                    else
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "第" + index + "行,物料信息不全(物料代码,物料名称)";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
 
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = error;
                objJsonResult.data = tb2;
                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_CustomerTagInfo/Sc_CustomerTagInfo_btnSave")]
        [HttpPost]
        public object Sc_CustomerTagInfo_btnSave([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 user = sArray[1].ToString();
            try
            {
                if (!DBUtility.ClsPub.Security_Log("Sc_CustomerTagInfo_Edit", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无保存权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
                List<object> Excel = Newtonsoft.Json.JsonConvert.DeserializeObject<List<object>>(msg2);
                List<Dictionary<string, string>> list = new List<Dictionary<string, string>>();
 
                foreach (JObject item in Excel)
                {
                    Dictionary<string, string> dic = new Dictionary<string, string>();
                    foreach (var itm in item.Properties())
                    {
                        dic.Add(itm.Name, itm.Value.ToString());
                    }
                    list.Add(dic);
                }
 
                oCN.BeginTran();
                long HInterID =  DBUtility.ClsPub.CreateBillID("10003", ref DBUtility.ClsPub.sExeReturnInfo);
                string HBillNo = DBUtility.ClsPub.CreateBillCode("10003", ref DBUtility.ClsPub.sExeReturnInfo,true);
 
                string mainSql = "Insert Into Sc_CustomerTagInfoMain" +
                   "(HInterID,HBillNo,HDate,HYear,HPeriod,HRemark,HMaker,HMakeDate,HBillStatus" +
                   ",HMainSourceInterID,HMainSourceEntryID,HMainSourceBillNo,HMainSourceBillType" +
                   ") " +
                   "values(" +
                   "" + HInterID + 
                   ",'" + HBillNo + "'" +
                   ",getdate()" +
                   ",Year(getdate())" +
                   ",Month(getdate())" +
                   "," + "''" +
                   ",'" + "Excel" + "'" +
                   "," + "getdate()" + "" +
                   "," + "1" + "" +
                   "," + 0 + "" +
                   "," + 0 + "" +
                   ",'" + "''" + "'" +
                   ",'" + "''" + "'" +
                   ") ";
 
                oCN.RunProc(mainSql);
 
                int i = 1;
                foreach (Dictionary<string, string> item in list)
                {
                    string HMaterNumber = item["物料代码"];
                    string HMaterName = item["物料名称"];
                    string HCustNumber = item["客户代码"];
                    string HCustName = item["客户名称"];
                    string HEPE = item["EPE%"];
                    string HPU = item["PU%"];
                    string HSKU = item["SKU"];
                    string HSIZE1 = item["SIZE1"];
                    string HSIZE2 = item["SIZE2"];
                    string HLBS = item["LBS"];
                    string HOZ = item["OZ"];
                    string HUPC = item["UPC A"];
                    string HSKU2 = item["SKU2"];
                    string HFABRIC = item["FABRIC"];
                    string HSN = item["SN号"];
                    string HSize = item["尺寸"];
                    string HCustMaterNumber = item["客户指定代码"];
                    string HCustMaterName = item["客户指定名称"];
                    string HCustMaterModel = item["客户指定规格"];
                    Int32 HMaterID = Convert.ToInt32(item["HMaterID"]);
                    Int32 HCustID = Convert.ToInt32(item["HCustID"]);
 
 
                    ds = oCN.RunProcReturn("select HMaterID,HCustID from Sc_CustomerTagInfoSub with(nolock) where HMaterID=" + HMaterID + " and HCustID = " + HCustID, "Sc_CustomerTagInfoSub");
 
                    if (ds.Tables[0].Rows.Count == 0)
                    {
                        string sql = "insert into Sc_CustomerTagInfoSub(HInterID,HEntryID,HRemark,HBillNo_bak,HMaterID,HCustID,HEPE,HPU,HSKU,HSIZE1,HSIZE2,HLBS,HOZ,HUPC,HSKU2" +
                            ",HFABRIC,HSN,HSize,HCustMaterNumber,HCustMaterName,HCustMaterModel,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType)" +
                            $"values('{HInterID}', '{i}','{""}', '{HBillNo}', '{HMaterID}', '{HCustID}', '{HEPE}','{HPU}','{HSKU}','{HSIZE1}','{HSIZE2}','{HLBS}','{HOZ}','{HUPC}','{HSKU2}','{HFABRIC}','{HSN}','{HSize}','{HCustMaterNumber}','{HCustMaterName}','{HCustMaterModel}',{0},{0},'{""}','{""}')";
                        oCN.RunProc(sql);
 
                        i++;
                    }
                    else
                    {
                        oCN.RunProc("update Sc_CustomerTagInfoSub set HEPE='" + HEPE + "',HPU='" + HPU + "',HSKU='" + HSKU + "',HSIZE1='" + HSIZE1 + "',HSIZE2='" + HSIZE2 + "',HLBS='" + HLBS + "',HOZ='" + HOZ + "',HUPC='" + HUPC + "',HSKU2='" + HSKU2 + "',HFABRIC='" + HFABRIC + "',HSN='" + HSN + "',HSize='" + HSize + "',HCustMaterNumber='" + HCustMaterNumber + "',HCustMaterName='" + HCustMaterName + "',HCustMaterModel='" + HCustMaterModel + "'  where HMaterID=" + HMaterID + " and HCustID=" + HCustID);
                    }
 
                    i++;
                }
 
                oCN.Commit();
 
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "导入成功!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            catch (Exception e)
            {
                oCN.RollBack();
                LogService.Write(e);
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
 
        #region [客户标签信息删除功能]
        [Route("Sc_CustomerTagInfo/Delete")]
        [HttpGet]
        public object Delete(string HItemSubIDs, string user)
        {
            try
            {
                DataSet Ds;
                DataSet Ds2;
 
                if (HItemSubIDs == "")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "[0000-1-009]选择客户标签信息为空!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
 
                Ds = oCN.RunProcReturn("Select * from h_v_Sc_CustomerTagInfoList with(nolock) Where HItemSubID in (" + HItemSubIDs + ")", "h_v_Sc_CustomerTagInfoList");
                if (Ds.Tables[0].Rows.Count != 0)
                {
                    oCN.BeginTran();
 
                    //删除客户标签信息--子表
                    oCN.RunProc("Delete from Sc_CustomerTagInfoSub Where HItemSubID in (" + HItemSubIDs + ")");
 
                    //写入系统日志
                    for (int i = 0; i < Ds.Tables[0].Rows.Count; i++)
                    {
                        oCN.RunProc("Insert into System_log (GeginDate, userid, WorkstationName, WorkList, SystemName, NetuserName, State) select GETDATE(),'" + user + "','','" + "Sc_CustomerTagInfoList——Delete" + "','LMES-客户标签信息模块','" + DBUtility.ClsPub.IPAddress + "','" + user + "删除客户标签信息," + "客户名称:" + Ds.Tables[0].Rows[i]["客户名称"] + ",物料代码:" + Ds.Tables[0].Rows[i]["物料代码"] + ",单据号:" + Ds.Tables[0].Rows[i]["单据号"] + "'", ref DBUtility.ClsPub.sExeReturnInfo);
                    }
 
                    oCN.Commit();
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "[0000-1-008]删除成功";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "[0000-1-045]单据未找到";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
            }
            catch (Exception e)
            {
                oCN.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "[0000-1-007]" + e.Message;
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
 
 
        #region 客户标签档案生成
        [Route("Sc_CustomerTagBarCode/Save")]
        [HttpGet]
        public object BarCodeSave(string HICMOInterID, string HICMOEntryID)
        {
            try
            {
               
                if (HICMOInterID == null || HICMOInterID.Equals("") || HICMOEntryID == null || HICMOEntryID.Equals(""))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "订单信息不全!HICMOInterID:" + HICMOInterID + ",HICMOEntryID:" + HICMOEntryID;
                    objJsonResult.data = ds.Tables[0];
                    return objJsonResult;
                }
                else
                {                   
                    ds = oCN.RunProcReturn("exec h_p_Sc_CustomerTagBarCode_AutoSave " + HICMOInterID + "," + HICMOEntryID, "h_p_Sc_CustomerTagBarCode_AutoSave");
                }
 
                if (DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBack"]) != "0")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "失败!" + DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBackRemark"]);
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
                {
                    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_CustomerTagBarCode/BarPageList")]
        [HttpGet]
        public object BarPageList(string sWhere, string user, string Organization, int page, int size)
        {
            try
            {
                List<object> columnNameList = new List<object>();  //定义声明变量 ,把通过 new List<object>()创建的 实例,赋值给变量
 
                if (sWhere == null || sWhere.Equals(""))
                {
                    ds = oCN.RunProcReturn("exec h_p_Sc_CustomerTagBarCodeList " + page + "," + size + ",'" + Organization + "'," + "''", "h_p_Sc_CustomerTagBarCodeList");
                }
                else
                {
                    sWhere = sWhere.Replace("'", "''");
                    ds = oCN.RunProcReturn("exec h_p_Sc_CustomerTagBarCodeList " + page + "," + size + ",'" + Organization + "','" + sWhere + "'", "h_p_Sc_CustomerTagBarCodeList");
                }
 
                //添加列名
                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 = int.Parse(ds.Tables[1].Rows[0]["count"].ToString());
                objJsonResult.Message = "Sucess!";
                objJsonResult.list = columnNameList;
                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_CustomerTagBarCode/DeleteBarCode")]
        [HttpGet]
        public object DeleteBarCode(string HItemIDs,string user)
        {
            try
            {
                DataSet Ds;
 
                if (HItemIDs == "")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "[0000-1-009]选择条码为空!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
 
                Ds = oCN.RunProcReturn("Select * from h_v_Sc_CustomerTagBarCodeList with(nolock) Where HItemID in (" + HItemIDs + ")", "h_v_Sc_CustomerTagBarCodeList");
                if (Ds.Tables[0].Rows.Count != 0)
                {
                    oCN.BeginTran();
 
                    //删除客户标签条码
                    oCN.RunProc("Delete from Sc_CustomerTagBarCode Where HItemID in (" + HItemIDs + ")");
 
                    //写入系统日志
                    for (int i = 0; i < Ds.Tables[0].Rows.Count; i++)
                    {
                        oCN.RunProc("Insert into System_log (GeginDate, userid, WorkstationName, WorkList, SystemName, NetuserName, State) select GETDATE(),'" + user + "','','" + "Sc_CustomerTagBarCodeList——Delete" + "','LMES-客户标签条码模块','" + DBUtility.ClsPub.IPAddress + "','" + user + "删除客户标签条码," + "生产订单:" + Ds.Tables[0].Rows[i]["生产订单号"] + ",物料代码:" + Ds.Tables[0].Rows[i]["物料代码"] + ",流水号:" + Ds.Tables[0].Rows[i]["流水号"] + "'", ref DBUtility.ClsPub.sExeReturnInfo);
                    }
 
                    oCN.Commit();
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "[0000-1-008]删除成功";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "[0000-1-045]单据未找到";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
            }
            catch (Exception e)
            {
                oCN.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "[0000-1-007]" + e.Message;
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
 
        #region 客户标签档案重新生成
        [Route("Sc_CustomerTagBarCode/ReSave")]
        [HttpGet]
        public object BarCodeReSave(string HICMOInterID, string HICMOEntryID, string HSerialNum)
        {
            try
            {
 
                if (HICMOInterID == null || HICMOInterID.Equals("") || HICMOEntryID == null || HICMOEntryID.Equals("") || HSerialNum == null || HSerialNum.Equals(""))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "订单信息不全!HICMOInterID:" + HICMOInterID + ",HICMOEntryID:" + HICMOEntryID + ",HSerialNum:" + HSerialNum;
                    objJsonResult.data = ds.Tables[0];
                    return objJsonResult;
                }
                else
                {
                    ds = oCN.RunProcReturn("exec h_p_Sc_CustomerTagBarCode_AutoReSave " + HICMOInterID + "," + HICMOEntryID + "," + HSerialNum, "h_p_Sc_CustomerTagBarCode_AutoReSave");
                }
 
                if (DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBack"]) != "0")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "失败!" + DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBackRemark"]);
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
                {
                    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
 
    }
}