Make_NewMatainInf.cs 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. sql.Clear();
  74. sql.Append("select nr_code,nr_name,nr_group from QUA_NGReason where ");
  75. sql.Append("nr_group in(" + (nrg_code == "" ? "''" : nrg_code) + ")");
  76. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  77. //未查询到查询全部数据
  78. if (dt.Rows.Count == 0)
  79. dt = (DataTable)dh.ExecuteSql("select nr_code,nr_name,nr_group from QUA_NGReason", "select");
  80. AddDataToListView(nr_name_lsv, dt);
  81. //加载责任别
  82. dt = (DataTable)dh.ExecuteSql("select nd_code,nd_name from ngduty", "select");
  83. AddDataToListView(mbr_dutycode_lsv, dt);
  84. //加载解决方案
  85. sql.Clear();
  86. sql.Append("select so_code,so_name from PRODUCTSOLUTION left join solution on ");
  87. sql.Append("so_code=ps_socode where ps_kindcode='" + pk_code + "'");
  88. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  89. if (dt.Rows.Count == 0)
  90. dt = (DataTable)dh.ExecuteSql("select so_code,so_name from solution", "select");
  91. AddDataToListView(mbr_solutioncode_lsv, dt);
  92. }
  93. /// <summary>
  94. /// 往ListView添加数据
  95. /// </summary>
  96. /// <param name="lsv"></param>
  97. /// <param name="dt"></param>
  98. private void AddDataToListView(ListView lsv, DataTable dt)
  99. {
  100. lsv.Items.Clear();
  101. lsv.BeginUpdate();
  102. for (int i = 0; i < dt.Rows.Count; i++)
  103. {
  104. ListViewItem lvi = new ListViewItem(dt.Rows[i][0].ToString());
  105. //第一列是勾选列,设置列头文本为空
  106. for (int j = 1; j < dt.Columns.Count; j++)
  107. lvi.SubItems.Add(dt.Rows[i][j].ToString());
  108. lsv.Items.Add(lvi);
  109. }
  110. lsv.EndUpdate();
  111. }
  112. private void Cancel_Click(object sender, EventArgs e)
  113. {
  114. Close();
  115. }
  116. private int GetListViewCheckCount(ListView lsv)
  117. {
  118. int CheckedNum = 0;
  119. //已存在在ListView中的Item是不能添加到其他ListView中的,需要调用其克隆的方法
  120. for (int i = lsv.Items.Count - 1; i >= 0; i--)
  121. {
  122. if (lsv.Items[i].Selected)
  123. CheckedNum++;
  124. }
  125. return CheckedNum;
  126. }
  127. private string GetListViewSelectedItemText(ListView lsv)
  128. {
  129. for (int i = lsv.Items.Count - 1; i >= 0; i--)
  130. {
  131. if (lsv.Items[i].Selected)
  132. return lsv.Items[i].SubItems[0].Text;
  133. }
  134. return null;
  135. }
  136. private void Save_Click(object sender, EventArgs e)
  137. {
  138. if (bg_name.Text == "" || bc_name.Text == "")
  139. {
  140. MessageBox.Show("不良代码组和不良代码不能为空");
  141. return;
  142. }
  143. string[] mbc_component = new string[GetListViewCheckCount(mbc_component_lsv)];
  144. string[] nrg_name = new string[GetListViewCheckCount(nrg_name_lsv)];
  145. string[] nr_name = new string[GetListViewCheckCount(nr_name_lsv)];
  146. string[] mbr_dutycode = new string[GetListViewCheckCount(mbr_dutycode_lsv)];
  147. string[] mbr_solutioncode = new string[GetListViewCheckCount(mbr_solutioncode_lsv)];
  148. string ErrorMessage = "";
  149. if (nrg_name.Length == 0)
  150. ErrorMessage += " 不良原因组 ";
  151. if (nr_name.Length == 0)
  152. ErrorMessage += " 不良原因 ";
  153. if (mbr_dutycode.Length == 0)
  154. ErrorMessage += " 责任别 ";
  155. if (mbr_solutioncode.Length == 0)
  156. ErrorMessage += " 解决方案 ";
  157. if (ErrorMessage == "")
  158. {
  159. ErrorMessage = "";
  160. string mbccomponent = GetListViewSelectedItemText(mbc_component_lsv);
  161. string nrgcode = GetListViewSelectedItemText(nrg_name_lsv);
  162. string nrcode = GetListViewSelectedItemText(nr_name_lsv);
  163. string mbrdutycode = GetListViewSelectedItemText(mbr_dutycode_lsv);
  164. string mbrsolutioncode = GetListViewSelectedItemText(mbr_solutioncode_lsv);
  165. dt = (DataTable)dh.ExecuteSql("select ms_makecode from makeserial where ms_id='" + msid + "' and ms_sncode='" + sncode + "' and ms_status=3", "select");
  166. if (dt.Rows.Count > 0)
  167. {
  168. string macode = dt.Rows[0]["ms_makecode"].ToString();
  169. if (!dh.CheckExist("makebadreason", "mbr_sncode='" + sncode + "' and mbr_badcode='" + bccode + "' "))
  170. {
  171. string mbr_id = dh.GetSEQ("makebadreason_seq");
  172. sql.Clear();
  173. sql.Append("insert into makebadreason (mbr_mbid,mbr_id,mbr_brcode,mbr_solutioncode,");
  174. sql.Append("mbr_dutycode,mbr_brgcode,mbr_badcode,mbr_sncode,mbr_makecode,mbr_indate,");
  175. sql.Append("mbr_inman) select '" + mbid + "'," + mbr_id + ",'" + nrgcode + "',");
  176. sql.Append("'" + mbrsolutioncode + "','" + mbrdutycode + "','" + nrcode + "','" + bccode+ "',");
  177. sql.Append("'" + sncode + "','" + macode + "',sysdate,'" + User.UserCode + "' from dual");
  178. dh.ExecuteSql(sql.GetString(), "insert");
  179. }
  180. else ErrorMessage = "序列号" + sncode + "已存在不良代码" + bccode + "\n";
  181. if (mbccomponent != "" || mbccomponent != null)
  182. {
  183. if (!dh.CheckExist("makebadrscom", "mbc_sncode='" + sncode + "' and mbc_component='" + mbccomponent + "'"))
  184. {
  185. sql.Clear();
  186. sql.Append("insert into makebadrscom (mbc_id,mbc_mbrid,mbc_component,mbc_badcode,");
  187. sql.Append("mbc_brcode,mbc_sncode,mbc_makecode,mbc_indate,mbc_inman ) values ");
  188. sql.Append("(makebadrscom_seq.nextval,'" + mbid + "' ,'" + mbccomponent + "',");
  189. sql.Append("'" + bccode + "','" + nrcode + "','" + sncode + "','" + macode + "',sysdate,'" + User.UserCode + "')");
  190. dh.ExecuteSql(sql.GetString(), "insert");
  191. }
  192. else ErrorMessage += "序列号" + sncode + "已存在不良组件" + mbccomponent;
  193. }
  194. if (ErrorMessage != "")
  195. MessageBox.Show(ErrorMessage);
  196. else
  197. Close();
  198. }
  199. else
  200. MessageBox.Show("序列号错误,不存在或者不处于维修状态");
  201. }
  202. else
  203. MessageBox.Show(ErrorMessage + "未勾选");
  204. }
  205. private void ListView_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
  206. {
  207. e.Item.BackColor = Color.LightBlue;
  208. foreach (ListViewItem item in (sender as ListView).Items)
  209. {
  210. if (item != e.Item)
  211. item.BackColor = Color.White;
  212. }
  213. }
  214. }
  215. }