Special_CancelOQC.cs 14 KB

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