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.Make { public partial class Make_SingleBoard : Form { DataHelper dh; LogStringBuilder sql = new LogStringBuilder(); DataTable Dbfind; /// /// 已选的不良 /// List ChoosedList = new List(); /// /// 待选的不良 /// List WaitList = new List(); public Make_SingleBoard() { InitializeComponent(); } private void Special_BoxSplit_Load(object sender, EventArgs e) { ma_code.TableName = "make left join product on ma_prodcode=pr_code"; ma_code.SelectField = "ma_code # 工单号,ma_pocode # 内部订单号,ma_prodcode # 产品编号,ma_qty # 工单数量,pr_spec # 产品规格,ma_softversion # 软件版本,ma_salecode # 销售单号,pr_sendchecktype # 产品送检方式"; ma_code.FormName = Name; ma_code.SetValueField = new string[] { "ma_code", "ma_pocode", "ma_prodcode", "ma_qty", "substr(pr_spec,0,50)pr_spec", "ma_softversion", "ma_salecode", "nvl(pr_sendchecktype,'LineCode')pr_sendchecktype" }; ma_code.Condition = "ma_statuscode='STARTED'"; ma_code.DbChange += Ma_code_DbChange; dh = SystemInf.dh; LockMakeCode.GetMakeCodeCtl(ma_code); ma_code.SetLockCheckBox(LockMakeCode); } private void Ma_code_DbChange(object sender, EventArgs e) { Dbfind = ma_code.ReturnData; BaseUtil.SetFormValue(this.Controls, Dbfind); LoadBadGroupData(); } 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 ma_prodcode,sp_fsoncode,pr_oldcode from make left join stepbom on ma_bomversion=sb_bomversion " + "left join stepproduct on sp_sbid=sb_id left join product on pr_code=ma_prodcode where ma_code='" + ma_code.Text + "'", "select"); bool checksn = false; for (int i = 0; i < dt.Rows.Count; i++) { string sp_fsoncode = dt.Rows[i]["sp_fsoncode"].ToString(); string pr_oldcode = dt.Rows[i]["pr_oldcode"].ToString(); string ma_prodcode = dt.Rows[i]["ma_prodcode"].ToString(); if (SN.Text.Contains(dt.Rows[i]["ma_prodcode"].ToString()) || (pr_oldcode != "" && SN.Text.Contains(dt.Rows[i]["pr_oldcode"].ToString()))) { checksn = true; } } if (!User.CurrentStepCode.Contains("单板上料")) { OperateResult.AppendText(">>单板上料界面,请登录【单板上料】资源\n", Color.Red, SN); return; } if (!checksn) { OperateResult.AppendText(">>" + SN.Text + "不在用料表中,不允许扫描\n", Color.Red, SN); return; } if (User.CurrentStepCode == "单板上料") { if (dh.CheckExist("singleboard", "sb_sncode='" + SN.Text + "'")) { OperateResult.AppendText(">>" + SN.Text + "已执行单板上料\n", Color.Red, SN); return; } else { dh.ExecuteSql("insert into singleboard(SB_ID, SB_MAKECODE, SB_SNCODE, SB_INDATE, SB_NEXTSTEPCODE, SB_BADTIMS, SB_STATUS,sb_stepcode)" + "values(singleboard_seq.nextval,'" + ma_code.Text + "','" + SN.Text + "',sysdate,'单板测试',0,'1','单板上料')", "insert"); } } //if (User.CurrentStepCode == "刷三防漆") //{ // dt = (DataTable)dh.ExecuteSql("select SB_NEXTSTEPCODE,sb_status from singleboard where sb_sncode='" + SN.Text + "'", "select"); // if (dt.Rows.Count > 0) // { // string SB_NEXTSTEPCODE = dt.Rows[0]["SB_NEXTSTEPCODE"].ToString(); // string sb_status = dt.Rows[0]["sb_status"].ToString(); // if (sb_status == "3") // { // OperateResult.AppendText(">>" + SN.Text + "测试不良不允许采集,请先进行维修\n", Color.Red); // return; // } // if (SB_NEXTSTEPCODE == User.CurrentStepCode) // { // dh.ExecuteSql("update singleboard set sb_status=2,sb_nextstepcode='' where sb_sncode='" + SN.Text + "'", "update"); ; // } // } //} if (OK.Checked) { LogicHandler.DoCommandLog(Tag.ToString(), User.UserName, ma_code.Text, User.UserLineCode, User.UserSourceCode, User.CurrentStepCode, User.CurrentStepCode + "结果为良品", 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; } LogicHandler.DoCommandLog(Tag.ToString(), User.UserName, ma_code.Text, User.UserLineCode, User.UserSourceCode, User.CurrentStepCode, User.CurrentStepCode + "结果为良品", SN.Text, ""); } OperateResult.AppendText("序列号" + SN.Text + User.CurrentStepCode + "采集成功\n", System.Drawing.Color.Green, SN); } } 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 (User.CurrentStepCode == "单板测试") { if (dh.CheckExist("singleboard", "sb_sncode='" + SN.Text + "'")) { if (OK.Checked) { OperateResult.AppendText(">>" + SN.Text + "已执行单板测试\n", Color.Red, SN); return; } } else { dh.ExecuteSql("insert into singleboard(SB_ID, SB_MAKECODE, SB_SNCODE, SB_INDATE, SB_NEXTSTEPCODE, SB_BADTIMS, SB_STATUS)" + "values(singleboard_seq.nextval,'" + ma_code.Text + "','" + SN.Text + "',sysdate,'刷三防漆',0,'1')", "insert"); } } DataTable dt = (DataTable)dh.ExecuteSql("select SB_NEXTSTEPCODE,sb_status from singleboard where sb_sncode='" + SN.Text + "'", "select"); if (dt.Rows.Count > 0) { string SB_NEXTSTEPCODE = dt.Rows[0]["SB_NEXTSTEPCODE"].ToString(); string sb_status = dt.Rows[0]["sb_status"].ToString(); if (sb_status == "3") { OperateResult.AppendText(">>" + SN.Text + "已经采集不良,不允许重复采集\n", Color.Red, SN); return; } } if (NG.Checked) { 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,sb_sncode,sb_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 singleboard on sb_makecode=ma_code "); sql.Append(" where sb_sncode='" + SN.Text + "' and sb_makecode='" + ma_code.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 singleboard set sb_status=3,SB_BADTIMS=nvl(SB_BADTIMS,0)+1,sb_nextstepcode='',sb_stepcode='" + User.CurrentStepCode + "' where sb_sncode='" + SN.Text + "'", "update"); LogicHandler.DoCommandLog(Tag.ToString(), User.UserName, ma_code.Text, User.UserLineCode, User.UserSourceCode, User.CurrentStepCode, User.CurrentStepCode + "结果不良品", SN.Text, ""); OperateResult.AppendText("序列号" + SN.Text + "采集不良成功\n", System.Drawing.Color.Green, SN); } } } }