OQC_PlanMaintain.cs 10 KB

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