Special_OQC.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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.Special
  15. {
  16. public partial class Special_OQC : 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 Special_OQC()
  30. {
  31. InitializeComponent();
  32. }
  33. private void Special_BoxSplit_Load(object sender, EventArgs e)
  34. {
  35. dh = SystemInf.dh;
  36. }
  37. private void LoadBadGroupData()
  38. {
  39. //如果ms_makecode的值修改过再去查询
  40. sql.Clear();
  41. sql.Append("select bg_code||':'||bg_name bg_name,bg_code from badgroup left join (select pb_badgroup,pr_kind ");
  42. sql.Append("from product left join productkind on pk_name=pr_kind ");
  43. sql.Append("left join productbadgroup on pk_code=PB_KINDCODE where pr_code='" + ma_prodcode.Text + "')");
  44. sql.Append("on pb_badgroup=bg_code where bg_statuscode='AUDITED' order by case when bg_code='" + User.DefaultBadGroup + "' then 0 else 1 end");
  45. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  46. bc_groupcode.DisplayMember = "bg_name";
  47. bc_groupcode.ValueMember = "bg_code";
  48. bc_groupcode.DataSource = dt;
  49. }
  50. private void LoadBadCodeListView()
  51. {
  52. object bg_code = bc_groupcode.SelectedValue;
  53. sql.Clear();
  54. sql.Append("select bg_code||':'||bg_name bg_code,bc_code,bc_name,'' bc_remark from badgroupdetail ");
  55. sql.Append("left join badgroup on bg_id=bgd_bgid left join badcode on bgd_badcode=bc_code where ");
  56. sql.Append("bg_code='" + (bg_code != null ? bg_code.ToString() : "") + "' and bg_code is not null order by bgd_detno");
  57. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  58. BadInfSource.DataSource = dt;
  59. //往listview中添加数据
  60. WaitRejectList.Items.Clear();
  61. WaitRejectList.BeginUpdate();
  62. for (int i = 0; i < dt.Rows.Count; i++)
  63. {
  64. if (!ChoosedList.Contains(dt.Rows[i]["bc_code"].ToString()))
  65. {
  66. ListViewItem lvi = new ListViewItem();
  67. //第一列是勾选列,设置列头文本为空
  68. lvi.Text = "";
  69. WaitList.Add(dt.Rows[i]["bc_code"].ToString());
  70. for (int j = 0; j < dt.Columns.Count; j++)
  71. lvi.SubItems.Add(dt.Rows[i][j].ToString());
  72. WaitRejectList.Items.Add(lvi);
  73. }
  74. }
  75. WaitRejectList.EndUpdate();
  76. }
  77. private void SN_KeyDown(object sender, KeyEventArgs e)
  78. {
  79. if (e.KeyCode == Keys.Enter)
  80. {
  81. DataTable dt = (DataTable)dh.ExecuteSql("select ms_sncode,ms_makecode,ms_id,ma_prodcode,pr_detail from makeserial left join make on ms_makecode=ma_code left join product on pr_code=ma_prodcode where ms_sncode='" + SN.Text + "' or ms_imei1='" + SN.Text + "' or ms_imei2='" + SN.Text + "' order by ms_id desc", "select");
  82. if (dt.Rows.Count == 0)
  83. {
  84. OperateResult.AppendText("序列号" + SN.Text + "不存在", System.Drawing.Color.Red);
  85. return;
  86. }
  87. BaseUtil.SetFormValue(this.Controls, dt);
  88. string ms_id = dt.Rows[0]["ms_id"].ToString();
  89. SN.Text = dt.Rows[0]["ms_sncode"].ToString();
  90. if (OK.Checked)
  91. {
  92. dh.ExecuteSql("update makeserial set ms_iftest=-1 where ms_id=" + ms_id, "update");
  93. LogicHandler.DoCommandLog(Tag.ToString(), User.UserName, ms_makecode.Text, User.UserLineCode, User.UserSourceCode, "QC抽检", "QC抽检成功,结果为良品", SN.Text, "");
  94. }
  95. else
  96. {
  97. int CheckedNum = 0;
  98. //是否已经添加到不良
  99. bool AddToReject = false;
  100. for (int i = WaitRejectList.Items.Count - 1; i >= 0; i--)
  101. {
  102. if (WaitRejectList.Items[i].Checked)
  103. {
  104. AddToReject = false;
  105. for (int j = 0; j < ChoosedRejectList.Items.Count; j++)
  106. {
  107. if ((ChoosedRejectList.Items[j].SubItems[2].Text == WaitRejectList.Items[i].SubItems[2].Text))
  108. {
  109. AddToReject = true;
  110. OperateResult.AppendText(">>已存在" + ChoosedRejectList.Items[j].SubItems[2].Text + "不良\n", Color.Red);
  111. break;
  112. }
  113. }
  114. //未添加则进行添加
  115. if (!AddToReject)
  116. {
  117. WaitRejectList.Items[i].Checked = false;
  118. ChoosedRejectList.Items.Add((ListViewItem)WaitRejectList.Items[i].Clone());
  119. WaitRejectList.Items[i].Remove();
  120. CheckedNum++;
  121. }
  122. }
  123. }
  124. if (CheckedNum == 0)
  125. {
  126. OperateResult.AppendText(">>请勾选不良代码\n", Color.Red);
  127. return;
  128. }
  129. dh.ExecuteSql("update makeserial set ms_status=3,ms_nextstepcode='' ,ms_iftest=-1 where ms_id=" + ms_id, "update");
  130. LogicHandler.DoCommandLog(Tag.ToString(), User.UserName, ms_makecode.Text, User.UserLineCode, User.UserSourceCode, "QC抽检", "QC抽检成功,结果为不良", SN.Text, "");
  131. }
  132. OperateResult.AppendText("序列号" + SN.Text + "抽检记录成功", System.Drawing.Color.Green);
  133. }
  134. }
  135. private void ChooseedReject_Click(object sender, EventArgs e)
  136. {
  137. if (SN.Text == "")
  138. {
  139. OperateResult.AppendText(">>序列号不能为空\n", Color.Red);
  140. SN.Focus();
  141. return;
  142. }
  143. int CheckedNum = 0;
  144. //是否已经添加到不良
  145. bool AddToReject = false;
  146. for (int i = WaitRejectList.Items.Count - 1; i >= 0; i--)
  147. {
  148. if (WaitRejectList.Items[i].Checked)
  149. {
  150. AddToReject = false;
  151. for (int j = 0; j < ChoosedRejectList.Items.Count; j++)
  152. {
  153. if ((ChoosedRejectList.Items[j].SubItems[2].Text == WaitRejectList.Items[i].SubItems[2].Text))
  154. {
  155. AddToReject = true;
  156. OperateResult.AppendText(">>已存在" + ChoosedRejectList.Items[j].SubItems[2].Text + "不良\n", Color.Red);
  157. break;
  158. }
  159. }
  160. //未添加则进行添加
  161. if (!AddToReject)
  162. {
  163. WaitRejectList.Items[i].Checked = false;
  164. ChoosedRejectList.Items.Add((ListViewItem)WaitRejectList.Items[i].Clone());
  165. WaitRejectList.Items[i].Remove();
  166. CheckedNum++;
  167. }
  168. }
  169. }
  170. if (CheckedNum == 0)
  171. {
  172. OperateResult.AppendText(">>请勾选不良代码\n", Color.Red);
  173. }
  174. }
  175. private void WaitReject_Click(object sender, EventArgs e)
  176. {
  177. int CheckedNum = 0;
  178. //已存在在ListView中的Item是不能添加到其他ListView中的,需要调用其克隆的方法
  179. for (int i = ChoosedRejectList.Items.Count - 1; i >= 0; i--)
  180. {
  181. if (ChoosedRejectList.Items[i].Checked)
  182. {
  183. ChoosedRejectList.Items[i].Checked = false;
  184. WaitRejectList.Items.Add((ListViewItem)ChoosedRejectList.Items[i].Clone());
  185. ChoosedRejectList.Items[i].Remove();
  186. CheckedNum++;
  187. }
  188. }
  189. if (CheckedNum == 0)
  190. {
  191. for (int i = ChoosedRejectList.Items.Count - 1; i >= 0; i--)
  192. {
  193. WaitRejectList.Items.Add((ListViewItem)ChoosedRejectList.Items[i].Clone());
  194. ChoosedRejectList.Items[i].Remove();
  195. }
  196. }
  197. }
  198. private void bc_groupcode_SelectedIndexChanged(object sender, EventArgs e)
  199. {
  200. LoadBadCodeListView();
  201. }
  202. private void ma_prodcode_TextChanged(object sender, EventArgs e)
  203. {
  204. LoadBadGroupData();
  205. }
  206. private void SaveRepairInf_Click(object sender, EventArgs e)
  207. {
  208. if (NG.Checked)
  209. {
  210. DataTable dt = (DataTable)dh.ExecuteSql("select ms_sncode,ms_makecode,ms_id,ma_prodcode,pr_detail from makeserial left join make on ms_makecode=ma_code left join product on pr_code=ma_prodcode where ms_sncode='" + SN.Text + "' or ms_imei1='" + SN.Text + "' or ms_imei2='" + SN.Text + "' order by ms_id desc", "select");
  211. if (dt.Rows.Count == 0)
  212. {
  213. OperateResult.AppendText("序列号" + SN.Text + "不存在", System.Drawing.Color.Red);
  214. return;
  215. }
  216. BaseUtil.SetFormValue(this.Controls, dt);
  217. string ms_id = dt.Rows[0]["ms_id"].ToString();
  218. int RejectCount = ChoosedRejectList.Items.Count;
  219. string[] bccode = new string[RejectCount];
  220. string[] bcremark = new string[RejectCount];
  221. string[] bgcode = new string[RejectCount];
  222. string[] bgname = new string[RejectCount];
  223. string[] bcname = new string[RejectCount];
  224. if (ChoosedRejectList.Items.Count == 0)
  225. {
  226. OperateResult.AppendText(">>不良品必须选择不良原因和不良代码!\n", Color.Red);
  227. return;
  228. }
  229. else
  230. {
  231. for (int i = 0; i < RejectCount; i++)
  232. {
  233. //获取不良代码组
  234. bgcode[i] = ChoosedRejectList.Items[i].SubItems[1].Text.Split(':')[0];
  235. //获取不良代码组名称
  236. bgname[i] = ChoosedRejectList.Items[i].SubItems[1].Text.Split(':')[1];
  237. //获取所有的不良代码
  238. bccode[i] = ChoosedRejectList.Items[i].SubItems[2].Text;
  239. //获取不良名称
  240. bcname[i] = ChoosedRejectList.Items[i].SubItems[3].Text;
  241. //获取所有的不良备注
  242. bcremark[i] = bc_remark.Text;
  243. }
  244. }
  245. sql.Clear();
  246. sql.Append("insert into makebad(mb_id,mb_makecode,mb_mscode,mb_sncode,mb_inman,mb_indate,mb_stepcode");
  247. sql.Append(",mb_sourcecode,mb_badcode,mb_bgcode,mb_badtable,mb_status,mb_badremark,mb_bgname,mb_badname,mb_type)");
  248. sql.Append("select makebad_seq.nextval,ma_code,ms_code,ms_sncode,'" + User.UserCode + "',sysdate,'" + User.CurrentStepCode + "','" + User.UserSourceCode + "',:bc_code,:bg_code,'',");
  249. sql.Append("'0',:bc_remark,:bg_name,:bc_name,'Client' from make left join makeSerial on ms_makecode=ma_code ");
  250. sql.Append(" where ms_sncode='" + SN.Text + "' or ms_imei1='" + SN.Text + "' or ms_imei2='" + SN.Text + "' and ms_makecode='" + ms_makecode.Text + "'");
  251. if (bgcode.Length > 0)
  252. {
  253. dh.BatchInsert(sql.GetString(), new string[] { "bc_code", "bg_code", "bc_remark", "bg_name", "bc_name" }, bccode, bgcode, bcremark, bgname, bcname);
  254. }
  255. dh.ExecuteSql("update makeserial set ms_status=3,ms_nextstepcode='' ,ms_iftest=-1 where ms_id=" + ms_id, "update");
  256. LogicHandler.DoCommandLog(Tag.ToString(), User.UserName, ms_makecode.Text, User.UserLineCode, User.UserSourceCode, "QC抽检", "QC抽检成功,结果为不良", SN.Text, "");
  257. OperateResult.AppendText("序列号" + SN.Text + "抽检记录成功", System.Drawing.Color.Green);
  258. }
  259. }
  260. }
  261. }