Make_NewBadCode.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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 : 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 Make_NewBadCode(string iSnCode, string iMakeCode)
  41. {
  42. InitializeComponent();
  43. sncode = iSnCode;
  44. macode = iMakeCode;
  45. }
  46. private void Make_NewBadCode_Load(object sender, EventArgs e)
  47. {
  48. dh = SystemInf.dh;
  49. ms_makecode.Text = macode;
  50. ms_sncode.Text = sncode;
  51. string pr_code = dh.getFieldDataByCondition("makeserial", "ms_prodcode", "ms_sncode='" + sncode + "' and ms_makecode='" + macode + "'").ToString();
  52. sql.Clear();
  53. sql.Append("select bg_code,bg_name from product left join productkind on pr_kind =pk_name ");
  54. sql.Append("left join productbadgroup on pb_kindcode= pk_code left join badgroup on ");
  55. 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");
  56. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  57. //如果未查询到数据则获取全部的不良组别
  58. if (dt.Rows.Count == 0)
  59. {
  60. sql.Clear();
  61. 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");
  62. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  63. badgroup.DataSource = dt;
  64. badgroup.DisplayMember = "bg_name";
  65. badgroup.ValueMember = "bg_code";
  66. LoadBadCodeListView();
  67. }
  68. else
  69. {
  70. badgroup.DataSource = dt;
  71. badgroup.DisplayMember = "bg_name";
  72. badgroup.ValueMember = "bg_code";
  73. LoadBadCodeListView();
  74. }
  75. }
  76. private void ChooseedReject_Click(object sender, EventArgs e)
  77. {
  78. int CheckedNum = 0;
  79. //是否已经添加到不良
  80. bool AddToReject = false;
  81. for (int i = WaitRejectList.Items.Count - 1; i >= 0; i--)
  82. {
  83. if (WaitRejectList.Items[i].Checked)
  84. {
  85. AddToReject = false;
  86. for (int j = 0; j < ChoosedRejectList.Items.Count; j++)
  87. {
  88. if ((ChoosedRejectList.Items[j].SubItems[3].Text == WaitRejectList.Items[i].SubItems[3].Text))
  89. {
  90. AddToReject = true;
  91. break;
  92. }
  93. }
  94. if (!AddToReject)
  95. {
  96. WaitRejectList.Items[i].Checked = false;
  97. ChoosedRejectList.Items.Add((ListViewItem)WaitRejectList.Items[i].Clone());
  98. WaitRejectList.Items[i].Remove();
  99. CheckedNum++;
  100. }
  101. }
  102. }
  103. if (CheckedNum == 0)
  104. {
  105. for (int i = WaitRejectList.Items.Count - 1; i >= 0; i--)
  106. {
  107. AddToReject = false;
  108. for (int j = 0; j < ChoosedRejectList.Items.Count; j++)
  109. {
  110. if ((ChoosedRejectList.Items[j].SubItems[3].Text == WaitRejectList.Items[i].SubItems[3].Text))
  111. {
  112. AddToReject = true;
  113. break;
  114. }
  115. }
  116. if (!AddToReject)
  117. {
  118. ChoosedRejectList.Items.Add((ListViewItem)WaitRejectList.Items[i].Clone());
  119. WaitRejectList.Items[i].Remove();
  120. CheckedNum++;
  121. }
  122. }
  123. }
  124. }
  125. private void WaitReject_Click(object sender, EventArgs e)
  126. {
  127. int CheckedNum = 0;
  128. //已存在在ListView中的Item是不能添加到其他ListView中的,需要调用其克隆的方法
  129. for (int i = ChoosedRejectList.Items.Count - 1; i >= 0; i--)
  130. {
  131. if (ChoosedRejectList.Items[i].Checked)
  132. {
  133. ChoosedRejectList.Items[i].Checked = false;
  134. WaitRejectList.Items.Add((ListViewItem)ChoosedRejectList.Items[i].Clone());
  135. ChoosedRejectList.Items[i].Remove();
  136. CheckedNum++;
  137. }
  138. }
  139. if (CheckedNum == 0)
  140. {
  141. for (int i = ChoosedRejectList.Items.Count - 1; i >= 0; i--)
  142. {
  143. WaitRejectList.Items.Add((ListViewItem)ChoosedRejectList.Items[i].Clone());
  144. ChoosedRejectList.Items[i].Remove();
  145. }
  146. }
  147. }
  148. private void Cancel_Click(object sender, EventArgs e)
  149. {
  150. Close();
  151. }
  152. private void Save_Click(object sender, EventArgs e)
  153. {
  154. if (ms_sncode.Text == "" || ms_makecode.Text == "")
  155. {
  156. MessageBox.Show("序列号和工单号不允许为空");
  157. return;
  158. }
  159. int RejectCount = ChoosedRejectList.Items.Count;
  160. string[] bccode = new string[RejectCount];
  161. string[] bgcode = new string[RejectCount];
  162. string[] id = new string[RejectCount];
  163. string ErrorMessage = "";
  164. if (ChoosedRejectList.Items.Count == 0)
  165. {
  166. MessageBox.Show("不良品必须选择不良原因和不良代码!");
  167. return;
  168. }
  169. else
  170. {
  171. //用户未填写不良代码一切按照正常逻辑,填写了从index=1开始执行
  172. for (int i = 0; i < RejectCount; i++)
  173. {
  174. bgcode[i] = ChoosedRejectList.Items[i].SubItems[1].Text;
  175. //获取所有的不良代码
  176. bccode[i] = ChoosedRejectList.Items[i].SubItems[3].Text;
  177. //获取所有的不良备注
  178. id[i] = dh.GetSEQ("MakeBad_seq");
  179. }
  180. }
  181. sql.Clear();
  182. sql.Append("insert when (not exists(select 1 from makebad where mb_sncode='" + sncode + "' and mb_makecode='" + macode + "' and ");
  183. sql.Append("mb_status=0 and mb_badcode=:bc_code)) then into makebad(mb_id,mb_makecode,mb_mscode,mb_sncode,mb_inman,");
  184. sql.Append("mb_indate,mb_stepcode,mb_sourcecode,mb_badcode,mb_bgcode,mb_badtable,mb_status)");
  185. sql.Append("select DISTINCT :id,ma_code,ms_code,ms_sncode,'" + User.UserCode + "',sysdate,'" + User.CurrentStepCode + "',ms_sourcecode,:bc_code,:bg_code,'',");
  186. sql.Append("'0' from make left join makeSerial on ms_makecode=ma_code left join stepProduct on ");
  187. sql.Append("sp_mothercode=ma_prodcode and sp_stepcode=ms_nextstepcode and ms_craftcode = sp_craftcode where ms_sncode='" + sncode + "' and ms_makecode = '" + macode + "'");
  188. dh.BatchInsert(sql.GetString(), new string[] { "bc_code", "id", "bc_code", "bg_code" }, bccode, id, bccode, bgcode);
  189. MessageBox.Show("保存成功");
  190. Close();
  191. }
  192. private void badgroup_SelectedIndexChanged(object sender, EventArgs e)
  193. {
  194. LoadBadCodeListView();
  195. }
  196. /// <summary>
  197. /// 加载不良代码的ListView的信息
  198. /// </summary>
  199. private void LoadBadCodeListView()
  200. {
  201. string bg_id = badgroup.SelectedValue.ToString();
  202. sql.Clear();
  203. sql.Append("select bg_code,bg_name,bc_code,bc_name,bc_note from badgroupdetail left join badgroup on bgd_bgid=bg_id ");
  204. 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 ");
  205. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  206. BadInfo.DataSource = dt;
  207. //往listview中添加数据
  208. WaitRejectList.Items.Clear();
  209. WaitRejectList.BeginUpdate();
  210. for (int i = 0; i < dt.Rows.Count; i++)
  211. {
  212. ListViewItem lvi = new ListViewItem();
  213. //第一列是勾选列,设置列头文本为空
  214. lvi.Text = "";
  215. for (int j = 0; j < dt.Columns.Count; j++)
  216. lvi.SubItems.Add(dt.Rows[i][j].ToString());
  217. WaitRejectList.Items.Add(lvi);
  218. }
  219. WaitRejectList.EndUpdate();
  220. }
  221. private void headBar1_MouseDown(object sender, MouseEventArgs e)
  222. {
  223. ReleaseCapture();
  224. SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
  225. }
  226. private void Filter_UserControlTextChanged(object sender, EventArgs e)
  227. {
  228. try
  229. {
  230. DataRow[] dr = (BadInfo.DataSource as DataTable).Select(" bc_name like '%" + Filter.Text + "%'");
  231. DataTable dt = (BadInfo.DataSource as DataTable).Clone();
  232. for (int i = 0; i < dr.Length; i++)
  233. {
  234. dt.Rows.Add(dr[i].ItemArray);
  235. }
  236. WaitRejectList.Items.Clear();
  237. WaitRejectList.BeginUpdate();
  238. for (int i = 0; i < dt.Rows.Count; i++)
  239. {
  240. ListViewItem lvi = new ListViewItem();
  241. //第一列是勾选列,设置列头文本为空
  242. lvi.Text = "";
  243. for (int j = 0; j < dt.Columns.Count; j++)
  244. lvi.SubItems.Add(dt.Rows[i][j].ToString());
  245. WaitRejectList.Items.Add(lvi);
  246. }
  247. WaitRejectList.EndUpdate();
  248. }
  249. catch (Exception)
  250. {
  251. }
  252. }
  253. }
  254. }