OQC_SamplingDataCollection.cs 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  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. if (!checkBox1.Checked)
  96. {
  97. Confirm_Click(sender, e);
  98. }
  99. }
  100. }
  101. private bool CheckSnCode()
  102. {
  103. //输入的序列号不能为空
  104. if (sncode.Text != "")
  105. {
  106. //判断当前的检验状态
  107. if (ob_status.Text == "待检验" || ob_status.Text == "检验中")
  108. {
  109. 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");
  110. if (temp.Rows.Count > 0)
  111. {
  112. if (temp.Rows[0]["ms_reworkstatus"].ToString() == "3")
  113. {
  114. OperateResult.AppendText(">>返修的不良序列号必须先进行维修\n", Color.Red);
  115. return false;
  116. }
  117. }
  118. 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");
  119. if (dt.Rows.Count > 0)
  120. {
  121. if (dt.Rows[0]["ob_source"].ToString() != "工序")
  122. {
  123. return true;
  124. }
  125. else
  126. {
  127. string ErrorMessage = "";
  128. string oMakeCode = "";
  129. string oMsID = "";
  130. if (LogicHandler.CheckStepSNAndMacode(dt.Rows[0]["obd_makecode"].ToString(), User.UserSourceCode, sncode.Text, User.UserCode, out oMakeCode, out oMsID, out ErrorMessage))
  131. {
  132. return true;
  133. }
  134. else
  135. {
  136. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  137. return false;
  138. }
  139. }
  140. }
  141. else
  142. {
  143. string nowcheck = dh.getFieldDataByCondition("makeserial", "ms_checkno", "ms_sncode = '"+ sncode.Text + "' order by ms_id desc").ToString();
  144. OperateResult.AppendText(">>序列号" + sncode.Text + "所属批次:"+ nowcheck + ",不属于当前抽检批次\n", Color.Red);
  145. return false;
  146. }
  147. }
  148. else
  149. {
  150. OperateResult.AppendText(">>送检批次必须是待检验或者检验中\n", Color.Red);
  151. return false;
  152. }
  153. }
  154. else
  155. {
  156. OperateResult.AppendText(">>序列号不能为空\n", Color.Red);
  157. return false;
  158. }
  159. }
  160. private void GetBatchTypeGridData()
  161. {
  162. 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");
  163. if (dt.Rows.Count == 0)
  164. {
  165. OperateResult.AppendText(">>请先维护抽样计划\n", Color.Red);
  166. return;
  167. }
  168. string checkkind = "";
  169. for (int i = 0; i < dt.Rows.Count; i++)
  170. {
  171. checkkind += ("'" + dt.Rows[i]["oi_checkkind"].ToString() + "',");
  172. }
  173. sql.Clear();
  174. sql.Append("select 1 choose,ci_name,oi_itemcode,oi_checkkind,oi_sampleqty,nvl((oi_checkqty),0) oi_checkqty, ");
  175. sql.Append("nvl(ois_id,0) ois_id,nvl(ois_ifng,0) oi_ng,nvl(ois_defectlevel,'-1') oi_leveldefect, ");
  176. sql.Append("ois_remark,case nvl(ois_id,0) when 0 then '未检验' else '已检验' end ois_status ");
  177. 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 ");
  178. sql.Append("ois_itemcode=oi_itemcode and ois_projectcode = oi_projectcode where oi_checkno ='" + ob_checkno.Text + "' ");
  179. sql.Append("and oi_checkkind in (" + checkkind.Substring(0, checkkind.Length - 1) + ")");
  180. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  181. BaseUtil.FillDgvWithDataTable(CheckTypeDGV, dt);
  182. sql.Clear();
  183. sql.Append("select bg_code,bg_code||':'||bg_name bg_name from PRODUCTBADGROUP left join productkind on ");
  184. sql.Append("pk_code= pb_kindcode left join product on pr_kind=pk_name left join ");
  185. sql.Append("badgroup on bg_code=pb_badgroup where pr_code='" + ob_prodcode.Text + "'");
  186. BadCode = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  187. if (BadCode.Rows.Count > 0)
  188. {
  189. BadGroupCode.DisplayMember = "bg_name";
  190. BadGroupCode.ValueMember = "bg_code";
  191. BadGroupCode.DataSource = BadCode;
  192. }
  193. else
  194. {
  195. BadCode = (DataTable)dh.ExecuteSql("select bg_code,bg_name from badgroup where bg_statuscode='AUDITED'", "select");
  196. BadGroupCode.DisplayMember = "bg_name";
  197. BadGroupCode.ValueMember = "bg_code";
  198. BadGroupCode.DataSource = BadCode;
  199. }
  200. }
  201. private void Confirm_Click(object sender, EventArgs e)
  202. {
  203. //只能操作检验中或者待检验的批次
  204. if (ob_status.Text == "待检验" || ob_status.Text == "检验中")
  205. {
  206. if (!CheckSnCode())
  207. return;
  208. //判断检验项是否勾选,如勾选取出明细数据
  209. DataTable dt = (DataTable)CheckTypeDGV.DataSource;
  210. //判断是否有勾选的明
  211. DataTable Savedt = BaseUtil.filterDataTable(dt, "choose<>0");
  212. if (Savedt.Rows.Count > 0)
  213. {
  214. bool IfContainNG = false;
  215. for (int i = 0; i < Savedt.Rows.Count; i++)
  216. {
  217. string if_ng = Savedt.Rows[i]["oi_ng"].ToString();
  218. if (if_ng != "0" && if_ng != "")
  219. {
  220. IfContainNG = true;
  221. }
  222. }
  223. if (!IfContainNG && ChoosedDGV.Rows.Count > 0)
  224. {
  225. OperateResult.AppendText(">>全部通过不允许勾选不良代码\n", Color.Red);
  226. return;
  227. }
  228. if ((IfContainNG && ChoosedDGV.RowCount > 0) || !IfContainNG)
  229. {
  230. //用于存放更新的数据
  231. List<string> ois_ifng_update = new List<string>();
  232. List<string> ois_defectlevel_update = new List<string>();
  233. List<string> ois_remark_update = new List<string>();
  234. List<string> ois_id_update = new List<string>();
  235. //用于存放插入的数据
  236. List<string> ois_ifng_insert = new List<string>();
  237. List<string> ois_defectlevel_insert = new List<string>();
  238. List<string> ois_remark_insert = new List<string>();
  239. List<string> oi_itemcode_insert = new List<string>();
  240. for (int i = 0; i < Savedt.Rows.Count; i++)
  241. {
  242. //将布尔值转换为0,-1
  243. if (Savedt.Rows[i]["ois_id"].ToString() != "" && Savedt.Rows[i]["ois_id"].ToString() != "0")
  244. {
  245. ois_ifng_update.Add(Savedt.Rows[i]["oi_ng"].ToString());
  246. ois_defectlevel_update.Add(Savedt.Rows[i]["oi_leveldefect"].ToString());
  247. ois_remark_update.Add(Savedt.Rows[i]["ois_remark"].ToString());
  248. ois_id_update.Add(Savedt.Rows[i]["ois_id"].ToString());
  249. }
  250. else
  251. {
  252. oi_itemcode_insert.Add(Savedt.Rows[i]["oi_itemcode"].ToString());
  253. ois_ifng_insert.Add(Savedt.Rows[i]["oi_ng"].ToString());
  254. ois_defectlevel_insert.Add(Savedt.Rows[i]["oi_leveldefect"].ToString());
  255. ois_remark_insert.Add(Savedt.Rows[i]["ois_remark"].ToString());
  256. }
  257. }
  258. //执行批量更新的SQL
  259. if (ois_id_update.Count > 0)
  260. {
  261. 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",
  262. 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());
  263. }
  264. //如果主键为空,并且存在需要插入的数据则执行插入操作
  265. if (oi_itemcode_insert.Count > 0)
  266. {
  267. string[] id = new string[oi_itemcode_insert.Count];
  268. id = dh.GetSEQ("OQCItemSamples_SEQ", id.Length);
  269. sql.Clear();
  270. //when () then
  271. sql.Append("insert into OQCItemSamples (ois_id,ois_checkno,ois_makecode, ois_sncode,ois_projectcode,ois_itemcode,");
  272. sql.Append("ois_ifng,ois_defectlevel,ois_remark,ois_indate)select :id,'" + ob_checkno.Text + "','" + ob_makecode.Text + "'");
  273. sql.Append(",'" + sncode.Text + "','" + ob_projectcode.Text + "',:ois_itemcode,:ois_ifng,:ois_defectlevel,:ois_remark,sysdate from dual ");
  274. 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)");
  275. dh.BatchInsert(sql.GetString(), new string[] { "id", "ois_itemcode", "ois_ifng", "ois_defectlevel", "ois_remark", "ois_itemcode" },
  276. id, oi_itemcode_insert.ToArray(), ois_ifng_insert.ToArray(), ois_defectlevel_insert.ToArray(), ois_remark_insert.ToArray(), oi_itemcode_insert.ToArray());
  277. }
  278. //采集不良信息
  279. List<string> bc_code = new List<string>();
  280. List<string> bc_name = new List<string>();
  281. List<string> bg_code = new List<string>();
  282. List<string> bg_name = new List<string>();
  283. for (int i = 0; i < ChoosedDGV.RowCount; i++)
  284. {
  285. bc_code.Add(ChoosedDGV.Rows[i].Cells["bc_code1"].Value.ToString());
  286. bc_name.Add(ChoosedDGV.Rows[i].Cells["bc_name1"].Value.ToString());
  287. bg_code.Add(ChoosedDGV.Rows[i].Cells["bg_code1"].Value.ToString());
  288. bg_name.Add(ChoosedDGV.Rows[i].Cells["bg_name1"].Value.ToString());
  289. }
  290. dh.ExecuteSql("delete from OQCNGReason where or_sncode='" + sncode.Text + "' and or_checkno='" + ob_checkno.Text + "'", "delete");
  291. if (bc_name.Count > 0)
  292. {
  293. //dh.UpdateByCondition("makeserial", "ms_badtimes=ms_badtimes+1", "ms_sncode='" + sncode.Text + "'");
  294. sql.Clear();
  295. sql.Append("insert into OQCNGReason(or_id, or_checkno, or_makecode, or_sncode, or_badcode, or_description, or_remark,or_bgcode)");
  296. sql.Append("values (OQCNGReason_seq.nextval,'" + ob_checkno.Text + "','" + ob_makecode.Text + "','" + sncode.Text + "',:a,:b,'" + ob_remark.Text + "',:c)");
  297. dh.BatchInsert(sql.GetString(), new string[] { "a", "b", "c" }, bc_code.ToArray(), bc_name.ToArray(), bg_code.ToArray());
  298. //插入MakeBad表
  299. sql.Clear();
  300. sql.Append("insert into makebad(mb_id,mb_makecode,mb_mscode,mb_sncode,mb_inman,mb_indate,mb_stepcode");
  301. sql.Append(",mb_sourcecode,mb_badcode,mb_bgcode,mb_badtable,mb_soncode,mb_badname,mb_status,mb_bgname,mb_type,MB_DUTYSTEPCODE,MB_DUTYEMCODE)");
  302. sql.Append("select makebad_seq.nextval,ma_code,ms_code,ms_sncode,'" + User.UserCode + "',sysdate,'" + User.CurrentStepCode + "','"+User.UserSourceCode+"',:bc_code,:bg_code,'',");
  303. sql.Append("'',:bc_name,'0',:bg_name,'Client','"+User.CurrentStepCode+"','"+User.UserCode+"' from make left join makeSerial on ms_makecode=ma_code ");
  304. sql.Append(" where ms_sncode='" + sncode.Text + "' and ms_checkno='" + ob_checkno.Text + "'");
  305. 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());
  306. string makecode = dh.getFieldDataByCondition("makeserial", "ms_makecode", "ms_sncode='" + sncode.Text + "' and ms_checkno='" + ob_checkno.Text + "'").ToString();
  307. for (int i = 0; i < bc_code.Count; i++)
  308. {
  309. if (dh.CheckExist("badgroupdetail left join badgroup on bgd_bgid = bg_id", "bgd_badcode = '" + bc_code[i] + "' and bg_code = '" + bg_code[i] + "' and bgd_brcode is not null and bgd_dutycode is not null and bgd_solutioncode is not null "))
  310. {
  311. string makebadid = dh.getFieldDataByCondition("makebad", "mb_id", "mb_sncode = '" + sncode.Text + "' and mb_makecode = '" + makecode + "' and mb_badcode = '" + bc_code[i] + "' order by mb_id desc").ToString();
  312. DataTable temp = dh.getFieldsDatasByCondition(" badgroupdetail left join badgroup on bgd_bgid = bg_id left join QUA_NGReason on nr_code = bgd_brcode left join QUA_NGReasonGroup on nrg_code = bgd_brgcode left join NGDuty on nd_code = bgd_dutycode left join solution on so_code = bgd_solutioncode", new string[] { "bgd_brgcode", "bgd_dutycode", "bgd_solutioncode", "bgd_brcode", "nrg_name", "nr_name", "nd_name", "so_name" }, "bgd_badcode= '" + bc_code[i] + "' and bg_code = '" + bg_code[i] + "'");
  313. string bgd_brgcode = temp.Rows[0]["bgd_brgcode"].ToString();
  314. string bgd_brcode = temp.Rows[0]["bgd_brcode"].ToString();
  315. string bgd_dutycode = temp.Rows[0]["bgd_dutycode"].ToString();
  316. string bgd_solutioncode = temp.Rows[0]["bgd_solutioncode"].ToString();
  317. string mbr_id = dh.GetSEQ("makebadreason_seq");
  318. string bgd_brgname = temp.Rows[0]["nrg_name"].ToString();
  319. string bgd_brname = temp.Rows[0]["nr_name"].ToString();
  320. string bgd_dutyname = temp.Rows[0]["nd_name"].ToString();
  321. string bgd_solutionname = temp.Rows[0]["so_name"].ToString();
  322. sql.Clear();
  323. sql.Append("insert into makebadreason (mbr_mbid,mbr_id,mbr_brcode,mbr_solutioncode,");
  324. sql.Append("mbr_dutycode,mbr_brgcode,mbr_badcode,mbr_sncode,mbr_makecode,mbr_indate,");
  325. sql.Append("mbr_inman,mbr_brname,mbr_solutionname,mbr_badname,mbr_brgname,mbr_dutyname) select '" + makebadid + "','" + mbr_id + "','" + bgd_brcode + "',");
  326. sql.Append("'" + bgd_solutioncode + "','" + bgd_dutycode + "','" + bgd_brgcode + "','" + bc_code[i] + "',");
  327. sql.Append("'" + sncode.Text + "','" + makecode + "',sysdate,'" + User.UserCode + "','" + bgd_brname + "','" + bgd_solutionname + "','" + bc_name[i] + "','" + bgd_brgname + "','" + bgd_dutyname + "' from dual");
  328. dh.ExecuteSql(sql.GetString(), "insert");
  329. }
  330. }
  331. dh.ExecuteSql("update oqcbatchdetail set obd_ifng = -1,obd_checkdate = sysdate where obd_checkno='" + ob_checkno.Text + "' and obd_sncode='" + sncode.Text + "'", "update");
  332. }
  333. //更新项目编号中的抽检数、不合格数,根据采样项目记录
  334. sql.Clear();
  335. sql.Append("UPDATE OQCItems SET (oi_ngqty,oi_checkqty)=(select nvl(sum(case when ");
  336. sql.Append("nvl(ois_ifng,0)=0 then 0 else 1 end),0) ,count(1) from OQCItemSamples where ois_checkno=oi_checkno ");
  337. sql.Append("and ois_itemcode=oi_itemcode)where oi_checkno ='" + ob_checkno.Text + "' and oi_projectcode ='" + ob_projectcode.Text + "'");
  338. dh.ExecuteSql(sql.GetString(), "update");
  339. //更新检验状态,如果是待检验的更新为检验中
  340. if (ob_status.Text == "待检验")
  341. {
  342. dh.ExecuteSql("update OQCBatch set ob_status='CHECKING' where ob_checkno='" + ob_checkno.Text + "' and ob_status='UNCHECK'", "update");
  343. //如果返工的不需要更新数量
  344. if (!(ifrework != "0" && ifrework != ""))
  345. {
  346. sql.Clear();
  347. sql.Append("update makecraftdetail set mcd_inqty=nvl(mcd_inqty,0)+ nvl((select count(1) from oqcbatchdetail ");
  348. sql.Append("where obd_checkno='" + ob_checkno.Text + "' and obd_makecode=mcd_macode),0) ");
  349. sql.Append("where mcd_macode in(select distinct obd_makecode from oqcbatchdetail ");
  350. sql.Append("where obd_checkno='" + ob_checkno.Text + "') and mcd_stepcode='" + User.CurrentStepCode + "'");
  351. dh.ExecuteSql(sql.GetString(), "select");
  352. }
  353. }
  354. //更新批次中的合格数不合格数:用抽检批检验项目表获取最大的抽检数和不合格数
  355. sql.Clear();
  356. sql.Append("select count(1)from (select ois_sncode from OQCITEMSAMPLES where ");
  357. sql.Append("ois_checkno = '" + ob_checkno.Text + "' and ois_ifng = 1 group by ois_sncode)");
  358. string ngqty = (dh.ExecuteSql(sql.GetString(), "select") as DataTable).Rows[0][0].ToString();
  359. string checkqty = dh.getFieldDataByCondition("OQCItems", "max(oi_checkqty)", "oi_checkno ='" + ob_checkno.Text + "'").ToString();
  360. dh.ExecuteSql("update OQCBATCH set ob_ngqty='" + ngqty + "',ob_actsampleqty='" + checkqty + "',ob_okqty=('" + checkqty + "'-'" + ngqty + "') where ob_checkno ='" + ob_checkno.Text + "'", "update");
  361. if (!IfContainNG)
  362. {
  363. OperateResult.AppendText(">>序列号" + sncode.Text + "抽样良品\n", Color.Green);
  364. }
  365. else {
  366. OperateResult.AppendText(">>序列号" + sncode.Text + "抽样不良\n", Color.OrangeRed);
  367. }
  368. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, "", User.UserLineCode, User.UserSourceCode, "抽样数据采集", "检验项目采集成功", sncode.Text, ob_checkno.Text);
  369. dh.ExecuteSql("update oqcbatchdetail set obd_ifcheck = '-1',obd_checkdate = sysdate where obd_checkno='" + ob_checkno.Text + "' and obd_sncode='" + sncode.Text + "'", "update");
  370. ChoosedDGV.DataSource = null;
  371. BaseUtil.CleanDGVData(CheckTypeDGV);
  372. BaseUtil.CleanDGVData(WaitChooseDGV);
  373. sncode.Text = "";
  374. sncode.Focus();
  375. GetBatch.PerformClick();
  376. }
  377. else OperateResult.AppendText(">>含有未通过项请勾选不良明细\n", Color.Red);
  378. }
  379. else OperateResult.AppendText(">>请勾选送检明细\n", Color.Red);
  380. }
  381. else OperateResult.AppendText(">>必须是待检验或者检测中的送检批才能进行此操作\n", Color.Red);
  382. }
  383. private void BatchPass_Click(object sender, EventArgs e)
  384. {
  385. if (CheckBefore())
  386. {
  387. if (int.Parse(ob_ngqty.Text == "" ? "0" : ob_ngqty.Text) <= int.Parse(ob_maxngacceptqty.Text == "" ? "0" : ob_maxngacceptqty.Text))
  388. {
  389. string ReworkCode = "";
  390. if (LogicHandler.OQCBatchJudge(ob_checkno.Text, User.UserSourceCode, "OK", "", User.UserCode, ob_remark.Text, out ReworkCode, out ErrorMessage))
  391. {
  392. GetBatch.PerformClick();
  393. BatchPass.Enabled = false;
  394. OperateResult.AppendText(">>批次号" + ob_checkno.Text + "通过批成功\n", Color.Aquamarine);
  395. ob_checkno.Text = "";
  396. //记录操作日志
  397. }
  398. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  399. }
  400. else OperateResult.AppendText(">>当前批次不合格数为" + ob_ngqty.Text + ",大于最大不合格允通过数" + ob_maxngacceptqty.Text + "\n", Color.Red);
  401. }
  402. }
  403. private bool CheckBefore()
  404. {
  405. if (ob_maxngacceptqty.Text == "")
  406. {
  407. if (ob_aqlcode.Text == "")
  408. OperateResult.AppendText(">>最大不合格允许通过数为空的时候必须填写维护AQL标准\n", Color.Red);
  409. else
  410. {
  411. 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");
  412. if (dt.Rows.Count > 0)
  413. {
  414. for (int i = 0; i < dt.Rows.Count; i++)
  415. {
  416. int batchqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text);
  417. int minqty = int.Parse(dt.Rows[i]["ad_minqty"].ToString());
  418. int maxqty = int.Parse(dt.Rows[i]["ad_maxqty"].ToString());
  419. if (batchqty > minqty && batchqty <= maxqty)
  420. {
  421. ob_maxngacceptqty.Text = dt.Rows[i]["ad_maxngacceptqty"].ToString();
  422. return true;
  423. }
  424. }
  425. }
  426. }
  427. }
  428. else
  429. {
  430. return true;
  431. }
  432. return false;
  433. }
  434. private void WaitReject_Click(object sender, EventArgs e)
  435. {
  436. for (int i = ChoosedDGV.Rows.Count - 1; i >= 0; i--)
  437. {
  438. if (ChoosedDGV.Rows[i].Cells["choose1"].FormattedValue.ToString() == "True")
  439. {
  440. ChoosedDGV.Rows.RemoveAt(i);
  441. }
  442. }
  443. (ChoosedDGV.DataSource as DataTable).AcceptChanges();
  444. }
  445. private void ChooseedReject_Click(object sender, EventArgs e)
  446. {
  447. DataTable wait = BaseUtil.filterDataTable((DataTable)WaitChooseDGV.DataSource, "ChooseAll<>0");
  448. DataTable choose = (ChoosedDGV.DataSource as DataTable);
  449. List<string> Chooseed = new List<string>();
  450. for (int i = 0; i < choose.Rows.Count; i++)
  451. {
  452. Chooseed.Add(choose.Rows[i]["bc_code"].ToString());
  453. }
  454. if (wait.Rows.Count > 0)
  455. {
  456. for (int i = 0; i < wait.Rows.Count; i++)
  457. {
  458. if (!Chooseed.Contains(wait.Rows[i]["bc_code"].ToString()))
  459. {
  460. DataRow dr1 = choose.NewRow();
  461. dr1["bc_code"] = wait.Rows[i]["bc_code"];
  462. dr1["bc_name"] = wait.Rows[i]["bc_name"];
  463. dr1["bg_code"] = wait.Rows[i]["bg_code"];
  464. dr1["bg_name"] = wait.Rows[i]["bg_name"];
  465. choose.Rows.Add(dr1);
  466. }
  467. }
  468. for (int i = 0; i < WaitChooseDGV.Rows.Count; i++)
  469. {
  470. ((DataTable)WaitChooseDGV.DataSource).Rows[i]["ChooseAll"] = 0;
  471. }
  472. }
  473. else OperateResult.AppendText(">>请勾选不良明细\n", Color.Red);
  474. }
  475. private void CheckTypeDGV_DataError(object sender, DataGridViewDataErrorEventArgs e) { }
  476. //如果当前行的Cell有修改过就将CheckBox勾选上
  477. private void CheckTypeDGV_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  478. {
  479. if (e.RowIndex > 0 && e.ColumnIndex > 0)
  480. CheckTypeDGV.Rows[e.RowIndex].Cells[0].Value = true;
  481. }
  482. private void WaitChooseDGV_DataError(object sender, DataGridViewDataErrorEventArgs e) { }
  483. private void bccode_KeyDown(object sender, KeyEventArgs e)
  484. {
  485. if (e.KeyCode == Keys.Enter)
  486. {
  487. dt = (DataTable)dh.ExecuteSql("select bc_code bg_code,bc_name bg_name from badcode where bc_code='" + bccode.Text + "'", "select");
  488. if (dt.Rows.Count > 0)
  489. {
  490. try
  491. {
  492. for (int i = 0; i < ChoosedDGV.Rows.Count; i++)
  493. {
  494. if (ChoosedDGV.Rows[i].Cells[1].Value.ToString() == dt.Rows[0][0].ToString())
  495. {
  496. OperateResult.AppendText(">>已添加过不良代码" + bccode.Text + "\n", Color.Red);
  497. bccode.Clear();
  498. return;
  499. }
  500. }
  501. dt.Merge(ChoosedDGV.DataSource as DataTable);
  502. BaseUtil.FillDgvWithDataTable(ChoosedDGV, dt);
  503. bccode.Clear();
  504. }
  505. catch (Exception) { }
  506. }
  507. else OperateResult.AppendText(">>不良代码不存在\n", Color.Red);
  508. }
  509. }
  510. private void ob_checkno_KeyDown(object sender, KeyEventArgs e)
  511. {
  512. if (e.KeyCode == Keys.Enter)
  513. {
  514. GetBatch.PerformClick();
  515. }
  516. }
  517. private void ms_sncode_KeyDown(object sender, KeyEventArgs e)
  518. {
  519. if (e.KeyCode == Keys.Enter)
  520. GetBatch.PerformClick();
  521. }
  522. private void obd_outboxcode_KeyDown(object sender, KeyEventArgs e)
  523. {
  524. if (e.KeyCode == Keys.Enter)
  525. GetBatch.PerformClick();
  526. }
  527. private void BadGroupCode_SelectedIndexChanged(object sender, EventArgs e)
  528. {
  529. string bg_code = BadGroupCode.SelectedValue.ToString();
  530. sql.Clear();
  531. sql.Append("select 0 ChooseAll,bc_code,bc_name,bg_name,bg_code from badgroupdetail left join badgroup on bg_id=bgd_bgid ");
  532. 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 ");
  533. sql.Append(" order by bc_code");
  534. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  535. BadInfoSource.DataSource = dt;
  536. BaseUtil.FillDgvWithDataTable(WaitChooseDGV, dt);
  537. }
  538. private void OQC_SamplingDataCollection_FormClosing(object sender, FormClosingEventArgs e)
  539. {
  540. dh.Dispose();
  541. }
  542. private void Filter_UserControlTextChanged(object sender, EventArgs e)
  543. {
  544. try
  545. {
  546. DataRow[] dr = (BadInfoSource.DataSource as DataTable).Select("bc_code like '%" + Filter.Text + "%' or bc_name like '%" + Filter.Text + "%'");
  547. DataTable dt = (BadInfoSource.DataSource as DataTable).Clone();
  548. for (int i = 0; i < dr.Length; i++)
  549. {
  550. dt.Rows.Add(dr[i].ItemArray);
  551. }
  552. BaseUtil.FillDgvWithDataTable(WaitChooseDGV, dt);
  553. }
  554. catch (Exception)
  555. {
  556. }
  557. }
  558. private void checkBox1_CheckedChanged(object sender, EventArgs e)
  559. {
  560. sncode.Focus();
  561. sncode.SelectAll();
  562. }
  563. }
  564. }