quanzhou
2025-09-11 31de09d1ba504cb036ae29a98a9efbb0c2d61914
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
using Bro.Common.Helper;
using Bro.M135.Common;
using Bro.UI.Model.Winform;
using Newtonsoft.Json;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace Bro.M141.Process.UI
{
    [MenuNode("扫码界面", "扫码界面", 2, EnumHelper.TopMenu.SystemInfo, MenuNodeType.Form)]
    public partial class DataPrinter : MenuFormBase
    {
        public DataPrinter()
        {
            InitializeComponent();
            
        }
        
        private static DataPrinter _instance;
 
        public static DataPrinter GetInstance()
        {
            if (_instance == null || _instance.IsDisposed)
            {
                _instance = new DataPrinter();
            }
            return _instance;
        }
 
        M141Config Config141 => Process.IConfig as M141Config;
        M141Process Process141 => Process as M141Process;
 
        M141Process_Mysql mysqlhelper = new M141Process_Mysql();
 
        public override void OnProcessUpdated()
        {
            base.OnProcessUpdated();
 
            Process141.RerefreshBasketcodeUI += RerefreshUI;
            RerefreshUI();
        }
 
        private void RerefreshUI()
        {
            mysqlhelper.IniDBIP(Config141.IPforall);
 
        }
 
        public class codedata
        {
            public string code { get; set; }
            public string reasult { get; set; }
        }
 
        private void DataPrinter_Load(object sender, EventArgs e)
        {
            Data_Textbox.Focus();
        }
 
        private void Data_Textbox_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == '\r')
            {
                // 如果是回车键
                e.Handled = true;
 
                string barcode = Data_Textbox.Text;
 
                if (!string.IsNullOrEmpty(barcode))
                {
                    // 将条码全部选中,下一次扫码的时候,旧条码就会被新条码覆盖
                    Data_Textbox.SelectAll();
                    // 处理条码
                    // ProcessBarcode(barcode);
                    DatatoGridView(barcode);
 
                    Data_Textbox.Focus();
                }
            }
        }
        List<codedata> codes = new List<codedata>();
 
        public bool ISOK = true;
        private void DatatoGridView(string ID)
        {
            if (!ISOK)
            {
                MessageBox.Show("前一个条码为NG,需要解锁");
                return;
            }
 
            if (uiCheckBox1.Checked == true)
            {
                uiLabel3.Text = "OK";
                uiLabel3.ForeColor = Color.Green;
 
                codes.Add(new codedata()
                {
                    code = ID,
                    reasult = "OK",
                });
                //上传mes
            }
            else
            {
                var plist = mysqlhelper.SNGetProductList(ID, "S2");
                var plist1 = mysqlhelper.SNGetProductList(ID, "S3");
                var plist2 = mysqlhelper.SNGetProductList(ID, "S4");
                var plist3 = mysqlhelper.SNGetProductList(ID, "S5");
 
                if (plist != null && plist1 != null && plist2 != null && plist3 != null)//判断产品是否存在
                {
                    if (plist.Count != 0 && plist1.Count != 0 && plist2.Count != 0 && plist3.Count != 0)
                    {
                        if (plist[0].Result == "OK" && plist1[0].Result == "OK" && plist2[0].Result == "OK" && plist3[0].Result == "OK")
                        {
                            uiLabel3.Text = "OK";
                            uiLabel3.ForeColor = Color.Green;
                            uiLabel4.Text = "产品检测为OK";
                            //上传mes
                            ProductModel newp = new ProductModel();
                            newp.SEQUENCE = plist[0].SEQUENCE;
                            newp.PID = plist[0].PID;
                            newp.Zword = plist[0].Zword;
                            newp.BasketCode = plist[0].BasketCode;
                            newp.Result = "OK";
                            newp.SN = plist[0].SN;
                            if (uiCheckBox3.Checked)
                            {
                                if (Config141.numpro >= 50)
                                {
                                    Config141.numpro = 0;
                                }
                                Config141.numpro++;
                                var Msgreceice = Task.Run(() => Process141.mqtt.MESForProduceAsync(newp, Config141.mesnum2.ToString(), Config141.numpro)).Result;
                                Config141.mesnum2++;
                                if (Msgreceice != null)
                                {
                                    var obj = JsonConvert.DeserializeObject<AutoLineMacBarcodeQueueBak>(Msgreceice);
 
                                    if (obj.zstatus == "200")
                                    {
                                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"产品{newp.PID}数据上传MES成功  {Msgreceice}");
 
                                        if (Config141.Isprint && !string.IsNullOrEmpty(obj.tary_label))
                                        {
                                            Process141.StartPrint(obj.tary_label);
                                        }
                                    }
                                    else
                                    {
                                        LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"产品{newp.PID}数据上传MES失败  {Msgreceice}");
                                    }
                                }
 
                            }
 
                        }
                        else
                        {
                            uiLabel3.Text = "NG";
                            uiLabel3.ForeColor = Color.Red;
                             ISOK = false;
                            if (plist[0]?.Result == "OK" && plist2[0]?.Result == "OK")
                            {
                                uiLabel4.Text = "缺陷为外观NG";
                            }
                            else
                            {
                                uiLabel4.Text = "缺陷为AOI尺寸NG";
                            }
 
                        }
                        codes.Add(new codedata()
                        {
 
                            code = ID,
                            reasult = uiLabel4.Text,
 
                        });
                    }
                    else
                    {
                        uiLabel3.Text = "NG";
                        uiLabel3.ForeColor = Color.Red;
                        ISOK = false;
                        uiLabel4.Text = "产品未查询到结果";
                        codes.Add(new codedata
                        {
                            code = ID,
                            reasult = "无数据",
                        });
 
                    }
 
                }
                else
                {
                    uiLabel3.Text = "NG";                   
                    uiLabel3.ForeColor = Color.Red;
                    ISOK = false;
                    uiLabel4.Text = "产品未查询到结果";
                    codes.Add(new codedata
                    {
                        code = ID,
                        reasult = "无数据",
                    });
                }
            }
 
            Data_Textbox.Text = "";
            Data_Textbox.Focus();
            var bindingSource = new BindingSource { DataSource = codes };
 
            Codesdataview.DataSource = bindingSource;
 
            Codesdataview.Refresh();
 
        }
 
        private void uiCheckBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (uiCheckBox1.Checked)
            {
                uiCheckBox2.Checked = false;
            }
        }
 
        private void uiCheckBox2_CheckedChanged(object sender, EventArgs e)
        {
            if (uiCheckBox2.Checked)
            {
                uiCheckBox1.Checked = false;
            }
        }
 
        private void uiButton1_Click(object sender, EventArgs e)
        {
 
            Frm_Login.GetInstance().changeBool += new Frm_Login.ChangeBoolHander(change_bool);
 
            Frm_Login.GetInstance().ShowDialog();
 
        }
 
        public void change_bool(bool islogin)
        {
 
            ISOK = islogin;
 
        }
 
    }
}