Special_CancelCollection.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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.Special
  13. {
  14. public partial class Special_CancelCollection : Form
  15. {
  16. DataHelper dh = SystemInf.dh;
  17. LogStringBuilder sql = new LogStringBuilder();
  18. public Special_CancelCollection()
  19. {
  20. InitializeComponent();
  21. }
  22. private void Confirm_Click(object sender, EventArgs e)
  23. {
  24. //获取序列号的途程
  25. DataTable dt = (DataTable)dh.ExecuteSql("select ms_id,ms_nextstepcode,ms_currentstepcode,ms_makecode,ms_status,ms_checkno,ms_craftcode,ms_prodcode,ms_stepcode from makeserial where ms_sncode='" + sn_code.Text + "' order by ms_id desc", "select");
  26. if (dt.Rows.Count > 0)
  27. {
  28. string pr_code = dt.Rows[0]["ms_prodcode"].ToString();
  29. string cr_code = dt.Rows[0]["ms_craftcode"].ToString();
  30. string ms_nextstepcode = dt.Rows[0]["ms_nextstepcode"].ToString();
  31. string ms_makecode = dt.Rows[0]["ms_makecode"].ToString();
  32. string ms_stepcode = dt.Rows[0]["ms_stepcode"].ToString();
  33. string ms_checkno = dt.Rows[0]["ms_checkno"].ToString();
  34. string ms_status = dt.Rows[0]["ms_status"].ToString();
  35. string ms_currentstepcode = dt.Rows[0]["ms_currentstepcode"].ToString();
  36. string ms_id = dt.Rows[0]["ms_id"].ToString();
  37. sql.Clear();
  38. sql.Append("select cd_stepcode from craft left join craftdetail on cr_id=cd_crid where ");
  39. sql.Append("cr_prodcode='" + pr_code + "' and cr_code='" + cr_code + "' order by cd_detno ");
  40. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  41. if (ms_stepcode == dt.Rows[0]["cd_stepcode"].ToString() || (ms_stepcode == "" && ms_nextstepcode == User.CurrentStepCode))
  42. {
  43. List<string> sqls = new List<string>();
  44. //存在不良删除不良记录
  45. if (ms_status == "3")
  46. {
  47. sqls.Add("delete from makebad where mb_sncode='" + sn_code.Text + "' and mb_makecode='" + ms_makecode + "'");
  48. //更新MakeCraftDetail表记录
  49. sqls.Add("update makecraftdetail set mcd_inqty=mcd_inqty-1 where mcd_macode='" + ms_makecode + "' and mcd_stepcode='" + ms_stepcode + "'");
  50. }
  51. else
  52. {
  53. sqls.Add("update makecraftdetail set mcd_inqty=mcd_inqty-1,mcd_outqty=mcd_outqty-1,mcd_okqty=mcd_okqty-1 where mcd_macode='" + ms_makecode + "' and mcd_stepcode='" + ms_stepcode + "'");
  54. }
  55. if (ms_checkno != "")
  56. {
  57. //删除送检明细
  58. sqls.Add("delete from oqcbatchdetail where obd_sncode='" + sn_code.Text + "' and obd_makecode='" + ms_makecode + "'");
  59. //送检数量-1
  60. sqls.Add("update oqcbatch set ob_nowcheckqty=ob_nowcheckqty-1 where ob_checkno='" + ms_checkno + "'");
  61. }
  62. //清除上料数据
  63. dt = (DataTable)dh.ExecuteSql("select cm_barcode,cm_materialtype,cm_makecode,cm_stepcode from craftmaterial where cm_sncode='" + sn_code.Text + "' and cm_makecode='" + ms_makecode + "'", "select");
  64. if (dt.Rows.Count > 0)
  65. {
  66. List<string> barcode = new List<string>();
  67. for (int i = 0; i < dt.Rows.Count; i++)
  68. {
  69. barcode.Add(dt.Rows[i]["cm_barcode"].ToString());
  70. //存在批管控的物料
  71. if (dt.Rows[i]["cm_materialtype"].ToString() == "2")
  72. {
  73. string mss_id = dh.getFieldDataByCondition("makesourcestock", "mss_id", "mss_makecode='" + dt.Rows[i]["cm_makecode"].ToString() + "' and mss_barcode='" + dt.Rows[i]["cm_barcode"].ToString() + "' and mss_stepcode='" + dt.Rows[i]["cm_stepcode"].ToString() + "' and mss_validtime is not null and mss_invalidtime is null").ToString();
  74. dh.UpdateByCondition("makesourcestock", "mss_remain=mss_remain+mss_baseqty,mss_useqty=mss_useqty-mss_baseqty", "mss_id='" + mss_id + "'");
  75. }
  76. }
  77. sql.Clear();
  78. sql.Append("update makeserial set ms_nextmacode='' where ms_sncode=:barcode and ms_nextmacode='" + ms_makecode + "'");
  79. dh.BatchInsert(sql.GetString(), new string[] { "barcode" }, barcode.ToArray());
  80. sqls.Add("delete from craftmaterial where cm_sncode='" + sn_code.Text + "' and cm_makecode='" + ms_makecode + "'");
  81. }
  82. //删除打印日志
  83. sqls.Add("delete from labelprintlog where lpl_value='" + sn_code.Text + "' and lpl_makecode='" + ms_makecode + "'");
  84. //删除老化记录
  85. sqls.Add("delete from AGINGRECORD where ar_sncode='" + sn_code.Text + "' and ar_macode='" + ms_makecode + "'");
  86. //初始化导入数据状态
  87. sqls.Add("update makesnlist set msl_status=0 where msl_sncode='" + sn_code.Text + "' and msl_makecode='" + ms_makecode + "' and msl_type='before'");
  88. //判断此时SN是否仍处于此工单SN导入范围
  89. if (dh.CheckExist("MAKESNRULE", "MSR_MAKECODE = '" + ms_makecode + "' and '" + sn_code.Text + "' BETWEEN MSR_STARTNO AND MSR_ENDNO AND MSR_TYPE = 'before'"))
  90. {
  91. ////初始化号段状态
  92. sqls.Add("update MAKESNRULEDETAIL set msd_status=0 where msd_sncode='" + sn_code.Text + "' and msd_makecode='" + ms_makecode + "' and msd_type='before'");
  93. }
  94. //不符合即删除
  95. else
  96. {
  97. ////初始化号段状态
  98. sqls.Add("delete MAKESNRULEDETAIL where msd_sncode='" + sn_code.Text + "' and msd_makecode='" + ms_makecode + "' and msd_type='before'");
  99. }
  100. //解除前一工单板的使用
  101. sqls.Add("update makeserial set ms_nextmacode='' where ms_sncode='" + sn_code.Text + "' and ms_nextmacode='" + ms_makecode + "'");
  102. //清除操作日志
  103. //sqls.Add("delete from commandlog where cl_makecode='" + ms_makecode + "' and cl_sncode='" + sn_code.Text + "'");
  104. //删除过站记录
  105. //sqls.Add("delete from makeprocess where mp_sncode='" + sn_code.Text + "' and mp_makecode='" + ms_makecode + "'");
  106. //投入数-1
  107. sqls.Add("update make set ma_inqty=ma_inqty-1 where ma_code='" + ms_makecode + "'");
  108. //删除StepPass
  109. sqls.Add("delete from steppassed where sp_sncode='" + sn_code.Text + "' and sp_makecode='" + ms_makecode + "'");
  110. sqls.Add("delete from makeserial where ms_id='" + ms_id + "'");
  111. dh.ExecuteSQLTran(sqls.ToArray());
  112. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode, User.UserLineCode, User.UserSourceCode, "取消采集", "取消采集成功", sn_code.Text, "");
  113. OperateResult.AppendText(">>序列号" + sn_code.Text + "成功解除绑定\n", Color.Green, sn_code);
  114. }
  115. else OperateResult.AppendText(">>序列号" + sn_code.Text + "不处于第一道工序,不允许取消采集\n", Color.Red, sn_code);
  116. }
  117. else OperateResult.AppendText(">>序列号" + sn_code.Text + "不存在\n", Color.Red, sn_code);
  118. }
  119. private void Clean_Click(object sender, EventArgs e)
  120. {
  121. OperateResult.Clear();
  122. }
  123. }
  124. }