Special_Delete.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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_Delete : 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_Delete()
  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_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. dh.ExecuteSql("delete makeserial where ms_sncode='" + sncode + "' and ms_makecode='" + ms_makecode + "'", "update");
  58. dh.ExecuteSql("delete makebad where mb_sncode = '" + sncode + "' and mb_status = 0", "delete");
  59. dh.ExecuteSql("delete labelprintlog where lpl_value = '" + sncode + "' and lpl_makecode='" + ms_makecode + "'", "delete");
  60. sql.Clear();
  61. sql.Append("delete craftmaterial where cm_sncode = '" + sncode + "' and cm_makecode='" + ms_makecode + "' ");
  62. dh.ExecuteSql(sql.GetString(), "update");
  63. List<string> sqls = new List<string>();
  64. sqls.Add("delete from sninfo where si_sn='" + ms_sncode + "'");
  65. //sqls.Add("update makeaddresslist set mal_sncode='',mal_status=0 where mal_sncode='" + sn_code.Text + "'");
  66. //删除打印日志
  67. sqls.Add("delete from labelprintlog where lpl_value='" + ms_sncode + "' and lpl_makecode='" + ms_makecode + "'");
  68. //删除老化记录
  69. sqls.Add("delete from AGINGRECORD where ar_sncode='" + ms_sncode + "' and ar_macode='" + ms_makecode + "'");
  70. //删除IMIE分配记录
  71. sqls.Add("update makeimeilist set mil_status=0 where mil_sncode='" + ms_sncode + "' and mil_makecode='" + ms_makecode + "'");
  72. //更新MAC使用记录
  73. sqls.Add("update makeserial set ms_nextmacode='' where ms_sncode='"+ms_sncode+"' or ms_code='"+ ms_code + "' and ms_nextmacode='" + ms_makecode + "'");
  74. sqls.Add("update makeaddresslist set mal_status=0 where mal_sncode='" + ms_sncode + "' and mal_makecode='" + ms_makecode + "'");
  75. //初始化导入数据状态
  76. sqls.Add("update makesnlist set msl_status=0 where msl_sncode='" + ms_sncode + "' and msl_makecode='" + ms_makecode + "' and msl_type='before'");
  77. ////初始化号段状态
  78. sqls.Add("update MAKESNRULEDETAIL set msd_status=0 where msd_sncode='" + ms_sncode + "' and msd_makecode='" + ms_makecode + "' and msd_type='before'");
  79. sqls.Add("delete from makesnrelation where SN='" + ms_sncode + "' and makecode='" + ms_makecode + "' ");
  80. dh.ExecuteSQLTran(sqls.ToArray());
  81. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode, User.UserLineCode, User.UserSourceCode, "工单解绑", "工单解绑成功", sncode, "");
  82. }
  83. return true;
  84. }
  85. private void Split_Click(object sender, EventArgs e)
  86. {
  87. if (sb.Count == 0)
  88. {
  89. OperatResult.AppendText(">>采集数工位不能为空\n", Color.Red);
  90. return;
  91. }
  92. string Delete = MessageBox.Show(this.ParentForm, "是否确认解绑工单?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  93. if (Delete == "Yes")
  94. {
  95. if (serBtn.Checked)
  96. {
  97. for (int i = 0; i < sb.Count; i++)
  98. {
  99. if (ReSN(sb[i].ToString()))
  100. OperatResult.AppendText("SN:" + sb[i].ToString() + "解绑完成\n", Color.Green);
  101. }
  102. WeighRecord.Clear();
  103. sb.Clear();
  104. }
  105. else if (bigboxBtn.Checked)
  106. {
  107. for (int i = 0; i < sb.Count; i++)
  108. {
  109. DataTable dt2 = (DataTable)dh.ExecuteSql("select ms_sncode from makeserial where ms_outboxcode = '" + sb[i].ToString() + "'", "select");
  110. for (int k = 0; k < dt2.Rows.Count; k++)
  111. {
  112. ReSN(dt2.Rows[k]["ms_sncode"].ToString());
  113. }
  114. dh.ExecuteSql("delete from labelprintlog where lpl_value='" + sb[i].ToString() + "'", "delete");
  115. dh.ExecuteSql("insert into PACKAGEBACKUP select * from package where pa_outboxcode='" + sb[i].ToString() + "'", "insert");
  116. dh.ExecuteSql("insert into PACKAGEBACKUPDETAIL select * from packagedetail where pd_outboxcode='" + sb[i].ToString() + "'", "insert");
  117. dh.ExecuteSql("delete from package where pa_outboxcode = '" + sb[i].ToString() + "'", "delete");
  118. //删除箱的明细
  119. dh.ExecuteSql("delete from packagedetail where pd_outboxcode='" + sb[i].ToString() + "'", "delete");
  120. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode.Text, User.UserLineCode, User.UserSourceCode, "解绑工单", "解绑工单成功", sb[i].ToString(), "");
  121. OperatResult.AppendText("卡通箱:" + sb[i].ToString() + "解绑完成\n", Color.Green);
  122. }
  123. WeighRecord.Clear();
  124. sb.Clear();
  125. }
  126. sql.Clear();
  127. 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");
  128. 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");
  129. sql.Append(" ON (makecraftdetail.MCD_MACODE = A.MCD_MACODE and makecraftdetail.mcd_stepcode = A.mcd_stepcode) ");
  130. sql.Append(" WHEN MATCHED THEN UPDATE SET makecraftdetail.mcd_inqty = A.inqty,makecraftdetail.mcd_outqty = A.inqty,makecraftdetail.mcd_okqty = A.inqty ");
  131. dh.ExecuteSql(sql.GetString(), "update");
  132. }
  133. }
  134. private void bigboxBtn_Click(object sender, EventArgs e)
  135. {
  136. if (((RadioButton)sender).Checked == true)
  137. {
  138. if (WeighRecord.Items.Count > 0)
  139. {
  140. string logout_confirm = MessageBox.Show(this.ParentForm, "是否更换采集项(已录入信息会清空)?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  141. if (logout_confirm == "Yes")
  142. {
  143. WeighRecord.Items.Clear();
  144. sb.Clear();
  145. ms_makecode.Text = "";
  146. ms_prodcode.Text = "";
  147. }
  148. else
  149. {
  150. serBtn.Checked = bigboxBtn.Checked;
  151. bigboxBtn.Checked = !serBtn.Checked;
  152. }
  153. }
  154. if (((RadioButton)sender).Name == "serBtn")
  155. {
  156. input.Focus();
  157. OperatResult.AppendText("请输入序列号进行采集\n", Color.Black, input);
  158. }
  159. else if (((RadioButton)sender).Name == "bigboxBtn")
  160. {
  161. input.Focus();
  162. OperatResult.AppendText("请输入箱号进行采集\n", Color.Black, input);
  163. }
  164. }
  165. }
  166. private void input_KeyDown(object sender, KeyEventArgs e)
  167. {
  168. if (e.KeyCode == Keys.Enter)
  169. {
  170. if (serBtn.Checked)
  171. {
  172. 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");
  173. if (dt.Rows.Count > 0)
  174. {
  175. input.Text = dt.Rows[0]["ms_sncode"].ToString();
  176. if (ms_makecode.Text != "" && dt.Rows[0]["ms_makecode"].ToString() != ms_makecode.Text)
  177. {
  178. OperatResult.AppendText("SN:" + input.Text + "所属工单" + dt.Rows[0]["ms_makecode"].ToString() + "与当前工单" + ms_makecode.Text + "不一致\n", Color.Red, input);
  179. return;
  180. }
  181. if (dt.Rows[0]["ms_status"].ToString() == "3")
  182. {
  183. OperatResult.AppendText("SN:" + input.Text + "为不良品,不允许采集\n", Color.Red, input);
  184. return;
  185. }
  186. if (dt.Rows[0]["ms_outboxcode"].ToString() != "")
  187. {
  188. OperatResult.AppendText("SN:" + input.Text + "已装箱" + dt.Rows[0]["ms_outboxcode"].ToString() + ",不允许采集\n", Color.Red, input);
  189. return;
  190. }
  191. BaseUtil.SetFormValue(this.Controls, dt);
  192. if (sb.Contains(dt.Rows[0]["ms_sncode"].ToString()))
  193. {
  194. OperatResult.AppendText("SN:" + input.Text + "已采集\n", Color.Red, input);
  195. return;
  196. }
  197. WeighRecord.Items.Add(dt.Rows[0]["ms_sncode"].ToString());
  198. sb.Add(dt.Rows[0]["ms_sncode"].ToString());
  199. OperatResult.AppendText("SN:" + input.Text + "采集\n", Color.Green, input);
  200. }
  201. else
  202. {
  203. OperatResult.AppendText("SN:" + input.Text + "不存在\n", Color.Red, input);
  204. return;
  205. }
  206. }
  207. else if (bigboxBtn.Checked)
  208. {
  209. 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");
  210. if (dt.Rows.Count > 0)
  211. {
  212. if (ms_makecode.Text != "" && dt.Rows[0]["ms_makecode"].ToString() != ms_makecode.Text)
  213. {
  214. OperatResult.AppendText("SN:" + input.Text + "所属工单" + dt.Rows[0]["ms_makecode"].ToString() + "与当前工单" + ms_makecode.Text + "不一致\n", Color.Red, input);
  215. return;
  216. }
  217. if (dt.Rows[0]["pa_iostatus"].ToString() != "0")
  218. {
  219. OperatResult.AppendText("卡通箱:" + input.Text + "处于状态入库状态,不允许采集\n", Color.Red, input);
  220. return;
  221. }
  222. if (dt.Rows[0]["pa_mothercode"].ToString() != "")
  223. {
  224. OperatResult.AppendText("卡通箱:" + input.Text + "已装栈板" + dt.Rows[0]["pa_mothercode"].ToString() + ",不允许采集\n", Color.Red, input);
  225. return;
  226. }
  227. BaseUtil.SetFormValue(this.Controls, dt);
  228. if (sb.Contains(dt.Rows[0]["pa_outboxcode"].ToString()))
  229. {
  230. OperatResult.AppendText("卡通箱:" + input.Text + "已采集\n", Color.Red, input);
  231. return;
  232. }
  233. WeighRecord.Items.Add(dt.Rows[0]["pa_outboxcode"].ToString());
  234. sb.Add(dt.Rows[0]["pa_outboxcode"].ToString());
  235. OperatResult.AppendText("卡通箱:" + input.Text + "采集\n", Color.Green, input);
  236. }
  237. else
  238. {
  239. OperatResult.AppendText("卡通箱:" + input.Text + "不存在\n", Color.Red, input);
  240. return;
  241. }
  242. }
  243. }
  244. }
  245. private void 数据清空_Click(object sender, EventArgs e)
  246. {
  247. BaseUtil.CleanControls(this.Controls);
  248. WeighRecord.Items.Clear();
  249. sb.Clear();
  250. }
  251. private void Special_Reset_SizeChanged(object sender, EventArgs e)
  252. {
  253. asc.controlAutoSize(this);
  254. }
  255. private void DeleteALLSN_Click(object sender, EventArgs e)
  256. {
  257. if (PassWord.Text == dh.getFieldDataByCondition("configs", "data", "code='Password' and caller='MESSetting'").ToString())
  258. {
  259. DataTable dt = (DataTable)dh.ExecuteSql("select ms_sncode,ms_makecode from makeserial where ms_makecode ='" + ma_code.Text + "'", "select");
  260. TotalSN.Text = "总计" + dt.Rows.Count;
  261. for (int i = 0; i < dt.Rows.Count; i++)
  262. {
  263. ReSN(dt.Rows[i]["ms_sncode"].ToString());
  264. RemainSN.Text = "已解绑" + (i + 1);
  265. }
  266. dh.ExecuteSql("update make set ma_inqty=0,ma_endqty=0 where ma_code='" + ma_code.Text + "'", "update");
  267. dh.ExecuteSql("update makecraftdetail set MCD_INQTY=0, MCD_OUTQTY=0, MCD_OKQTY=0 where mcd_macode='"+ma_code.Text+"'","update");
  268. }
  269. else
  270. {
  271. MessageBox.Show("密码不正确");
  272. }
  273. }
  274. }
  275. }