Special_GetBad.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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.Make;
  12. using UAS_MES_NEW.PublicMethod;
  13. namespace UAS_MES_NEW.Special
  14. {
  15. public partial class Special_GetBad : Form
  16. {
  17. DataHelper dh;
  18. LogStringBuilder sql = new LogStringBuilder();
  19. DataTable dt;
  20. public Special_GetBad()
  21. {
  22. InitializeComponent();
  23. }
  24. private void Special_BoxSplit_Load(object sender, EventArgs e)
  25. {
  26. dh = SystemInf.dh;
  27. }
  28. private void Split_Click(object sender, EventArgs e)
  29. {
  30. if (SN.Text == "" || makecode.Text == null || makecode.Text == ""|| bc_remark.Text==null|| bc_remark.Text=="")
  31. {
  32. OperatResult.AppendText(">>序列号,工单号,原因分析不允许为空\n", Color.Red);
  33. }
  34. else
  35. {
  36. //如果存在送检批号则进行删除
  37. if (dh.CheckExist("oqcbatchdetail", "obd_sncode='" + SN.Text + "'"))
  38. {
  39. string checkno = dh.getFieldDataByCondition("oqcbatchdetail", "obd_checkno", "obd_sncode='" + SN.Text + "'").ToString();
  40. string ifng = dh.getFieldDataByCondition("oqcbatchdetail", "obd_ifng", "obd_sncode='" + SN.Text + "'").ToString();
  41. if (ifng == "-1")
  42. {
  43. dh.ExecuteSql("delete OQCITEMSAMPLES where ois_sncode = '" + SN.Text + "'", "select");
  44. dh.ExecuteSql("update oqcbatch set ob_nowcheckqty=ob_nowcheckqty-1,ob_ngqty = ob_ngqty -1 where ob_checkno='" + checkno + "'", "update");
  45. }
  46. dh.ExecuteSql("delete from oqcbatchdetail where obd_sncode='" + SN.Text + "'", "delete");
  47. }
  48. //之前保存的不良就不再调用
  49. DataTable dt = dh.getFieldsDataByCondition("makeserial", new string[] { "ms_stepcode", "nvl(ms_ifrework,0)ms_ifrework", "ms_status" }, "ms_sncode='" + SN.Text + "' and ms_makecode='" + makecode.Text + "'");
  50. if (dt.Rows.Count > 0)
  51. {
  52. string ifrework = dt.Rows[0]["ms_ifrework"].ToString();
  53. string ms_stepcode = dt.Rows[0]["ms_stepcode"].ToString();
  54. string ms_status = dt.Rows[0]["ms_status"].ToString();
  55. if (ms_status == "2")
  56. {
  57. dh.UpdateByCondition("make", "ma_madeqty=nvl(ma_madeqty,0)-1", "ma_code='" + makecode.Text + "'");
  58. }
  59. dh.UpdateByCondition("makeserial", "ms_nextstepcode='',ms_status=3", "ms_sncode='" + SN.Text + "' and ms_makecode='" + makecode.Text + "' ");
  60. }
  61. if (dh.CheckExist("makeserial", "ms_sncode='" + SN.Text + "' and ms_makecode='" + makecode.Text + "' and ms_outboxcode is not null"))
  62. {
  63. string outboxcode = dh.getFieldDataByCondition("makeserial", "nvl(ms_outboxcode,' ')", "ms_sncode='" + SN.Text + "' and ms_makecode='" + makecode.Text + "' order by ms_id desc").ToString();
  64. string delete1 = "delete from packagedetail where pd_outboxcode = '"+ outboxcode + "' and pd_barcode = '" + SN.Text + "'";
  65. string delete2 = "update makeserial set ms_outboxcode = '', ms_currentstepcode = null where ms_sncode='" + SN.Text + "' and ms_makecode='" + makecode.Text + "'";
  66. string delete3 = "update package set pa_currentqty = pa_currentqty - 1,pa_totalqty = pa_totalqty - 1,pa_packageqty = pa_packageqty - 1,pa_status = 0 where pa_outboxcode = '" + outboxcode + "' ";
  67. string delete4 = "update package set pa_packtype = null, pa_sccode = null, pa_checkno = null, pa_salecode = null, pa_makecode = null, pa_prodcode = null where pa_outboxcode = '" + outboxcode + "' and pa_currentqty = 0";
  68. //string delete = "delete from makebad where mb_id = '" + mb_id + "'";
  69. dh.ExecuteSQLTran(delete1, delete2, delete3, delete4);
  70. }
  71. dh.ExecuteSql("insert into FIRSTALY(fa_id,fa_sncode,fa_makecode,fa_content,fa_date) values (FIRSTALY_seq.nextval,'"+SN.Text+"','"+makecode.Text+"','"+ bc_remark.Text+ "',SYSDATE)", "insert");
  72. LogicHandler.InsertMakeProcess(SN.Text, makecode.Text, User.UserSourceCode, "采集成不良", "首件测试不良", User.UserCode);
  73. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, makecode.Text, User.UserLineCode, User.UserSourceCode, "采集成不良", "首件采集不良", SN.Text,"");
  74. OperatResult.AppendText(">>序列号:" + SN.Text + "不良采集成功\n", Color.Green);
  75. BaseUtil.CleanControls(this.Controls);
  76. }
  77. }
  78. private void SN_KeyDown(object sender, KeyEventArgs e)
  79. {
  80. if (e.KeyCode == Keys.Enter)
  81. {
  82. sql.Clear();
  83. sql.Append("select ms_makecode makecode from makeserial left join make ");
  84. sql.Append("on ms_makecode=ma_code where ms_sncode = '" + SN.Text + "' order by ms_id desc");
  85. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  86. BaseUtil.SetFormValue(this.Controls, dt);
  87. string ms_paststep = "";
  88. if (!(dt.Rows.Count > 0))
  89. {
  90. OperatResult.AppendText(">>序列号:" + SN.Text + "不存在\n", Color.Red);
  91. BaseUtil.CleanForm(this);
  92. return;
  93. }
  94. if (!dh.CheckExist("FIRSTRECORD", "fr_content='" + SN.Text + "' and FR_STATUS = 0"))
  95. {
  96. string outboxcode = dh.getFieldDataByCondition("makeserial", "nvl(ms_outboxcode,' ')", "ms_sncode='" + SN.Text + "' and ms_makecode='" + makecode.Text + "' order by ms_id desc").ToString();
  97. if (!dh.CheckExist("FIRSTRECORD", "fr_content='" + outboxcode + "' and FR_STATUS = 0"))
  98. {
  99. OperatResult.AppendText(">>序列号:" + SN.Text + "非在测首件SN\n", Color.Red);
  100. BaseUtil.CleanForm(this);
  101. return;
  102. }
  103. }
  104. }
  105. }
  106. private void NewBadCode_Click(object sender, EventArgs e)
  107. {
  108. if (SN.Text == "" || makecode.Text == null || makecode.Text == "")
  109. {
  110. OperatResult.AppendText(">>序列号和工单号不允许为空\n", Color.Red);
  111. }
  112. else
  113. {
  114. Make_NewBadCode badcode = new Make_NewBadCode(SN.Text, makecode.Text);
  115. // badcode.FormClosed += LoadBadInfTree;
  116. BaseUtil.SetFormCenter(badcode);
  117. badcode.ShowDialog();
  118. }
  119. }
  120. }
  121. }