Make_NewMatainInf.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. [DllImport("user32.dll")]
  18. public static extern bool ReleaseCapture();
  19. [DllImport("user32.dll")]
  20. public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
  21. [DllImport("user32.dll", EntryPoint = "GetWindowLong", CharSet = CharSet.Auto)]
  22. public static extern int GetWindowLong(HandleRef hWnd, int nIndex);
  23. [DllImport("user32.dll", EntryPoint = "SetWindowLong", CharSet = CharSet.Auto)]
  24. public static extern IntPtr SetWindowLong(HandleRef hWnd, int nIndex, int dwNewLong);
  25. public const int WM_SYSCOMMAND = 0x0112;
  26. public const int SC_MOVE = 0xF010;
  27. public const int HTCAPTION = 0x0002;
  28. /// <summary>
  29. /// 序列号
  30. /// </summary>
  31. string sncode = "";
  32. /// <summary>
  33. /// 不良组代码
  34. /// </summary>
  35. string bgcode = "";
  36. /// <summary>
  37. /// 不良代码
  38. /// </summary>
  39. string bccode = "";
  40. /// <summary>
  41. /// MakeSerial表ID
  42. /// </summary>
  43. string msid = "";
  44. /// <summary>
  45. /// MakeBad表主键
  46. /// </summary>
  47. string mbid = "";
  48. DataHelper dh;
  49. DataTable dt;
  50. LogStringBuilder sql = new LogStringBuilder();
  51. public Make_NewMatainInf(string iBgName, string iBgCode, string iBcName, string iBccode, string iSnCode, string iMsID, string iMbID)
  52. {
  53. InitializeComponent();
  54. bg_name.Text = iBgName;
  55. bc_name.Text = iBcName;
  56. bgcode = iBgCode;
  57. bccode = iBccode;
  58. sncode = iSnCode;
  59. msid = iMsID;
  60. mbid = iMbID;
  61. }
  62. private void Make_NewMatainInf_Load(object sender, EventArgs e)
  63. {
  64. dh = new DataHelper();
  65. string pr_code = dh.getFieldDataByCondition("makeserial", "ms_prodcode", "ms_sncode='" + sncode + "'").ToString();
  66. string pk_code = dh.getFieldDataByCondition("product left join productkind on pk_name=pr_kind", "pk_code", "pr_code='" + pr_code + "'").ToString();
  67. //加载不良原因组数据
  68. sql.Clear();
  69. sql.Append("select nrg_code,nrg_name from PRODUCTBADREASONGROUP left join ");
  70. sql.Append("QUA_NGReasonGroup on nrg_code=pbr_brgcode where pbr_kindcode='" + pk_code + "'");
  71. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  72. //未查询到则查询全部数据
  73. if (dt.Rows.Count == 0)
  74. dt = (DataTable)dh.ExecuteSql("select nrg_code,nrg_name from QUA_NGReasonGroup where nrg_statuscode ='AUDITED'", "select");
  75. AddDataToListView(nrg_name_lsv, dt);
  76. //加载不良原因
  77. string nrg_code = "";
  78. for (int i = 0; i < dt.Rows.Count; i++)
  79. {
  80. if (i == dt.Rows.Count - 1)
  81. nrg_code += "'" + dt.Rows[i]["nrg_code"] + "'";
  82. else
  83. nrg_code += "'" + dt.Rows[i]["nrg_code"] + "',";
  84. }
  85. //加载责任别
  86. dt = (DataTable)dh.ExecuteSql("select nd_code,nd_name from ngduty", "select");
  87. AddDataToListView(mbr_dutycode_lsv, dt);
  88. //加载解决方案
  89. sql.Clear();
  90. sql.Append("select so_code,so_name from PRODUCTSOLUTION left join solution on ");
  91. sql.Append("so_code=ps_socode where ps_kindcode='" + pk_code + "'");
  92. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  93. if (dt.Rows.Count == 0)
  94. dt = (DataTable)dh.ExecuteSql("select so_code,so_name from solution", "select");
  95. AddDataToListView(mbr_solutioncode_lsv, dt);
  96. }
  97. /// <summary>
  98. /// 往ListView添加数据
  99. /// </summary>
  100. /// <param name="lsv"></param>
  101. /// <param name="dt"></param>
  102. private void AddDataToListView(ListView lsv, DataTable dt)
  103. {
  104. lsv.Items.Clear();
  105. lsv.BeginUpdate();
  106. for (int i = 0; i < dt.Rows.Count; i++)
  107. {
  108. ListViewItem lvi = new ListViewItem(dt.Rows[i][0].ToString());
  109. //第一列是勾选列,设置列头文本为空
  110. for (int j = 1; j < dt.Columns.Count; j++)
  111. lvi.SubItems.Add(dt.Rows[i][j].ToString());
  112. lsv.Items.Add(lvi);
  113. }
  114. lsv.EndUpdate();
  115. }
  116. private void Cancel_Click(object sender, EventArgs e)
  117. {
  118. Close();
  119. }
  120. private int GetListViewCheckCount(ListView lsv)
  121. {
  122. int CheckedNum = 0;
  123. //已存在在ListView中的Item是不能添加到其他ListView中的,需要调用其克隆的方法
  124. for (int i = lsv.Items.Count - 1; i >= 0; i--)
  125. {
  126. if (lsv.Items[i].Selected)
  127. CheckedNum++;
  128. }
  129. return CheckedNum;
  130. }
  131. private string GetListViewSelectedItemText(ListView lsv, int ItemIndex)
  132. {
  133. for (int i = lsv.Items.Count - 1; i >= 0; i--)
  134. {
  135. if (lsv.Items[i].Selected)
  136. return lsv.Items[i].SubItems[ItemIndex].Text;
  137. }
  138. return null;
  139. }
  140. private void Save_Click(object sender, EventArgs e)
  141. {
  142. if (bg_name.Text == "" || bc_name.Text == "")
  143. {
  144. MessageBox.Show("不良代码组和不良代码不能为空");
  145. return;
  146. }
  147. string[] mbc_component = new string[GetListViewCheckCount(mbc_component_lsv)];
  148. string[] nrg_name = new string[GetListViewCheckCount(nrg_name_lsv)];
  149. string[] nr_name = new string[GetListViewCheckCount(nr_name_lsv)];
  150. string[] mbr_dutycode = new string[GetListViewCheckCount(mbr_dutycode_lsv)];
  151. string[] mbr_solutioncode = new string[GetListViewCheckCount(mbr_solutioncode_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 (mbr_solutioncode.Length == 0)
  160. ErrorMessage += " 解决方案 ";
  161. if (ErrorMessage == "")
  162. {
  163. ErrorMessage = "";
  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. if (!dh.CheckExist("makebadreason", "mbr_sncode='" + sncode + "' and mbr_brcode='" + nrcode + "' and mbr_badcode='" + bccode + "'"))
  176. {
  177. sql.Clear();
  178. sql.Append("insert into makebadreason (mbr_mbid,mbr_id,mbr_brcode,mbr_solutioncode,");
  179. sql.Append("mbr_dutycode,mbr_brgcode,mbr_badcode,mbr_sncode,mbr_makecode,mbr_indate,");
  180. sql.Append("mbr_inman) select '" + mbid + "','" + mbr_id + "','" + nrcode + "',");
  181. sql.Append("'" + mbrsolutioncode + "','" + mbrdutycode + "','" + nrgcode + "','" + bccode + "',");
  182. sql.Append("'" + sncode + "','" + macode + "',sysdate,'" + User.UserCode + "' from dual");
  183. dh.ExecuteSql(sql.GetString(), "insert");
  184. MessageBox.Show("不良原因保存成功");
  185. }
  186. else {
  187. ErrorMessage = "不良代码【" + bc_name.Text + "】已存在不良原因【" + nrname + "】";
  188. }
  189. if (mbccomponent != "" || mbccomponent != null)
  190. {
  191. if (!dh.CheckExist("makebadrscom", "mbc_badcode='" + bccode + "' and mbc_sncode='" + sncode + "' and mbc_component='" + mbccomponent + "'"))
  192. {
  193. sql.Clear();
  194. sql.Append("insert into makebadrscom (mbc_id,mbc_mbrid,mbc_component,mbc_badcode,");
  195. sql.Append("mbc_brcode,mbc_sncode,mbc_makecode,mbc_indate,mbc_inman ) values ");
  196. sql.Append("(makebadrscom_seq.nextval,'" + mbr_id + "' ,'" + mbccomponent + "',");
  197. sql.Append("'" + bccode + "','" + nrcode + "','" + sncode + "','" + macode + "',sysdate,'" + User.UserCode + "')");
  198. dh.ExecuteSql(sql.GetString(), "insert");
  199. }
  200. else ErrorMessage += "序列号" + sncode + "已存在不良组件" + mbccomponent;
  201. }
  202. if (ErrorMessage != "")
  203. MessageBox.Show(ErrorMessage);
  204. else Close();
  205. }
  206. else MessageBox.Show("序列号错误,不存在或者不处于维修状态");
  207. }
  208. else MessageBox.Show(ErrorMessage + "未勾选");
  209. }
  210. private void ListView_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
  211. {
  212. e.Item.BackColor = Color.LightBlue;
  213. foreach (ListViewItem item in (sender as ListView).Items)
  214. {
  215. if (item != e.Item)
  216. item.BackColor = Color.White;
  217. }
  218. }
  219. private void nrg_name_lsv_SelectedIndexChanged(object sender, EventArgs e)
  220. {
  221. string nrg_code = "";
  222. if (nrg_name_lsv.SelectedItems.Count > 0) //或者使用SelectedItem!=null判断
  223. {
  224. nrg_code = nrg_name_lsv.SelectedItems[0].SubItems[0].Text;
  225. }
  226. sql.Clear();
  227. sql.Append("select nr_code,nr_name,nr_group from QUA_NGReason where ");
  228. sql.Append("nr_group in('" + (nrg_code == "" ? "''" : nrg_code) + "')");
  229. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  230. AddDataToListView(nr_name_lsv, dt);
  231. }
  232. private void headBar1_MouseDown(object sender, MouseEventArgs e)
  233. {
  234. ReleaseCapture();
  235. SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
  236. }
  237. }
  238. }