wbc
2025-12-03 f65c60f600d23538329d72109ac22292b032e8ba
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
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Views.Grid;
using Gs.DevApp.ToolBox;
using Gs.DevApp.UserControl;
using Gs.DevApp.Entity;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Windows.Forms;
 
namespace Gs.DevApp.DevFrm.MJGL
{
    public partial class Frm_MesMoldManagement : XtraForm
    {
        private readonly string _webServiceName = "MesMoldManagementManager/";
        private List<FilterEntity> _filterList = new List<FilterEntity>();
        private DataTable _moldListDt;
 
        public Frm_MesMoldManagement()
        {
            InitializeComponent();
            toolBarMenu1.btnAddClick += ToolBarMenu1_btnAddClick;
            toolBarMenu1.btnEdtClick += ToolBarMenu1_btnEdtClick;
            toolBarMenu1.btnSaveClick += ToolBarMenu1_btnSaveClick;
            toolBarMenu1.btnLoadClick += ToolBarMenu1_btnLoadClick;
            toolBarMenu1.btnEscClick += ToolBarMenu1_btnEscClick;
            toolBarMenu1.btnQueryClick += ToolBarMenu1_btnQueryClick;
            toolBarMenu1.btnDelClick += ToolBarMenu1_btnDelClick1;
            toolBarMenu1.getXmlConfig();
 
            UtilityHelper.SetGridViewParameter(gridView1, null, null, null, "", (value) =>
            {
                UtilityHelper.JumpTab(xtraTabControl1, 0);
            }, tips);
            UtilityHelper.SetTabParameter(gridView1, xtraTabControl1, pageBar1, (value) =>
            {
                getModel(value);
            }, (value) =>
            {
                getPageList(pageBar1.CurrentPage);
            }, lbGuid);
 
          
 
            txt_itemCode.DoubleClick += (s, e) =>
            {
                try
                {
                    var frm = new Gs.DevApp.DevFrm.QC.JyxmShow("");
                    frm.UpdateParent += (ss, ee) =>
                    {
                        try
                        {
                            var lst = ee.DynamicList;
                            txt_itemId.Text = Convert.ToString(lst[0].itemId);
                            txt_itemCode.Text = Convert.ToString(lst[0].itemNo);
                            txt_itemName.Text = Convert.ToString(lst[0].itemName);
                            txt_itemModel.Text = Convert.ToString(lst[0].itemModel);
                        }
                        catch (Exception ex2)
                        {
                            MsgHelper.Warning("提示:" + ex2.Message);
                        }
                    };
                    frm.ShowDialog();
                }
                catch (Exception ex)
                {
                    MsgHelper.Warning("提示:" + ex.Message);
                }
            };
 
          
            // 物料ID选择,复用QC检验项目的选择弹窗
            txt_itemId.ButtonClick += (s, e) =>
            {
                try
                {
                    var frm = new Gs.DevApp.DevFrm.QC.JyxmShow("");
                    frm.UpdateParent += (ss, ee) =>
                    {
                        try
                        {
                            var lst = ee.DynamicList;
                            txt_itemId.Text = Convert.ToString(lst[0].itemId);
                            txt_itemCode.Text = Convert.ToString(lst[0].itemNo);
                        }
                        catch (Exception ex2)
                        {
                            MsgHelper.Warning("提示:" + ex2.Message);
                        }
                    };
                    frm.ShowDialog();
                }
                catch (Exception ex)
                {
                    MsgHelper.Warning("提示:" + ex.Message);
                }
            };
 
            // 模具下拉数据绑定(集成到模具编码控件)
            try
            {
                var pgqMold = new PageQueryModel(1, 999999, "mold_code", "asc", "", "");
                var jMold = JsonConvert.SerializeObject(pgqMold);
                var strMold = UtilityHelper.HttpPost("", "MesMoldArchivesManager/GetMoldCodeList", jMold);
                var rtnMold = UtilityHelper.ReturnToTablePage(strMold);
                var dtMold = rtnMold.rtnData.list;
                _moldListDt = dtMold;
 
                string codeField = _moldListDt.Columns.Contains("mold_code") ? "mold_code" : (_moldListDt.Columns.Contains("moldCode") ? "moldCode" : "");
                string nameField = _moldListDt.Columns.Contains("mold_name") ? "mold_name" : (_moldListDt.Columns.Contains("moldName") ? "moldName" : "");
                string specField = _moldListDt.Columns.Contains("mold_spec") ? "mold_spec" : (_moldListDt.Columns.Contains("moldSpec") ? "moldSpec" : "");
 
                txt_moldCode.Properties.DataSource = _moldListDt;
                txt_moldCode.Properties.DisplayMember = string.IsNullOrEmpty(codeField) ? nameField : codeField;
                txt_moldCode.Properties.ValueMember = string.IsNullOrEmpty(codeField) ? nameField : codeField;
                txt_moldCode.ForceInitialize();
                txt_moldCode.Properties.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
 
                var view = lookMoldView;
                view.Columns.Clear();
                view.OptionsBehavior.AutoPopulateColumns = false;
                if (!string.IsNullOrEmpty(codeField))
                {
                    var colCode = view.Columns.AddVisible(codeField, "模具编码");
                    colCode.VisibleIndex = 0;
                }
                if (!string.IsNullOrEmpty(nameField))
                {
                    var colName = view.Columns.AddVisible(nameField, "模具名称");
                    colName.VisibleIndex = 1;
                }
                if (!string.IsNullOrEmpty(specField))
                {
                    var colSpec = view.Columns.AddVisible(specField, "模具规格");
                    colSpec.VisibleIndex = 2;
                }
                view.OptionsView.ShowAutoFilterRow = true;
                view.BestFitColumns();
 
                txt_moldCode.EditValueChanged += (s, e) =>
                {
                    try
                    {
                        var row = txt_moldCode.GetSelectedDataRow() as DataRowView;
                        if (row != null)
                        {
                            if (!string.IsNullOrEmpty(nameField)) txt_moldName.Text = Convert.ToString(row[nameField]);
                            if (!string.IsNullOrEmpty(specField)) txt_moldSpec.Text = Convert.ToString(row[specField]);
                        }
                    }
                    catch { }
                };
            }
            catch (Exception ex)
            {
                MsgHelper.Warning("提示:" + ex.Message);
            }
 
            // 物料下拉数据绑定
            try
            {
                var objItems = new
                {
                    currentPage = 1,
                    everyPageSize = 999999,
                    sortName = "",
                    keyWhere = "",
                    keyType = ""
                };
                var jItems = JsonConvert.SerializeObject(objItems);
                var strItems = UtilityHelper.HttpPost("", "MesItemsManager/GetListSelect", jItems);
                var rtnItems = UtilityHelper.ReturnToTablePage(strItems);
                var dtItems = rtnItems.rtnData.list;
                lookItem.Properties.DataSource = dtItems;
                lookItem.Properties.DisplayMember = "ItemNo";
                lookItem.Properties.ValueMember = "Id";
                lookItem.ForceInitialize();
                lookItem.Properties.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
                lookItem.EditValueChanged += (s, e) =>
                {
                    try
                    {
                        var row = lookItem.GetSelectedDataRow() as DataRowView;
                        if (row != null)
                        {
                            txt_itemCode.Text = Convert.ToString(row["ItemNo"]);
                            txt_itemId.Text = Convert.ToString(row["Id"]);
                            txt_itemName.Text = Convert.ToString(row["ItemName"]);
                            txt_itemModel.Text = Convert.ToString(row["ItemModel"]);
                        }
                    }
                    catch { }
                };
            }
            catch (Exception ex)
            {
                MsgHelper.Warning("提示:" + ex.Message);
            }
 
            
 
            getPageList(1);
            pageBar1.PagerEvent += PageBar1_PagerEvent;
        }
 
        private void PageBar1_PagerEvent(int curPage, int pageSize)
        {
            getPageList(curPage);
        }
 
        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();
        }
 
        private void Frm_UpdateParent(object sender, UpdateParentEventArgs e)
        {
            _filterList = e.FilterList;
            getPageList(1);
        }
 
        private void GridView1_ColumnFilterChanged(object sender, EventArgs e)
        {
            _filterList = UtilityHelper.GetDilter(gridView1.Columns, gridView1);
            getPageList(1);
        }
 
        private void ToolBarMenu1_btnLoadClick(object sender, EventArgs e)
        {
            if (xtraTabControl1.SelectedTabPageIndex == 1)
                getModel(lbGuid.Text.Trim());
            else
                getPageList(pageBar1.CurrentPage);
        }
 
        private void ToolBarMenu1_btnEscClick(object sender, EventArgs e)
        {
            UtilityHelper.JumpTab(xtraTabControl1, 1);
        }
 
        private void ToolBarMenu1_btnEdtClick(object sender, EventArgs e)
        {
            toolBarMenu1.currentAction = "edit";
            string rowGuid, rowName;
            (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1, lbGuid, txt_moldCode, gridView1);
            if (string.IsNullOrEmpty(rowGuid))
            {
                MsgHelper.Warning("请先选择你要操作的行!");
                return;
            }
            UtilityHelper.JumpTab(xtraTabControl1, 3);
            getModel(rowGuid);
        }
 
        private void ToolBarMenu1_btnAddClick(object sender, EventArgs e)
        {
            lbGuid.Text = "";
            UtilityHelper.JumpTab(xtraTabControl1, 4);
            UtilityHelper.CleanValueByControl(this.layoutMx1.Controls, true);
        }
 
        private void ToolBarMenu1_btnDelClick1(object sender, EventArgs e)
        {
            string rowGuid, rowName;
            (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1, lbGuid, txt_moldCode, gridView1);
            if (string.IsNullOrEmpty(rowGuid))
            {
                MsgHelper.Warning("请先选择你要操作的行!");
                return;
            }
            try
            {
                var strJson = UtilityHelper.HttpPost("", _webServiceName + "DeleteModel", JsonConvert.SerializeObject(new List<string> { rowGuid }));
                var rtn = UtilityHelper.ReturnToDynamic(strJson);
                MsgHelper.Warning("提示:" + rtn.rtnMsg);
                if (rtn.rtnCode > 0) getPageList(pageBar1.CurrentPage);
            }
            catch (Exception ex)
            {
                MsgHelper.Warning("提示:" + ex.Message);
            }
        }
 
        private void ToolBarMenu1_btnSaveClick(object sender, EventArgs e)
        {
            toolBarMenu1.isSetBtn = false;
            var moldCodeVal = Convert.ToString(txt_moldCode.EditValue)?.Trim();
            if (string.IsNullOrEmpty(moldCodeVal))
            {
                MsgHelper.Warning("模具编码不能为空!");
                txt_moldCode.Focus();
                return;
            }
            var obj = new
            {
                Guid = UtilityHelper.ToGuid(lbGuid.Text.Trim()),
                MoldCode = moldCodeVal,
                ItemCode = txt_itemCode.Text.Trim(),
                ItemId = txt_itemId.Text.Trim(),
                Status = txt_status.Text.Trim(),
                PackQty = txt_packQty.Text.Trim(),
                Capacity = txt_capacity.Text.Trim(),
                Description = txt_description.Text.Trim()
            };
            if (string.IsNullOrEmpty(txt_itemCode.Text.Trim()) || string.IsNullOrEmpty(txt_itemId.Text.Trim()))
            {
                MsgHelper.Warning("物料编码与物料ID必须选择!");
                txt_itemId.Focus();
                return;
            }
            try
            {
                var strJson = UtilityHelper.HttpPost("", _webServiceName + "EditModel", JsonConvert.SerializeObject(obj));
                var rtn = UtilityHelper.ReturnToDynamic(strJson);
                MsgHelper.Warning("提示:" + rtn.rtnMsg);
                if (rtn.rtnCode > 0)
                {
                    lbGuid.Text = rtn.rtnData;
                    toolBarMenu1.isSetBtn = true;
                    UtilityHelper.ChangeEnableByControl(this.layoutMx1.Controls, false);
                    toolBarMenu1.currentAction = "";
                    UtilityHelper.JumpTab(xtraTabControl1, 6);
                }
            }
            catch (Exception ex)
            {
                MsgHelper.Warning("提示:" + ex.Message);
            }
        }
 
        private void getPageList(int curPage)
        {
            gcMain1.DataSource = null;
            var sbWhere = UtilityHelper.GetSearchWhere(_filterList);
            var pgq = new PageQueryModel(curPage, this.pageBar1.RowsCount, "mold_code", "asc", "", sbWhere.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(); UtilityHelper.SetGridLayout(gridView1);
                    }
                    else
                        SetDefaultTableSafe();
                    gridView1.ColumnFilterChanged += GridView1_ColumnFilterChanged;
                    pageBar1.TotalPages = dd.rtnData.pages;
                    pageBar1.CurrentPage = curPage;
                    pageBar1.RecordCount = dd.rtnData.total;
                }
                else
                {
                    MsgHelper.ShowError("提示:" + dd.rtnMsg);
                    SetDefaultTableSafe();
                }
            }
            catch (Exception ex)
            {
                MsgHelper.Warning("提示:" + ex.Message);
            }
        }
 
        private void getModel(string strGuid)
        {
            bool isEdit = toolBarMenu1.currentAction == "edit";
            if (string.IsNullOrEmpty(strGuid))
            {
                MsgHelper.Warning("请先选择你要操作的行!");
                return;
            }
            var _obj = new { guid = strGuid };
            try
            {
                var strJson = UtilityHelper.HttpPost("", _webServiceName + "GetModel", JsonConvert.SerializeObject(_obj));
                var _rtn = UtilityHelper.ReturnToDynamic(strJson);
                if (_rtn.rtnCode > 0)
                {
                    var dy = _rtn.rtnData;
                    lbGuid.Text = strGuid;
                    UtilityHelper.SetValueByObj(this.layoutMx1.Controls, dy, isEdit);
                   
                }
                else
                {
                    MsgHelper.Warning("提示:" + _rtn.rtnMsg);
                }
            }
            catch (Exception ex)
            {
                MsgHelper.Warning("提示:" + ex.Message);
            }
        }
 
        private void SetDefaultTableSafe()
        {
            var dt = new DataTable();
            foreach (DevExpress.XtraGrid.Columns.GridColumn col in gridView1.Columns)
            {
                var field = col.FieldName;
                if (string.IsNullOrEmpty(field)) continue;
                if (col.UnboundDataType == typeof(System.Boolean))
                    dt.Columns.Add(field, typeof(System.Boolean));
                else
                    dt.Columns.Add(field, typeof(string));
            }
            gcMain1.BindingContext = new BindingContext();
            gcMain1.DataSource = dt;
            gcMain1.ForceInitialize();
            gridView1.BestFitColumns();
        }
    }
}