OQC_CheckNoSplit.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Drawing;
  5. using System.Windows.Forms;
  6. using UAS_MES_NEW.DataOperate;
  7. using UAS_MES_NEW.Entity;
  8. using UAS_MES_NEW.PublicMethod;
  9. namespace UAS_MES_NEW.OQC
  10. {
  11. public partial class OQC_CheckNoSplit : Form
  12. {
  13. AutoSizeFormClass asc = new AutoSizeFormClass();
  14. DataHelper dh;
  15. LogStringBuilder sql = new LogStringBuilder();
  16. DataTable dt;
  17. string ErrorMessage = "";
  18. List<string> DeleteSn = new List<string>();
  19. public OQC_CheckNoSplit()
  20. {
  21. InitializeComponent();
  22. }
  23. private void OQC_CheckNoSplit_Load(object sender, EventArgs e)
  24. {
  25. asc.controllInitializeSize(this);
  26. dh = SystemInf.dh;
  27. }
  28. private void OQC_CheckNoSplit_SizeChanged(object sender, EventArgs e)
  29. {
  30. asc.controlAutoSize(this);
  31. }
  32. private void KeyDown(object sender, KeyEventArgs e)
  33. {
  34. if (e.KeyCode == Keys.Enter)
  35. {
  36. GetBatch.PerformClick();
  37. }
  38. }
  39. private void GetBatch_Click(object sender, EventArgs e)
  40. {
  41. string ErrorMessage = "";
  42. DataTable[] dt = LogicHandler.GetOQCBatch(ms_sncode.Text, obd_outboxcode.Text, ob_checkno.Text, "OQCCHECKNOSPLIT", out ErrorMessage);
  43. if (ErrorMessage == "")
  44. {
  45. BaseUtil.SetFormValue(this.Controls, dt[0]);
  46. if (dt[1] != null)
  47. {
  48. BaseUtil.FillDgvWithDataTable(OutBoxDGV, dt[1]);
  49. }
  50. int oldchecknocount = dh.getRowCount("oqcbatch", "ob_oldcheckno='" + ob_checkno.Text + "'");
  51. new_checkno.Text = ob_checkno.Text + "-0" + (oldchecknocount + 1);
  52. choosedsn.Text = "0";
  53. totalsn.Text = OutBoxDGV.Rows.Count.ToString();
  54. ALL = true;
  55. DeleteSn.Clear();
  56. }
  57. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  58. }
  59. private void SplitCheckNo_Click(object sender, EventArgs e)
  60. {
  61. if (choosedsn.Text != "0")
  62. {
  63. dt = dh.getFieldsDataByCondition("oqcbatch", new string[] { "ob_status", "ob_makecode" }, "ob_checkno='" + ob_checkno.Text + "'");
  64. if (dt.Rows.Count > 0)
  65. {
  66. if (dt.Rows[0]["ob_status"].ToString() == "UNCHECK")
  67. {
  68. List<string> sqls = new List<string>();
  69. //插入新批次的主表
  70. dt = (DataTable)dh.ExecuteSql("select ob_id,ob_makecode from oqcbatch where ob_checkno='" + new_checkno.Text + "'", "select");
  71. string ob_id = "";
  72. if (dt.Rows.Count > 0)
  73. {
  74. ob_id = dt.Rows[0]["ob_id"].ToString();
  75. if (ob_makecode.Text != dt.Rows[0]["ob_makecode"].ToString())
  76. {
  77. OperateResult.AppendText(">>原批次工单" + ob_makecode.Text + ",新批次工单" + dt.Rows[0]["ob_makecode"].ToString() + ",不允许拆批\n", Color.Red);
  78. return;
  79. }
  80. }
  81. if (dt.Rows.Count == 0)
  82. {
  83. ob_id = dh.GetSEQ("oqcbatch_seq");
  84. sql.Clear();
  85. sql.Append("insert into oqcbatch(ob_id,ob_checkno,ob_indate,ob_oldcheckno,ob_source,");
  86. sql.Append("ob_batchqty,ob_status,ob_prodcode,ob_sourcecode,ob_reworkcode,ob_orgcheckno,");
  87. sql.Append("OB_CRAFTCODE,OB_STEPCODE,OB_MAKECODE,oB_WCCODE,OB_FACTORY,OB_PROJECTCODE,OB_DESCRIPTION,");
  88. sql.Append("OB_AQLCODE,OB_REMARK,OB_INMAN) select '" + ob_id + "','" + new_checkno.Text + "',sysdate,");
  89. sql.Append("'" + ob_checkno.Text + "',ob_source,ob_batchqty,ob_status,ob_prodcode, ob_sourcecode,");
  90. sql.Append("ob_reworkcode,ob_orgcheckno,OB_CRAFTCODE, OB_STEPCODE,OB_MAKECODE,oB_WCCODE,OB_FACTORY,");
  91. sql.Append("OB_PROJECTCODE,OB_DESCRIPTION,OB_AQLCODE,OB_REMARK,'" + User.UserCode + "' from oqcbatch where ob_checkno='" + ob_checkno.Text + "'");
  92. sqls.Add(sql.GetString());
  93. }
  94. //插入新明细
  95. sql.Clear();
  96. sql.Append("insert into oqcbatchdetail(OBD_ID,OBD_OBID,OBD_CHECKNO,OBD_SNCODE,obd_outboxcode,OBD_MAKECODE");
  97. sql.Append(",OBD_BUILDDATE,obd_prodcode) SELECT oqcbatchdetail_seq.nextval,'" + ob_id + "','" + new_checkno.Text + "',OBD_SNCODE,obd_outboxcode");
  98. sql.Append(",OBD_MAKECODE,sysdate,obd_prodcode from oqcbatchdetail where obd_checkno='" + ob_checkno.Text + "' and obd_sncode=:obd_sncode ");
  99. dh.BatchInsert(sql.GetString(), new string[] { "obd_sncode" }, DeleteSn.ToArray());
  100. dh.BatchInsert("delete from oqcbatchdetail where obd_checkno='" + ob_checkno.Text + "' and obd_sncode =:obd_sncode ", new string[] { "obd_sncode" }, DeleteSn.ToArray());
  101. 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());
  102. //删除之前的明细
  103. 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());
  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. }