Special_Reset.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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_Reset : Form
  12. {
  13. DataHelper dh;
  14. LogStringBuilder sql = new LogStringBuilder();
  15. AutoSizeFormClass asc = new AutoSizeFormClass();
  16. DataTable Dbfind;
  17. DataTable dt;
  18. List<String> sb = new List<string>();
  19. public Special_Reset()
  20. {
  21. InitializeComponent();
  22. }
  23. private void Special_BoxSplit_Load(object sender, EventArgs e)
  24. {
  25. dh = SystemInf.dh;
  26. asc.controllInitializeSize(this);
  27. cd_stepcode.FormName = Name;
  28. cd_stepcode.TableName = "craftdetail left join step on st_code=cd_stepcode left join craft on cd_crid=cr_id";
  29. cd_stepcode.SetValueField = new string[] { "cd_stepcode", "cd_stepno" };
  30. cd_stepcode.SelectField = "cd_stepname # 工序名称 ,cd_stepcode # 工序编号,cd_stepno # 执行顺序";
  31. cd_stepcode.Condition = "ST_STATUSCODE='AUDITED' and cr_code='" + cr_code.Text + "' and cr_prodcode='" + ms_prodcode.Text + "' order by cd_stepno";
  32. cd_stepcode.DBTitle = "回流工序";
  33. cd_stepcode.DbChange += Cd_stepcode_DbChange;
  34. }
  35. private void Cd_stepcode_DbChange(object sender, EventArgs e)
  36. {
  37. Dbfind = cd_stepcode.ReturnData;
  38. BaseUtil.SetFormValue(this.Controls, Dbfind);
  39. }
  40. private void ReSN(string sncode, string stepcode)
  41. {
  42. string stname = dh.getFieldDataByCondition("step", "st_name", "st_code = '" + stepcode + "'").ToString();
  43. dh.ExecuteSql("update makeserial set ms_status=1,ms_outboxcode='',ms_printcount = 0, ms_nextstepcode= '" + stepcode + "' where ms_sncode='" + sncode + "'", "update");
  44. dh.ExecuteSql("delete makebad where mb_sncode = '" + sncode + "' and mb_status = 0", "delete");
  45. //dh.ExecuteSql("delete labelprintlog where lpl_value = '" + sncode + "' ", "delete");
  46. sql.Clear();
  47. sql.Append("update craftmaterial set cm_status=-1,cm_lastdeco=-1,cm_dropman='" + User.UserCode + "',");
  48. sql.Append("cm_dropdate =sysdate,CM_REMARK = '重置站点拆解',cm_dropstep='" + User.CurrentStepCode + "',");
  49. sql.Append("cm_dropsccode='" + User.UserSourceCode + "' where cm_sncode = '" + sncode + "' and cm_stepcode in (select cd_stepcode from craftdetail left join step on st_code=cd_stepcode left join craft on cd_crid=cr_id where ST_STATUSCODE='AUDITED' and cr_code='" + cr_code.Text + "' and cr_prodcode='" + ms_prodcode.Text + "' and cd_detno >=" + cd_stepno.Text + " )");
  50. dh.ExecuteSql(sql.GetString(), "update");
  51. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode.Text, User.UserLineCode, User.UserSourceCode, "站点重置", "站点重置至" + stname, sncode, "");
  52. }
  53. private void Split_Click(object sender, EventArgs e)
  54. {
  55. if (sb.Count == 0 || cd_stepcode.Text == "")
  56. {
  57. OperatResult.AppendText(">>采集数与回流工位不能为空\n", Color.Red);
  58. return;
  59. }
  60. string Delete = MessageBox.Show(this.ParentForm, "是否确认重置站点?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  61. if (Delete == "Yes")
  62. {
  63. if (serBtn.Checked)
  64. {
  65. for (int i = 0; i < sb.Count; i++)
  66. {
  67. ReSN(sb[i].ToString(), cd_stepcode.Text);
  68. OperatResult.AppendText("SN:" + sb[i].ToString() + "回流至" + cd_stepcode.Text + "完成\n", Color.Green);
  69. }
  70. WeighRecord.Clear();
  71. sb.Clear();
  72. }
  73. else if (bigboxBtn.Checked)
  74. {
  75. string stname = dh.getFieldDataByCondition("step", "st_name", "st_code = '" + cd_stepcode.Text + "'").ToString();
  76. for (int i = 0; i < sb.Count; i++)
  77. {
  78. DataTable dt2 = (DataTable)dh.ExecuteSql("select ms_sncode from makeserial where ms_outboxcode = '" + sb[i].ToString() + "'", "select");
  79. for (int k = 0; k < dt2.Rows.Count; k++)
  80. {
  81. ReSN(dt2.Rows[k]["ms_sncode"].ToString(), cd_stepcode.Text);
  82. }
  83. dh.ExecuteSql("insert into PACKAGEBACKUP select * from package where pa_outboxcode='" + sb[i].ToString() + "'", "insert");
  84. dh.ExecuteSql("insert into PACKAGEBACKUPDETAIL select * from packagedetail where pd_outboxcode='" + sb[i].ToString() + "'", "insert");
  85. dh.ExecuteSql("delete from package where pa_outboxcode = '" + sb[i].ToString() + "'", "delete");
  86. //删除箱的明细
  87. dh.ExecuteSql("delete from packagedetail where pd_outboxcode='" + sb[i].ToString() + "'", "delete");
  88. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode.Text, User.UserLineCode, User.UserSourceCode, "站点重置", "站点重置至" + stname, sb[i].ToString(), "");
  89. OperatResult.AppendText("卡通箱:" + sb[i].ToString() + "回流至" + cd_stepcode.Text + "完成\n", Color.Green);
  90. }
  91. WeighRecord.Clear();
  92. sb.Clear();
  93. }
  94. sql.Clear();
  95. 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");
  96. 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");
  97. sql.Append(" ON (makecraftdetail.MCD_MACODE = A.MCD_MACODE and makecraftdetail.mcd_stepcode = A.mcd_stepcode) ");
  98. sql.Append(" WHEN MATCHED THEN UPDATE SET makecraftdetail.mcd_inqty = A.inqty,makecraftdetail.mcd_outqty = A.inqty,makecraftdetail.mcd_okqty = A.inqty ");
  99. dh.ExecuteSql(sql.GetString(), "update");
  100. }
  101. }
  102. private void bigboxBtn_Click(object sender, EventArgs e)
  103. {
  104. if (((RadioButton)sender).Checked == true)
  105. {
  106. if (WeighRecord.Items.Count > 0)
  107. {
  108. string logout_confirm = MessageBox.Show(this.ParentForm, "是否更换采集项(已录入信息会清空)?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  109. if (logout_confirm == "Yes")
  110. {
  111. WeighRecord.Items.Clear();
  112. sb.Clear();
  113. ms_makecode.Text = "";
  114. ms_prodcode.Text = "";
  115. cr_code.Text = "";
  116. cd_stepcode.Text = "";
  117. }
  118. else
  119. {
  120. serBtn.Checked = bigboxBtn.Checked;
  121. bigboxBtn.Checked = !serBtn.Checked;
  122. }
  123. }
  124. if (((RadioButton)sender).Name == "serBtn")
  125. {
  126. input.Focus();
  127. OperatResult.AppendText("请输入序列号进行采集\n", Color.Black, input);
  128. }
  129. else if (((RadioButton)sender).Name == "bigboxBtn")
  130. {
  131. input.Focus();
  132. OperatResult.AppendText("请输入箱号进行采集\n", Color.Black, input);
  133. }
  134. }
  135. }
  136. private void cr_code_TextChanged(object sender, EventArgs e)
  137. {
  138. cd_stepcode.Condition = "ST_STATUSCODE='AUDITED' and cr_code='" + cr_code.Text + "' and cr_prodcode='" + ms_prodcode.Text + "' order by cd_stepno";
  139. }
  140. private void input_KeyDown(object sender, KeyEventArgs e)
  141. {
  142. if (e.KeyCode == Keys.Enter)
  143. {
  144. if (serBtn.Checked)
  145. {
  146. 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 + "' order by ms_id desc", "select");
  147. if (dt.Rows.Count > 0)
  148. {
  149. if (ms_makecode.Text != "" && dt.Rows[0]["ms_makecode"].ToString() != ms_makecode.Text)
  150. {
  151. OperatResult.AppendText("SN:" + input.Text + "所属工单" + dt.Rows[0]["ms_makecode"].ToString() + "与当前工单" + ms_makecode.Text + "不一致\n", Color.Red, input);
  152. return;
  153. }
  154. if (dt.Rows[0]["ms_status"].ToString() == "3")
  155. {
  156. OperatResult.AppendText("SN:" + input.Text + "为不良品,不允许采集\n", Color.Red, input);
  157. return;
  158. }
  159. if (dt.Rows[0]["ms_outboxcode"].ToString() != "")
  160. {
  161. OperatResult.AppendText("SN:" + input.Text + "已装箱" + dt.Rows[0]["ms_outboxcode"].ToString() + ",不允许采集\n", Color.Red, input);
  162. return;
  163. }
  164. BaseUtil.SetFormValue(this.Controls, dt);
  165. if (sb.Contains(dt.Rows[0]["ms_sncode"].ToString()))
  166. {
  167. OperatResult.AppendText("SN:" + input.Text + "已采集\n", Color.Red, input);
  168. return;
  169. }
  170. WeighRecord.Items.Add(dt.Rows[0]["ms_sncode"].ToString());
  171. sb.Add(dt.Rows[0]["ms_sncode"].ToString());
  172. OperatResult.AppendText("SN:" + input.Text + "采集\n", Color.Green, input);
  173. cd_stepcode.Condition = "ST_STATUSCODE='AUDITED' and cr_code='" + cr_code.Text + "' and cr_prodcode='" + ms_prodcode.Text + "' order by cd_stepno";
  174. }
  175. else
  176. {
  177. OperatResult.AppendText("SN:" + input.Text + "不存在\n", Color.Red, input);
  178. return;
  179. }
  180. }
  181. else if (bigboxBtn.Checked)
  182. {
  183. dt = (DataTable)dh.ExecuteSql("select pa_makecode ms_makecode,pa_prodcode ms_prodcode,pa_outboxcode,pa_mothercode,ma_craftcode cr_code from package left join make on pa_makecode = ma_code where pa_outboxcode = '" + input.Text + "' and pa_type = '1'", "select");
  184. if (dt.Rows.Count > 0)
  185. {
  186. if (ms_makecode.Text != "" && dt.Rows[0]["ms_makecode"].ToString() != ms_makecode.Text)
  187. {
  188. OperatResult.AppendText("SN:" + input.Text + "所属工单" + dt.Rows[0]["ms_makecode"].ToString() + "与当前工单" + ms_makecode.Text + "不一致\n", Color.Red, input);
  189. return;
  190. }
  191. if (dt.Rows[0]["pa_mothercode"].ToString() != "")
  192. {
  193. OperatResult.AppendText("卡通箱:" + input.Text + "已装栈板" + dt.Rows[0]["pa_mothercode"].ToString() + ",不允许采集\n", Color.Red, input);
  194. return;
  195. }
  196. BaseUtil.SetFormValue(this.Controls, dt);
  197. if (sb.Contains(dt.Rows[0]["pa_outboxcode"].ToString()))
  198. {
  199. OperatResult.AppendText("卡通箱:" + input.Text + "已采集\n", Color.Red, input);
  200. return;
  201. }
  202. WeighRecord.Items.Add(dt.Rows[0]["pa_outboxcode"].ToString());
  203. sb.Add(dt.Rows[0]["pa_outboxcode"].ToString());
  204. OperatResult.AppendText("卡通箱:" + input.Text + "采集\n", Color.Green, input);
  205. cd_stepcode.Condition = "ST_STATUSCODE='AUDITED' and cr_code='" + cr_code.Text + "' and cr_prodcode='" + ms_prodcode.Text + "' order by cd_stepno";
  206. }
  207. else
  208. {
  209. OperatResult.AppendText("卡通箱:" + input.Text + "不存在\n", Color.Red, input);
  210. return;
  211. }
  212. }
  213. }
  214. }
  215. private void 数据清空_Click(object sender, EventArgs e)
  216. {
  217. BaseUtil.CleanControls(this.Controls);
  218. WeighRecord.Items.Clear();
  219. sb.Clear();
  220. }
  221. private void Special_Reset_SizeChanged(object sender, EventArgs e)
  222. {
  223. asc.controlAutoSize(this);
  224. }
  225. }
  226. }