cnf
2025-08-27 9a853780edf120c99712c15fd3b174fa08ef142c
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
using Gs.DevApp.ToolBox;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Windows.Forms;
 
namespace Gs.DevApp.DevFrm.Ck
{
    public partial class UcBlclSelect : DevExpress.XtraEditors.XtraForm
    {
        private readonly string _webServiceName = "WomdaaManager/";
        private string daaId = "";
        private string orgId = "";
 
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="_daaGuid">daaGuid</param>
        /// <param name="_orgId">生产组织</param>
        public UcBlclSelect(string _daaGuid, string _orgId)
        {
            InitializeComponent();
            InitializeGridSettings();
            this.daaId = _daaGuid;
            this.orgId = _orgId;
            Gs.DevApp.ToolBox.UtilityHelper.SetGridViewParameter(gridView1, null, null, null, "", null, null, false);
            getPageList(1);
            getPageListWithFilter(2); // 使用过滤方法
            SetupButtonClickEvent();
        }
 
        /// <summary>
        /// 重载构造函数 - 筛选掉kbsl为0的数据
        /// </summary>
        /// <param name="_daaGuid">daaGuid</param>
        /// <param name="_orgId">生产组织</param>
        /// <param name="_type">类型标识</param>
        public UcBlclSelect(string _daaGuid, string _orgId, string _type)
        {
            InitializeComponent();
            InitializeGridSettings();
            this.daaId = _daaGuid;
            this.orgId = _orgId;
            Gs.DevApp.ToolBox.UtilityHelper.SetGridViewParameter(gridView1, null, null, null, "", null, null, false);
            getPageListWithFilter(1); // 使用过滤方法
            SetupButtonClickEvent();
        }
 
        /// <summary>
        /// 初始化网格设置
        /// </summary>
        private void InitializeGridSettings()
        {
            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;
        }
 
        /// <summary>
        /// 设置按钮点击事件
        /// </summary>
        private void SetupButtonClickEvent()
        {
            btnIn.Click += (s, e) =>
            {
                gridView1.PostEditor();
                gridView1.UpdateCurrentRow();
                var list = new List<dynamic>();
                DataTable dt = this.gcMain.DataSource as DataTable;
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        string checkBox = dr["chkInt"].ToString();
                        string _guid = dr["dabGuid"].ToString();
                        if (Gs.DevApp.ToolBox.UtilityHelper.ToCheck(checkBox))
                        {
                            list.Add(new
                            {
                                dabGuid = _guid,
                                dwName = dr["dwName"].ToString(),
                                itemModel = dr["itemModel"].ToString(),
                                itemName = dr["itemName"].ToString(),
                                itemNo = dr["itemNo"].ToString(),
                                gdh = dr["gdh"].ToString(),
                                kbsl = dr["kbsl"].ToString()
                            });
                        }
                    }
                }
                UpdateParent?.Invoke(this, new UpdateParentEventArgs { DynamicList = list });
                Close();
            };
        }
 
        /// <summary>
        /// 选择后的回调事件
        /// </summary>
        public event EventHandler<UpdateParentEventArgs> UpdateParent;
 
        /// <summary>
        /// 获取页面数据(不过滤)
        /// </summary>
        /// <param name="curPage">第几页</param>
        private void getPageList(int curPage)
        {
            var _obj = new
            {
                currentPage = 1,
                everyPageSize = 999999,
                sortName = "",
                keyWhere = "",
                daaGuid = daaId
            };
            var json = JsonConvert.SerializeObject(_obj);
            try
            {
                var strReturn = UtilityHelper.HttpPost("",
                    _webServiceName + "GetListSelectDab", json);
                var dd = UtilityHelper.ReturnToTablePage(strReturn);
                var dt = dd.rtnData.list;
                gcMain.BindingContext = new BindingContext();
                gcMain.DataSource = dt;
                gcMain.ForceInitialize();
                gridView1.BestFitColumns();
                Gs.DevApp.ToolBox.UtilityHelper.SetGridLayout(gridView1);
            }
            catch (Exception ex)
            {
                MsgHelper.Warning("提示:" + ex.Message);
            }
        }
 
        /// <summary>
        /// 获取页面数据并筛选掉kbsl为0的数据
        /// </summary>
        /// <param name="curPage">第几页</param>
        private void getPageListWithFilter(int curPage)
        {
            var _obj = new
            {
                currentPage = 1,
                everyPageSize = 999999,
                sortName = "",
                keyWhere = "",
                daaGuid = daaId
            };
            var json = JsonConvert.SerializeObject(_obj);
            try
            {
                var strReturn = UtilityHelper.HttpPost("",
                    _webServiceName + "GetListSelectDab", json);
                var dd = UtilityHelper.ReturnToTablePage(strReturn);
                var dt = dd.rtnData.list;
 
                DataTable filteredDt = FilterZeroKbsl(dt);
 
                if (curPage == 1)
                {
                    // 筛选掉kbsl为0的数据
                    filteredDt = FilterZeroKbsl(dt);
                }
                else
                {
                    // 过滤dab006(需领用量)小于等于ylQty(已领用量)的数据
                    filteredDt = FilterByDab006AndYlQty(dt);
                }
 
                gcMain.BindingContext = new BindingContext();
                gcMain.DataSource = filteredDt;
                gcMain.ForceInitialize();
                gridView1.BestFitColumns();
                Gs.DevApp.ToolBox.UtilityHelper.SetGridLayout(gridView1);
            }
            catch (Exception ex)
            {
                MsgHelper.Warning("提示:" + ex.Message);
            }
        }
 
        /// <summary>
        /// 筛选掉kbsl为0的数据
        /// </summary>
        /// <param name="sourceTable">源数据表</param>
        /// <returns>过滤后的数据表</returns>
        private DataTable FilterZeroKbsl(DataTable sourceTable)
        {
            if (sourceTable == null || sourceTable.Rows.Count == 0)
                return sourceTable;
 
            // 创建新的DataTable来存储过滤后的数据
            DataTable filteredTable = sourceTable.Clone();
 
            foreach (DataRow row in sourceTable.Rows)
            {
                // 检查kbsl列是否存在且不为0
                if (sourceTable.Columns.Contains("kbsl"))
                {
                    object kbslValue = row["kbsl"];
                    decimal kbsl = 0;
 
                    // 尝试转换为decimal
                    if (kbslValue != null && kbslValue != DBNull.Value &&
                        decimal.TryParse(kbslValue.ToString(), out kbsl))
                    {
                        if (kbsl > 0) // 只保留kbsl大于0的行
                        {
                            filteredTable.ImportRow(row);
                        }
                    }
                }
                else
                {
                    // 如果没有kbsl列,保留所有行
                    filteredTable.ImportRow(row);
                }
            }
 
            return filteredTable;
        }
 
        /// <summary>
        /// 过滤dab006(需领用量)小于等于ylQty(已领用量)的数据
        /// </summary>
        /// <param name="sourceTable">源数据表</param>
        /// <returns>过滤后的数据表</returns>
        private DataTable FilterByDab006AndYlQty(DataTable sourceTable)
        {
            if (sourceTable == null || sourceTable.Rows.Count == 0)
                return sourceTable;
 
            // 创建新的DataTable来存储过滤后的数据
            DataTable filteredTable = sourceTable.Clone();
 
            foreach (DataRow row in sourceTable.Rows)
            {
                // 检查dab006和ylQty列是否存在
                if (sourceTable.Columns.Contains("dab006") && sourceTable.Columns.Contains("ylQty"))
                {
                    object dab006Value = row["dab006"];
                    object ylQtyValue = row["ylQty"];
 
                    decimal dab006 = 0;
                    decimal ylQty = 0;
 
                    // 尝试转换为decimal
                    bool dab006Valid = dab006Value != null && dab006Value != DBNull.Value &&
                                      decimal.TryParse(dab006Value.ToString(), out dab006);
                    bool ylQtyValid = ylQtyValue != null && ylQtyValue != DBNull.Value &&
                                     decimal.TryParse(ylQtyValue.ToString(), out ylQty);
 
                    // 过滤条件:dab006 >= ylQty
                    if (dab006Valid && ylQtyValid && dab006 <= ylQty)
                    {
                        filteredTable.ImportRow(row);
                    }
                }
                else
                {
                    // 如果没有这两个列,保留所有行
                    filteredTable.ImportRow(row);
                }
            }
 
            return filteredTable;
        }
 
    }
}