OQC_CheckNoSplit.cs 12 KB

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