schangxiang@126.com
2025-09-17 ff43ddf18764629ff875478e4e47a7281cbd230a
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
using iWareCC.Common.Helper;
using iWareCC.WCF;
using iWareCommon;
using iWareCommon.Utils;
using iWareModel.Entity.MES;
using iWareSql.DataAccess;
using iWareSql.MyDbContext;
using Newtonsoft.Json;
using System;
using System.Configuration;
using System.Drawing;
using System.Net;
using System.ServiceModel;
using System.Threading;
using System.Windows.Forms;
 
namespace iWareCC
{
    public partial class FormCC : Form
    {
        /// <summary>
        /// WCS的IP地址
        /// </summary> 
        public static string WcsIp = ConfigurationSettings.AppSettings["WcsApiHost"].Trim();
 
        public static string WcsSysUserName = "调度系统";
 
 
        /// <summary>
        /// 是否模拟PLC
        /// </summary>
        public static bool IsSimulationPLC = ConfigHelper.GetConfigBool("IsSimulationPLC");
 
        private string currentCheckModelText = "";
 
        const int cycleDelay_Device = 1000;//各个线程的延迟毫秒数
        const int cycleDelay_Task = 1000;
 
        Thread startModelTipsThread;//启动线程提示
        private bool isStartModelTipsThread = false;//是否启动了线程提示
        private Color default_btn_Start_Color = Color.FromArgb(0, 192, 0);//默认的开始模拟按钮颜色
        private Color ss_btn_Start_Color1 = Color.FromArgb(255, 255, 192);//开始模拟按钮后闪烁的颜色1
        private Color ss_btn_Start_Color2 = Color.FromArgb(192, 192, 255);//开始模拟按钮后闪烁的颜色1
 
 
        public FormCC()
        {
            InitializeComponent();
 
            //暂时注释
            //tp_Thread.Parent = null;//隐藏标签[线程控制] 
 
            CheckForIllegalCrossThreadCalls = false;
 
            //设置界面初始化的选项
            //暂时 默认就选中自动模式
            this.rBNormal.Checked = SystemValue.rBNormal_Checked = true;
            this.rbHand.Checked = SystemValue.rbHand_Checked = false;
            this.rBDebug.Checked = SystemValue.rBDebug_Checked = false;
 
 
 
            SetModelCheckBoxToSystemValue();
 
            startModelTipsThread = new Thread(ShowTipsWhenStartModel);
            startModelTipsThread.Start();
 
 
            var tskSetSrmLable = new Thread(SrmRead_Label);
            tskSetSrmLable.Start();
 
 
            #region 服务线程启动
 
 
 
            //处理 1、2巷道的任务下发
            new Thread(IssueTasHandler.Handler).Start();
 
 
            //平库WCS任务完成线程
            new Thread(TaskFinishHandler.Handler).Start();
 
 
 
            new Thread(DeleteData).Start();
 
            new Thread(PrintHandler.Handler).Start();
 
 
            new Thread(ReceivingPoOrderHandler.Handler).Start();
 
            #endregion
 
        }
        private void FormCC_Load(object sender, EventArgs e)
        {
 
 
 
 
            #region 对外发布WCF形式数据访问服务
            try
            {
                #region 对外发布WCF形式数据访问服务
                var lineServiceHost = new ServiceHost(typeof(CCWcfService));
                lineServiceHost.Open();
                lbl_WCFMsg.Text = "发布WCF成功," + lineServiceHost.BaseAddresses[0].AbsoluteUri;
                lbl_WCFMsg.ForeColor = Color.Green;
                #endregion
 
            }
            catch (Exception ex)
            {
                Log4NetHelper.WriteErrorLog(iWareCommon.Utils.LogType.CCWCFService, "发布WCF失败", ex);
                lbl_WCFMsg.Text = "发布WCF失败:" + ex.Message;
                lbl_WCFMsg.ForeColor = Color.Red;
            }
 
            #endregion
 
 
            this.lbl_IsSimulationPLC.Text = "是否模拟PLC:" + (IsSimulationPLC ? "是" : "否");
            if (IsSimulationPLC)
            {
                //暂时注释
                this.panel_Model.BackColor = Color.Tomato;
            }
            else
            {//正式模式 
 
            }
 
            this.lbl_IsSimulationPLC.BackColor = IsSimulationPLC ? Color.Red : Color.Green;
 
            //此处暂时快速启动 调试模式,用于开发用
            //btn_Start_Click(null, null);
        }
 
 
        #region 其他线程
 
        /// <summary>
        /// 设置1/2号堆垛机的前端显示
        /// </summary>
        private void SrmRead_Label()
        {
            while (true)
            {
                Thread.Sleep(1000);
                try
                {
 
                    var showNowTime = "(" + DateTimeHelper.ConvertToStringForOnlyShowTime(DateTime.Now) + ")";
 
                    this.tb_Alert_OutPlanTaskHandler.Text = showNowTime + SystemWarningMsg._lbl_Alert_OutPlanTaskHandler;
                    this.tb__Alert_OutPlanTaskHandler3.Text = showNowTime + SystemWarningMsg._lbl_Alert_OutPlanTaskHandler3;
 
                    this.lbl_Alert_SrmTaskFinish.Text = showNowTime + SystemWarningMsg._lbl_Alert_SrmTaskFinish;
                    this.lbl_Alert_PingKuTaskFinish.Text = showNowTime + SystemWarningMsg._lbl_Alert_PingKuTaskFinish;
 
                    this.lbl_Alert_库存邮箱预警线程.Text = showNowTime + SystemWarningMsg._lbl_Alert_StoreWaringMailHandler;
                    this.lbl_Alert_邮件发送处理线程.Text = showNowTime + SystemWarningMsg._lbl_Alert_PoDeliveryHandler;
                    this.lbl_Alert_InventorySnapshotHandler.Text = showNowTime + SystemWarningMsg._lbl_Alert_noti;
 
                    this.lbl_Alert_PrintHandler.Text = showNowTime + SystemWarningMsg.lbl_Alert_ReceivingPoOrderHandler;
 
                    this.lbl_Alert_InventorySnapshotHandler.Text = showNowTime + SystemWarningMsg._lbl_Alert_InventorySnapshotHandler;
                }
                catch (Exception ex)
                {
                    Log4NetHelper.WriteErrorLog(iWareCommon.Utils.LogType.SrmTheadService, "方法SrmRead_Label出现异常:" + ex.Message, ex);
                    continue;
                }
            }
        }
 
        #region 定时删除数据
 
        /// <summary>
        /// 定时删除数据
        /// </summary>
        public void DeleteData()
        {
            while (true)
            {
                try
                {
                    if (SystemValue.isAllowRuning_DeleteData && SystemValue.isStartedModel)
                    {
                        ClearDataHandler.Delete_wms_stock_snapshot(360);
                        ClearDataHandler.Delete_wms_stock_snapshot_details(360);
                        ClearDataHandler.Delete_wms_stock_snapshot_group(360);
                        ClearDataHandler.Delete_wms_stock_quan_zero(60);
                        ClearDataHandler.Delete_wms_stock_quan_out(60);
                        ClearDataHandler.Delete_HttpRequestRecord(14);
                        //ClearDataHandler.Delete_Task_Part(10);
                        //ClearDataHandler.Delete_Device_Warning(30);
                        //ClearDataHandler.Delete_HttpRequestRecord(14);
 
                        //ClearDataHandler.Delete_MES_BTJReceiveReq(30);
                        //ClearDataHandler.Delete_MES_OnLineReq(30);
 
                        LogTextHelper.BatchDeleteLog();
 
                        Thread.Sleep(8 * 60 * 60 * 1000);//每天8小时一次 
                    }
                    else
                    {
                        Thread.Sleep(6 * 1000);
                    }
                }
                catch (Exception ex)
                {
                    SystemWarningMsg._lbl_Alert_DeleteData = "出现异常:" + ex.Message;
                    Log4NetHelper.WriteErrorLog(iWareCommon.Utils.LogType.CCWCFService, "定时删除数据 出现异常", ex);
                }
                finally
                {
 
                }
            }
        }
 
        #endregion
 
        #endregion
 
        private void rBNormal_CheckedChanged(object sender, EventArgs e)
        {
            SetModelCheckBoxToSystemValue();
        }
 
        private void rBDebug_CheckedChanged(object sender, EventArgs e)
        {
            SetModelCheckBoxToSystemValue();
        }
 
 
        /// <summary>
        /// 根据选择的模式配置不同的值
        /// </summary>
        private void SetModelCheckBoxToSystemValue()
        {
            SystemValue.rBNormal_Checked = this.rBNormal.Checked ? true : false;
            SystemValue.rbHand_Checked = this.rbHand.Checked ? true : false;
            SystemValue.rBDebug_Checked = this.rBDebug.Checked ? true : false;
 
 
 
            var title = "当前模式: ";
            if (SystemValue.rBNormal_Checked)
            {//选中了 自动模式
                currentCheckModelText = "自动模式";
                this.lbl_ModelText.Text = title + currentCheckModelText;
                this.gBoxThread.Enabled = false;
                SetAllCheckBoxChecked(true);
            }
            else if (SystemValue.rbHand_Checked)
            {
                currentCheckModelText = "手动模式";
                this.lbl_ModelText.Text = title + currentCheckModelText;
                this.gBoxThread.Enabled = false;
                SetAllCheckBoxChecked(false);
 
            }
            else if (SystemValue.rBDebug_Checked)
            {
                currentCheckModelText = "调试模式";
                this.lbl_ModelText.Text = title + currentCheckModelText;
                SetAllCheckBoxChecked(false);
                this.gBoxThread.Enabled = true;
 
            }
            else if (SystemValue.rBOnlyIn_Checked)
            {
                currentCheckModelText = "入库模式";
                this.lbl_ModelText.Text = title + currentCheckModelText;
                SetAllCheckBoxChecked(true);
 
 
                this.gBoxThread.Enabled = true;
            }
            else
            {
                currentCheckModelText = "无效模式";
            }
        }
 
        /// <summary>
        /// 遍历所有的Checkbox,并配置是否被选中
        /// </summary>
        /// <param name="enabled"></param>
        private void SetAllCheckBoxChecked(bool _checked)
        {
            var contorls = this.groupBox1.Controls;
            foreach (var control in contorls)
            {
                if (control is CheckBox)
                {
                    CheckBox c = (CheckBox)control;
                    c.Checked = _checked;
                }
            }
        }
 
 
        /// <summary>
        /// 通用的checkbox改变事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CommonCheckedChanged(object sender, EventArgs e)
        {
 
 
            DoCommonCheckedChanged(ref SystemValue.isAllowRuning_OutTaskIssueTaskHandler, ck_OutPlanTaskHandler);
            DoCommonCheckedChanged(ref SystemValue.isAllowRuning_OutTaskIssueTaskHandler3, ck_OutPlanTaskHandler3);
 
 
 
            DoCommonCheckedChanged(ref SystemValue.isAllowRuning_DeleteData, ckDeleteData);
 
 
 
            DoCommonCheckedChanged(ref SystemValue.isAllowRuning_SrmTaskFinish, ckSrmTaskFinish);
 
            DoCommonCheckedChanged(ref SystemValue.isAllowRuning_PingKuTaskFinish, ckPingKuTaskFinish);
            DoCommonCheckedChanged(ref SystemValue.isAllowRuning_PrintHandler, ck_PrintHandler);
            DoCommonCheckedChanged(ref SystemValue.isAllowRuning_PoDeliveryHandler, ck_PoDeliveryHandler);
            DoCommonCheckedChanged(ref SystemValue.isAllowRuning_ReceivingPoOrderHandler, ck_ReceivingPoOrderHandler);
 
            DoCommonCheckedChanged(ref SystemValue.isAllowRuning_InventorySnapshotHandler, ck_InventorySnapshotHandler);
            DoCommonCheckedChanged(ref SystemValue.isAllowRuning_StoreWaringMailHandler, ck_库存邮箱预警线程);
            DoCommonCheckedChanged(ref SystemValue.isAllowRuning_PoDeliveryHandler, ck_邮件发送处理线程);
 
        }
 
        private void DoCommonCheckedChanged(ref bool isAllowValue, CheckBox cb)
        {
            isAllowValue = cb.Checked ? true : false;
        }
 
        private void FormCC_SizeChanged(object sender, EventArgs e)
        {
 
        }
 
        /// <summary>
        /// 停止
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_End_Click(object sender, EventArgs e)
        {
            //首先确认下,是不是选择的是 自动模式或者是 提前配板模式
            //注意:这里增加模式时,要处理的 !!!!
            if (!(SystemValue.rBNormal_Checked
                 || SystemValue.rbHand_Checked
                 || SystemValue.rBDebug_Checked
                 || SystemValue.rBOnlyIn_Checked
                ))
            {
                WZ.Useful.Commons.MessageUtil.ShowError("当前没有选择模式,停止动作无效!");
                return;
            }
            if (isStartModelTipsThread == false)
            {
                WZ.Useful.Commons.MessageUtil.ShowError("当前没有模式在运行,停止动作无效!");
                return;
            }
 
            MessageBoxButtons messButton = MessageBoxButtons.OKCancel;
            DialogResult dr = MessageBox.Show("确定要停止【" + currentCheckModelText + "】模式吗?", "停止模式", messButton);
            if (dr == DialogResult.OK)//如果点击“确定”按钮
            {
                var doResult = CommonStopService();
                if (!doResult)
                {
                    return;
                }
 
 
                this.btn_Start.Text = "启动模式";
                this.btn_Start.Enabled = true;
                SystemValue.isStartedModel = false;
 
                //启用选择模式的checkbox
                SetEnableForModelRadioButton(true);
                //this.rBNormal.Enabled = true;
                //this.rBClose.Enabled = true;
                //this.rBDebug.Enabled = true;
                //this.rBPrepare.Enabled = true;
                //this.rBPersonRaw.Enabled = true;
                //this.rBInOutStore.Enabled = true;
                //this.rBCancelBatchBackToStore.Enabled = true;
 
                //不需要重新关闭checkbox
                //SetAllCheckBoxChecked(false);
 
                isStartModelTipsThread = false;
                this.btn_Start.BackColor = default_btn_Start_Color;//还原颜色
            }
            else//如果点击“取消”按钮
            {
 
            }
        }
 
        /// <summary>
        /// 控制模式中的RadioButton禁启用
        /// </summary>
        /// <param name="enabled"></param>
        private void SetEnableForModelRadioButton(bool enabled)
        {
            var ctls = this.panel_Model.Controls;
            foreach (var item in ctls)
            {
                if (item is RadioButton)
                {
                    RadioButton rb = (RadioButton)item;
                    rb.Enabled = enabled;
                }
            }
        }
 
        /// <summary>
        /// 启动
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_Start_Click(object sender, EventArgs e)
        {
            //首先确认下,是不是选择的是 自动模式或者是 提前配板模式
            if (!(SystemValue.rBNormal_Checked
                || SystemValue.rbHand_Checked
                || SystemValue.rBDebug_Checked
                || SystemValue.rBOnlyIn_Checked
                ))
            {
                WZ.Useful.Commons.MessageUtil.ShowError("请选择其中一个模式!");
                return;
            }
 
            MessageBoxButtons messButton = MessageBoxButtons.OKCancel;
            DialogResult dr = MessageBox.Show("确定要启动【" + currentCheckModelText + "】模式吗?", "启动模式", messButton);
            if (dr == DialogResult.OK)//如果点击“确定”按钮
            {
                using (MyDbContext edm = new MyDbContext())
                {
                    var ccSystem = BasicDataSetHandler.GetCCSystem(edm);
                    if (ccSystem == null)
                    {
                        WZ.Useful.Commons.MessageUtil.ShowError("请联系管理员维护系统调度相关的数据!");
                        return;
                    };
                    //判断是否是自己开启的软件
                    if (!string.IsNullOrEmpty(ccSystem.Machine) && ccSystem.Machine != Dns.GetHostName())
                    {//默认的空值
                        WZ.Useful.Commons.MessageUtil.ShowError(string.Format("调度系统已经在其他地方启动模式,机器名:{0},启动时间:{1}!"
                            , ccSystem.Machine, DateTimeHelper.ConvertToString(ccSystem.OnLineTime)));
                        return;
                    }
 
                    ccSystem.BasicDataValue = SystemValue.SystemStartGuid = Guid.NewGuid().ToString();
                    ccSystem.OnLineTime = DateTime.Now;
                    ccSystem.Machine = Dns.GetHostName();
 
                    int i = edm.SaveChanges();
                    if (i <= 0)
                    {
                        WZ.Useful.Commons.MessageUtil.ShowError("保存系统调度相关的数据失败!");
                        return;
                    }
                    //*/
                }
 
                this.btn_Start.Text = "【" + currentCheckModelText + "】模式运行中...";
                this.btn_Start.Enabled = false;
                this.btn_End.Enabled = true;
                SystemValue.isStartedModel = true;
 
                //禁用选择模式的checkbox
                SetEnableForModelRadioButton(false);
                //this.rBNormal.Enabled = false;
                //this.rBClose.Enabled = false;
                //this.rBDebug.Enabled = false;
                //this.rBPersonRaw.Enabled = false;
                //this.rBPrepare.Enabled = false;
                //this.rBInOutStore.Enabled = false;
 
 
                isStartModelTipsThread = true;
 
            }
            else//如果点击“取消”按钮
            {
 
            }
 
        }
 
        /// <summary>
        /// 公共停止服务的处理
        /// </summary>
        /// <returns></returns>
        private bool CommonStopService()
        {
            using (MyDbContext edm = new MyDbContext())
            {
                var ccSystem = BasicDataSetHandler.GetCCSystem(edm);
                if (ccSystem == null)
                {
                    WZ.Useful.Commons.MessageUtil.ShowError("请联系管理员维护系统调度相关的数据!");
                    return false;
                };
                //判断是否是自己开启的软件模式
                if (SystemValue.SystemStartGuid == ccSystem.BasicDataValue)
                {
                    ccSystem.BasicDataValue = "000000";//默认的空值
                    ccSystem.OnLineTime = null;
                    ccSystem.Machine = string.Empty;
                    ccSystem.LastMachine = Dns.GetHostName();
                    ccSystem.LastUnLineTime = DateTime.Now;
                    ccSystem.UpdateTime = DateTime.Now;
 
                    int i = edm.SaveChanges();
                    if (i <= 0)
                    {
                        WZ.Useful.Commons.MessageUtil.ShowError("保存系统调度相关的数据失败!");
                        return false;
                    }
                }
            }
            return true;
        }
 
        private void FormCC_FormClosing(object sender, FormClosingEventArgs e)
        {
            MessageBoxButtons messButton = MessageBoxButtons.OKCancel;
            DialogResult dr = MessageBox.Show("确定要退出吗?", "确认", messButton);
            if (dr == DialogResult.OK)//如果点击“确定”按钮
            {
                try
                {
                    var doResult = CommonStopService();
                    if (!doResult)
                    {
                        e.Cancel = true;
                        return;
                    }
                    e.Cancel = false;
                }
                catch (Exception ex)
                {
                    WZ.Useful.Commons.MessageUtil.ShowError("出现错误!" + ex.Message);
                    e.Cancel = true;
                }
            }
            else//如果点击“取消”按钮
            {
                e.Cancel = true;
            }
        }
        private void FormCC_FormClosed(object sender, FormClosedEventArgs e)
        {
            try
            {
                Dispose();
            }
            catch (Exception)
            {
            }
            Environment.Exit(0);
        }
 
 
        /// <summary>
        /// 模式启动后,按钮闪烁
        /// </summary>
        /// <param name="obj"></param>
        private void ShowTipsWhenStartModel(object obj)
        {
            while (true)
            {
                Thread.Sleep(1000);
                if (isStartModelTipsThread)
                {
                    try
                    {
                        this.btn_Start.BackColor = ss_btn_Start_Color2;
                        Thread.Sleep(1000);
                        this.btn_Start.BackColor = ss_btn_Start_Color1;
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                }
                else
                {
                    if (this.btn_Start.BackColor != default_btn_Start_Color)
                    {
                        this.btn_Start.BackColor = default_btn_Start_Color;//还原颜色
                    }
                }
            }
        }
 
        private void panel27_Paint(object sender, PaintEventArgs e)
        {
 
        }
 
        private void rBOnlyIn_CheckedChanged(object sender, EventArgs e)
        {
            SetModelCheckBoxToSystemValue();
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                CriterionContainerOutput outs = WMSRequestHelper.FindEmptyLocationForLane3(1, "SLTP-3", 0);
                MessageBox.Show("返回:" + JsonConvert.SerializeObject(outs));
            }
            catch (Exception ex)
            {
                MessageBox.Show("异常:" + ex.Message);
            }
        }
 
        /// <summary>
        /// 获取单个PO单
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            //      this.tb_Msg.Text = StringHelper.GetLog("PO收货单:" + poNummber + ",返回结果:" + JsonConvert.SerializeObject(purchaseOrderEntity) + ",错误消息:" + msg);
        }
 
        /// <summary>
        /// PO收货单并保存数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button3_Click(object sender, EventArgs e)
        {
            //var poNummber = this.tb_PoNumber.Text.Trim();
            //if (string.IsNullOrEmpty(poNummber))
            //{
            //    MessageBox.Show("请输入PO单号");
            //    return;
            //}
            //var msg = "";
            //iWareCC.WuhanMakinoSapWcfService.PurchaseOrderEntity purchaseOrderEntity = null;
            //try
            //{
            //    using (WuhanMakinoSapWcfService.SapWcfServiceClient sapWcfServiceClient = new WuhanMakinoSapWcfService.SapWcfServiceClient())
            //    {
            //        purchaseOrderEntity = sapWcfServiceClient.GetPurchaseOrder(poNummber, out msg);
            //    }
            //}
            //catch (Exception ex)
            //{
            //    msg = "异常:" + ex.Message;
            //}
 
 
            //this.tb_Msg.Text = StringHelper.GetLog("PO收货单:" + poNummber + ",返回结果:" + JsonConvert.SerializeObject(purchaseOrderEntity) + ",错误消息:" + msg);
 
            //if (purchaseOrderEntity != null)
            //{
            //    try
            //    {
            //        using (MyDbContext context = new MyDbContext())
            //        {
            //            var _list = new System.Collections.Generic.List<PurchaseOrderEntity>()
            //        {
            //            purchaseOrderEntity
            //        };
            //            Sap_PurchaseOrderTaskHandler.SavePurchaseOrder(context, _list);
            //        }
 
            //    }
            //    catch (Exception ex)
            //    {
            //        msg = "异常:" + ex.Message;
            //    }
            //}
            //this.tb_Msg.Text += StringHelper.GetLog("PO收货单:" + poNummber + ",错误消息:" + msg);
        }
 
        private void tabPage1_Click(object sender, EventArgs e)
        {
 
        }
 
        private void ck_ReceivingPoOrderHandler_CheckedChanged(object sender, EventArgs e)
        {
 
        }
 
        private void lbl_Alert_ReceivingPoOrderHandler_Click(object sender, EventArgs e)
        {
 
        }
 
        private void lbl_Alert_PrintHandler_Click(object sender, EventArgs e)
        {
 
        }
 
        private void lbl_Alert_PoDeliveryHandler_Click(object sender, EventArgs e)
        {
 
        }
 
        private void ck_PoDeliveryHandler_CheckedChanged(object sender, EventArgs e)
        {
 
        }
 
        private void groupBox1_Enter(object sender, EventArgs e)
        {
 
        }
 
 
        //private void button1_Click(object sender, EventArgs e)
        //{
        //    IDictionary<string, string> hs = new System.Collections.Generic.Dictionary<string, string>();
        //    hs.Add("1-1-4-18", "MYH03711");
        //    hs.Add("3-12-1-4", "MYST000273");
        //    hs.Add("1-11-4-11", "MYH02720");
        //    hs.Add("1-11-4-8", "MYS02366");
        //    hs.Add("1-11-4-12", "MYH02712");
        //    hs.Add("1-11-4-13", "MYH02722");
        //    hs.Add("1-11-4-17", "MYH03663");
        //    hs.Add("1-11-4-18", "MYH00297");
        //    hs.Add("1-12-1-11", "MYH00168");
        //    hs.Add("1-12-1-13", "MYH00163");
        //    hs.Add("1-12-4-1", "MYS03325");
        //    hs.Add("1-12-4-3", "MYS00196");
        //    hs.Add("1-12-1-14", "MYH02710");
        //    hs.Add("1-12-4-15", "MYH00892");
        //    hs.Add("1-12-4-16", "MYH00973");
        //    hs.Add("1-12-4-17", "MYH00490");
        //    hs.Add("1-12-4-18", "MYH00349");
        //    hs.Add("1-1-2-2", "MYS00698");
        //    hs.Add("1-1-1-3", "MYS04090");
        //    hs.Add("2-6-2-4", "MYS00822");
        //    hs.Add("1-1-1-4", "MYS00510");
        //    hs.Add("2-39-2-2", "MYS00829");
        //    hs.Add("1-1-1-6", "MYS00566");
        //    hs.Add("1-1-4-12", "MYH00246");
        //    hs.Add("1-10-1-13", "MYH01680");
        //    hs.Add("1-1-4-15", "MYH02675");
 
        //    try
        //    {
        //        using (MyDbContext context = new MyDbContext())
        //        {
 
        //            foreach (var item in hs)
        //            {
        //                var isEist = context.ware_location_vs_container.Where(x => x.WareLocationCode == item.Key && (x.IsDeleted == null || x.IsDeleted == false)).FirstOrDefault();
        //                if (isEist == null)
        //                {
        //                    ware_location_vs_container ware_Location_Vs_Container = new ware_location_vs_container()
        //                    {
        //                        Id = Yitter.IdGenerator.YitIdHelper.NextId(),
        //                        WareLocationCode = item.Key,
        //                        WareContainerCode = item.Value,
        //                        IsEmptyContainer = false,
        //                        CreatedTime = DateTime.Now,
        //                        IsDeleted = false,
        //                        Status = 0,
        //                        TenantId = 0,
        //                        CreatedUserId = 0,
        //                        CreatedUserName = "cc",
        //                        UpdatedUserId = 0
        //                    };
 
        //                    context.ware_location_vs_container.Add(ware_Location_Vs_Container);
        //                }
 
        //            }
 
        //            context.SaveChanges();
 
        //            MessageBox.Show("成功");
        //        }
        //    }
        //    catch (Exception ex)
        //    {
 
        //        MessageBox.Show("异常:" + ex.Message);
        //    }
 
        //}
    }
}