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
using DevExpress.XtraEditors;
using Gs.DevApp.ToolBox;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Windows.Forms;
 
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>
        public SelectCgMx(string _suppId, string _receiveOrgId)
        {
            // 初始化表单控件
            InitializeComponent();
 
            // 为GridView的列标题绘制事件添加处理方法,使用自定义绘制
            this.gridView1.CustomDrawColumnHeader += (s, e) => { Gs.DevApp.ToolBox.UtilityHelper.CustomDrawColumnHeader(s, e); };
 
            // 为GridView的鼠标抬起事件添加处理方法,实现自定义交互
            this.gridView1.MouseUp += (s, e) => { 
                Gs.DevApp.ToolBox.UtilityHelper.CustomMouseUp(s, e, gcMain, gridView1); 
                
                // 全选/取消全选后立即更新汇总,缩短延迟时间
                System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
                timer.Interval = 80; // 缩短延迟确保操作完成后立即刷新
                timer.Tick += (sender, args) =>
                {
                    timer.Stop();
                    timer.Dispose();
                    UtilityHelper.RefreshConditionalSummary(gridView1); // 使用新的刷新方法
                };
                timer.Start();
            };
 
            // 配置复选列的排序和筛选选项,禁用排序和筛选功能
            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;
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        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();
            };
 
            // 为单选按钮组添加选中项变化事件,切换时重新加载数据
            radioGroup1.SelectedIndexChanged += (s, e) =>
            {
                getPageList(1);
            };
         
            /// <summary>
            /// 条件汇总:只对选中(打勾)的行进行汇总
            /// chkInt字段为true时才计算purchaseQty和wssl的合计
            /// 使用一键式方法,包含条件汇总+实时刷新功能
            /// </summary>
            UtilityHelper.SetupCompleteConditionalSummary(gridView1, "chkInt", true, new string[] { "purchaseQty", "wssl" });
 
 
        }
 
        /// <summary>
        /// 选择后的回调事件,用于向父窗体传递选中的数据
        /// </summary>
        public event EventHandler<UpdateParentEventArgs> UpdateParent;
 
        /// <summary>
        /// 从服务器获取分页数据并绑定到GridView
        /// </summary>
        /// <param name="curPage">当前页码</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
            };
 
            // 将参数对象序列化为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);
            }
            catch (Exception ex)
            {
                // 显示错误信息
                MsgHelper.Warning("提示:" + ex.Message);
            }
        }
    }
}