OQC_SamplingDataCollection.cs 20 KB

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