Make_NewMatainInf.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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[] mbr_solutioncode = new string[GetListViewCheckCount(mbr_solutioncode_lsv)];
  153. string ErrorMessage = "";
  154. if (nrg_name.Length == 0)
  155. ErrorMessage += " 不良原因组 ";
  156. if (nr_name.Length == 0)
  157. ErrorMessage += " 不良原因 ";
  158. if (mbr_dutycode.Length == 0)
  159. ErrorMessage += " 责任别 ";
  160. if (mbr_solutioncode.Length == 0)
  161. ErrorMessage += " 解决方案 ";
  162. if (ErrorMessage == "")
  163. {
  164. string mbccomponent = GetListViewSelectedItemText(mbc_component_lsv, 0);
  165. string nrgcode = GetListViewSelectedItemText(nrg_name_lsv, 0);
  166. string nrcode = GetListViewSelectedItemText(nr_name_lsv, 0);
  167. string nrname = GetListViewSelectedItemText(nr_name_lsv, 1);
  168. string mbrdutycode = GetListViewSelectedItemText(mbr_dutycode_lsv, 0);
  169. string mbrsolutioncode = GetListViewSelectedItemText(mbr_solutioncode_lsv, 0);
  170. dt = (DataTable)dh.ExecuteSql("select ms_makecode from makeserial where ms_id='" + msid + "' and ms_sncode='" + sncode + "' and ms_status=3", "select");
  171. if (dt.Rows.Count > 0)
  172. {
  173. string macode = dt.Rows[0]["ms_makecode"].ToString();
  174. string mbr_id = dh.GetSEQ("makebadreason_seq");
  175. //存在不良组件进行提示
  176. if (dh.CheckExist("makebadreason", "mbr_badcode='" + bccode + "' and mbr_sncode='" + sncode + "' and mbr_brcode='" + nrcode + "'"))
  177. {
  178. ErrorMessage = "不良代码【" + bc_name.Text + "】已存在不良原因【" + nrname + "】\n";
  179. }
  180. if (ErrorMessage != "")
  181. {
  182. MessageBox.Show(ErrorMessage);
  183. return;
  184. }
  185. else
  186. {
  187. //保存不良原因
  188. sql.Clear();
  189. sql.Append("insert into makebadrscom (mbc_id,mbc_mbrid,mbc_component,mbc_badcode,");
  190. sql.Append("mbc_brcode,mbc_sncode,mbc_makecode,mbc_indate,mbc_inman ) values ");
  191. sql.Append("(makebadrscom_seq.nextval,'" + mbr_id + "' ,'" + mbccomponent + "',");
  192. sql.Append("'" + bccode + "','" + nrcode + "','" + sncode + "','" + macode + "',sysdate,'" + User.UserCode + "')");
  193. dh.ExecuteSql(sql.GetString(), "insert");
  194. Close();
  195. }
  196. if (mbccomponent != "" || mbccomponent != null)
  197. {
  198. //保存不良组件
  199. sql.Clear();
  200. sql.Append("insert into makebadreason (mbr_mbid,mbr_id,mbr_brcode,mbr_solutioncode,");
  201. sql.Append("mbr_dutycode,mbr_brgcode,mbr_badcode,mbr_sncode,mbr_makecode,mbr_indate,");
  202. sql.Append("mbr_inman) select '" + mbid + "','" + mbr_id + "','" + nrcode + "',");
  203. sql.Append("'" + mbrsolutioncode + "','" + mbrdutycode + "','" + nrgcode + "','" + bccode + "',");
  204. sql.Append("'" + sncode + "','" + macode + "',sysdate,'" + User.UserCode + "' from dual");
  205. dh.ExecuteSql(sql.GetString(), "insert");
  206. }
  207. }
  208. else MessageBox.Show("序列号错误,不存在或者不处于维修状态");
  209. }
  210. else MessageBox.Show(ErrorMessage + "未勾选");
  211. }
  212. private void ListView_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
  213. {
  214. e.Item.BackColor = Color.LightBlue;
  215. foreach (ListViewItem item in (sender as ListView).Items)
  216. {
  217. if (item != e.Item)
  218. item.BackColor = Color.White;
  219. }
  220. }
  221. private void nrg_name_lsv_SelectedIndexChanged(object sender, EventArgs e)
  222. {
  223. string nrg_code = "";
  224. if (nrg_name_lsv.SelectedItems.Count > 0) //或者使用SelectedItem!=null判断
  225. {
  226. nrg_code = nrg_name_lsv.SelectedItems[0].SubItems[0].Text;
  227. }
  228. sql.Clear();
  229. sql.Append("select nr_code,nr_name,nr_group from QUA_NGReason where ");
  230. sql.Append("nr_group in('" + (nrg_code == "" ? "''" : nrg_code) + "')");
  231. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  232. AddDataToListView(nr_name_lsv, dt);
  233. }
  234. private void headBar1_MouseDown(object sender, MouseEventArgs e)
  235. {
  236. ReleaseCapture();
  237. SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
  238. }
  239. private void mbc_component_lsv_ItemChecked(object sender, ItemCheckedEventArgs e)
  240. {
  241. if (e.Item.Checked)
  242. {
  243. foreach (ListViewItem item in this.mbc_component_lsv.CheckedItems)
  244. {
  245. if (item != e.Item)
  246. {
  247. item.Checked = false;
  248. item.Selected = false;
  249. }
  250. }
  251. e.Item.Selected = true;
  252. }
  253. else
  254. {
  255. e.Item.Selected = false;
  256. }
  257. }
  258. }
  259. }