BandBarodeDialog.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using static MainForm.SQLHelper;
  11. namespace MainForm.FaForm
  12. {
  13. public partial class BandBarodeDialog : Form
  14. {
  15. public string pcbCode { get; private set; }
  16. public string _CarrierBarcode { private get; set; }
  17. public string _ProductBarcode { private get; set; }
  18. public string _PCBBarcode { private get; set; }
  19. private Timer _inputTimer;
  20. public BandBarodeDialog()
  21. {
  22. InitializeComponent();
  23. //置顶
  24. this.TopMost = true;
  25. // 设置窗口相对于父窗口居中
  26. this.StartPosition = FormStartPosition.CenterParent;
  27. this.Shown += MainForm_Shown;
  28. }
  29. private void BandBarodeDialog_Load(object sender, EventArgs e)
  30. {
  31. CarrierBarcode.Text = _CarrierBarcode;
  32. ProductBarcode.Text = _ProductBarcode;
  33. PCBBarcode.Text = _PCBBarcode;
  34. Barcode.Text = string.Empty;
  35. Form_Home.isNoStop=true;
  36. // 初始化定时器
  37. _inputTimer = new Timer();
  38. _inputTimer.Interval = 500; // 500毫秒
  39. _inputTimer.Tick += InputTimer_Tick;
  40. // 绑定 TextChanged 事件
  41. Barcode.TextChanged += PCBBarcode_TextChanged;
  42. }
  43. private void button1_Click(object sender, EventArgs e)
  44. {
  45. Close();
  46. }
  47. private void PCBBarcode_TextChanged(object sender, EventArgs e)
  48. {
  49. // 每次文本变化时重置定时器
  50. _inputTimer.Stop();
  51. _inputTimer.Start();
  52. }
  53. private void InputTimer_Tick(object sender, EventArgs e)
  54. {
  55. // 定时器触发,表示输入已经完成
  56. _inputTimer.Stop();
  57. // 处理条码
  58. string pcbcode = Barcode.Text.Trim();
  59. if (!string.IsNullOrEmpty(pcbcode))
  60. {
  61. var Carrierdt = Db.Queryable<CarrierBind>()
  62. .Where(x => ( x.CarrierCode == _CarrierBarcode && x.PCBBarcode == pcbcode) || x.ProductBarcode == pcbcode)
  63. .OrderByDescending(x => x.ID)
  64. .Take(1)
  65. .ToList();
  66. if (Carrierdt != null && Carrierdt.Count > 0)
  67. {
  68. closeWin();
  69. }
  70. else
  71. {
  72. ErrorLab.Text=$"校验失败:PCB码[{pcbcode}]与载具码[{_CarrierBarcode}]未绑定";
  73. }
  74. }
  75. }
  76. private void closeWin() {
  77. _CarrierBarcode = string.Empty;
  78. _ProductBarcode = string.Empty;
  79. this.DialogResult= DialogResult.OK;
  80. this.Close();
  81. }
  82. private void MainForm_Shown(object sender, EventArgs e)
  83. {
  84. // 将焦点设置到 textBox1
  85. Barcode.Focus();
  86. }
  87. private void BandBarodeDialog_FormClosing(object sender, FormClosingEventArgs e)
  88. {
  89. Form_Home.isNoStop = false;
  90. }
  91. }
  92. }