Make_NewMatainInf.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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.DataOperate;
  11. using UAS_MES.Entity;
  12. using UAS_MES.PublicMethod;
  13. namespace UAS_MES.Make
  14. {
  15. public partial class Make_NewMatainInf : Form
  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 = new DataHelper();
  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", "select");
  96. AddDataToListView(mbr_solutioncode_lsv, dt);
  97. }
  98. /// <summary>
  99. /// 往ListView添加数据
  100. /// </summary>
  101. /// <param name="lsv"></param>
  102. /// <param name="dt"></param>
  103. private void AddDataToListView(ListView lsv, DataTable dt)
  104. {
  105. lsv.Items.Clear();
  106. lsv.BeginUpdate();
  107. for (int i = 0; i < dt.Rows.Count; i++)
  108. {
  109. ListViewItem lvi = new ListViewItem(dt.Rows[i][0].ToString());
  110. //第一列是勾选列,设置列头文本为空
  111. for (int j = 1; j < dt.Columns.Count; j++)
  112. lvi.SubItems.Add(dt.Rows[i][j].ToString());
  113. lsv.Items.Add(lvi);
  114. }
  115. lsv.EndUpdate();
  116. }
  117. private void Cancel_Click(object sender, EventArgs e)
  118. {
  119. Close();
  120. }
  121. private int GetListViewCheckCount(ListView lsv)
  122. {
  123. int CheckedNum = 0;
  124. //已存在在ListView中的Item是不能添加到其他ListView中的,需要调用其克隆的方法
  125. for (int i = lsv.Items.Count - 1; i >= 0; i--)
  126. {
  127. if (lsv.Items[i].Selected)
  128. CheckedNum++;
  129. }
  130. return CheckedNum;
  131. }
  132. private string GetListViewSelectedItemText(ListView lsv, int ItemIndex)
  133. {
  134. for (int i = lsv.Items.Count - 1; i >= 0; i--)
  135. {
  136. if (lsv.Items[i].Selected)
  137. return lsv.Items[i].SubItems[ItemIndex].Text;
  138. }
  139. return null;
  140. }
  141. private void Save_Click(object sender, EventArgs e)
  142. {
  143. if (bg_name.Text == "" || bc_name.Text == "")
  144. {
  145. MessageBox.Show("不良代码组和不良代码不能为空");
  146. return;
  147. }
  148. string[] mbc_component = new string[GetListViewCheckCount(mbc_component_lsv)];
  149. string[] nrg_name = new string[GetListViewCheckCount(nrg_name_lsv)];
  150. string[] nr_name = new string[GetListViewCheckCount(nr_name_lsv)];
  151. string[] mbr_dutycode = new string[GetListViewCheckCount(mbr_dutycode_lsv)];
  152. string ErrorMessage = "";
  153. if (nrg_name.Length == 0)
  154. ErrorMessage += " 不良原因组 ";
  155. if (nr_name.Length == 0)
  156. ErrorMessage += " 不良原因 ";
  157. if (mbr_dutycode.Length == 0)
  158. ErrorMessage += " 责任别 ";
  159. if (ErrorMessage == "")
  160. {
  161. for (int i = 0; i < mbc_component_lsv.Items.Count; i++)
  162. {
  163. if (mbc_component_lsv.Items[i].Checked)
  164. {
  165. mbc_component_lsv.Items[i].Selected = true;
  166. }
  167. else
  168. {
  169. mbc_component_lsv.Items[i].Selected = false;
  170. }
  171. }
  172. string mbccomponent = GetListViewSelectedItemText(mbc_component_lsv, 0);
  173. string nrgcode = GetListViewSelectedItemText(nrg_name_lsv, 0);
  174. string nrcode = GetListViewSelectedItemText(nr_name_lsv, 0);
  175. string nrname = GetListViewSelectedItemText(nr_name_lsv, 1);
  176. string mbrdutycode = GetListViewSelectedItemText(mbr_dutycode_lsv, 0);
  177. string mbrsolutioncode = GetListViewSelectedItemText(mbr_solutioncode_lsv, 0);
  178. dt = (DataTable)dh.ExecuteSql("select ms_makecode from makeserial where ms_id='" + msid + "' and ms_sncode='" + sncode + "' and ms_status=3", "select");
  179. if (dt.Rows.Count > 0)
  180. {
  181. string macode = dt.Rows[0]["ms_makecode"].ToString();
  182. string mbr_id = dh.GetSEQ("makebadreason_seq");
  183. //存在不良组件进行提示
  184. 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"))
  185. {
  186. ErrorMessage = "不良代码【" + bc_name.Text + "】已存在不良原因【" + nrname + "】\n";
  187. }
  188. if (ErrorMessage != "")
  189. {
  190. MessageBox.Show(ErrorMessage);
  191. return;
  192. }
  193. else
  194. {
  195. //保存不良组件
  196. sql.Clear();
  197. sql.Append("insert into makebadrscom (mbc_id,mbc_mbrid,mbc_component,mbc_badcode,");
  198. sql.Append("mbc_brcode,mbc_sncode,mbc_makecode,mbc_indate,mbc_inman ) values ");
  199. sql.Append("(makebadrscom_seq.nextval,'" + mbr_id + "' ,'" + mbccomponent + "',");
  200. sql.Append("'" + bccode + "','" + nrcode + "','" + sncode + "','" + macode + "',sysdate,'" + User.UserCode + "')");
  201. dh.ExecuteSql(sql.GetString(), "insert");
  202. Close();
  203. }
  204. if (mbccomponent != "" || mbccomponent != null)
  205. {
  206. //保存不良原因
  207. sql.Clear();
  208. sql.Append("insert into makebadreason (mbr_mbid,mbr_id,mbr_brcode,mbr_solutioncode,");
  209. sql.Append("mbr_dutycode,mbr_brgcode,mbr_badcode,mbr_sncode,mbr_makecode,mbr_indate,");
  210. sql.Append("mbr_inman) select '" + mbid + "','" + mbr_id + "','" + nrcode + "',");
  211. sql.Append("'" + mbrsolutioncode + "','" + mbrdutycode + "','" + nrgcode + "','" + bccode + "',");
  212. sql.Append("'" + sncode + "','" + macode + "',sysdate,'" + User.UserCode + "' from dual");
  213. dh.ExecuteSql(sql.GetString(), "insert");
  214. }
  215. }
  216. else MessageBox.Show("序列号错误,不存在或者不处于维修状态");
  217. }
  218. else MessageBox.Show(ErrorMessage + "未勾选");
  219. }
  220. private void ListView_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
  221. {
  222. e.Item.BackColor = Color.LightBlue;
  223. foreach (ListViewItem item in (sender as ListView).Items)
  224. {
  225. if (item != e.Item)
  226. item.BackColor = Color.White;
  227. }
  228. }
  229. private void nrg_name_lsv_SelectedIndexChanged(object sender, EventArgs e)
  230. {
  231. string nrg_code = "";
  232. if (nrg_name_lsv.SelectedItems.Count > 0) //或者使用SelectedItem!=null判断
  233. {
  234. nrg_code = nrg_name_lsv.SelectedItems[0].SubItems[0].Text;
  235. }
  236. sql.Clear();
  237. sql.Append("select nr_code,nr_name,nr_group from QUA_NGREASONGROUPDET left join QUA_NGREASONGROUP ");
  238. sql.Append("on nrgd_nrgid=nrg_id left join QUA_NGReason on nrgd_nrcode=nr_code where ");
  239. sql.Append("nrg_code in('" + (nrg_code == "" ? "''" : nrg_code) + "')");
  240. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  241. AddDataToListView(nr_name_lsv, dt);
  242. }
  243. private void headBar1_MouseDown(object sender, MouseEventArgs e)
  244. {
  245. ReleaseCapture();
  246. SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
  247. }
  248. private void mbc_component_lsv_ItemChecked(object sender, ItemCheckedEventArgs e)
  249. {
  250. if (e.Item.Checked)
  251. {
  252. foreach (ListViewItem item in this.mbc_component_lsv.CheckedItems)
  253. {
  254. if (item != e.Item)
  255. {
  256. item.Checked = false;
  257. }
  258. }
  259. }
  260. }
  261. }
  262. }