OQC_BatchResultJudge.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. using System;
  2. using System.Data;
  3. using System.Windows.Forms;
  4. using System.Drawing;
  5. using UAS_MES_NEW.PublicMethod;
  6. using UAS_MES_NEW.DataOperate;
  7. using System.Text;
  8. using UAS_MES_NEW.Entity;
  9. using System.Collections.Generic;
  10. namespace UAS_MES_NEW.OQC
  11. {
  12. public partial class OQC_BatchResultJudge : Form
  13. {
  14. AutoSizeFormClass asc = new AutoSizeFormClass();
  15. DataHelper dh;
  16. LogStringBuilder sql = new LogStringBuilder();
  17. DataTable dt;
  18. string ErrorMessage = "";
  19. /// <summary>
  20. /// 是否通过资源验证
  21. /// </summary>
  22. bool PassCheckStep = false;
  23. public OQC_BatchResultJudge()
  24. {
  25. InitializeComponent();
  26. }
  27. private void 抽检批维护_Load(object sender, EventArgs e)
  28. {
  29. dh = SystemInf.dh;
  30. ob_checkno.Focus();
  31. asc.controllInitializeSize(this);
  32. }
  33. private void GetBatch_Click(object sender, EventArgs e)
  34. {
  35. if (CheckStep())
  36. {
  37. DataTable temp = dh.getFieldsDatasByCondition("makeserial", new string[] { "nvl(ms_ifrework,0)ms_ifrework", "ms_reworkcheckno" }, "(ms_sncode)='" + ms_sncode.Text.ToUpper() + "' order by ms_id desc");
  38. if (temp.Rows.Count > 0)
  39. {
  40. if (temp.Rows[0]["ms_ifrework"].ToString() != "0")
  41. {
  42. ob_checkno.Text = temp.Rows[0]["ms_reworkcheckno"].ToString();
  43. }
  44. }
  45. PassCheckStep = true;
  46. string ErrorMessage = "";
  47. DataTable[] dt = LogicHandler.GetOQCBatch(ms_sncode.Text, obd_outboxcode.Text, ob_checkno.Text, "OQCResultDetermine", out ErrorMessage);
  48. if (ErrorMessage == "")
  49. {
  50. BaseUtil.SetFormValue(Controls, dt[0]);
  51. switch (ob_result.Text)
  52. {
  53. case "OK":
  54. BatchPass.Enabled = false;
  55. BatchRejection.Enabled = false;
  56. ForcePass.Enabled = false;
  57. ForceRejection.Enabled = false;
  58. WithdrawPass.Enabled = true;
  59. WithdrawRejection.Enabled = false;
  60. break;
  61. case "FOK":
  62. BatchPass.Enabled = false;
  63. BatchRejection.Enabled = false;
  64. ForcePass.Enabled = false;
  65. ForceRejection.Enabled = false;
  66. WithdrawPass.Enabled = true;
  67. WithdrawRejection.Enabled = false;
  68. break;
  69. case "NG":
  70. BatchPass.Enabled = false;
  71. BatchRejection.Enabled = false;
  72. ForcePass.Enabled = false;
  73. ForceRejection.Enabled = false;
  74. WithdrawPass.Enabled = false;
  75. WithdrawRejection.Enabled = true;
  76. break;
  77. case "FNG":
  78. BatchPass.Enabled = false;
  79. BatchRejection.Enabled = false;
  80. ForcePass.Enabled = false;
  81. ForceRejection.Enabled = false;
  82. WithdrawPass.Enabled = false;
  83. WithdrawRejection.Enabled = true;
  84. break;
  85. case "":
  86. if (ob_checkno.Text != "")
  87. {
  88. BatchPass.Enabled = true;
  89. BatchRejection.Enabled = true;
  90. ForcePass.Enabled = true;
  91. ForceRejection.Enabled = true;
  92. WithdrawPass.Enabled = true;
  93. WithdrawRejection.Enabled = true;
  94. }
  95. break;
  96. default:
  97. break;
  98. }
  99. }
  100. else
  101. {
  102. BaseUtil.CleanForm(this);
  103. BatchPass.Enabled = false;
  104. BatchRejection.Enabled = false;
  105. ForcePass.Enabled = false;
  106. ForceRejection.Enabled = false;
  107. WithdrawPass.Enabled = false;
  108. WithdrawRejection.Enabled = false;
  109. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  110. }
  111. }
  112. else
  113. {
  114. PassCheckStep = false;
  115. }
  116. }
  117. private void BatchPass_Click(object sender, EventArgs e)
  118. {
  119. string ReworkCode = "";
  120. if (CheckBefore() && PassCheckStep)
  121. {
  122. if (int.Parse(ob_ngqty.Text == "" ? "0" : ob_ngqty.Text) <= int.Parse(ob_maxngacceptqty.Text == "" ? "0" : ob_maxngacceptqty.Text))
  123. {
  124. if (LogicHandler.OQCBatchJudge(ob_checkno.Text, User.UserSourceCode, "OK", "", User.UserCode, Remark.Text, out ReworkCode, out ErrorMessage))
  125. {
  126. LogicHandler.DoCommandLog(Tag.ToString(),User.UserCode,"",User.UserLineCode,User.UserSourceCode,"通过批", "抽检批: "+ ob_checkno.Text+"通过","",ob_checkno.Text);
  127. OperateResult.AppendText(">>通过批成功\n", Color.Green);
  128. GetBatch.PerformClick();
  129. }
  130. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  131. }
  132. else
  133. OperateResult.AppendText(">>当前批次不合格数为" + ob_ngqty.Text + ",大于最大不合格允通过数" + ob_maxngacceptqty.Text + "\n", Color.Red);
  134. }
  135. }
  136. private void BatchRejection_Click(object sender, EventArgs e)
  137. {
  138. string ReworkCode = "";
  139. if (CheckBefore() && PassCheckStep)
  140. {
  141. if (LogicHandler.OQCBatchJudge(ob_checkno.Text, User.UserSourceCode, "NG", ReworkRequire.Checked ? "Y" : "N", User.UserCode, Remark.Text, out ReworkCode, out ErrorMessage))
  142. {
  143. OperateResult.AppendText(">>判退批成功\n", Color.Green);
  144. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, "", User.UserLineCode, User.UserSourceCode, "判退批", "抽检批: " + ob_checkno.Text + "判退", "", ob_checkno.Text);
  145. if (ReworkRequire.Checked)
  146. {
  147. dh.UpdateByCondition("oqcbatch", "ob_reworkcode='" + ReworkCode + "'", "ob_checkno='" + ob_checkno.Text + "'");
  148. OperateResult.AppendText(">>生成返工需求单" + ReworkCode + "\n", Color.Green);
  149. }
  150. GetBatch.PerformClick();
  151. }
  152. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  153. }
  154. }
  155. private void ForcePass_Click(object sender, EventArgs e)
  156. {
  157. string ReworkCode = "";
  158. if (PassCheckStep)
  159. {
  160. if (LogicHandler.OQCBatchJudge(ob_checkno.Text, User.UserSourceCode, "FOK", "", User.UserCode, Remark.Text, out ReworkCode, out ErrorMessage))
  161. {
  162. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, "", User.UserLineCode, User.UserSourceCode, "强制通过批", "抽检批: " + ob_checkno.Text + "强制通过", "", ob_checkno.Text);
  163. OperateResult.AppendText(">>强制通过批" + ob_checkno.Text + "成功\n", Color.Green);
  164. GetBatch.PerformClick();
  165. }
  166. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  167. }
  168. }
  169. private void ForceRejection_Click(object sender, EventArgs e)
  170. {
  171. string ReworkCode = "";
  172. if (PassCheckStep)
  173. {
  174. if (LogicHandler.OQCBatchJudge(ob_checkno.Text, User.UserSourceCode, "FNG", ReworkRequire.Checked ? "Y" : "N", User.UserCode, Remark.Text, out ReworkCode, out ErrorMessage))
  175. {
  176. OperateResult.AppendText(">>强制退批" + ob_checkno.Text + "成功\n", Color.Green);
  177. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, "", User.UserLineCode, User.UserSourceCode, "强制退批", "抽检批: " + ob_checkno.Text + "强制退批", "", ob_checkno.Text);
  178. if (ReworkRequire.Checked)
  179. {
  180. dh.UpdateByCondition("oqcbatch", "ob_reworkcode='" + ReworkCode + "'", "ob_checkno='" + ob_checkno.Text + "'");
  181. OperateResult.AppendText(">>生成返工需求单" + ReworkCode + "\n", Color.Green);
  182. }
  183. GetBatch.PerformClick();
  184. }
  185. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  186. }
  187. }
  188. private void WithdrawPass_Click(object sender, EventArgs e)
  189. {
  190. string ReworkCode = "";
  191. if (PassCheckStep)
  192. {
  193. if (ob_result.Text == "OK" || ob_result.Text == "FOK")
  194. {
  195. if (LogicHandler.OQCBatchJudge(ob_checkno.Text, User.UserSourceCode, "REOK", "", User.UserCode, Remark.Text, out ReworkCode, out ErrorMessage))
  196. {
  197. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, "", User.UserLineCode, User.UserSourceCode, "撤销通过批", "抽检批: " + ob_checkno.Text + "撤销通过", "", ob_checkno.Text);
  198. OperateResult.AppendText(">>撤销通过批" + ob_checkno.Text + "成功\n", Color.Green);
  199. GetBatch.PerformClick();
  200. }
  201. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  202. }
  203. else OperateResult.AppendText(">>该抽检批次未通过,无需撤销通过\n", Color.Red);
  204. }
  205. }
  206. private void WithdrawRejection_Click(object sender, EventArgs e)
  207. {
  208. string ReworkCode = "";
  209. if (PassCheckStep)
  210. {
  211. if (ob_result.Text == "NG" || ob_result.Text == "FNG")
  212. {
  213. dt = (DataTable)dh.ExecuteSql("select re_statuscode from rework where re_checkno='" + ob_checkno.Text + "'", "select");
  214. if (dt.Rows.Count > 0)
  215. {
  216. if (dt.Rows[0]["re_statuscode"].ToString() == "AUDITED")
  217. {
  218. OperateResult.AppendText(">>该批次存在已审核的返修工单,不允许撤销\n", Color.Red);
  219. return;
  220. }
  221. else
  222. {
  223. string logout_confirm = MessageBox.Show("已存在返修工单,撤销会删除该工单,是否继续", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  224. if (logout_confirm == "Yes")
  225. {
  226. if (LogicHandler.OQCBatchJudge(ob_checkno.Text, User.UserSourceCode, "RENG", "", User.UserCode, Remark.Text, out ReworkCode, out ErrorMessage))
  227. {
  228. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, "", User.UserLineCode, User.UserSourceCode, "撤销判退", "抽检批: " + ob_checkno.Text + "撤销判退", "", ob_checkno.Text);
  229. OperateResult.AppendText(">>撤销判退成功\n", Color.Green);
  230. ob_result.Text = "";
  231. GetBatch.PerformClick();
  232. }
  233. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  234. }
  235. else return;
  236. }
  237. }
  238. else
  239. {
  240. if (LogicHandler.OQCBatchJudge(ob_checkno.Text, User.UserSourceCode, "RENG", "", User.UserCode, Remark.Text, out ReworkCode, out ErrorMessage))
  241. {
  242. OperateResult.AppendText(">>撤销判退成功\n", Color.Green);
  243. ob_result.Text = "";
  244. GetBatch.PerformClick();
  245. }
  246. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  247. }
  248. }
  249. else OperateResult.AppendText(">>该抽检批次未判退,无需撤销判退\n", Color.Red);
  250. }
  251. }
  252. private void Clean_Click(object sender, EventArgs e)
  253. {
  254. OperateResult.Clear();
  255. }
  256. /// <summary>
  257. /// 操作之前通用的验证逻辑
  258. /// </summary>
  259. /// <returns></returns>
  260. private bool CheckBefore()
  261. {
  262. if (ob_status.Text == "检验中")
  263. {
  264. if (ob_maxngacceptqty.Text == "")
  265. {
  266. if (ob_aqlcode.Text == "")
  267. OperateResult.AppendText(">>AQL标准为空的时候必须填写最大不合格允许通过数\n", Color.Red);
  268. else
  269. {
  270. sql.Clear();
  271. sql.Append("select nvl(ad_minqty,0)ad_minqty,nvl(ad_maxqty,0)ad_maxqty,nvl(ad_maxngacceptqty,0) ");
  272. sql.Append("ad_maxngacceptqty from QUA_Aql left join qua_aqldetail on ad_alid=al_id where ");
  273. sql.Append("al_code='" + ob_aqlcode.Text + "' and ad_minqty<='" + ob_nowcheckqty.Text + "' and ad_maxqty>='" + ob_nowcheckqty.Text + "'");
  274. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  275. if (dt.Rows.Count > 0)
  276. {
  277. ob_maxngacceptqty.Text = dt.Rows[0]["ad_maxngacceptqty"].ToString();
  278. return true;
  279. }
  280. }
  281. }
  282. else
  283. {
  284. return true;
  285. }
  286. }
  287. else OperateResult.AppendText(">>状态未在检验中的批次不允许进行判断\n", Color.Red);
  288. return false;
  289. }
  290. private bool CheckStep()
  291. {
  292. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
  293. {
  294. return true;
  295. }
  296. else
  297. {
  298. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  299. return false;
  300. }
  301. }
  302. private void 抽检批维护_SizeChanged(object sender, EventArgs e)
  303. {
  304. asc.controlAutoSize(this);
  305. }
  306. private void ob_checkno_KeyDown(object sender, KeyEventArgs e)
  307. {
  308. if (e.KeyCode == Keys.Enter)
  309. GetBatch.PerformClick();
  310. }
  311. private void ms_sncode_KeyDown(object sender, KeyEventArgs e)
  312. {
  313. if (e.KeyCode == Keys.Enter)
  314. {
  315. //因为通过序列号获取的时候会带出送检批次,获取数据的方法根据送检批次为主
  316. //所以在通过序列号获取的时候要清除界面数据
  317. string sncode = ms_sncode.Text;
  318. BaseUtil.CleanForm(this);
  319. ms_sncode.Text = sncode;
  320. GetBatch.PerformClick();
  321. }
  322. }
  323. private void obd_outboxcode_KeyDown(object sender, KeyEventArgs e)
  324. {
  325. if (e.KeyCode == Keys.Enter)
  326. GetBatch.PerformClick();
  327. }
  328. private void OQC_BatchResultJudge_FormClosing(object sender, FormClosingEventArgs e)
  329. {
  330. dh.Dispose();
  331. }
  332. private void normalButton1_Click(object sender, EventArgs e)
  333. {
  334. if (ob_checkno.Text != "")
  335. {
  336. dh.UpdateByCondition("oqcbatch", "ob_remark = '" + Remark.Text + "'", "ob_checkno = '" + ob_checkno.Text + "'");
  337. OperateResult.AppendText(">>抽检批" + ob_checkno.Text + "备注维护完成\n", Color.Green);
  338. }
  339. else
  340. {
  341. OperateResult.AppendText(">>抽检批号不可为空\n", Color.Red);
  342. }
  343. }
  344. }
  345. }