OQC_PlanMaintain.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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. DataTable[] dt = LogicHandler.GetOQCBatch(ms_sncode.Text, obd_outboxcode.Text, ob_checkno.Text, "OQCPlanMaintain", out ErrorMessage);
  74. if (dt != null)
  75. {
  76. if (ErrorMessage == "")
  77. {
  78. ob_sampleqty.Text = "";
  79. ob_maxngacceptqty.Text = "";
  80. BaseUtil.SetFormValue(Controls, dt[0]);
  81. BaseUtil.FillDgvWithDataTable(CheckTypeDGV, dt[1]);
  82. al_code.Text = "";
  83. al_code.Text = dt[0].Rows[0]["ob_aqlcode"].ToString();
  84. }
  85. else
  86. {
  87. BaseUtil.CleanForm(this);
  88. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  89. ErrorMessage = "";
  90. }
  91. }
  92. else
  93. {
  94. BaseUtil.CleanForm(this);
  95. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  96. }
  97. }
  98. else
  99. {
  100. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  101. }
  102. }
  103. private void SaveConfiguration_Click(object sender, EventArgs e)
  104. {
  105. if (ob_status.Text == "待检验")
  106. {
  107. sql.Clear();
  108. sql.Append("select wm_concat(ms_sncode) sn from oqcbatch left join oqcbatchdetail on ob_id=obd_obid left join makeserial ");
  109. sql.Append("on ms_sncode=obd_sncode and obd_makecode=ms_makecode where ob_checkno='" + ob_checkno.Text + "' and ms_downstatus<>0");
  110. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  111. if (dt.Rows[0]["sn"].ToString() != "")
  112. {
  113. OperateResult.AppendText(">>批次含有序列号" + dt.Rows[0]["sn"].ToString() + "处于下地状态,不允许保存抽样计划\n", Color.Red);
  114. return;
  115. }
  116. if (ob_source.Text == "返工" && ob_reworkcode.Text != "")
  117. {
  118. dt = (DataTable)dh.ExecuteSql("select re_id from rework where re_code='" + ob_reworkcode.Text + "' and nvl(re_nullngfinsh,0)=0", "select");
  119. if (dt.Rows.Count > 0)
  120. {
  121. sql.Clear();
  122. sql.Append("select count(1),wm_concat(obd_sncode) sn from oqcbatchdetail left join makeserial ");
  123. sql.Append("on ms_sncode=obd_sncode and ms_reworkcheckno=obd_checkno where obd_checkno");
  124. sql.Append("='" + ob_checkno.Text + "'and ms_nextstepcode<>'" + User.CurrentStepCode + "' and rownum<20");
  125. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  126. if (dt.Rows[0]["sn"].ToString() != "")
  127. {
  128. OperateResult.AppendText(">>序列号" + dt.Rows[0]["sn"].ToString() + "下一道不是OQC工序\n", Color.Red);
  129. return;
  130. }
  131. }
  132. }
  133. //新增的数据
  134. List<string> oi_id = new List<string>();
  135. List<string> ci_kind = new List<string>();
  136. List<string> oi_sampleqty = new List<string>();
  137. //更新的数据
  138. List<string> ci_kind_update = new List<string>();
  139. List<string> oi_sampleqty_update = new List<string>();
  140. int ChooseCount = 0;
  141. for (int i = 0; i < CheckTypeDGV.Rows.Count; i++)
  142. {
  143. //用户勾选的数据才进行操作
  144. if (CheckTypeDGV.Rows[i].Cells["Choose"].FormattedValue.ToString() == "True")
  145. {
  146. ChooseCount = ChooseCount + 1;
  147. if (int.Parse(CheckTypeDGV.Rows[i].Cells["oi_sampleqty"].Value.ToString()) > 0)
  148. {
  149. if (!(int.Parse(CheckTypeDGV.Rows[i].Cells["oi_sampleqty"].Value.ToString()) > int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text)))
  150. {
  151. oi_id.Add(CheckTypeDGV.Rows[i].Cells["oi_id"].Value.ToString());
  152. ci_kind.Add(CheckTypeDGV.Rows[i].Cells["ci_kind"].Value.ToString());
  153. oi_sampleqty.Add(CheckTypeDGV.Rows[i].Cells["oi_sampleqty"].Value.ToString());
  154. }
  155. else
  156. {
  157. OperateResult.AppendText(">>第" + (i + 1) + "行的数量大于送检批数量\n", Color.Red);
  158. return;
  159. }
  160. }
  161. else
  162. {
  163. OperateResult.AppendText(">>第" + (i + 1) + "行的抽样数量必需大于0\n", Color.Red);
  164. return;
  165. }
  166. }
  167. }
  168. if (ChooseCount == 0)
  169. {
  170. OperateResult.AppendText(">>请勾选检验项目\n", Color.Red);
  171. return;
  172. }
  173. //如果ID为0的数组存在内容则进行插入操作
  174. dh.ExecuteSql("delete from oqcitems where oi_checkno='" + ob_checkno.Text + "'", "delete");
  175. if (oi_id.Count > 0)
  176. {
  177. sql.Clear();
  178. sql.Append("insert into OQCItems(oi_id,oi_checkno, oi_projectcode,oi_batchqty ,oi_checkkind,oi_sampleqty,oi_itemcode) select ");
  179. sql.Append("OQCItems_seq.nextval,'" + ob_checkno.Text + "','" + pr_code.Text + "','" + ob_nowcheckqty.Text + "',:ci_kind,");
  180. sql.Append(":oi_sampleqty,ci_code from QUA_PROJECT left join QUA_PROJECTDETAIL on pd_prid=pr_id ");
  181. sql.Append("LEFT JOIN QUA_CHECKITEM ON PD_CIID=CI_ID where pr_code='" + pr_code.Text + "' and ci_kind=:ci_kind1");
  182. dh.BatchInsert(sql.GetString(), new string[] { "ci_kind", "oi_sampleqty", "ci_kind1" }, ci_kind.ToArray(), oi_sampleqty.ToArray(), ci_kind.ToArray());
  183. //更新物料资料的抽检方案未当前选取的
  184. dh.UpdateByCondition("product", "pr_qualmethod='" + pr_code.Text + "'", "pr_code='" + ob_prodcode.Text + "'");
  185. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, "", User.UserLineCode, User.UserSourceCode, "OQC抽样计划采集保存抽样计划", "成功", ms_sncode.Text, ob_checkno.Text);
  186. }
  187. OperateResult.AppendText(">>批次" + ob_checkno.Text + "保存抽样计划成功\n", Color.Green);
  188. }
  189. else OperateResult.AppendText(">>送检批次必须为待检验状态\n", Color.Red);
  190. }
  191. private void Save_Click(object sender, EventArgs e)
  192. {
  193. if (al_code.Text != "" || ob_maxngacceptqty.Text != "")
  194. {
  195. if (dh.getFieldDataByCondition("oqcbatch", "ob_status", "ob_checkno='" + ob_checkno.Text + "'").ToString() == "UNCHECK")
  196. {
  197. if (Checkob_maxngacceptqty())
  198. {
  199. SaveConfiguration_Click(sender, e);
  200. }
  201. }
  202. else OperateResult.AppendText(">>送检批次必须为待检验状态\n", Color.Red);
  203. }
  204. else OperateResult.AppendText(">>AQL和最大不合格允许通过数至少填写一个\n", Color.Red);
  205. }
  206. //对于最大不合格允通过数的校验
  207. private bool Checkob_maxngacceptqty()
  208. {
  209. if (int.Parse(ob_maxngacceptqty.Text == "" ? "0" : ob_maxngacceptqty.Text) < 0)
  210. {
  211. OperateResult.AppendText(">>最大不合格允通过数必须大于等于0\n", Color.Red);
  212. ob_maxngacceptqty.Text = null;
  213. return false;
  214. }
  215. else
  216. {
  217. if (ob_maxngacceptqty.Text == "")
  218. {
  219. 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();
  220. }
  221. if (int.Parse(ob_maxngacceptqty.Text == "" ? "0" : ob_maxngacceptqty.Text) > int.Parse(ob_sampleqty.Text == "" ? "0" : ob_sampleqty.Text))
  222. {
  223. OperateResult.AppendText(">>最大不合格通过数不允许大于抽检数\n", Color.Red);
  224. return false;
  225. }
  226. 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");
  227. return result > 0;
  228. }
  229. }
  230. private void Clean_Click(object sender, EventArgs e)
  231. {
  232. OperateResult.Clear();
  233. }
  234. private void ob_checkno_KeyDown(object sender, KeyEventArgs e)
  235. {
  236. if (e.KeyCode == Keys.Enter)
  237. GetBatch.PerformClick();
  238. }
  239. private void ms_sncode_KeyDown(object sender, KeyEventArgs e)
  240. {
  241. if (e.KeyCode == Keys.Enter)
  242. GetBatch.PerformClick();
  243. }
  244. private void obd_outboxcode_KeyDown(object sender, KeyEventArgs e)
  245. {
  246. if (e.KeyCode == Keys.Enter)
  247. GetBatch.PerformClick();
  248. }
  249. private void ob_aqlcode_UserControlTextChanged(object sender, EventArgs e)
  250. {
  251. if (al_code.Text != "")
  252. {
  253. sql.Clear();
  254. 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 ");
  255. 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 + "'");
  256. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  257. if (dt.Rows.Count > 0)
  258. {
  259. ob_maxngacceptqty.Text = dt.Rows[0]["ad_maxngacceptqty"].ToString();
  260. ob_sampleqty.Text = dt.Rows[0]["ad_qty"].ToString();
  261. }
  262. else
  263. {
  264. ob_maxngacceptqty.Text = "";
  265. ob_sampleqty.Text = "";
  266. }
  267. }
  268. }
  269. private void ad_qty_TextChanged_1(object sender, EventArgs e)
  270. {
  271. for (int i = 0; i < CheckTypeDGV.Rows.Count; i++)
  272. {
  273. CheckTypeDGV.Rows[i].Cells["oi_sampleqty"].Value = ob_sampleqty.Text;
  274. }
  275. }
  276. private void ob_projectcode_UserControlTextChanged(object sender, EventArgs e)
  277. {
  278. sql.Clear();
  279. sql.Append("select nvl(max(oi_id),0)oi_id,ci_kind,nvl(max(oi_sampleqty),0) oi_sampleqty from QUA_PROJECT left join ");
  280. sql.Append(" QUA_ProjectDetail on pd_prid=pr_id left join QUA_CheckItem on pd_ciid=ci_id ");
  281. sql.Append("left join OQCITEMS on oi_checkno ='" + ob_checkno.Text + "' and oi_projectcode='" + pr_code.Text + "' ");
  282. sql.Append("and oi_projectcode = pr_code and oi_checkkind = ci_kind where pr_code='" + pr_code.Text + "' group by ci_kind");
  283. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  284. BaseUtil.FillDgvWithDataTable(CheckTypeDGV, dt);
  285. }
  286. private void OQC_PlanMaintain_FormClosing(object sender, FormClosingEventArgs e)
  287. {
  288. dh.Dispose();
  289. }
  290. private void CheckTypeDGV_DataSourceChanged(object sender, EventArgs e)
  291. {
  292. //更换抽检方案后保持抽选状态和检验数量
  293. for (int i = 0; i < CheckTypeDGV.Rows.Count; i++)
  294. {
  295. CheckTypeDGV.Rows[i].Cells["Choose"].Value = true;
  296. CheckTypeDGV.Rows[i].Cells["oi_sampleqty"].Value = ob_sampleqty.Text;
  297. }
  298. }
  299. private void normalButton1_Click(object sender, EventArgs e)
  300. {
  301. ob_checkno.Clear();
  302. ms_sncode.Focus();
  303. ms_sncode.SelectAll();
  304. }
  305. }
  306. }