OQC_CheckNoSplit.cs 12 KB

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