OQC_PlanMaintain.cs 11 KB

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