Make_NewMatainInf.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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.Text;
  8. using System.Windows.Forms;
  9. using UAS_MES.DataOperate;
  10. using UAS_MES.Entity;
  11. using UAS_MES.PublicMethod;
  12. namespace UAS_MES.Make
  13. {
  14. public partial class Make_NewMatainInf : Form
  15. {
  16. /// <summary>
  17. /// 序列号
  18. /// </summary>
  19. string sncode = "";
  20. /// <summary>
  21. /// 不良组代码
  22. /// </summary>
  23. string bgcode = "";
  24. /// <summary>
  25. /// 不良代码
  26. /// </summary>
  27. string bccode = "";
  28. /// <summary>
  29. /// MakeSerial表ID
  30. /// </summary>
  31. string msid = "";
  32. /// <summary>
  33. /// MakeBad表主键
  34. /// </summary>
  35. string mbid = "";
  36. DataHelper dh;
  37. DataTable dt;
  38. LogStringBuilder sql = new LogStringBuilder();
  39. public Make_NewMatainInf(string iBgName, string iBgCode, string iBcName, string iBccode, string iSnCode, string iMsID, string iMbID)
  40. {
  41. InitializeComponent();
  42. bg_name.Text = iBgName;
  43. bc_name.Text = iBcName;
  44. bgcode = iBgCode;
  45. bccode = iBccode;
  46. sncode = iSnCode;
  47. msid = iMsID;
  48. mbid = iMbID;
  49. }
  50. private void Make_NewMatainInf_Load(object sender, EventArgs e)
  51. {
  52. dh = new DataHelper();
  53. string pr_code = dh.getFieldDataByCondition("makeserial", "ms_prodcode", "ms_sncode='" + sncode + "'").ToString();
  54. string pk_code = dh.getFieldDataByCondition("product left join productkind on pk_name=pr_kind", "pk_code", "pr_code='" + pr_code + "'").ToString();
  55. //加载不良原因组数据
  56. sql.Clear();
  57. sql.Append("select nrg_code,nrg_name from PRODUCTBADREASONGROUP left join ");
  58. sql.Append("QUA_NGReasonGroup on nrg_code=pbr_brgcode where pbr_kindcode='" + pk_code + "'");
  59. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  60. //未查询到则查询全部数据
  61. if (dt.Rows.Count == 0)
  62. dt = (DataTable)dh.ExecuteSql("select nrg_code,nrg_name from QUA_NGReasonGroup where nrg_statuscode ='AUDITED'", "select");
  63. AddDataToListView(nrg_name_lsv, dt);
  64. //加载不良原因
  65. string nrg_code = "";
  66. for (int i = 0; i < dt.Rows.Count; i++)
  67. {
  68. if (i == dt.Rows.Count - 1)
  69. nrg_code += "'" + dt.Rows[i]["nrg_code"] + "'";
  70. else
  71. nrg_code += "'" + dt.Rows[i]["nrg_code"] + "',";
  72. }
  73. //加载责任别
  74. dt = (DataTable)dh.ExecuteSql("select nd_code,nd_name from ngduty", "select");
  75. AddDataToListView(mbr_dutycode_lsv, dt);
  76. //加载解决方案
  77. sql.Clear();
  78. sql.Append("select so_code,so_name from PRODUCTSOLUTION left join solution on ");
  79. sql.Append("so_code=ps_socode where ps_kindcode='" + pk_code + "'");
  80. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  81. if (dt.Rows.Count == 0)
  82. dt = (DataTable)dh.ExecuteSql("select so_code,so_name from solution", "select");
  83. AddDataToListView(mbr_solutioncode_lsv, dt);
  84. }
  85. /// <summary>
  86. /// 往ListView添加数据
  87. /// </summary>
  88. /// <param name="lsv"></param>
  89. /// <param name="dt"></param>
  90. private void AddDataToListView(ListView lsv, DataTable dt)
  91. {
  92. lsv.Items.Clear();
  93. lsv.BeginUpdate();
  94. for (int i = 0; i < dt.Rows.Count; i++)
  95. {
  96. ListViewItem lvi = new ListViewItem(dt.Rows[i][0].ToString());
  97. //第一列是勾选列,设置列头文本为空
  98. for (int j = 1; j < dt.Columns.Count; j++)
  99. lvi.SubItems.Add(dt.Rows[i][j].ToString());
  100. lsv.Items.Add(lvi);
  101. }
  102. lsv.EndUpdate();
  103. }
  104. private void Cancel_Click(object sender, EventArgs e)
  105. {
  106. Close();
  107. }
  108. private int GetListViewCheckCount(ListView lsv)
  109. {
  110. int CheckedNum = 0;
  111. //已存在在ListView中的Item是不能添加到其他ListView中的,需要调用其克隆的方法
  112. for (int i = lsv.Items.Count - 1; i >= 0; i--)
  113. {
  114. if (lsv.Items[i].Selected)
  115. CheckedNum++;
  116. }
  117. return CheckedNum;
  118. }
  119. private string GetListViewSelectedItemText(ListView lsv)
  120. {
  121. for (int i = lsv.Items.Count - 1; i >= 0; i--)
  122. {
  123. if (lsv.Items[i].Selected)
  124. return lsv.Items[i].SubItems[0].Text;
  125. }
  126. return null;
  127. }
  128. private void Save_Click(object sender, EventArgs e)
  129. {
  130. if (bg_name.Text == "" || bc_name.Text == "")
  131. {
  132. MessageBox.Show("不良代码组和不良代码不能为空");
  133. return;
  134. }
  135. string[] mbc_component = new string[GetListViewCheckCount(mbc_component_lsv)];
  136. string[] nrg_name = new string[GetListViewCheckCount(nrg_name_lsv)];
  137. string[] nr_name = new string[GetListViewCheckCount(nr_name_lsv)];
  138. string[] mbr_dutycode = new string[GetListViewCheckCount(mbr_dutycode_lsv)];
  139. string[] mbr_solutioncode = new string[GetListViewCheckCount(mbr_solutioncode_lsv)];
  140. string ErrorMessage = "";
  141. if (nrg_name.Length == 0)
  142. ErrorMessage += " 不良原因组 ";
  143. if (nr_name.Length == 0)
  144. ErrorMessage += " 不良原因 ";
  145. if (mbr_dutycode.Length == 0)
  146. ErrorMessage += " 责任别 ";
  147. if (mbr_solutioncode.Length == 0)
  148. ErrorMessage += " 解决方案 ";
  149. if (ErrorMessage == "")
  150. {
  151. ErrorMessage = "";
  152. string mbccomponent = GetListViewSelectedItemText(mbc_component_lsv);
  153. string nrgcode = GetListViewSelectedItemText(nrg_name_lsv);
  154. string nrcode = GetListViewSelectedItemText(nr_name_lsv);
  155. string mbrdutycode = GetListViewSelectedItemText(mbr_dutycode_lsv);
  156. string mbrsolutioncode = GetListViewSelectedItemText(mbr_solutioncode_lsv);
  157. dt = (DataTable)dh.ExecuteSql("select ms_makecode from makeserial where ms_id='" + msid + "' and ms_sncode='" + sncode + "' and ms_status=3", "select");
  158. if (dt.Rows.Count > 0)
  159. {
  160. string macode = dt.Rows[0]["ms_makecode"].ToString();
  161. string mbr_id = dh.GetSEQ("makebadreason_seq");
  162. sql.Clear();
  163. sql.Append("insert into makebadreason (mbr_mbid,mbr_id,mbr_brcode,mbr_solutioncode,");
  164. sql.Append("mbr_dutycode,mbr_brgcode,mbr_badcode,mbr_sncode,mbr_makecode,mbr_indate,");
  165. sql.Append("mbr_inman) select '" + mbid + "','" + mbr_id + "','" + nrcode + "',");
  166. sql.Append("'" + mbrsolutioncode + "','" + mbrdutycode + "','" + nrgcode + "','" + bccode + "',");
  167. sql.Append("'" + sncode + "','" + macode + "',sysdate,'" + User.UserCode + "' from dual");
  168. dh.ExecuteSql(sql.GetString(), "insert");
  169. if (mbccomponent != "" || mbccomponent != null)
  170. {
  171. if (!dh.CheckExist("makebadrscom", "mbc_sncode='" + sncode + "' and mbc_component='" + mbccomponent + "'"))
  172. {
  173. sql.Clear();
  174. sql.Append("insert into makebadrscom (mbc_id,mbc_mbrid,mbc_component,mbc_badcode,");
  175. sql.Append("mbc_brcode,mbc_sncode,mbc_makecode,mbc_indate,mbc_inman ) values ");
  176. sql.Append("(makebadrscom_seq.nextval,'" + mbr_id + "' ,'" + mbccomponent + "',");
  177. sql.Append("'" + bccode + "','" + nrcode + "','" + sncode + "','" + macode + "',sysdate,'" + User.UserCode + "')");
  178. dh.ExecuteSql(sql.GetString(), "insert");
  179. }
  180. else ErrorMessage += "序列号" + sncode + "已存在不良组件" + mbccomponent;
  181. }
  182. if (ErrorMessage != "")
  183. MessageBox.Show(ErrorMessage);
  184. else
  185. Close();
  186. }
  187. else
  188. MessageBox.Show("序列号错误,不存在或者不处于维修状态");
  189. }
  190. else
  191. MessageBox.Show(ErrorMessage + "未勾选");
  192. }
  193. private void ListView_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
  194. {
  195. e.Item.BackColor = Color.LightBlue;
  196. foreach (ListViewItem item in (sender as ListView).Items)
  197. {
  198. if (item != e.Item)
  199. item.BackColor = Color.White;
  200. }
  201. }
  202. private void nrg_name_lsv_SelectedIndexChanged(object sender, EventArgs e)
  203. {
  204. string nrg_code = "";
  205. if (nrg_name_lsv.SelectedItems.Count > 0) //或者使用SelectedItem!=null判断
  206. {
  207. nrg_code = nrg_name_lsv.SelectedItems[0].SubItems[0].Text;
  208. }
  209. sql.Clear();
  210. sql.Append("select nr_code,nr_name,nr_group from QUA_NGReason where ");
  211. sql.Append("nr_group in('" + (nrg_code == "" ? "''" : nrg_code) + "')");
  212. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  213. AddDataToListView(nr_name_lsv, dt);
  214. }
  215. }
  216. }