OQC_SamplingDataCollection.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  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. DataTable TempForCheckType = new DataTable();
  23. DataTable TempForBadGroup = new DataTable();
  24. string ErrorMessage = "";
  25. public OQC_SamplingDataCollection()
  26. {
  27. InitializeComponent();
  28. }
  29. private void 抽样数据采集_Load(object sender, EventArgs e)
  30. {
  31. asc.controllInitializeSize(this);
  32. BaseUtil.DataGridViewNotSort(CheckTypeDGV);
  33. BaseUtil.DataGridViewNotSort(WaitChooseDGV);
  34. dh = new DataHelper();
  35. }
  36. private void 抽样数据采集_SizeChanged(object sender, EventArgs e)
  37. {
  38. asc.controlAutoSize(this);
  39. }
  40. private void GetBatch_Click(object sender, EventArgs e)
  41. {
  42. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
  43. {
  44. DataTable[] dt = LogicHandler.GetOQCBatch(ms_sncode.Text, obd_outboxcode.Text, ob_checkno.Text, "OQCDataCollection", out ErrorMessage);
  45. if (ErrorMessage == "")
  46. {
  47. BaseUtil.SetFormValue(Controls, dt[0]);
  48. oi_checkqty.Text = dh.getFieldDataByCondition("oqcitems", "max(oi_checkqty)", "oi_checkno='"+ob_checkno.Text+"'").ToString();
  49. if (ob_aqlcode.Text == "")
  50. {
  51. }
  52. dgvr.Clear();
  53. }
  54. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  55. }
  56. else
  57. {
  58. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  59. }
  60. }
  61. private void Clean_Click(object sender, EventArgs e)
  62. {
  63. OperateResult.Clear();
  64. }
  65. private void sncode_KeyDown(object sender, KeyEventArgs e)
  66. {
  67. if (e.KeyCode == Keys.Enter)
  68. {
  69. if (CheckSnCode())
  70. {
  71. dt = (DataTable)dh.ExecuteSql("select or_id,or_reasoncode bg_code, oi_description bg_name from OQCNGReason where or_checkno='" + ob_checkno.Text + "' and or_sncode='" + sncode.Text + "'", "select");
  72. BaseUtil.FillDgvWithDataTable(ChoosedDGV, dt);
  73. GetBatchTypeGridData();
  74. }
  75. }
  76. }
  77. private bool CheckSnCode()
  78. {
  79. //输入的序列号不能为空
  80. if (sncode.Text != "")
  81. {
  82. //判断当前的检验状态
  83. if (ob_status.Text == "待检验" || ob_status.Text == "检验中")
  84. {
  85. 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");
  86. if (dt.Rows.Count > 0)
  87. {
  88. if (dt.Rows[0]["ob_source"].ToString() != "工序")
  89. {
  90. return true;
  91. }
  92. else
  93. {
  94. string ErrorMessage = "";
  95. string oMakeCode = "";
  96. string oMsID = "";
  97. if (LogicHandler.CheckStepSNAndMacode(dt.Rows[0]["ob_makecode"].ToString(), User.UserSourceCode, sncode.Text, User.UserCode, out oMakeCode, out oMsID, out ErrorMessage))
  98. {
  99. return true;
  100. }
  101. else
  102. {
  103. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  104. return false;
  105. }
  106. }
  107. }
  108. else
  109. {
  110. OperateResult.AppendText(">>序列号" + sncode.Text + "不属于当前抽检批次\n", Color.Red);
  111. return false;
  112. }
  113. }
  114. else
  115. {
  116. OperateResult.AppendText(">>送检批次必须是待检验或者检验中\n", Color.Red);
  117. return false;
  118. }
  119. }
  120. else
  121. {
  122. OperateResult.AppendText(">>序列号不能为空\n", Color.Red);
  123. return false;
  124. }
  125. }
  126. private void GetBatchTypeGridData()
  127. {
  128. dt = (DataTable)dh.ExecuteSql("select oi_checkkind,max(oi_sampleqty) oi_count,nvl(max(oi_checkqty),0) oi_checkedcount from OQCBatch left join OQCItems on ob_checkno=oi_checkno where oi_checkno='" + ob_checkno.Text + "' group by oi_checkkind ", "select");
  129. BaseUtil.FillExpandDgvWithDataTable(CheckTypeDGV, dt, true,true);
  130. if (CheckTypeDGV.Rows.Count == 0)
  131. {
  132. OperateResult.AppendText(">>请先维护抽样计划\n", Color.Red);
  133. return;
  134. }
  135. string checkkind = "";
  136. for (int i = 0; i < CheckTypeDGV.Rows.Count; i++)
  137. {
  138. checkkind +=("'"+ CheckTypeDGV.Rows[i].Cells["oi_itemcode"].Value.ToString() + "',") ;
  139. }
  140. sql.Clear();
  141. sql.Append("select 1 choose,oi_checkkind,ois_sncode,nvl(ois_id,0) ois_id ,oi_itemcode ,nvl(ois_ifng,0) oi_ng,nvl(ois_defectlevel,'-1')");
  142. sql.Append("oi_leveldefect,ois_remark,case nvl(ois_id,0) when 0 then '未检验' else '已检验' end ois_status from OQCItems ");
  143. sql.Append("left join OQCItemSamples on ois_sncode='" + sncode.Text + "' and ois_checkno=oi_checkno and ");
  144. sql.Append("ois_itemcode=oi_itemcode and ois_projectcode = oi_projectcode where oi_checkno ='" + ob_checkno.Text + "' ");
  145. sql.Append("and oi_checkkind in (" + checkkind.Substring(0,checkkind.Length-1) + ")");
  146. TempForCheckType = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  147. sql.Clear();
  148. sql.Append("select bg_code,bg_name from product left join productkind ");
  149. sql.Append("on pr_kind=pk_name left join PRODUCTBADGROUP on pk_code= pb_kindcode ");
  150. sql.Append("left join badgroup on bg_code=pb_badgroup where pr_code='" + ob_prodcode.Text + "'");
  151. BadCode = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  152. BaseUtil.FillExpandDgvWithDataTable(WaitChooseDGV, BadCode, true,false);
  153. }
  154. private void Confirm_Click(object sender, EventArgs e)
  155. {
  156. //只能操作检验中或者待检验的批次
  157. if (ob_status.Text == "待检验" || ob_status.Text == "检验中")
  158. {
  159. if (!CheckSnCode())
  160. return;
  161. //判断检验项是否勾选,如勾选取出明细数据
  162. for (int i = TempForCheckType.Rows.Count - 1; i >= 0; i--)
  163. {
  164. if (TempForCheckType.Rows[i][0].ToString() == "False")
  165. {
  166. TempForCheckType.Rows.RemoveAt(i);
  167. }
  168. }
  169. if (TempForCheckType != null && TempForCheckType.Rows.Count > 0)
  170. {
  171. //用于存放更新的数据
  172. List<string> ois_ifng_update = new List<string>();
  173. List<string> ois_defectlevel_update = new List<string>();
  174. List<string> ois_remark_update = new List<string>();
  175. List<string> ois_id_update = new List<string>();
  176. //用于存放插入的数据
  177. List<string> ois_ifng_insert = new List<string>();
  178. List<string> ois_defectlevel_insert = new List<string>();
  179. List<string> ois_remark_insert = new List<string>();
  180. List<string> oi_itemcode_insert = new List<string>();
  181. for (int i = 0; i < TempForCheckType.Rows.Count; i++)
  182. {
  183. //将布尔值转换为0,-1
  184. if (TempForCheckType.Rows[i]["ois_id"].ToString() != "" && TempForCheckType.Rows[i]["ois_id"].ToString() != "0")
  185. {
  186. ois_ifng_update.Add(TempForCheckType.Rows[i]["oi_ng"].ToString());
  187. ois_defectlevel_update.Add(TempForCheckType.Rows[i]["oi_leveldefect"].ToString());
  188. ois_remark_update.Add(TempForCheckType.Rows[i]["ois_remark"].ToString());
  189. ois_id_update.Add(TempForCheckType.Rows[i]["ois_id"].ToString());
  190. }
  191. else
  192. {
  193. oi_itemcode_insert.Add(TempForCheckType.Rows[i]["oi_itemcode"].ToString());
  194. ois_ifng_insert.Add(TempForCheckType.Rows[i]["oi_ng"].ToString());
  195. ois_defectlevel_insert.Add(TempForCheckType.Rows[i]["oi_leveldefect"].ToString());
  196. ois_remark_insert.Add(TempForCheckType.Rows[i]["ois_remark"].ToString());
  197. }
  198. }
  199. //判断是否含不通过的内容
  200. bool AllPass = true;
  201. for (int i = 0; i < ois_ifng_insert.Count; i++)
  202. {
  203. if (ois_ifng_insert[i] != "0")
  204. AllPass = false;
  205. }
  206. for (int i = 0; i < ois_ifng_update.Count; i++)
  207. {
  208. if (ois_ifng_update[i] != "0")
  209. AllPass = false;
  210. }
  211. if (ChoosedDGV.RowCount > 0 || AllPass)
  212. {
  213. //执行批量更新的SQL
  214. if (ois_id_update.Count > 0)
  215. {
  216. dh.BatchInsert("update OQCItemSamples set ois_ifng=:ois_ifng,ois_defectlevel=:ois_defectlevel,ois_remark=:ois_remark,ois_indate=sysdate where ois_id=:ois_id",
  217. 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());
  218. }
  219. //如果主键为空,并且存在需要插入的数据则执行插入操作
  220. if (oi_itemcode_insert.Count > 0)
  221. {
  222. string[] id = new string[oi_itemcode_insert.Count];
  223. for (int i = 0; i < id.Length; i++)
  224. {
  225. id[i] = dh.GetSEQ("OQCItemSamples_SEQ");
  226. }
  227. sql.Clear();
  228. sql.Append("insert when (not exists (select ois_id from OQCItemSamples where ois_checkno='" + ob_checkno.Text + "' and ois_sncode='" + sncode.Text + "' and ois_itemcode =:ois_itemcode)) then ");
  229. sql.Append("into OQCItemSamples (ois_id,ois_checkno,ois_makecode, ois_sncode,ois_projectcode,ois_itemcode,");
  230. sql.Append("ois_ifng,ois_defectlevel,ois_remark,ois_indate)select :id,'" + ob_checkno.Text + "',");
  231. sql.Append("'" + ob_makecode.Text + "','" + sncode.Text + "','" + ob_projectcode.Text + "',:ois_itemcode,:ois_ifng,:ois_defectlevel,:ois_remark,sysdate from dual");
  232. dh.BatchInsert(sql.GetString(), new string[] { "ois_itemcode", "id", "ois_itemcode", "ois_ifng", "ois_defectlevel", "ois_remark" },
  233. oi_itemcode_insert.ToArray(), id, oi_itemcode_insert.ToArray(), ois_ifng_insert.ToArray(), ois_defectlevel_insert.ToArray(), ois_remark_insert.ToArray());
  234. }
  235. //采集不良信息
  236. List<string> bc_code = new List<string>();
  237. List<string> bc_name = new List<string>();
  238. for (int i = 0; i < ChoosedDGV.RowCount; i++)
  239. {
  240. bc_code.Add(ChoosedDGV.Rows[i].Cells[1].Value.ToString());
  241. bc_name.Add(ChoosedDGV.Rows[i].Cells[2].Value.ToString());
  242. }
  243. if (bc_name.Count > 0)
  244. {
  245. dh.UpdateByCondition("makeserial", "ms_badtimes=ms_badtimes+1", "ms_sncode='"+sncode.Text+"'");
  246. dh.ExecuteSql("delete from OQCNGReason where or_sncode='" + sncode.Text + "' and or_checkno='" + ob_checkno.Text + "'", "delete");
  247. sql.Clear();
  248. sql.Append("insert into OQCNGReason(or_id, or_checkno, or_makecode, or_sncode, or_reasoncode, oi_description, oi_remark)");
  249. sql.Append("values (OQCNGReason_seq.nextval,'" + ob_checkno.Text + "','" + ob_makecode.Text + "','" + sncode.Text + "',:a,:b,'" + ob_remark.Text + "')");
  250. dh.BatchInsert(sql.GetString(), new string[] { "a", "b" }, bc_code.ToArray(), bc_name.ToArray());
  251. }
  252. //更新项目编号中的抽检数、不合格数,根据采样项目记录
  253. sql.Clear();
  254. sql.Append("UPDATE OQCItems SET (oi_ngqty,oi_checkqty)=(select nvl(sum(case when ");
  255. sql.Append("nvl(ois_ifng,0)=0 then 0 else 1 end),0) ,count(1) from OQCItemSamples where ois_checkno=oi_checkno ");
  256. sql.Append("and ois_itemcode=oi_itemcode)where oi_checkno ='" + ob_checkno.Text + "' and oi_projectcode ='" + ob_projectcode.Text + "'");
  257. dh.ExecuteSql(sql.GetString(), "update");
  258. //更新检验状态,如果是待检验的更新为检验中
  259. dh.ExecuteSql("update OQCBatch set ob_status='CHECKING' where ob_checkno='" + ob_checkno.Text + "' and ob_status='UNCHECK'", "update");
  260. //更新批次中的合格数不合格数:用抽检批检验项目表获取最大的抽检数和不合格数
  261. sql.Clear();
  262. sql.Append("select count(1)from (select ois_sncode from OQCITEMSAMPLES where ");
  263. sql.Append("ois_checkno = '"+ob_checkno.Text+"' and ois_ifng = 1 group by ois_sncode)");
  264. string ngqty = (dh.ExecuteSql(sql.GetString(),"select") as DataTable).Rows[0][0].ToString();
  265. dh.ExecuteSql("update OQCBATCH set ob_ngqty='"+ngqty+"',ob_okqty=(select max(oi_checkqty)-'"+ngqty+"' from OQCItems where oi_checkno ='" + ob_checkno.Text + "') where ob_checkno ='" + ob_checkno.Text + "'", "update");
  266. OperateResult.AppendText(">>序列号 " + sncode.Text + "操作成功\n", Color.Green);
  267. GetBatch.PerformClick();
  268. ChoosedDGV.DataSource = null;
  269. BaseUtil.CleanDGVData(CheckTypeDGV);
  270. BaseUtil.CleanDGVData(WaitChooseDGV);
  271. sncode.Text = "";
  272. TempForCheckType.Clear();
  273. TempForBadGroup.Clear();
  274. sncode.Focus();
  275. }
  276. else OperateResult.AppendText(">>含有未通过项请勾选不良明细\n", Color.Red);
  277. }
  278. else OperateResult.AppendText(">>请勾选送检明细\n", Color.Red);
  279. }
  280. else OperateResult.AppendText(">>必须是待检验或者检测中的送检批才能进行此操作\n", Color.Red);
  281. }
  282. private void BatchPass_Click(object sender, EventArgs e)
  283. {
  284. if (CheckBefore())
  285. {
  286. if (int.Parse(ob_ngqty.Text == "" ? "0" : ob_ngqty.Text) <= int.Parse(ob_maxngacceptqty.Text == "" ? ob_maxngacceptqty.Text : ob_maxngacceptqty.Text))
  287. {
  288. dh.ExecuteSql("update OQCBatch set ob_status='OK',ob_result='OK' where ob_checkno='" + ob_checkno.Text + "'", "select");
  289. string ErrorMessage;
  290. LogicHandler.UpdateOQCMessage(ms_sncode.Text, ob_checkno.Text,ob_makecode.Text, "OQC批判过", User.UserSourceCode, User.UserName, "批次通过", out ErrorMessage);
  291. //记录操作日志
  292. LogicHandler.InsertMakeProcess(ms_sncode.Text, ob_makecode.Text, User.UserSourceCode, "批结果判定", "批次通过", User.UserName);
  293. GetBatch.PerformClick();
  294. OperateResult.AppendText(">>"+ob_checkno.Text+"通过批成功\n", Color.Green);
  295. }
  296. else
  297. OperateResult.AppendText(">>当前批次不合格数为" + ob_ngqty.Text + ",大于最大不合格允通过数" + ob_maxngacceptqty.Text + "\n", Color.Red);
  298. }
  299. }
  300. private bool CheckBefore()
  301. {
  302. if (ob_maxngacceptqty.Text == "" || ob_maxngacceptqty.Text == "0")
  303. {
  304. if (ob_aqlcode.Text == "")
  305. OperateResult.AppendText(">>最大不合格允许通过数为空的时候必须填写维护AQL标准\n", Color.Red);
  306. else
  307. {
  308. dt = (DataTable)dh.ExecuteSql("select nvl(ad_minqty,0)ad_minqty,nvl(ad_maxqty,0)ad_maxqty,nvl(ad_maxngacceptqty,0)ad_maxngacceptqty from QUA_Aql left join qua_aqldetail on ad_alid=al_id where al_code='" + ob_aqlcode.Text + "'", "select");
  309. if (dt.Rows.Count > 0)
  310. {
  311. for (int i = 0; i < dt.Rows.Count; i++)
  312. {
  313. int batchqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text);
  314. int minqty = int.Parse(dt.Rows[i]["ad_minqty"].ToString());
  315. int maxqty = int.Parse(dt.Rows[i]["ad_maxqty"].ToString());
  316. if (batchqty > minqty && batchqty <= maxqty)
  317. {
  318. ob_maxngacceptqty.Text = dt.Rows[i]["ad_maxngacceptqty"].ToString();
  319. return true;
  320. }
  321. }
  322. }
  323. }
  324. }
  325. else
  326. {
  327. sql.Clear();
  328. sql.Append("select wm_concat(oi_itemcode) codes from OQCitems where ");
  329. sql.Append("nvl(oi_checkqty,0)<oi_sampleqty and oi_sampleqty>0 and rownum<30 and oi_checkno='" + ob_checkno.Text + "'");
  330. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  331. if (dt.Rows.Count > 0)
  332. {
  333. if (dt.Rows[0]["codes"].ToString() != "")
  334. {
  335. OperateResult.AppendText(">>项目编号抽检数未达到样本数,项目编号[" + dt.Rows[0]["codes"].ToString() + "]\n", Color.Red);
  336. return false;
  337. }
  338. else
  339. return true;
  340. }
  341. }
  342. return false;
  343. }
  344. private void WaitReject_Click(object sender, EventArgs e)
  345. {
  346. BaseUtil.CleanDGVData(ChoosedDGV);
  347. }
  348. private void ChooseedReject_Click(object sender, EventArgs e)
  349. {
  350. if (TempForBadGroup != null)
  351. {
  352. for (int i = TempForBadGroup.Rows.Count - 1; i >= 0; i--)
  353. {
  354. if (TempForBadGroup.Rows[i][0].ToString() != "True")
  355. TempForBadGroup.Rows.RemoveAt(i);
  356. }
  357. BaseUtil.FillDgvWithDataTable(ChoosedDGV, TempForBadGroup.Copy());
  358. }
  359. else
  360. OperateResult.AppendText(">>请先勾选不良明细\n", Color.Red);
  361. }
  362. private void CheckTypeDGV_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
  363. {
  364. if (!dgvr.Contains(CheckTypeDGV.Rows[e.RowIndex]))
  365. {
  366. string checkkind = CheckTypeDGV.Rows[e.RowIndex].Cells["oi_itemcode"].Value.ToString();
  367. DataTable dt = BaseUtil.filterDataTable(TempForCheckType,"oi_checkkind='"+checkkind+"'");
  368. DataGridViewRow headerRow = new DataGridViewRow();
  369. DataGridViewTextBoxCell textcell = new DataGridViewTextBoxCell();
  370. textcell.Value = "";
  371. headerRow.Cells.Add(textcell);
  372. textcell = new DataGridViewTextBoxCell();
  373. textcell.Value = "检验项目";
  374. headerRow.Cells.Add(textcell);
  375. textcell = new DataGridViewTextBoxCell();
  376. textcell.Value = "不通过";
  377. headerRow.Cells.Add(textcell);
  378. textcell = new DataGridViewTextBoxCell();
  379. textcell.Value = "缺陷等级";
  380. headerRow.Cells.Add(textcell);
  381. textcell = new DataGridViewTextBoxCell();
  382. textcell.Value = "备注";
  383. headerRow.Cells.Add(textcell);
  384. textcell = new DataGridViewTextBoxCell();
  385. textcell.Value = "检验状态";
  386. headerRow.Cells.Add(textcell);
  387. headerRow.ReadOnly = true;
  388. CollapseDataGridViewRow cl = new CollapseDataGridViewRow();
  389. try
  390. {
  391. cl = (CollapseDataGridViewRow)(CheckTypeDGV.Rows[e.RowIndex]);
  392. }
  393. catch
  394. {
  395. }
  396. cl.Rows.Add(headerRow);
  397. for (int i = 0; i < dt.Rows.Count; i++)
  398. {
  399. DataGridViewRow dataRow = new DataGridViewRow();
  400. //标记展开的子行
  401. dataRow.Tag = "SonRow";
  402. DataGridViewCheckBoxCell checkcell = new DataGridViewCheckBoxCell();
  403. checkcell.Tag = "SonRow";
  404. checkcell.Value=true;
  405. dataRow.Cells.Add(checkcell);
  406. textcell = new DataGridViewTextBoxCell();
  407. textcell.Value = dt.Rows[i]["oi_itemcode"].ToString();
  408. dataRow.Cells.Add(textcell);
  409. textcell.ReadOnly = true;
  410. DataGridViewCheckBoxCell checkcel2 = new DataGridViewCheckBoxCell();
  411. checkcel2.Value = dt.Rows[i]["oi_ng"].ToString() != "0" ? true : false;
  412. dataRow.Cells.Add(checkcel2);
  413. textcell.ReadOnly = false;
  414. DataGridViewComboBoxCell combocell = new DataGridViewComboBoxCell();
  415. BaseUtil.SetDGVCellComboxData(combocell, "display", "value", LevelDefect);
  416. combocell.Value = dt.Rows[i]["oi_leveldefect"].ToString();
  417. dataRow.Cells.Add(combocell);
  418. textcell.ReadOnly = false;
  419. textcell = new DataGridViewTextBoxCell();
  420. textcell.Value = dt.Rows[i]["ois_remark"].ToString();
  421. dataRow.Cells.Add(textcell);
  422. textcell.ReadOnly = false;
  423. textcell = new DataGridViewTextBoxCell();
  424. textcell.Value = dt.Rows[i]["ois_status"].ToString();
  425. dataRow.Cells.Add(textcell);
  426. textcell.ReadOnly = true;
  427. textcell = new DataGridViewTextBoxCell();
  428. textcell.Value = dt.Rows[i]["ois_id"].ToString();
  429. dataRow.Cells.Add(textcell);
  430. cl.Rows.Add(dataRow);
  431. }
  432. dgvr.Add(CheckTypeDGV.Rows[e.RowIndex]);
  433. }
  434. }
  435. private void CheckTypeDGV_DataError(object sender, DataGridViewDataErrorEventArgs e) { }
  436. private void WaitChooseDGV_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
  437. {
  438. if (!dgvr.Contains(WaitChooseDGV.Rows[e.RowIndex]))
  439. {
  440. string bg_code = WaitChooseDGV.Rows[e.RowIndex].Cells["bg_code"].Value.ToString();
  441. DataTable dt = (DataTable)dh.ExecuteSql("select bc_code,bc_name from BADCODE where bc_groupcode='" + bg_code + "'", "select");
  442. DataGridViewRow headerRow = new DataGridViewRow();
  443. DataGridViewTextBoxCell textcell = new DataGridViewTextBoxCell();
  444. textcell.Value = "";
  445. headerRow.Cells.Add(textcell);
  446. textcell = new DataGridViewTextBoxCell();
  447. textcell.Value = "不良代码";
  448. headerRow.Cells.Add(textcell);
  449. textcell = new DataGridViewTextBoxCell();
  450. textcell.Value = "不良原因";
  451. headerRow.Cells.Add(textcell);
  452. headerRow.ReadOnly = true;
  453. CollapseDataGridViewRow cl = new CollapseDataGridViewRow();
  454. try
  455. {
  456. cl = (CollapseDataGridViewRow)(WaitChooseDGV.Rows[e.RowIndex]);
  457. }
  458. catch (Exception) { }
  459. cl.Rows.Add(headerRow);
  460. for (int i = 0; i < dt.Rows.Count; i++)
  461. {
  462. DataGridViewRow dataRow = new DataGridViewRow();
  463. //标记展开的子行
  464. dataRow.Tag = "SonRow";
  465. DataGridViewCheckBoxCell checkcell = new DataGridViewCheckBoxCell();
  466. checkcell.Tag = "SonRow";
  467. dataRow.Cells.Add(checkcell);
  468. textcell = new DataGridViewTextBoxCell();
  469. textcell.Value = dt.Rows[i]["bc_code"].ToString();
  470. dataRow.Cells.Add(textcell);
  471. textcell = new DataGridViewTextBoxCell();
  472. textcell.Value = dt.Rows[i]["bc_name"].ToString();
  473. dataRow.Cells.Add(textcell);
  474. cl.Rows.Add(dataRow);
  475. }
  476. dgvr.Add(WaitChooseDGV.Rows[e.RowIndex]);
  477. }
  478. }
  479. //如果当前行的Cell有修改过就将CheckBox勾选上
  480. private void CheckTypeDGV_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  481. {
  482. if (e.RowIndex > 0 && e.ColumnIndex > 0)
  483. CheckTypeDGV.Rows[e.RowIndex].Cells[0].Value = true;
  484. try
  485. {
  486. if (CheckTypeDGV.Rows[e.RowIndex].Cells[0].Tag != null)
  487. {
  488. if (CheckTypeDGV.Rows[e.RowIndex].Cells[0].Tag.ToString() == "SonRow")
  489. BaseUtil.GetExpandDGVCheckedRow(CheckTypeDGV, TempForCheckType, e.RowIndex, 1);
  490. }
  491. }
  492. catch (Exception)
  493. {
  494. }
  495. }
  496. private void WaitChooseDGV_DataError(object sender, DataGridViewDataErrorEventArgs e) { }
  497. private void WaitChooseDGV_CellContentClick(object sender, DataGridViewCellEventArgs e)
  498. {
  499. BaseUtil.ExpandDGVCheck(WaitChooseDGV, e);
  500. }
  501. private void CheckTypeDGV_CellContentClick(object sender, DataGridViewCellEventArgs e)
  502. {
  503. BaseUtil.ExpandDGVCheck(CheckTypeDGV, e);
  504. }
  505. private void bccode_KeyDown(object sender, KeyEventArgs e)
  506. {
  507. if (e.KeyCode == Keys.Enter)
  508. {
  509. dt = (DataTable)dh.ExecuteSql("select bc_code bg_code,bc_name bg_name from badgroup left join badcode on bg_code=bc_groupcode where bc_code='" + bccode.Text + "'", "select");
  510. if (dt.Rows.Count > 0)
  511. {
  512. try
  513. {
  514. dt.Merge(ChoosedDGV.DataSource as DataTable);
  515. BaseUtil.FillDgvWithDataTable(ChoosedDGV, dt);
  516. }
  517. catch (Exception) { }
  518. }
  519. else OperateResult.AppendText(">>不良代码不存在\n", Color.Red);
  520. }
  521. }
  522. private void ob_checkno_KeyDown(object sender, KeyEventArgs e)
  523. {
  524. if (e.KeyCode == Keys.Enter)
  525. {
  526. GetBatch.PerformClick();
  527. }
  528. }
  529. private void ms_sncode_KeyDown(object sender, KeyEventArgs e)
  530. {
  531. if (e.KeyCode == Keys.Enter)
  532. GetBatch.PerformClick();
  533. }
  534. private void obd_outboxcode_KeyDown(object sender, KeyEventArgs e)
  535. {
  536. if (e.KeyCode == Keys.Enter)
  537. GetBatch.PerformClick();
  538. }
  539. private void WaitChooseDGV_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  540. {
  541. try
  542. {
  543. if (e.ColumnIndex == 0)
  544. {
  545. if (WaitChooseDGV.Rows[e.RowIndex].Cells[0].Tag != null)
  546. {
  547. if (WaitChooseDGV.Rows[e.RowIndex].Cells[0].Tag.ToString() == "SonRow")
  548. BaseUtil.GetExpandDGVCheckedRow(WaitChooseDGV, TempForBadGroup, e.RowIndex, 1);
  549. }
  550. }
  551. }
  552. catch (Exception)
  553. {
  554. }
  555. }
  556. }
  557. }