using BZFAStandardLib; using EIP_Protocol; using MainForm.ClassFile.ProjectClass; using Sunny.UI; using Sunny.UI.Win32; using System; using System.Collections.Generic; using System.Numerics; using System.Threading.Tasks; using System.Windows.Forms; namespace MainForm.FaForm { public partial class Dialog_MaterialVerify : Form { Form_Home home =new Form_Home(); int plcNo = 1; string stationid = ""; string stationCode = ""; //OP30_MesData_t OP30PLC_MesData; //PLC的MES数据 //OP70_MesData_t OP70PLC_MesData; //PLC的MES数据 private Timer _inputTimer; public Dialog_MaterialVerify(string Code,string flag,string Material) { InitializeComponent(); //置顶 this.TopMost = true; // 设置窗口相对于父窗口居中 this.StartPosition = FormStartPosition.CenterParent; this.Shown += MainForm_Shown; if (Code.Contains("OP30")) { if (flag == "Left") { Station.Text = "[OP31]点散热胶装备1"; stationid = GlobalContext.s3_1_station; } if (flag == "Right") { Station.Text = "[OP32]点散热胶装备2"; stationid = GlobalContext.s3_2_station; } } if (Code.Contains("OP80")) { if (flag == "Left") { Station.Text = "[OP81]上盖板锁螺丝1"; } if (flag == "Right") { Station.Text = "[OP82]上盖板锁螺丝2"; } } stationCode = Code; Type.Text = Material; } private void Dialog_MaterialVerify_S1_Load(object sender, System.EventArgs e) { // 初始化定时器 _inputTimer = new Timer(); _inputTimer.Interval = 500; // 500毫秒 _inputTimer.Tick += InputTimer_Tick; // 绑定 TextChanged 事件 Barcode.TextChanged += Barcode_TextChanged; } private void OK_btn_Click(object sender, System.EventArgs e) { if (stationCode.Contains("OP30")) { //胶水上传MES int res = home.MaterialVerifyPost(SN.Text.Trim(), stationid); if (res == 1) { string logPath = GlobalContext.MaterialVerifyLog + "MaterialVerify" + DateTime.Now.ToString("yyyyMM") + ".txt"; FileOperate.NewTxtFile(logPath, DateTime.Now + $"===>【辅耗材上料】工位:{Station.Text};耗材类型:{Type.Text};SN:{SN.Text} "); OKcloseWin(); } else { //上传失败,取消窗口 CancelcloseWin(); } } else { string logPath = GlobalContext.MaterialVerifyLog + "MaterialVerify" + DateTime.Now.ToString("yyyyMM") + ".txt"; FileOperate.NewTxtFile(logPath, DateTime.Now + $"===>【辅耗材上料】工位:{Station.Text};耗材类型:{Type.Text};SN:{SN.Text} "); OKcloseWin(); } } private void Cancel_btn_Click(object sender, System.EventArgs e) { CancelcloseWin(); } private void OKcloseWin() { Station.Text = ""; Type.Text = ""; SN.Text = ""; this.DialogResult = DialogResult.OK; Form_Home.OpenDailogFalg = true; this.Close(); } private void CancelcloseWin() { this.DialogResult = DialogResult.Cancel; Form_Home.OpenDailogFalg = true; this.Close(); } private void MainForm_Shown(object sender, EventArgs e) { // 将焦点设置到 textBox1 Barcode.Focus(); } private void InputTimer_Tick(object sender, EventArgs e) { // 定时器触发,表示输入已经完成 _inputTimer.Stop(); //模拟点击 Barcode.Focus(); string strBarcode = Barcode.Text.Trim(); if (!string.IsNullOrEmpty(strBarcode)) { SN.Text = strBarcode.ToUpper(); Barcode.Text = ""; } } private void Barcode_TextChanged(object sender, EventArgs e) { // 每次文本变化时重置定时器 _inputTimer.Stop(); _inputTimer.Start(); } } }