Make_SingleBoard2.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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_SingleBoard2 : 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_SingleBoard2()
  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 sp_fsoncode from make left join stepbom on ma_bomversion=sb_bomversion " +
  96. "left join stepproduct on sp_sbid=sb_id where ma_code='" + ma_code.Text + "'", "select");
  97. bool checksn = false;
  98. for (int i = 0; i < dt.Rows.Count; i++)
  99. {
  100. if (SN.Text.Contains(dt.Rows[i]["sp_fsoncode"].ToString()))
  101. {
  102. checksn = true;
  103. }
  104. }
  105. if (!User.CurrentStepCode.Contains("刷三防漆"))
  106. {
  107. OperateResult.AppendText(">>单板采集界面,请登录【刷三防漆】资源\n", Color.Red);
  108. return;
  109. }
  110. //if (!checksn)
  111. //{
  112. // OperateResult.AppendText(">>" + SN.Text + "不在用料表中,不允许扫描\n", Color.Red);
  113. // return;
  114. //}
  115. //if (User.CurrentStepCode == "单板测试")
  116. //{
  117. // if (dh.CheckExist("singleboard", "sb_sncode='" + SN.Text + "'"))
  118. // {
  119. // OperateResult.AppendText(">>" + SN.Text + "已执行单板测试\n", Color.Red);
  120. // return;
  121. // }
  122. // else
  123. // {
  124. // dh.ExecuteSql("insert into singleboard(SB_ID, SB_MAKECODE, SB_SNCODE, SB_INDATE, SB_NEXTSTEPCODE, SB_BADTIMS, SB_STATUS,sb_stepcode)" +
  125. // "values(singleboard_seq.nextval,'" + ma_code.Text + "','" + SN.Text + "',sysdate,'刷三防漆',0,'1','单板测试')", "insert");
  126. // }
  127. //}
  128. if (User.CurrentStepCode == "刷三防漆")
  129. {
  130. dt = (DataTable)dh.ExecuteSql("select SB_NEXTSTEPCODE,sb_status from singleboard where sb_sncode='" + SN.Text + "'", "select");
  131. if (dt.Rows.Count > 0)
  132. {
  133. string SB_NEXTSTEPCODE = dt.Rows[0]["SB_NEXTSTEPCODE"].ToString();
  134. string sb_status = dt.Rows[0]["sb_status"].ToString();
  135. if (sb_status == "3")
  136. {
  137. OperateResult.AppendText(">>" + SN.Text + "测试不良不允许采集,请先进行维修\n", Color.Red);
  138. return;
  139. }
  140. if (sb_status == "2")
  141. {
  142. OperateResult.AppendText(">>" + SN.Text + "已完工\n", Color.Red);
  143. return;
  144. }
  145. if (SB_NEXTSTEPCODE == User.CurrentStepCode)
  146. {
  147. dh.ExecuteSql("update singleboard set sb_nextstepcode='',sb_status=2 where sb_sncode='" + SN.Text + "'", "update"); ;
  148. }
  149. else
  150. {
  151. OperateResult.AppendText(">>" + SN.Text + "当前所属工序" + SB_NEXTSTEPCODE + ",当前资源不允许采集\n", Color.Red);
  152. return;
  153. }
  154. }
  155. }
  156. if (OK.Checked)
  157. {
  158. LogicHandler.DoCommandLog(Tag.ToString(), User.UserName, ma_code.Text, User.UserLineCode, User.UserSourceCode, User.CurrentStepCode, User.CurrentStepCode + "结果为良品", SN.Text, "");
  159. }
  160. else
  161. {
  162. int CheckedNum = 0;
  163. //是否已经添加到不良
  164. bool AddToReject = false;
  165. for (int i = WaitRejectList.Items.Count - 1; i >= 0; i--)
  166. {
  167. if (WaitRejectList.Items[i].Checked)
  168. {
  169. AddToReject = false;
  170. for (int j = 0; j < ChoosedRejectList.Items.Count; j++)
  171. {
  172. if ((ChoosedRejectList.Items[j].SubItems[2].Text == WaitRejectList.Items[i].SubItems[2].Text))
  173. {
  174. AddToReject = true;
  175. OperateResult.AppendText(">>已存在" + ChoosedRejectList.Items[j].SubItems[2].Text + "不良\n", Color.Red);
  176. break;
  177. }
  178. }
  179. //未添加则进行添加
  180. if (!AddToReject)
  181. {
  182. WaitRejectList.Items[i].Checked = false;
  183. ChoosedRejectList.Items.Add((ListViewItem)WaitRejectList.Items[i].Clone());
  184. WaitRejectList.Items[i].Remove();
  185. CheckedNum++;
  186. }
  187. }
  188. }
  189. if (CheckedNum == 0)
  190. {
  191. OperateResult.AppendText(">>请勾选不良代码\n", Color.Red);
  192. return;
  193. }
  194. LogicHandler.DoCommandLog(Tag.ToString(), User.UserName, ma_code.Text, User.UserLineCode, User.UserSourceCode, User.CurrentStepCode, User.CurrentStepCode + "结果为良品", SN.Text, "");
  195. }
  196. OperateResult.AppendText("序列号" + SN.Text + User.CurrentStepCode + "采集成功\n", System.Drawing.Color.Green);
  197. }
  198. }
  199. private void ChooseedReject_Click(object sender, EventArgs e)
  200. {
  201. if (SN.Text == "")
  202. {
  203. OperateResult.AppendText(">>序列号不能为空\n", Color.Red);
  204. SN.Focus();
  205. return;
  206. }
  207. int CheckedNum = 0;
  208. //是否已经添加到不良
  209. bool AddToReject = false;
  210. for (int i = WaitRejectList.Items.Count - 1; i >= 0; i--)
  211. {
  212. if (WaitRejectList.Items[i].Checked)
  213. {
  214. AddToReject = false;
  215. for (int j = 0; j < ChoosedRejectList.Items.Count; j++)
  216. {
  217. if ((ChoosedRejectList.Items[j].SubItems[2].Text == WaitRejectList.Items[i].SubItems[2].Text))
  218. {
  219. AddToReject = true;
  220. OperateResult.AppendText(">>已存在" + ChoosedRejectList.Items[j].SubItems[2].Text + "不良\n", Color.Red);
  221. break;
  222. }
  223. }
  224. //未添加则进行添加
  225. if (!AddToReject)
  226. {
  227. WaitRejectList.Items[i].Checked = false;
  228. ChoosedRejectList.Items.Add((ListViewItem)WaitRejectList.Items[i].Clone());
  229. WaitRejectList.Items[i].Remove();
  230. CheckedNum++;
  231. }
  232. }
  233. }
  234. if (CheckedNum == 0)
  235. {
  236. OperateResult.AppendText(">>请勾选不良代码\n", Color.Red);
  237. }
  238. }
  239. private void WaitReject_Click(object sender, EventArgs e)
  240. {
  241. int CheckedNum = 0;
  242. //已存在在ListView中的Item是不能添加到其他ListView中的,需要调用其克隆的方法
  243. for (int i = ChoosedRejectList.Items.Count - 1; i >= 0; i--)
  244. {
  245. if (ChoosedRejectList.Items[i].Checked)
  246. {
  247. ChoosedRejectList.Items[i].Checked = false;
  248. WaitRejectList.Items.Add((ListViewItem)ChoosedRejectList.Items[i].Clone());
  249. ChoosedRejectList.Items[i].Remove();
  250. CheckedNum++;
  251. }
  252. }
  253. if (CheckedNum == 0)
  254. {
  255. for (int i = ChoosedRejectList.Items.Count - 1; i >= 0; i--)
  256. {
  257. WaitRejectList.Items.Add((ListViewItem)ChoosedRejectList.Items[i].Clone());
  258. ChoosedRejectList.Items[i].Remove();
  259. }
  260. }
  261. }
  262. private void bc_groupcode_SelectedIndexChanged(object sender, EventArgs e)
  263. {
  264. LoadBadCodeListView();
  265. }
  266. private void ma_prodcode_TextChanged(object sender, EventArgs e)
  267. {
  268. LoadBadGroupData();
  269. }
  270. private void SaveRepairInf_Click(object sender, EventArgs e)
  271. {
  272. if (User.CurrentStepCode == "单板测试")
  273. {
  274. if (dh.CheckExist("singleboard", "sb_sncode='" + SN.Text + "'"))
  275. {
  276. if (OK.Checked)
  277. {
  278. OperateResult.AppendText(">>" + SN.Text + "已执行单板测试\n", Color.Red);
  279. return;
  280. }
  281. }
  282. else
  283. {
  284. dh.ExecuteSql("insert into singleboard(SB_ID, SB_MAKECODE, SB_SNCODE, SB_INDATE, SB_NEXTSTEPCODE, SB_BADTIMS, SB_STATUS)" +
  285. "values(singleboard_seq.nextval,'" + ma_code.Text + "','" + SN.Text + "',sysdate,'刷三防漆',0,'1')", "insert");
  286. }
  287. }
  288. DataTable dt = (DataTable)dh.ExecuteSql("select SB_NEXTSTEPCODE,sb_status from singleboard where sb_sncode='" + SN.Text + "'", "select");
  289. if (dt.Rows.Count > 0)
  290. {
  291. string SB_NEXTSTEPCODE = dt.Rows[0]["SB_NEXTSTEPCODE"].ToString();
  292. string sb_status = dt.Rows[0]["sb_status"].ToString();
  293. if (sb_status == "3")
  294. {
  295. OperateResult.AppendText(">>" + SN.Text + "已经采集不良,不允许重复采集\n", Color.Red);
  296. return;
  297. }
  298. }
  299. if (NG.Checked)
  300. {
  301. int RejectCount = ChoosedRejectList.Items.Count;
  302. string[] bccode = new string[RejectCount];
  303. string[] bcremark = new string[RejectCount];
  304. string[] bgcode = new string[RejectCount];
  305. string[] bgname = new string[RejectCount];
  306. string[] bcname = new string[RejectCount];
  307. if (ChoosedRejectList.Items.Count == 0)
  308. {
  309. OperateResult.AppendText(">>不良品必须选择不良原因和不良代码!\n", Color.Red);
  310. return;
  311. }
  312. else
  313. {
  314. for (int i = 0; i < RejectCount; i++)
  315. {
  316. //获取不良代码组
  317. bgcode[i] = ChoosedRejectList.Items[i].SubItems[1].Text.Split(':')[0];
  318. //获取不良代码组名称
  319. bgname[i] = ChoosedRejectList.Items[i].SubItems[1].Text.Split(':')[1];
  320. //获取所有的不良代码
  321. bccode[i] = ChoosedRejectList.Items[i].SubItems[2].Text;
  322. //获取不良名称
  323. bcname[i] = ChoosedRejectList.Items[i].SubItems[3].Text;
  324. //获取所有的不良备注
  325. bcremark[i] = bc_remark.Text;
  326. }
  327. }
  328. sql.Clear();
  329. sql.Append("insert into makebad(mb_id,mb_makecode,mb_mscode,mb_sncode,mb_inman,mb_indate,mb_stepcode");
  330. sql.Append(",mb_sourcecode,mb_badcode,mb_bgcode,mb_badtable,mb_status,mb_badremark,mb_bgname,mb_badname,mb_type)");
  331. sql.Append("select makebad_seq.nextval,ma_code,sb_sncode,sb_sncode,'" + User.UserCode + "',sysdate,'" + User.CurrentStepCode + "','" + User.UserSourceCode + "',:bc_code,:bg_code,'',");
  332. sql.Append("'0',:bc_remark,:bg_name,:bc_name,'Client' from make left join singleboard on sb_makecode=ma_code ");
  333. sql.Append(" where sb_sncode='" + SN.Text + "' and sb_makecode='" + ma_code.Text + "'");
  334. if (bgcode.Length > 0)
  335. {
  336. dh.BatchInsert(sql.GetString(), new string[] { "bc_code", "bg_code", "bc_remark", "bg_name", "bc_name" }, bccode, bgcode, bcremark, bgname, bcname);
  337. }
  338. 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");
  339. LogicHandler.DoCommandLog(Tag.ToString(), User.UserName, ma_code.Text, User.UserLineCode, User.UserSourceCode, User.CurrentStepCode, User.CurrentStepCode + "结果不良品", SN.Text, "");
  340. OperateResult.AppendText("序列号" + SN.Text + "采集不良成功\n", System.Drawing.Color.Green);
  341. }
  342. }
  343. }
  344. }