啊鑫
6 天以前 650fe9e42e3de66be29769da72cc755273246dd9
DevApp/Gs.DevApp/UserControl/SelectCgMx.cs
@@ -1,6 +1,7 @@
using DevExpress.Data;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Views.Grid;
using Gs.DevApp.Entity;
using Gs.DevApp.ToolBox;
using Newtonsoft.Json;
using System;
@@ -10,112 +11,85 @@
namespace Gs.DevApp.UserControl
{
    // 继承自XtraForm,这是DevExpress提供的增强型表单控件
    public partial class SelectCgMx : XtraForm
    {
        // Web服务名称常量,用于调用后端接口
        private readonly string _webServiceName = "MesInvItemArnManager/";
        // 供应商ID和收料组织ID的私有变量
        private string suppId = "";
        private string receiveOrgId = "";
        /// <summary>
        /// 构造函数
        ///
        /// </summary>
        /// <param name="_suppId">供应商ID参数</param>
        /// <param name="_receiveOrgId">收料组织ID参数</param>
        /// <param name="_suppId">供应商</param>
        /// <param name="_receiveOrgId">收料组织</param>
        /// <param name="_isWw">是否委外</param>
        public SelectCgMx(string _suppId, string _receiveOrgId)
        {
            // 初始化表单控件
            InitializeComponent();
      /*  #region 自动汇总beg
        gridView1.Columns["purchaseQty"].SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Custom;
        gridView1.Columns["yssl"].SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Custom;
        gridView1.Columns["wssl"].SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Custom;
        gridView1.CustomSummaryCalculate += (sender, e) =>
        {
            GridView view = sender as GridView;
            if (e.SummaryProcess == CustomSummaryProcess.Start)
            #region MyRegion
            gridView1.Columns["purchaseQty"].SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Custom;
            gridView1.Columns["yssl"].SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Custom;
            gridView1.Columns["wssl"].SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Custom;
            gridView1.CustomSummaryCalculate += (sender, e) =>
            {
                // 初始化汇总值
                e.TotalValue = 0m;
            }
            else if (e.SummaryProcess == CustomSummaryProcess.Calculate)
            {
                // 检查当前行的Status字段是否为1
                int status = Convert.ToInt32(view.GetListSourceRowCellValue(e.RowHandle, "chkInt"));
                if (status == 1)
                GridView view = sender as GridView;
                object obj = e.FieldValue;
                if (e.SummaryProcess == CustomSummaryProcess.Start)
                {
                    string _colCaption = e.Item.ToString();
                    if (_colCaption.Contains("采购"))
                    // 初始化汇总值
                    e.TotalValue = 0;
                }
                else if (e.SummaryProcess == CustomSummaryProcess.Calculate)
                {
                    // 检查当前行的Status字段是否为1
                    int status = Convert.ToInt32(view.GetListSourceRowCellValue(e.RowHandle, "chkInt"));
                    if (status == 1)
                    {
                        decimal amount = Convert.ToDecimal(view.GetListSourceRowCellValue(e.RowHandle, "purchaseQty"));
                        e.TotalValue = Convert.ToDecimal(e.TotalValue) + amount;
                    }
                    else if (_colCaption.Contains("已收"))
                    {
                        decimal amount2 = Convert.ToDecimal(view.GetListSourceRowCellValue(e.RowHandle, "yssl"));
                        e.TotalValue = Convert.ToDecimal(e.TotalValue) + amount2;
                    }
                    else if (_colCaption.Contains("未收"))
                    {
                        decimal amount3 = Convert.ToDecimal(view.GetListSourceRowCellValue(e.RowHandle, "wssl"));
                        e.TotalValue = Convert.ToDecimal(e.TotalValue) + amount3;
                        string _colCaption = e.Item.ToString();
                        if (_colCaption.Contains("采购"))
                        {
                            decimal amount = Convert.ToDecimal(view.GetListSourceRowCellValue(e.RowHandle, "purchaseQty"));
                            e.TotalValue = Convert.ToDecimal(e.TotalValue) + amount;
                        }
                        else
                        {
                            if (_colCaption.Contains("已收"))
                            {
                                decimal amount2 = Convert.ToDecimal(view.GetListSourceRowCellValue(e.RowHandle, "yssl"));
                                e.TotalValue = Convert.ToDecimal(e.TotalValue) + amount2;
                            }
                            else
                            {
                                if (_colCaption.Contains("未收"))
                                {
                                    decimal amount3 = Convert.ToDecimal(view.GetListSourceRowCellValue(e.RowHandle, "wssl"));
                                    e.TotalValue = Convert.ToDecimal(e.TotalValue) + amount3;
                                }
                            }
                        }
                    }
                }
            }
            else if (e.SummaryProcess == CustomSummaryProcess.Finalize)
            {
                // 设置最终汇总值
                e.TotalValue = e.TotalValue;
            }
        };
        // 添加复选框变化事件,实时更新汇总
        gridView1.CellValueChanged += (s, e) =>
        {
            if (e.Column.FieldName == "chkInt")
            {
                // 复选框值变化时强制刷新汇总
                gridView1.UpdateSummary();
            }
        };
        #endregion
      */
            // 为GridView的列标题绘制事件添加处理方法,使用自定义绘制
                else if (e.SummaryProcess == CustomSummaryProcess.Finalize)
                {
                    // 设置最终汇总值
                    e.TotalValue = e.TotalValue;
                }
            };
            #endregion
            this.gridView1.CustomDrawColumnHeader += (s, e) => { Gs.DevApp.ToolBox.UtilityHelper.CustomDrawColumnHeader(s, e); };
            // 添加鼠标点击事件处理复选框点击
            this.gridView1.MouseUp += (s, e) => { Gs.DevApp.ToolBox.UtilityHelper.CustomMouseUp(s, e, gcMain, gridView1); };
            // 配置复选列的排序和筛选选项,禁用排序和筛选功能
            this.colChkInt.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
            this.colChkInt.OptionsFilter.AllowAutoFilter = false;
            this.colChkInt.OptionsFilter.AllowFilter = false;
            this.colChkInt.OptionsFilter.AllowInHeaderSearch = DevExpress.Utils.DefaultBoolean.False;
            // 设置单选按钮组默认选中第一项(采购类型)
            radioGroup1.SelectedIndex = 0;
            // 保存传入的供应商ID和收料组织ID
            this.suppId = _suppId;
            this.receiveOrgId = _receiveOrgId;
            // 设置GridView的参数配置
            Gs.DevApp.ToolBox.UtilityHelper.SetGridViewParameter(gridView1, null, null, null, "", null, null, false);
            // 加载第一页数据
            getPageList(1);
            // 为"确定"按钮添加点击事件处理
            btnIn.Click += (s, e) =>
            {
                // 提交编辑并更新当前行数据
                gridView1.PostEditor();
                gridView1.UpdateCurrentRow();
                // 收集选中行的GUID
                var list = new List<string>();
                DataTable dt = this.gcMain.DataSource as DataTable;
                {
@@ -123,77 +97,135 @@
                    {
                        string checkBox = dr["chkInt"].ToString();
                        string _guid = dr["guid"].ToString();
                        // 检查是否选中
                        if (Gs.DevApp.ToolBox.UtilityHelper.ToCheck(checkBox))
                        {
                            list.Add(_guid);
                        }
                    }
                }
                // 触发回调事件,传递选中的GUID列表,然后关闭表单
                UpdateParent?.Invoke(this, new UpdateParentEventArgs { StringList = list });
                Close();
                UpdateParent?.Invoke(this, new UpdateParentEventArgs { StringList = list }); Close();
            };
            // 为单选按钮组添加选中项变化事件,切换时重新加载数据
            radioGroup1.SelectedIndexChanged += (s, e) =>
            {
                getPageList(1);
                getPageListSrm(1);
            };
            /////////
            Gs.DevApp.ToolBox.UtilityHelper.SetGridViewParameter(gridView2, null, null, null, "", null, null, false);
            getPageListSrm(1);
        }
        /// <summary>
        /// 选择后的回调事件,用于向父窗体传递选中的数据
        ///     选择后的回调事件
        /// </summary>
        public event EventHandler<UpdateParentEventArgs> UpdateParent;
        /// <summary>
        /// 从服务器获取分页数据并绑定到GridView
        /// </summary>
        /// <param name="curPage">当前页码</param>
        /// <param name="curPage">第几页</param>
        /// <param name="pageSize">每页几条</param>
        private void getPageList(int curPage)
        {
            // 创建请求参数对象
            var _obj = new
            {
                currentPage = curPage,          // 当前页码
                everyPageSize = 999999,         // 每页记录数(这里设置了一个很大的值,可能是为了获取所有数据)
                sortName = "",                  // 排序字段
                keyWhere = "",                  // 查询条件
                inBusType = (radioGroup1.SelectedIndex + 1), // 业务类型:1是采购,2是委外
                inSupId = this.suppId,          // 供应商ID
                inReceiveOrgId = this.receiveOrgId, // 收料组织ID
                currentPage = curPage,
                everyPageSize = 999999,
                sortName = "",
                keyWhere = "",
                inBusType = (radioGroup1.SelectedIndex + 1),//1是采购,2是委外
                inSupId = this.suppId,//供应商
                inReceiveOrgId = this.receiveOrgId,//组织
            };
            // 将参数对象序列化为JSON字符串
            var json = JsonConvert.SerializeObject(_obj);
            try
            {
                // 调用Web服务获取数据
                var strReturn = UtilityHelper.HttpPost("",
                    _webServiceName + "SelectForm", json);
                // 解析返回结果为DataTable
                var dd = UtilityHelper.ReturnToTablePage(strReturn);
                var dt = dd.rtnData.list;
                // 绑定数据到GridControl
                gcMain.BindingContext = new BindingContext();
                gcMain.DataSource = dt;
                gcMain.ForceInitialize();
                // 自动调整列宽并应用网格布局
                gridView1.BestFitColumns();
                Gs.DevApp.ToolBox.UtilityHelper.SetGridLayout(gridView1);
                gridView1.BestFitColumns(); Gs.DevApp.ToolBox.UtilityHelper.SetGridLayout(gridView1);
            }
            catch (Exception ex)
            {
                // 显示错误信息
                MsgHelper.Warning("提示:" + ex.Message);
            }
        }
        #region  SRM的列表和选择事件
        /// <summary>
        /// </summary>
        /// <param name="curPage">第几页</param>
        /// <param name="pageSize">每页几条</param>
        private void getPageListSrm(int curPage)
        {
            var _obj = new
            {
                currentPage = curPage,
                everyPageSize = 999999,
                sortName = "",
                keyWhere = "",
                inBusType = (radioGroup1.SelectedIndex + 1),//1是采购,2是委外
                inSupId = this.suppId,//供应商
                inReceiveOrgId = this.receiveOrgId,//组织
            };
            var json = JsonConvert.SerializeObject(_obj);
            try
            {
                var strReturn = UtilityHelper.HttpPost("", "MesInvItemArnManager/SelectSrm", json);
                var dd = UtilityHelper.ReturnToTablePage(strReturn);
                if (dd.rtnCode > 0)
                {
                    DataTable dt = dd.rtnData.list;
                    gridControl2.BindingContext = new BindingContext();
                    if (dt.Rows.Count > 0)
                    {
                        gridControl2.DataSource = dt;
                        gridControl2.ForceInitialize();
                        gridView2.BestFitColumns();
                        Gs.DevApp.ToolBox.UtilityHelper.SetGridLayout(gridView2);
                    }
                    else
                        UtilityHelper.SetDefaultTable(gridControl2, gridView2);
                }
                else
                {
                    ToolBox.MsgHelper.ShowError("提示:" + dd.rtnMsg);
                }
            }
            catch (Exception ex)
            {
                MsgHelper.Warning("提示:" + ex.Message);
            }
        }
        private void rptSrm_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            var rowhandle = gridView2.FocusedRowHandle;
            if (rowhandle < 0)
                return;
            if (e.Button.Index == 0)
            {
                var dr = gridView2.GetDataRow(rowhandle);
                var mxGuid = dr["deliveryNo"].ToString();
                if (string.IsNullOrEmpty(mxGuid))
                {
                    return;
                }
                var list = new List<dynamic>();
                list.Add(new
                {
                    guid = mxGuid,
                    receiveOrgId = dr["receiveOrgId"].ToString(),
                    suppId = dr["suppId"].ToString(),
                    suppName = dr["suppName"].ToString(),
                });
                UpdateParent?.Invoke(this, new UpdateParentEventArgs { DynamicList = list });
                Close();
            }
        }
        #endregion
    }
}