Make_EquiConnect.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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.Windows.Forms;
  9. using UAS_MES_NEW.DataOperate;
  10. using UAS_MES_NEW.Entity;
  11. namespace UAS_MES_NEW.Make
  12. {
  13. public partial class Make_EquiConnect : Form
  14. {
  15. public Make_EquiConnect()
  16. {
  17. InitializeComponent();
  18. }
  19. StringBuilder SQL = new StringBuilder();
  20. DataHelper dh = SystemInf.dh;
  21. DataTable dt;
  22. private void Make_EquiConnect_Load(object sender, EventArgs e)
  23. {
  24. dt = (DataTable)dh.ExecuteSql("SELECT * FROM line WHERE li_wcname = 'SMT' ORDER BY li_auditdate", "select");
  25. if (dt.Rows.Count > 0)
  26. {
  27. foreach (DataRow item in dt.Rows)
  28. {
  29. LineVal.Items.Add(item["li_code"].ToString());
  30. }
  31. }
  32. }
  33. private void OK_Click(object sender, EventArgs e)
  34. {
  35. if (string.IsNullOrEmpty(EmployeeVal.Text))
  36. {
  37. ShowMsg(0, "请输入抽检人员姓名");
  38. return;
  39. }
  40. /*if (string.IsNullOrEmpty(LineVal.Text))
  41. {
  42. ShowMsg(0, "请选择线体");
  43. return;
  44. }*/
  45. if (string.IsNullOrEmpty(SNVal.Text))
  46. {
  47. ShowMsg(0, "请选择扫描序列号");
  48. return;
  49. }
  50. //InsertLog("OK");
  51. }
  52. private void NG_Click(object sender, EventArgs e)
  53. {
  54. if (string.IsNullOrEmpty(EmployeeVal.Text))
  55. {
  56. ShowMsg(0, "请输入抽检人员姓名");
  57. return;
  58. }
  59. /*if (string.IsNullOrEmpty(LineVal.Text))
  60. {
  61. ShowMsg(0, "请选择线体");
  62. return;
  63. }*/
  64. if (string.IsNullOrEmpty(SNVal.Text))
  65. {
  66. ShowMsg(0, "请选择扫描序列号");
  67. return;
  68. }
  69. //InsertLog("NG");
  70. }
  71. private void InsertLog(string sn, string resType, string main_sn = "")
  72. {
  73. dt = (DataTable)dh.ExecuteSql($@"select * from steptestdetail where std_class = 'Xray抽检' and std_sn = '{sn}'", "select");
  74. if (dt.Rows.Count > 0)
  75. {
  76. if (string.IsNullOrEmpty(main_sn))
  77. {
  78. ShowMsg(0, $"序列号:{sn} 已采集Xray信息");
  79. return;
  80. }
  81. else
  82. {
  83. ShowMsg(0, $"拼板号:{main_sn} 中序列号:{sn} ,已采集Xray信息");
  84. return;
  85. }
  86. }
  87. UpdateSN("L", sn);
  88. SQL.Clear();
  89. SQL.Append($@"INSERT INTO steptestdetail (std_id,std_sn,std_makecode,std_class,std_testresult,std_indate,STD_SUBCLASS1,STD_SUBCLASS2)
  90. VALUES (steptestdetail_seq.NEXTVAL, '{sn}','{workOrder.Text.Trim()}','Xray抽检','{resType}',sysdate, '{LineVal.Text}','{EmployeeVal.Text.Trim()}')");
  91. dh.ExecuteSql(SQL.ToString(), "insert");
  92. if (string.IsNullOrEmpty(main_sn))
  93. {
  94. ShowMsg(1, $"已记录 {sn},测试结果为 {resType}");
  95. }
  96. else
  97. {
  98. ShowMsg(1, $"拼板号:{main_sn} 已记录序列号:{sn} ,测试结果为 {resType}");
  99. }
  100. }
  101. private void ShowMsg(int type, string msg)
  102. {
  103. msg = msg.Replace("\r", "").Replace("\n", "");
  104. string msgTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  105. string showMsg = $"{msgTime}: {msg}\n";
  106. if (type == 0)
  107. {
  108. OperatResult.AppendText(showMsg, Color.Red);
  109. }
  110. else if (type == 1)
  111. {
  112. OperatResult.AppendText(showMsg, Color.Green);
  113. }
  114. else if (type == 2)
  115. {
  116. OperatResult.AppendText(showMsg, Color.GreenYellow);
  117. }
  118. }
  119. private void UpdateSN(string type, string sn)
  120. {
  121. if (type == "C")
  122. {
  123. serialNumber.Text = "";
  124. workOrder.Text = "";
  125. productCode.Text = "";
  126. productName.Text = "";
  127. TargetQty.Text = "";
  128. }
  129. else if (type == "L")
  130. {
  131. SQL.Clear();
  132. SQL.Append($@"SELECT ms_sncode,ma_code,pr_code,pr_spec,ma_qty FROM makeserial,make,product
  133. WHERE ms_sncode = '{sn}' AND ms_makecode = ma_code AND ms_prodcode = pr_code");
  134. dt = (DataTable)dh.ExecuteSql(SQL.ToString(), "select");
  135. if (dt.Rows.Count > 0)
  136. {
  137. serialNumber.Text = dt.Rows[0]["ms_sncode"].ToString();
  138. workOrder.Text = dt.Rows[0]["ma_code"].ToString();
  139. productCode.Text = dt.Rows[0]["pr_code"].ToString();
  140. productName.Text = dt.Rows[0]["pr_spec"].ToString();
  141. TargetQty.Text = dt.Rows[0]["ma_qty"].ToString();
  142. }
  143. else
  144. {
  145. UpdateSN("C", sn);
  146. }
  147. }
  148. }
  149. private void EmployeeVal_KeyDown_1(object sender, KeyEventArgs e)
  150. {
  151. if (e.KeyCode != Keys.Enter) return;
  152. if (string.IsNullOrEmpty(EmployeeVal.Text)) return;
  153. /*dt = (DataTable)dh.ExecuteSql($"select * from employee where em_name = '{EmployeeVal.Text.Trim()}'", "select");
  154. if (dt.Rows.Count == 0)
  155. {
  156. MessageBox.Show("请输入正确人员账号");
  157. EmployeeVal.Text = "";
  158. EmployeeVal.Focus();
  159. EmployeeVal.SelectAll();
  160. return;
  161. }*/
  162. }
  163. private void EmployeeVal_Leave_1(object sender, EventArgs e)
  164. {
  165. if (string.IsNullOrEmpty(EmployeeVal.Text)) return;
  166. /*dt = (DataTable)dh.ExecuteSql($"select * from employee where em_name = '{EmployeeVal.Text.Trim()}'", "select");
  167. if (dt.Rows.Count == 0)
  168. {
  169. MessageBox.Show("请输入正确人员账号");
  170. EmployeeVal.Text = "";
  171. EmployeeVal.Focus();
  172. EmployeeVal.SelectAll();
  173. return;
  174. }*/
  175. }
  176. private void NgBox_Click(object sender, EventArgs e)
  177. {
  178. OkBox.Checked = false;
  179. }
  180. private void OkBox_Click(object sender, EventArgs e)
  181. {
  182. NgBox.Checked = false;
  183. }
  184. private void SnType1_Click(object sender, EventArgs e)
  185. {
  186. SnType2.Checked = false;
  187. }
  188. private void SnType2_Click(object sender, EventArgs e)
  189. {
  190. SnType1.Checked = false;
  191. }
  192. private void SNVal_KeyDown(object sender, KeyEventArgs e)
  193. {
  194. if (e.KeyCode != Keys.Enter) return;
  195. SNVal.Text = SNVal.Text.Trim();
  196. if (string.IsNullOrEmpty(EmployeeVal.Text))
  197. {
  198. ShowMsg(0, "请输入抽检人员姓名");
  199. return;
  200. }
  201. if (!OkBox.Checked && !NgBox.Checked)
  202. {
  203. ShowMsg(0, "请勾选判定结果");
  204. return;
  205. }
  206. /*if (!SnType1.Checked && !SnType2.Checked)
  207. {
  208. ShowMsg(0, "请勾选序列号类型");
  209. return;
  210. }*/
  211. if (string.IsNullOrEmpty(SNVal.Text))
  212. {
  213. ShowMsg(0, "请选择扫描序列号");
  214. return;
  215. }
  216. List<string> snList = new List<string>();
  217. dt = (DataTable)dh.ExecuteSql($@"select * from smtbind where sb_maincode = '{SNVal.Text.Trim()}'", "select");
  218. if (dt.Rows.Count > 0)
  219. {
  220. foreach (DataRow dr in dt.Rows)
  221. {
  222. snList.Add(dr["sb_barcode"].ToString());
  223. }
  224. foreach (string str in snList)
  225. {
  226. dt = (DataTable)dh.ExecuteSql($@"SELECT ms_makecode,ms_prodcode,cd_stepcode,cd_stepname,cd_stepno FROM makeserial,craft,craftdetail
  227. WHERE ms_sncode = '{str}' AND ms_prodcode = cr_prodcode AND cr_id = cd_crid AND cd_stepno = 1 ORDER BY cd_stepno", "select");
  228. if (dt.Rows.Count == 0)
  229. {
  230. ShowMsg(0, $"拼板号:{SNVal.Text} 中序列号:{str} 无归属记录,请过投入站后再采集Xray信息");
  231. return;
  232. }
  233. dt = (DataTable)dh.ExecuteSql($@"SELECT mp_linecode FROM makeprocess WHERE mp_sncode = '{str}' AND mp_stepcode = '{dt.Rows[0]["cd_stepcode"]}'", "select");
  234. if (dt.Rows.Count == 0)
  235. {
  236. ShowMsg(0, $"拼板号:{SNVal.Text} 中序列号:{str} 无投入过站记录,请过投入站后再采集Xray信息");
  237. return;
  238. }
  239. for (int i = 0; i <= LineVal.Items.Count; i++)
  240. {
  241. string mplinecode = dt.Rows[0]["mp_linecode"].ToString();
  242. string allLine = LineVal.Items[i].ToString();
  243. if (mplinecode == allLine)
  244. {
  245. LineVal.SelectedIndex = i;
  246. break;
  247. }
  248. }
  249. InsertLog(str, OkBox.Checked ? "OK" : "NG", SNVal.Text.Trim());
  250. }
  251. }
  252. else
  253. {
  254. dt = (DataTable)dh.ExecuteSql($@"SELECT ms_makecode,ms_prodcode,cd_stepcode,cd_stepname,cd_stepno FROM makeserial,craft,craftdetail
  255. WHERE ms_sncode = '{SNVal.Text}' AND ms_prodcode = cr_prodcode AND cr_id = cd_crid AND cd_stepno = 1 ORDER BY cd_stepno", "select");
  256. if (dt.Rows.Count == 0)
  257. {
  258. ShowMsg(0, $"序列号:{SNVal.Text} 无归属记录,请过投入站后再采集Xray信息");
  259. return;
  260. }
  261. dt = (DataTable)dh.ExecuteSql($@"SELECT mp_linecode FROM makeprocess WHERE mp_sncode = '{SNVal.Text}' AND mp_stepcode = '{dt.Rows[0]["cd_stepcode"]}'", "select");
  262. if (dt.Rows.Count == 0)
  263. {
  264. ShowMsg(0, $"序列号:{SNVal.Text} 无投入过站记录,请过投入站后再采集Xray信息");
  265. return;
  266. }
  267. for (int i = 0; i <= LineVal.Items.Count; i++)
  268. {
  269. string mplinecode = dt.Rows[0]["mp_linecode"].ToString();
  270. string allLine = LineVal.Items[i].ToString();
  271. if (mplinecode == allLine)
  272. {
  273. LineVal.SelectedIndex = i;
  274. break;
  275. }
  276. }
  277. InsertLog(SNVal.Text.Trim(), OkBox.Checked ? "OK" : "NG");
  278. }
  279. //if (string.IsNullOrEmpty(LineVal.Text))
  280. //{
  281. // ShowMsg(0, "请选择线体");
  282. // return;
  283. //}
  284. SNVal.Focus();
  285. SNVal.SelectAll();
  286. SNVal.Text = "";
  287. }
  288. }
  289. }