Make_RepairQualityConfirm.cs 14 KB

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