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 { private get; set; } public string _ProductBarcode { private get; set; } private Timer _inputTimer; public BandBarodeDialog() { 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 = _ProductBarcode; PCBBarcode.Text = string.Empty; // 初始化定时器 _inputTimer = new Timer(); _inputTimer.Interval = 500; // 500毫秒 _inputTimer.Tick += InputTimer_Tick; // 绑定 TextChanged 事件 PCBBarcode.TextChanged += PCBBarcode_TextChanged; } 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 = PCBBarcode.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; this.Close(); } private void MainForm_Shown(object sender, EventArgs e) { // 将焦点设置到 textBox1 PCBBarcode.Focus(); } } }