Make_NewMatainInf.cs 10 KB

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