BandBarodeDialog.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 { get; set; }
  17. #region
  18. private string _strProductBarcode = "";
  19. private string _strPCBBarcode = "";
  20. #endregion
  21. public string _ProductBarcode { get; set; }
  22. public string _PCBBarcode { get; set; }
  23. private Timer _inputTimer;
  24. public BandBarodeDialog(string carrierBarcode, string strProductBarcode, string strPCBBarcode)
  25. {
  26. _CarrierBarcode = carrierBarcode;
  27. _strProductBarcode = strProductBarcode;
  28. _strPCBBarcode = strPCBBarcode;
  29. InitializeComponent();
  30. //置顶
  31. this.TopMost = true;
  32. // 设置窗口相对于父窗口居中
  33. this.StartPosition = FormStartPosition.CenterParent;
  34. this.Shown += MainForm_Shown;
  35. }
  36. private void BandBarodeDialog_Load(object sender, EventArgs e)
  37. {
  38. CarrierBarcode.Text = _CarrierBarcode;
  39. ProductBarcode.Text = _strProductBarcode;
  40. PCBBarcode.Text = _strPCBBarcode;
  41. Barcode.Text = string.Empty;
  42. // 初始化定时器
  43. _inputTimer = new Timer();
  44. _inputTimer.Interval = 500; // 500毫秒
  45. _inputTimer.Tick += InputTimer_Tick;
  46. // 绑定 TextChanged 事件
  47. Barcode.TextChanged += PCBBarcode_TextChanged;
  48. Form_Home.StopWhile = true;
  49. }
  50. private void button1_Click(object sender, EventArgs e)
  51. {
  52. Close();
  53. }
  54. private void PCBBarcode_TextChanged(object sender, EventArgs e)
  55. {
  56. // 每次文本变化时重置定时器
  57. _inputTimer.Stop();
  58. _inputTimer.Start();
  59. }
  60. private void InputTimer_Tick(object sender, EventArgs e)
  61. {
  62. // 定时器触发,表示输入已经完成
  63. _inputTimer.Stop();
  64. // 处理条码
  65. string pcbcode = Barcode.Text.Trim();
  66. if (!string.IsNullOrEmpty(pcbcode))
  67. {
  68. var Carrierdt = Db.Queryable<CarrierBind>()
  69. .Where(x => ( x.CarrierCode == _CarrierBarcode && x.PCBBarcode == pcbcode) || x.ProductBarcode == pcbcode)
  70. .OrderByDescending(x => x.ID)
  71. .Take(1)
  72. .ToList();
  73. if (Carrierdt != null && Carrierdt.Count > 0)
  74. {
  75. closeWin();
  76. }
  77. else
  78. {
  79. ErrorLab.Text=$"校验失败:PCB码[{pcbcode}]与载具码[{_CarrierBarcode}]未绑定";
  80. }
  81. }
  82. }
  83. private void closeWin() {
  84. _CarrierBarcode = string.Empty;
  85. _ProductBarcode = string.Empty;
  86. this.DialogResult= DialogResult.OK;
  87. Form_Home.StopWhile = false;
  88. this.Close();
  89. }
  90. private void MainForm_Shown(object sender, EventArgs e)
  91. {
  92. // 将焦点设置到 textBox1
  93. Barcode.Focus();
  94. }
  95. private void BandBarodeDialog_FormClosing(object sender, FormClosingEventArgs e)
  96. {
  97. Form_Home.StopWhile = false;
  98. }
  99. }
  100. }