cnf
2025-09-01 8c7ac11905cc442d9cf8920de01dc5ef29179987
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
using Gs.DevApp.DevFrm.Rpt;
using Gs.DevApp.Entity;
using Gs.DevApp.ToolBox;
using Gs.DevApp.UserControl;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace Gs.DevApp.DevFrm
{
    public partial class Frm_ArrivalBarcode : DevExpress.XtraEditors.XtraForm
    {
        string _webServiceName = "VArrivalBarcodeManager/";
        List<FilterEntity> _filterList = new List<FilterEntity>();
        public Frm_ArrivalBarcode()
        {
            InitializeComponent();
            this.toolBarMenu1.btnLoadClick += ToolBarMenu1_btnLoadClick;
            this.toolBarMenu1.btnQueryClick += ToolBarMenu1_btnQueryClick;
            this.toolBarMenu1.getXmlConfig();
            Gs.DevApp.ToolBox.UtilityHelper.SetGridViewParameterMx(gvMx1);
            Gs.DevApp.ToolBox.UtilityHelper.SetGridViewParameterMx(gvMx2);
            Gs.DevApp.ToolBox.UtilityHelper.SetGridViewParameterMx(gvMx3);
            Gs.DevApp.ToolBox.UtilityHelper.SetGridViewParameterMx(gvMxL1);
            Gs.DevApp.ToolBox.UtilityHelper.SetGridViewParameterMx(gvMxL2);
            Gs.DevApp.ToolBox.UtilityHelper.SetGridViewParameterMx(gvMxL3);
            Gs.DevApp.ToolBox.UtilityHelper.SetGridViewParameter(gridView1, null, null, "", "", (value) =>
            {
                Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 0);
            }, tips, true, (strGuid) => {
                getModelList(strGuid);
            });
            Gs.DevApp.ToolBox.UtilityHelper.SetTabParameter(gridView1, xtraTabControl1, pageBar1, (value) =>
            {
               
                getModel(value);
           
 
            }, (value) =>
            {
                getPageList(this.pageBar1.CurrentPage);
            }, lbGuid);
            getPageList(1);
            pageBar1.PagerEvent += PageBar1_PagerEvent;
            //打印事件
            this.ucBtnPrint1.btnPrintClick += (s, e) =>
            {
                string rowGuid = lbMxGuid.Text.Trim();
                ucBtnPrint1.guidKey = rowGuid;
                if (!Gs.DevApp.ToolBox.UtilityHelper.IsNumeric3(txt_iCount_1.Text.Trim(), txt_yuliang_1.Text.Trim()))
                {
                    Gs.DevApp.ToolBox.MsgHelper.ShowError("请输入正确的条码数量!");
                    txt_iCount_1.Focus();
                    this.ucBtnPrint1.rptParameter = "return false";
                    return;
                }
                if (!Gs.DevApp.ToolBox.UtilityHelper.IsNumeric3(txt_psnQty_1.Text.Trim()))
                {
                    Gs.DevApp.ToolBox.MsgHelper.ShowError("请选择打印条码数量!");
                    txt_psnQty_1.Focus();
                    this.ucBtnPrint1.rptParameter = "return false";
                    return;
                }
                if (lbMxGuid.Text.Trim().Length < 10)
                {
                    Gs.DevApp.ToolBox.MsgHelper.ShowError("请选择打印的行!");
                    this.ucBtnPrint1.rptParameter = "return false";
                    return;
                }
                this.ucBtnPrint1.rptParameter = "rpt_Arrival{"
                       + lbMxGuid.Text.Trim()//关联主键
                       + "," + ""
                       + "," + Gs.DevApp.ToolBox.UtilityHelper.ToDecimal(txt_yuliang_1.Text.Trim())//余数
                       + "," + txt_iCount_1.Text.Trim()//张数
                       + "," + txt_psnQty_1.Text.Trim()//每张条码数量
                       + "}";
                txt_iCount_1.Text = "";
                txt_psnQty_1.Text = "";
            };
            //打印批量操作事件
            this.ucBtnPrint1.btnAllClick += (s, e) =>
            {
                string rowGuid = lbMxGuid.Text.Trim();
                SelectDeleteBar frm = new SelectDeleteBar(rowGuid, "采购入库");
                string strCodeList = "";
                frm.UpdateParent += (ss, ee) =>
                {
                    strCodeList = ee.StringSingle;
                };
                frm.ShowDialog();
                if (string.IsNullOrEmpty(strCodeList))
                    return;
                try
                {
                    string rptParameter = "rpt_Arrival{"
                    + "100"//重打都是传100,
                    + "," + ""
                    + "," + ""
                    + "," + ""
                    + "," + ""
                    + "," + strCodeList
                    + "}";
                    using (Form rpt = new RptPreview(rowGuid, rptParameter))
                    {
                        rpt.ShowDialog();
                    }
                    frm.Close();
                }
                catch (Exception ex)
                {
                    MsgHelper.ShowError(ex.Message);
                }
            };
 
            // -------------------- gvMx3 打印事件 --------------------
           
            this.ucBtnPrint2.btnPrintClick += (s, e) =>
            {
                string rowGuid = txt_releaseNo.Text.Trim(); // 新增lbMxGuid3用于存储gvMx3的选中行GUID
                ucBtnPrint2.guidKey = rowGuid;
 
                // 验证输入(使用gvMx3对应的输入控件)
                if (!Gs.DevApp.ToolBox.UtilityHelper.IsNumeric3(txt_iCount_2.Text.Trim(), txt_yuliang_2.Text.Trim()))
                {
                    Gs.DevApp.ToolBox.MsgHelper.ShowError("请输入正确的条码数量!");
                    txt_iCount_2.Focus();
                    this.ucBtnPrint2.rptParameter = "return false";
                    return;
                }
                if (!Gs.DevApp.ToolBox.UtilityHelper.IsNumeric3(txt_psnQty_2.Text.Trim()))
                {
                    Gs.DevApp.ToolBox.MsgHelper.ShowError("请选择打印条码数量!");
                    txt_psnQty_2.Focus();
                    this.ucBtnPrint2.rptParameter = "return false";
                    return;
                }
                if (rowGuid.Length < 10)
                {
                    Gs.DevApp.ToolBox.MsgHelper.ShowError("请选择打印的行!");
                    this.ucBtnPrint2.rptParameter = "return false";
                    return;
                }
 
                // 组装打印参数(使用gvMx3的控件值)
                this.ucBtnPrint2.rptParameter = "rpt_Arrival_Hb{"
                       + rowGuid//关联主键(gvMx3的GUID)
                       + "," + ""
                       + "," + Gs.DevApp.ToolBox.UtilityHelper.ToDecimal(txt_yuliang_2.Text.Trim())//余数
                       + "," + txt_iCount_2.Text.Trim()//张数
                       + "," + txt_psnQty_2.Text.Trim()//每张条码数量
                       + "}";
 
                // 清空输入框
                txt_iCount_2.Text = "";
                txt_psnQty_2.Text = "";
            };
            // gvMx3 批量打印事件
            this.ucBtnPrint2.btnAllClick += (s, e) =>
            {
                // string rowGuid = lbMxGuid3.Text.Trim(); // 使用gvMx3的GUID
                string rowGuid = txt_releaseNo.Text.Trim();
                SelectDeleteBar frm = new SelectDeleteBar(rowGuid, "到货条码(合并)码"); // 标题区分来源
                string strCodeList = "";
                frm.UpdateParent += (ss, ee) =>
                {
                    strCodeList = ee.StringSingle;
                };
                frm.ShowDialog();
                if (string.IsNullOrEmpty(strCodeList))
                    return;
                try
                {
                    string rptParameter = "rpt_Arrival_Hb{"
                    + "100"//重打标识
                    + "," + ""
                    + "," + ""
                    + "," + ""
                    + "," + ""
                    + "," + strCodeList
                    + "}";
                    using (Form rpt = new RptPreview(rowGuid, rptParameter))
                    {
                        rpt.ShowDialog();
                    }
                    frm.Close();
                }
                catch (Exception ex)
                {
                    MsgHelper.ShowError(ex.Message);
                }
            };
 
 
            // --------------------gvMx3 ucBtnPrintOne1 批量打印事件(优化版)--------------------
            this.ucBtnPrintOne1.btnPrintClick += (s, e) =>
            {
                // 1. 基础验证:主表行选择
                string mainGuid = lbGuid.Text.Trim();
                if (string.IsNullOrEmpty(mainGuid) || mainGuid.Length < 10)
                {
                    Gs.DevApp.ToolBox.MsgHelper.ShowError("请先在主表中选择数据行!");
                    this.ucBtnPrintOne1.rptParameter = "return false";
                    return;
                }
 
                // 2. 获取明细数据源
                DataTable dtDetails = gcMx3.DataSource as DataTable;
                if (dtDetails == null || dtDetails.Rows.Count == 0)
                {
                    Gs.DevApp.ToolBox.MsgHelper.ShowError("当前主表无关联的明细数据,请先加载明细!");
                    this.ucBtnPrintOne1.rptParameter = "return false";
                    return;
                }
 
                // 3. 筛选可打印明细(逻辑不变)
                List<string> validReleaseNos = new List<string>();
                List<string> validPrintQtys = new List<string>();
                string releaseNoField = "releaseNo";
 
                if (!dtDetails.Columns.Contains(releaseNoField))
                {
                    Gs.DevApp.ToolBox.MsgHelper.ShowError($"明细数据源缺少必要字段:{releaseNoField}");
                    this.ucBtnPrintOne1.rptParameter = "return false";
                    return;
                }
 
                foreach (DataRow row in dtDetails.Rows)
                {
                    string rowReleaseNo = row[releaseNoField]?.ToString()?.Trim() ?? "";
                    if (string.IsNullOrEmpty(rowReleaseNo) || rowReleaseNo.Length < 5)
                    {
                        Gs.DevApp.ToolBox.MsgHelper.ShowError($"跳过无效明细行:缺少或无效的releaseNo");
                        continue;
                    }
 
                    string kQtyStr = row["kQty"]?.ToString()?.Trim() ?? "0";
                    if (!Gs.DevApp.ToolBox.UtilityHelper.IsNumeric3(kQtyStr)
                        || !decimal.TryParse(kQtyStr, out decimal kQty)
                        || kQty <= 0)
                    {
                        Gs.DevApp.ToolBox.MsgHelper.ShowError($"跳过明细行(releaseNo:{rowReleaseNo}):可打印数量无效或<=0");
                        continue;
                    }
 
                    if (!validReleaseNos.Contains(rowReleaseNo))
                    {
                        validReleaseNos.Add(rowReleaseNo);
                        validPrintQtys.Add(kQty.ToString("F2"));
                    }
                    else
                    {
                        Gs.DevApp.ToolBox.MsgHelper.ShowError($"跳过重复明细行(releaseNo:{rowReleaseNo}):已包含该releaseNo");
                    }
                }
 
                if (validReleaseNos.Count == 0)
                {
                    Gs.DevApp.ToolBox.MsgHelper.ShowError("没有可批量打印的明细行(所有行均为无效数据或可打印数量<=0)");
                    this.ucBtnPrintOne1.rptParameter = "return false";
                    return;
                }
 
                // 4. 组装参数(适配_rptGetParameterP解析逻辑)
                string releaseNosStr = string.Join("|", validReleaseNos);
                string printQtysStr = string.Join("|", validPrintQtys);
 
                // 仅传6个关键参数,对应解析方法的s0-s5
                string[] reportParams = new string[]
                {
        "batch",       // s0 → @in1:批量标识
        "0",           // s1 → @in2:占位
        "0",           // s2 → @in3:余量
        "1",           // s3 → @in4:张数
        printQtysStr,  // s4 → @in5:数量列表
        releaseNosStr  // s5 → @in6:releaseNo列表
                };
 
                /*string paramContent = string.Join(",", reportParams);
                string rptParam = $"rpt_Arrival_One{{{paramContent}}}";
 
                this.ucBtnPrintOne1.guidKey = mainGuid;
                this.ucBtnPrintOne1.rptParameter = rptParam;
 
                // 5. 调用预览(逻辑不变)
                try
                {
                    using (Form rptPreviewForm = new RptPreview(mainGuid, rptParam))
                    {
                        DialogResult previewResult = rptPreviewForm.ShowDialog();
                        if (previewResult == DialogResult.OK)
                        {
                            getModel(mainGuid);
                            Gs.DevApp.ToolBox.MsgHelper.ShowError($"批量打印完成!共打印 {validReleaseNos.Count} 条有效明细");
                        }
                        else if (previewResult == DialogResult.Cancel)
                        {
                            Gs.DevApp.ToolBox.MsgHelper.ShowError("用户取消批量打印操作");
                        }
                    }
                }
                catch (Exception ex)
                {
                    string errorMsg = $"批量打印异常:{ex.Message}";
                    if (ex.InnerException != null)
                    {
                        errorMsg += $"\n内部错误:{ex.InnerException.Message}";
                    }
                    Gs.DevApp.ToolBox.MsgHelper.ShowError(errorMsg);
                    this.ucBtnPrintOne1.rptParameter = "return false";
                }
*/
 
                this.ucBtnPrintOne1.guidKey = mainGuid;
                this.ucBtnPrintOne1.rptParameter = "rpt_Arrival_One{"
                    + string.Join(",", reportParams)  // 拼接reportParams数组元素
                    + "}";
                // 6. 清空控件
                txt_iCount_2.Text = "";
                txt_psnQty_2.Text = "";
                txt_releaseNo.Text = "";
            };
 
 
            //明细行切换事件
            // 关键:绑定gvMx1和gvMx3的焦点行变化事件
            gvMx1.FocusedRowChanged += GvMx1_FocusedRowChanged;
            gvMx3.FocusedRowChanged += GvMx3_FocusedRowChanged; // 取消注释并绑定事件
            //gvMx1打印自动计算
            txt_psnQty_1.TextChanged += (s, e) =>
            {
                Gs.DevApp.ToolBox.UtilityHelper.PrintJiSuan(txt_psnQty_1, txt_iCount_1, txt_kQty.Text.Trim(), radOut, txt_yuliang_1);
            };
            radOut.SelectedIndexChanged += (s, e) =>
            {
                Gs.DevApp.ToolBox.UtilityHelper.PrintAuto(txt_psnQty_1, txt_iCount_1, radOut, txt_yuliang_1);
            };
            // gvMx3的自动计算
            txt_psnQty_2.TextChanged += (s, e) =>
            {
                Gs.DevApp.ToolBox.UtilityHelper.PrintJiSuan(txt_psnQty_2, txt_iCount_2, txt_kQtyHb.Text.Trim(), radOut2, txt_yuliang_2);
            };
            radOut2.SelectedIndexChanged += (s, e) =>
            {
                Gs.DevApp.ToolBox.UtilityHelper.PrintAuto(txt_psnQty_2, txt_iCount_2, radOut2, txt_yuliang_2);
            };
 
 
 
            ////底部汇总启用
            //gvMx1.OptionsView.ShowFooter = true;
            //// 为某一列设置求和汇总
            //gvMx1.Columns["quantity"].SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Sum;
            //gvMx1.Columns["quantity"].SummaryItem.DisplayFormat = "合计: {0}";
 
            // 为了方便使用整合到  UtilityHelper 类中的 SetupGridSummary 方法
            UtilityHelper.SetupGridSummary(gvMx1, "quantity", "okRkqty");
            UtilityHelper.SetupGridSummary(gvMxL1, "quantity", "okRkqty");
 
            // 检查数据加载后再设置颜色
            this.Load += (s, e) => {
 
               
                System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
                timer.Interval = 1000; // 1秒后执行,确保数据已加载
                timer.Tick += (sender, args) => {
                    timer.Stop();
                    timer.Dispose();
                    
                    // 使用新的简化格式设置检验结果颜色
                    UtilityHelper.SetSimpleGridColor(gvMxL1, "jyjg", "contains不合格", "Cell", Color.Red);
                    UtilityHelper.SetSimpleGridColor(gvMxL1, "jyjg", "contains合格", "Cell", Color.Green);
                    UtilityHelper.SetSimpleGridColor(gvMxL1, "jyjg", "contains免检", "Cell", Color.Green);
                    
                    UtilityHelper.SetSimpleGridColor(gvMxL2, "jyjg", "contains不合格", "Cell", Color.Red);
                    UtilityHelper.SetSimpleGridColor(gvMxL2, "jyjg", "contains合格", "Cell", Color.Green);
                    UtilityHelper.SetSimpleGridColor(gvMxL2, "jyjg", "contains免检", "Cell", Color.Green);
                    
                    UtilityHelper.SetSimpleGridColor(gvMx1, "jyjg", "contains不合格", "Cell", Color.Red);
                    UtilityHelper.SetSimpleGridColor(gvMx1, "jyjg", "contains合格", "Cell", Color.Green);
                    UtilityHelper.SetSimpleGridColor(gvMx1, "jyjg", "contains免检", "Cell", Color.Green);
                    
                    UtilityHelper.SetSimpleGridColor(gvMx3, "jyjg", "contains不合格", "Cell", Color.Red);
                    UtilityHelper.SetSimpleGridColor(gvMx3, "jyjg", "contains合格", "Cell", Color.Green);
                    UtilityHelper.SetSimpleGridColor(gvMx3, "jyjg", "contains免检", "Cell", Color.Green);
 
                    //  当收货数量(quantity)大于已入库数量(okRkqty)时,整行显示橙色
                    // UtilityHelper.SetSimpleGridColor(gvMx1, "", "quantity-okRkqty>0", "Row", Color.Orange);
 
                    //  当可打印数量(kQty)小于等于0时,整行显示灰色
                    //UtilityHelper.SetSimpleGridColor(gvMx1, "", "kQty<=0", "Row", Color.Gray);
                    UtilityHelper.SetSimpleGridColor(gridView1, "barRatio", "=100.00%", "Cell", Color.Green);
                    //入库比例
                    UtilityHelper.SetSimpleGridColor(gridView1, "rkbl", "=100.00%", "Cell", Color.Green);
                };
                timer.Start();
            };
 
        }
        private void GridView1_ColumnFilterChanged(object sender, EventArgs e)
        {
            _filterList = Gs.DevApp.ToolBox.UtilityHelper.GetDilter(gridView1.Columns, gridView1);
            Task.Delay(100);
            getPageList(1);
        }
 
 
 
        private void GvMx1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            if (e.FocusedRowHandle >= 0)
            {
                DataRow row = gvMx1.GetDataRow(e.FocusedRowHandle);
                lbMxGuid.Text = row["guid"].ToString();
                txtWlid.Text = row["itemNo"].ToString();
                txtWlgg.Text = row["itemModel"].ToString();
                txtWlmc.Text = row["itemName"].ToString();
                txtQuantity.Text = row["quantity"].ToString();//本次收货总量
                txt_yQty.Text = row["yQty"].ToString();//已打印总量
                txt_kQty.Text = row["kQty"].ToString(); //可打印总量
                txt_psnQty_1.Text = row["mrtmsl"].ToString(); //默认每张条码数量
            }
            else
            {
                lbMxGuid.Text = "";
                ucBtnPrint1.guidKey = "";
                txtWlid.Text = "";
                txtWlgg.Text = "";
                txtWlmc.Text = "";
                txtQuantity.Text = "";
                txt_yQty.Text = "";
                txt_kQty.Text = "";
                txt_psnQty_1.Text = "";
                txt_iCount_1.Text = "";
            }
        }
 
        //明细行切换事件
         
        private void GvMx3_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            if (e.FocusedRowHandle >= 0)
            {
                DataRow row = gvMx3.GetDataRow(e.FocusedRowHandle);
                //lbMxGuid.Text = row["guid"].ToString();
                txtItemNo.Text = row["itemNo"].ToString();
                txtItemModel.Text = row["itemModel"].ToString();
                txtItemName.Text = row["itemName"].ToString();
                txtQuantityHb.Text = row["quantity"].ToString();//本次收货总量
                txt_yQtyHb.Text = row["yQty"].ToString();//已打印总量
                txt_kQtyHb.Text = row["kQty"].ToString(); //可打印总量
                txt_psnQty_2.Text = row["mrtmsl"].ToString(); //默认每张条码数量
                txt_releaseNo.Text = row["releaseNo"].ToString(); //可打印总量
            }
            else
            {
                lbMxGuid.Text = "";
                ucBtnPrint1.guidKey = "";
                txtItemNo.Text = "";
                txtItemModel.Text = "";
                txtItemName.Text = "";
                txtQuantityHb.Text = "";
                txt_yQtyHb.Text = "";
                txt_kQtyHb.Text = "";
                txt_psnQty_2.Text = "";
                txt_iCount_2.Text = "";
            }
        }
 
        /// <summary>
        /// 分页事件
        /// </summary>
        /// <param name="curPage"></param>
        /// <param name="pageSize"></param>
        private void PageBar1_PagerEvent(int curPage, int pageSize)
        {
            getPageList(curPage);
        }
        /// <summary>
        /// 查询事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolBarMenu1_btnQueryClick(object sender, EventArgs e)
        {
            gridView1.ColumnFilterChanged -= GridView1_ColumnFilterChanged;
            gridView1.ActiveFilter.Clear();
            gridView1.ColumnFilterChanged += GridView1_ColumnFilterChanged;
            var frm = new ShowFilter(gridView1.Columns, _filterList, this.GetType().FullName);
            frm.UpdateParent += Frm_UpdateParent;
            frm.ShowDialog();
        }
        /// <summary>
        /// 查询回调
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Frm_UpdateParent(object sender, UpdateParentEventArgs e)
        {
            _filterList = e.FilterList;
            getPageList(1);
        }
 
        /// <summary>
        /// 刷新事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolBarMenu1_btnLoadClick(object sender, EventArgs e)
        {
            if (xtraTabControl1.SelectedTabPageIndex == 1)
                getModel(lbGuid.Text.Trim());
            else
            {
                //_filterList.Clear();
                //if (gridView1.ActiveFilter.Count > 0)
                //{
                //    gridView1.ColumnFilterChanged -= GridView1_ColumnFilterChanged;
                //    gridView1.ActiveFilter.Clear();
                //    gridView1.ColumnFilterChanged += GridView1_ColumnFilterChanged;
                //}
                //getPageList(1);
                getPageList(this.pageBar1.CurrentPage);
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="curPage">第几页</param>
        /// <param name="pageSize">每页几条</param>
        private void getPageList(int curPage)
        {
            gcMain1.DataSource = null; var _sbSqlWhere = UtilityHelper.GetSearchWhere(_filterList);
            var pgq = new PageQueryModel(curPage, this.pageBar1.RowsCount, "create_date",
                "asc", "", _sbSqlWhere.ToString());
            var json = JsonConvert.SerializeObject(pgq);
            try
            {
                var strReturn = UtilityHelper.HttpPost("",
                    _webServiceName + "GetListPage", json);
                var dd = UtilityHelper.ReturnToTablePage(strReturn);
                if (dd.rtnCode > 0)
                {
                    DataTable dt = dd.rtnData.list;
                    gcMain1.BindingContext = new BindingContext();
                    gridView1.ColumnFilterChanged -= GridView1_ColumnFilterChanged;
                    if (dt.Rows.Count > 0)
                    {
                        gcMain1.DataSource = dt;
                        gcMain1.ForceInitialize();
                        gridView1.BestFitColumns(); Gs.DevApp.ToolBox.UtilityHelper.SetGridLayout(gridView1);
                    }
                    else
                        UtilityHelper.SetDefaultTable(gcMain1, gridView1);
                    gridView1.ColumnFilterChanged += GridView1_ColumnFilterChanged;
                    pageBar1.TotalPages = dd.rtnData.pages;//总页
                    pageBar1.CurrentPage = curPage;//当前页
                    pageBar1.RecordCount = dd.rtnData.total;//总记录数
                }
                else
                {
                    ToolBox.MsgHelper.ShowError("提示:" + dd.rtnMsg);
                }
            }
            catch (Exception ex)
            {
                MsgHelper.Warning("提示:" + ex.Message);
            }
        }
        private void getModel(string strGuid)
        {
            gcMx3.DataSource = null;
            gcMx1.DataSource = null;
            gcMx2.DataSource = null;
            
            bool isEdit = false;
            if (toolBarMenu1.currentAction == "add") return;
            if (toolBarMenu1.currentAction == "edit") isEdit = true;
            if (string.IsNullOrEmpty(strGuid))
            {
                ToolBox.MsgHelper.Warning("请先选择你要操作的行!");
                return;
            }
            var _obj = new
            {
                guid = strGuid,//主建
            };
            try
            {
                string strJson = UtilityHelper.HttpPost("", _webServiceName + "GetModel", JsonConvert.SerializeObject(_obj));
                ReturnModel<dynamic> _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson);
             
                if (_rtn.rtnCode > 0)
                {
                    dynamic dy = _rtn.rtnData;
                    lbGuid.Text = strGuid;
                    List<DevExpress.XtraGrid.Views.Grid.GridView> gvList = new List<DevExpress.XtraGrid.Views.Grid.GridView>();
                    gvList.Add(gvMx1);
                    gvList.Add(gvMx2);
                    gvList.Add(gvMx3);
                    UtilityHelper.SetValueByObj(this.layoutMx1.Controls, dy, isEdit, gvList);
 
                    JArray array3 = new JArray();
                    foreach (var a in dy["list3"])
                    {
                        array3.Add(a);
                    }
                    DataTable dt3 = JsonConvert.DeserializeObject<DataTable>(array3.ToString());
                    if (dt3.Rows.Count > 0)
                    {
                        gcMx3.BindingContext = new BindingContext();
                        gcMx3.DataSource = dt3;
                        gcMx3.ForceInitialize();
                        gvMx3.BestFitColumns();
                        Gs.DevApp.ToolBox.UtilityHelper.SetGridLayout(gvMx3);
                    }
                    else
                    {
                        Gs.DevApp.ToolBox.UtilityHelper.SetDefaultTable(gcMx3, gvMx3);
                    }
 
 
                    JArray array1 = new JArray();
                    foreach (var a in dy["list1"])
                    {
                        array1.Add(a);
                    }
 
                    DataTable dt1 = JsonConvert.DeserializeObject<DataTable>(array1.ToString());
                    if (dt1.Rows.Count > 0)
                    {
                        gcMx1.BindingContext = new BindingContext();
                        gcMx1.DataSource = dt1;
                        gcMx1.ForceInitialize();
                        gvMx1.BestFitColumns();
                        Gs.DevApp.ToolBox.UtilityHelper.SetGridLayout(gvMx1);
                    }
                    else
                    {
                        Gs.DevApp.ToolBox.UtilityHelper.SetDefaultTable(gcMx1, gvMx1);
                    }
                 
                    JArray array2 = new JArray();
                    foreach (var a in dy["list2"])
                    {
                        array2.Add(a);
                    }
                    DataTable dt2 = JsonConvert.DeserializeObject<DataTable>(array2.ToString());
                    if (dt2.Rows.Count > 0)
                    {
                        gcMx2.BindingContext = new BindingContext();
                        gcMx2.DataSource = dt2;
                        gcMx2.ForceInitialize();
                        gvMx2.BestFitColumns();
                        Gs.DevApp.ToolBox.UtilityHelper.SetGridLayout(gvMx2);
                    }
                    else
                    {
                        Gs.DevApp.ToolBox.UtilityHelper.SetDefaultTable(gcMx2, gvMx2);
                    }
                  
                       }
 
           
                else
                    ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg);
            }
            catch (Exception ex)
            {
                ToolBox.MsgHelper.Warning("提示:" + ex.Message);
            }
        }
        /// <summary>
        ///  新增方法:列表显示   
        /// </summary>
        /// <param name="strGuid">主表id</param>
         
        private void getModelList(string strGuid)
        {
            gcMxL1.DataSource = null;
            gcMxL2.DataSource = null;
            gcMxL3.DataSource = null;
            var _obj = new
            {
                guid = strGuid,//主建
            };
            try
            {
                string strJson = UtilityHelper.HttpPost("", _webServiceName + "GetModel", JsonConvert.SerializeObject(_obj));
                ReturnModel<dynamic> _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson);
                if (_rtn.rtnCode > 0)
                {
                    dynamic dy = _rtn.rtnData;
                   
                    JArray array1 = new JArray();
                    foreach (var a in dy["list1"])
                    {
                        array1.Add(a);
                    }
                    DataTable dt1 = JsonConvert.DeserializeObject<DataTable>(array1.ToString());
                    if (dt1.Rows.Count > 0)
                    {
                        gcMxL1.BindingContext = new BindingContext();
                        gcMxL1.DataSource = dt1;
                        gcMxL1.ForceInitialize();
                        gvMxL1.BestFitColumns();
                        Gs.DevApp.ToolBox.UtilityHelper.SetGridLayout(gvMxL1);
                    }
                    else
                    {
                        Gs.DevApp.ToolBox.UtilityHelper.SetDefaultTable(gcMxL1, gvMxL1);
                    }
                    JArray array2 = new JArray();
                    foreach (var a in dy["list3"])
                    {
                        array2.Add(a);
                    }
 
                    DataTable dt2 = JsonConvert.DeserializeObject<DataTable>(array2.ToString());
                    if (dt2.Rows.Count > 0)
                    {
                        gcMxL2.BindingContext = new BindingContext();
                        gcMxL2.DataSource = dt2;
                        gcMxL2.ForceInitialize();
                        gvMxL2.BestFitColumns();
                        Gs.DevApp.ToolBox.UtilityHelper.SetGridLayout(gvMxL2);
                    }
                    else
                    {
                        Gs.DevApp.ToolBox.UtilityHelper.SetDefaultTable(gcMxL2, gvMxL2);
                    }
                    JArray array3 = new JArray();
                    foreach (var a in dy["list2"])
                    {
                        array3.Add(a);
                    }
                    DataTable dt3 = JsonConvert.DeserializeObject<DataTable>(array3.ToString());
                    if (dt3.Rows.Count > 0)
                    {
                        gcMxL3.BindingContext = new BindingContext();
                        gcMxL3.DataSource = dt3;
                        gcMxL3.ForceInitialize();
                        gvMxL3.BestFitColumns();
                        Gs.DevApp.ToolBox.UtilityHelper.SetGridLayout(gvMxL3);
                    }
                    else
                    {
                        Gs.DevApp.ToolBox.UtilityHelper.SetDefaultTable(gcMxL3, gvMxL3);
                    }
                }
                else
                    ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg);
            }
            catch (Exception ex)
            {
                ToolBox.MsgHelper.Warning("提示:" + ex.Message);
            }
        }
 
    }
}