OQC_SamplingDataCollection.cs 27 KB

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