Make_BakingManage.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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_BakingManage : Form
  15. {
  16. public Make_BakingManage()
  17. {
  18. InitializeComponent();
  19. }
  20. StringBuilder SQL = new StringBuilder();
  21. DataHelper dh = SystemInf.dh;
  22. DataTable dt;
  23. DataTable Dbfind;
  24. private void Make_InBaking_Load(object sender, EventArgs e)
  25. {
  26. LoadBaking();
  27. Timer ReLoad = new Timer();
  28. ReLoad.Interval = 10000;
  29. ReLoad.Tick += ReLoadData;
  30. ReLoad.Start();
  31. //设置锁定工单
  32. LockMakeCode.GetMakeCodeCtl(ma_code);
  33. ma_code.SetLockCheckBox(LockMakeCode);
  34. //工单号放大镜配置
  35. ma_code.TableName = "make left join product on ma_prodcode=pr_code";
  36. ma_code.SelectField = "ma_code # 工单号,pr_code # 产品编号,pr_detail # 产品名称";
  37. ma_code.FormName = Name;
  38. ma_code.SetValueField = new string[] { "ma_code", "pr_code", "pr_detail" };
  39. ma_code.Condition = "ma_statuscode='STARTED'";
  40. ma_code.DbChange += Ma_code_DbChange;
  41. }
  42. private void Ma_code_DbChange(object sender, EventArgs e)
  43. {
  44. Dbfind = ma_code.ReturnData;
  45. BaseUtil.SetFormValue(this.Controls, Dbfind);
  46. //获取工单的其他信息
  47. SQL.Clear();
  48. SQL.Append("select ma_code,nvl(mcd_okqty,0) mcd_okqty,ma_prodcode as pr_code ,pr_detail,");
  49. SQL.Append("pr_spec,ma_qty - nvl(mcd_inqty, 0) mcd_remainqty,ma_qty from make left join makecraftdetail on ");
  50. SQL.Append("mcd_maid=ma_id left join product on pr_code=ma_prodcode where ma_code='" + ma_code.Text + "'");
  51. dt = (DataTable)dh.ExecuteSql(SQL.ToString(), "select");
  52. if (dt.Rows.Count > 0)
  53. {
  54. BaseUtil.SetFormValue(this.Controls, dt);
  55. }
  56. EstimateVal.Focus();
  57. EstimateVal.SelectAll();
  58. }
  59. private void ReLoadData(object sender, EventArgs e)
  60. {
  61. LoadBaking();
  62. }
  63. private void ReelNoVal_Leave(object sender, EventArgs e)
  64. {
  65. if (!string.IsNullOrEmpty(ReelNoVal.Text))
  66. {
  67. UpdateMaterial("L", ReelNoVal.Text);
  68. dt = (DataTable)dh.ExecuteSql($"select * from barcode where bar_code = '{ReelNoVal.Text}'", "select");
  69. if (dt.Rows.Count == 0)
  70. {
  71. MessageBox.Show($"条码:{ReelNoVal.Text} 不是MES系统中库存条码");
  72. ReelNoVal.Text = "";
  73. return;
  74. }
  75. }
  76. }
  77. private void ReelNoVal_KeyDown(object sender, KeyEventArgs e)
  78. {
  79. if (e.KeyCode != Keys.Enter) return;
  80. ReelNoVal.Text = ReelNoVal.Text.Trim();
  81. if (!string.IsNullOrEmpty(ReelNoVal.Text))
  82. {
  83. UpdateMaterial("L", ReelNoVal.Text);
  84. dt = (DataTable)dh.ExecuteSql($"select * from barcode where bar_code = '{ReelNoVal.Text}'", "select");
  85. if (dt.Rows.Count == 0)
  86. {
  87. MessageBox.Show($"条码:{ReelNoVal.Text} 不是MES系统中库存条码");
  88. ReelNoVal.Text = "";
  89. return;
  90. }
  91. }
  92. Choose_Click(null, null);
  93. }
  94. private void ReelNoVal1_KeyDown(object sender, KeyEventArgs e)
  95. {
  96. if (e.KeyCode != Keys.Enter) return;
  97. ReelNoVal1.Text = ReelNoVal1.Text.Trim();
  98. if (!string.IsNullOrEmpty(ReelNoVal1.Text))
  99. {
  100. UpdateMaterial("L", ReelNoVal1.Text);
  101. dt = (DataTable)dh.ExecuteSql($"select * from barcode where bar_code = '{ReelNoVal1.Text}'", "select");
  102. if (dt.Rows.Count == 0)
  103. {
  104. MessageBox.Show($"条码:{ReelNoVal1.Text} 不是MES系统中库存条码");
  105. ReelNoVal1.Text = "";
  106. return;
  107. }
  108. }
  109. Choose1_Click(null, null);
  110. }
  111. private void ReelNoVal1_Leave(object sender, EventArgs e)
  112. {
  113. if (!string.IsNullOrEmpty(ReelNoVal1.Text))
  114. {
  115. UpdateMaterial("L", ReelNoVal1.Text);
  116. dt = (DataTable)dh.ExecuteSql($"select * from barcode where bar_code = '{ReelNoVal1.Text}'", "select");
  117. if (dt.Rows.Count == 0)
  118. {
  119. MessageBox.Show($"条码:{ReelNoVal1.Text} 不是MES系统中库存条码");
  120. ReelNoVal1.Text = "";
  121. return;
  122. }
  123. }
  124. }
  125. private void LoadBaking()
  126. {
  127. SQL.Clear();
  128. /*SQL.Append($@"SELECT work_order,box_no,reel_no,in_date,in_name,estimate_time,trunc((sysdate - in_date) * 24) || ':' || lpad(trunc(MOD((sysdate - in_date) * 24 * 60, 60)), 2, '0')
  129. || ':' || lpad(trunc(MOD((sysdate - in_date) * 24 * 60 * 60, 60)),2,'0') baking_time,nvl(baking_qty,0) baking_qty FROM baking_log WHERE status = '烘烤中' ORDER BY in_date DESC");*/
  130. SQL.Append($@"SELECT work_order,box_no,reel_no,in_date,in_name,estimate_time,trunc((sysdate - in_date) * 24)|| ':'|| lpad(trunc(MOD((sysdate - in_date) * 24 * 60, 60)),2,'0')|| ':'
  131. || lpad(trunc(MOD((sysdate - in_date) * 24 * 60 * 60, 60)),2,'0') baking_time,nvl(baking_qty, 0) baking_qty,pr_spec FROM baking_log LEFT JOIN barcode ON reel_no = bar_code
  132. LEFT JOIN product@wp ON bar_prodid = pr_id WHERE status = '烘烤中' ORDER BY in_date DESC");
  133. dt = (DataTable)dh.ExecuteSql(SQL.ToString(), "select");
  134. DataBox.DataSource = dt;
  135. }
  136. private void UpdateMaterial(string type, string reelNo = "")
  137. {
  138. if (type == "C")
  139. {
  140. serialNumber.Text = "";
  141. workOrder.Text = "";
  142. productCode.Text = "";
  143. productName.Text = "";
  144. }
  145. else if (type == "L")
  146. {
  147. dt = (DataTable)dh.ExecuteSql($@"SELECT bar_code,bar_prodcode,pr_detail,pr_spec,bar_batchqty
  148. FROM barcode LEFT JOIN product ON pr_code = bar_prodcode WHERE bar_code = '{reelNo}'", "select");
  149. if (dt.Rows.Count > 0)
  150. {
  151. serialNumber.Text = dt.Rows[0]["bar_code"].ToString();
  152. workOrder.Text = dt.Rows[0]["pr_detail"].ToString();
  153. productCode.Text = dt.Rows[0]["bar_prodcode"].ToString();
  154. productName.Text = dt.Rows[0]["pr_spec"].ToString();
  155. }
  156. else
  157. {
  158. UpdateMaterial("C");
  159. }
  160. }
  161. }
  162. private void BackingVal_KeyDown(object sender, KeyEventArgs e)
  163. {
  164. if (e.KeyCode != Keys.Enter) return;
  165. //BackingVal.Text = BackingVal.Text.Trim();
  166. EstimateVal.Focus();
  167. EstimateVal.SelectAll();
  168. }
  169. private void EstimateVal_KeyDown(object sender, KeyEventArgs e)
  170. {
  171. if (e.KeyCode != Keys.Enter) return;
  172. EstimateVal.Text = EstimateVal.Text.Trim();
  173. ReelNoVal.Focus();
  174. ReelNoVal.SelectAll();
  175. }
  176. private void EmployeeVal_KeyDown(object sender, KeyEventArgs e)
  177. {
  178. if (e.KeyCode != Keys.Enter) return;
  179. if (string.IsNullOrEmpty(EmployeeVal.Text)) return;
  180. /*dt = (DataTable)dh.ExecuteSql($"select * from employee where em_name = '{EmployeeVal.Text.Trim()}'", "select");
  181. if (dt.Rows.Count == 0)
  182. {
  183. MessageBox.Show("请输入正确人员姓名");
  184. EmployeeVal.Text = "";
  185. EmployeeVal.Focus();
  186. EmployeeVal.SelectAll();
  187. return;
  188. }*/
  189. }
  190. private void EmployeeVal_Leave(object sender, EventArgs e)
  191. {
  192. if (string.IsNullOrEmpty(EmployeeVal.Text)) return;
  193. /*dt = (DataTable)dh.ExecuteSql($"select * from employee where em_name = '{EmployeeVal.Text.Trim()}'", "select");
  194. if (dt.Rows.Count == 0)
  195. {
  196. MessageBox.Show("请输入正确人员姓名");
  197. EmployeeVal.Text = "";
  198. EmployeeVal.Focus();
  199. EmployeeVal.SelectAll();
  200. return;
  201. }*/
  202. }
  203. private void EmployeeVal1_KeyDown(object sender, KeyEventArgs e)
  204. {
  205. if (e.KeyCode != Keys.Enter) return;
  206. if (string.IsNullOrEmpty(EmployeeVal1.Text)) return;
  207. /*dt = (DataTable)dh.ExecuteSql($"select * from employee where em_name = '{EmployeeVal1.Text.Trim()}'", "select");
  208. if (dt.Rows.Count == 0)
  209. {
  210. MessageBox.Show("请输入正确人员姓名");
  211. EmployeeVal1.Text = "";
  212. EmployeeVal1.Focus();
  213. EmployeeVal1.SelectAll();
  214. return;
  215. }*/
  216. }
  217. private void EmployeeVal1_Leave(object sender, EventArgs e)
  218. {
  219. if (string.IsNullOrEmpty(EmployeeVal1.Text)) return;
  220. /*dt = (DataTable)dh.ExecuteSql($"select * from employee where em_name = '{EmployeeVal1.Text.Trim()}'", "select");
  221. if (dt.Rows.Count == 0)
  222. {
  223. MessageBox.Show("请输入正确人员姓名");
  224. EmployeeVal1.Text = "";
  225. EmployeeVal1.Focus();
  226. EmployeeVal1.SelectAll();
  227. return;
  228. }*/
  229. }
  230. private void Choose_Click(object sender, EventArgs e)
  231. {
  232. if (string.IsNullOrEmpty(ma_code.Text))
  233. {
  234. MessageBox.Show("请选择归属工单");
  235. return;
  236. }
  237. if (string.IsNullOrEmpty(EmployeeVal.Text))
  238. {
  239. MessageBox.Show("请输入烘烤操作员姓名");
  240. return;
  241. }
  242. //if (string.IsNullOrEmpty(BackingVal.Text))
  243. //{
  244. // MessageBox.Show("请扫描烘烤箱号");
  245. // return;
  246. //}
  247. if (string.IsNullOrEmpty(EstimateVal.Text))
  248. {
  249. MessageBox.Show("请填写扫描时长");
  250. return;
  251. }
  252. if (string.IsNullOrEmpty(ReelNoVal.Text))
  253. {
  254. MessageBox.Show("请扫描入烘烤物料条码");
  255. return;
  256. }
  257. dt = (DataTable)dh.ExecuteSql($@"SELECT * FROM baking_log WHERE status = '烘烤中' AND reel_no = '{ReelNoVal.Text}'", "select");
  258. if (dt.Rows.Count > 0)
  259. {
  260. MessageBox.Show($"条码号:{ReelNoVal.Text} 已在烘烤箱中");
  261. return;
  262. }
  263. dt = (DataTable)dh.ExecuteSql($"select * from barcode where bar_code = '{ReelNoVal.Text}'", "select");
  264. string baking_qty = dt.Rows[0]["BAR_REMAIN"].ToString();
  265. dh.ExecuteSql($@"INSERT INTO baking_log (baking_id,box_no,reel_no,status,in_date,in_name,estimate_time,work_order,baking_qty)
  266. SELECT baking_log_seq.NEXTVAL,'', '{ReelNoVal.Text}', '烘烤中',sysdate,'{EmployeeVal.Text.Trim()}','{EstimateVal.Text}','{ma_code.Text}',{baking_qty} FROM dual", "insert");
  267. //EmployeeVal.Text = "";
  268. //BackingVal.Text = "";
  269. //EstimateVal.Text = "";
  270. ReelNoVal.Text = "";
  271. //UpdateMaterial("C");
  272. LoadBaking();
  273. MessageBox.Show($"条码号:{ReelNoVal.Text} 入烘烤箱成功");
  274. }
  275. private void Choose1_Click(object sender, EventArgs e)
  276. {
  277. if (string.IsNullOrEmpty(EmployeeVal1.Text))
  278. {
  279. MessageBox.Show("请输入烘烤操作员姓名");
  280. return;
  281. }
  282. if (string.IsNullOrEmpty(ReelNoVal1.Text))
  283. {
  284. MessageBox.Show("请扫描入烘烤物料条码");
  285. return;
  286. }
  287. dt = (DataTable)dh.ExecuteSql($@"SELECT * FROM baking_log WHERE status = '烘烤中' AND reel_no = '{ReelNoVal1.Text.Trim()}'", "select");
  288. if (dt.Rows.Count == 0)
  289. {
  290. MessageBox.Show($"条码号:{ReelNoVal1.Text} 不在烘烤箱中,请重试");
  291. ReelNoVal1.Focus();
  292. ReelNoVal1.SelectAll();
  293. return;
  294. }
  295. dh.ExecuteSql($@"UPDATE baking_log SET status = '已烘烤',out_date = sysdate,baking_time = trunc((sysdate - in_date) * 24) || ':' || lpad(trunc(MOD((sysdate - in_date) * 24 * 60, 60)),2,'0') || ':' || lpad(trunc(MOD((sysdate - in_date) * 24 * 60 * 60, 60)),2,'0'),out_name = '{EmployeeVal1.Text.Trim()}' WHERE status = '烘烤中' and reel_no = '{ReelNoVal1.Text.Trim()}'", "insert");
  296. //EmployeeVal1.Text = "";
  297. ReelNoVal1.Text = "";
  298. //UpdateMaterial("C");
  299. LoadBaking();
  300. MessageBox.Show($"条码号:{ReelNoVal1.Text} 出烘烤箱成功");
  301. }
  302. }
  303. }