BandBarodeDialog.cs 2.9 KB

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