kyy
2025-11-25 91777cd07bb42802b2ac730cc6c35750ab7cc69e
DevApp/Gs.DevApp/DevFrm/Warehouse/Frm_ArrivalBarcode.cs
@@ -53,80 +53,50 @@
            #region 打印相关 2025-10-18 
            // -------------------- gvMx1 打印事件 --------------------
            //浏览打印事件
            this.ucBtnPrint1.btnPrintClick += (s, e) =>
            {
                  _print(0);
                _print(0);
              
            };
            //直接打印事件
            this.ucBtnPrint1.btnZhiJieClick += (s, e) =>
            {
                _print(1);
            };
            //打印批量操作事件
            this.ucBtnPrint1.btnAllClick += (s, e) =>
            {
                string rowGuid = lbMxGuid.Text.Trim();
                SelectDeleteBar frm = new SelectDeleteBar(rowGuid, "采购入库");
                string strCodeList = "";
                string strAction = "";
                frm.UpdateParent += (ss, ee) =>
                {
                    strCodeList = ee.StringSingle;
                    strAction = ee.Data;
                };
                frm.ShowDialog();
                if (string.IsNullOrEmpty(strCodeList))
                    return;
                if (strAction == "print")
                {
                    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);
                    }
                }
                _print100(rowGuid, frm);//重打都是传100,
            };
            //直接打印事件
            this.ucBtnPrint1.btnZhiJieClick += (s, e) =>
            {
                  _print(1);
            };
            // -------------------- gvMx3 打印事件 --------------------
            this.ucBtnPrint2.btnPrintClick += (s, e) =>
            {
                _print2(0);
            };
            //直接打印事件
            this.ucBtnPrint2.btnZhiJieClick += (s, e) =>
            {
                _print2(1);
            };
            // gvMx3 批量打印事件
            // gvMx1 1打印事件
            this.ucBtnPrint2.btnAllClick += (s, e) =>
            {
                // string rowGuid = lbMxGuid3.Text.Trim(); // 使用gvMx3的GUID
                string rowGuid = txt_releaseNo.Text.Trim();
                SelectDeleteBar frm = new SelectDeleteBar(rowGuid, "到货条码(合并)码"); // 标题区分来源
              //  _print100(rowGuid, frm);//重打都是传100,
                string strCodeList = "";
                string strAction = "";
                frm.UpdateParent += (ss, ee) =>
@@ -161,135 +131,36 @@
                    }
                }
            };
            // --------------------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;
//                }
            // --------------------gvMx1 ucBtnPrintOne1  明细打印事件(优化版)--------------------
//                // 3. 筛选可打印明细(逻辑不变)
//                List<string> validReleaseNos = new List<string>();
//                List<string> validPrintQtys = new List<string>();
//                string releaseNoField = "releaseNo";
            //一键打印事件
            this.ucBtnPrintOne1.btnPrintClick += (s, e) =>
            {
                _print3(101); //一键打印101
            };
            this.ucBtnPrintOne1.btnAllClick += (s, e) =>
            {
                string mainGuid = lbGuid.Text.Trim();
                SelectDeleteBar frm = new SelectDeleteBar(mainGuid, "批量条码"); // 标题区分来源
                _print100(mainGuid, frm);//重打都是传100,
            };
//                if (!dtDetails.Columns.Contains(releaseNoField))
//                {
//                    Gs.DevApp.ToolBox.MsgHelper.ShowError($"明细数据源缺少必要字段:{releaseNoField}");
//                    this.ucBtnPrintOne1.rptParameter = "return false";
//                    return;
//                }
            // --------------------gvMx3 ucBtnPrintOne2 合并批量打印事件(优化版)--------------------
//                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 = "";
//            };
            //一键打印事件
            this.ucBtnPrintOne2.btnPrintClick += (s, e) =>
            {
                _print4(102); //一键合并打印102
            };
            this.ucBtnPrintOne2.btnAllClick += (s, e) =>
            {
                string mainGuid = lbGuid.Text.Trim();
                SelectDeleteBar frm = new SelectDeleteBar(mainGuid, "批量条码"); // 标题区分来源
                _print100(mainGuid, frm);//重打都是传100,
            };
            //明细行切换事件
            // 关键:绑定gvMx1和gvMx3的焦点行变化事件
@@ -322,9 +193,12 @@
            //gvMx1.Columns["quantity"].SummaryItem.DisplayFormat = "合计: {0}";
            // 为了方便使用整合到  UtilityHelper 类中的 SetupGridSummary 方法
           // UtilityHelper.SetupGridSummary(gvMx1, "quantity", "okRkqty");
           // UtilityHelper.SetupGridSummary(gvMxL1, "quantity", "okRkqty");
            UtilityHelper.SetupGridSummary(gvMx1, "quantity", "okRkqty");
            UtilityHelper.SetupGridSummary(gvMxL1, "quantity", "okRkqty");
            UtilityHelper.SetupGridSummary(gvMx2, "quantity", "okRkqty");
            UtilityHelper.SetupGridSummary(gvMxL2, "quantity", "okRkqty");
            UtilityHelper.SetupGridSummary(gvMx3, "quantity", "okRkqty");
            UtilityHelper.SetupGridSummary(gvMxL3, "quantity", "okRkqty");
            // 检查数据加载后再设置颜色
            this.Load += (s, e) =>
            {
@@ -403,7 +277,6 @@
            txt_iCount_1.Text = "";
            txt_psnQty_1.Text = "";
        }
        private void _print2(int type)
        {
            string rowGuid = txt_releaseNo.Text.Trim(); // 新增lbMxGuid3用于存储gvMx3的选中行GUID
@@ -444,7 +317,74 @@
            txt_iCount_2.Text = "";
            txt_psnQty_2.Text = "";
        }
        private void _print3(int type)
        {
            string mainGuid = lbGuid.Text.Trim();
            ucBtnPrintOne1.guidKey = mainGuid;
            this.ucBtnPrintOne1.rptParameter = "rpt_Arrival{"
            + type
            + "," + ""
            + "," + ""
            + "," + ""
            + "," + ""
            + "}";
            txt_iCount_1.Text = "";
            txt_psnQty_1.Text = "";
        }
        private void _print4(int type)
        {
            string mainGuid = lbGuid.Text.Trim();
            ucBtnPrintOne2.guidKey = mainGuid;
            this.ucBtnPrintOne2.rptParameter = "rpt_Arrival{"
            + type
            + "," + ""
            + "," + ""
            + "," + ""
            + "," + ""
            + "}";
            txt_iCount_1.Text = "";
            txt_psnQty_1.Text = "";
        }
        private void _print100(string mainGuid, SelectDeleteBar frm)
        {
            string strCodeList = "";
            string strAction = "";
            frm.UpdateParent += (ss, ee) =>
            {
                strCodeList = ee.StringSingle;
                strAction = ee.Data;
            };
            frm.ShowDialog();
            if (string.IsNullOrEmpty(strCodeList))
                return;
            if (strAction == "print")
            {
                try
                {
                    string rptParameter = "rpt_Arrival{"
                    + "100"//重打都是传100,
                    + "," + ""
                    + "," + ""
                    + "," + ""
                    + "," + ""
                    + "," + strCodeList
                    + "}";
                    using (Form rpt = new RptPreview(mainGuid, rptParameter))
                    {
                        rpt.ShowDialog();
                    }
                    frm.Close();
                }
                catch (Exception ex)
                {
                    MsgHelper.ShowError(ex.Message);
                }
            }
        }
        private void GridView1_ColumnFilterChanged(object sender, EventArgs e)
        {
            _filterList = Gs.DevApp.ToolBox.UtilityHelper.GetDilter(gridView1.Columns, gridView1);