Dialog_MaterialVerify.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. using BZFAStandardLib;
  2. using EIP_Protocol;
  3. using MainForm.ClassFile.ProjectClass;
  4. using Sunny.UI;
  5. using Sunny.UI.Win32;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Numerics;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace MainForm.FaForm
  12. {
  13. public partial class Dialog_MaterialVerify : Form
  14. {
  15. Form_Home home =new Form_Home();
  16. int plcNo = 1;
  17. string stationid = "";
  18. string stationCode = "";
  19. //OP30_MesData_t OP30PLC_MesData; //PLC的MES数据
  20. //OP70_MesData_t OP70PLC_MesData; //PLC的MES数据
  21. private Timer _inputTimer;
  22. public Dialog_MaterialVerify(string Code,string flag,string Material)
  23. {
  24. InitializeComponent();
  25. //置顶
  26. this.TopMost = true;
  27. // 设置窗口相对于父窗口居中
  28. this.StartPosition = FormStartPosition.CenterParent;
  29. this.Shown += MainForm_Shown;
  30. if (Code.Contains("OP30") || Code.Contains("OP31") || Code.Contains("OP32")) {
  31. if (flag == "Left") {
  32. Station.Text = "[OP31]点散热胶装备1";
  33. stationid = GlobalContext.s3_1_station;
  34. }
  35. if (flag == "Right") {
  36. Station.Text = "[OP32]点散热胶装备2";
  37. stationid = GlobalContext.s3_2_station;
  38. }
  39. }
  40. if (Code.Contains("OP80") || Code.Contains("OP81") || Code.Contains("OP82"))
  41. {
  42. if (flag == "Left")
  43. {
  44. Station.Text = "[OP81]上盖板锁螺丝1";
  45. }
  46. if (flag == "Right")
  47. {
  48. Station.Text = "[OP82]上盖板锁螺丝2";
  49. }
  50. }
  51. stationCode = Code;
  52. Type.Text = Material;
  53. }
  54. private void Dialog_MaterialVerify_S1_Load(object sender, System.EventArgs e)
  55. {
  56. // 初始化定时器
  57. _inputTimer = new Timer();
  58. _inputTimer.Interval = 500; // 500毫秒
  59. _inputTimer.Tick += InputTimer_Tick;
  60. // 绑定 TextChanged 事件
  61. Barcode.TextChanged += Barcode_TextChanged;
  62. }
  63. private void OK_btn_Click(object sender, System.EventArgs e)
  64. {
  65. if (stationCode.Contains("OP30"))
  66. {
  67. //胶水上传MES
  68. int res = home.MaterialVerifyPost(SN.Text.Trim(), stationid);
  69. if (res == 1)
  70. {
  71. string logPath = GlobalContext.MaterialVerifyLog + "MaterialVerify" + DateTime.Now.ToString("yyyyMM") + ".txt";
  72. FileOperate.NewTxtFile(logPath, DateTime.Now + $"===>【辅耗材上料】工位:{Station.Text};耗材类型:{Type.Text};SN:{SN.Text} ");
  73. OKcloseWin();
  74. }
  75. else
  76. {
  77. //上传失败,取消窗口
  78. CancelcloseWin();
  79. }
  80. }
  81. else {
  82. string logPath = GlobalContext.MaterialVerifyLog + "MaterialVerify" + DateTime.Now.ToString("yyyyMM") + ".txt";
  83. FileOperate.NewTxtFile(logPath, DateTime.Now + $"===>【辅耗材上料】工位:{Station.Text};耗材类型:{Type.Text};SN:{SN.Text} ");
  84. OKcloseWin();
  85. }
  86. }
  87. private void Cancel_btn_Click(object sender, System.EventArgs e)
  88. {
  89. CancelcloseWin();
  90. }
  91. private void OKcloseWin()
  92. {
  93. Station.Text = "";
  94. Type.Text = "";
  95. SN.Text = "";
  96. this.DialogResult = DialogResult.OK;
  97. Form_Home.OpenDailogFalg = true;
  98. this.Close();
  99. }
  100. private void CancelcloseWin()
  101. {
  102. this.DialogResult = DialogResult.Cancel;
  103. Form_Home.OpenDailogFalg = true;
  104. this.Close();
  105. }
  106. private void MainForm_Shown(object sender, EventArgs e)
  107. {
  108. // 将焦点设置到 textBox1
  109. Barcode.Focus();
  110. }
  111. private void InputTimer_Tick(object sender, EventArgs e)
  112. {
  113. // 定时器触发,表示输入已经完成
  114. _inputTimer.Stop();
  115. //模拟点击
  116. Barcode.Focus();
  117. string strBarcode = Barcode.Text.Trim();
  118. if (!string.IsNullOrEmpty(strBarcode))
  119. {
  120. SN.Text = strBarcode.ToUpper();
  121. Barcode.Text = "";
  122. }
  123. }
  124. private void Barcode_TextChanged(object sender, EventArgs e)
  125. {
  126. // 每次文本变化时重置定时器
  127. _inputTimer.Stop();
  128. _inputTimer.Start();
  129. }
  130. }
  131. }