OQC_PlanMaintain.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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.DataOperate;
  8. using UAS_MES_NEW.Entity;
  9. using UAS_MES_NEW.PublicMethod;
  10. namespace UAS_MES_NEW.OQC
  11. {
  12. public partial class OQC_PlanMaintain : Form
  13. {
  14. AutoSizeFormClass asc = new AutoSizeFormClass();
  15. LogStringBuilder sql = new LogStringBuilder();
  16. DataTable dt;
  17. DataHelper dh;
  18. string ErrorMessage = "";
  19. DataTable Dbfind;
  20. public OQC_PlanMaintain()
  21. {
  22. InitializeComponent();
  23. }
  24. private void 抽样计划维护_Load(object sender, EventArgs e)
  25. {
  26. asc.controllInitializeSize(this);
  27. dh = SystemInf.dh;
  28. pr_code.TableName = "QUA_Project";
  29. pr_code.SelectField = "pr_code # 方案编号,pr_name # 方案名称,pr_class # 检验单类型,pr_standard # 方案标准,pr_startdate # 生效日期,pr_enddate #失效日期 ,pr_status # 状态";
  30. pr_code.SetValueField = new string[] { "pr_code" };
  31. pr_code.FormName = Name;
  32. pr_code.DbChange += Pr_code_DbChange;
  33. al_code.TableName = "QUA_AQL";
  34. al_code.DBTitle = "抽样标准查询";
  35. al_code.SelectField = "al_code # 流水编号,AL_NAME # 检验标准名称";
  36. al_code.SetValueField = new string[] { "al_code" };
  37. al_code.FormName = Name;
  38. al_code.Condition = "al_statuscode='AUDITED'";
  39. al_code.DbChange += Al_code_DbChange;
  40. ChooseAll.ChooseAll(CheckTypeDGV);
  41. }
  42. private void Al_code_DbChange(object sender, EventArgs e)
  43. {
  44. Dbfind = al_code.ReturnData;
  45. BaseUtil.SetFormValue(this.Controls, Dbfind);
  46. }
  47. private void Pr_code_DbChange(object sender, EventArgs e)
  48. {
  49. Dbfind = pr_code.ReturnData;
  50. BaseUtil.SetFormValue(this.Controls, Dbfind);
  51. }
  52. private void 抽样计划维护_SizeChanged(object sender, EventArgs e)
  53. {
  54. asc.controlAutoSize(this);
  55. }
  56. /// <summary>
  57. /// 获取批次点击按钮
  58. /// </summary>
  59. /// <param name="sender"></param>
  60. /// <param name="e"></param>
  61. private void GetBatch_Click(object sender, EventArgs e)
  62. {
  63. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
  64. {
  65. 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");
  66. if (temp.Rows.Count > 0)
  67. {
  68. if (temp.Rows[0]["ms_ifrework"].ToString() != "0")
  69. {
  70. ob_checkno.Text = temp.Rows[0]["ms_reworkcheckno"].ToString();
  71. }
  72. }
  73. if (ms_sncode.Text != "")
  74. {
  75. ob_checkno.Text = "";
  76. }
  77. DataTable[] dt = LogicHandler.GetOQCBatch(ms_sncode.Text, obd_outboxcode.Text, ob_checkno.Text, "OQCPlanMaintain", out ErrorMessage);
  78. if (dt != null)
  79. {
  80. if (ErrorMessage == "")
  81. {
  82. ob_sampleqty.Text = "";
  83. ob_maxngacceptqty.Text = "";
  84. BaseUtil.SetFormValue(Controls, dt[0]);
  85. BaseUtil.FillDgvWithDataTable(CheckTypeDGV, dt[1]);
  86. al_code.Text = "";
  87. al_code.Text = dt[0].Rows[0]["ob_aqlcode"].ToString();
  88. }
  89. else
  90. {
  91. BaseUtil.CleanForm(this);
  92. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  93. ErrorMessage = "";
  94. }
  95. }
  96. else
  97. {
  98. BaseUtil.CleanForm(this);
  99. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  100. }
  101. }
  102. else
  103. {
  104. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  105. }
  106. }
  107. private void SaveConfiguration_Click(object sender, EventArgs e)
  108. {
  109. if (ob_status.Text == "待检验")
  110. {
  111. sql.Clear();
  112. sql.Append("select wm_concat(ms_sncode) sn from oqcbatch left join oqcbatchdetail on ob_id=obd_obid left join makeserial ");
  113. sql.Append("on ms_sncode=obd_sncode and obd_makecode=ms_makecode where ob_checkno='" + ob_checkno.Text + "' and ms_downstatus<>0");
  114. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  115. if (dt.Rows[0]["sn"].ToString() != "")
  116. {
  117. OperateResult.AppendText(">>批次含有序列号" + dt.Rows[0]["sn"].ToString() + "处于下地状态,不允许保存抽样计划\n", Color.Red);
  118. return;
  119. }
  120. if (ob_source.Text == "返工" && ob_reworkcode.Text != "")
  121. {
  122. dt = (DataTable)dh.ExecuteSql("select re_id from rework where re_code='" + ob_reworkcode.Text + "' and nvl(re_nullngfinsh,0)=0", "select");
  123. if (dt.Rows.Count > 0)
  124. {
  125. sql.Clear();
  126. sql.Append("select count(1),wm_concat(obd_sncode) sn from oqcbatchdetail left join makeserial ");
  127. sql.Append("on ms_sncode=obd_sncode and ms_reworkcheckno=obd_checkno where obd_checkno");
  128. sql.Append("='" + ob_checkno.Text + "'and ms_nextstepcode<>'" + User.CurrentStepCode + "' and rownum<20");
  129. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  130. if (dt.Rows[0]["sn"].ToString() != "")
  131. {
  132. OperateResult.AppendText(">>序列号" + dt.Rows[0]["sn"].ToString() + "下一道不是OQC工序\n", Color.Red);
  133. return;
  134. }
  135. }
  136. }
  137. //新增的数据
  138. List<string> oi_id = new List<string>();
  139. List<string> ci_kind = new List<string>();
  140. List<string> oi_sampleqty = new List<string>();
  141. //更新的数据
  142. List<string> ci_kind_update = new List<string>();
  143. List<string> oi_sampleqty_update = new List<string>();
  144. int ChooseCount = 0;
  145. for (int i = 0; i < CheckTypeDGV.Rows.Count; i++)
  146. {
  147. //用户勾选的数据才进行操作
  148. if (CheckTypeDGV.Rows[i].Cells["Choose"].FormattedValue.ToString() == "True")
  149. {
  150. ChooseCount = ChooseCount + 1;
  151. if (int.Parse(CheckTypeDGV.Rows[i].Cells["oi_sampleqty"].Value.ToString()) > 0)
  152. {
  153. if (!(int.Parse(CheckTypeDGV.Rows[i].Cells["oi_sampleqty"].Value.ToString()) > int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text)))
  154. {
  155. oi_id.Add(CheckTypeDGV.Rows[i].Cells["oi_id"].Value.ToString());
  156. ci_kind.Add(CheckTypeDGV.Rows[i].Cells["ci_kind"].Value.ToString());
  157. oi_sampleqty.Add(CheckTypeDGV.Rows[i].Cells["oi_sampleqty"].Value.ToString());
  158. }
  159. else
  160. {
  161. OperateResult.AppendText(">>第" + (i + 1) + "行的数量大于送检批数量\n", Color.Red);
  162. return;
  163. }
  164. }
  165. else
  166. {
  167. OperateResult.AppendText(">>第" + (i + 1) + "行的抽样数量必需大于0\n", Color.Red);
  168. return;
  169. }
  170. }
  171. }
  172. if (ChooseCount == 0)
  173. {
  174. OperateResult.AppendText(">>请勾选检验项目\n", Color.Red);
  175. return;
  176. }
  177. //如果ID为0的数组存在内容则进行插入操作
  178. dh.ExecuteSql("delete from oqcitems where oi_checkno='" + ob_checkno.Text + "'", "delete");
  179. if (oi_id.Count > 0)
  180. {
  181. sql.Clear();
  182. sql.Append("insert into OQCItems(oi_id,oi_checkno, oi_projectcode,oi_batchqty ,oi_checkkind,oi_sampleqty,oi_itemcode) select ");
  183. sql.Append("OQCItems_seq.nextval,'" + ob_checkno.Text + "','" + pr_code.Text + "','" + ob_nowcheckqty.Text + "',:ci_kind,");
  184. sql.Append(":oi_sampleqty,ci_code from QUA_PROJECT left join QUA_PROJECTDETAIL on pd_prid=pr_id ");
  185. sql.Append("LEFT JOIN QUA_CHECKITEM ON PD_CIID=CI_ID where pr_code='" + pr_code.Text + "' and ci_kind=:ci_kind1");
  186. dh.BatchInsert(sql.GetString(), new string[] { "ci_kind", "oi_sampleqty", "ci_kind1" }, ci_kind.ToArray(), oi_sampleqty.ToArray(), ci_kind.ToArray());
  187. //更新物料资料的抽检方案未当前选取的
  188. dh.UpdateByCondition("product", "pr_qualmethod='" + pr_code.Text + "'", "pr_code='" + ob_prodcode.Text + "'");
  189. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, "", User.UserLineCode, User.UserSourceCode, "OQC抽样计划采集保存抽样计划", "成功", ms_sncode.Text, ob_checkno.Text);
  190. }
  191. OperateResult.AppendText(">>批次" + ob_checkno.Text + "保存抽样计划成功\n", Color.Green);
  192. }
  193. else OperateResult.AppendText(">>送检批次必须为待检验状态\n", Color.Red);
  194. }
  195. private void Save_Click(object sender, EventArgs e)
  196. {
  197. if (al_code.Text != "" || ob_maxngacceptqty.Text != "")
  198. {
  199. if (dh.getFieldDataByCondition("oqcbatch", "ob_status", "ob_checkno='" + ob_checkno.Text + "'").ToString() == "UNCHECK")
  200. {
  201. if (Checkob_maxngacceptqty())
  202. {
  203. SaveConfiguration_Click(sender, e);
  204. }
  205. }
  206. else OperateResult.AppendText(">>送检批次必须为待检验状态\n", Color.Red);
  207. }
  208. else OperateResult.AppendText(">>AQL和最大不合格允许通过数至少填写一个\n", Color.Red);
  209. }
  210. //对于最大不合格允通过数的校验
  211. private bool Checkob_maxngacceptqty()
  212. {
  213. if (int.Parse(ob_maxngacceptqty.Text == "" ? "0" : ob_maxngacceptqty.Text) < 0)
  214. {
  215. OperateResult.AppendText(">>最大不合格允通过数必须大于等于0\n", Color.Red);
  216. ob_maxngacceptqty.Text = null;
  217. return false;
  218. }
  219. else
  220. {
  221. if (ob_maxngacceptqty.Text == "")
  222. {
  223. ob_maxngacceptqty.Text = dh.getFieldDataByCondition("QUA_Aql left join qua_aqldetail on ad_alid=al_id", "nvl(ad_maxngacceptqty,0)", "al_code='" + al_code.Text + "' and ad_minqty<='" + ob_nowcheckqty.Text + "' and ad_maxqty>='" + ob_nowcheckqty.Text + "'").ToString();
  224. }
  225. if (int.Parse(ob_maxngacceptqty.Text == "" ? "0" : ob_maxngacceptqty.Text) > int.Parse(ob_sampleqty.Text == "" ? "0" : ob_sampleqty.Text))
  226. {
  227. OperateResult.AppendText(">>最大不合格通过数不允许大于抽检数\n", Color.Red);
  228. return false;
  229. }
  230. int result = (int)dh.ExecuteSql("update OQCBatch set ob_projectcode='" + pr_code.Text + "',ob_remark = '" + ob_remark.Text + "',ob_aqlcode='" + al_code.Text + "',ob_maxngacceptqty='" + ob_maxngacceptqty.Text + "',ob_actsampleqty='" + ob_sampleqty.Text + "' where ob_checkno='" + ob_checkno.Text + "' ", "update");
  231. return result > 0;
  232. }
  233. }
  234. private void Clean_Click(object sender, EventArgs e)
  235. {
  236. OperateResult.Clear();
  237. }
  238. private void ob_checkno_KeyDown(object sender, KeyEventArgs e)
  239. {
  240. if (e.KeyCode == Keys.Enter)
  241. GetBatch.PerformClick();
  242. }
  243. private void ms_sncode_KeyDown(object sender, KeyEventArgs e)
  244. {
  245. if (e.KeyCode == Keys.Enter)
  246. GetBatch.PerformClick();
  247. }
  248. private void obd_outboxcode_KeyDown(object sender, KeyEventArgs e)
  249. {
  250. if (e.KeyCode == Keys.Enter)
  251. GetBatch.PerformClick();
  252. }
  253. private void ob_aqlcode_UserControlTextChanged(object sender, EventArgs e)
  254. {
  255. if (al_code.Text != "")
  256. {
  257. sql.Clear();
  258. sql.Append("select nvl(ad_minqty,0)ad_minqty,nvl(ad_maxqty,0)ad_maxqty,nvl(ad_maxngacceptqty,0)ad_maxngacceptqty,ad_qty from QUA_Aql ");
  259. sql.Append("left join qua_aqldetail on ad_alid=al_id where al_code='" + al_code.Text + "' and ad_minqty<='" + ob_nowcheckqty.Text + "' and ad_maxqty>='" + ob_nowcheckqty.Text + "'");
  260. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  261. if (dt.Rows.Count > 0)
  262. {
  263. ob_maxngacceptqty.Text = dt.Rows[0]["ad_maxngacceptqty"].ToString();
  264. ob_sampleqty.Text = dt.Rows[0]["ad_qty"].ToString();
  265. }
  266. else
  267. {
  268. ob_maxngacceptqty.Text = "";
  269. ob_sampleqty.Text = "";
  270. }
  271. }
  272. }
  273. private void ad_qty_TextChanged_1(object sender, EventArgs e)
  274. {
  275. for (int i = 0; i < CheckTypeDGV.Rows.Count; i++)
  276. {
  277. CheckTypeDGV.Rows[i].Cells["oi_sampleqty"].Value = ob_sampleqty.Text;
  278. }
  279. }
  280. private void ob_projectcode_UserControlTextChanged(object sender, EventArgs e)
  281. {
  282. sql.Clear();
  283. sql.Append("select nvl(max(oi_id),0)oi_id,ci_code,ci_kind,nvl(max(oi_sampleqty),0) oi_sampleqty from QUA_PROJECT left join ");
  284. sql.Append(" QUA_ProjectDetail on pd_prid=pr_id left join QUA_CheckItem on pd_ciid=ci_id ");
  285. sql.Append("left join OQCITEMS on oi_checkno ='" + ob_checkno.Text + "' and oi_projectcode='" + pr_code.Text + "' ");
  286. sql.Append("and oi_projectcode = pr_code and oi_checkkind = ci_kind where pr_code='" + pr_code.Text + "' group by ci_code,ci_kind");
  287. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  288. BaseUtil.FillDgvWithDataTable(CheckTypeDGV, dt);
  289. }
  290. private void OQC_PlanMaintain_FormClosing(object sender, FormClosingEventArgs e)
  291. {
  292. dh.Dispose();
  293. }
  294. private void CheckTypeDGV_DataSourceChanged(object sender, EventArgs e)
  295. {
  296. //更换抽检方案后保持抽选状态和检验数量
  297. for (int i = 0; i < CheckTypeDGV.Rows.Count; i++)
  298. {
  299. CheckTypeDGV.Rows[i].Cells["Choose"].Value = true;
  300. CheckTypeDGV.Rows[i].Cells["oi_sampleqty"].Value = ob_sampleqty.Text;
  301. }
  302. }
  303. }
  304. }