123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- 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 Dialog_BandBarode_S3 : 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 Dialog_BandBarode_S3(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();
- //模拟点击
- Barcode.Focus();
- // 处理条码
- string pcbcode = Barcode.Text.Trim();
- if (!string.IsNullOrEmpty(pcbcode))
- {
- var Carrierdt = Db.Queryable<CarrierBind>()
- .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;
- }
- }
- }
|