Special_DeleteWN.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. using HslCommunication.Profinet.Knx;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Windows.Forms;
  10. using UAS_MES_NEW.DataOperate;
  11. using UAS_MES_NEW.Entity;
  12. using UAS_MES_NEW.PublicMethod;
  13. using static System.Runtime.CompilerServices.RuntimeHelpers;
  14. namespace UAS_MES_NEW.Special
  15. {
  16. public partial class Special_DeleteWN : Form
  17. {
  18. DataHelper dh;
  19. LogStringBuilder sql = new LogStringBuilder();
  20. AutoSizeFormClass asc = new AutoSizeFormClass();
  21. DataTable Dbfind;
  22. DataTable dt;
  23. List<String> sb = new List<string>();
  24. public Special_DeleteWN()
  25. {
  26. InitializeComponent();
  27. }
  28. private void Special_BoxSplit_Load(object sender, EventArgs e)
  29. {
  30. ma_code.TableName = " make left join product on ma_prodcode=pr_code";
  31. ma_code.SelectField = "ma_code # 工单编号,pr_code # 产品编号,pr_spec # 型号";
  32. ma_code.FormName = Name;
  33. ma_code.SetValueField = new string[] { "ma_code" };
  34. ma_code.Condition = "ma_statuscode='STARTED'";
  35. ma_code.DbChange += pr_code_DbChange;
  36. dh = SystemInf.dh;
  37. asc.controllInitializeSize(this);
  38. }
  39. private void pr_code_DbChange(object sender, EventArgs e)
  40. {
  41. Dbfind = ma_code.ReturnData;
  42. BaseUtil.SetFormValue(this.Controls, Dbfind);
  43. 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");
  44. }
  45. private void Cd_stepcode_DbChange(object sender, EventArgs e)
  46. {
  47. BaseUtil.SetFormValue(this.Controls, Dbfind);
  48. }
  49. private bool ReSN(string sncode)
  50. {
  51. DataTable dt = (DataTable)dh.ExecuteSql("select ms_makecode,ms_sncode,ms_outboxcode,ms_code from makeserial where ms_sncode ='" + sncode + "' order by ms_id desc", "select");
  52. if (dt.Rows.Count > 0)
  53. {
  54. string ms_makecode = dt.Rows[0]["ms_makecode"].ToString();
  55. string ms_sncode = dt.Rows[0]["ms_sncode"].ToString();
  56. string ms_code = dt.Rows[0]["ms_code"].ToString();
  57. string ms_outboxcode = dt.Rows[0]["ms_outboxcode"].ToString();
  58. if (ms_outboxcode != "") {
  59. OperatResult.AppendText("SN:" + sncode + "已装箱不允许解绑\n", Color.Red);
  60. return false;
  61. }
  62. dh.ExecuteSql("delete makeserial where ms_sncode='" + sncode + "' and ms_makecode='" + ms_makecode + "'", "update");
  63. dh.ExecuteSql("delete makebad where mb_sncode = '" + sncode + "' and mb_status = 0", "delete");
  64. dh.ExecuteSql("delete labelprintlog where lpl_value = '" + sncode + "' and lpl_makecode='" + ms_makecode + "'", "delete");
  65. sql.Clear();
  66. sql.Append("delete craftmaterial where cm_sncode = '" + sncode + "' and cm_makecode='" + ms_makecode + "' ");
  67. dh.ExecuteSql(sql.GetString(), "update");
  68. List<string> sqls = new List<string>();
  69. sqls.Add("delete from sninfo where si_sn='" + ms_sncode + "'");
  70. //sqls.Add("update makeaddresslist set mal_sncode='',mal_status=0 where mal_sncode='" + sn_code.Text + "'");
  71. //删除打印日志
  72. sqls.Add("delete from labelprintlog where lpl_value='" + ms_sncode + "' and lpl_makecode='" + ms_makecode + "'");
  73. //删除老化记录
  74. sqls.Add("delete from AGINGRECORD where ar_sncode='" + ms_sncode + "' and ar_macode='" + ms_makecode + "'");
  75. sqls.Add("delete from steppassed where sp_sncode='" + ms_sncode + "' or sp_sncode='"+ms_code+"' and sp_makecode='" + ms_makecode + "'");
  76. //删除IMIE分配记录
  77. sqls.Add("update makeimeilist set mil_status=0,mil_sncode='',mil_psn='' where mil_sncode='" + ms_sncode + "' and mil_makecode='" + ms_makecode + "'");
  78. //更新MAC使用记录
  79. sqls.Add("update makeserial set ms_nextmacode='' where ms_sncode='" + ms_sncode + "' or ms_code='" + ms_code + "' and ms_nextmacode='" + ms_makecode + "'");
  80. sqls.Add("update makeaddresslist set mal_status=0,mal_sncode='' where mal_sncode='" + ms_sncode + "' and mal_makecode='" + ms_makecode + "'");
  81. //初始化导入数据状态
  82. sqls.Add("update makesnlist set msl_status=0 where msl_sncode='" + ms_sncode + "' and msl_makecode='" + ms_makecode + "' and msl_type='before'");
  83. ////初始化号段状态
  84. sqls.Add("update MAKESNRULEDETAIL set msd_status=0 where msd_sncode='" + ms_sncode + "' and msd_makecode='" + ms_makecode + "' and msd_type='before'");
  85. sqls.Add("delete from makesnrelation where SN='" + ms_sncode + "' and makecode='" + ms_makecode + "' ");
  86. dh.ExecuteSQLTran(sqls.ToArray());
  87. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode, User.UserLineCode, User.UserSourceCode, "工单解绑", "工单解绑成功", sncode, "");
  88. }
  89. return true;
  90. }
  91. private void Split_Click(object sender, EventArgs e)
  92. {
  93. if (sb.Count == 0)
  94. {
  95. OperatResult.AppendText(">>采集数工位不能为空\n", Color.Red);
  96. return;
  97. }
  98. string Delete = MessageBox.Show(this.ParentForm, "是否确认解绑工单?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  99. if (Delete == "Yes")
  100. {
  101. if (serBtn.Checked)
  102. {
  103. for (int i = 0; i < sb.Count; i++)
  104. {
  105. if (ReSN(sb[i].ToString()))
  106. OperatResult.AppendText("SN:" + sb[i].ToString() + "解绑完成\n", Color.Green);
  107. }
  108. WeighRecord.Clear();
  109. sb.Clear();
  110. }
  111. else if (bigboxBtn.Checked)
  112. {
  113. for (int i = 0; i < sb.Count; i++)
  114. {
  115. DataTable dt2 = (DataTable)dh.ExecuteSql("select ms_sncode from makeserial where ms_outboxcode = '" + sb[i].ToString() + "'", "select");
  116. for (int k = 0; k < dt2.Rows.Count; k++)
  117. {
  118. ReSN(dt2.Rows[k]["ms_sncode"].ToString());
  119. }
  120. dh.ExecuteSql("delete from labelprintlog where lpl_value='" + sb[i].ToString() + "'", "delete");
  121. dh.ExecuteSql("insert into PACKAGEBACKUP select * from package where pa_outboxcode='" + sb[i].ToString() + "'", "insert");
  122. dh.ExecuteSql("insert into PACKAGEBACKUPDETAIL select * from packagedetail where pd_outboxcode='" + sb[i].ToString() + "'", "insert");
  123. dh.ExecuteSql("delete from package where pa_outboxcode = '" + sb[i].ToString() + "'", "delete");
  124. //删除箱的明细
  125. dh.ExecuteSql("delete from packagedetail where pd_outboxcode='" + sb[i].ToString() + "'", "delete");
  126. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode.Text, User.UserLineCode, User.UserSourceCode, "解绑工单", "解绑工单成功", sb[i].ToString(), "");
  127. OperatResult.AppendText("卡通箱:" + sb[i].ToString() + "解绑完成\n", Color.Green);
  128. }
  129. WeighRecord.Clear();
  130. sb.Clear();
  131. }
  132. sql.Clear();
  133. sql.Append("MERGE INTO makecraftdetail USING (select mcd_macode,mcd_detno,mcd_stepcode,mcd_stepname,nvl(count(distinct A.ms_sncode),0) n,nvl(count(distinct B.ms_sncode),0) bn,(select nvl(count(distinct sp_sncode),0) from STEPPASSED where SP_MAKECODE = mcd_macode AND SP_STEPCODE = mcd_stepcode) inqty from MAKECRAFTdetail");
  134. sql.Append(" left join makeserial A on mcd_macode = A.ms_makecode and mcd_stepcode = A.ms_nextstepcode AND A.MS_STATUS = 1 LEFT JOIN MAKESERIAL B ON mcd_macode = B.ms_makecode AND MCD_STEPCODE = B.MS_STEPCODE AND B.MS_STATUS = 3 where mcd_macode = '" + ms_makecode.Text + "' group by mcd_macode,mcd_detno, mcd_stepcode, mcd_stepname order by mcd_detno asc) A");
  135. sql.Append(" ON (makecraftdetail.MCD_MACODE = A.MCD_MACODE and makecraftdetail.mcd_stepcode = A.mcd_stepcode) ");
  136. sql.Append(" WHEN MATCHED THEN UPDATE SET makecraftdetail.mcd_inqty = A.inqty,makecraftdetail.mcd_outqty = A.inqty,makecraftdetail.mcd_okqty = A.inqty ");
  137. dh.ExecuteSql(sql.GetString(), "update");
  138. }
  139. }
  140. private void bigboxBtn_Click(object sender, EventArgs e)
  141. {
  142. if (((RadioButton)sender).Checked == true)
  143. {
  144. if (WeighRecord.Items.Count > 0)
  145. {
  146. string logout_confirm = MessageBox.Show(this.ParentForm, "是否更换采集项(已录入信息会清空)?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  147. if (logout_confirm == "Yes")
  148. {
  149. WeighRecord.Items.Clear();
  150. sb.Clear();
  151. ms_makecode.Text = "";
  152. ms_prodcode.Text = "";
  153. }
  154. else
  155. {
  156. serBtn.Checked = bigboxBtn.Checked;
  157. bigboxBtn.Checked = !serBtn.Checked;
  158. }
  159. }
  160. if (((RadioButton)sender).Name == "serBtn")
  161. {
  162. input.Focus();
  163. OperatResult.AppendText("请输入序列号进行采集\n", Color.Black, input);
  164. }
  165. else if (((RadioButton)sender).Name == "bigboxBtn")
  166. {
  167. input.Focus();
  168. OperatResult.AppendText("请输入箱号进行采集\n", Color.Black, input);
  169. }
  170. }
  171. }
  172. private void input_KeyDown(object sender, KeyEventArgs e)
  173. {
  174. if (e.KeyCode == Keys.Enter)
  175. {
  176. if (serBtn.Checked)
  177. {
  178. dt = (DataTable)dh.ExecuteSql("select ms_makecode,ms_prodcode,ms_sncode,ms_craftcode cr_code,ms_status,ms_outboxcode from makeserial where ms_sncode = '" + input.Text + "' or ms_imei1='" + input.Text + "' or ms_imei2='" + input.Text + "' order by ms_id desc", "select");
  179. if (dt.Rows.Count > 0)
  180. {
  181. input.Text = dt.Rows[0]["ms_sncode"].ToString();
  182. if (ms_makecode.Text != "" && dt.Rows[0]["ms_makecode"].ToString() != ms_makecode.Text)
  183. {
  184. OperatResult.AppendText("SN:" + input.Text + "所属工单" + dt.Rows[0]["ms_makecode"].ToString() + "与当前工单" + ms_makecode.Text + "不一致\n", Color.Red, input);
  185. return;
  186. }
  187. if (dt.Rows[0]["ms_status"].ToString() == "3")
  188. {
  189. OperatResult.AppendText("SN:" + input.Text + "为不良品,不允许采集\n", Color.Red, input);
  190. return;
  191. }
  192. if (dt.Rows[0]["ms_outboxcode"].ToString() != "")
  193. {
  194. OperatResult.AppendText("SN:" + input.Text + "已装箱" + dt.Rows[0]["ms_outboxcode"].ToString() + ",不允许采集\n", Color.Red, input);
  195. return;
  196. }
  197. BaseUtil.SetFormValue(this.Controls, dt);
  198. if (sb.Contains(dt.Rows[0]["ms_sncode"].ToString()))
  199. {
  200. OperatResult.AppendText("SN:" + input.Text + "已采集\n", Color.Red, input);
  201. return;
  202. }
  203. WeighRecord.Items.Add(dt.Rows[0]["ms_sncode"].ToString());
  204. sb.Add(dt.Rows[0]["ms_sncode"].ToString());
  205. OperatResult.AppendText("SN:" + input.Text + "采集\n", Color.Green, input);
  206. }
  207. else
  208. {
  209. OperatResult.AppendText("SN:" + input.Text + "不存在\n", Color.Red, input);
  210. return;
  211. }
  212. }
  213. else if (bigboxBtn.Checked)
  214. {
  215. dt = (DataTable)dh.ExecuteSql("select pa_makecode ms_makecode,pa_prodcode ms_prodcode,pa_outboxcode,pa_mothercode,ma_craftcode,nvl(pa_iostatus,0)pa_iostatus,ma_craftcode cr_code from package left join make on pa_makecode = ma_code where pa_outboxcode = '" + input.Text + "' and pa_type = '1'", "select");
  216. if (dt.Rows.Count > 0)
  217. {
  218. if (ms_makecode.Text != "" && dt.Rows[0]["ms_makecode"].ToString() != ms_makecode.Text)
  219. {
  220. OperatResult.AppendText("SN:" + input.Text + "所属工单" + dt.Rows[0]["ms_makecode"].ToString() + "与当前工单" + ms_makecode.Text + "不一致\n", Color.Red, input);
  221. return;
  222. }
  223. if (dt.Rows[0]["pa_iostatus"].ToString() != "0")
  224. {
  225. OperatResult.AppendText("卡通箱:" + input.Text + "处于状态入库状态,不允许采集\n", Color.Red, input);
  226. return;
  227. }
  228. if (dt.Rows[0]["pa_mothercode"].ToString() != "")
  229. {
  230. OperatResult.AppendText("卡通箱:" + input.Text + "已装栈板" + dt.Rows[0]["pa_mothercode"].ToString() + ",不允许采集\n", Color.Red, input);
  231. return;
  232. }
  233. BaseUtil.SetFormValue(this.Controls, dt);
  234. if (sb.Contains(dt.Rows[0]["pa_outboxcode"].ToString()))
  235. {
  236. OperatResult.AppendText("卡通箱:" + input.Text + "已采集\n", Color.Red, input);
  237. return;
  238. }
  239. WeighRecord.Items.Add(dt.Rows[0]["pa_outboxcode"].ToString());
  240. sb.Add(dt.Rows[0]["pa_outboxcode"].ToString());
  241. OperatResult.AppendText("卡通箱:" + input.Text + "采集\n", Color.Green, input);
  242. }
  243. else
  244. {
  245. OperatResult.AppendText("卡通箱:" + input.Text + "不存在\n", Color.Red, input);
  246. return;
  247. }
  248. }
  249. }
  250. }
  251. private void 数据清空_Click(object sender, EventArgs e)
  252. {
  253. BaseUtil.CleanControls(this.Controls);
  254. WeighRecord.Items.Clear();
  255. sb.Clear();
  256. }
  257. private void Special_Reset_SizeChanged(object sender, EventArgs e)
  258. {
  259. asc.controlAutoSize(this);
  260. }
  261. private void DeleteALLSN_Click(object sender, EventArgs e)
  262. {
  263. if (PassWord.Text == dh.getFieldDataByCondition("configs", "data", "code='Password' and caller='MESSetting'").ToString())
  264. {
  265. DataTable dt = (DataTable)dh.ExecuteSql("select ms_sncode,ms_makecode from makeserial where ms_makecode ='" + ma_code.Text + "'", "select");
  266. TotalSN.Text = "总计" + dt.Rows.Count;
  267. for (int i = 0; i < dt.Rows.Count; i++)
  268. {
  269. ReSN(dt.Rows[i]["ms_sncode"].ToString());
  270. RemainSN.Text = "已解绑" + (i + 1);
  271. }
  272. dh.ExecuteSql("update make set ma_inqty=0,ma_endqty=0 where ma_code='" + ma_code.Text + "'", "update");
  273. dh.ExecuteSql("update makecraftdetail set MCD_INQTY=0, MCD_OUTQTY=0, MCD_OKQTY=0 where mcd_macode='"+ma_code.Text+"'","update");
  274. }
  275. else
  276. {
  277. MessageBox.Show("密码不正确");
  278. }
  279. }
  280. }
  281. }