OQC_CheckNoSplit.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using UAS_MES.DataOperate;
  10. using UAS_MES.Entity;
  11. using UAS_MES.PublicMethod;
  12. namespace UAS_MES.OQC
  13. {
  14. public partial class OQC_CheckNoSplit : Form
  15. {
  16. AutoSizeFormClass asc = new AutoSizeFormClass();
  17. DataHelper dh;
  18. LogStringBuilder sql = new LogStringBuilder();
  19. DataTable dt;
  20. string ErrorMessage = "";
  21. List<string> DeleteSn = new List<string>();
  22. public OQC_CheckNoSplit()
  23. {
  24. InitializeComponent();
  25. }
  26. private void OQC_CheckNoSplit_Load(object sender, EventArgs e)
  27. {
  28. asc.controllInitializeSize(this);
  29. dh = new DataHelper();
  30. }
  31. private void OQC_CheckNoSplit_SizeChanged(object sender, EventArgs e)
  32. {
  33. asc.controlAutoSize(this);
  34. }
  35. private void KeyDown(object sender, KeyEventArgs e)
  36. {
  37. if (e.KeyCode == Keys.Enter)
  38. {
  39. GetBatch.PerformClick();
  40. }
  41. }
  42. private void GetBatch_Click(object sender, EventArgs e)
  43. {
  44. string ErrorMessage = "";
  45. DataTable[] dt = LogicHandler.GetOQCBatch(ms_sncode.Text, obd_outboxcode.Text, ob_checkno.Text, "OQCCHECKNOSPLIT", out ErrorMessage);
  46. if (ErrorMessage == "")
  47. {
  48. BaseUtil.SetFormValue(this.Controls, dt[0]);
  49. if (dt[1] != null)
  50. {
  51. BaseUtil.FillDgvWithDataTable(OutBoxDGV, dt[1]);
  52. }
  53. int oldchecknocount = dh.getRowCount("oqcbatch", "ob_oldcheckno='" + ob_checkno.Text + "'");
  54. new_checkno.Text = ob_checkno.Text + "-0" + (oldchecknocount + 1);
  55. choosedsn.Text = "0";
  56. totalsn.Text = OutBoxDGV.Rows.Count.ToString();
  57. ALL = true;
  58. DeleteSn.Clear();
  59. }
  60. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  61. }
  62. private void SplitCheckNo_Click(object sender, EventArgs e)
  63. {
  64. if (choosedsn.Text != "0")
  65. {
  66. dt = dh.getFieldsDataByCondition("oqcbatch", new string[] { "ob_status", "ob_makecode" }, "ob_checkno='" + ob_checkno.Text + "'");
  67. if (dt.Rows.Count > 0)
  68. {
  69. if (dt.Rows[0]["ob_status"].ToString() == "UNCHECK")
  70. {
  71. List<string> sqls = new List<string>();
  72. //插入新批次的主表
  73. dt = (DataTable)dh.ExecuteSql("select ob_id,ob_makecode from oqcbatch where ob_checkno='" + new_checkno.Text + "'", "select");
  74. string ob_id = "";
  75. if (dt.Rows.Count > 0)
  76. {
  77. ob_id = dt.Rows[0]["ob_id"].ToString();
  78. if (ob_makecode.Text != dt.Rows[0]["ob_makecode"].ToString())
  79. {
  80. OperateResult.AppendText(">>原批次工单" + ob_makecode.Text + ",新批次工单" + dt.Rows[0]["ob_makecode"].ToString() + ",不允许拆批\n", Color.Red);
  81. return;
  82. }
  83. }
  84. if (dt.Rows.Count == 0)
  85. {
  86. ob_id = dh.GetSEQ("oqcbatch_seq");
  87. sql.Clear();
  88. sql.Append("insert into oqcbatch(ob_id,ob_checkno,ob_indate,ob_oldcheckno,ob_source,");
  89. sql.Append("ob_batchqty,ob_status,ob_prodcode,ob_sourcecode,ob_reworkcode,ob_orgcheckno,");
  90. sql.Append("OB_CRAFTCODE,OB_STEPCODE,OB_MAKECODE,oB_WCCODE,OB_FACTORY,OB_PROJECTCODE,OB_DESCRIPTION,");
  91. sql.Append("OB_AQLCODE,OB_REMARK,OB_INMAN) select '" + ob_id + "','" + new_checkno.Text + "',sysdate,");
  92. sql.Append("'" + ob_checkno.Text + "',ob_source,ob_batchqty,ob_status,ob_prodcode, ob_sourcecode,");
  93. sql.Append("ob_reworkcode,ob_orgcheckno,OB_CRAFTCODE, OB_STEPCODE,OB_MAKECODE,oB_WCCODE,OB_FACTORY,");
  94. sql.Append("OB_PROJECTCODE,OB_DESCRIPTION,OB_AQLCODE,OB_REMARK,'" + User.UserCode + "' from oqcbatch where ob_checkno='" + ob_checkno.Text + "'");
  95. sqls.Add(sql.GetString());
  96. }
  97. //插入新明细
  98. sql.Clear();
  99. sql.Append("insert into oqcbatchdetail(OBD_ID,OBD_OBID,OBD_CHECKNO,OBD_SNCODE,obd_outboxcode,OBD_MAKECODE");
  100. sql.Append(",OBD_BUILDDATE,obd_prodcode) SELECT oqcbatchdetail_seq.nextval,'" + ob_id + "','" + new_checkno.Text + "',OBD_SNCODE,obd_outboxcode");
  101. sql.Append(",OBD_MAKECODE,sysdate,obd_prodcode from oqcbatchdetail where obd_checkno='" + ob_checkno.Text + "' and obd_sncode=:obd_sncode ");
  102. dh.BatchInsert(sql.GetString(), new string[] { "obd_sncode" }, DeleteSn.ToArray());
  103. //删除之前的明细
  104. dh.BatchInsert("delete from oqcbatchdetail where obd_checkno='" + ob_checkno.Text + "' and obd_sncode =:obd_sncode ", new string[] { "obd_sncode" }, DeleteSn.ToArray());
  105. //插入新批次的从表,更新两个批次
  106. sqls.Add("update OQCBatch set ob_nowcheckqty=(select count(1) from oqcbatchdetail where obd_checkno='" + new_checkno.Text + "') where ob_checkno='" + new_checkno.Text + "'");
  107. sqls.Add("update OQCBatch set ob_nowcheckqty=(select count(1) from oqcbatchdetail where obd_checkno='" + ob_checkno.Text + "') where ob_checkno='" + ob_checkno.Text + "'");
  108. dh.ExecuteSQLTran(sqls.ToArray());
  109. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, "", User.UserLineCode, User.UserSourceCode, "抽检批拆解", "拆解成功,原批次" + ob_checkno.Text + "新批次:" + new_checkno.Text, "", ob_checkno.Text);
  110. DeleteSn.Clear();
  111. OperateResult.AppendText(">>批次" + ob_checkno.Text + ",成功拆解至批次" + new_checkno.Text + "\n ", Color.Green);
  112. GetBatch.PerformClick();
  113. }
  114. else OperateResult.AppendText(">>批次状态必须是待检验\n", Color.Red);
  115. }
  116. else OperateResult.AppendText(">>需要拆解的批次" + ob_checkno.Text + "不存在\n", Color.Red);
  117. }
  118. else OperateResult.AppendText(">>请勾选需要拆解的序列号\n", Color.Red);
  119. }
  120. private void OutBoxDGV_CellContentClick(object sender, DataGridViewCellEventArgs e)
  121. {
  122. if (e.RowIndex >= 0)
  123. {
  124. if (OutBoxDGV.Columns[e.ColumnIndex].Name == "choose")
  125. {
  126. if (OutBoxDGV.Rows[e.RowIndex].Cells["obd_outboxcode1"].Value.ToString() != "")
  127. {
  128. string Checked = OutBoxDGV.Rows[e.RowIndex].Cells[0].EditedFormattedValue.ToString();
  129. for (int i = 0; i < OutBoxDGV.Rows.Count; i++)
  130. {
  131. if (OutBoxDGV.Rows[i].Cells["obd_outboxcode1"].Value.ToString() == OutBoxDGV.Rows[e.RowIndex].Cells["obd_outboxcode1"].Value.ToString())
  132. {
  133. if (Checked == "True")
  134. OutBoxDGV.Rows[i].Cells[0].Value = true;
  135. else
  136. OutBoxDGV.Rows[i].Cells[0].Value = false;
  137. }
  138. }
  139. }
  140. int ChoosedNum = 0;
  141. for (int i = 0; i < OutBoxDGV.Rows.Count; i++)
  142. {
  143. if (OutBoxDGV.Rows[i].Cells[0].EditedFormattedValue.ToString() == "True")
  144. {
  145. ChoosedNum = ChoosedNum + 1;
  146. if (!DeleteSn.Contains(OutBoxDGV.Rows[i].Cells["obd_sncode"].Value.ToString()))
  147. DeleteSn.Add(OutBoxDGV.Rows[i].Cells["obd_sncode"].Value.ToString());
  148. }
  149. }
  150. choosedsn.Text = ChoosedNum.ToString();
  151. }
  152. }
  153. }
  154. private void sncode_KeyDown(object sender, KeyEventArgs e)
  155. {
  156. if (e.KeyCode == Keys.Enter)
  157. {
  158. bool FindSN = false;
  159. for (int i = 0; i < OutBoxDGV.Rows.Count; i++)
  160. {
  161. if (sncode.Text == OutBoxDGV.Rows[i].Cells["obd_sncode"].Value.ToString())
  162. {
  163. if (OutBoxDGV.Rows[i].Cells[0].EditedFormattedValue.ToString() != "True")
  164. OutBoxDGV.Rows[i].Cells[0].Value = true;
  165. else
  166. OutBoxDGV.Rows[i].Cells[0].Value = false;
  167. if (OutBoxDGV.Rows[i].Cells["obd_outboxcode1"].Value.ToString() != "")
  168. {
  169. string Checked = OutBoxDGV.Rows[i].Cells[0].EditedFormattedValue.ToString();
  170. for (int j = 0; j < OutBoxDGV.Rows.Count; j++)
  171. {
  172. if (OutBoxDGV.Rows[j].Cells["obd_outboxcode1"].Value.ToString() == OutBoxDGV.Rows[i].Cells["obd_outboxcode1"].Value.ToString())
  173. {
  174. if (Checked == "True")
  175. OutBoxDGV.Rows[j].Cells[0].Value = true;
  176. else
  177. OutBoxDGV.Rows[j].Cells[0].Value = false;
  178. }
  179. }
  180. FindSN = true;
  181. break;
  182. }
  183. }
  184. }
  185. if (!FindSN)
  186. OperateResult.AppendText(">>批次" + ob_checkno.Text + "不存在序列号" + sncode.Text + "\n", Color.Red);
  187. sncode.Text = "";
  188. }
  189. }
  190. bool ALL = true;
  191. private void ChooseAll_Click(object sender, EventArgs e)
  192. {
  193. for (int i = 0; i < OutBoxDGV.Rows.Count; i++)
  194. {
  195. OutBoxDGV.Rows[i].Cells["choose"].Value = ALL;
  196. }
  197. if (!ALL)
  198. ALL = true;
  199. else
  200. ALL = false;
  201. }
  202. private void OutBoxDGV_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  203. {
  204. int ChoosedNum = 0;
  205. for (int i = 0; i < OutBoxDGV.Rows.Count; i++)
  206. {
  207. if (OutBoxDGV.Rows[i].Cells[0].EditedFormattedValue.ToString() == "True")
  208. {
  209. ChoosedNum = ChoosedNum + 1;
  210. if (!DeleteSn.Contains(OutBoxDGV.Rows[i].Cells["obd_sncode"].Value.ToString()))
  211. DeleteSn.Add(OutBoxDGV.Rows[i].Cells["obd_sncode"].Value.ToString());
  212. }
  213. }
  214. choosedsn.Text = ChoosedNum.ToString();
  215. }
  216. }
  217. }