12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- 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<CarrierBind>()
- .Where(x => x.CarrierCode == _CarrierBarcode)
- .Where(x => x.PCBBarcode == 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();
- }
- }
- }
|