OQC_SamplingDataCollection.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  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_NEW.CustomControl.DataGrid_View;
  8. using UAS_MES_NEW.DataOperate;
  9. using UAS_MES_NEW.Entity;
  10. using UAS_MES_NEW.PublicMethod;
  11. namespace UAS_MES_NEW.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[] { "CR#CR", "MI#MI", "MA#MA" };
  22. string ifrework = "";
  23. DataTable TempForCheckType = 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.SetDgvColumnComboxData((DataGridViewComboBoxColumn)CheckTypeDGV.Columns["oi_leveldefect"], "oi_leveldefect", "display", "value", LevelDefect);
  33. dh = SystemInf.dh;
  34. }
  35. private void 抽样数据采集_SizeChanged(object sender, EventArgs e)
  36. {
  37. asc.controlAutoSize(this);
  38. }
  39. private void GetBatch_Click(object sender, EventArgs e)
  40. {
  41. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
  42. {
  43. DataTable temp = dh.getFieldsDatasByCondition("makeserial", new string[] { "nvl(ms_ifrework,0)ms_ifrework", "ms_reworkcheckno", "ms_reworkstatus" }, "(ms_sncode)='" + sncode.Text + "' order by ms_id desc");
  44. if (temp.Rows.Count > 0)
  45. {
  46. if (temp.Rows[0]["ms_reworkstatus"].ToString() == "3")
  47. {
  48. OperateResult.AppendText(">>返修的不良序列号必须先进行维修\n", Color.Red);
  49. return;
  50. }
  51. ifrework = temp.Rows[0]["ms_ifrework"].ToString();
  52. if (ifrework != "0")
  53. {
  54. ob_checkno.Text = temp.Rows[0]["ms_reworkcheckno"].ToString();
  55. }
  56. }
  57. DataTable[] dt = LogicHandler.GetOQCBatch(ms_sncode.Text == "" ? sncode.Text : ms_sncode.Text, obd_outboxcode.Text, ob_checkno.Text, "OQCDataCollection", out ErrorMessage);
  58. if (ErrorMessage == "")
  59. {
  60. BaseUtil.SetFormValue(Controls, dt[0]);
  61. //如果已经判定过则不可再编辑
  62. if (ob_status.Text == "OK" || ob_status.Text == "NG" || ob_status.Text == "FOK" || ob_status.Text == "FNG")
  63. {
  64. BatchPass.Enabled = false;
  65. }
  66. else
  67. {
  68. BatchPass.Enabled = true;
  69. }
  70. oi_checkqty1.Text = dh.getFieldDataByCondition("oqcitems", "max(oi_sampleqty)", "oi_checkno='" + ob_checkno.Text + "'").ToString();
  71. dgvr.Clear();
  72. }
  73. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  74. }
  75. else
  76. {
  77. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  78. }
  79. }
  80. private void Clean_Click(object sender, EventArgs e)
  81. {
  82. OperateResult.Clear();
  83. }
  84. private void sncode_KeyDown(object sender, KeyEventArgs e)
  85. {
  86. if (e.KeyCode == Keys.Enter)
  87. {
  88. GetBatch.PerformClick();
  89. if (CheckSnCode())
  90. {
  91. dt = (DataTable)dh.ExecuteSql("select or_id,or_badcode bc_code,or_description bc_name,or_bgcode bg_code,bg_name from OQCNGReason left join badgroup on or_bgcode=bg_code where or_checkno='" + ob_checkno.Text + "' and or_sncode='" + sncode.Text + "'", "select");
  92. BaseUtil.FillDgvWithDataTable(ChoosedDGV, dt);
  93. GetBatchTypeGridData();
  94. }
  95. }
  96. }
  97. private bool CheckSnCode()
  98. {
  99. //输入的序列号不能为空
  100. if (sncode.Text != "")
  101. {
  102. //判断当前的检验状态
  103. if (ob_status.Text == "待检验" || ob_status.Text == "检验中")
  104. {
  105. DataTable temp = dh.getFieldsDatasByCondition("makeserial", new string[] { "nvl(ms_ifrework,0)ms_ifrework", "ms_reworkcheckno", "ms_reworkstatus" }, "(ms_sncode)='" + sncode.Text + "' order by ms_id desc");
  106. if (temp.Rows.Count > 0)
  107. {
  108. if (temp.Rows[0]["ms_reworkstatus"].ToString() == "3")
  109. {
  110. OperateResult.AppendText(">>返修的不良序列号必须先进行维修\n", Color.Red);
  111. return false;
  112. }
  113. }
  114. dt = (DataTable)dh.ExecuteSql("select obd_sncode,ob_source,obd_makecode from OQCBatchDetail left join OQCBatch on ob_id=obd_obid where obd_sncode='" + sncode.Text + "' and ob_checkno='" + ob_checkno.Text + "'", "select");
  115. if (dt.Rows.Count > 0)
  116. {
  117. if (dt.Rows[0]["ob_source"].ToString() != "工序")
  118. {
  119. return true;
  120. }
  121. else
  122. {
  123. string ErrorMessage = "";
  124. string oMakeCode = "";
  125. string oMsID = "";
  126. if (LogicHandler.CheckStepSNAndMacode(dt.Rows[0]["obd_makecode"].ToString(), User.UserSourceCode, sncode.Text, User.UserCode, out oMakeCode, out oMsID, out ErrorMessage))
  127. {
  128. return true;
  129. }
  130. else
  131. {
  132. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  133. return false;
  134. }
  135. }
  136. }
  137. else
  138. {
  139. OperateResult.AppendText(">>序列号" + sncode.Text + "不属于当前抽检批次\n", Color.Red);
  140. return false;
  141. }
  142. }
  143. else
  144. {
  145. OperateResult.AppendText(">>送检批次必须是待检验或者检验中\n", Color.Red);
  146. return false;
  147. }
  148. }
  149. else
  150. {
  151. OperateResult.AppendText(">>序列号不能为空\n", Color.Red);
  152. return false;
  153. }
  154. }
  155. private void GetBatchTypeGridData()
  156. {
  157. 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");
  158. if (dt.Rows.Count == 0)
  159. {
  160. OperateResult.AppendText(">>请先维护抽样计划\n", Color.Red);
  161. return;
  162. }
  163. string checkkind = "";
  164. for (int i = 0; i < dt.Rows.Count; i++)
  165. {
  166. checkkind += ("'" + dt.Rows[i]["oi_checkkind"].ToString() + "',");
  167. }
  168. sql.Clear();
  169. sql.Append("select 1 choose,ci_name,oi_itemcode,oi_checkkind,oi_sampleqty,nvl((oi_checkqty),0) oi_checkqty, ");
  170. sql.Append("nvl(ois_id,0) ois_id,nvl(ois_ifng,0) oi_ng,nvl(ois_defectlevel,'-1') oi_leveldefect, ");
  171. sql.Append("ois_remark,case nvl(ois_id,0) when 0 then '未检验' else '已检验' end ois_status ");
  172. sql.Append("from OQCItems left join QUA_CHECKITEM on oi_itemcode=ci_code left join OQCItemSamples on ois_sncode='" + sncode.Text + "' and ois_checkno=oi_checkno and ");
  173. sql.Append("ois_itemcode=oi_itemcode and ois_projectcode = oi_projectcode where oi_checkno ='" + ob_checkno.Text + "' ");
  174. sql.Append("and oi_checkkind in (" + checkkind.Substring(0, checkkind.Length - 1) + ")");
  175. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  176. BaseUtil.FillDgvWithDataTable(CheckTypeDGV, dt);
  177. sql.Clear();
  178. sql.Append("select bg_code,bg_code||':'||bg_name bg_name from PRODUCTBADGROUP left join productkind on ");
  179. sql.Append("pk_code= pb_kindcode left join product on pr_kind=pk_name left join ");
  180. sql.Append("badgroup on bg_code=pb_badgroup where pr_code='" + ob_prodcode.Text + "'");
  181. BadCode = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  182. if (BadCode.Rows.Count > 0)
  183. {
  184. BadGroupCode.DisplayMember = "bg_name";
  185. BadGroupCode.ValueMember = "bg_code";
  186. BadGroupCode.DataSource = BadCode;
  187. }
  188. else
  189. {
  190. BadCode = (DataTable)dh.ExecuteSql("select bg_code,bg_name from badgroup where bg_statuscode='AUDITED'", "select");
  191. BadGroupCode.DisplayMember = "bg_name";
  192. BadGroupCode.ValueMember = "bg_code";
  193. BadGroupCode.DataSource = BadCode;
  194. }
  195. }
  196. private void Confirm_Click(object sender, EventArgs e)
  197. {
  198. //只能操作检验中或者待检验的批次
  199. if (ob_status.Text == "待检验" || ob_status.Text == "检验中")
  200. {
  201. if (!CheckSnCode())
  202. return;
  203. //判断检验项是否勾选,如勾选取出明细数据
  204. DataTable dt = (DataTable)CheckTypeDGV.DataSource;
  205. //判断是否有勾选的明
  206. DataTable Savedt = BaseUtil.filterDataTable(dt, "choose<>0");
  207. if (Savedt.Rows.Count > 0)
  208. {
  209. bool IfContainNG = false;
  210. for (int i = 0; i < Savedt.Rows.Count; i++)
  211. {
  212. string if_ng = Savedt.Rows[i]["oi_ng"].ToString();
  213. if (if_ng != "0" && if_ng != "")
  214. {
  215. IfContainNG = true;
  216. }
  217. }
  218. if (!IfContainNG && ChoosedDGV.Rows.Count > 0)
  219. {
  220. OperateResult.AppendText(">>全部通过不允许勾选不良代码\n", Color.Red);
  221. return;
  222. }
  223. if ((IfContainNG && ChoosedDGV.RowCount > 0) || !IfContainNG)
  224. {
  225. //用于存放更新的数据
  226. List<string> ois_ifng_update = new List<string>();
  227. List<string> ois_defectlevel_update = new List<string>();
  228. List<string> ois_remark_update = new List<string>();
  229. List<string> ois_id_update = new List<string>();
  230. //用于存放插入的数据
  231. List<string> ois_ifng_insert = new List<string>();
  232. List<string> ois_defectlevel_insert = new List<string>();
  233. List<string> ois_remark_insert = new List<string>();
  234. List<string> oi_itemcode_insert = new List<string>();
  235. for (int i = 0; i < Savedt.Rows.Count; i++)
  236. {
  237. //将布尔值转换为0,-1
  238. if (Savedt.Rows[i]["ois_id"].ToString() != "" && Savedt.Rows[i]["ois_id"].ToString() != "0")
  239. {
  240. ois_ifng_update.Add(Savedt.Rows[i]["oi_ng"].ToString());
  241. ois_defectlevel_update.Add(Savedt.Rows[i]["oi_leveldefect"].ToString());
  242. ois_remark_update.Add(Savedt.Rows[i]["ois_remark"].ToString());
  243. ois_id_update.Add(Savedt.Rows[i]["ois_id"].ToString());
  244. }
  245. else
  246. {
  247. oi_itemcode_insert.Add(Savedt.Rows[i]["oi_itemcode"].ToString());
  248. ois_ifng_insert.Add(Savedt.Rows[i]["oi_ng"].ToString());
  249. ois_defectlevel_insert.Add(Savedt.Rows[i]["oi_leveldefect"].ToString());
  250. ois_remark_insert.Add(Savedt.Rows[i]["ois_remark"].ToString());
  251. }
  252. }
  253. //执行批量更新的SQL
  254. if (ois_id_update.Count > 0)
  255. {
  256. 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",
  257. 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());
  258. }
  259. //如果主键为空,并且存在需要插入的数据则执行插入操作
  260. if (oi_itemcode_insert.Count > 0)
  261. {
  262. string[] id = new string[oi_itemcode_insert.Count];
  263. id = dh.GetSEQ("OQCItemSamples_SEQ", id.Length);
  264. sql.Clear();
  265. //when () then
  266. sql.Append("insert into OQCItemSamples (ois_id,ois_checkno,ois_makecode, ois_sncode,ois_projectcode,ois_itemcode,");
  267. sql.Append("ois_ifng,ois_defectlevel,ois_remark,ois_indate)select :id,'" + ob_checkno.Text + "','" + ob_makecode.Text + "'");
  268. sql.Append(",'" + sncode.Text + "','" + ob_projectcode.Text + "',:ois_itemcode,:ois_ifng,:ois_defectlevel,:ois_remark,sysdate from dual ");
  269. sql.Append("where not exists (select ois_id from OQCItemSamples where ois_checkno='" + ob_checkno.Text + "' and ois_sncode='" + sncode.Text + "' and ois_itemcode =:ois_itemcode)");
  270. dh.BatchInsert(sql.GetString(), new string[] { "id", "ois_itemcode", "ois_ifng", "ois_defectlevel", "ois_remark", "ois_itemcode" },
  271. id, oi_itemcode_insert.ToArray(), ois_ifng_insert.ToArray(), ois_defectlevel_insert.ToArray(), ois_remark_insert.ToArray(), oi_itemcode_insert.ToArray());
  272. }
  273. //采集不良信息
  274. List<string> bc_code = new List<string>();
  275. List<string> bc_name = new List<string>();
  276. List<string> bg_code = new List<string>();
  277. List<string> bg_name = new List<string>();
  278. for (int i = 0; i < ChoosedDGV.RowCount; i++)
  279. {
  280. bc_code.Add(ChoosedDGV.Rows[i].Cells["bc_code1"].Value.ToString());
  281. bc_name.Add(ChoosedDGV.Rows[i].Cells["bc_name1"].Value.ToString());
  282. bg_code.Add(ChoosedDGV.Rows[i].Cells["bg_code1"].Value.ToString());
  283. bg_name.Add(ChoosedDGV.Rows[i].Cells["bg_name1"].Value.ToString());
  284. }
  285. dh.ExecuteSql("delete from OQCNGReason where or_sncode='" + sncode.Text + "' and or_checkno='" + ob_checkno.Text + "'", "delete");
  286. if (bc_name.Count > 0)
  287. {
  288. //dh.UpdateByCondition("makeserial", "ms_badtimes=ms_badtimes+1", "ms_sncode='" + sncode.Text + "'");
  289. sql.Clear();
  290. sql.Append("insert into OQCNGReason(or_id, or_checkno, or_makecode, or_sncode, or_badcode, or_description, or_remark,or_bgcode)");
  291. sql.Append("values (OQCNGReason_seq.nextval,'" + ob_checkno.Text + "','" + ob_makecode.Text + "','" + sncode.Text + "',:a,:b,'" + ob_remark.Text + "',:c)");
  292. dh.BatchInsert(sql.GetString(), new string[] { "a", "b", "c" }, bc_code.ToArray(), bc_name.ToArray(), bg_code.ToArray());
  293. //插入MakeBad表
  294. sql.Clear();
  295. sql.Append("insert into makebad(mb_id,mb_makecode,mb_mscode,mb_sncode,mb_inman,mb_indate,mb_stepcode");
  296. sql.Append(",mb_sourcecode,mb_badcode,mb_bgcode,mb_badtable,mb_soncode,mb_badname,mb_status,mb_bgname,mb_type)");
  297. sql.Append("select makebad_seq.nextval,ma_code,ms_code,ms_sncode,'" + User.UserCode + "',sysdate,'" + User.CurrentStepCode + "',ms_sourcecode,:bc_code,:bg_code,'',");
  298. sql.Append("sp_soncode,:bc_name,'0',:bg_name,'Client' from make left join makeSerial on ms_makecode=ma_code left join stepProduct on ");
  299. sql.Append("sp_mothercode=ma_prodcode and sp_stepcode=ms_nextstepcode where ms_sncode='" + sncode.Text + "' and ms_makecode='" + ob_makecode.Text + "'");
  300. dh.BatchInsert(sql.GetString(), new string[] { "bc_code", "bg_code", "bc_name", "bg_name" }, bc_code.ToArray(), bg_code.ToArray(), bc_name.ToArray(), bg_name.ToArray());
  301. dh.ExecuteSql("update oqcbatchdetail set obd_ifng = -1 where obd_checkno='" + ob_checkno.Text + "' and obd_sncode='" + sncode.Text + "'", "update");
  302. }
  303. //更新项目编号中的抽检数、不合格数,根据采样项目记录
  304. sql.Clear();
  305. sql.Append("UPDATE OQCItems SET (oi_ngqty,oi_checkqty)=(select nvl(sum(case when ");
  306. sql.Append("nvl(ois_ifng,0)=0 then 0 else 1 end),0) ,count(1) from OQCItemSamples where ois_checkno=oi_checkno ");
  307. sql.Append("and ois_itemcode=oi_itemcode)where oi_checkno ='" + ob_checkno.Text + "' and oi_projectcode ='" + ob_projectcode.Text + "'");
  308. dh.ExecuteSql(sql.GetString(), "update");
  309. //更新检验状态,如果是待检验的更新为检验中
  310. if (ob_status.Text == "待检验")
  311. {
  312. dh.ExecuteSql("update OQCBatch set ob_status='CHECKING' where ob_checkno='" + ob_checkno.Text + "' and ob_status='UNCHECK'", "update");
  313. //如果返工的不需要更新数量
  314. if (!(ifrework != "0" && ifrework != ""))
  315. {
  316. sql.Clear();
  317. sql.Append("update makecraftdetail set mcd_inqty=nvl(mcd_inqty,0)+ nvl((select count(1) from oqcbatchdetail ");
  318. sql.Append("where obd_checkno='" + ob_checkno.Text + "' and obd_makecode=mcd_macode),0) ");
  319. sql.Append("where mcd_macode in(select distinct obd_makecode from oqcbatchdetail ");
  320. sql.Append("where obd_checkno='" + ob_checkno.Text + "') and mcd_stepcode='" + User.CurrentStepCode + "'");
  321. dh.ExecuteSql(sql.GetString(), "select");
  322. }
  323. }
  324. //更新批次中的合格数不合格数:用抽检批检验项目表获取最大的抽检数和不合格数
  325. sql.Clear();
  326. sql.Append("select count(1)from (select ois_sncode from OQCITEMSAMPLES where ");
  327. sql.Append("ois_checkno = '" + ob_checkno.Text + "' and ois_ifng = 1 group by ois_sncode)");
  328. string ngqty = (dh.ExecuteSql(sql.GetString(), "select") as DataTable).Rows[0][0].ToString();
  329. string checkqty = dh.getFieldDataByCondition("OQCItems", "max(oi_checkqty)", "oi_checkno ='" + ob_checkno.Text + "'").ToString();
  330. dh.ExecuteSql("update OQCBATCH set ob_ngqty='" + ngqty + "',ob_actsampleqty='" + checkqty + "',ob_okqty=('" + checkqty + "'-'" + ngqty + "') where ob_checkno ='" + ob_checkno.Text + "'", "update");
  331. OperateResult.AppendText(">>序列号" + sncode.Text + "操作成功\n", Color.Green);
  332. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, "", User.UserLineCode, User.UserSourceCode, "抽样数据采集", "检验项目采集成功", sncode.Text, ob_checkno.Text);
  333. dh.ExecuteSql("update oqcbatchdetail set obd_ifcheck = '-1' where obd_checkno='" + ob_checkno.Text + "' and obd_sncode='" + sncode.Text + "'", "update");
  334. ChoosedDGV.DataSource = null;
  335. BaseUtil.CleanDGVData(CheckTypeDGV);
  336. BaseUtil.CleanDGVData(WaitChooseDGV);
  337. sncode.Text = "";
  338. sncode.Focus();
  339. GetBatch.PerformClick();
  340. }
  341. else OperateResult.AppendText(">>含有未通过项请勾选不良明细\n", Color.Red);
  342. }
  343. else OperateResult.AppendText(">>请勾选送检明细\n", Color.Red);
  344. }
  345. else OperateResult.AppendText(">>必须是待检验或者检测中的送检批才能进行此操作\n", Color.Red);
  346. }
  347. private void BatchPass_Click(object sender, EventArgs e)
  348. {
  349. if (CheckBefore())
  350. {
  351. if (int.Parse(ob_ngqty.Text == "" ? "0" : ob_ngqty.Text) <= int.Parse(ob_maxngacceptqty.Text == "" ? "0" : ob_maxngacceptqty.Text))
  352. {
  353. string ReworkCode = "";
  354. if (LogicHandler.OQCBatchJudge(ob_checkno.Text, User.UserSourceCode, "OK", "", User.UserCode, ob_remark.Text, out ReworkCode, out ErrorMessage))
  355. {
  356. GetBatch.PerformClick();
  357. BatchPass.Enabled = false;
  358. OperateResult.AppendText(">>" + ob_checkno.Text + "通过批成功\n", Color.Green);
  359. //记录操作日志
  360. }
  361. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  362. }
  363. else OperateResult.AppendText(">>当前批次不合格数为" + ob_ngqty.Text + ",大于最大不合格允通过数" + ob_maxngacceptqty.Text + "\n", Color.Red);
  364. }
  365. }
  366. private bool CheckBefore()
  367. {
  368. if (ob_maxngacceptqty.Text == "")
  369. {
  370. if (ob_aqlcode.Text == "")
  371. OperateResult.AppendText(">>最大不合格允许通过数为空的时候必须填写维护AQL标准\n", Color.Red);
  372. else
  373. {
  374. 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");
  375. if (dt.Rows.Count > 0)
  376. {
  377. for (int i = 0; i < dt.Rows.Count; i++)
  378. {
  379. int batchqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text);
  380. int minqty = int.Parse(dt.Rows[i]["ad_minqty"].ToString());
  381. int maxqty = int.Parse(dt.Rows[i]["ad_maxqty"].ToString());
  382. if (batchqty > minqty && batchqty <= maxqty)
  383. {
  384. ob_maxngacceptqty.Text = dt.Rows[i]["ad_maxngacceptqty"].ToString();
  385. return true;
  386. }
  387. }
  388. }
  389. }
  390. }
  391. else
  392. {
  393. return true;
  394. }
  395. return false;
  396. }
  397. private void WaitReject_Click(object sender, EventArgs e)
  398. {
  399. for (int i = ChoosedDGV.Rows.Count - 1; i >= 0; i--)
  400. {
  401. if (ChoosedDGV.Rows[i].Cells["choose1"].FormattedValue.ToString() == "True")
  402. {
  403. ChoosedDGV.Rows.RemoveAt(i);
  404. }
  405. }
  406. (ChoosedDGV.DataSource as DataTable).AcceptChanges();
  407. }
  408. private void ChooseedReject_Click(object sender, EventArgs e)
  409. {
  410. DataTable wait = BaseUtil.filterDataTable((DataTable)WaitChooseDGV.DataSource, "ChooseAll<>0");
  411. DataTable choose = (ChoosedDGV.DataSource as DataTable);
  412. List<string> Chooseed = new List<string>();
  413. for (int i = 0; i < choose.Rows.Count; i++)
  414. {
  415. Chooseed.Add(choose.Rows[i]["bc_code"].ToString());
  416. }
  417. if (wait.Rows.Count > 0)
  418. {
  419. for (int i = 0; i < wait.Rows.Count; i++)
  420. {
  421. if (!Chooseed.Contains(wait.Rows[i]["bc_code"].ToString()))
  422. {
  423. DataRow dr1 = choose.NewRow();
  424. dr1["bc_code"] = wait.Rows[i]["bc_code"];
  425. dr1["bc_name"] = wait.Rows[i]["bc_name"];
  426. dr1["bg_code"] = wait.Rows[i]["bg_code"];
  427. dr1["bg_name"] = wait.Rows[i]["bg_name"];
  428. choose.Rows.Add(dr1);
  429. }
  430. }
  431. for (int i = 0; i < WaitChooseDGV.Rows.Count; i++)
  432. {
  433. ((DataTable)WaitChooseDGV.DataSource).Rows[i]["ChooseAll"] = 0;
  434. }
  435. }
  436. else OperateResult.AppendText(">>请勾选不良明细\n", Color.Red);
  437. }
  438. private void CheckTypeDGV_DataError(object sender, DataGridViewDataErrorEventArgs e) { }
  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. }
  445. private void WaitChooseDGV_DataError(object sender, DataGridViewDataErrorEventArgs e) { }
  446. private void bccode_KeyDown(object sender, KeyEventArgs e)
  447. {
  448. if (e.KeyCode == Keys.Enter)
  449. {
  450. dt = (DataTable)dh.ExecuteSql("select bc_code bg_code,bc_name bg_name from badcode where bc_code='" + bccode.Text + "'", "select");
  451. if (dt.Rows.Count > 0)
  452. {
  453. try
  454. {
  455. for (int i = 0; i < ChoosedDGV.Rows.Count; i++)
  456. {
  457. if (ChoosedDGV.Rows[i].Cells[1].Value.ToString() == dt.Rows[0][0].ToString())
  458. {
  459. OperateResult.AppendText(">>已添加过不良代码" + bccode.Text + "\n", Color.Red);
  460. bccode.Clear();
  461. return;
  462. }
  463. }
  464. dt.Merge(ChoosedDGV.DataSource as DataTable);
  465. BaseUtil.FillDgvWithDataTable(ChoosedDGV, dt);
  466. bccode.Clear();
  467. }
  468. catch (Exception) { }
  469. }
  470. else OperateResult.AppendText(">>不良代码不存在\n", Color.Red);
  471. }
  472. }
  473. private void ob_checkno_KeyDown(object sender, KeyEventArgs e)
  474. {
  475. if (e.KeyCode == Keys.Enter)
  476. {
  477. GetBatch.PerformClick();
  478. }
  479. }
  480. private void ms_sncode_KeyDown(object sender, KeyEventArgs e)
  481. {
  482. if (e.KeyCode == Keys.Enter)
  483. GetBatch.PerformClick();
  484. }
  485. private void obd_outboxcode_KeyDown(object sender, KeyEventArgs e)
  486. {
  487. if (e.KeyCode == Keys.Enter)
  488. GetBatch.PerformClick();
  489. }
  490. private void BadGroupCode_SelectedIndexChanged(object sender, EventArgs e)
  491. {
  492. string bg_code = BadGroupCode.SelectedValue.ToString();
  493. sql.Clear();
  494. sql.Append("select 0 ChooseAll,bc_code,bc_name,bg_name,bg_code from badgroupdetail left join badgroup on bg_id=bgd_bgid ");
  495. sql.Append("left join badcode on bgd_badcode=bc_code where bg_code='" + ((bg_code != "" && bg_code != "System.Data.DataRowView") ? bg_code.ToString() : "") + "' and bg_code is not null ");
  496. sql.Append(" order by bc_code");
  497. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  498. BadInfoSource.DataSource = dt;
  499. BaseUtil.FillDgvWithDataTable(WaitChooseDGV, dt);
  500. }
  501. private void OQC_SamplingDataCollection_FormClosing(object sender, FormClosingEventArgs e)
  502. {
  503. dh.Dispose();
  504. }
  505. private void Filter_UserControlTextChanged(object sender, EventArgs e)
  506. {
  507. try
  508. {
  509. DataRow[] dr = (BadInfoSource.DataSource as DataTable).Select("bc_code like '%" + Filter.Text + "%' or bc_name like '%" + Filter.Text + "%'");
  510. DataTable dt = (BadInfoSource.DataSource as DataTable).Clone();
  511. for (int i = 0; i < dr.Length; i++)
  512. {
  513. dt.Rows.Add(dr[i].ItemArray);
  514. }
  515. BaseUtil.FillDgvWithDataTable(WaitChooseDGV, dt);
  516. }
  517. catch (Exception)
  518. {
  519. }
  520. }
  521. }
  522. }