using DevExpress.Entity.ProjectModel; using DevExpress.Utils; using LabelManager2; using NPOI.SS.Formula.Functions; using System; using System.Collections.Generic; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using UAS_MES_NEW.DataOperate; using UAS_MES_NEW.Entity; using UAS_MES_NEW.PublicMethod; namespace UAS_MES_NEW.Special { public partial class Special_CancelOQC : Form { DataHelper dh; LogStringBuilder sql = new LogStringBuilder(); DataTable Dbfind; /// /// 已选的不良 /// List ChoosedList = new List(); /// /// 待选的不良 /// List WaitList = new List(); public Special_CancelOQC() { InitializeComponent(); } private void Special_BoxSplit_Load(object sender, EventArgs e) { dh = SystemInf.dh; } private void LoadBadGroupData() { //如果ms_makecode的值修改过再去查询 sql.Clear(); sql.Append("select bg_code||':'||bg_name bg_name,bg_code from badgroup left join (select pb_badgroup,pr_kind "); sql.Append("from product left join productkind on pk_name=pr_kind "); sql.Append("left join productbadgroup on pk_code=PB_KINDCODE where pr_code='" + ma_prodcode.Text + "')"); sql.Append("on pb_badgroup=bg_code where bg_statuscode='AUDITED' order by case when bg_code='" + User.DefaultBadGroup + "' then 0 else 1 end"); DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); bc_groupcode.DisplayMember = "bg_name"; bc_groupcode.ValueMember = "bg_code"; bc_groupcode.DataSource = dt; } private void LoadBadCodeListView() { object bg_code = bc_groupcode.SelectedValue; sql.Clear(); sql.Append("select bg_code||':'||bg_name bg_code,bc_code,bc_name,'' bc_remark from badgroupdetail "); sql.Append("left join badgroup on bg_id=bgd_bgid left join badcode on bgd_badcode=bc_code where "); sql.Append("bg_code='" + (bg_code != null ? bg_code.ToString() : "") + "' and bg_code is not null order by bgd_detno"); DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); BadInfSource.DataSource = dt; //往listview中添加数据 WaitRejectList.Items.Clear(); WaitRejectList.BeginUpdate(); for (int i = 0; i < dt.Rows.Count; i++) { if (!ChoosedList.Contains(dt.Rows[i]["bc_code"].ToString())) { ListViewItem lvi = new ListViewItem(); //第一列是勾选列,设置列头文本为空 lvi.Text = ""; WaitList.Add(dt.Rows[i]["bc_code"].ToString()); for (int j = 0; j < dt.Columns.Count; j++) lvi.SubItems.Add(dt.Rows[i][j].ToString()); WaitRejectList.Items.Add(lvi); } } WaitRejectList.EndUpdate(); } private void SN_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { DataTable dt = (DataTable)dh.ExecuteSql("select ms_sncode,ms_makecode,ms_id,ma_prodcode,pr_detail from makeserial left join make on ms_makecode=ma_code left join product on pr_code=ma_prodcode where ms_sncode='" + SN.Text + "' or ms_imei1='" + SN.Text + "' or ms_imei2='" + SN.Text + "' order by ms_id desc", "select"); if (dt.Rows.Count == 0) { OperateResult.AppendText("序列号" + SN.Text + "不存在", System.Drawing.Color.Red); return; } BaseUtil.SetFormValue(this.Controls, dt); string ms_id = dt.Rows[0]["ms_id"].ToString(); SN.Text = dt.Rows[0]["ms_sncode"].ToString(); if (OK.Checked) { dh.ExecuteSql("update makeserial set ms_iftest=-1 where ms_id=" + ms_id, "update"); LogicHandler.DoCommandLog(Tag.ToString(), User.UserName, ms_makecode.Text, User.UserLineCode, User.UserSourceCode, "QC抽检", "QC抽检成功,结果为良品", SN.Text, ""); } else { int CheckedNum = 0; //是否已经添加到不良 bool AddToReject = false; for (int i = WaitRejectList.Items.Count - 1; i >= 0; i--) { if (WaitRejectList.Items[i].Checked) { AddToReject = false; for (int j = 0; j < ChoosedRejectList.Items.Count; j++) { if ((ChoosedRejectList.Items[j].SubItems[2].Text == WaitRejectList.Items[i].SubItems[2].Text)) { AddToReject = true; OperateResult.AppendText(">>已存在" + ChoosedRejectList.Items[j].SubItems[2].Text + "不良\n", Color.Red); break; } } //未添加则进行添加 if (!AddToReject) { WaitRejectList.Items[i].Checked = false; ChoosedRejectList.Items.Add((ListViewItem)WaitRejectList.Items[i].Clone()); WaitRejectList.Items[i].Remove(); CheckedNum++; } } } if (CheckedNum == 0) { OperateResult.AppendText(">>请勾选不良代码\n", Color.Red); return; } dh.ExecuteSql("update makeserial set ms_status=3,ms_nextstepcode='' ,ms_iftest=-1 where ms_id=" + ms_id, "update"); LogicHandler.DoCommandLog(Tag.ToString(), User.UserName, ms_makecode.Text, User.UserLineCode, User.UserSourceCode, "QC抽检", "QC抽检成功,结果为不良", SN.Text, ""); } OperateResult.AppendText("序列号" + SN.Text + "抽检记录成功", System.Drawing.Color.Green); } } private void ChooseedReject_Click(object sender, EventArgs e) { if (SN.Text == "") { OperateResult.AppendText(">>序列号不能为空\n", Color.Red); SN.Focus(); return; } int CheckedNum = 0; //是否已经添加到不良 bool AddToReject = false; for (int i = WaitRejectList.Items.Count - 1; i >= 0; i--) { if (WaitRejectList.Items[i].Checked) { AddToReject = false; for (int j = 0; j < ChoosedRejectList.Items.Count; j++) { if ((ChoosedRejectList.Items[j].SubItems[2].Text == WaitRejectList.Items[i].SubItems[2].Text)) { AddToReject = true; OperateResult.AppendText(">>已存在" + ChoosedRejectList.Items[j].SubItems[2].Text + "不良\n", Color.Red); break; } } //未添加则进行添加 if (!AddToReject) { WaitRejectList.Items[i].Checked = false; ChoosedRejectList.Items.Add((ListViewItem)WaitRejectList.Items[i].Clone()); WaitRejectList.Items[i].Remove(); CheckedNum++; } } } if (CheckedNum == 0) { OperateResult.AppendText(">>请勾选不良代码\n", Color.Red); } } private void WaitReject_Click(object sender, EventArgs e) { int CheckedNum = 0; //已存在在ListView中的Item是不能添加到其他ListView中的,需要调用其克隆的方法 for (int i = ChoosedRejectList.Items.Count - 1; i >= 0; i--) { if (ChoosedRejectList.Items[i].Checked) { ChoosedRejectList.Items[i].Checked = false; WaitRejectList.Items.Add((ListViewItem)ChoosedRejectList.Items[i].Clone()); ChoosedRejectList.Items[i].Remove(); CheckedNum++; } } if (CheckedNum == 0) { for (int i = ChoosedRejectList.Items.Count - 1; i >= 0; i--) { WaitRejectList.Items.Add((ListViewItem)ChoosedRejectList.Items[i].Clone()); ChoosedRejectList.Items[i].Remove(); } } } private void bc_groupcode_SelectedIndexChanged(object sender, EventArgs e) { LoadBadCodeListView(); } private void ma_prodcode_TextChanged(object sender, EventArgs e) { LoadBadGroupData(); } private void SaveRepairInf_Click(object sender, EventArgs e) { if (NG.Checked) { DataTable dt = (DataTable)dh.ExecuteSql("select ms_sncode,ms_makecode,ms_id,ma_prodcode,pr_detail from makeserial left join make on ms_makecode=ma_code left join product on pr_code=ma_prodcode where ms_sncode='" + SN.Text + "' or ms_imei1='" + SN.Text + "' or ms_imei2='" + SN.Text + "' order by ms_id desc", "select"); if (dt.Rows.Count == 0) { OperateResult.AppendText("序列号" + SN.Text + "不存在", System.Drawing.Color.Red); return; } BaseUtil.SetFormValue(this.Controls, dt); string ms_id = dt.Rows[0]["ms_id"].ToString(); int RejectCount = ChoosedRejectList.Items.Count; string[] bccode = new string[RejectCount]; string[] bcremark = new string[RejectCount]; string[] bgcode = new string[RejectCount]; string[] bgname = new string[RejectCount]; string[] bcname = new string[RejectCount]; if (ChoosedRejectList.Items.Count == 0) { OperateResult.AppendText(">>不良品必须选择不良原因和不良代码!\n", Color.Red); return; } else { for (int i = 0; i < RejectCount; i++) { //获取不良代码组 bgcode[i] = ChoosedRejectList.Items[i].SubItems[1].Text.Split(':')[0]; //获取不良代码组名称 bgname[i] = ChoosedRejectList.Items[i].SubItems[1].Text.Split(':')[1]; //获取所有的不良代码 bccode[i] = ChoosedRejectList.Items[i].SubItems[2].Text; //获取不良名称 bcname[i] = ChoosedRejectList.Items[i].SubItems[3].Text; //获取所有的不良备注 bcremark[i] = bc_remark.Text; } } sql.Clear(); sql.Append("insert into makebad(mb_id,mb_makecode,mb_mscode,mb_sncode,mb_inman,mb_indate,mb_stepcode"); sql.Append(",mb_sourcecode,mb_badcode,mb_bgcode,mb_badtable,mb_status,mb_badremark,mb_bgname,mb_badname,mb_type)"); sql.Append("select makebad_seq.nextval,ma_code,ms_code,ms_sncode,'" + User.UserCode + "',sysdate,'" + User.CurrentStepCode + "','" + User.UserSourceCode + "',:bc_code,:bg_code,'',"); sql.Append("'0',:bc_remark,:bg_name,:bc_name,'Client' from make left join makeSerial on ms_makecode=ma_code "); sql.Append(" where ms_sncode='" + SN.Text + "' or ms_imei1='" + SN.Text + "' or ms_imei2='" + SN.Text + "' and ms_makecode='" + ms_makecode.Text + "'"); if (bgcode.Length > 0) { dh.BatchInsert(sql.GetString(), new string[] { "bc_code", "bg_code", "bc_remark", "bg_name", "bc_name" }, bccode, bgcode, bcremark, bgname, bcname); } dh.ExecuteSql("update makeserial set ms_status=3,ms_nextstepcode='' ,ms_iftest=-1 where ms_id=" + ms_id, "update"); LogicHandler.DoCommandLog(Tag.ToString(), User.UserName, ms_makecode.Text, User.UserLineCode, User.UserSourceCode, "QC抽检", "QC抽检成功,结果为不良", SN.Text, ""); OperateResult.AppendText("序列号" + SN.Text + "抽检记录成功", System.Drawing.Color.Green); } } } }