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; using static MainForm.SQLHelper; namespace MainForm.FaForm { public partial class BandBarodeDialog : Form { public string pcbCode { get; private set; } public string _CarrierBarcode { get; set; } #region private string _strProductBarcode = ""; private string _strPCBBarcode = ""; #endregion public string _ProductBarcode { get; set; } public string _PCBBarcode { get; set; } private Timer _inputTimer; public BandBarodeDialog(string carrierBarcode, string strProductBarcode, string strPCBBarcode) { _CarrierBarcode = carrierBarcode; _strProductBarcode = strProductBarcode; _strPCBBarcode = strPCBBarcode; InitializeComponent(); //置顶 this.TopMost = true; // 设置窗口相对于父窗口居中 this.StartPosition = FormStartPosition.CenterParent; this.Shown += MainForm_Shown; } private void BandBarodeDialog_Load(object sender, EventArgs e) { CarrierBarcode.Text = _CarrierBarcode; ProductBarcode.Text = _strProductBarcode; PCBBarcode.Text = _strPCBBarcode; Barcode.Text = string.Empty; // 初始化定时器 _inputTimer = new Timer(); _inputTimer.Interval = 500; // 500毫秒 _inputTimer.Tick += InputTimer_Tick; // 绑定 TextChanged 事件 Barcode.TextChanged += PCBBarcode_TextChanged; Form_Home.StopWhile = true; } private void button1_Click(object sender, EventArgs e) { Close(); } private void PCBBarcode_TextChanged(object sender, EventArgs e) { // 每次文本变化时重置定时器 _inputTimer.Stop(); _inputTimer.Start(); } private void InputTimer_Tick(object sender, EventArgs e) { // 定时器触发,表示输入已经完成 _inputTimer.Stop(); // 处理条码 string pcbcode = Barcode.Text.Trim(); if (!string.IsNullOrEmpty(pcbcode)) { var Carrierdt = Db.Queryable() .Where(x => ( x.CarrierCode == _CarrierBarcode && x.PCBBarcode == pcbcode) || x.ProductBarcode == pcbcode) .OrderByDescending(x => x.ID) .Take(1) .ToList(); if (Carrierdt != null && Carrierdt.Count > 0) { closeWin(); } else { ErrorLab.Text=$"校验失败:PCB码[{pcbcode}]与载具码[{_CarrierBarcode}]未绑定"; } } } private void closeWin() { _CarrierBarcode = string.Empty; _ProductBarcode = string.Empty; this.DialogResult= DialogResult.OK; Form_Home.StopWhile = false; this.Close(); } private void MainForm_Shown(object sender, EventArgs e) { // 将焦点设置到 textBox1 Barcode.Focus(); } private void BandBarodeDialog_FormClosing(object sender, FormClosingEventArgs e) { Form_Home.StopWhile = false; } } }