Make_NewMatainInf.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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_NewMatainInf : 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 bgcode = "";
  37. /// <summary>
  38. /// 不良代码
  39. /// </summary>
  40. string bccode = "";
  41. /// <summary>
  42. /// MakeSerial表ID
  43. /// </summary>
  44. string msid = "";
  45. /// <summary>
  46. /// MakeBad表主键
  47. /// </summary>
  48. string mbid = "";
  49. DataHelper dh;
  50. DataTable dt;
  51. LogStringBuilder sql = new LogStringBuilder();
  52. public Make_NewMatainInf(string iBgName, string iBgCode, string iBcName, string iBccode, string iSnCode, string iMsID, string iMbID)
  53. {
  54. InitializeComponent();
  55. bg_name.Text = iBgName;
  56. bc_name.Text = iBcName;
  57. bgcode = iBgCode;
  58. bccode = iBccode;
  59. sncode = iSnCode;
  60. msid = iMsID;
  61. mbid = iMbID;
  62. }
  63. private void Make_NewMatainInf_Load(object sender, EventArgs e)
  64. {
  65. dh = SystemInf.dh;
  66. string pr_code = dh.getFieldDataByCondition("makeserial", "ms_prodcode", "ms_sncode='" + sncode + "'").ToString();
  67. string pk_code = dh.getFieldDataByCondition("product left join productkind on pk_name=pr_kind", "pk_code", "pr_code='" + pr_code + "'").ToString();
  68. //加载不良原因组数据
  69. sql.Clear();
  70. sql.Append("select nrg_code,nrg_name from PRODUCTBADREASONGROUP left join ");
  71. sql.Append("QUA_NGReasonGroup on nrg_code=pbr_brgcode where pbr_kindcode='" + pk_code + "'");
  72. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  73. //未查询到则查询全部数据
  74. if (dt.Rows.Count == 0)
  75. dt = (DataTable)dh.ExecuteSql("select nrg_code,nrg_name from QUA_NGReasonGroup where nrg_statuscode ='AUDITED'", "select");
  76. AddDataToListView(nrg_name_lsv, dt);
  77. //加载不良原因
  78. string nrg_code = "";
  79. for (int i = 0; i < dt.Rows.Count; i++)
  80. {
  81. if (i == dt.Rows.Count - 1)
  82. nrg_code += "'" + dt.Rows[i]["nrg_code"] + "'";
  83. else
  84. nrg_code += "'" + dt.Rows[i]["nrg_code"] + "',";
  85. }
  86. //加载责任别
  87. dt = (DataTable)dh.ExecuteSql("select nd_code,nd_name from ngduty", "select");
  88. AddDataToListView(mbr_dutycode_lsv, dt);
  89. //加载解决方案
  90. sql.Clear();
  91. sql.Append("select so_code,so_name from PRODUCTSOLUTION left join solution on ");
  92. sql.Append("so_code=ps_socode where ps_kindcode='" + pk_code + "'");
  93. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  94. if (dt.Rows.Count == 0)
  95. dt = (DataTable)dh.ExecuteSql("select so_code,so_name from solution order by so_id", "select");
  96. AddDataToListView(mbr_solutioncode_lsv, dt);
  97. for (int i = 0; i < nrg_name_lsv.Items.Count; i++)
  98. {
  99. if (nrg_name_lsv.Items[i].SubItems[0].Text == bgcode)
  100. {
  101. ListView_ItemSelectionChanged(nrg_name_lsv, new ListViewItemSelectionChangedEventArgs(nrg_name_lsv.Items[i], i, true));
  102. nrg_name_lsv.Items[i].Selected = true;
  103. }
  104. }
  105. }
  106. /// <summary>
  107. /// 往ListView添加数据
  108. /// </summary>
  109. /// <param name="lsv"></param>
  110. /// <param name="dt"></param>
  111. private void AddDataToListView(ListView lsv, DataTable dt)
  112. {
  113. lsv.Items.Clear();
  114. lsv.BeginUpdate();
  115. for (int i = 0; i < dt.Rows.Count; i++)
  116. {
  117. ListViewItem lvi = new ListViewItem(dt.Rows[i][0].ToString());
  118. //第一列是勾选列,设置列头文本为空
  119. for (int j = 1; j < dt.Columns.Count; j++)
  120. lvi.SubItems.Add(dt.Rows[i][j].ToString());
  121. lsv.Items.Add(lvi);
  122. }
  123. lsv.EndUpdate();
  124. }
  125. private void Cancel_Click(object sender, EventArgs e)
  126. {
  127. Close();
  128. }
  129. private int GetListViewCheckCount(ListView lsv)
  130. {
  131. int CheckedNum = 0;
  132. //已存在在ListView中的Item是不能添加到其他ListView中的,需要调用其克隆的方法
  133. for (int i = lsv.Items.Count - 1; i >= 0; i--)
  134. {
  135. if (lsv.Items[i].Selected)
  136. CheckedNum++;
  137. }
  138. return CheckedNum;
  139. }
  140. private string GetListViewSelectedItemText(ListView lsv, int ItemIndex)
  141. {
  142. for (int i = lsv.Items.Count - 1; i >= 0; i--)
  143. {
  144. if (lsv.Items[i].Selected)
  145. return lsv.Items[i].SubItems[ItemIndex].Text;
  146. }
  147. return null;
  148. }
  149. private void Save_Click(object sender, EventArgs e)
  150. {
  151. if (bg_name.Text == "" || bc_name.Text == "")
  152. {
  153. MessageBox.Show("不良代码组和不良代码不能为空");
  154. return;
  155. }
  156. string[] mbc_component = new string[GetListViewCheckCount(mbc_component_lsv)];
  157. string[] nrg_name = new string[GetListViewCheckCount(nrg_name_lsv)];
  158. string[] nr_name = new string[GetListViewCheckCount(nr_name_lsv)];
  159. string[] mbr_dutycode = new string[GetListViewCheckCount(mbr_dutycode_lsv)];
  160. string ErrorMessage = "";
  161. if (nrg_name.Length == 0)
  162. ErrorMessage += " 不良原因组 ";
  163. if (nr_name.Length == 0)
  164. ErrorMessage += " 不良原因 ";
  165. if (mbr_dutycode.Length == 0)
  166. ErrorMessage += " 责任别 ";
  167. if (ErrorMessage == "")
  168. {
  169. for (int i = 0; i < mbc_component_lsv.Items.Count; i++)
  170. {
  171. if (mbc_component_lsv.Items[i].Checked)
  172. {
  173. mbc_component_lsv.Items[i].Selected = true;
  174. }
  175. else
  176. {
  177. mbc_component_lsv.Items[i].Selected = false;
  178. }
  179. }
  180. string mbccomponent = GetListViewSelectedItemText(mbc_component_lsv, 0);
  181. string nrgcode = GetListViewSelectedItemText(nrg_name_lsv, 0);
  182. string nrgname = GetListViewSelectedItemText(nrg_name_lsv, 1);
  183. string nrcode = GetListViewSelectedItemText(nr_name_lsv, 0);
  184. string nrname = GetListViewSelectedItemText(nr_name_lsv, 1);
  185. string mbrdutycode = GetListViewSelectedItemText(mbr_dutycode_lsv, 0);
  186. string mbrdutyname = GetListViewSelectedItemText(mbr_dutycode_lsv, 1);
  187. string mbrsolutioncode = GetListViewSelectedItemText(mbr_solutioncode_lsv, 0);
  188. string mbrsolutionname = GetListViewSelectedItemText(mbr_solutioncode_lsv, 1);
  189. dt = (DataTable)dh.ExecuteSql("select ms_makecode from makeserial where ms_id='" + msid + "' and ms_sncode='" + sncode + "' and (ms_status=3 or ms_reworkstatus=3) ", "select");
  190. if (dt.Rows.Count > 0)
  191. {
  192. string macode = dt.Rows[0]["ms_makecode"].ToString();
  193. string mbr_id = dh.GetSEQ("makebadreason_seq");
  194. //存在不良组件进行提示
  195. if (dh.CheckExist("makebadreason left join makebad on mbr_mbid=mb_id and mbr_sncode=mb_sncode", "mbr_badcode='" + bccode + "' and mbr_sncode='" + sncode + "' and mbr_brcode='" + nrcode + "' and mb_status=0"))
  196. {
  197. ErrorMessage = "不良代码【" + bc_name.Text + "】已存在不良原因【" + nrname + "】\n";
  198. }
  199. if (ErrorMessage != "")
  200. {
  201. MessageBox.Show(ErrorMessage);
  202. return;
  203. }
  204. else
  205. {
  206. //保存不良组件
  207. sql.Clear();
  208. sql.Append("insert into makebadrscom (mbc_id,mbc_mbrid,mbc_component,mbc_badcode,");
  209. sql.Append("mbc_brcode,mbc_sncode,mbc_makecode,mbc_indate,mbc_inman ) values ");
  210. sql.Append("(makebadrscom_seq.nextval,'" + mbr_id + "' ,'" + mbccomponent + "',");
  211. sql.Append("'" + bccode + "','" + nrcode + "','" + sncode + "','" + macode + "',sysdate,'" + User.UserCode + "')");
  212. dh.ExecuteSql(sql.GetString(), "insert");
  213. Close();
  214. }
  215. if (mbccomponent != "" || mbccomponent != null)
  216. {
  217. //保存不良原因
  218. sql.Clear();
  219. sql.Append("insert into makebadreason (mbr_mbid,mbr_id,mbr_brcode,mbr_solutioncode,");
  220. sql.Append("mbr_dutycode,mbr_brgcode,mbr_badcode,mbr_sncode,mbr_makecode,mbr_indate,");
  221. sql.Append("mbr_inman,mbr_brname,mbr_solutionname,mbr_badname,mbr_brgname,mbr_dutyname) select '" + mbid + "','" + mbr_id + "','" + nrcode + "',");
  222. sql.Append("'" + mbrsolutioncode + "','" + mbrdutycode + "','" + nrgcode + "','" + bccode + "',");
  223. sql.Append("'" + sncode + "','" + macode + "',sysdate,'" + User.UserCode + "','" + nrname + "','" + mbrsolutionname + "','" + bc_name.Text + "','" + nrgname + "','" + mbrdutyname + "' from dual");
  224. dh.ExecuteSql(sql.GetString(), "insert");
  225. }
  226. }
  227. else MessageBox.Show("序列号错误,不存在或者不处于维修状态");
  228. }
  229. else MessageBox.Show(ErrorMessage + "未勾选");
  230. }
  231. private void ListView_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
  232. {
  233. e.Item.BackColor = Color.LightBlue;
  234. foreach (ListViewItem item in (sender as ListView).Items)
  235. {
  236. if (item != e.Item)
  237. item.BackColor = Color.White;
  238. }
  239. }
  240. private void nrg_name_lsv_SelectedIndexChanged(object sender, EventArgs e)
  241. {
  242. string nrg_code = "";
  243. if (nrg_name_lsv.SelectedItems.Count > 0) //或者使用SelectedItem!=null判断
  244. {
  245. nrg_code = nrg_name_lsv.SelectedItems[0].SubItems[0].Text;
  246. }
  247. sql.Clear();
  248. sql.Append("select nr_code,nr_name,nr_group from QUA_NGREASONGROUPDET left join QUA_NGREASONGROUP ");
  249. sql.Append("on nrgd_nrgid=nrg_id left join QUA_NGReason on nrgd_nrcode=nr_code where ");
  250. sql.Append("nrg_code in('" + (nrg_code == "" ? "''" : nrg_code) + "')");
  251. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  252. AddDataToListView(nr_name_lsv, dt);
  253. for (int i = 0; i < nr_name_lsv.Items.Count; i++)
  254. {
  255. if (nr_name_lsv.Items[i].SubItems[0].Text == bccode)
  256. {
  257. ListView_ItemSelectionChanged(nr_name_lsv, new ListViewItemSelectionChangedEventArgs(nr_name_lsv.Items[i], i, true));
  258. nr_name_lsv.Items[i].Selected = true;
  259. }
  260. }
  261. }
  262. private void headBar1_MouseDown(object sender, MouseEventArgs e)
  263. {
  264. ReleaseCapture();
  265. SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
  266. }
  267. private void mbc_component_lsv_ItemChecked(object sender, ItemCheckedEventArgs e)
  268. {
  269. if (e.Item.Checked)
  270. {
  271. foreach (ListViewItem item in this.mbc_component_lsv.CheckedItems)
  272. {
  273. if (item != e.Item)
  274. {
  275. item.Checked = false;
  276. }
  277. }
  278. }
  279. }
  280. }
  281. }