Make_HandFeedRegistration.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. using DevComponents.DotNetBar.Controls;
  2. using NPOI.SS.Formula.Eval;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Data.SqlClient;
  8. using System.Drawing;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows.Forms;
  14. using UAS_MES_NEW.DataOperate;
  15. using UAS_MES_NEW.Entity;
  16. namespace UAS_MES_NEW.Make
  17. {
  18. public partial class Make_HandFeedRegistration : Form
  19. {
  20. public Make_HandFeedRegistration()
  21. {
  22. InitializeComponent();
  23. }
  24. StringBuilder SQL = new StringBuilder();
  25. DataTable dt;
  26. DataHelper dh;
  27. int checkedCount = 0;
  28. private void Make_HandFeedRegistration_Load(object sender, EventArgs e)
  29. {
  30. dh = SystemInf.dh;
  31. snVal.Focus();
  32. snVal.SelectAll();
  33. submit.Enabled = false;
  34. handCount.Text = $"补料数量: {checkedCount}";
  35. }
  36. private void snVal_KeyDown(object sender, KeyEventArgs e)
  37. {
  38. if (e.KeyCode != Keys.Enter) return;
  39. snVal.Text = snVal.Text.Replace(";", ";").Trim();
  40. SQL.Clear();
  41. //SQL.Append($@"SELECT * FROM (SELECT ms_makecode,ms_prodcode,ps_linecode,ps_processcode,
  42. // ps_table,ROW_NUMBER() OVER(PARTITION BY ps_processcode ORDER BY ps_auditdate DESC) AS rn
  43. // FROM makeserial a,productsmt b WHERE a.ms_sncode = '{snVal.Text}' AND a.ms_prodcode = b.ps_prodcode
  44. // AND instr(ps_linecode, a.ms_linecode) > 0) WHERE rn = 1 ORDER BY ps_processcode");
  45. SQL.Append($@"SELECT ps_processcode FROM makeserial a,productsmt b
  46. WHERE a.ms_sncode = '{snVal.Text}' AND a.ms_prodcode = b.ps_prodcode");
  47. dt = (DataTable)dh.ExecuteSql(SQL.ToString(), "select");
  48. if (dt.Rows.Count > 0)
  49. {
  50. machineVal.Items.Clear();
  51. foreach (DataRow dr in dt.Rows)
  52. {
  53. machineVal.Items.Add(dr["ps_processcode"].ToString());
  54. }
  55. machineVal.SelectedIndex = 0;
  56. machineVal.SelectAll();
  57. UpdateSN("L", snVal.Text);
  58. query_Click(null, null);
  59. }
  60. else
  61. {
  62. UpdateSN("C");
  63. machineVal.Items.Clear();
  64. machineVal.SelectedIndex = -1;
  65. snVal.Focus();
  66. snVal.SelectAll();
  67. MessageBox.Show("该序列号没有对应机台", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  68. }
  69. }
  70. private void query_Click(object sender, EventArgs e)
  71. {
  72. if (string.IsNullOrEmpty(snVal.Text))
  73. {
  74. MessageBox.Show("请扫描序列号", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  75. snVal.Focus();
  76. snVal.SelectAll();
  77. return;
  78. }
  79. if (string.IsNullOrEmpty(machineVal.Text))
  80. {
  81. MessageBox.Show("请选择机台名称", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  82. machineVal.SelectAll();
  83. return;
  84. }
  85. SQL.Clear();
  86. SQL.Append($@"SELECT rownum rn,ms_sncode,ps_linecode,
  87. ps_processcode,ps_table,psl_location,psl_bomlocation,psl_prodcode,psl_baseqty
  88. FROM makeserial a,productsmt b,productsmtlocation c
  89. WHERE a.ms_sncode = '{snVal.Text}' AND b.ps_processcode = '{machineVal.Text}'
  90. AND a.ms_prodcode = b.ps_prodcode AND b.ps_id = c.psl_psid ORDER BY psl_detno");
  91. dt = (DataTable)dh.ExecuteSql(SQL.ToString(), "select");
  92. if (dt.Rows.Count > 0)
  93. {
  94. dgv.DataSource = dt;
  95. checkedCount = 0;
  96. handCount.Text = $"补料数量: {checkedCount}";
  97. submit.Enabled = true;
  98. }
  99. }
  100. private void dgv_CellClick(object sender, DataGridViewCellEventArgs e)
  101. {
  102. if (e.RowIndex < 0 || e.ColumnIndex < 0) return;
  103. var column = dgv.Columns[e.ColumnIndex];
  104. if (column is DataGridViewCheckBoxColumn)
  105. {
  106. var cell = dgv[e.ColumnIndex, e.RowIndex] as DataGridViewCheckBoxCell;
  107. if (cell != null && !cell.ReadOnly)
  108. {
  109. bool currentValue = false;
  110. if (cell.Value != null && cell.Value != DBNull.Value)
  111. {
  112. currentValue = Convert.ToBoolean(cell.Value);
  113. }
  114. cell.Value = !currentValue;
  115. dgv.CommitEdit(DataGridViewDataErrorContexts.Commit);
  116. dgv.EndEdit();
  117. var row = dgv.Rows[e.RowIndex];
  118. if (currentValue)
  119. {
  120. row.DefaultCellStyle.BackColor = dgv.DefaultCellStyle.BackColor;
  121. row.DefaultCellStyle.ForeColor = dgv.DefaultCellStyle.ForeColor;
  122. checkedCount--;
  123. }
  124. else
  125. {
  126. row.DefaultCellStyle.BackColor = Color.LightSkyBlue;
  127. row.DefaultCellStyle.ForeColor = Color.Black;
  128. checkedCount++;
  129. }
  130. handCount.Text = $"补料数量: {checkedCount}";
  131. if (checkedCount > 0)
  132. {
  133. submit.Enabled = true;
  134. }
  135. else
  136. {
  137. submit.Enabled = false;
  138. }
  139. }
  140. }
  141. }
  142. private void submit_Click(object sender, EventArgs e)
  143. {
  144. if (checkedCount == 0)
  145. {
  146. MessageBox.Show("请勾选所补物料对应站位信息", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  147. return;
  148. }
  149. DataTable upLoadDatas = new DataTable();
  150. upLoadDatas.Columns.Add(new DataColumn("rn"));
  151. upLoadDatas.Columns.Add(new DataColumn("ms_sncode"));
  152. upLoadDatas.Columns.Add(new DataColumn("ps_linecode"));
  153. upLoadDatas.Columns.Add(new DataColumn("ps_processcode"));
  154. upLoadDatas.Columns.Add(new DataColumn("ps_table"));
  155. upLoadDatas.Columns.Add(new DataColumn("psl_location"));
  156. upLoadDatas.Columns.Add(new DataColumn("psl_bomlocation"));
  157. upLoadDatas.Columns.Add(new DataColumn("psl_prodcode"));
  158. upLoadDatas.Columns.Add(new DataColumn("psl_baseqty"));
  159. foreach (DataGridViewRow item in dgv.Rows)
  160. {
  161. var checkCell = item.Cells["isHandReel"] as DataGridViewCheckBoxCell;
  162. if (Convert.ToBoolean(checkCell.Value))
  163. {
  164. upLoadDatas.Rows.Add(item.Cells["rn"].Value, item.Cells["ms_sncode"].Value, item.Cells["ps_linecode"].Value,
  165. item.Cells["ps_processcode"].Value, item.Cells["ps_table"].Value, item.Cells["psl_location"].Value,
  166. item.Cells["psl_bomlocation"].Value, item.Cells["psl_prodcode"].Value, item.Cells["psl_baseqty"].Value);
  167. }
  168. }
  169. dgv.DataSource = upLoadDatas;
  170. foreach (DataGridViewRow rw in dgv.Rows)
  171. {
  172. var checkCell = rw.Cells["isHandReel"] as DataGridViewCheckBoxCell;
  173. checkCell.Value = true;
  174. try
  175. {
  176. SQL.Clear();
  177. SQL.Append($@"INSERT INTO smt_handreel_log (serial_number,line_name,machine_name,side,
  178. position,reel_position, part_no, reel_qty,
  179. update_time, update_name) VALUES
  180. ( '{rw.Cells["ms_sncode"].Value}','{rw.Cells["ps_linecode"].Value}','{rw.Cells["ps_processcode"].Value}','{rw.Cells["ps_table"].Value}',
  181. '{rw.Cells["psl_location"].Value}','{rw.Cells["psl_bomlocation"].Value}','{rw.Cells["psl_prodcode"].Value}','{rw.Cells["psl_baseqty"].Value}',
  182. sysdate,'{User.UserName}' )");
  183. dh.ExecuteSql(SQL.ToString(), "insert");
  184. }
  185. catch (Exception ex)
  186. {
  187. MessageBox.Show($"提交手补料异常{ex.Message}", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  188. return;
  189. }
  190. }
  191. MessageBox.Show("已提交手补料记录", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  192. submit.Enabled = false;
  193. }
  194. private void UpdateSN(string type, string sn = "")
  195. {
  196. if (type == "C")
  197. {
  198. serialNumber.Text = "";
  199. workOrder.Text = "";
  200. productCode.Text = "";
  201. productName.Text = "";
  202. }
  203. else if (type == "L")
  204. {
  205. SQL.Clear();
  206. SQL.Append($@"SELECT ms_sncode,ma_code,pr_code,pr_spec FROM makeserial,make,product
  207. WHERE ms_sncode = '{sn}' AND ms_makecode = ma_code AND ms_prodcode = pr_code");
  208. dt = (DataTable)dh.ExecuteSql(SQL.ToString(), "select");
  209. if (dt.Rows.Count > 0)
  210. {
  211. serialNumber.Text = dt.Rows[0]["ms_sncode"].ToString();
  212. workOrder.Text = dt.Rows[0]["ma_code"].ToString();
  213. productCode.Text = dt.Rows[0]["pr_code"].ToString();
  214. productName.Text = dt.Rows[0]["pr_spec"].ToString();
  215. }
  216. else
  217. {
  218. UpdateSN("C", sn);
  219. }
  220. }
  221. }
  222. }
  223. }