| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using UAS_MES.DataOperate;
- using UAS_MES.Entity;
- using UAS_MES.PublicMethod;
- namespace UAS_MES.Make
- {
- public partial class Make_NewMatainInf : Form
- {
- /// <summary>
- /// 序列号
- /// </summary>
- string sncode = "";
- /// <summary>
- /// 不良组代码
- /// </summary>
- string bgcode = "";
- /// <summary>
- /// 不良代码
- /// </summary>
- string bccode = "";
- /// <summary>
- /// MakeSerial表ID
- /// </summary>
- string msid = "";
- /// <summary>
- /// MakeBad表主键
- /// </summary>
- string mbid = "";
- DataHelper dh;
- DataTable dt;
- LogStringBuilder sql = new LogStringBuilder();
- public Make_NewMatainInf(string iBgName, string iBgCode, string iBcName, string iBccode, string iSnCode, string iMsID, string iMbID)
- {
- InitializeComponent();
- bg_name.Text = iBgName;
- bc_name.Text = iBcName;
- bgcode = iBgCode;
- bccode = iBccode;
- sncode = iSnCode;
- msid = iMsID;
- mbid = iMbID;
- }
- private void Make_NewMatainInf_Load(object sender, EventArgs e)
- {
- dh = new DataHelper();
- string pr_code = dh.getFieldDataByCondition("makeserial", "ms_prodcode", "ms_sncode='" + sncode + "'").ToString();
- string pk_code = dh.getFieldDataByCondition("product left join productkind on pk_name=pr_kind", "pk_code", "pr_code='" + pr_code + "'").ToString();
- //加载不良原因组数据
- sql.Clear();
- sql.Append("select nrg_code,nrg_name from PRODUCTBADREASONGROUP left join ");
- sql.Append("QUA_NGReasonGroup on nrg_code=pbr_brgcode where pbr_kindcode='" + pk_code + "'");
- dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- //未查询到则查询全部数据
- if (dt.Rows.Count == 0)
- dt = (DataTable)dh.ExecuteSql("select nrg_code,nrg_name from QUA_NGReasonGroup where nrg_statuscode ='AUDITED'", "select");
- AddDataToListView(nrg_name_lsv, dt);
- //加载不良原因
- string nrg_code = "";
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- if (i == dt.Rows.Count - 1)
- nrg_code += "'" + dt.Rows[i]["nrg_code"] + "'";
- else
- nrg_code += "'" + dt.Rows[i]["nrg_code"] + "',";
- }
- sql.Clear();
- sql.Append("select nr_code,nr_name,nr_group from QUA_NGReason where ");
- sql.Append("nr_group in(" + (nrg_code == "" ? "''" : nrg_code) + ")");
- dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- //未查询到查询全部数据
- if (dt.Rows.Count == 0)
- dt = (DataTable)dh.ExecuteSql("select nr_code,nr_name,nr_group from QUA_NGReason", "select");
- AddDataToListView(nr_name_lsv, dt);
- //加载责任别
- dt = (DataTable)dh.ExecuteSql("select nd_code,nd_name from ngduty", "select");
- AddDataToListView(mbr_dutycode_lsv, dt);
- //加载解决方案
- sql.Clear();
- sql.Append("select so_code,so_name from PRODUCTSOLUTION left join solution on ");
- sql.Append("so_code=ps_socode where ps_kindcode='" + pk_code + "'");
- dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- if (dt.Rows.Count == 0)
- dt = (DataTable)dh.ExecuteSql("select so_code,so_name from solution", "select");
- AddDataToListView(mbr_solutioncode_lsv, dt);
- }
- /// <summary>
- /// 往ListView添加数据
- /// </summary>
- /// <param name="lsv"></param>
- /// <param name="dt"></param>
- private void AddDataToListView(ListView lsv, DataTable dt)
- {
- lsv.Items.Clear();
- lsv.BeginUpdate();
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- ListViewItem lvi = new ListViewItem(dt.Rows[i][0].ToString());
- //第一列是勾选列,设置列头文本为空
- for (int j = 1; j < dt.Columns.Count; j++)
- lvi.SubItems.Add(dt.Rows[i][j].ToString());
- lsv.Items.Add(lvi);
- }
- lsv.EndUpdate();
- }
- private void Cancel_Click(object sender, EventArgs e)
- {
- Close();
- }
- private int GetListViewCheckCount(ListView lsv)
- {
- int CheckedNum = 0;
- //已存在在ListView中的Item是不能添加到其他ListView中的,需要调用其克隆的方法
- for (int i = lsv.Items.Count - 1; i >= 0; i--)
- {
- if (lsv.Items[i].Selected)
- CheckedNum++;
- }
- return CheckedNum;
- }
- private string GetListViewSelectedItemText(ListView lsv)
- {
- for (int i = lsv.Items.Count - 1; i >= 0; i--)
- {
- if (lsv.Items[i].Selected)
- return lsv.Items[i].SubItems[0].Text;
- }
- return null;
- }
- private void Save_Click(object sender, EventArgs e)
- {
- if (bg_name.Text == "" || bc_name.Text == "")
- {
- MessageBox.Show("不良代码组和不良代码不能为空");
- return;
- }
- string[] mbc_component = new string[GetListViewCheckCount(mbc_component_lsv)];
- string[] nrg_name = new string[GetListViewCheckCount(nrg_name_lsv)];
- string[] nr_name = new string[GetListViewCheckCount(nr_name_lsv)];
- string[] mbr_dutycode = new string[GetListViewCheckCount(mbr_dutycode_lsv)];
- string[] mbr_solutioncode = new string[GetListViewCheckCount(mbr_solutioncode_lsv)];
- string ErrorMessage = "";
- if (nrg_name.Length == 0)
- ErrorMessage += " 不良原因组 ";
- if (nr_name.Length == 0)
- ErrorMessage += " 不良原因 ";
- if (mbr_dutycode.Length == 0)
- ErrorMessage += " 责任别 ";
- if (mbr_solutioncode.Length == 0)
- ErrorMessage += " 解决方案 ";
- if (ErrorMessage == "")
- {
- ErrorMessage = "";
- string mbccomponent = GetListViewSelectedItemText(mbc_component_lsv);
- string nrgcode = GetListViewSelectedItemText(nrg_name_lsv);
- string nrcode = GetListViewSelectedItemText(nr_name_lsv);
- string mbrdutycode = GetListViewSelectedItemText(mbr_dutycode_lsv);
- string mbrsolutioncode = GetListViewSelectedItemText(mbr_solutioncode_lsv);
- dt = (DataTable)dh.ExecuteSql("select ms_makecode from makeserial where ms_id='" + msid + "' and ms_sncode='" + sncode + "' and ms_status=3", "select");
- if (dt.Rows.Count > 0)
- {
- string macode = dt.Rows[0]["ms_makecode"].ToString();
- if (!dh.CheckExist("makebadreason", "mbr_sncode='" + sncode + "' and mbr_badcode='" + bccode + "' "))
- {
- string mbr_id = dh.GetSEQ("makebadreason_seq");
- sql.Clear();
- sql.Append("insert into makebadreason (mbr_mbid,mbr_id,mbr_brcode,mbr_solutioncode,");
- sql.Append("mbr_dutycode,mbr_brgcode,mbr_badcode,mbr_sncode,mbr_makecode,mbr_indate,");
- sql.Append("mbr_inman) select '" + mbid + "'," + mbr_id + ",'" + nrgcode + "',");
- sql.Append("'" + mbrsolutioncode + "','" + mbrdutycode + "','" + nrcode + "','" + bccode+ "',");
- sql.Append("'" + sncode + "','" + macode + "',sysdate,'" + User.UserCode + "' from dual");
- dh.ExecuteSql(sql.GetString(), "insert");
- }
- else ErrorMessage = "序列号" + sncode + "已存在不良代码" + bccode + "\n";
- if (mbccomponent != "" || mbccomponent != null)
- {
- if (!dh.CheckExist("makebadrscom", "mbc_sncode='" + sncode + "' and mbc_component='" + mbccomponent + "'"))
- {
- sql.Clear();
- sql.Append("insert into makebadrscom (mbc_id,mbc_mbrid,mbc_component,mbc_badcode,");
- sql.Append("mbc_brcode,mbc_sncode,mbc_makecode,mbc_indate,mbc_inman ) values ");
- sql.Append("(makebadrscom_seq.nextval,'" + mbid + "' ,'" + mbccomponent + "',");
- sql.Append("'" + bccode + "','" + nrcode + "','" + sncode + "','" + macode + "',sysdate,'" + User.UserCode + "')");
- dh.ExecuteSql(sql.GetString(), "insert");
- }
- else ErrorMessage += "序列号" + sncode + "已存在不良组件" + mbccomponent;
- }
- if (ErrorMessage != "")
- MessageBox.Show(ErrorMessage);
- else
- Close();
- }
- else
- MessageBox.Show("序列号错误,不存在或者不处于维修状态");
- }
- else
- MessageBox.Show(ErrorMessage + "未勾选");
- }
- private void ListView_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
- {
- e.Item.BackColor = Color.LightBlue;
- foreach (ListViewItem item in (sender as ListView).Items)
- {
- if (item != e.Item)
- item.BackColor = Color.White;
- }
- }
- }
- }
|