Dialog_MaterialVerify.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. using static ICSharpCode.SharpZipLib.Zip.ExtendedUnixData;
  12. namespace MainForm.FaForm
  13. {
  14. public partial class Dialog_MaterialVerify : Form
  15. {
  16. Form_Home home =new Form_Home();
  17. int plcNo = 1;
  18. string stationid = "";
  19. string stationCode = "";
  20. string strflag = "";
  21. string AglueCode = "F070HARJS";//A胶水
  22. string BglueCode = "F070HARKS";//B胶水
  23. string screw = "1660601000016A";//螺丝
  24. //OP30_MesData_t OP30PLC_MesData; //PLC的MES数据
  25. //OP70_MesData_t OP70PLC_MesData; //PLC的MES数据
  26. private Timer _inputTimer;
  27. public Dialog_MaterialVerify(string Code,string flag,string Material)
  28. {
  29. InitializeComponent();
  30. //置顶
  31. this.TopMost = true;
  32. // 设置窗口相对于父窗口居中
  33. this.StartPosition = FormStartPosition.CenterParent;
  34. this.Shown += MainForm_Shown;
  35. if (Code.Contains("OP30") || Code.Contains("OP31") || Code.Contains("OP32")) {
  36. if (flag == "Left") {
  37. Station.Text = "[OP31]点散热胶装备1";
  38. stationid = GlobalContext.s3_1_station;
  39. }
  40. if (flag == "Right") {
  41. Station.Text = "[OP32]点散热胶装备2";
  42. stationid = GlobalContext.s3_2_station;
  43. }
  44. }
  45. if (Code.Contains("OP80") || Code.Contains("OP81") || Code.Contains("OP82"))
  46. {
  47. if (flag == "Left")
  48. {
  49. Station.Text = "[OP81]上盖板锁螺丝1";
  50. }
  51. if (flag == "Right")
  52. {
  53. Station.Text = "[OP82]上盖板锁螺丝2";
  54. }
  55. }
  56. stationCode = Code;
  57. strflag = flag;
  58. Type.Text = Material;
  59. }
  60. private void Dialog_MaterialVerify_S1_Load(object sender, System.EventArgs e)
  61. {
  62. // 初始化定时器
  63. _inputTimer = new Timer();
  64. _inputTimer.Interval = 500; // 500毫秒
  65. _inputTimer.Tick += InputTimer_Tick;
  66. // 绑定 TextChanged 事件
  67. Barcode.TextChanged += Barcode_TextChanged;
  68. }
  69. private void OK_btn_Click(object sender, System.EventArgs e)
  70. {
  71. string strSN = SN.Text.Trim().Substring(0,9);
  72. if (stationCode.Contains("OP30") || stationCode.Contains("OP31") || stationCode.Contains("OP32"))
  73. {
  74. //左工位,AB胶水校验
  75. if (strSN != AglueCode && strflag == "Left" && Type.Text== "A胶水")
  76. {
  77. ErrorLab.Text = $"SN[{strSN}]与当前上料工位{Type.Text}不匹配,请重新扫码!";
  78. return;
  79. }
  80. if (strSN != BglueCode && strflag == "Left" && Type.Text == "B胶水")
  81. {
  82. ErrorLab.Text = $"SN[{strSN}]与当前上料工位{Type.Text}不匹配,请重新扫码!";
  83. return;
  84. }
  85. //右工位,AB胶水校验
  86. if (strSN != AglueCode && strflag == "Right" && Type.Text == "A胶水")
  87. {
  88. ErrorLab.Text = $"SN[{strSN}]与当前上料工位{Type.Text}不匹配,请重新扫码!";
  89. return;
  90. }
  91. if (strSN != BglueCode && strflag == "Right" && Type.Text == "B胶水")
  92. {
  93. ErrorLab.Text = $"SN[{strSN}]与当前上料工位{Type.Text}不匹配,请重新扫码!";
  94. return;
  95. }
  96. //胶水上传MES
  97. int res = home.MaterialVerifyPost(SN.Text.Trim(), stationid);
  98. if (res == 1)
  99. {
  100. string logPath = GlobalContext.MaterialVerifyLog + "MaterialVerify" + DateTime.Now.ToString("yyyyMM") + ".txt";
  101. FileOperate.NewTxtFile(logPath, DateTime.Now + $"===>【辅耗材上料】工位:{Station.Text};耗材类型:{Type.Text};SN:{SN.Text} ");
  102. OKcloseWin();
  103. }
  104. else
  105. {
  106. //上传失败,取消窗口
  107. CancelcloseWin();
  108. }
  109. }
  110. else if(stationCode.Contains("OP80") || stationCode.Contains("OP81") || stationCode.Contains("OP82"))
  111. {
  112. if (strSN != screw && strflag == "Left")
  113. {
  114. ErrorLab.Text = $"料号[{strSN}]不匹配,请重新扫码!";
  115. return;
  116. }
  117. else if (strSN != screw && strflag == "Right")
  118. {
  119. ErrorLab.Text = $"料号[{strSN}]不匹配,请重新扫码!";
  120. return;
  121. }
  122. string logPath = GlobalContext.MaterialVerifyLog + "MaterialVerify" + DateTime.Now.ToString("yyyyMM") + ".txt";
  123. FileOperate.NewTxtFile(logPath, DateTime.Now + $"===>【辅耗材上料】工位:{Station.Text};耗材类型:{Type.Text};SN:{SN.Text} ");
  124. OKcloseWin();
  125. }
  126. }
  127. private void Cancel_btn_Click(object sender, System.EventArgs e)
  128. {
  129. CancelcloseWin();
  130. }
  131. private void OKcloseWin()
  132. {
  133. Station.Text = "";
  134. Type.Text = "";
  135. SN.Text = "";
  136. this.DialogResult = DialogResult.OK;
  137. Form_Home.OpenDailogFalg = true;
  138. this.Close();
  139. }
  140. private void CancelcloseWin()
  141. {
  142. this.DialogResult = DialogResult.Cancel;
  143. Form_Home.OpenDailogFalg = true;
  144. this.Close();
  145. }
  146. private void MainForm_Shown(object sender, EventArgs e)
  147. {
  148. // 将焦点设置到 textBox1
  149. Barcode.Focus();
  150. }
  151. private void InputTimer_Tick(object sender, EventArgs e)
  152. {
  153. // 定时器触发,表示输入已经完成
  154. _inputTimer.Stop();
  155. //模拟点击
  156. Barcode.Focus();
  157. string strBarcode = Barcode.Text.Trim();
  158. if (!string.IsNullOrEmpty(strBarcode))
  159. {
  160. SN.Text = strBarcode.ToUpper();
  161. Barcode.Text = "";
  162. OK_btn_Click(sender,e);//模拟点击事件
  163. }
  164. }
  165. private void Barcode_TextChanged(object sender, EventArgs e)
  166. {
  167. // 每次文本变化时重置定时器
  168. _inputTimer.Stop();
  169. _inputTimer.Start();
  170. }
  171. }
  172. }