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(); // 处理条码 DatatoGridView(barcode); Data_Textbox.Focus(); } } } List codes = new List(); 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(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, "Honeywell PX240S(300 dpi)"); } } 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; } } }