Make_BurnInfo.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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. using UAS_MES_NEW.PublicMethod;
  12. namespace UAS_MES_NEW.Make
  13. {
  14. public partial class Make_BurnInfo : Form
  15. {
  16. public Make_BurnInfo()
  17. {
  18. InitializeComponent();
  19. }
  20. LogStringBuilder sql = new LogStringBuilder();
  21. DataTable Dbfind;
  22. DataHelper dh;
  23. DataTable dt;
  24. string remainQty;
  25. DateTime callTime = DateTime.Now;
  26. private void Make_BurnInfo_Load(object sender, EventArgs e)
  27. {
  28. //设置锁定工单
  29. LockMakeCode.GetMakeCodeCtl(ma_code);
  30. ma_code.SetLockCheckBox(LockMakeCode);
  31. //工单号放大镜配置
  32. ma_code.TableName = "make left join product on ma_prodcode=pr_code";
  33. ma_code.SelectField = "ma_code # 工单号,pr_code # 产品编号,pr_detail # 产品名称";
  34. ma_code.FormName = Name;
  35. ma_code.SetValueField = new string[] { "ma_code", "pr_code", "pr_detail" };
  36. ma_code.Condition = "ma_statuscode='STARTED'";
  37. ma_code.DbChange += Ma_code_DbChange;
  38. dh = SystemInf.dh;
  39. dt = (DataTable)dh.ExecuteSql("SELECT * FROM line WHERE li_wcname = 'SMT' ORDER BY li_auditdate", "select");
  40. if (dt.Rows.Count > 0)
  41. {
  42. foreach (DataRow item in dt.Rows)
  43. {
  44. LineVal.Items.Add(item["li_code"].ToString());
  45. }
  46. }
  47. }
  48. private void Ma_code_DbChange(object sender, EventArgs e)
  49. {
  50. Dbfind = ma_code.ReturnData;
  51. BaseUtil.SetFormValue(this.Controls, Dbfind);
  52. //获取工单的其他信息
  53. sql.Clear();
  54. sql.Append("select ma_code,nvl(mcd_okqty,0) mcd_okqty,ma_prodcode as pr_code ,pr_detail,");
  55. sql.Append("pr_spec,ma_qty - nvl(mcd_inqty, 0) mcd_remainqty,ma_qty from make left join makecraftdetail on ");
  56. sql.Append("mcd_maid=ma_id left join product on pr_code=ma_prodcode where ma_code='" + ma_code.Text + "'");
  57. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  58. if (dt.Rows.Count > 0)
  59. {
  60. BaseUtil.SetFormValue(this.Controls, dt);
  61. }
  62. if ((DateTime.Now - callTime).TotalSeconds > 10)
  63. {
  64. callTime = DateTime.Now;
  65. dt = (DataTable)dh.ExecuteSql($"SELECT BURN_LOTNO,WORK_ORDER,LINE,BURN_SOFTWARE,CHECK_CODE,DOT_DETAIL,UPDATE_TIME,UPDATE_NAME,BURN_QTY,inspect_res,IC_DETAIL,burn_id,remark FROM burn_info LEFT JOIN burn_inspect ON burn_id = burnid WHERE work_order = '{ma_code.Text}'", "select");
  66. DataBox.DataSource = dt;
  67. ShowMsg(1, $"工单: {ma_code.Text} 已找到{dt.Rows.Count}条烧录记录");
  68. dt = (DataTable)dh.ExecuteSql($"select nvl(sum(burn_qty),0) allqty from burn_info where work_order = '{ma_code.Text}'", "select");
  69. if (dt.Rows.Count > 0)
  70. {
  71. CurrQtyVal.Text = dt.Rows[0]["allqty"].ToString();
  72. }
  73. if (BaseUtil.GetCacheData("BurnInfoWo").ToString() == ma_code.Text.Trim())
  74. {
  75. BurnSwVal.Text = BaseUtil.GetCacheData("BurnInfo_BurnSwVal").ToString();
  76. CheckCodeVal.Text = BaseUtil.GetCacheData("BurnInfo_CheckCodeVal").ToString();
  77. DotVal.Text = BaseUtil.GetCacheData("BurnInfo_DotVal").ToString();
  78. IcDetailVal.Text = BaseUtil.GetCacheData("BurnInfo_IcDetailVal").ToString();
  79. }
  80. }
  81. if (!string.IsNullOrEmpty(ma_code.Text)) SaveCache.Enabled = true;
  82. else SaveCache.Enabled = false;
  83. }
  84. private void Confirm_Click(object sender, EventArgs e)
  85. {
  86. if (string.IsNullOrEmpty(ma_code.Text))
  87. {
  88. ShowMsg(0, "请选择归属工单");
  89. ma_code.Focus();
  90. return;
  91. }
  92. /*if (string.IsNullOrEmpty(LineVal.Text))
  93. {
  94. ShowMsg(0, "请选择线体");
  95. LineVal.Focus();
  96. LineVal.SelectAll();
  97. return;
  98. }*/
  99. if (string.IsNullOrEmpty(BurnLotnoVal.Text))
  100. {
  101. ShowMsg(0, "请扫描包批次号");
  102. BurnLotnoVal.Focus();
  103. BurnLotnoVal.SelectAll();
  104. return;
  105. }
  106. dt = (DataTable)dh.ExecuteSql($@"select * from burn_info where burn_lotno = '{BurnLotnoVal.Text}'", "select");
  107. if (dt.Rows.Count > 0)
  108. {
  109. ShowMsg(0, $"批号 {BurnLotnoVal.Text}已记录,请勿重复使用");
  110. return;
  111. }
  112. dh.ExecuteSql($@"insert INTO burn_info (burn_id,burn_lotno,burn_software,
  113. check_code,dot_detail,line,burn_qty,
  114. update_name,update_time,work_order) VALUES (BURN_INFO_SEQ.nextval,'{BurnLotnoVal.Text.Trim()}','{BurnSwVal.Text.Trim()}',
  115. '{CheckCodeVal.Text.Trim()}','{DotVal.Text.Trim()}','{LineVal.Text.Trim()}','{remainQty}',
  116. '{User.UserName}',sysdate,'{ma_code.Text.Trim()}')", "insert");
  117. BurnLotnoVal.Focus();
  118. BurnLotnoVal.SelectAll();
  119. BurnSwVal.Text = "";
  120. CheckCodeVal.Text = "";
  121. DotVal.Text = "";
  122. ShowMsg(1, "添加烧录信息成功");
  123. dt = (DataTable)dh.ExecuteSql($"SELECT BURN_LOTNO,WORK_ORDER,LINE,BURN_SOFTWARE,CHECK_CODE,DOT_DETAIL,UPDATE_TIME,UPDATE_NAME,BURN_QTY,inspect_res,IC_DETAIL,burn_id,remark FROM burn_info LEFT JOIN burn_inspect ON burn_id = burnid WHERE work_order = '{ma_code.Text}'", "select");
  124. DataBox.DataSource = dt;
  125. dt = (DataTable)dh.ExecuteSql($"select nvl(sum(burn_qty),0) allqty from burn_info where work_order = '{ma_code.Text}'", "select");
  126. if (dt.Rows.Count > 0)
  127. {
  128. CurrQtyVal.Text = dt.Rows[0]["allqty"].ToString();
  129. }
  130. }
  131. private void ShowMsg(int type, string msg)
  132. {
  133. string fullDateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  134. if (type == 0)
  135. {
  136. OperateResult.AppendText($"{fullDateTime}: {msg}\n", Color.Red);
  137. }
  138. else if (type == 1)
  139. {
  140. OperateResult.AppendText($"{fullDateTime}: {msg}\n", Color.Green);
  141. }
  142. }
  143. private void BurnLotnoVal_KeyDown(object sender, KeyEventArgs e)
  144. {
  145. if (e.KeyCode != Keys.Enter) return;
  146. BurnLotnoVal.Text = BurnLotnoVal.Text.Trim();
  147. if (!string.IsNullOrEmpty(BurnLotnoVal.Text))
  148. {
  149. dt = (DataTable)dh.ExecuteSql($"select * from barcode where bar_code = '{BurnLotnoVal.Text}'", "select");
  150. if (dt.Rows.Count == 0)
  151. {
  152. ShowMsg(0, $"条码:{BurnLotnoVal.Text} 不是MES系统中库存条码");
  153. BurnLotnoVal.Text = "";
  154. return;
  155. }
  156. remainQty = dt.Rows[0]["BAR_REMAIN"].ToString();
  157. }
  158. if (string.IsNullOrEmpty(ma_code.Text))
  159. {
  160. ShowMsg(0, "请选择归属工单");
  161. ma_code.Focus();
  162. return;
  163. }
  164. if(Convert.ToInt32(CurrQtyVal.Text) > Convert.ToInt32(ma_qty.Text))
  165. {
  166. ShowMsg(0, "烧录数量已达标,超过工单批量");
  167. ma_code.Focus();
  168. return;
  169. }
  170. if (string.IsNullOrEmpty(EmployeeVal.Text))
  171. {
  172. ShowMsg(0, "请输入操作人员");
  173. ma_code.Focus();
  174. return;
  175. }
  176. /*if (string.IsNullOrEmpty(LineVal.Text))
  177. {
  178. ShowMsg(0, "请选择线体");
  179. LineVal.Focus();
  180. LineVal.SelectAll();
  181. return;
  182. }*/
  183. if (string.IsNullOrEmpty(BurnLotnoVal.Text))
  184. {
  185. ShowMsg(0, "请扫描包批次号");
  186. BurnLotnoVal.Focus();
  187. BurnLotnoVal.SelectAll();
  188. return;
  189. }
  190. dt = (DataTable)dh.ExecuteSql($@"select * from burn_info where burn_lotno = '{BurnLotnoVal.Text}'", "select");
  191. if (dt.Rows.Count > 0)
  192. {
  193. ShowMsg(0, $"批号:{BurnLotnoVal.Text} 已记录,请勿重复使用");
  194. return;
  195. }
  196. dh.ExecuteSql($@"insert INTO burn_info (burn_id,burn_lotno,burn_software,
  197. check_code,dot_detail,line,burn_qty,
  198. update_name,update_time,work_order,ic_detail,remark) VALUES (BURN_INFO_SEQ.nextval,'{BurnLotnoVal.Text.Trim()}','{BurnSwVal.Text.Trim()}',
  199. '{CheckCodeVal.Text.Trim()}','{DotVal.Text.Trim()}','{LineVal.Text.Trim()}','{remainQty}',
  200. '{EmployeeVal.Text}',sysdate,'{ma_code.Text.Trim()}','{IcDetailVal.Text.Trim()}','{RemarkVal.Text.Trim()}')", "insert");
  201. BurnLotnoVal.Focus();
  202. BurnLotnoVal.SelectAll();
  203. BurnLotnoVal.Text = "";
  204. /*BurnSwVal.Text = "";
  205. CheckCodeVal.Text = "";
  206. DotVal.Text = "";*/
  207. ShowMsg(1, $"批号:{BurnLotnoVal.Text} 添加烧录信息成功");
  208. dt = (DataTable)dh.ExecuteSql($"SELECT BURN_LOTNO,WORK_ORDER,LINE,BURN_SOFTWARE,CHECK_CODE,DOT_DETAIL,UPDATE_TIME,UPDATE_NAME,BURN_QTY,inspect_res,IC_DETAIL,burn_id,remark FROM burn_info LEFT JOIN burn_inspect ON burn_id = burnid WHERE work_order = '{ma_code.Text}'", "select");
  209. DataBox.DataSource = dt;
  210. dt = (DataTable)dh.ExecuteSql($"select nvl(sum(burn_qty),0) allqty from burn_info where work_order = '{ma_code.Text}'", "select");
  211. if (dt.Rows.Count > 0)
  212. {
  213. CurrQtyVal.Text = dt.Rows[0]["allqty"].ToString();
  214. }
  215. }
  216. private void DeleteLog_Click(object sender, EventArgs e)
  217. {
  218. if (DataBox.SelectedRows.Count == 0)
  219. {
  220. ShowMsg(0, "请在列表选中需删除记录");
  221. return;
  222. }
  223. string burn_id = DataBox.SelectedRows[0].Cells["burn_id"].Value?.ToString();
  224. string burn_lotno = DataBox.SelectedRows[0].Cells["BURN_LOTNO"].Value?.ToString();
  225. DialogResult res = MessageBox.Show($"确认删除烧录条码:{burn_lotno}","Warning",MessageBoxButtons.YesNo,MessageBoxIcon.Warning);
  226. if(res == DialogResult.Yes)
  227. {
  228. dh.ExecuteSql($"delete burn_info where burn_id = '{burn_id}'", "delete");
  229. dt = (DataTable)dh.ExecuteSql($"SELECT BURN_LOTNO,WORK_ORDER,LINE,BURN_SOFTWARE,CHECK_CODE,DOT_DETAIL,UPDATE_TIME,UPDATE_NAME,BURN_QTY,inspect_res,IC_DETAIL,burn_id FROM burn_info LEFT JOIN burn_inspect ON burn_id = burnid WHERE work_order = '{ma_code.Text}'", "select");
  230. DataBox.DataSource = dt;
  231. }
  232. }
  233. private void DataBox_SelectionChanged(object sender, EventArgs e)
  234. {
  235. if (DataBox.SelectedRows.Count > 0)
  236. {
  237. DeleteLog.Enabled = true;
  238. }
  239. else
  240. {
  241. DeleteLog.Enabled = false;
  242. }
  243. }
  244. private void SaveCache_Click(object sender, EventArgs e)
  245. {
  246. BaseUtil.SetCacheData("BurnInfoWo", ma_code.Text.Trim());
  247. BaseUtil.SetCacheData("BurnInfo_BurnSwVal", BurnSwVal.Text.Trim());
  248. BaseUtil.SetCacheData("BurnInfo_CheckCodeVal", CheckCodeVal.Text.Trim());
  249. BaseUtil.SetCacheData("BurnInfo_DotVal", DotVal.Text.Trim());
  250. BaseUtil.SetCacheData("BurnInfo_IcDetailVal", IcDetailVal.Text.Trim());
  251. ShowMsg(1, $"已缓存工单: {ma_code.Text.Trim()} 输入信息");
  252. }
  253. private void BurnSwVal_KeyDown(object sender, KeyEventArgs e)
  254. {
  255. if (e.KeyCode != Keys.Enter) return;
  256. CheckCodeVal.Focus();
  257. CheckCodeVal.SelectAll();
  258. }
  259. private void CheckCodeVal_KeyDown(object sender, KeyEventArgs e)
  260. {
  261. if (e.KeyCode != Keys.Enter) return;
  262. DotVal.Focus();
  263. DotVal.SelectAll();
  264. }
  265. private void DotVal_KeyDown(object sender, KeyEventArgs e)
  266. {
  267. if (e.KeyCode != Keys.Enter) return;
  268. Confirm.Focus();
  269. }
  270. private void ClearMsg_Click(object sender, EventArgs e)
  271. {
  272. OperateResult.Clear();
  273. }
  274. }
  275. }