OQC_PlanMaintain.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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.DataOperate;
  8. using UAS_MES.Entity;
  9. using UAS_MES.PublicMethod;
  10. namespace UAS_MES.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. public OQC_PlanMaintain()
  20. {
  21. InitializeComponent();
  22. }
  23. private void 抽样计划维护_Load(object sender, EventArgs e)
  24. {
  25. asc.controllInitializeSize(this);
  26. dh = new DataHelper();
  27. pr_code.TableName = "QUA_Project";
  28. pr_code.SelectField = "pr_code # 方案编号,pr_name # 方案名称,pr_class # 检验单类型,pr_standard # 方案标准,pr_startdate # 生效日期,pr_enddate #失效日期 ,pr_status # 状态";
  29. pr_code.SetValueField = new string[] { "ob_projectcode" };
  30. pr_code.FormName = Name;
  31. al_code.TableName = "QUA_AQL";
  32. al_code.DBTitle = "抽样标准查询";
  33. al_code.SelectField = "AL_CODE # 流水编号,AL_NAME # 检验标准名称";
  34. al_code.SetValueField = new string[] { "ob_aqlcode" };
  35. al_code.FormName = Name;
  36. al_code.Condition = "al_statuscode='AUDITED'";
  37. ChooseAll.ChooseAll(CheckTypeDGV);
  38. }
  39. private void 抽样计划维护_SizeChanged(object sender, EventArgs e)
  40. {
  41. asc.controlAutoSize(this);
  42. }
  43. /// <summary>
  44. /// 获取批次点击按钮
  45. /// </summary>
  46. /// <param name="sender"></param>
  47. /// <param name="e"></param>
  48. private void GetBatch_Click(object sender, EventArgs e)
  49. {
  50. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
  51. {
  52. DataTable temp = dh.getFieldsDataByCondition("makeserial", new string[] { "nvl(ms_ifrework,0)ms_ifrework", "ms_reworkcheckno" }, "upper(ms_sncode)='" + ms_sncode.Text.ToUpper() + "'");
  53. if (temp.Rows.Count > 0)
  54. {
  55. if (temp.Rows[0]["ms_ifrework"].ToString() != "0")
  56. {
  57. ob_checkno.Text = temp.Rows[0]["ms_reworkcheckno"].ToString();
  58. }
  59. }
  60. DataTable[] dt = LogicHandler.GetOQCBatch(ms_sncode.Text, obd_outboxcode.Text, ob_checkno.Text, "OQCPlanMaintain", out ErrorMessage);
  61. if (dt != null)
  62. {
  63. if (ErrorMessage == "")
  64. {
  65. ob_sampleqty.Text = "";
  66. ob_maxngacceptqty.Text = "";
  67. BaseUtil.SetFormValue(Controls, dt[0]);
  68. BaseUtil.FillDgvWithDataTable(CheckTypeDGV, dt[1]);
  69. al_code.Text = "";
  70. al_code.Text = dt[0].Rows[0]["ob_aqlcode"].ToString();
  71. }
  72. else
  73. {
  74. BaseUtil.CleanForm(this);
  75. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  76. ErrorMessage = "";
  77. }
  78. }
  79. else
  80. {
  81. BaseUtil.CleanForm(this);
  82. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  83. }
  84. }
  85. else
  86. {
  87. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  88. }
  89. }
  90. private void SaveConfiguration_Click(object sender, EventArgs e)
  91. {
  92. if (ob_status.Text == "待检验")
  93. {
  94. //新增的数据
  95. List<string> oi_id = new List<string>();
  96. List<string> ci_kind = new List<string>();
  97. List<string> oi_sampleqty = new List<string>();
  98. //更新的数据
  99. List<string> ci_kind_update = new List<string>();
  100. List<string> oi_sampleqty_update = new List<string>();
  101. int ChooseCount = 0;
  102. if (int.Parse(ob_maxngacceptqty.Text == "" ? "0" : ob_maxngacceptqty.Text) > int.Parse(ob_sampleqty.Text == "" ? "0" : ob_sampleqty.Text))
  103. {
  104. OperateResult.AppendText(">>最大不合格通过数不允许大于抽检数\n", Color.Red);
  105. return;
  106. }
  107. for (int i = 0; i < CheckTypeDGV.Rows.Count; i++)
  108. {
  109. //用户勾选的数据才进行操作
  110. if (CheckTypeDGV.Rows[i].Cells["Choose"].FormattedValue.ToString() == "True")
  111. {
  112. ChooseCount = ChooseCount + 1;
  113. if (int.Parse(CheckTypeDGV.Rows[i].Cells["oi_sampleqty"].Value.ToString()) > 0)
  114. {
  115. if (!(int.Parse(CheckTypeDGV.Rows[i].Cells["oi_sampleqty"].Value.ToString()) > int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text)))
  116. {
  117. oi_id.Add(CheckTypeDGV.Rows[i].Cells["oi_id"].Value.ToString());
  118. ci_kind.Add(CheckTypeDGV.Rows[i].Cells["ci_kind"].Value.ToString());
  119. oi_sampleqty.Add(CheckTypeDGV.Rows[i].Cells["oi_sampleqty"].Value.ToString());
  120. }
  121. else
  122. {
  123. OperateResult.AppendText(">>第" + (i + 1) + "行的数量大于送检批数量\n", Color.Red);
  124. return;
  125. }
  126. }
  127. else
  128. {
  129. OperateResult.AppendText(">>第" + (i + 1) + "行的抽样数量必需大于0\n", Color.Red);
  130. return;
  131. }
  132. }
  133. }
  134. if (ChooseCount == 0)
  135. {
  136. OperateResult.AppendText(">>请勾选检验项目\n", Color.Red);
  137. return;
  138. }
  139. //如果ID为0的数组存在内容则进行插入操作
  140. dh.ExecuteSql("delete from oqcitems where oi_checkno='" + ob_checkno.Text + "'", "delete");
  141. if (oi_id.Count > 0)
  142. {
  143. sql.Clear();
  144. sql.Append("insert into OQCItems(oi_id,oi_checkno, oi_projectcode,oi_batchqty ,oi_checkkind,oi_sampleqty,oi_itemcode) select ");
  145. sql.Append("OQCItems_seq.nextval,'" + ob_checkno.Text + "','" + pr_code.Text + "','" + ob_nowcheckqty.Text + "',:ci_kind,");
  146. sql.Append(":oi_sampleqty,ci_code from QUA_PROJECT left join QUA_PROJECTDETAIL on pd_prid=pr_id ");
  147. sql.Append("LEFT JOIN QUA_CHECKITEM ON PD_CIID=CI_ID where pr_code='" + pr_code.Text + "' and ci_kind=:ci_kind1");
  148. dh.BatchInsert(sql.GetString(), new string[] { "ci_kind", "oi_sampleqty", "ci_kind1" }, ci_kind.ToArray(), oi_sampleqty.ToArray(), ci_kind.ToArray());
  149. LogicHandler.DoCommandLog(User.UserCode, "", User.UserLineCode, User.UserSourceCode, "OQC抽样计划采集保存抽样计划", "成功", ms_sncode.Text, ob_checkno.Text);
  150. }
  151. OperateResult.AppendText(">>保存成功\n", Color.Green);
  152. }
  153. else OperateResult.AppendText(">>送检批次必须为待检验状态\n", Color.Red);
  154. }
  155. private void Save_Click(object sender, EventArgs e)
  156. {
  157. if (al_code.Text != "" || ob_maxngacceptqty.Text != "")
  158. {
  159. if (Checkob_maxngacceptqty())
  160. {
  161. SaveConfiguration_Click(sender, e);
  162. }
  163. }
  164. else
  165. OperateResult.AppendText(">>AQL和最大不合格允许通过数至少填写一个\n", Color.Red);
  166. }
  167. //对于最大不合格允通过数的校验
  168. private bool Checkob_maxngacceptqty()
  169. {
  170. if (int.Parse(ob_maxngacceptqty.Text == "" ? "0" : ob_maxngacceptqty.Text) < 0)
  171. {
  172. OperateResult.AppendText(">>最大不合格允通过数必须大于等于0\n", Color.Red);
  173. ob_maxngacceptqty.Text = null;
  174. return false;
  175. }
  176. else
  177. {
  178. 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");
  179. return result > 0;
  180. }
  181. }
  182. private void Clean_Click(object sender, EventArgs e)
  183. {
  184. OperateResult.Clear();
  185. }
  186. private void ob_checkno_KeyDown(object sender, KeyEventArgs e)
  187. {
  188. if (e.KeyCode == Keys.Enter)
  189. GetBatch.PerformClick();
  190. }
  191. private void ms_sncode_KeyDown(object sender, KeyEventArgs e)
  192. {
  193. if (e.KeyCode == Keys.Enter)
  194. GetBatch.PerformClick();
  195. }
  196. private void obd_outboxcode_KeyDown(object sender, KeyEventArgs e)
  197. {
  198. if (e.KeyCode == Keys.Enter)
  199. GetBatch.PerformClick();
  200. }
  201. private void ob_aqlcode_UserControlTextChanged(object sender, EventArgs e)
  202. {
  203. if (al_code.Text != "")
  204. {
  205. bool Find = false;
  206. dt = (DataTable)dh.ExecuteSql("select nvl(ad_minqty,0)ad_minqty,nvl(ad_maxqty,0)ad_maxqty,nvl(ad_maxngacceptqty,0)ad_maxngacceptqty,ad_qty from QUA_Aql left join qua_aqldetail on ad_alid=al_id where al_code='" + al_code.Text + "'", "select");
  207. if (dt.Rows.Count > 0)
  208. {
  209. for (int i = 0; i < dt.Rows.Count; i++)
  210. {
  211. int batchqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text);
  212. int minqty = int.Parse(dt.Rows[i]["ad_minqty"].ToString());
  213. int maxqty = int.Parse(dt.Rows[i]["ad_maxqty"].ToString());
  214. if (batchqty > minqty && batchqty <= maxqty)
  215. {
  216. ob_maxngacceptqty.Text = dt.Rows[i]["ad_maxngacceptqty"].ToString();
  217. ob_sampleqty.Text = dt.Rows[i]["ad_qty"].ToString();
  218. Find = true;
  219. }
  220. }
  221. }
  222. if (!Find)
  223. {
  224. ob_maxngacceptqty.Text = "";
  225. ob_sampleqty.Text = "";
  226. }
  227. }
  228. }
  229. private void ad_qty_TextChanged_1(object sender, EventArgs e)
  230. {
  231. for (int i = 0; i < CheckTypeDGV.Rows.Count; i++)
  232. {
  233. CheckTypeDGV.Rows[i].Cells["oi_sampleqty"].Value = ob_sampleqty.Text;
  234. }
  235. }
  236. private void ob_projectcode_UserControlTextChanged(object sender, EventArgs e)
  237. {
  238. sql.Clear();
  239. sql.Append("select nvl(max(oi_id),0)oi_id,ci_kind,nvl(max(oi_sampleqty),0) oi_sampleqty from QUA_PROJECT left join ");
  240. sql.Append(" QUA_ProjectDetail on pd_prid=pr_id left join QUA_CheckItem on pd_ciid=ci_id ");
  241. sql.Append("left join OQCITEMS on oi_checkno ='" + ob_checkno.Text + "' and oi_projectcode='" + pr_code.Text + "' ");
  242. sql.Append("and oi_projectcode = pr_code and oi_checkkind = ci_kind where pr_code='" + pr_code.Text + "' group by ci_kind");
  243. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  244. BaseUtil.FillDgvWithDataTable(CheckTypeDGV, dt);
  245. }
  246. }
  247. }