OQC_PlanMaintain.cs 9.6 KB

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