Special_CancelCollectionWN.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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.Special
  10. {
  11. public partial class Special_CancelCollectionWN : Form
  12. {
  13. DataHelper dh = SystemInf.dh;
  14. LogStringBuilder sql = new LogStringBuilder();
  15. public Special_CancelCollectionWN()
  16. {
  17. InitializeComponent();
  18. }
  19. private void Confirm_Click(object sender, EventArgs e)
  20. {
  21. DataTable dt = (DataTable)dh.ExecuteSql("select ms_sncode from makeserial where ms_imei1='" + sn_code.Text + "' order by ms_id desc", "select");
  22. if (dt.Rows.Count > 0)
  23. {
  24. sn_code.Text = dt.Rows[0]["ms_sncode"].ToString();
  25. }
  26. else
  27. {
  28. dt = (DataTable)dh.ExecuteSql("select ms_sncode from makeserial where ms_imei2='" + sn_code.Text + "' order by ms_id desc", "select");
  29. if (dt.Rows.Count > 0)
  30. {
  31. sn_code.Text = dt.Rows[0]["ms_sncode"].ToString();
  32. }
  33. else
  34. {
  35. dt = (DataTable)dh.ExecuteSql("select mil_sncode from makeimeilist where mil_imei1='" + sn_code.Text + "' order by mil_id desc", "select");
  36. if (dt.Rows.Count > 0)
  37. {
  38. sn_code.Text = dt.Rows[0]["mil_sncode"].ToString();
  39. }
  40. else
  41. {
  42. dt = (DataTable)dh.ExecuteSql("select mil_sncode from makeimeilist where mil_imei2='" + sn_code.Text + "' order by mil_id desc", "select");
  43. if (dt.Rows.Count > 0)
  44. {
  45. sn_code.Text = dt.Rows[0]["mil_sncode"].ToString();
  46. }
  47. }
  48. }
  49. }
  50. //获取序列号的途程
  51. dt = (DataTable)dh.ExecuteSql("select ms_code,ms_outboxcode,ms_sncode,ms_firstsn,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 + "' or ms_imei1='" + sn_code.Text + "' and ms_imei2='" + sn_code.Text + "')and ms_makecode='" + ma_code.Text + "' order by ms_id desc", "select");
  52. if (dt.Rows.Count > 0)
  53. {
  54. string pr_code = dt.Rows[0]["ms_prodcode"].ToString();
  55. string ms_outboxcode = dt.Rows[0]["ms_outboxcode"].ToString();
  56. string cr_code = dt.Rows[0]["ms_craftcode"].ToString();
  57. string ms_nextstepcode = dt.Rows[0]["ms_nextstepcode"].ToString();
  58. string ms_makecode = dt.Rows[0]["ms_makecode"].ToString();
  59. string ms_stepcode = dt.Rows[0]["ms_stepcode"].ToString();
  60. string ms_checkno = dt.Rows[0]["ms_checkno"].ToString();
  61. string ms_status = dt.Rows[0]["ms_status"].ToString();
  62. string ms_currentstepcode = dt.Rows[0]["ms_currentstepcode"].ToString();
  63. string ms_id = dt.Rows[0]["ms_id"].ToString();
  64. string ms_firstsn = dt.Rows[0]["ms_firstsn"].ToString();
  65. string ms_code = dt.Rows[0]["ms_code"].ToString();
  66. sn_code.Text = dt.Rows[0]["ms_sncode"].ToString();
  67. sql.Clear();
  68. sql.Append("select cd_stepcode from craft left join craftdetail on cr_id=cd_crid where ");
  69. sql.Append("cr_prodcode='" + pr_code + "' and cr_code='" + cr_code + "' order by cd_detno ");
  70. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  71. //if (ms_stepcode == dt.Rows[0]["cd_stepcode"].ToString() || (ms_stepcode == "" && ms_nextstepcode == User.CurrentStepCode))
  72. //{
  73. List<string> sqls = new List<string>();
  74. if (ms_outboxcode != "")
  75. {
  76. OperateResult.AppendText(">>序列号" + sn_code.Text + "已装箱" + ms_outboxcode + ",不允许取消采集\n", Color.Red, sn_code);
  77. return;
  78. }
  79. //存在不良删除不良记录
  80. if (ms_status == "3")
  81. {
  82. sqls.Add("delete from makebad where mb_sncode='" + sn_code.Text + "' and mb_makecode='" + ms_makecode + "'");
  83. //更新MakeCraftDetail表记录
  84. sqls.Add("update makecraftdetail set mcd_inqty=mcd_inqty-1 where mcd_macode='" + ms_makecode + "' and instr((select ms_paststep from makeserial where ms_sncode='" + sn_code.Text + "' and ms_makecode='" + ms_makecode + "'),mcd_stepcode)>0 ");
  85. }
  86. else
  87. {
  88. 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 instr((select ms_paststep from makeserial where ms_sncode='" + sn_code.Text + "' and ms_makecode='" + ms_makecode + "'),mcd_stepcode)>0 ");
  89. }
  90. if (ms_checkno != "")
  91. {
  92. //删除送检明细
  93. sqls.Add("delete from oqcbatchdetail where obd_sncode='" + sn_code.Text + "' and obd_makecode='" + ms_makecode + "'");
  94. //送检数量-1
  95. sqls.Add("update oqcbatch set ob_nowcheckqty=ob_nowcheckqty-1 where ob_checkno='" + ms_checkno + "'");
  96. }
  97. //清除上料数据
  98. 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");
  99. if (dt.Rows.Count > 0)
  100. {
  101. List<string> barcode = new List<string>();
  102. for (int i = 0; i < dt.Rows.Count; i++)
  103. {
  104. barcode.Add(dt.Rows[i]["cm_barcode"].ToString());
  105. //存在批管控的物料
  106. if (dt.Rows[i]["cm_materialtype"].ToString() == "2")
  107. {
  108. 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();
  109. dh.UpdateByCondition("makesourcestock", "mss_remain=mss_remain+mss_baseqty,mss_useqty=mss_useqty-mss_baseqty", "mss_id='" + mss_id + "'");
  110. }
  111. }
  112. sql.Clear();
  113. sql.Append("update makeserial set ms_nextmacode='' where ms_sncode=:barcode and ms_nextmacode='" + ms_makecode + "'");
  114. dh.BatchInsert(sql.GetString(), new string[] { "barcode" }, barcode.ToArray());
  115. sqls.Add("update craftmaterial set cm_status=-1 where cm_sncode='" + sn_code.Text + "' and cm_makecode='" + ms_makecode + "'");
  116. }
  117. sqls.Add("delete from sninfo where si_sn='" + sn_code.Text + "'");
  118. //sqls.Add("update makeaddresslist set mal_sncode='',mal_status=0 where mal_sncode='" + sn_code.Text + "'");
  119. //删除打印日志
  120. sqls.Add("delete from labelprintlog where lpl_value='" + sn_code.Text + "' and lpl_makecode='" + ms_makecode + "'");
  121. //删除老化记录
  122. sqls.Add("delete from AGINGRECORD where ar_sncode='" + sn_code.Text + "' and ar_macode='" + ms_makecode + "'");
  123. //删除IMIE分配记录
  124. sqls.Add("update makeimeilist set mil_status=0,mil_sncode='' where mil_sncode='" + sn_code.Text + "' and mil_makecode='" + ms_makecode + "'");
  125. //更新MAC使用记录
  126. sqls.Add("update makeaddresslist set mal_status=0,mal_sncode='' where mal_sncode='" + sn_code.Text + "' and mal_makecode='" + ms_makecode + "'");
  127. //解除前一工单板的使用
  128. sqls.Add("update makeserial set ms_nextmacode='' where ms_firstsn='" + ms_firstsn + "' or ms_code='" + ms_code + "' and ms_nextmacode='" + ms_makecode + "'");
  129. //初始化导入数据状态
  130. sqls.Add("update makesnlist set msl_status=0 where msl_sncode='" + sn_code.Text + "' and msl_makecode='" + ms_makecode + "' and msl_type='before'");
  131. ////初始化号段状态
  132. sqls.Add("update MAKESNRULEDETAIL set msd_status=0 where msd_sncode='" + sn_code.Text + "' and msd_makecode='" + ms_makecode + "' and msd_type='before'");
  133. sqls.Add("delete from makesnrelation where SN='" + sn_code.Text + "' and makecode='" + ms_makecode + "' ");
  134. //清除操作日志
  135. //sqls.Add("delete from commandlog where cl_makecode='" + ms_makecode + "' and cl_sncode='" + sn_code.Text + "'");
  136. //删除过站记录
  137. //sqls.Add("delete from makeprocess where mp_sncode='" + sn_code.Text + "' and mp_makecode='" + ms_makecode + "'");
  138. //投入数-1
  139. sqls.Add("update make set ma_inqty=ma_inqty-1 where ma_code='" + ms_makecode + "'");
  140. //删除StepPass
  141. sqls.Add("delete from steppassed where sp_sncode='" + ms_firstsn + "' or sp_sncode='" + ms_code + "' and sp_makecode='" + ms_makecode + "'");
  142. sqls.Add("delete from makeserial where ms_id='" + ms_id + "'");
  143. dh.ExecuteSQLTran(sqls.ToArray());
  144. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode, User.UserLineCode, User.UserSourceCode, "取消采集", "取消采集成功", sn_code.Text, "");
  145. OperateResult.AppendText(">>序列号" + sn_code.Text + "成功解除绑定\n", Color.Green, sn_code);
  146. //}
  147. //else OperateResult.AppendText(">>序列号" + sn_code.Text + "不处于第一道工序,不允许取消采集\n", Color.Red, sn_code);
  148. }
  149. else OperateResult.AppendText(">>序列号" + sn_code.Text + "不存在于工单" + ma_code.Text + "\n", Color.Red, sn_code);
  150. }
  151. private void Clean_Click(object sender, EventArgs e)
  152. {
  153. OperateResult.Clear();
  154. }
  155. private void Special_CancelCollection_Load(object sender, EventArgs e)
  156. {
  157. ma_code.TableName = " make left join product on ma_prodcode=pr_code";
  158. ma_code.SelectField = "ma_code # 工单编号,pr_code # 产品编号,pr_spec # 型号";
  159. ma_code.FormName = Name;
  160. ma_code.SetValueField = new string[] { "ma_code" };
  161. ma_code.Condition = "ma_statuscode='STARTED'";
  162. ma_code.DbChange += pr_code_DbChange;
  163. }
  164. DataTable Dbfind;
  165. private void pr_code_DbChange(object sender, EventArgs e)
  166. {
  167. Dbfind = ma_code.ReturnData;
  168. BaseUtil.SetFormValue(this.Controls, Dbfind);
  169. DataTable dt = (DataTable)dh.ExecuteSql("select ma_qty,ma_prodcode,pr_detail,ma_printnum from make left join product on ma_prodcode=pr_code left join (select count(1)ma_printnum,mil_makecode from makeimeilist where mil_printstatus=-1 group by mil_makecode) on mil_makecode=ma_code where ma_code='" + ma_code.Text + "'", "select");
  170. if (dt.Rows.Count > 0)
  171. {
  172. pr_code.Text = dt.Rows[0]["ma_prodcode"].ToString();
  173. pr_detail.Text = dt.Rows[0]["pr_detail"].ToString();
  174. }
  175. }
  176. }
  177. }