cdk
昨天 8efb7bd645073441a6a1c6659dfc7514290e57f0
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
using Gs.DevApp.Entity;
using Gs.DevApp.ToolBox;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Data;
using System.Dynamic;
using System.Windows.Forms;
 
namespace Gs.DevApp.DevFrm.Work
{
    public partial class Frm_Work01Fg : DevExpress.XtraEditors.XtraForm
    {
        string _webServiceName = "WorkCollect/";
        string dianJianPath = "";//电检取值路径
        string goodTag = "√";
        string badTag = "×";
        string fGxTouRu = "G001:投入";
       
        /// <summary>
        /// 
        /// </summary>
        /// <param name="_fGx">工序</param>
        /// <param name="_fBc">班次</param>
        /// <param name="_strinOther">目前为电检路径</param>
        /// <param name="chkWater">是否水检</param>
        public Frm_Work01Fg(string _fGx, string _fBc)
        {
            InitializeComponent();
            System.Drawing.Font ft1 = new System.Drawing.Font("宋体", 35F);//大按钮
            System.Drawing.Font ft2 = new System.Drawing.Font("宋体", 25F);//中按钮
            System.Drawing.Font ft3 = new System.Drawing.Font("宋体", 15F);//grid
            System.Drawing.Font ft4 = new System.Drawing.Font("宋体", 12F);//head
            System.Drawing.Font ft5 = new System.Drawing.Font("宋体", 12F);//表头
            //设置字体大小 
            this.btnGood.Appearance.Font = ft1;
            this.btnBad.Appearance.Font = ft1;
            this.simpleButton3.Appearance.Font = ft2;
            this.simpleButton7.Appearance.Font = ft2;
            this.simpleButton5.Appearance.Font = ft2;
            this.simpleButton4.Appearance.Font = ft2;
            this.simpleButton6.Appearance.Font = ft2;
            this.lbSum1.Appearance.Font = ft2;
            this.lbSum2.Appearance.Font = ft2;
            this.lbSum3.Appearance.Font = ft2;
            this.lbSum4.Appearance.Font = ft2;
            this.gvMx1.Appearance.Row.Font = ft3;
            this.gvMx2.Appearance.Row.Font = ft3;
            this.layoutControlItem1.AppearanceItemCaption.Font = ft4;
            this.layoutControlItem2.AppearanceItemCaption.Font = ft4;
            this.layoutControlItem3.AppearanceItemCaption.Font = ft4;
            this.layoutControlItem4.AppearanceItemCaption.Font = ft4;
            this.layoutControlItem5.AppearanceItemCaption.Font = ft4;
            this.layShuiJian.AppearanceItemCaption.Font = ft4;
            this.layoutControlItem7.AppearanceItemCaption.Font = ft4;
            this.layoutControlItem8.AppearanceItemCaption.Font = ft4;
            this.layoutControlItem10.AppearanceItemCaption.Font = ft4;
            this.layoutControlItem11.AppearanceItemCaption.Font = ft4;
            this.layoutControlItem12.AppearanceItemCaption.Font = ft4;
            this.layoutControlItem13.AppearanceItemCaption.Font = ft4;
            this.layoutControlItem14.AppearanceItemCaption.Font = ft4;
            this.layoutControlItem15.AppearanceItemCaption.Font = ft4;
            this.txt_gdbh.Properties.Appearance.Font = ft5;
            this.txt_itemNo.Properties.Appearance.Font = ft5;
            this.txt_itemModel.Properties.Appearance.Font = ft5;
            this.txt_gx.Properties.Appearance.Font = ft5;
            this.txt_bc.Properties.Appearance.Font = ft5;
            this.txt_itemName.Properties.Appearance.Font = ft5;
            this.txt_yjDate.Properties.Appearance.Font = ft5;
            this.txt_collectBy.Properties.Appearance.Font = ft5;
            this.txt_sbNo.Properties.Appearance.Font = ft5;
            this.txt_sjXt.Properties.Appearance.Font = ft5;
            this.txt_sjDate.Properties.Appearance.Font = ft5;
            this.txt_barCode.Properties.Appearance.Font = ft5;
            this.txt_currentBarCode.Properties.Appearance.Font = ft5;
            this.txt_OldLiuShuiMa.Properties.Appearance.Font = ft5;
            gvMx1.IndicatorWidth = 60;
            gvMx1.CustomDrawRowIndicator += (s, e) =>
            {
                if (e.Info.IsRowIndicator && e.RowHandle >= 0)
                    e.Info.DisplayText = (e.RowHandle + 1).ToString();
            };
            txt_gx.Text = _fGx;
            txt_bc.Text = _fBc;
            this.Text = "工序采集【" + _fGx + " - " + _fBc + "】";
            label8.Text = _fGx + "数量";
            //追溯码框回车事件
            txt_barCode.KeyDown += (s, e) =>
            {
                if (e.KeyCode == Keys.Enter)
                {
                    txt_OldLiuShuiMa.Focus();
                }
            };
            //流水码框回车事件
            txt_OldLiuShuiMa.KeyDown += (s, e) =>
            {
                if (e.KeyCode == Keys.Enter)
                {
                    if (txt_OldLiuShuiMa.Text.Trim().Length <= 0)
                    {
                        Toast vm = new Toast(-1, "操作失败@n请先扫追溯码");
                        vm.Show();
                        this.ActiveControl = this.txt_OldLiuShuiMa;
                        txt_OldLiuShuiMa.Focus();
                        return;
                    }
                    addModel(goodTag);
                }
            };
            //良品按钮事件
            btnGood.Click += (s, e) =>
            {
                addModel(goodTag);
            };
            //不良品按钮事件
            btnBad.Click += (s, e) =>
            {
                int idx = tabMx.SelectedTabPageIndex;
                if (idx > 0)
                {
                    Toast vm = new Toast(-1, "请重新操作@n已帮你切换到【良品明细】");
                    vm.Show();
                    tabMx.SelectedTabPageIndex = 0;
                    return;
                }
                string _collectGuid = "";
                string _collCode = "";
                var dr = gvMx1.GetFocusedDataRow();
                if (dr == null || string.IsNullOrEmpty(dr["guid"].ToString()))
                {
 
                }
                else
                {
                    _collectGuid = dr["guid"].ToString();
                    _collCode = dr["barCode"].ToString();
                }
                if (_collectGuid.Length < 30)
                {
                    Toast vm = new Toast(-1, "操作失败@n请先选择追溯码");
                    vm.Show();
                    return;
                }
                string _msg = "你准备将【" + _collCode + "】变更为不良";
                string _type = "";
                if (txt_gx.Text.Trim() == fGxTouRu)
                    _type = "工序G001:投入不良描述";
                string condition = $" pid<>'00000000-0000-0000-0000-000000000000' ";
                if (txt_orgId.Text.Trim() == "104554") // 电器
                {
                    condition += $" and a.s_type =  '{_type}' ";
                }
                if (txt_orgId.Text.Trim() == "104540") // 魔凡
                {
                    condition += $" and a.s_type = '魔凡{_type}' ";
                }
 
                UcDictionarySelect frm = new UcDictionarySelect(_type, condition, _msg);
                frm.UpdateParent += (ss, ee) =>
                {
                    System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
                    var lst = ee.DynamicList;
                    foreach (dynamic dym in lst)
                    {
                        if (stringBuilder.Length > 0)
                            stringBuilder.Append("&");
                        stringBuilder.Append(dym.dicTxt);
                    }
                    string _txt = stringBuilder.ToString();
                    if (string.IsNullOrEmpty(_txt))
                    {
                        Toast vm = new Toast(-1, "操作失败@n请选择不良项目");
                        vm.Show();
                    }
                    else
                        addModel(badTag, _txt, _collectGuid);
                };
                frm.ShowDialog();
                this.ActiveControl = this.txt_barCode;
                txt_barCode.Focus();
            };
            this.ActiveControl = this.txt_barCode;
            txt_barCode.Focus();
        }
 
        /// <summary>
        /// 根据工序,构造不同类型的实体,读取不同的数据
        /// </summary>
        /// <param name="_barCode">条码</param>
        /// <param name="_checkResult">结果</param>
        /// <param name="_badDescription">不良描述</param>
        /// <param name="_collectGuid">采集guid,如果是不良,需要collectGuid</param>
        /// <returns></returns>
        private dynamic getObj(string _barCode, string _checkResult, string _badDescription = "", string _collectGuid = "")
        {
            dynamic _obj = new ExpandoObject();
            _obj.barCode = _barCode;
            _obj.checkResult = _checkResult;//检测结果
            _obj.processNo = txt_gx.Text.Trim();//工序
            _obj.banCi = txt_bc.Text.Trim();//班次
            _obj.gongWei = "";//工位
            _obj.badDescription = _badDescription.Trim();//不良描述
            _obj.collectGuid = _collectGuid;
            _obj.oldLiushuima = txt_OldLiuShuiMa.Text.Trim();
            //不良,直接提交
            if (!string.IsNullOrEmpty(_collectGuid))
            {
                return _obj;
            }
            //投入,直接提交
            if (txt_gx.Text.Trim() == fGxTouRu)
            {
                return _obj;
            }
            return null;
        }
 
        /// <summary>
        /// 上报实体
        /// </summary>
        /// <param name="_checkResult">结果:√</param>
        /// <param name="_badDescription">不良描述</param>
        private void addModel(string _checkResult, string _badDescription = "", string _collectGuid = "")
        {
            string _barCode = txt_barCode.Text.Trim();
            if (string.IsNullOrEmpty(_collectGuid))
            {
                if (string.IsNullOrEmpty(_barCode))
                {
                    Toast vm = new Toast(-1, "操作失败@n请先扫描追溯码");
                    vm.Show();
                    this.ActiveControl = this.txt_barCode;
                    txt_barCode.Focus();
                    return;
                }
            }
            dynamic _obj = getObj(_barCode, _checkResult, _badDescription, _collectGuid);
            try
            {
                string strJson = UtilityHelper.HttpPost("", _webServiceName + "GetModel", JsonConvert.SerializeObject(_obj));
                ReturnModel<dynamic> _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson);
                if (_rtn.rtnCode > 0)
                {
                    dynamic dy = _rtn.rtnData;
                    //表头和汇总
                    UtilityHelper.SetValueByObj(this.layoutMx1.Controls, dy, false);
                    lbSum1.Text = dy.lbSum1;
                    lbSum2.Text = dy.lbSum2;
                    lbSum3.Text = dy.lbSum3;
                    lbSum4.Text = dy.lbSum4;
                    prog1.Position = dy.jd;
                    txt_barCode.ReadOnly = false;
                     txt_OldLiuShuiMa.ReadOnly = false;
                    //良品列表
                    JObject _job = JObject.Parse(strJson);
                    JArray array = new JArray();
                    foreach (var a in _job["rtnData"]["list"])
                    {
                        array.Add(a);
                    }
                    DataTable dt = JsonConvert.DeserializeObject<DataTable>(array.ToString());
                    if (dt.Rows.Count > 0)
                    {
                        gcMx1.BindingContext = new BindingContext();
                        gcMx1.DataSource = dt;
                        gcMx1.ForceInitialize();
                        gvMx1.BestFitColumns();
                        Gs.DevApp.ToolBox.UtilityHelper.SetGridLayout(gvMx1);
                    }
                    else
                    {
                        Gs.DevApp.ToolBox.UtilityHelper.SetDefaultTable(gcMx1, gvMx1);
                    }
                    //不良品列表
                    JArray array2 = new JArray();
                    foreach (var a in _job["rtnData"]["list2"])
                    {
                        array2.Add(a);
                    }
                    DataTable dt2 = JsonConvert.DeserializeObject<DataTable>(array2.ToString());
                    if (dt2.Rows.Count > 0)
                    {
                        gcMx2.BindingContext = new BindingContext();
                        gcMx2.DataSource = dt2;
                        gcMx2.ForceInitialize();
                        gvMx2.BestFitColumns();
                        Gs.DevApp.ToolBox.UtilityHelper.SetGridLayout(gvMx2);
                    }
                    else
                    {
                        Gs.DevApp.ToolBox.UtilityHelper.SetDefaultTable(gcMx2, gvMx2);
                    }
                    string _msg = _rtn.rtnMsg;
                    if (!string.IsNullOrEmpty(_msg))
                    {
                        // Toast vm = new Toast((goodTag == "√" ? 1 : -1), _msg); 2025-08-20 修改提示外观
                        Toast vm;
                        if (_msg.EndsWith("."))
                            vm = new Toast(-1, _rtn.rtnMsg);
                        else
                            vm = new Toast(1, _rtn.rtnMsg);
                        vm.Show();
                    }
                }
                else
                {
                    Toast vm = new Toast(-1, _rtn.rtnMsg);
                    vm.Show();
                }
            }
            catch (Exception ex)
            {
                Toast vm = new Toast(-1, ex.Message);
                vm.Show();
            }
            txt_barCode.Text = "";
            txt_OldLiuShuiMa.Text = "";
            this.ActiveControl = this.txt_barCode;
            txt_barCode.Focus();
        }
    }
}