OQC_SamplingDataCollection.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Drawing;
  5. using System.Text;
  6. using System.Windows.Forms;
  7. using UAS_MES.CustomControl.DataGrid_View;
  8. using UAS_MES.DataOperate;
  9. using UAS_MES.Entity;
  10. using UAS_MES.PublicMethod;
  11. namespace UAS_MES.OQC
  12. {
  13. public partial class OQC_SamplingDataCollection : Form
  14. {
  15. AutoSizeFormClass asc = new AutoSizeFormClass();
  16. DataHelper dh;
  17. DataTable dt;
  18. DataTable BadCode;
  19. List<DataGridViewRow> dgvr = new List<DataGridViewRow>();
  20. LogStringBuilder sql = new LogStringBuilder();
  21. string[] LevelDefect = new string[] { "A#A", "B#B", "C#C", "D#D" };
  22. public OQC_SamplingDataCollection()
  23. {
  24. InitializeComponent();
  25. }
  26. private void 抽样数据采集_Load(object sender, EventArgs e)
  27. {
  28. asc.controllInitializeSize(this);
  29. dh = new DataHelper();
  30. }
  31. private void 抽样数据采集_SizeChanged(object sender, EventArgs e)
  32. {
  33. asc.controlAutoSize(this);
  34. }
  35. private void GetBatch_Click(object sender, EventArgs e)
  36. {
  37. string ErrorMessage = "";
  38. DataTable[] dt = LogicHandler.GetOQCBatch(ms_sncode.Text, obd_outboxcode.Text, ob_checkno.Text, "OQCDataCollection", out ErrorMessage);
  39. if (ErrorMessage == "")
  40. {
  41. BaseUtil.SetFormValue(Controls, dt[0]);
  42. BaseUtil.FillExpandDgvWithDataTable(CheckTypeDGV, dt[1], true);
  43. }
  44. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  45. }
  46. private void Clean_Click(object sender, EventArgs e)
  47. {
  48. OperateResult.Clear();
  49. }
  50. private void sncode_KeyDown(object sender, KeyEventArgs e)
  51. {
  52. if (e.KeyCode == Keys.Enter)
  53. {
  54. //输入的序列号不能为空
  55. if (sncode.Text != "")
  56. {
  57. //判断当前的检验状态
  58. if (ob_status.Text == "待检验" || ob_status.Text == "检验中")
  59. {
  60. dt = (DataTable)dh.ExecuteSql("select obd_sncode,ob_source,ob_makecode from OQCBatchDetail left join OQCBatch on ob_id=obd_obid where obd_sncode='" + sncode.Text + "'", "select");
  61. if (dt.Rows.Count > 0)
  62. {
  63. if (dt.Rows[0]["ob_source"].ToString() != "工序")
  64. GetBatchTypeGridData();
  65. else
  66. {
  67. string ErrorMessage = "";
  68. bool ifFirst;
  69. if (LogicHandler.CheckCurrentStepAndIfFirst(sncode.Text, dt.Rows[0]["ob_makecode"].ToString(), User.UserSourceCode, "OQC!SamplingDataCollection", out ifFirst, out ErrorMessage))
  70. GetBatchTypeGridData();
  71. else
  72. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  73. }
  74. }
  75. else OperateResult.AppendText(">>该序列号不属于当前抽检批次\n", Color.Red);
  76. }
  77. else OperateResult.AppendText(">>送检批次必须是待检验或者检验中\n", Color.Red);
  78. }
  79. else OperateResult.AppendText(">>输入的内容不能为空\n", Color.Red);
  80. }
  81. }
  82. private void GetBatchTypeGridData()
  83. {
  84. dt = (DataTable)dh.ExecuteSql("select 0,oi_checkkind,max(oi_sampleqty) oi_count,max(oi_checkqty) oi_checkedcount from OQCBatch left join OQCItems on ob_checkno=oi_checkno where oi_checkno='" + ob_checkno.Text + "' group by oi_checkkind ", "select");
  85. BaseUtil.FillExpandDgvWithDataTable(CheckTypeDGV, dt, true);
  86. sql.Clear();
  87. sql.Append("select pb_badgroup, bg_name,bg_code from product left join productkind ");
  88. sql.Append("on pr_kind=pk_name left join PRODUCTBADGROUP on pk_code= pb_kindcode ");
  89. sql.Append("left join badgroup on bg_code=pb_badgroup where pr_code='" + ob_prodcode.Text + "'");
  90. BadCode = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  91. BaseUtil.FillExpandDgvWithDataTable(WaitChooseDGV, BadCode, true);
  92. }
  93. private void Confirm_Click(object sender, EventArgs e)
  94. {
  95. //只能操作检验中或者待检验的批次
  96. if (ob_status.Text == "待检验" || ob_status.Text == "检验中")
  97. {
  98. //判断检验项是否勾选,如勾选取出明细数据
  99. DataTable UpdateData = BaseUtil.DGVIfChecked(CheckTypeDGV);
  100. if (UpdateData != null)
  101. {
  102. if (ChoosedDGV.RowCount > 0)
  103. {
  104. //用于存放更新的数据
  105. List<string> ois_ifng_update = new List<string>();
  106. List<string> ois_defectlevel_update = new List<string>();
  107. List<string> ois_remark_update = new List<string>();
  108. List<string> ois_id_update = new List<string>();
  109. //用于存放插入的数据
  110. List<string> ois_ifng_insert = new List<string>();
  111. List<string> ois_defectlevel_insert = new List<string>();
  112. List<string> ois_remark_insert = new List<string>();
  113. List<string> oi_itemcode_insert = new List<string>();
  114. for (int i = 0; i < UpdateData.Rows.Count; i++)
  115. {
  116. //将布尔值转换为0,-1
  117. if (UpdateData.Rows[i]["ois_id"].ToString() != "" && UpdateData.Rows[i]["ois_id"].ToString() != "0")
  118. {
  119. ois_ifng_update.Add(UpdateData.Rows[i]["oi_ng"].ToString() == "True" ? "-1" : "0");
  120. ois_defectlevel_update.Add(UpdateData.Rows[i]["oi_leveldefect"].ToString());
  121. ois_remark_update.Add(UpdateData.Rows[i]["ois_remark"].ToString());
  122. ois_id_update.Add(UpdateData.Rows[i]["ois_id"].ToString());
  123. }
  124. else
  125. {
  126. oi_itemcode_insert.Add(UpdateData.Rows[i]["oi_itemcode"].ToString());
  127. ois_ifng_insert.Add(UpdateData.Rows[i]["oi_ng"].ToString() == "True" ? "-1" : "0");
  128. ois_defectlevel_insert.Add(UpdateData.Rows[i]["oi_leveldefect"].ToString());
  129. ois_remark_insert.Add(UpdateData.Rows[i]["ois_remark"].ToString());
  130. }
  131. }
  132. //执行批量更新的SQL
  133. dh.BatchInsert("update OQCItemSamples set ois_ifng=:ois_ifng,ois_defectlevel=:ois_defectlevel,ois_remark=:ois_remark where ois_id=:ois_id",
  134. new string[] { "ois_ifng", "ois_defectlevel", "ois_remark", "ois_id" }, ois_ifng_update.ToArray(), ois_defectlevel_update.ToArray(), ois_remark_update.ToArray(), ois_id_update.ToArray());
  135. //如果主键为空,并且存在需要插入的数据则执行插入操作
  136. if (oi_itemcode_insert.Count > 0)
  137. {
  138. sql.Clear();
  139. sql.Append("insert into OQCItemSamples (ois_id,ois_checkno,ois_makecode, ois_sncode,ois_projectcode,ois_itemcode,");
  140. sql.Append("ois_ifng,ois_defectlevel,ois_remark)values(OQCItemSamples_SEQ.nextval,'" + ob_checkno.Text + "',");
  141. sql.Append("'" + ob_makecode.Text + "','" + sncode.Text + "','',:ois_itemcode,:ois_ifng,:ois_defectlevel,:ois_remark)");
  142. dh.BatchInsert(sql.GetString(), new string[] { "ois_itemcode", "ois_ifng", "ois_defectlevel", "ois_remark" },
  143. oi_itemcode_insert.ToArray(), ois_ifng_insert.ToArray(), ois_defectlevel_insert.ToArray(), ois_remark_insert.ToArray());
  144. }
  145. //采集不良信息
  146. List<string> bc_code = new List<string>();
  147. List<string> bc_name = new List<string>();
  148. for (int i = 0; i < ChoosedDGV.RowCount; i++)
  149. {
  150. bc_code.Add(ChoosedDGV.Rows[i].Cells[0].Value.ToString());
  151. bc_name.Add(ChoosedDGV.Rows[i].Cells[1].Value.ToString());
  152. }
  153. sql.Clear();
  154. sql.Append("insert into OQCNGReason(or_id, or_checkno, or_makecode, or_sncode, or_reasoncode, oi_description, oi_remark)");
  155. sql.Append("values (OQCNGReason_seq.nextval,'" + ob_checkno.Text + "','" + ob_makecode.Text + "','" + sncode.Text + "',:a,:b,'" + ob_remark.Text + "')");
  156. dh.BatchInsert(sql.GetString(), new string[] { "a", "b" }, bc_code.ToArray(), bc_name.ToArray());
  157. sql.Clear();
  158. //更新项目编号中的抽检数、不合格数,根据采样项目记录
  159. sql.Append("UPDATE OQCItems SET (oi_ngqty,oi_checkqty)=(select nvl(sum(case when ");
  160. sql.Append("nvl(ois_ifng,0)=0 then 0 else 1 end),0) ,count(1) from OQCItemSamples where ois_checkno=oi_checkno ");
  161. sql.Append("and ois_itemcode=oi_itemcode)where oi_checkno ='" + ob_checkno.Text + "' and oi_projectcode ='" + ob_projectcode.Text + "'");
  162. dh.ExecuteSql(sql.GetString(), "update");
  163. //更新检验状态,如果是待检验的更新为检验中
  164. dh.ExecuteSql("update OQCBatch set ob_status='CHECKING' where ob_checkno='" + ob_checkno.Text + "' and ob_status='UNCHECK'", "update");
  165. //更新批次中的合格数不合格数:用抽检批检验项目表获取最大的抽检数和不合格数
  166. dh.ExecuteSql("update OQCBATCH set (ob_ngqty,ob_okqty)=(select nvl(max(oi_ngqty), 0), max(oi_checkqty) - nvl(max(oi_ngqty), 0) from OQCItems where oi_checkno ='" + ob_checkno.Text + "') where ob_checkno ='" + ob_checkno.Text + "'", "update");
  167. OperateResult.AppendText(">>操作成功\n", Color.Green);
  168. }
  169. else
  170. OperateResult.AppendText(">>请勾选不良明细\n", Color.Red);
  171. }
  172. else
  173. {
  174. OperateResult.AppendText(">>请勾选送检明细\n", Color.Red);
  175. }
  176. }
  177. else
  178. {
  179. OperateResult.AppendText(">>必须是待检验或者检测中的送检批才能进行此操作\n", Color.Red);
  180. }
  181. }
  182. private void Cancel_Click(object sender, EventArgs e)
  183. {
  184. }
  185. private void BatchPass_Click(object sender, EventArgs e)
  186. {
  187. if (CheckBefore())
  188. {
  189. sql.Clear();
  190. sql.Append("select max(nvl(ad_maxngacceptqty,0)) maxngacceptqty from QUA_Aql,QUA_AqlDetail where al_id=ad_alid ");
  191. sql.Append("and al_statuscode='AUDITED' and al_code ='" + ob_aqlcode.Text + "' and " + (ob_batchqty.Text != "" ? ob_batchqty.Text : "0") + " >= ad_minqty");
  192. sql.Append(" and " + (ob_batchqty.Text != "" ? ob_batchqty.Text : "0") + "<=ad_maxqty ");
  193. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  194. if (int.Parse(ob_ngqty.Text == "" ? "0" : ob_ngqty.Text) <= int.Parse(dt.Rows[0]["maxngacceptqty"].ToString() == "" ? ob_maxngacceptqty.Text : dt.Rows[0]["maxngacceptqty"].ToString()))
  195. {
  196. dh.ExecuteSql("update OQCBatch set ob_status='OK',ob_result='OK' where ob_checkno='" + ob_checkno.Text + "'", "select");
  197. string ErrorMessage;
  198. LogicHandler.UpdateMakeMessage(ms_sncode.Text, ob_makecode.Text, "OQC批判过", User.UserSourceCode, User.UserName, "批次通过", out ErrorMessage);
  199. //记录操作日志
  200. LogicHandler.InsertMakeProcess(ms_sncode.Text, ob_makecode.Text, "批结果判定", "批次通过", User.UserName);
  201. GetBatch.PerformClick();
  202. OperateResult.AppendText(">>通过批成功\n", Color.Green);
  203. }
  204. else
  205. OperateResult.AppendText(">>当前批次不合格数为" + ob_ngqty.Text + ",大于最大不合格允通过数" + ob_maxngacceptqty.Text + "\n", Color.Red);
  206. }
  207. }
  208. private void Refresh_Click(object sender, EventArgs e)
  209. {
  210. }
  211. private bool CheckBefore()
  212. {
  213. //如果AQL标准为空
  214. if (ob_aqlcode.Text == "")
  215. {
  216. if (ob_maxngacceptqty.Text == "")
  217. OperateResult.AppendText(">>AQL标准为空的时候必须填写最大不合格允许通过数\n", Color.Red);
  218. else
  219. {
  220. sql.Clear();
  221. sql.Append("select wm_concat(oi_itemcode) codes from OQCitems where ");
  222. sql.Append("nvl(oi_checkqty,0)<oi_sampleqty and oi_sampleqty>0 and rownum<30 and oi_checkno='" + ob_checkno.Text + "'");
  223. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  224. if (dt.Rows.Count > 0)
  225. {
  226. if (dt.Rows[0]["codes"].ToString() != "")
  227. {
  228. OperateResult.AppendText(">>项目编号抽检数未达到样本数,项目编号['" + ob_makecode.Text + "']\n", Color.Red);
  229. return false;
  230. }
  231. else
  232. return true;
  233. }
  234. }
  235. }
  236. return false;
  237. }
  238. private void WaitReject_Click(object sender, EventArgs e)
  239. {
  240. BaseUtil.CleanDGVData(ChoosedDGV);
  241. }
  242. private void ChooseedReject_Click(object sender, EventArgs e)
  243. {
  244. dt = BaseUtil.DGVIfChecked(WaitChooseDGV);
  245. if (dt != null)
  246. BaseUtil.FillDgvWithDataTable(ChoosedDGV, dt);
  247. else
  248. OperateResult.AppendText(">>请先勾选不良明细\n", Color.Red);
  249. }
  250. private void CheckTypeDGV_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
  251. {
  252. if (!dgvr.Contains(CheckTypeDGV.Rows[e.RowIndex]))
  253. {
  254. sql.Clear();
  255. sql.Append("select nvl(ois_id,0) ois_ id ,oi_itemcode ,nvl(ois_ifng,1) oi_ng,nvl(ois_defectlevel,'-1') oi_leveldefect,");
  256. sql.Append("ois_remark,case ois_id when 0 then '未检验' else '已检验' end ois_status from OQCItems left join OQCItemSamples on ois_checkno=oi_checkno ");
  257. sql.Append("and ois_itemcode=oi_itemcode where ois_projectcode = oi_projectcode and oi_checkno ='" + ob_checkno.Text + "' and ois_sncode ='" + sncode.Text + "'");
  258. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  259. DataGridViewRow headerRow = new DataGridViewRow();
  260. DataGridViewTextBoxCell textcell = new DataGridViewTextBoxCell();
  261. textcell.Value = "";
  262. headerRow.Cells.Add(textcell);
  263. textcell = new DataGridViewTextBoxCell();
  264. textcell.Value = "检验项目";
  265. headerRow.Cells.Add(textcell);
  266. textcell = new DataGridViewTextBoxCell();
  267. textcell.Value = "不通过";
  268. headerRow.Cells.Add(textcell);
  269. textcell = new DataGridViewTextBoxCell();
  270. textcell.Value = "缺陷等级";
  271. headerRow.Cells.Add(textcell);
  272. textcell = new DataGridViewTextBoxCell();
  273. textcell.Value = "备注";
  274. headerRow.Cells.Add(textcell);
  275. textcell = new DataGridViewTextBoxCell();
  276. textcell.Value = "检验状态";
  277. headerRow.Cells.Add(textcell);
  278. headerRow.ReadOnly = true;
  279. CollapseDataGridViewRow cl = (CollapseDataGridViewRow)(CheckTypeDGV.Rows[e.RowIndex]);
  280. cl.Rows.Add(headerRow);
  281. for (int i = 0; i < dt.Rows.Count; i++)
  282. {
  283. DataGridViewRow dataRow = new DataGridViewRow();
  284. //标记展开的子行
  285. dataRow.Tag = "SonRow";
  286. DataGridViewCheckBoxCell checkcell = new DataGridViewCheckBoxCell();
  287. dataRow.Cells.Add(checkcell);
  288. textcell = new DataGridViewTextBoxCell();
  289. textcell.Value = dt.Rows[i]["oi_itemcode"].ToString();
  290. dataRow.Cells.Add(textcell);
  291. textcell.ReadOnly = true;
  292. checkcell = new DataGridViewCheckBoxCell();
  293. checkcell.Value = dt.Rows[i]["oi_ng"].ToString() != "0" ? true : false;
  294. dataRow.Cells.Add(checkcell);
  295. textcell.ReadOnly = false;
  296. DataGridViewComboBoxCell combocell = new DataGridViewComboBoxCell();
  297. BaseUtil.SetDGVCellComboxData(combocell, "display", "value", LevelDefect);
  298. combocell.Value = dt.Rows[i]["oi_leveldefect"].ToString();
  299. dataRow.Cells.Add(combocell);
  300. textcell.ReadOnly = false;
  301. textcell = new DataGridViewTextBoxCell();
  302. textcell.Value = dt.Rows[i]["ois_remark"].ToString();
  303. dataRow.Cells.Add(textcell);
  304. textcell.ReadOnly = false;
  305. textcell = new DataGridViewTextBoxCell();
  306. textcell.Value = dt.Rows[i]["ois_status"].ToString();
  307. dataRow.Cells.Add(textcell);
  308. textcell.ReadOnly = true;
  309. textcell = new DataGridViewTextBoxCell();
  310. textcell.Value = dt.Rows[i]["ois_id"].ToString();
  311. dataRow.Cells.Add(textcell);
  312. cl.Rows.Add(dataRow);
  313. }
  314. dgvr.Add(CheckTypeDGV.Rows[e.RowIndex]);
  315. }
  316. }
  317. private void CheckTypeDGV_DataError(object sender, DataGridViewDataErrorEventArgs e) { }
  318. private void WaitChooseDGV_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
  319. {
  320. if (!dgvr.Contains(WaitChooseDGV.Rows[e.RowIndex]))
  321. {
  322. DataTable dt = (DataTable)dh.ExecuteSql("select bc_code,bc_name from BADCODE where bc_groupcode='2015040001'", "select");
  323. DataGridViewRow headerRow = new DataGridViewRow();
  324. DataGridViewTextBoxCell textcell = new DataGridViewTextBoxCell();
  325. textcell.Value = "";
  326. headerRow.Cells.Add(textcell);
  327. textcell = new DataGridViewTextBoxCell();
  328. textcell.Value = "不良代码";
  329. headerRow.Cells.Add(textcell);
  330. textcell = new DataGridViewTextBoxCell();
  331. textcell.Value = "不良原因";
  332. headerRow.Cells.Add(textcell);
  333. headerRow.ReadOnly = true;
  334. CollapseDataGridViewRow cl = (CollapseDataGridViewRow)(WaitChooseDGV.Rows[e.RowIndex]);
  335. cl.Rows.Add(headerRow);
  336. for (int i = 0; i < dt.Rows.Count; i++)
  337. {
  338. DataGridViewRow dataRow = new DataGridViewRow();
  339. //标记展开的子行
  340. dataRow.Tag = "SonRow";
  341. DataGridViewCheckBoxCell checkcell = new DataGridViewCheckBoxCell();
  342. dataRow.Cells.Add(checkcell);
  343. textcell = new DataGridViewTextBoxCell();
  344. textcell.Value = dt.Rows[i]["bc_code"].ToString();
  345. dataRow.Cells.Add(textcell);
  346. textcell = new DataGridViewTextBoxCell();
  347. textcell.Value = dt.Rows[i]["bc_name"].ToString();
  348. dataRow.Cells.Add(textcell);
  349. cl.Rows.Add(dataRow);
  350. }
  351. dgvr.Add(WaitChooseDGV.Rows[e.RowIndex]);
  352. }
  353. }
  354. //如果当前行的Cell有修改过就将CheckBox勾选上
  355. private void CheckTypeDGV_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  356. {
  357. if (e.RowIndex > 0)
  358. CheckTypeDGV.Rows[e.RowIndex].Cells[0].Value = true;
  359. }
  360. private void WaitChooseDGV_DataError(object sender, DataGridViewDataErrorEventArgs e) { }
  361. private void WaitChooseDGV_CellContentClick(object sender, DataGridViewCellEventArgs e)
  362. {
  363. BaseUtil.ExpandDGVCheck(WaitChooseDGV, e);
  364. }
  365. private void CheckTypeDGV_CellContentClick(object sender, DataGridViewCellEventArgs e)
  366. {
  367. BaseUtil.ExpandDGVCheck(CheckTypeDGV, e);
  368. }
  369. private void bccode_KeyDown(object sender, KeyEventArgs e)
  370. {
  371. if (e.KeyCode == Keys.Enter)
  372. {
  373. dt = (DataTable)dh.ExecuteSql("select bc_code,bc_name from badcode where bc_code='" + bccode.Text + "'", "select");
  374. try
  375. {
  376. dt.Merge(ChoosedDGV.DataSource as DataTable);
  377. ChoosedDGV.DataSource = dt;
  378. }
  379. catch (Exception)
  380. {
  381. }
  382. }
  383. }
  384. private void ob_checkno_KeyDown(object sender, KeyEventArgs e)
  385. {
  386. if (e.KeyCode == Keys.Enter)
  387. {
  388. GetBatch.PerformClick();
  389. }
  390. }
  391. private void ms_sncode_KeyDown(object sender, KeyEventArgs e)
  392. {
  393. if (e.KeyCode == Keys.Enter)
  394. {
  395. GetBatch.PerformClick();
  396. }
  397. }
  398. }
  399. }