Make_SingleBoard.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. using DevExpress.Entity.ProjectModel;
  2. using DevExpress.Utils;
  3. using LabelManager2;
  4. using NPOI.SS.Formula.Functions;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Data;
  8. using System.Drawing;
  9. using System.Text;
  10. using System.Windows.Forms;
  11. using UAS_MES_NEW.DataOperate;
  12. using UAS_MES_NEW.Entity;
  13. using UAS_MES_NEW.PublicMethod;
  14. namespace UAS_MES_NEW.Make
  15. {
  16. public partial class Make_SingleBoard : Form
  17. {
  18. DataHelper dh;
  19. LogStringBuilder sql = new LogStringBuilder();
  20. DataTable Dbfind;
  21. /// <summary>
  22. /// 已选的不良
  23. /// </summary>
  24. List<string> ChoosedList = new List<string>();
  25. /// <summary>
  26. /// 待选的不良
  27. /// </summary>
  28. List<string> WaitList = new List<string>();
  29. public Make_SingleBoard()
  30. {
  31. InitializeComponent();
  32. }
  33. private void Special_BoxSplit_Load(object sender, EventArgs e)
  34. {
  35. ma_code.TableName = "make left join product on ma_prodcode=pr_code";
  36. ma_code.SelectField = "ma_code # 工单号,ma_pocode # 内部订单号,ma_prodcode # 产品编号,ma_qty # 工单数量,pr_spec # 产品规格,ma_softversion # 软件版本,ma_salecode # 销售单号,pr_sendchecktype # 产品送检方式";
  37. ma_code.FormName = Name;
  38. ma_code.SetValueField = new string[] { "ma_code", "ma_pocode", "ma_prodcode", "ma_qty", "substr(pr_spec,0,50)pr_spec", "ma_softversion", "ma_salecode", "nvl(pr_sendchecktype,'LineCode')pr_sendchecktype" };
  39. ma_code.Condition = "ma_statuscode='STARTED'";
  40. ma_code.DbChange += Ma_code_DbChange;
  41. dh = SystemInf.dh;
  42. LockMakeCode.GetMakeCodeCtl(ma_code);
  43. ma_code.SetLockCheckBox(LockMakeCode);
  44. }
  45. private void Ma_code_DbChange(object sender, EventArgs e)
  46. {
  47. Dbfind = ma_code.ReturnData;
  48. BaseUtil.SetFormValue(this.Controls, Dbfind);
  49. LoadBadGroupData();
  50. }
  51. private void LoadBadGroupData()
  52. {
  53. //如果ms_makecode的值修改过再去查询
  54. sql.Clear();
  55. sql.Append("select bg_code||':'||bg_name bg_name,bg_code from badgroup left join (select pb_badgroup,pr_kind ");
  56. sql.Append("from product left join productkind on pk_name=pr_kind ");
  57. sql.Append("left join productbadgroup on pk_code=PB_KINDCODE where pr_code='" + ma_prodcode.Text + "')");
  58. sql.Append("on pb_badgroup=bg_code where bg_statuscode='AUDITED' order by case when bg_code='" + User.DefaultBadGroup + "' then 0 else 1 end");
  59. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  60. bc_groupcode.DisplayMember = "bg_name";
  61. bc_groupcode.ValueMember = "bg_code";
  62. bc_groupcode.DataSource = dt;
  63. }
  64. private void LoadBadCodeListView()
  65. {
  66. object bg_code = bc_groupcode.SelectedValue;
  67. sql.Clear();
  68. sql.Append("select bg_code||':'||bg_name bg_code,bc_code,bc_name,'' bc_remark from badgroupdetail ");
  69. sql.Append("left join badgroup on bg_id=bgd_bgid left join badcode on bgd_badcode=bc_code where ");
  70. sql.Append("bg_code='" + (bg_code != null ? bg_code.ToString() : "") + "' and bg_code is not null order by bgd_detno");
  71. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  72. BadInfSource.DataSource = dt;
  73. //往listview中添加数据
  74. WaitRejectList.Items.Clear();
  75. WaitRejectList.BeginUpdate();
  76. for (int i = 0; i < dt.Rows.Count; i++)
  77. {
  78. if (!ChoosedList.Contains(dt.Rows[i]["bc_code"].ToString()))
  79. {
  80. ListViewItem lvi = new ListViewItem();
  81. //第一列是勾选列,设置列头文本为空
  82. lvi.Text = "";
  83. WaitList.Add(dt.Rows[i]["bc_code"].ToString());
  84. for (int j = 0; j < dt.Columns.Count; j++)
  85. lvi.SubItems.Add(dt.Rows[i][j].ToString());
  86. WaitRejectList.Items.Add(lvi);
  87. }
  88. }
  89. WaitRejectList.EndUpdate();
  90. }
  91. private void SN_KeyDown(object sender, KeyEventArgs e)
  92. {
  93. if (e.KeyCode == Keys.Enter)
  94. {
  95. DataTable dt = (DataTable)dh.ExecuteSql("select ma_prodcode,sp_fsoncode,pr_oldcode from make left join stepbom on ma_bomversion=sb_bomversion " +
  96. "left join stepproduct on sp_sbid=sb_id left join product on pr_code=ma_prodcode where ma_code='" + ma_code.Text + "'", "select");
  97. bool checksn = false;
  98. for (int i = 0; i < dt.Rows.Count; i++)
  99. {
  100. string sp_fsoncode = dt.Rows[i]["sp_fsoncode"].ToString();
  101. string pr_oldcode = dt.Rows[i]["pr_oldcode"].ToString();
  102. string ma_prodcode = dt.Rows[i]["ma_prodcode"].ToString();
  103. if (SN.Text.Contains(dt.Rows[i]["ma_prodcode"].ToString()) || (pr_oldcode != "" && SN.Text.Contains(dt.Rows[i]["pr_oldcode"].ToString())))
  104. {
  105. checksn = true;
  106. }
  107. }
  108. if (!User.CurrentStepCode.Contains("单板上料"))
  109. {
  110. OperateResult.AppendText(">>单板上料界面,请登录【单板上料】资源\n", Color.Red, SN);
  111. return;
  112. }
  113. if (!checksn)
  114. {
  115. OperateResult.AppendText(">>" + SN.Text + "不在用料表中,不允许扫描\n", Color.Red, SN);
  116. return;
  117. }
  118. if (User.CurrentStepCode == "单板上料")
  119. {
  120. if (dh.CheckExist("singleboard", "sb_sncode='" + SN.Text + "'"))
  121. {
  122. OperateResult.AppendText(">>" + SN.Text + "已执行单板上料\n", Color.Red, SN);
  123. return;
  124. }
  125. else
  126. {
  127. dh.ExecuteSql("insert into singleboard(SB_ID, SB_MAKECODE, SB_SNCODE, SB_INDATE, SB_NEXTSTEPCODE, SB_BADTIMS, SB_STATUS,sb_stepcode)" +
  128. "values(singleboard_seq.nextval,'" + ma_code.Text + "','" + SN.Text + "',sysdate,'单板测试',0,'1','单板上料')", "insert");
  129. }
  130. }
  131. //if (User.CurrentStepCode == "刷三防漆")
  132. //{
  133. // dt = (DataTable)dh.ExecuteSql("select SB_NEXTSTEPCODE,sb_status from singleboard where sb_sncode='" + SN.Text + "'", "select");
  134. // if (dt.Rows.Count > 0)
  135. // {
  136. // string SB_NEXTSTEPCODE = dt.Rows[0]["SB_NEXTSTEPCODE"].ToString();
  137. // string sb_status = dt.Rows[0]["sb_status"].ToString();
  138. // if (sb_status == "3")
  139. // {
  140. // OperateResult.AppendText(">>" + SN.Text + "测试不良不允许采集,请先进行维修\n", Color.Red);
  141. // return;
  142. // }
  143. // if (SB_NEXTSTEPCODE == User.CurrentStepCode)
  144. // {
  145. // dh.ExecuteSql("update singleboard set sb_status=2,sb_nextstepcode='' where sb_sncode='" + SN.Text + "'", "update"); ;
  146. // }
  147. // }
  148. //}
  149. if (OK.Checked)
  150. {
  151. LogicHandler.DoCommandLog(Tag.ToString(), User.UserName, ma_code.Text, User.UserLineCode, User.UserSourceCode, User.CurrentStepCode, User.CurrentStepCode + "结果为良品", SN.Text, "");
  152. }
  153. else
  154. {
  155. int CheckedNum = 0;
  156. //是否已经添加到不良
  157. bool AddToReject = false;
  158. for (int i = WaitRejectList.Items.Count - 1; i >= 0; i--)
  159. {
  160. if (WaitRejectList.Items[i].Checked)
  161. {
  162. AddToReject = false;
  163. for (int j = 0; j < ChoosedRejectList.Items.Count; j++)
  164. {
  165. if ((ChoosedRejectList.Items[j].SubItems[2].Text == WaitRejectList.Items[i].SubItems[2].Text))
  166. {
  167. AddToReject = true;
  168. OperateResult.AppendText(">>已存在" + ChoosedRejectList.Items[j].SubItems[2].Text + "不良\n", Color.Red);
  169. break;
  170. }
  171. }
  172. //未添加则进行添加
  173. if (!AddToReject)
  174. {
  175. WaitRejectList.Items[i].Checked = false;
  176. ChoosedRejectList.Items.Add((ListViewItem)WaitRejectList.Items[i].Clone());
  177. WaitRejectList.Items[i].Remove();
  178. CheckedNum++;
  179. }
  180. }
  181. }
  182. if (CheckedNum == 0)
  183. {
  184. OperateResult.AppendText(">>请勾选不良代码\n", Color.Red);
  185. return;
  186. }
  187. LogicHandler.DoCommandLog(Tag.ToString(), User.UserName, ma_code.Text, User.UserLineCode, User.UserSourceCode, User.CurrentStepCode, User.CurrentStepCode + "结果为良品", SN.Text, "");
  188. }
  189. OperateResult.AppendText("序列号" + SN.Text + User.CurrentStepCode + "采集成功\n", System.Drawing.Color.Green, SN);
  190. }
  191. }
  192. private void ChooseedReject_Click(object sender, EventArgs e)
  193. {
  194. if (SN.Text == "")
  195. {
  196. OperateResult.AppendText(">>序列号不能为空\n", Color.Red);
  197. SN.Focus();
  198. return;
  199. }
  200. int CheckedNum = 0;
  201. //是否已经添加到不良
  202. bool AddToReject = false;
  203. for (int i = WaitRejectList.Items.Count - 1; i >= 0; i--)
  204. {
  205. if (WaitRejectList.Items[i].Checked)
  206. {
  207. AddToReject = false;
  208. for (int j = 0; j < ChoosedRejectList.Items.Count; j++)
  209. {
  210. if ((ChoosedRejectList.Items[j].SubItems[2].Text == WaitRejectList.Items[i].SubItems[2].Text))
  211. {
  212. AddToReject = true;
  213. OperateResult.AppendText(">>已存在" + ChoosedRejectList.Items[j].SubItems[2].Text + "不良\n", Color.Red);
  214. break;
  215. }
  216. }
  217. //未添加则进行添加
  218. if (!AddToReject)
  219. {
  220. WaitRejectList.Items[i].Checked = false;
  221. ChoosedRejectList.Items.Add((ListViewItem)WaitRejectList.Items[i].Clone());
  222. WaitRejectList.Items[i].Remove();
  223. CheckedNum++;
  224. }
  225. }
  226. }
  227. if (CheckedNum == 0)
  228. {
  229. OperateResult.AppendText(">>请勾选不良代码\n", Color.Red);
  230. }
  231. }
  232. private void WaitReject_Click(object sender, EventArgs e)
  233. {
  234. int CheckedNum = 0;
  235. //已存在在ListView中的Item是不能添加到其他ListView中的,需要调用其克隆的方法
  236. for (int i = ChoosedRejectList.Items.Count - 1; i >= 0; i--)
  237. {
  238. if (ChoosedRejectList.Items[i].Checked)
  239. {
  240. ChoosedRejectList.Items[i].Checked = false;
  241. WaitRejectList.Items.Add((ListViewItem)ChoosedRejectList.Items[i].Clone());
  242. ChoosedRejectList.Items[i].Remove();
  243. CheckedNum++;
  244. }
  245. }
  246. if (CheckedNum == 0)
  247. {
  248. for (int i = ChoosedRejectList.Items.Count - 1; i >= 0; i--)
  249. {
  250. WaitRejectList.Items.Add((ListViewItem)ChoosedRejectList.Items[i].Clone());
  251. ChoosedRejectList.Items[i].Remove();
  252. }
  253. }
  254. }
  255. private void bc_groupcode_SelectedIndexChanged(object sender, EventArgs e)
  256. {
  257. LoadBadCodeListView();
  258. }
  259. private void ma_prodcode_TextChanged(object sender, EventArgs e)
  260. {
  261. LoadBadGroupData();
  262. }
  263. private void SaveRepairInf_Click(object sender, EventArgs e)
  264. {
  265. if (User.CurrentStepCode == "单板测试")
  266. {
  267. if (dh.CheckExist("singleboard", "sb_sncode='" + SN.Text + "'"))
  268. {
  269. if (OK.Checked)
  270. {
  271. OperateResult.AppendText(">>" + SN.Text + "已执行单板测试\n", Color.Red, SN);
  272. return;
  273. }
  274. }
  275. else
  276. {
  277. dh.ExecuteSql("insert into singleboard(SB_ID, SB_MAKECODE, SB_SNCODE, SB_INDATE, SB_NEXTSTEPCODE, SB_BADTIMS, SB_STATUS)" +
  278. "values(singleboard_seq.nextval,'" + ma_code.Text + "','" + SN.Text + "',sysdate,'刷三防漆',0,'1')", "insert");
  279. }
  280. }
  281. DataTable dt = (DataTable)dh.ExecuteSql("select SB_NEXTSTEPCODE,sb_status from singleboard where sb_sncode='" + SN.Text + "'", "select");
  282. if (dt.Rows.Count > 0)
  283. {
  284. string SB_NEXTSTEPCODE = dt.Rows[0]["SB_NEXTSTEPCODE"].ToString();
  285. string sb_status = dt.Rows[0]["sb_status"].ToString();
  286. if (sb_status == "3")
  287. {
  288. OperateResult.AppendText(">>" + SN.Text + "已经采集不良,不允许重复采集\n", Color.Red, SN);
  289. return;
  290. }
  291. }
  292. if (NG.Checked)
  293. {
  294. int RejectCount = ChoosedRejectList.Items.Count;
  295. string[] bccode = new string[RejectCount];
  296. string[] bcremark = new string[RejectCount];
  297. string[] bgcode = new string[RejectCount];
  298. string[] bgname = new string[RejectCount];
  299. string[] bcname = new string[RejectCount];
  300. if (ChoosedRejectList.Items.Count == 0)
  301. {
  302. OperateResult.AppendText(">>不良品必须选择不良原因和不良代码!\n", Color.Red);
  303. return;
  304. }
  305. else
  306. {
  307. for (int i = 0; i < RejectCount; i++)
  308. {
  309. //获取不良代码组
  310. bgcode[i] = ChoosedRejectList.Items[i].SubItems[1].Text.Split(':')[0];
  311. //获取不良代码组名称
  312. bgname[i] = ChoosedRejectList.Items[i].SubItems[1].Text.Split(':')[1];
  313. //获取所有的不良代码
  314. bccode[i] = ChoosedRejectList.Items[i].SubItems[2].Text;
  315. //获取不良名称
  316. bcname[i] = ChoosedRejectList.Items[i].SubItems[3].Text;
  317. //获取所有的不良备注
  318. bcremark[i] = bc_remark.Text;
  319. }
  320. }
  321. sql.Clear();
  322. sql.Append("insert into makebad(mb_id,mb_makecode,mb_mscode,mb_sncode,mb_inman,mb_indate,mb_stepcode");
  323. sql.Append(",mb_sourcecode,mb_badcode,mb_bgcode,mb_badtable,mb_status,mb_badremark,mb_bgname,mb_badname,mb_type)");
  324. sql.Append("select makebad_seq.nextval,ma_code,sb_sncode,sb_sncode,'" + User.UserCode + "',sysdate,'" + User.CurrentStepCode + "','" + User.UserSourceCode + "',:bc_code,:bg_code,'',");
  325. sql.Append("'0',:bc_remark,:bg_name,:bc_name,'Client' from make left join singleboard on sb_makecode=ma_code ");
  326. sql.Append(" where sb_sncode='" + SN.Text + "' and sb_makecode='" + ma_code.Text + "'");
  327. if (bgcode.Length > 0)
  328. {
  329. dh.BatchInsert(sql.GetString(), new string[] { "bc_code", "bg_code", "bc_remark", "bg_name", "bc_name" }, bccode, bgcode, bcremark, bgname, bcname);
  330. }
  331. dh.ExecuteSql("update singleboard set sb_status=3,SB_BADTIMS=nvl(SB_BADTIMS,0)+1,sb_nextstepcode='',sb_stepcode='" + User.CurrentStepCode + "' where sb_sncode='" + SN.Text + "'", "update");
  332. LogicHandler.DoCommandLog(Tag.ToString(), User.UserName, ma_code.Text, User.UserLineCode, User.UserSourceCode, User.CurrentStepCode, User.CurrentStepCode + "结果不良品", SN.Text, "");
  333. OperateResult.AppendText("序列号" + SN.Text + "采集不良成功\n", System.Drawing.Color.Green, SN);
  334. }
  335. }
  336. }
  337. }