Make_NewBadCode_DE.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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.Runtime.InteropServices;
  8. using System.Text;
  9. using System.Windows.Forms;
  10. using UAS_MES_NEW.DataOperate;
  11. using UAS_MES_NEW.Entity;
  12. using UAS_MES_NEW.PublicMethod;
  13. namespace UAS_MES_NEW.Make
  14. {
  15. public partial class Make_NewBadCode_DE : CustomControl.BaseForm.BaseForm
  16. {
  17. //所有用到了headBar的部分都需要这段代码
  18. [DllImport("user32.dll")]
  19. public static extern bool ReleaseCapture();
  20. [DllImport("user32.dll")]
  21. public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
  22. [DllImport("user32.dll", EntryPoint = "GetWindowLong", CharSet = CharSet.Auto)]
  23. public static extern int GetWindowLong(HandleRef hWnd, int nIndex);
  24. [DllImport("user32.dll", EntryPoint = "SetWindowLong", CharSet = CharSet.Auto)]
  25. public static extern IntPtr SetWindowLong(HandleRef hWnd, int nIndex, int dwNewLong);
  26. public const int WM_SYSCOMMAND = 0x0112;
  27. public const int SC_MOVE = 0xF010;
  28. public const int HTCAPTION = 0x0002;
  29. /// <summary>
  30. /// 序列号
  31. /// </summary>
  32. string sncode = "";
  33. /// <summary>
  34. /// 工单号
  35. /// </summary>
  36. string macode = "";
  37. DataHelper dh;
  38. DataTable dt;
  39. LogStringBuilder sql = new LogStringBuilder();
  40. public string[] bccode;
  41. public string[] bgcode;
  42. public Make_NewBadCode_DE(string iSnCode, string iMakeCode)
  43. {
  44. InitializeComponent();
  45. sncode = iSnCode;
  46. macode = iMakeCode;
  47. }
  48. private void Make_NewBadCode_Load(object sender, EventArgs e)
  49. {
  50. dh = SystemInf.dh;
  51. ms_makecode.Text = macode;
  52. ms_sncode.Text = sncode;
  53. string pr_code = dh.getFieldDataByCondition("makeserial", "ms_prodcode", "ms_sncode='" + sncode + "' and ms_makecode='" + macode + "'").ToString();
  54. sql.Clear();
  55. sql.Append("select bg_code,bg_name from product left join productkind on pr_kind =pk_name ");
  56. sql.Append("left join productbadgroup on pb_kindcode= pk_code left join badgroup on ");
  57. sql.Append("bg_code=pb_badgroup where pr_code='" + pr_code + "' and nvl(pb_kindcode,'')<>'' and bg_statuscode='AUDITED' order by case when bg_code='" + User.DefaultBadGroup + "' then 0 else 1 end");
  58. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  59. //如果未查询到数据则获取全部的不良组别
  60. if (dt.Rows.Count == 0)
  61. {
  62. sql.Clear();
  63. sql.Append("select bg_code,bg_name from badgroup where bg_statuscode='AUDITED' order by case when bg_code='" + User.DefaultBadGroup + "' then 0 else 1 end");
  64. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  65. badgroup.DataSource = dt;
  66. badgroup.DisplayMember = "bg_name";
  67. badgroup.ValueMember = "bg_code";
  68. LoadBadCodeListView();
  69. }
  70. else
  71. {
  72. badgroup.DataSource = dt;
  73. badgroup.DisplayMember = "bg_name";
  74. badgroup.ValueMember = "bg_code";
  75. LoadBadCodeListView();
  76. }
  77. }
  78. private void ChooseedReject_Click(object sender, EventArgs e)
  79. {
  80. int CheckedNum = 0;
  81. //是否已经添加到不良
  82. bool AddToReject = false;
  83. for (int i = WaitRejectList.Items.Count - 1; i >= 0; i--)
  84. {
  85. if (WaitRejectList.Items[i].Checked)
  86. {
  87. AddToReject = false;
  88. for (int j = 0; j < ChoosedRejectList.Items.Count; j++)
  89. {
  90. if ((ChoosedRejectList.Items[j].SubItems[3].Text == WaitRejectList.Items[i].SubItems[3].Text))
  91. {
  92. AddToReject = true;
  93. break;
  94. }
  95. }
  96. if (!AddToReject)
  97. {
  98. WaitRejectList.Items[i].Checked = false;
  99. ChoosedRejectList.Items.Add((ListViewItem)WaitRejectList.Items[i].Clone());
  100. WaitRejectList.Items[i].Remove();
  101. CheckedNum++;
  102. }
  103. }
  104. }
  105. if (CheckedNum == 0)
  106. {
  107. for (int i = WaitRejectList.Items.Count - 1; i >= 0; i--)
  108. {
  109. AddToReject = false;
  110. for (int j = 0; j < ChoosedRejectList.Items.Count; j++)
  111. {
  112. if ((ChoosedRejectList.Items[j].SubItems[3].Text == WaitRejectList.Items[i].SubItems[3].Text))
  113. {
  114. AddToReject = true;
  115. break;
  116. }
  117. }
  118. if (!AddToReject)
  119. {
  120. ChoosedRejectList.Items.Add((ListViewItem)WaitRejectList.Items[i].Clone());
  121. WaitRejectList.Items[i].Remove();
  122. CheckedNum++;
  123. }
  124. }
  125. }
  126. }
  127. private void WaitReject_Click(object sender, EventArgs e)
  128. {
  129. int CheckedNum = 0;
  130. //已存在在ListView中的Item是不能添加到其他ListView中的,需要调用其克隆的方法
  131. for (int i = ChoosedRejectList.Items.Count - 1; i >= 0; i--)
  132. {
  133. if (ChoosedRejectList.Items[i].Checked)
  134. {
  135. ChoosedRejectList.Items[i].Checked = false;
  136. WaitRejectList.Items.Add((ListViewItem)ChoosedRejectList.Items[i].Clone());
  137. ChoosedRejectList.Items[i].Remove();
  138. CheckedNum++;
  139. }
  140. }
  141. if (CheckedNum == 0)
  142. {
  143. for (int i = ChoosedRejectList.Items.Count - 1; i >= 0; i--)
  144. {
  145. WaitRejectList.Items.Add((ListViewItem)ChoosedRejectList.Items[i].Clone());
  146. ChoosedRejectList.Items[i].Remove();
  147. }
  148. }
  149. }
  150. private void Cancel_Click(object sender, EventArgs e)
  151. {
  152. Close();
  153. }
  154. private void Save_Click(object sender, EventArgs e)
  155. {
  156. if (ms_sncode.Text == "" || ms_makecode.Text == "")
  157. {
  158. MessageBox.Show("序列号和工单号不允许为空");
  159. return;
  160. }
  161. int RejectCount = ChoosedRejectList.Items.Count;
  162. bccode = new string[RejectCount];
  163. bgcode = new string[RejectCount];
  164. string[] id = new string[RejectCount];
  165. string ErrorMessage = "";
  166. if (ChoosedRejectList.Items.Count == 0)
  167. {
  168. MessageBox.Show("不良品必须选择不良原因和不良代码!");
  169. return;
  170. }
  171. else
  172. {
  173. //用户未填写不良代码一切按照正常逻辑,填写了从index=1开始执行
  174. for (int i = 0; i < RejectCount; i++)
  175. {
  176. bgcode[i] = ChoosedRejectList.Items[i].SubItems[1].Text;
  177. //获取所有的不良代码
  178. bccode[i] = ChoosedRejectList.Items[i].SubItems[3].Text;
  179. }
  180. }
  181. }
  182. private void badgroup_SelectedIndexChanged(object sender, EventArgs e)
  183. {
  184. LoadBadCodeListView();
  185. }
  186. /// <summary>
  187. /// 加载不良代码的ListView的信息
  188. /// </summary>
  189. private void LoadBadCodeListView()
  190. {
  191. string bg_id = badgroup.SelectedValue.ToString();
  192. sql.Clear();
  193. sql.Append("select bg_code,bg_name,bc_code,bc_name,bc_note from badgroupdetail left join badgroup on bgd_bgid=bg_id ");
  194. sql.Append("left join badcode on bgd_badcode=bc_code where bg_code='" + ((bg_id != "" && bg_id != "System.Data.DataRowView") ? bg_id.ToString() : "") + "' and bg_code is not null ");
  195. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  196. BadInfo.DataSource = dt;
  197. //往listview中添加数据
  198. WaitRejectList.Items.Clear();
  199. WaitRejectList.BeginUpdate();
  200. for (int i = 0; i < dt.Rows.Count; i++)
  201. {
  202. ListViewItem lvi = new ListViewItem();
  203. //第一列是勾选列,设置列头文本为空
  204. lvi.Text = "";
  205. for (int j = 0; j < dt.Columns.Count; j++)
  206. lvi.SubItems.Add(dt.Rows[i][j].ToString());
  207. WaitRejectList.Items.Add(lvi);
  208. }
  209. WaitRejectList.EndUpdate();
  210. }
  211. private void headBar1_MouseDown(object sender, MouseEventArgs e)
  212. {
  213. ReleaseCapture();
  214. SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
  215. }
  216. private void Filter_UserControlTextChanged(object sender, EventArgs e)
  217. {
  218. try
  219. {
  220. DataRow[] dr = (BadInfo.DataSource as DataTable).Select(" bc_name like '%" + Filter.Text + "%'");
  221. DataTable dt = (BadInfo.DataSource as DataTable).Clone();
  222. for (int i = 0; i < dr.Length; i++)
  223. {
  224. dt.Rows.Add(dr[i].ItemArray);
  225. }
  226. WaitRejectList.Items.Clear();
  227. WaitRejectList.BeginUpdate();
  228. for (int i = 0; i < dt.Rows.Count; i++)
  229. {
  230. ListViewItem lvi = new ListViewItem();
  231. //第一列是勾选列,设置列头文本为空
  232. lvi.Text = "";
  233. for (int j = 0; j < dt.Columns.Count; j++)
  234. lvi.SubItems.Add(dt.Rows[i][j].ToString());
  235. WaitRejectList.Items.Add(lvi);
  236. }
  237. WaitRejectList.EndUpdate();
  238. }
  239. catch (Exception)
  240. {
  241. }
  242. }
  243. }
  244. }