bklLiudl
2024-07-23 277bbae216debe7e6c04e8cc6ee6e1ba9763e14b
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
using BLL;
using BLL.DAL;
using Common;
using Json;
using Lib;
using Model;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Script.Serialization;
 
namespace wms.Areas.Business.Controllers
{
    public class IPalletBindAjaxController : AjaxPage
    {
        public ActionResult GetBindList()
        {
            try
            {
                var dd = Request["ajaxdata"];
                var models = new JavaScriptSerializer().Deserialize<PalBindList>(dd);
                if (models != null)
                {
                    models.DepartGuid = this.LoginDepartNum;
                    PageInfo pageInfo = new PageInfo() { PageIndex = models.pageIndex, PageSize = models.pageSize };
 
                    DALPalletBind provider = new DALPalletBind();
                    List<PalBind> entity = provider.GetList(models, ref pageInfo).ToList();
 
                    string json = JsonHelper.IListToJson<PalBind>(entity, "List");
                    string pjson = ConvertJson.Serializer(pageInfo);
 
                    ReturnJson.AddProperty("Result", new JsonObject(json));
                    ReturnJson.AddProperty("PageInfo", new JsonObject(pjson));
                    ReturnJson.AddProperty("Code", 1);
                    ReturnJson.AddProperty("Message", "响应成功");
 
                    return Content(this.ReturnJson.ToString());
                }
 
                return Content(null);
            }
            catch (Exception ex)
            {
                WriteFileLog(ex.Message.ToString(), System.Reflection.MethodBase.GetCurrentMethod());
                return Content(null);
            }
        }
 
        public ActionResult Detail()
        {
            try
            {
                var dd = Request["ajaxdata"];
                var models = new JavaScriptSerializer().Deserialize<PalBind>(dd);
                if (models == null)
                {
                    return Content(null);
                }
 
                models.CreatUser = this.LoginUserCode;
                models.DepartGuid = this.LoginDepartNum;
 
                if (string.IsNullOrEmpty(models.Palno))//新增
                {
                    if (Session["TEMPDATA_CACHE_PALLETBIND"] == null)
                    {
                        Session["TEMPDATA_CACHE_PALLETBIND"] = new List<PalBind>();
                    }
                    List<PalBind> list = Session["TEMPDATA_CACHE_PALLETBIND"] as List<PalBind>;
 
                    IDALPalletBind dalPb = new DALPalletBind();
                    if (dalPb.Add(models, list))
                    {
                        Session["TEMPDATA_CACHE_PALLETBIND"] = null;
                        ReturnJson.AddProperty("Code", 1);
                        ReturnJson.AddProperty("Message", "托盘物料绑定成功");
                    }
                    else
                    {
                        ReturnJson.AddProperty("Code", 1);
                        ReturnJson.AddProperty("Message", "托盘物料绑定失败");
                    }
 
                    return Content(this.ReturnJson.ToString());
                }
                else
                {
                    //查看、 编辑,返回组盘明细
                    Session["TEMPDATA_CACHE_PalletBind"] = null;
 
                    IDALPalletBind pb = new DALPalletBind();
                    IList<PalBind> lst = new List<PalBind>();
                    pb.GetPalletBind(models, ref lst);
                    Session["TEMPDATA_CACHE_PalletBind"] = lst;
 
                    string json = JsonHelper.IListToJson<PalBind>(lst, "List");
                    ReturnJson.AddProperty("Result", new JsonObject(json));
                    ReturnJson.AddProperty("Code", 1);
                    ReturnJson.AddProperty("Message", "OK");
 
                    return Content(this.ReturnJson.ToString());
                }
            }
            catch (Exception ex)
            {
                WriteFileLog(ex.Message.ToString(), System.Reflection.MethodBase.GetCurrentMethod());
                return Content(null);
            }
        }
 
        public ActionResult GetInNoDetail()
        {
            try
            {
                var dd = Request["ajaxdata"];
                var models = new JavaScriptSerializer().Deserialize<PalBind>(dd);
                if (models.MatNo != null)
                {
                    List<PalBind> list = Session["TEMPDATA_CACHE_PALLETBIND"] as List<PalBind>;
                    models.DepartGuid = this.LoginDepartNum;
                    DALPalletBind dpl = new DALPalletBind();
                    PalBind lst = dpl.GetInNoDetail(models, list);
                    string json = ConvertJson.Serializer(lst);
 
                    if (lst.OrdNo == null)
                    {
                        ReturnJson.AddProperty("Code", -1);
                        ReturnJson.AddProperty("Message", "未找到与该物料匹配的入库单");
                    }
                    else
                    {
                        ReturnJson.AddProperty("Code", 1);
                        ReturnJson.AddProperty("Result", new JsonObject(json));
                        ReturnJson.AddProperty("Message", "该物料存在,可进行绑定操作");
                    }
 
                    return Content(this.ReturnJson.ToString());
                }
                return Content(null);
            }
            catch (Exception ex)
            {
                WriteFileLog(ex.Message.ToString(), System.Reflection.MethodBase.GetCurrentMethod());
                return Content(null);
            }
        }
 
        public ActionResult GetAddreList()
        {
            try
            {
                var dd = Request["ajaxdata"];
                var modelItems = new JavaScriptSerializer().Deserialize<QueryDLocation>(dd);
                if (modelItems != null)
                {
                    // 实例化分页信息
                    PageInfo pageInfo = new PageInfo()
                    {
                        PageIndex = modelItems.PageIndex,
                        PageSize = modelItems.PageSize
                    };
 
                    // 数据库交互,获取库区集合and分页信息。
                    DALDepotsLocation provider = new DALDepotsLocation();
                    List<DepotsLocation> entity = provider.GetDepotsLocationItems(modelItems, ref pageInfo).ToList();
 
                    // Data =》json
                    string json = JsonHelper.IListToJson<DepotsLocation>(entity, "List");
                    string pjson = ConvertJson.Serializer(pageInfo);
 
                    // controller => view
                    ReturnJson.AddProperty("Result", new JsonObject(json));
                    ReturnJson.AddProperty("PageInfo", new JsonObject(pjson));
                    ReturnJson.AddProperty("Code", 1);
                    ReturnJson.AddProperty("Message", "加载库位集合成功!");
 
                    return Content(this.ReturnJson.ToString());
                }
 
                return Content(null);
            }
            catch (Exception ex)
            {
                WriteFileLog(ex.Message.ToString(), System.Reflection.MethodBase.GetCurrentMethod());
                return Content(null);
            }
        }
 
        // liudl 注释 逻辑推断没必要验证
        public ActionResult GetErpin()
        {
            try
            {
                var dd = Request["ajaxdata"];
                var models = new JavaScriptSerializer().Deserialize<PalBind>(dd);
 
                if (models != null)
                {
                    IDALPalletBind idpl = new DALPalletBind();
                    IList<PalBind> lst = new List<PalBind>();
                    bool r = idpl.GetErpinByMatNo(models, ref lst);
                    int erpinCount = lst.Count;
                    List<PalBind> list = Session["TEMPDATA_CACHE_PALLETBIND"] as List<PalBind>;
                    if (erpinCount == 0)
                    {
                        List<PalBind> lt = new List<PalBind>();
                        string json = JsonHelper.IListToJson<PalBind>(lt, "List");
                        ReturnJson.AddProperty("Result", new JsonObject(json));
                        ReturnJson.AddProperty("Code", -1);
                        ReturnJson.AddProperty("Message", "未找到与该物料匹配的入库单");
 
                        return Content(this.ReturnJson.ToString());
                    }
                    else
                    {
                        ReturnJson.AddProperty("Code", 1);
                        ReturnJson.AddProperty("Message", "该物料存在,可进行绑定操作");
 
                        return Content(this.ReturnJson.ToString());
                    }
                }
                return Content(null);
            }
            catch (Exception ex)
            {
                WriteFileLog(ex.Message.ToString(), System.Reflection.MethodBase.GetCurrentMethod());
                return Content(null);
            }
        }
 
        // 未完成
        public ActionResult AddBinding()
        {
            try
            {
                var dd = Request["ajaxdata"];
                var models = new JavaScriptSerializer().Deserialize<PalBind>(dd);
 
                if ((models.OrdNo != null) && (models.MatNo != null))
                {
 
                    List<PalBind> list = Session["TEMPDATA_CACHE_PALLETBIND"] as List<PalBind>;
 
                    DALPalletBind pb = new DALPalletBind();
                    ErpInDetail eid = new ErpInDetail();
                    pb.GetOrderMatByMatNoAndOrd(models.OrdNo, models.MatNo, ref eid);
 
                    //models.LingNo = eid.LingNo;
                    //models.PageNo = eid.PageNo;
                    //models.TuNo = eid.TuNo;
                    models.MatName = eid.MatName;
                    // models.PackFormat = eid.PackFormat;
 
 
                    // liudl Edit 修改新增共用数量验证
                    int ordCount = 0, bindCount = 0, remainCount = 0;
                    pb.GetRemainBindCount(models.OrdNo, models.MatGuid, ref ordCount, ref bindCount, ref remainCount, models.Palno);
                    remainCount -= int.Parse(models.MatCount);//把当前要修改的数量减掉
                    if (remainCount < 0)
                    {
                        list = new List<PalBind>();
                        Session["TEMPDATA_CACHE_PALLETBIND"] = list;
                        string json2 = JsonHelper.IListToJson<PalBind>(list, "List");
                        ReturnJson.AddProperty("Result", new JsonObject(json2));
                        ReturnJson.AddProperty("Code", -1);
                        ReturnJson.AddProperty("Message", "绑定失败, 该物料绑定总数量超过入库单物料数量");
                        ReturnJson.AddProperty("SubCode", 0);
                        ReturnJson.AddProperty("SubMessage", "");
                        return Content(this.ReturnJson.ToString());
                    }
 
 
                    if (!list.IsEmpty() && list.Count > 0)
                    {
                        //修改绑定  物料编码and单据号相同时才可更新
                        bool firstAdd = true;
                        for (int i = 0; i < list.Count; i++)
                        {
                            if (list[i].MatNo == models.MatNo && list[i].OrdNo == models.OrdNo)
                            {
                                firstAdd = false;
                                list[i].MatCount = models.MatCount;
                                list[i].Palno = models.Palno;
                                list[i].LocationCode = models.LocationCode;
                                list[i].LingNo = models.LingNo;
                                list[i].Demo = models.Demo;
                            }
                        }
                        if (firstAdd)
                        {
                            list.Add(models);
                        }
 
                        Session["TEMPDATA_CACHE_PALLETBIND"] = list;
                        string json1 = JsonHelper.IListToJson<PalBind>(list, "List");
                        ReturnJson.AddProperty("Result", new JsonObject(json1));
                        ReturnJson.AddProperty("Code", 1);
                        ReturnJson.AddProperty("Message", "响应成功");
                    }
                    else
                    {
                        //添加绑定
                        list = new List<PalBind>();
                        list.Add(models);
                        Session["TEMPDATA_CACHE_PALLETBIND"] = list;
                        string json = JsonHelper.IListToJson<PalBind>(list, "List");
                        ReturnJson.AddProperty("Result", new JsonObject(json));
                        ReturnJson.AddProperty("Code", 1);
                        ReturnJson.AddProperty("Message", "响应成功");
                        ReturnJson.AddProperty("SubCode", 0);
                        ReturnJson.AddProperty("SubMessage", "");
                    }
 
                    return Content(this.ReturnJson.ToString());
                }
                return Content(null);
            }
            catch (Exception ex)
            {
                WriteFileLog(ex.Message.ToString(), System.Reflection.MethodBase.GetCurrentMethod());
                return Content(null);
            }
        }
 
        public ActionResult Add()
        {
            try
            {
                // 判断是否存在组盘信息
                if (Session["TEMPDATA_CACHE_PALLETBIND"] == null)
                {
                    ReturnJson.AddProperty("Code", -1);
                    ReturnJson.AddProperty("Message", "请添加绑定信息!");
                    return Content(this.ReturnJson.ToString());
                }
                string LocationCode = "";
                string ajaxdata = Request["ajaxdata"];
                var models = new JavaScriptSerializer().Deserialize<PalBind>(ajaxdata);
                if (models != null)
                {
                    LocationCode = models.LocationCode;
                }
                List<PalBind> list = Session["TEMPDATA_CACHE_PALLETBIND"] as List<PalBind>;
 
                foreach (var item in list)
                {
                    //if (string.IsNullOrWhiteSpace(item.LocationCode)
                    //    && !string.IsNullOrWhiteSpace(LocationCode))
                    //{
                        item.LocationCode = LocationCode;
                    //}
                }
 
                DALPalletBind pb = new DALPalletBind();
                string strMessage = pb.SetPalBinds(this.LoginUserCode, this.LoginDepartNum, list);
                if (strMessage.Length > 0)
                {
                    ReturnJson.AddProperty("Code", -1);
                    ReturnJson.AddProperty("Message", strMessage);
 
                }
                else
                {
                    ReturnJson.AddProperty("Code", 1);
                    ReturnJson.AddProperty("Message", "保存成功");
                }
 
                return Content(this.ReturnJson.ToString());
            }
            catch (Exception ex)
            {
                WriteFileLog(ex.Message.ToString(), System.Reflection.MethodBase.GetCurrentMethod());
                return Content(null);
            }
        }
 
        public ActionResult Del()
        {
            try
            {
                string OrdNo = Request["OrdNo"];
                string Palno = Request["Palno"];
                string LocationCode = Request["LocationCode"];
                if (!string.IsNullOrEmpty(Palno) && !string.IsNullOrEmpty(OrdNo))
                {
                    IDALPalletBind dalPB = new DALPalletBind();
                    string strMessage = dalPB.DelPalBind(this.LoginUserCode, Palno, OrdNo,LocationCode);
 
                    if (strMessage.Length > 0)
                    {
                        ReturnJson.AddProperty("Code", -1);
                        ReturnJson.AddProperty("Message", strMessage);
                    }
                    else
                    {
                        ReturnJson.AddProperty("Code", 1);
                        ReturnJson.AddProperty("Message", "删除组盘成功");
                    }
 
                    return Content(this.ReturnJson.ToString());
                }
 
                return Content(null);
            }
            catch (Exception ex)
            {
                WriteFileLog(ex.Message.ToString(), System.Reflection.MethodBase.GetCurrentMethod());
                return Content(null);
            }
        }
 
        public ActionResult DelBinding()
        {
            try
            {
                var dd = Request["ajaxdata"];
                var models = new JavaScriptSerializer().Deserialize<PalBind>(dd);
                if (models != null)
                {
                    List<PalBind> list = Session["TEMPDATA_CACHE_PALLETBIND"] as List<PalBind>;
 
                    if (!list.IsEmpty())
                    {
                        for (int i = 0; i < list.Count; i++)
                        {
                            if (list[i].MatNo == models.MatNo && list[i].OrdNo == models.OrdNo)
                            {
                                if (list[i].Guid != null)
                                {
                                    // 删除数据库信息
                                    IDALPalletBind dalPB = new DALPalletBind();
                                    dalPB.DelPalBindDetail(this.LoginUserCode, list[i].Guid, list[i].OrdNo);
                                }
 
                                list.Remove(list[i]);
                                i--;
                            }
                        }
                        Session["TEMPDATA_CACHE_PALLETBIND"] = list;
                        string json = JsonHelper.IListToJson<PalBind>(list, "List");
                        ReturnJson.AddProperty("Result", new JsonObject(json));
                        ReturnJson.AddProperty("Code", 1);
                        ReturnJson.AddProperty("Message", "响应成功");
 
                    }
                    else
                    {
                        Session["TEMPDATA_CACHE_PALLETBIND"] = list;
                        string json = JsonHelper.IListToJson<PalBind>(list, "List");
                        ReturnJson.AddProperty("Result", new JsonObject(json));
                        ReturnJson.AddProperty("Code", -1);
                        ReturnJson.AddProperty("Message", "响应失败,列表为空");
                    }
 
                    return Content(this.ReturnJson.ToString());
                }
                return Content(null);
            }
            catch (Exception ex)
            {
                WriteFileLog(ex.Message.ToString(), System.Reflection.MethodBase.GetCurrentMethod());
                return Content(null);
            }
        }
 
        [LoginFilter]
        public ActionResult Init()
        {
            Session["TEMPDATA_CACHE_PALLETBIND"] = null;
            List<PalletBind> list = new List<PalletBind>();
            string json = JsonHelper.IListToJson<PalletBind>(list, "List");
            ReturnJson.AddProperty("Result", new JsonObject(json));
            ReturnJson.AddProperty("Code", 1);
            ReturnJson.AddProperty("Message", "响应成功");
            ReturnJson.AddProperty("SubCode", 0);
            ReturnJson.AddProperty("SubMessage", "");
            return Content(this.ReturnJson.ToString());
        }
 
 
 
 
 
 
 
 
 
 
        [LoginFilter]
        public ActionResult AddOneMat()
        {
            var dd = Request["ajaxdata"];
 
            var models = new JavaScriptSerializer().Deserialize<PalletBind>(dd);
 
            if (/*(models.OrdNo != null) &&*/ (models.MatNo != null))
            {
                List<PalletBind> list = Session["TEMPDATA_CACHE_PALLETBIND"] as List<PalletBind>;
                DALPalletBind pb = new DALPalletBind();
                ErpInDetail eid = new ErpInDetail();
                pb.GetOrderMatByMatNoAndOrd(models.OrdNo, models.MatNo, ref eid);
                models.MatName = eid.MatName;
                models.PageNo = eid.PageNo;
                models.TuNo = eid.TuNo;
                models.MatCount = eid.CurQuant;
                models.OrdNo = eid.OrdNo;
                if (!list.IsEmpty())
                {
                    //修改绑定
                    bool firstAdd = true;
                    for (int i = 0; i < list.Count; i++)
                    {
                        if (list[i].MatNo == models.MatNo)
                        {
                            int ordCount = 0, bindCount = 0, remainCount = 0;
                            pb.GetRemainBindCount(models.OrdNo, models.MatNo, ref ordCount, ref bindCount, ref remainCount, models.PalletNo);
                            //判断当前绑定数量是否大于待绑定数量
                            remainCount -= 1;
                            if ((remainCount < 0) || (int.Parse(list[i].MatCount) > remainCount))
                            {
                                Session["TEMPDATA_CACHE_PALLETBIND"] = list;
                                string json = JsonHelper.IListToJson<PalletBind>(list, "List");
                                ReturnJson.AddProperty("Result", new JsonObject(json));
                                ReturnJson.AddProperty("Code", -1);
                                ReturnJson.AddProperty("Message", "物料绑定数量已经达到入库单数量");
                                ReturnJson.AddProperty("SubCode", 0);
                                ReturnJson.AddProperty("SubMessage", "");
                                return Content(this.ReturnJson.ToString());
                            }
 
                            firstAdd = false;
                            list[i].MatCount = (int.Parse(list[i].MatCount) + 1).ToString();
                        }
                    }
                    if (firstAdd)
                    {
                        models.MatCount = "1";
                        list.Add(models);
                    }
 
                    Session["TEMPDATA_CACHE_PALLETBIND"] = list;
                    string json1 = JsonHelper.IListToJson<PalletBind>(list, "List");
                    ReturnJson.AddProperty("Result", new JsonObject(json1));
                    ReturnJson.AddProperty("Code", 1);
                    ReturnJson.AddProperty("Message", "响应成功");
                    ReturnJson.AddProperty("SubCode", 0);
                    ReturnJson.AddProperty("SubMessage", "");
 
                }
                else
                {
                    models.MatCount = "1";
                    list = new List<PalletBind>();
                    int ordCount = 0, bindCount = 0, remainCount = 0;
                    pb.GetRemainBindCount(models.OrdNo, models.MatNo, ref ordCount, ref bindCount, ref remainCount, models.PalletNo);
                    remainCount -= 1;//把当前要修改的数量减掉
                    if (remainCount < 0)
                    {
                        Session["TEMPDATA_CACHE_PALLETBIND"] = list;
                        string json2 = JsonHelper.IListToJson<PalletBind>(list, "List");
                        ReturnJson.AddProperty("Result", new JsonObject(json2));
                        ReturnJson.AddProperty("Code", -1);
                        ReturnJson.AddProperty("Message", "物料绑定数量已经达到入库单数量");
                        ReturnJson.AddProperty("SubCode", 0);
                        ReturnJson.AddProperty("SubMessage", "");
                        return Content(this.ReturnJson.ToString());
                    }
                    //添加绑定
                    list = new List<PalletBind>();
                    list.Add(models);
                    Session["TEMPDATA_CACHE_PALLETBIND"] = list;
                    string json = JsonHelper.IListToJson<PalletBind>(list, "List");
                    ReturnJson.AddProperty("Result", new JsonObject(json));
                    ReturnJson.AddProperty("Code", 1);
                    ReturnJson.AddProperty("Message", "响应成功");
                    ReturnJson.AddProperty("SubCode", 0);
                    ReturnJson.AddProperty("SubMessage", "");
                }
 
                return Content(this.ReturnJson.ToString());
            }
            return Content(null);
        }
 
        public ActionResult CheckPalletNo()
        {
            ViewBag.LingNo = "";
            var dd = Request["ajaxdata"];
 
            var models = new JavaScriptSerializer().Deserialize<PalletBind>(dd);
 
            if (models != null)
            {
                IDALPalletBind idpl = new DALPalletBind();
                IList<PalletBind> lst = new List<PalletBind>();
                bool r = idpl.IsPalletUsing(models.PalletNo);
                if (r)
                {
                    ReturnJson.AddProperty("Code", -1);
                    ReturnJson.AddProperty("Message", "托盘码重复");
                    ReturnJson.AddProperty("SubCode", 0);
                    ReturnJson.AddProperty("SubMessage", "");
 
                    return Content(this.ReturnJson.ToString());
                }
                else
                {
                    ReturnJson.AddProperty("Code", 1);
                    ReturnJson.AddProperty("Message", "托盘码可用");
                    ReturnJson.AddProperty("SubCode", 0);
                    ReturnJson.AddProperty("SubMessage", "");
 
                    return Content(this.ReturnJson.ToString());
                }
            }
            return Content(null);
        }
 
        public ActionResult ErpIn()
        {
            var dd = Request["ajaxdata"];
            var models = new JavaScriptSerializer().Deserialize<Order>(dd);
 
            DAL_Pub pub = new DAL_Pub();
            models.CreateUser = this.LoginUserCode;
            models.CMDStatu = 0;
            models.CMDType = "in";
            pub.GetEmptyPos(ref models.OldAddre, 0);
            models.IsDel = 0;
 
            int ret = -1;
            ret = pub.GenPalletInOrder(models);
            if (ret == 0)
            {
                //IDALPalletBind pb = new DALPalletBind();
                //bool br = pb.UpdateAfterPalletIn(models.Palno, "2");
                //if(!br)
                //    br = pb.UpdateAfterPalletIn(models.Palno, "2");
                ReturnJson.AddProperty("Code", 1);
                ReturnJson.AddProperty("Message", "入库指令发送成功");
            }
            else
            {
                ReturnJson.AddProperty("Code", 1);
                ReturnJson.AddProperty("Message", "入库指令发送失败");
            }
 
            return Content(this.ReturnJson.ToString());
        }
 
        public ActionResult ErpClose()
        {
            var dd = Request["ajaxdata"];
            var models = new JavaScriptSerializer().Deserialize<PalletBind>(dd);
            var PalletNo = models.PalletNo;
            var LingNo = models.LingNo;
            var OrdNo = models.OrdNo;
            if (string.IsNullOrEmpty(PalletNo))//新增
            {
                if (models != null)
                {
                    List<PalletBind> list = Session["TEMPDATA_CACHE_PALLETBIND"] as List<PalletBind>;
 
                    IDALPalletBind dalPb = new DALPalletBind();
                    models.CreateUser = this.LoginUserCode;
 
                    bool value = false;
                    //if (editPallet == null)//
                    //{
                    //value = dalPb.Add(models, list);
                    //if (value)
                    //{
                    //    Session["TEMPDATA_CACHE_PALLETBIND"] = null;
                    //    ReturnJson.AddProperty("Code", 1);
                    //    ReturnJson.AddProperty("Message", "托盘物料绑定成功");
                    //}
                    //else
                    //{
                    //    ReturnJson.AddProperty("Code", 1);
                    //    ReturnJson.AddProperty("Message", "托盘物料绑定失败");
                    //}
 
                    ReturnJson.AddProperty("SubCode", 0);
                    ReturnJson.AddProperty("SubMessage", "");
                    //}
                    //else
                    //{
                    //    value = dalPb.Update(models,list);
                    //    if (value)
                    //    {
                    //        Session["TEMPDATA_CACHE_PALLETBIND"] = null;
                    //        ReturnJson.AddProperty("Code", 1);
                    //        ReturnJson.AddProperty("Message", "托盘物料绑定成功");
                    //    }
                    //    else
                    //    {
                    //        ReturnJson.AddProperty("Code", -1);
                    //        ReturnJson.AddProperty("Message", "托盘物料绑定失败");
                    //    }
                    //    ReturnJson.AddProperty("SubCode", 0);
                    //    ReturnJson.AddProperty("SubMessage", "");
                    //}
 
                    return Content(this.ReturnJson.ToString());
                }
 
            }
            else
            {
                //编辑,返回组盘明细
                Session["TEMPDATA_CACHE_PalletBind"] = null;
 
                IDALPalletBind pb = new DALPalletBind();
                IList<PalletBind> lst = new List<PalletBind>();
                pb.GetPalletBind(PalletNo, ref lst);
                Session["TEMPDATA_CACHE_PalletBind"] = lst;
                string json = JsonHelper.IListToJson<PalletBind>(lst, "List");
                ReturnJson.AddProperty("Result", new JsonObject(json));
                ReturnJson.AddProperty("Code", 1);
                ReturnJson.AddProperty("Message", "OK");
                ReturnJson.AddProperty("SubCode", 0);
                ReturnJson.AddProperty("SubMessage", "");
                return Content(this.ReturnJson.ToString());
            }
            return Content(null); ;
        }
 
        public ActionResult CheckStatus()
        {
            var dd = Request["ajaxdata"];
 
            var models = new JavaScriptSerializer().Deserialize<PalletBind>(dd);
            if (!string.IsNullOrEmpty(models.PalletNo))
            {
                IDALPalletBind pb = new DALPalletBind();
                string status = "等待执行";
                bool r = pb.GetPalletBindStatus(models.PalletNo, status);
                //if (lst.Count > 0)
                //{
                if (r)
                {
                    ReturnJson.AddProperty("Code", 1);
                    ReturnJson.AddProperty("Message", "状态可编辑");
                    ReturnJson.AddProperty("SubCode", 0);
                    ReturnJson.AddProperty("SubMessage", "");
                    return Content(this.ReturnJson.ToString());
                }
                else
                {
                    ReturnJson.AddProperty("Code", -1);
                    ReturnJson.AddProperty("Message", "状态不可编辑");
                    ReturnJson.AddProperty("SubCode", 0);
                    ReturnJson.AddProperty("SubMessage", "");
                    return Content(this.ReturnJson.ToString());
                }
                //}
            }
 
            ReturnJson.AddProperty("Code", 1);
            ReturnJson.AddProperty("Message", "状态可编辑");
            ReturnJson.AddProperty("SubCode", 0);
            ReturnJson.AddProperty("SubMessage", "");
            return Content(this.ReturnJson.ToString());
        }
    }
}