lu
2025-06-09 ccc1b0d541d8f3bdd2bcb72dd0b5533e68b886d5
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
using DevExpress.XtraGrid.Columns;
using Gs.DevApp.Entity;
using Gs.DevApp.ToolBox;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Dynamic;
using System.IO;
using System.Text;
using System.Windows.Forms;
 
namespace Gs.DevApp.DevFrm.Work
{
    public partial class Frm_Work01 : DevExpress.XtraEditors.XtraForm
    {
        string _webServiceName = "WorkCollect/";
        string dianJianPath = "";//电检取值路径
        string goodTag = "√";
        string badTag = "×";
        string fGxTouRu = "G001:投入";
        string fGxDianJian = "G002:电检";
        string fGxShouJian = "G003:水检";
        string fGxZhongJian = "G004:终检";
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="_fGx">工序</param>
        /// <param name="_fBc">班次</param>
        /// <param name="_strinOther">目前为电检路径</param>
        public Frm_Work01(string _fGx, string _fBc, string _strinOther)
        {
            InitializeComponent();
            txt_gx.Text = _fGx;
            txt_bc.Text = _fBc;
            txt_dianJianPath.Text = _strinOther;
            dianJianPath= _strinOther;
            this.Text = "工序采集【" + _fGx + " - " + _fBc + "】";
            addColumn();
            txt_barCode.KeyDown += (s, e) =>
            {
                if (e.KeyCode == Keys.Enter) { addModel(goodTag); };
            };
            btnGood.Click += (s, e) =>
            {
                addModel(goodTag);
            };
            btnBad.Click += (s, e) =>
            {
                UcDictionarySelect frm = new UcDictionarySelect("工序不良描述", " a.s_type='工序不良描述' and pid<>'00000000-0000-0000-0000-000000000000'");
                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, "~当为不良时,请选择不良项目~");
                        vm.Show();
                    }
                    else
                        addModel(badTag, _txt);
                };
                frm.ShowDialog();
            };
        }
 
        /// <summary>
        /// 根据工序,构造不同类型的实体
        /// </summary>
        /// <param name="_barCode">条码</param>
        /// <param name="_checkResult">结果</param>
        /// <param name="_badDescription">不良描述</param>
        /// <returns></returns>
        private dynamic getObj(string _barCode, string _checkResult, string _badDescription = "")
        {
            dynamic _obj = new ExpandoObject();
            _obj.barCode = _barCode;
            _obj.checkResult = _checkResult;//检测结果
            _obj.processNo = txt_gx.Text.Trim();//工序
            _obj.banCi = txt_bc.Text.Trim();//班次
            _obj.gongWei = txt_gw.Text.Trim();//工位
            _obj.badDescription = _badDescription.Trim();//不良描述
            if (txt_gx.Text.Trim() == fGxTouRu)
            {
                return _obj;
            }
            if (txt_gx.Text.Trim() == fGxDianJian)
            {
                string TM = "";
                string JD = "";
                string JY = "";
                string JN = "";
                string XL = "";
                string GV = "";
                string JDV = "";
                string JYV = "";
                string JNV = "";
                string XLV = "";
                string GVV = "";
                string myStr = File.ReadAllText(dianJianPath, Encoding.Default);
                if (myStr == "")
                {
                    return null;
                }
               
                JArray dsTemp = JArray.Parse(myStr);
                foreach (var ss in dsTemp)  //查找某个字段与值
                {
                    TM = (((JObject)ss)["TiaoMa"] == null) ? "" : ((JObject)ss)["TiaoMa"].ToString();
                    JD = (((JObject)ss)["JieDi"] == null) ? "" : ((JObject)ss)["JieDi"]["state"].ToString();
                    JY = (((JObject)ss)["JueYuan"] == null) ? "" : ((JObject)ss)["JueYuan"]["state"].ToString();
                    JN = (((JObject)ss)["JiaoNai"] == null) ? "" : ((JObject)ss)["JiaoNai"]["state"].ToString();
                    XL = (((JObject)ss)["XieLou"] == null) ? "" : ((JObject)ss)["XieLou"]["state"].ToString();
                    GV = (((JObject)ss)["GongLv"] == null) ? "" : ((JObject)ss)["GongLv"]["state"].ToString();
                    JDV = (((JObject)ss)["JieDi"] == null) ? "" : ((JObject)ss)["JieDi"]["value"].ToString().Replace(" ", ",");
                    JYV = (((JObject)ss)["JueYuan"] == null) ? "" : ((JObject)ss)["JueYuan"]["value"].ToString().Replace(" ", ", ");
                    JNV = (((JObject)ss)["JiaoNai"] == null) ? "" : ((JObject)ss)["JiaoNai"]["value"].ToString().Replace(" ", ", ");
                    XLV = (((JObject)ss)["XieLou"] == null) ? "" : ((JObject)ss)["XieLou"]["value"].ToString().Replace(" ", ", ");
                    GVV = (((JObject)ss)["GongLv"] == null) ? "" : ((JObject)ss)["GongLv"]["value"].ToString().Replace(" ", ", ");
                }
                _obj.t001 = TM;
                _obj.t002 = JD;
                _obj.t003 = JY;
                _obj.t004 = JN;
                _obj.t005 = XL;
                _obj.t006 = GV;
                _obj.t007 = JDV;
                _obj.t008 = JYV;
                _obj.t009 = JNV;
                _obj.t010 = XLV;
                _obj.t011 = GVV;
              //  File.WriteAllText(dianJianPath, "");
                return _obj;
            }
 
            if (txt_gx.Text.Trim() == fGxShouJian)
            {
                string strCsl1 = "strCsl1";
                string strSw1 = "strSw1";
                string strCsl2 = "strCsl2";
                string strSw2 = "strSw2";
                string strCsl3 = "strCsl3";
                string strSw3 = "strSw3";
                string strCsl4 = "strCsl4";
                string strSw4 = "strSw4";
                string strCsl5 = "strCsl5";
                string strSw5 = "strSw5";
                string SJJG = "";
                _obj.t002 = strCsl1;
                _obj.t003 = strSw1;
                _obj.t004 = strCsl2;
                _obj.t005 = strSw2;
                _obj.t006 = strCsl3;
                _obj.t007 = strSw3;
                _obj.t008 = strCsl4;
                _obj.t009 = strSw4;
                _obj.t010 = strCsl5;
                _obj.t011 = strSw5;
                // _obj.t012 = SJJG;这个待确定
                return _obj;
            }
 
            if (txt_gx.Text.Trim() == fGxZhongJian)
            {
                return _obj;
            }
            return null;
        }
 
        /// <summary>
        /// 上报实体
        /// </summary>
        /// <param name="_checkResult">结果:√</param>
        /// <param name="_badDescription">不良描述</param>
        private void addModel(string _checkResult, string _badDescription = "")
        {
            string _barCode = txt_barCode.Text.Trim();
            if (string.IsNullOrEmpty(_barCode))
            {
                Toast vm = new Toast(-1, "~请先扫追溯码~");
                vm.Show();
                return;
            }
            dynamic _obj = getObj(_barCode, _checkResult, _badDescription);
            if (_obj == null)
            {
                Toast vm = new Toast(-1, "~读取数据失败,请检查设备~");
                vm.Show();
                return;
            }
            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;
                    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);
                        vm.Show();
                    };
                }
                else
                {
                    Toast vm = new Toast(-1, _rtn.rtnMsg);
                    vm.Show();
                }
            }
            catch (Exception ex)
            {
                Toast vm = new Toast(-1, ex.Message);
                vm.Show();
            }
        }
 
        /// <summary>
        /// 增加电检取数的列
        /// </summary>
        public void addColumn()
        {
            List<dynamic> _lst = new List<dynamic>();
            if (txt_gx.Text.Trim() == fGxDianJian)
            {
                _lst.Add(new
                {
                    ziduan = "t002",
                    wenben = "接地",
                    kejian = true,
                    visibleIndex = 1,
                });
                _lst.Add(new
                {
                    ziduan = "t004",
                    wenben = "交耐",
                    kejian = true,
                    visibleIndex = 1,
                });
                _lst.Add(new
                {
                    ziduan = "t005",
                    wenben = "泄漏",
                    kejian = true,
                    visibleIndex = 1,
                });
                _lst.Add(new
                {
                    ziduan = "t006",
                    wenben = "功率",
                    kejian = true,
                    visibleIndex = 1,
                });
                _lst.Add(new
                {
                    ziduan = "t007",
                    wenben = "接地结果",
                    kejian = true,
                    visibleIndex = 1,
                });
                _lst.Add(new
                {
                    ziduan = "t009",
                    wenben = "交耐结果",
                    kejian = true,
                    visibleIndex = 1,
                });
                _lst.Add(new
                {
                    ziduan = "t010",
                    wenben = "泄漏结果",
                    kejian = true,
                    visibleIndex = 1,
                });
 
                _lst.Add(new
                {
                    ziduan = "t011",
                    wenben = "功率结果",
                    kejian = true,
                    visibleIndex = 1,
                });
            }
            if (txt_gx.Text.Trim() == fGxShouJian)
            {
                _lst.Add(new
                {
                    ziduan = "t002",
                    wenben = "出水量1",
                    kejian = true,
                    visibleIndex = 1,
                });
                _lst.Add(new
                {
                    ziduan = "t003",
                    wenben = "水温1",
                    kejian = true,
                    visibleIndex = 1,
                });
                _lst.Add(new
                {
                    ziduan = "t004",
                    wenben = "出水量2",
                    kejian = true,
                    visibleIndex = 1,
                });
                _lst.Add(new
                {
                    ziduan = "t005",
                    wenben = "水温2",
                    kejian = true,
                    visibleIndex = 1,
                });
                _lst.Add(new
                {
                    ziduan = "t006",
                    wenben = "出水量3",
                    kejian = true,
                    visibleIndex = 1,
                });
                _lst.Add(new
                {
                    ziduan = "t007",
                    wenben = "水温3",
                    kejian = true,
                    visibleIndex = 1,
                });
                _lst.Add(new
                {
                    ziduan = "t008",
                    wenben = "出水量4",
                    kejian = true,
                    visibleIndex = 1,
                });
                _lst.Add(new
                {
                    ziduan = "t009",
                    wenben = "水温4",
                    kejian = true,
                    visibleIndex = 1,
                });
 
                _lst.Add(new
                {
                    ziduan = "t010",
                    wenben = "出水量5",
                    kejian = true,
                    visibleIndex = 1,
                });
                _lst.Add(new
                {
                    ziduan = "t011",
                    wenben = "水温5",
                    kejian = true,
                    visibleIndex = 1,
                });
            }
            foreach (var item in _lst)
            {
                GridColumn newColumn = new GridColumn();
                newColumn.FieldName = item.ziduan; // 设置与数据源对应的字段名
                newColumn.Caption = item.wenben; // 设置列的标题
                                                 //newColumn.Visible = item.visibleIndex; // 设置列是否可见
                newColumn.VisibleIndex = item.visibleIndex; // 设置列的显示顺序
                gvMx1.Columns.Add(newColumn);
            }
        }
 
       
    }
}