Make_HandFeedRegistration.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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. dt = (DataTable)dh.ExecuteSql($@"SELECT ms_sncode, ps_linecode FROM makeserial a,productsmt b WHERE
  42. a.ms_sncode = '{snVal.Text}' AND a.ms_prodcode = b.ps_prodcode", "select");
  43. if (dt.Rows.Count > 0)
  44. {
  45. lineVal.Items.Clear();
  46. lineVal.Items.AddRange(dt.AsEnumerable().Select(r => r.Field<string>("ps_linecode")).ToArray());
  47. lineVal.SelectedIndex = 0;
  48. lineVal.SelectAll();
  49. UpdateSN("L", snVal.Text);
  50. query_Click(null, null);
  51. }
  52. else
  53. {
  54. UpdateSN("C");
  55. lineVal.Items.Clear();
  56. lineVal.SelectedIndex = -1;
  57. snVal.Focus();
  58. snVal.SelectAll();
  59. MessageBox.Show("该序列号未找到生产线体信息", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  60. }
  61. }
  62. private void query_Click(object sender, EventArgs e)
  63. {
  64. if (string.IsNullOrEmpty(snVal.Text))
  65. {
  66. MessageBox.Show("请扫描序列号", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  67. snVal.Focus();
  68. snVal.SelectAll();
  69. return;
  70. }
  71. if (string.IsNullOrEmpty(lineVal.Text))
  72. {
  73. MessageBox.Show("请选择生产线体", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  74. lineVal.SelectAll();
  75. return;
  76. }
  77. SQL.Clear();
  78. SQL.Append($@"SELECT rownum rn,ms_sncode,ps_linecode,
  79. ps_processcode,ps_table,psl_location,psl_devlocation,psl_prodcode,psl_baseqty, '' ReelRemark, '' ReelNum,pr_detail
  80. FROM makeserial a,productsmt b,productsmtlocation c,product d
  81. WHERE a.ms_sncode = '{snVal.Text}' AND a.ms_prodcode = b.ps_prodcode AND b.ps_linecode = '{lineVal.Text}' AND b.ps_id = c.psl_psid AND c.psl_prodcode = d.pr_code ORDER BY psl_detno");
  82. dt = (DataTable)dh.ExecuteSql(SQL.ToString(), "select");
  83. if (dt.Rows.Count > 0)
  84. {
  85. dgv.DataSource = dt;
  86. checkedCount = 0;
  87. handCount.Text = $"补料数量: {checkedCount}";
  88. submit.Enabled = true;
  89. }
  90. }
  91. private void dgv_CellClick(object sender, DataGridViewCellEventArgs e)
  92. {
  93. if (e.RowIndex < 0 || e.ColumnIndex < 0) return;
  94. var column = dgv.Columns[e.ColumnIndex];
  95. if (column is DataGridViewCheckBoxColumn)
  96. {
  97. var cell = dgv[e.ColumnIndex, e.RowIndex] as DataGridViewCheckBoxCell;
  98. if (cell != null && !cell.ReadOnly)
  99. {
  100. bool currentValue = false;
  101. if (cell.Value != null && cell.Value != DBNull.Value)
  102. {
  103. currentValue = Convert.ToBoolean(cell.Value);
  104. }
  105. cell.Value = !currentValue;
  106. dgv.CommitEdit(DataGridViewDataErrorContexts.Commit);
  107. dgv.EndEdit();
  108. var row = dgv.Rows[e.RowIndex];
  109. if (currentValue)
  110. {
  111. row.DefaultCellStyle.BackColor = dgv.DefaultCellStyle.BackColor;
  112. row.DefaultCellStyle.ForeColor = dgv.DefaultCellStyle.ForeColor;
  113. checkedCount--;
  114. }
  115. else
  116. {
  117. row.DefaultCellStyle.BackColor = Color.LightSkyBlue;
  118. row.DefaultCellStyle.ForeColor = Color.Black;
  119. checkedCount++;
  120. }
  121. handCount.Text = $"补料数量: {checkedCount}";
  122. if (checkedCount > 0)
  123. {
  124. submit.Enabled = true;
  125. }
  126. else
  127. {
  128. submit.Enabled = false;
  129. }
  130. }
  131. }
  132. }
  133. private void submit_Click(object sender, EventArgs e)
  134. {
  135. if (checkedCount == 0)
  136. {
  137. MessageBox.Show("请勾选所补物料对应站位信息", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  138. return;
  139. }
  140. DataTable upLoadDatas = new DataTable();
  141. upLoadDatas.Columns.Add(new DataColumn("rn"));
  142. upLoadDatas.Columns.Add(new DataColumn("ms_sncode"));
  143. upLoadDatas.Columns.Add(new DataColumn("ps_linecode"));
  144. upLoadDatas.Columns.Add(new DataColumn("ps_processcode"));
  145. upLoadDatas.Columns.Add(new DataColumn("ps_table"));
  146. upLoadDatas.Columns.Add(new DataColumn("psl_location"));
  147. upLoadDatas.Columns.Add(new DataColumn("psl_devlocation"));
  148. upLoadDatas.Columns.Add(new DataColumn("psl_prodcode"));
  149. upLoadDatas.Columns.Add(new DataColumn("psl_baseqty"));
  150. upLoadDatas.Columns.Add(new DataColumn("ReelRemark"));
  151. upLoadDatas.Columns.Add(new DataColumn("ReelNum"));
  152. bool flag = false;
  153. foreach (DataGridViewRow item in dgv.Rows)
  154. {
  155. var checkCell = item.Cells["isHandReel"] as DataGridViewCheckBoxCell;
  156. if (Convert.ToBoolean(checkCell.Value))
  157. {
  158. string remark = string.IsNullOrEmpty(item.Cells["ReelRemark"].Value.ToString()) ? "" : item.Cells["ReelRemark"].Value.ToString().ToUpper();
  159. if (!string.IsNullOrEmpty(remark))
  160. {
  161. string[] positonArr = item.Cells["psl_devlocation"].Value.ToString().Split(',');
  162. foreach(string str in positonArr)
  163. {
  164. if (remark.Contains(str.Trim()))
  165. {
  166. flag = true;
  167. }
  168. }
  169. if (!flag)
  170. {
  171. MessageBox.Show("请填写对应补料元件位置", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  172. return;
  173. }
  174. }
  175. int num = string.IsNullOrEmpty(item.Cells["ReelNum"].Value.ToString()) ? 1 : Convert.ToInt32(item.Cells["ReelNum"].Value);
  176. if (num > Convert.ToInt32(item.Cells["psl_baseqty"].Value.ToString()))
  177. {
  178. MessageBox.Show("补料数量不得大于单位用量", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  179. return;
  180. }
  181. upLoadDatas.Rows.Add(item.Cells["rn"].Value, item.Cells["ms_sncode"].Value, item.Cells["ps_linecode"].Value,
  182. item.Cells["ps_processcode"].Value, item.Cells["ps_table"].Value, item.Cells["psl_location"].Value,
  183. item.Cells["psl_devlocation"].Value, item.Cells["psl_prodcode"].Value, item.Cells["psl_baseqty"].Value,
  184. remark, item.Cells["ReelNum"].Value);
  185. }
  186. }
  187. dgv.DataSource = upLoadDatas;
  188. foreach (DataGridViewRow rw in dgv.Rows)
  189. {
  190. var checkCell = rw.Cells["isHandReel"] as DataGridViewCheckBoxCell;
  191. checkCell.Value = true;
  192. try
  193. {
  194. SQL.Clear();
  195. SQL.Append($@"INSERT INTO smt_handreel_log (serial_number,line_name,machine_name,side,
  196. position,reel_position, part_no, reel_qty,
  197. update_time, update_name,REELREMARK,REELNUM) VALUES
  198. ( '{rw.Cells["ms_sncode"].Value}','{rw.Cells["ps_linecode"].Value}','{rw.Cells["ps_processcode"].Value}','{rw.Cells["ps_table"].Value}',
  199. '{rw.Cells["psl_location"].Value}','{rw.Cells["psl_devlocation"].Value}','{rw.Cells["psl_prodcode"].Value}','{rw.Cells["psl_baseqty"].Value}',
  200. sysdate,'{User.UserName}','{rw.Cells["ReelRemark"].Value}','{rw.Cells["ReelNum"].Value}' )");
  201. dh.ExecuteSql(SQL.ToString(), "insert");
  202. }
  203. catch (Exception ex)
  204. {
  205. MessageBox.Show($"提交手补料异常{ex.Message}", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  206. return;
  207. }
  208. }
  209. MessageBox.Show("已提交手补料记录", "提示", MessageBoxButtons.OK, MessageBoxIcon.None);
  210. submit.Enabled = false;
  211. }
  212. private void UpdateSN(string type, string sn = "")
  213. {
  214. if (type == "C")
  215. {
  216. serialNumber.Text = "";
  217. workOrder.Text = "";
  218. productCode.Text = "";
  219. productName.Text = "";
  220. }
  221. else if (type == "L")
  222. {
  223. SQL.Clear();
  224. SQL.Append($@"SELECT ms_sncode,ma_code,pr_code,pr_spec FROM makeserial,make,product
  225. WHERE ms_sncode = '{sn}' AND ms_makecode = ma_code AND ms_prodcode = pr_code");
  226. dt = (DataTable)dh.ExecuteSql(SQL.ToString(), "select");
  227. if (dt.Rows.Count > 0)
  228. {
  229. serialNumber.Text = dt.Rows[0]["ms_sncode"].ToString();
  230. workOrder.Text = dt.Rows[0]["ma_code"].ToString();
  231. productCode.Text = dt.Rows[0]["pr_code"].ToString();
  232. productName.Text = dt.Rows[0]["pr_spec"].ToString();
  233. }
  234. else
  235. {
  236. UpdateSN("C", sn);
  237. }
  238. }
  239. }
  240. }
  241. }