Special_ResetCheck.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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_NEW.DataOperate;
  10. using UAS_MES_NEW.Entity;
  11. using UAS_MES_NEW.PublicMethod;
  12. namespace UAS_MES_NEW.Special
  13. {
  14. public partial class Special_ResetCheck : Form
  15. {
  16. DataHelper dh;
  17. LogStringBuilder sql = new LogStringBuilder();
  18. AutoSizeFormClass asc = new AutoSizeFormClass();
  19. DataTable Dbfind;
  20. DataTable dt;
  21. ExcelHandler eh;
  22. List<String> sb = new List<string>();
  23. public Special_ResetCheck()
  24. {
  25. InitializeComponent();
  26. }
  27. private void Special_BoxSplit_Load(object sender, EventArgs e)
  28. {
  29. eh = new ExcelHandler();
  30. dh = SystemInf.dh;
  31. asc.controllInitializeSize(this);
  32. cd_stepcode.FormName = Name;
  33. cd_stepcode.TableName = "craftdetail left join step on st_code=cd_stepcode left join craft on cd_crid=cr_id";
  34. cd_stepcode.SetValueField = new string[] { "cd_stepcode", "cd_stepno" };
  35. cd_stepcode.SelectField = "cd_stepname # 工序名称 ,cd_stepcode # 工序编号,cd_stepno # 执行顺序";
  36. cd_stepcode.Condition = "ST_STATUSCODE='AUDITED' and cr_code='" + cr_code.Text + "' and cr_prodcode='" + ms_prodcode.Text + "' and cd_ifoqc <> -1 order by cd_stepno";
  37. cd_stepcode.DBTitle = "回流工序";
  38. cd_stepcode.DbChange += Cd_stepcode_DbChange;
  39. }
  40. private void Cd_stepcode_DbChange(object sender, EventArgs e)
  41. {
  42. Dbfind = cd_stepcode.ReturnData;
  43. BaseUtil.SetFormValue(this.Controls, Dbfind);
  44. }
  45. private void ReSN(string sncode, string stepcode)
  46. {
  47. string stname = dh.getFieldDataByCondition("step", "st_name", "st_code = '" + stepcode + "'").ToString();
  48. dh.ExecuteSql("update makeserial set MS_STEPCODE = '',MS_CHECKNO = '', ms_status=1,ms_outboxcode='',ms_nextstepcode= '"+ stepcode + "' where ms_sncode='" + sncode + "' and ms_nextmacode is null", "update");
  49. //if (checkBox1.Checked)
  50. //{
  51. // dh.ExecuteSql("update makeserial set ms_bs = '',ms_key='',ms_keyid='',MS_HARDWREID='',MS_KEYSTATEID='',MS_BIOS='',ms_ec='',ms_uuid='',MS_KEYPARTNUMBER='',ms_bt='',ms_mac='',ms_imei='' where ms_sncode = '" + sncode + "' and ms_makecode = '" + ms_makecode.Text + "'", "update");
  52. //}
  53. dh.ExecuteSql("delete makebad where mb_sncode = '" + sncode + "' and mb_status = 0", "delete");
  54. dh.ExecuteSql("delete from LABELPRINTLOG where lpl_value = '" + sncode + "'", "delete");
  55. //sql.Clear();
  56. //sql.Append("update craftmaterial set cm_status=-1,cm_lastdeco=-1,cm_dropman='" + User.UserCode + "',");
  57. //sql.Append("cm_dropdate =sysdate,CM_REMARK = '重置站点拆解',cm_dropstep='" + User.CurrentStepCode + "',");
  58. //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 + " )");
  59. //dh.ExecuteSql(sql.GetString(), "update");
  60. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode.Text, User.UserLineCode, User.UserSourceCode, "站点重置", "站点重置至" + stname, sncode, "");
  61. }
  62. private void Split_Click(object sender, EventArgs e)
  63. {
  64. if (sb.Count == 0|| cd_stepcode.Text == "")
  65. {
  66. OperatResult.AppendText(">>采集数与回流工位不能为空\n", Color.Red);
  67. return;
  68. }
  69. string Delete = MessageBox.Show(this.ParentForm, "是否确认重置站点?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  70. if (Delete == "Yes")
  71. {
  72. if (serBtn.Checked)
  73. {
  74. for (int i = 0; i < sb.Count; i++)
  75. {
  76. ReSN(sb[i].ToString(), cd_stepcode.Text);
  77. OperatResult.AppendText("SN:" + sb[i].ToString()+ "回流至"+ cd_stepcode.Text + "完成\n", Color.Green);
  78. }
  79. WeighRecord.Items.Clear();
  80. sb.Clear();
  81. }
  82. else if(bigboxBtn.Checked)
  83. {
  84. string stname = dh.getFieldDataByCondition("step", "st_name", "st_code = '" + cd_stepcode.Text + "'").ToString();
  85. for (int i = 0; i < sb.Count; i++)
  86. {
  87. DataTable dt2 = (DataTable)dh.ExecuteSql("select ms_sncode from makeserial where ms_outboxcode = '" + sb[i].ToString() + "'", "select");
  88. for (int k = 0; k < dt2.Rows.Count; k++)
  89. {
  90. ReSN(dt2.Rows[k]["ms_sncode"].ToString(), cd_stepcode.Text);
  91. }
  92. dh.ExecuteSql("insert into PACKAGEBACKUP select * from package where pa_outboxcode='" + sb[i].ToString() + "'", "insert");
  93. dh.ExecuteSql("insert into PACKAGEBACKUPDETAIL select * from packagedetail where pd_outboxcode='" + sb[i].ToString() + "'", "insert");
  94. dh.ExecuteSql("delete from package where pa_outboxcode = '" + sb[i].ToString() + "'", "delete");
  95. dh.ExecuteSql("delete from LABELPRINTLOG where lpl_value = '" + sb[i].ToString() + "'", "delete");
  96. //删除箱的明细
  97. dh.ExecuteSql("delete from packagedetail where pd_outboxcode='" + sb[i].ToString() + "'", "delete");
  98. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode.Text, User.UserLineCode, User.UserSourceCode, "站点重置", "站点重置至" + stname, sb[i].ToString(), "");
  99. OperatResult.AppendText("卡通箱:" + sb[i].ToString() + "回流至" + cd_stepcode.Text + "完成\n", Color.Green);
  100. }
  101. WeighRecord.Items.Clear();
  102. sb.Clear();
  103. }
  104. else if (oqcBtn.Checked)
  105. {
  106. string stname = dh.getFieldDataByCondition("step", "st_name", "st_code = '" + cd_stepcode.Text + "'").ToString();
  107. for (int i = 0; i < sb.Count; i++)
  108. {
  109. DataTable dt2 = (DataTable)dh.ExecuteSql("select ms_sncode from makeserial where ms_checkno = '" + sb[i].ToString() + "' and ms_status = 1", "select");
  110. for (int k = 0; k < dt2.Rows.Count; k++)
  111. {
  112. ReSN(dt2.Rows[k]["ms_sncode"].ToString(), cd_stepcode.Text);
  113. }
  114. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode.Text, User.UserLineCode, User.UserSourceCode, "站点重置", "站点重置至" + stname, sb[i].ToString(), "");
  115. OperatResult.AppendText("抽检批:" + sb[i].ToString() + "回流至" + cd_stepcode.Text + "完成\n", Color.Green);
  116. }
  117. WeighRecord.Items.Clear();
  118. sb.Clear();
  119. }
  120. sql.Clear();
  121. 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");
  122. 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");
  123. sql.Append(" ON (makecraftdetail.MCD_MACODE = A.MCD_MACODE and makecraftdetail.mcd_stepcode = A.mcd_stepcode) ");
  124. sql.Append(" WHEN MATCHED THEN UPDATE SET makecraftdetail.mcd_inqty = A.inqty,makecraftdetail.mcd_outqty = A.inqty,makecraftdetail.mcd_okqty = A.inqty ");
  125. dh.ExecuteSql(sql.GetString(), "update");
  126. }
  127. }
  128. private void bigboxBtn_Click(object sender, EventArgs e)
  129. {
  130. if (((RadioButton)sender).Checked == true)
  131. {
  132. if (WeighRecord.Items.Count > 0)
  133. {
  134. //string logout_confirm = MessageBox.Show(this.ParentForm, "是否更换采集项(已录入信息会清空)?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  135. //if (logout_confirm == "Yes")
  136. //{
  137. WeighRecord.Items.Clear();
  138. sb.Clear();
  139. ms_makecode.Text = "";
  140. ms_prodcode.Text = "";
  141. cr_code.Text = "";
  142. cd_stepcode.Text = "";
  143. //}
  144. //else
  145. //{
  146. // serBtn.Checked = bigboxBtn.Checked;
  147. // bigboxBtn.Checked = !serBtn.Checked;
  148. //}
  149. }
  150. if (((RadioButton)sender).Name == "serBtn")
  151. {
  152. input.Focus();
  153. OperatResult.AppendText("请输入序列号进行采集\n", Color.Black, input);
  154. }
  155. else if (((RadioButton)sender).Name == "bigboxBtn")
  156. {
  157. input.Focus();
  158. OperatResult.AppendText("请输入箱号进行采集\n", Color.Black, input);
  159. }
  160. else if (((RadioButton)sender).Name == "oqcBtn")
  161. {
  162. input.Focus();
  163. OperatResult.AppendText("请输入返工抽检批号进行采集\n", Color.Black, input);
  164. }
  165. }
  166. }
  167. private void cr_code_TextChanged(object sender, EventArgs e)
  168. {
  169. cd_stepcode.Condition = "ST_STATUSCODE='AUDITED' and cr_code='" + cr_code.Text + "' and cr_prodcode='" + ms_prodcode.Text + "' and cd_ifoqc <> -1 order by cd_stepno";
  170. }
  171. private void input_KeyDown(object sender, KeyEventArgs e)
  172. {
  173. if (e.KeyCode == Keys.Enter)
  174. {
  175. if (serBtn.Checked)
  176. {
  177. 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");
  178. if (dt.Rows.Count > 0)
  179. {
  180. if (ms_makecode.Text != "" && dt.Rows[0]["ms_makecode"].ToString() != ms_makecode.Text)
  181. {
  182. OperatResult.AppendText("SN:" + input.Text + "所属工单" + dt.Rows[0]["ms_makecode"].ToString() + "与当前工单" + ms_makecode.Text + "不一致\n", Color.Red, input);
  183. return;
  184. }
  185. if (dt.Rows[0]["ms_status"].ToString() == "3")
  186. {
  187. OperatResult.AppendText("SN:" + input.Text + "为不良品,不允许采集\n", Color.Red, input);
  188. return;
  189. }
  190. if (dt.Rows[0]["ms_outboxcode"].ToString() != "")
  191. {
  192. OperatResult.AppendText("SN:" + input.Text + "已装箱" + dt.Rows[0]["ms_outboxcode"].ToString() + ",不允许采集\n", Color.Red, input);
  193. return;
  194. }
  195. BaseUtil.SetFormValue(this.Controls, dt);
  196. if (sb.Contains(dt.Rows[0]["ms_sncode"].ToString()))
  197. {
  198. OperatResult.AppendText("SN:" + input.Text + "已采集\n", Color.Red, input);
  199. return;
  200. }
  201. WeighRecord.Items.Add(dt.Rows[0]["ms_sncode"].ToString());
  202. sb.Add(dt.Rows[0]["ms_sncode"].ToString());
  203. OperatResult.AppendText("SN:" + input.Text + "采集\n", Color.Green, input);
  204. cd_stepcode.Condition = "ST_STATUSCODE='AUDITED' and cr_code='" + cr_code.Text + "' and cr_prodcode='" + ms_prodcode.Text + "' and cd_ifoqc <> -1 order by cd_stepno";
  205. }
  206. else
  207. {
  208. OperatResult.AppendText("SN:" + input.Text + "不存在\n", Color.Red, input);
  209. return;
  210. }
  211. }
  212. else if (bigboxBtn.Checked)
  213. {
  214. 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");
  215. if (dt.Rows.Count > 0)
  216. {
  217. if (ms_makecode.Text != "" && dt.Rows[0]["ms_makecode"].ToString() != ms_makecode.Text)
  218. {
  219. OperatResult.AppendText("SN:" + input.Text + "所属工单" + dt.Rows[0]["ms_makecode"].ToString() + "与当前工单" + ms_makecode.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. cd_stepcode.Condition = "ST_STATUSCODE='AUDITED' and cr_code='" + cr_code.Text + "' and cr_prodcode='" + ms_prodcode.Text + "' and cd_ifoqc <> -1 order by cd_stepno";
  237. }
  238. else
  239. {
  240. OperatResult.AppendText("卡通箱:" + input.Text + "不存在\n", Color.Red, input);
  241. return;
  242. }
  243. }
  244. else if (oqcBtn.Checked)
  245. {
  246. dt = (DataTable)dh.ExecuteSql("select ob_makecode ms_makecode,ob_prodcode ms_prodcode,ob_checkno,ma_craftcode cr_code from oqcbatch left join make on ob_makecode = ma_code left join makeserial on ms_checkno = ob_checkno where (ob_checkno = '" + input.Text + "' or ms_sncode = '" + input.Text + "') and ob_status IN( 'NG','FNG') ", "select");
  247. if (dt.Rows.Count > 0)
  248. {
  249. if (ms_makecode.Text != "" && dt.Rows[0]["ms_makecode"].ToString() != ms_makecode.Text)
  250. {
  251. OperatResult.AppendText("抽检批:" + input.Text + "所属工单" + dt.Rows[0]["ms_makecode"].ToString() + "与当前工单" + ms_makecode.Text + "不一致\n", Color.Red, input);
  252. return;
  253. }
  254. BaseUtil.SetFormValue(this.Controls, dt);
  255. if (sb.Contains(dt.Rows[0]["ob_checkno"].ToString()))
  256. {
  257. OperatResult.AppendText("抽检批:" + input.Text + "已采集\n", Color.Red, input);
  258. return;
  259. }
  260. WeighRecord.Items.Add(dt.Rows[0]["ob_checkno"].ToString());
  261. sb.Add(dt.Rows[0]["ob_checkno"].ToString());
  262. OperatResult.AppendText("抽检批:" + input.Text + "采集\n", Color.Green, input);
  263. cd_stepcode.Condition = "ST_STATUSCODE='AUDITED' and cr_code='" + cr_code.Text + "' and cr_prodcode='" + ms_prodcode.Text + "' and cd_ifoqc <> -1 order by cd_stepno";
  264. }
  265. else
  266. {
  267. OperatResult.AppendText("录入信息:" + input.Text + "不存在抽检批或不是批退状态\n", Color.Red, input);
  268. return;
  269. }
  270. }
  271. }
  272. }
  273. private void 数据清空_Click(object sender, EventArgs e)
  274. {
  275. BaseUtil.CleanControls(this.Controls);
  276. WeighRecord.Items.Clear();
  277. sb.Clear();
  278. }
  279. private void excelim_Click(object sender, EventArgs e)
  280. {
  281. DialogResult result = openFileDialog1.ShowDialog();
  282. if (result == DialogResult.OK)
  283. {
  284. DataTable ddtt;
  285. ddtt = eh.ImportExcel(openFileDialog1.FileName, "test");
  286. if (ddtt.Rows.Count > 0)
  287. {
  288. for (int i = 0; i < ddtt.Rows.Count; i++)
  289. {
  290. input.Text = ddtt.Rows[i][0].ToString();
  291. input_KeyDown(sender, new KeyEventArgs(Keys.Enter));
  292. }
  293. }
  294. }
  295. }
  296. }
  297. }