OQC_CheckNoSplit.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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_NEW.DataOperate;
  10. using UAS_MES_NEW.Entity;
  11. using UAS_MES_NEW.PublicMethod;
  12. namespace UAS_MES_NEW.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 = SystemInf.dh;
  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. dh.BatchInsert("delete from oqcbatchdetail where obd_checkno='" + ob_checkno.Text + "' and obd_sncode =:obd_sncode ", new string[] { "obd_sncode" }, DeleteSn.ToArray());
  104. dh.BatchInsert("update package set pa_checkno='" + new_checkno.Text + "' where pa_outboxcode in (select distinct obd_outboxcode from oqcbatchdetail where obd_sncode=:obd_sncode)", new string[] { "obd_sncode" }, DeleteSn.ToArray());
  105. //删除之前的明细
  106. dh.BatchInsert("update makeserial set ms_checkno='" + new_checkno.Text + "' where ms_makecode='" + ob_makecode.Text + "' and ms_sncode=:obd_sncode ", new string[] { "obd_sncode" }, DeleteSn.ToArray());
  107. dh.BatchInsert("delete from oqcbatchdetail where obd_checkno='" + ob_checkno.Text + "' and obd_sncode =:obd_sncode ", new string[] { "obd_sncode" }, DeleteSn.ToArray());
  108. //插入新批次的从表,更新两个批次
  109. sqls.Add("update OQCBatch set ob_nowcheckqty=(select count(1) from oqcbatchdetail where obd_checkno='" + new_checkno.Text + "') where ob_checkno='" + new_checkno.Text + "'");
  110. sqls.Add("update OQCBatch set ob_nowcheckqty=(select count(1) from oqcbatchdetail where obd_checkno='" + ob_checkno.Text + "') where ob_checkno='" + ob_checkno.Text + "'");
  111. dh.ExecuteSQLTran(sqls.ToArray());
  112. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, "", User.UserLineCode, User.UserSourceCode, "抽检批拆解", "拆解成功,原批次" + ob_checkno.Text + "新批次:" + new_checkno.Text, "", ob_checkno.Text);
  113. DeleteSn.Clear();
  114. OperateResult.AppendText(">>批次" + ob_checkno.Text + ",成功拆解至批次" + new_checkno.Text + "\n ", Color.Green);
  115. GetBatch.PerformClick();
  116. }
  117. else OperateResult.AppendText(">>批次状态必须是待检验\n", Color.Red);
  118. }
  119. else OperateResult.AppendText(">>需要拆解的批次" + ob_checkno.Text + "不存在\n", Color.Red);
  120. }
  121. else OperateResult.AppendText(">>请勾选需要拆解的序列号\n", Color.Red);
  122. }
  123. private void OutBoxDGV_CellContentClick(object sender, DataGridViewCellEventArgs e)
  124. {
  125. if (e.RowIndex >= 0)
  126. {
  127. if (OutBoxDGV.Columns[e.ColumnIndex].Name == "choose")
  128. {
  129. if (OutBoxDGV.Rows[e.RowIndex].Cells["obd_outboxcode1"].Value.ToString() != "")
  130. {
  131. string Checked = OutBoxDGV.Rows[e.RowIndex].Cells[0].EditedFormattedValue.ToString();
  132. for (int i = 0; i < OutBoxDGV.Rows.Count; i++)
  133. {
  134. if (OutBoxDGV.Rows[i].Cells["obd_outboxcode1"].Value.ToString() == OutBoxDGV.Rows[e.RowIndex].Cells["obd_outboxcode1"].Value.ToString())
  135. {
  136. if (Checked == "True")
  137. OutBoxDGV.Rows[i].Cells[0].Value = true;
  138. else
  139. OutBoxDGV.Rows[i].Cells[0].Value = false;
  140. }
  141. }
  142. }
  143. int ChoosedNum = 0;
  144. for (int i = 0; i < OutBoxDGV.Rows.Count; i++)
  145. {
  146. if (OutBoxDGV.Rows[i].Cells[0].EditedFormattedValue.ToString() == "True")
  147. {
  148. ChoosedNum = ChoosedNum + 1;
  149. if (!DeleteSn.Contains(OutBoxDGV.Rows[i].Cells["obd_sncode"].Value.ToString()))
  150. DeleteSn.Add(OutBoxDGV.Rows[i].Cells["obd_sncode"].Value.ToString());
  151. }
  152. }
  153. choosedsn.Text = ChoosedNum.ToString();
  154. }
  155. }
  156. }
  157. private void sncode_KeyDown(object sender, KeyEventArgs e)
  158. {
  159. if (e.KeyCode == Keys.Enter)
  160. {
  161. bool FindSN = false;
  162. for (int i = 0; i < OutBoxDGV.Rows.Count; i++)
  163. {
  164. if (sncode.Text == OutBoxDGV.Rows[i].Cells["obd_sncode"].Value.ToString())
  165. {
  166. if (OutBoxDGV.Rows[i].Cells[0].EditedFormattedValue.ToString() != "True")
  167. OutBoxDGV.Rows[i].Cells[0].Value = true;
  168. else
  169. OutBoxDGV.Rows[i].Cells[0].Value = false;
  170. if (OutBoxDGV.Rows[i].Cells["obd_outboxcode1"].Value.ToString() != "")
  171. {
  172. string Checked = OutBoxDGV.Rows[i].Cells[0].EditedFormattedValue.ToString();
  173. for (int j = 0; j < OutBoxDGV.Rows.Count; j++)
  174. {
  175. if (OutBoxDGV.Rows[j].Cells["obd_outboxcode1"].Value.ToString() == OutBoxDGV.Rows[i].Cells["obd_outboxcode1"].Value.ToString())
  176. {
  177. if (Checked == "True")
  178. OutBoxDGV.Rows[j].Cells[0].Value = true;
  179. else
  180. OutBoxDGV.Rows[j].Cells[0].Value = false;
  181. }
  182. }
  183. FindSN = true;
  184. break;
  185. }
  186. }
  187. }
  188. if (!FindSN)
  189. OperateResult.AppendText(">>批次" + ob_checkno.Text + "不存在序列号" + sncode.Text + "\n", Color.Red);
  190. sncode.Text = "";
  191. }
  192. }
  193. bool ALL = true;
  194. private void ChooseAll_Click(object sender, EventArgs e)
  195. {
  196. for (int i = 0; i < OutBoxDGV.Rows.Count; i++)
  197. {
  198. OutBoxDGV.Rows[i].Cells["choose"].Value = ALL;
  199. }
  200. if (!ALL)
  201. ALL = true;
  202. else
  203. ALL = false;
  204. }
  205. private void OutBoxDGV_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  206. {
  207. int ChoosedNum = 0;
  208. for (int i = 0; i < OutBoxDGV.Rows.Count; i++)
  209. {
  210. if (OutBoxDGV.Rows[i].Cells[0].EditedFormattedValue.ToString() == "True")
  211. {
  212. ChoosedNum = ChoosedNum + 1;
  213. if (!DeleteSn.Contains(OutBoxDGV.Rows[i].Cells["obd_sncode"].Value.ToString()))
  214. DeleteSn.Add(OutBoxDGV.Rows[i].Cells["obd_sncode"].Value.ToString());
  215. }
  216. }
  217. choosedsn.Text = ChoosedNum.ToString();
  218. }
  219. }
  220. }