Make_HandFeedQualityConfirm.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  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. using UAS_MES_NEW.PublicMethod;
  17. namespace UAS_MES_NEW.Make
  18. {
  19. public partial class Make_HandFeedQualityConfirm : Form
  20. {
  21. public Make_HandFeedQualityConfirm()
  22. {
  23. InitializeComponent();
  24. }
  25. StringBuilder SQL = new StringBuilder();
  26. DataTable dt, data;
  27. DataHelper dh;
  28. bool qaSwitching;
  29. private void Make_HandFeedQualityConfirm_Load(object sender, EventArgs e)
  30. {
  31. dh = SystemInf.dh;
  32. dgv.AutoGenerateColumns = false;
  33. data = new DataTable();
  34. data.Columns.Add("isScan", typeof(bool));
  35. data.Columns.Add("rn", typeof(int));
  36. data.Columns.Add("ms_sncode", typeof(string));
  37. data.Columns.Add("line_name", typeof(string));
  38. data.Columns.Add("side", typeof(string));
  39. data.Columns.Add("position", typeof(string));
  40. data.Columns.Add("reel_position", typeof(string));
  41. data.Columns.Add("part_no", typeof(string));
  42. data.Columns.Add("reel_qty", typeof(string));
  43. data.Columns.Add("reelremark", typeof(string));
  44. data.Columns.Add("reelnum", typeof(string));
  45. data.Columns.Add("qa_emp", typeof(string));
  46. data.Columns.Add("qa_date", typeof(string));
  47. data.Columns.Add("qa_type", typeof(string));
  48. data.Columns.Add("qa_result", typeof(string));
  49. data.Columns.Add("update_time", typeof(string));
  50. data.Columns.Add("handreel_id", typeof(string));
  51. dgv.DataSource = data;
  52. submit.Enabled = false;
  53. LockMakeCode.GetMakeCodeCtl(ma_code);
  54. ma_code.SetLockCheckBox(LockMakeCode);
  55. ma_code.TableName = "make left join product on ma_prodcode=pr_code";
  56. ma_code.SelectField = "ma_code # 工单号,ma_prodcode # 产品编号,ma_qty # 工单数量,pr_spec # 产品规格,ma_softversion # 软件版本,ma_salecode # 销售单号,pr_sendchecktype # 产品送检方式,pr_pcbacount # 拼版数";
  57. ma_code.FormName = Name;
  58. ma_code.SetValueField = new string[] { "ma_code", "ma_prodcode", "ma_qty", "pr_spec", "ma_softversion", "ma_salecode", "nvl(pr_sendchecktype,'LineCode')pr_sendchecktype", "pr_pcbacount" };
  59. ma_code.Condition = "ma_statuscode='STARTED'";
  60. ma_code.Focus();
  61. }
  62. private void ma_code_DbChange(object sender, EventArgs e)
  63. {
  64. BaseUtil.SetFormValue(this.Controls, ma_code.ReturnData);
  65. LoadHandReel();
  66. }
  67. private void LoadHandReel()
  68. {
  69. string makeCode = ma_code.Text.Trim();
  70. if (string.IsNullOrEmpty(makeCode))
  71. {
  72. MessageBox.Show("请输入工单", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  73. ma_code.Focus();
  74. return;
  75. }
  76. SQL.Clear();
  77. /*SQL.Append($@"SELECT m.ms_sncode, h.line_name, h.side,
  78. h.position, h.reel_position, h.part_no, h.reel_qty, h.reelremark, h.reelnum,
  79. h.qa_emp, to_char(h.qa_date,'yyyy-mm-dd hh24:mi:ss') qa_date, h.qa_type,
  80. to_char(h.update_time,'yyyy-mm-dd hh24:mi:ss') update_time, h.handreel_id
  81. FROM makeserial m, smt_handreel_log h
  82. WHERE h.serial_number = m.ms_sncode AND m.ms_makecode = '{makeCode}'
  83. ORDER BY m.ms_sncode, h.handreel_id");*/
  84. SQL.Append($@"SELECT m.ms_sncode, h.line_name, h.side, h.position,
  85. h.reel_position, h.part_no, h.reel_qty, h.reelremark, h.reelnum,
  86. h.qa_emp, to_char(h.qa_date, 'yyyy-mm-dd hh24:mi:ss') qa_date,
  87. h.qa_type, to_char(h.update_time, 'yyyy-mm-dd hh24:mi:ss') update_time, h.handreel_id
  88. FROM makeserial m, smt_handreel_log h WHERE h.serial_number = m.ms_sncode
  89. AND m.ms_makecode = '{makeCode}' AND h.update_time IN(SELECT MAX(t2.update_time) update_time
  90. FROM makeserial t1, smt_handreel_log t2 WHERE t2.serial_number = t1.ms_sncode
  91. AND t1.ms_makecode = '{makeCode}' GROUP BY t2.serial_number)
  92. ORDER BY m.ms_sncode, h.handreel_id");
  93. dt = (DataTable)dh.ExecuteSql(SQL.ToString(), "select");
  94. data.Rows.Clear();
  95. if (dt.Rows.Count == 0)
  96. {
  97. submit.Enabled = false;
  98. MessageBox.Show("该工单没有手补料序列号", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  99. ma_code.Focus();
  100. return;
  101. }
  102. for (int i = 0; i < dt.Rows.Count; i++)
  103. {
  104. DataRow src = dt.Rows[i];
  105. string qaType = NormalizeQaType(src["qa_type"]);
  106. data.Rows.Add(false, i + 1,
  107. src["ms_sncode"].ToString(),
  108. src["line_name"].ToString(),
  109. src["side"].ToString(),
  110. src["position"].ToString(),
  111. src["reel_position"].ToString(),
  112. src["part_no"].ToString(),
  113. src["reel_qty"].ToString(),
  114. src["reelremark"].ToString(),
  115. src["reelnum"].ToString(),
  116. src["qa_emp"].ToString(),
  117. src["qa_date"].ToString(),
  118. qaType,
  119. QaTypeText(qaType),
  120. src["update_time"].ToString(),
  121. src["handreel_id"].ToString());
  122. }
  123. ApplyLoadedStyle();
  124. submit.Enabled = true;
  125. snVal.Text = "";
  126. snVal.Focus();
  127. }
  128. private void snVal_KeyDown(object sender, KeyEventArgs e)
  129. {
  130. if (e.KeyCode != Keys.Enter) return;
  131. e.Handled = true;
  132. e.SuppressKeyPress = true;
  133. string scanSn = snVal.Text.Replace(";", ";").Trim();
  134. snVal.Text = scanSn;
  135. if (string.IsNullOrEmpty(scanSn))
  136. {
  137. MessageBox.Show("请扫描序列号", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  138. snVal.Focus();
  139. return;
  140. }
  141. if (data.Rows.Count == 0)
  142. {
  143. MessageBox.Show("请先输入工单", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  144. ma_code.Focus();
  145. return;
  146. }
  147. string qaType = SelectedQaType();
  148. if (qaType == "")
  149. {
  150. MessageBox.Show("请先选择合格或不合格", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  151. return;
  152. }
  153. bool found = false;
  154. bool already = true;
  155. int firstRow = -1;
  156. for (int i = 0; i < data.Rows.Count; i++)
  157. {
  158. if (!string.Equals(data.Rows[i]["ms_sncode"].ToString(), scanSn, StringComparison.OrdinalIgnoreCase))
  159. continue;
  160. found = true;
  161. if (firstRow < 0)
  162. firstRow = i;
  163. bool scanned = data.Rows[i]["isScan"] != DBNull.Value && Convert.ToBoolean(data.Rows[i]["isScan"]);
  164. if (!scanned || data.Rows[i]["qa_type"].ToString() != qaType)
  165. already = false;
  166. MarkScanRow(i, qaType);
  167. }
  168. if (!found)
  169. {
  170. UpdateSN("C");
  171. MessageBox.Show("该序列号不在当前工单手补料记录中", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  172. }
  173. else
  174. {
  175. UpdateSN("L", scanSn);
  176. if (already)
  177. MessageBox.Show("序列号已标记", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  178. else if (firstRow >= 0)
  179. dgv.FirstDisplayedScrollingRowIndex = firstRow;
  180. }
  181. snVal.Focus();
  182. snVal.SelectAll();
  183. }
  184. private void submit_Click(object sender, EventArgs e)
  185. {
  186. if (data.Rows.Count == 0)
  187. {
  188. MessageBox.Show("请先输入工单", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  189. ma_code.Focus();
  190. return;
  191. }
  192. List<DataRow> scanRows = new List<DataRow>();
  193. List<string> missing = new List<string>();
  194. foreach (DataRow row in data.Rows)
  195. {
  196. bool scanned = row["isScan"] != DBNull.Value && Convert.ToBoolean(row["isScan"]);
  197. if (!scanned)
  198. continue;
  199. string sn = row["ms_sncode"].ToString();
  200. string position = row["position"].ToString();
  201. string qaType = NormalizeQaType(row["qa_type"]);
  202. if (qaType == "")
  203. {
  204. missing.Add("序列号" + sn + "当前站位" + position);
  205. continue;
  206. }
  207. scanRows.Add(row);
  208. }
  209. if (missing.Count > 0)
  210. {
  211. MessageBox.Show(string.Join("、", missing) + "未选择合格或不合格", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  212. return;
  213. }
  214. if (scanRows.Count == 0)
  215. {
  216. MessageBox.Show("请先扫描序列号", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  217. snVal.Focus();
  218. return;
  219. }
  220. string emp = User.UserName ?? "";
  221. if (emp.Length > 20)
  222. emp = emp.Substring(0, 20);
  223. string confirmTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  224. try
  225. {
  226. foreach (DataRow row in scanRows)
  227. {
  228. string idSql = row["handreel_id"].ToString();
  229. string qaType = NormalizeQaType(row["qa_type"]);
  230. SQL.Clear();
  231. SQL.Append($@"UPDATE smt_handreel_log SET qa_emp = '{emp}', qa_date = sysdate, qa_type = '{qaType}'
  232. WHERE handreel_id = '{idSql}'");
  233. dh.ExecuteSql(SQL.ToString(), "update");
  234. }
  235. }
  236. catch (Exception ex)
  237. {
  238. MessageBox.Show("品质确认失败:" + ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  239. return;
  240. }
  241. List<string> snList = new List<string>();
  242. foreach (DataRow row in scanRows)
  243. {
  244. row["qa_emp"] = emp;
  245. row["qa_date"] = confirmTime;
  246. string sn = row["ms_sncode"].ToString();
  247. if (!snList.Contains(sn))
  248. snList.Add(sn);
  249. }
  250. MessageBox.Show($"序列号:{string.Join("、", snList)},数量{snList.Count},品质确认完成", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  251. snVal.Focus();
  252. snVal.SelectAll();
  253. snVal.Text = "";
  254. }
  255. private void qaPass_CheckedChanged(object sender, EventArgs e)
  256. {
  257. if (qaSwitching || !qaPass.Checked)
  258. return;
  259. qaSwitching = true;
  260. qaFail.Checked = false;
  261. qaSwitching = false;
  262. }
  263. private void qaFail_CheckedChanged(object sender, EventArgs e)
  264. {
  265. if (qaSwitching || !qaFail.Checked)
  266. return;
  267. qaSwitching = true;
  268. qaPass.Checked = false;
  269. qaSwitching = false;
  270. }
  271. private string SelectedQaType()
  272. {
  273. if (qaPass.Checked)
  274. return "1";
  275. if (qaFail.Checked)
  276. return "0";
  277. return "";
  278. }
  279. private string NormalizeQaType(object value)
  280. {
  281. string text = value == null || value == DBNull.Value ? "" : value.ToString().Trim();
  282. decimal number;
  283. if (decimal.TryParse(text, out number))
  284. {
  285. if (number == 1)
  286. return "1";
  287. if (number == 0 && text != "")
  288. return "0";
  289. }
  290. return "";
  291. }
  292. private string QaTypeText(string qaType)
  293. {
  294. if (qaType == "1")
  295. return "合格";
  296. if (qaType == "0")
  297. return "不合格";
  298. return "";
  299. }
  300. private void MarkScanRow(int rowIndex, string qaType)
  301. {
  302. data.Rows[rowIndex]["isScan"] = true;
  303. data.Rows[rowIndex]["qa_type"] = qaType;
  304. data.Rows[rowIndex]["qa_result"] = QaTypeText(qaType);
  305. PaintRow(rowIndex, qaType);
  306. }
  307. private void ApplyLoadedStyle()
  308. {
  309. int count = Math.Min(data.Rows.Count, dgv.Rows.Count);
  310. for (int i = 0; i < count; i++)
  311. PaintRow(i, NormalizeQaType(data.Rows[i]["qa_type"]));
  312. }
  313. private void PaintRow(int rowIndex, string qaType)
  314. {
  315. if (qaType == "1")
  316. {
  317. dgv.Rows[rowIndex].DefaultCellStyle.BackColor = Color.Green;
  318. dgv.Rows[rowIndex].DefaultCellStyle.ForeColor = Color.Black;
  319. }
  320. else if (qaType == "0")
  321. {
  322. dgv.Rows[rowIndex].DefaultCellStyle.BackColor = Color.DarkRed;
  323. dgv.Rows[rowIndex].DefaultCellStyle.ForeColor = Color.White;
  324. }
  325. else
  326. {
  327. dgv.Rows[rowIndex].DefaultCellStyle.BackColor = dgv.DefaultCellStyle.BackColor;
  328. dgv.Rows[rowIndex].DefaultCellStyle.ForeColor = dgv.DefaultCellStyle.ForeColor;
  329. }
  330. }
  331. private void UpdateSN(string type, string sn = "")
  332. {
  333. if (type == "C")
  334. {
  335. serialNumber.Text = "";
  336. workOrder.Text = "";
  337. productCode.Text = "";
  338. productName.Text = "";
  339. }
  340. else if (type == "L")
  341. {
  342. SQL.Clear();
  343. SQL.Append($@"SELECT ms_sncode,ma_code,pr_code,pr_spec FROM makeserial,make,product
  344. WHERE ms_sncode = '{sn}' AND ms_makecode = ma_code AND ms_prodcode = pr_code");
  345. dt = (DataTable)dh.ExecuteSql(SQL.ToString(), "select");
  346. if (dt.Rows.Count > 0)
  347. {
  348. serialNumber.Text = dt.Rows[0]["ms_sncode"].ToString();
  349. workOrder.Text = dt.Rows[0]["ma_code"].ToString();
  350. productCode.Text = dt.Rows[0]["pr_code"].ToString();
  351. productName.Text = dt.Rows[0]["pr_spec"].ToString();
  352. }
  353. else
  354. {
  355. UpdateSN("C");
  356. }
  357. }
  358. }
  359. }
  360. }