123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888 |
- using System;
- using System.Data;
- using System.Text;
- using System.Threading;
- using System.Drawing;
- using System.Windows.Forms;
- using UAS_MES_NEW.DataOperate;
- using UAS_MES_NEW.Entity;
- using UAS_MES_NEW.PublicMethod;
- using System.Collections.Generic;
- using UAS_MES_NEW.CustomControl.PowerControlForm;
- using Seagull.BarTender.Print;
- namespace UAS_MES_NEW.Make
- {
- public partial class Make_TestCollectionOnlyBad : Form
- {
- DataHelper dh = null;
- DataTable dt = null;
- //当前工序的名称
- string ErrorMessage = "";
- //用于保存是否之前输入的ms_sncode
- string LastSncode;
- string oMakeCode = "";
- string oMSID = "";
- string ifrework = "";
- string reworkstatus = "";
- LogStringBuilder sql = new LogStringBuilder();
- AutoSizeFormClass asc = new AutoSizeFormClass();
- /// <summary>
- /// 已选的不良
- /// </summary>
- List<string> ChoosedList = new List<string>();
- /// <summary>
- /// 待选的不良
- /// </summary>
- List<string> WaitList = new List<string>();
- bool AutoCut = false;
- bool LockSn = false;
- DataTable Dbfind;
- LabelFormatDocument format;
- Engine engine;
- bool EnablePrint;
- public Make_TestCollectionOnlyBad()
- {
- InitializeComponent();
- }
- private void TestCollection_Load(object sender, EventArgs e)
- {
-
- asc.controllInitializeSize(this);
- ms_sncode.Focus();
- //设置锁定工单
- LockMakeCode.GetMakeCodeCtl(ma_code);
- ma_code.SetLockCheckBox(LockMakeCode);
- ControlLockTimer.Tick += ControlLockTimer_Tick;
- ControlLockTimer.Interval = 100;
- //工单号放大镜配置
- 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;
- StepCount.StepCode = User.CurrentStepCode;
- StepCount.Source = User.UserSourceCode;
- StepCount.LineCode = User.UserLineCode;
- StepCount.Dh = dh;
- StepCount.Start();
- if (BaseUtil.CheckBarTenderEnable())
- {
- OperateResult.AppendText("已安装BarTender\n");
- try
- {
- engine = new Engine();
- engine.Start();
- format = engine.Documents.Open(Application.StartupPath + "/BadCode.btw");
- EnablePrint = true;
- }
- catch (Exception)
- {
- EnablePrint = false;
- OperateResult.AppendText("未正确安装BarTender");
- }
- }
- else
- {
- EnablePrint = false;
- OperateResult.AppendText("未正确安装BarTender");
- }
- }
- private void ControlLockTimer_Tick(object sender, EventArgs e)
- {
- this.Activate();
- ms_sncode.Focus();
- }
- private void Ma_code_DbChange(object sender, EventArgs e)
- {
- Dbfind = ma_code.ReturnData;
- BaseUtil.SetFormValue(this.Controls, Dbfind);
- LoadBadGroupData();
- LoadCollectedNum();
- LoadCheckQTY();
- }
- /// <summary>
- /// 将已选不良移动到待选不良
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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();
- }
- }
- }
- /// <summary>
- /// 将不良信息移动到已选不良
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void ChooseedReject_Click(object sender, EventArgs e)
- {
- if (ms_sncode.Text == "")
- {
- OperateResult.AppendText(">>序列号不能为空\n", Color.Red);
- ms_sncode.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 CleanInfo_Click(object sender, EventArgs e)
- {
- OperateResult.Clear();
- }
- private void ms_code_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- {
- ChoosedRejectList.Items.Clear();
- WaitList.Clear();
- ChoosedList.Clear();
- if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
- {
- bool NoteAlready = LogicHandler.CheckDiffMakeCodeBeforeStepCheck(ms_sncode.Text, ma_code.Text, NoteForChange.Checked, out oMakeCode, out ErrorMessage);
- if (!NoteAlready)
- {
- OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
- return;
- }
- if (LogicHandler.CheckStepSNAndMacode(oMakeCode, User.UserSourceCode, ms_sncode.Text, User.UserCode, out oMakeCode, out oMSID, out ErrorMessage))
- {
- //是否提示过工单切换框,检测前后执行
- if (!LogicHandler.CheckDiffMakeCodeAfterStepCheck(ms_sncode.Text, oMakeCode, NoteForChange.Checked, NoteAlready, ma_code, out ErrorMessage))
- {
- OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
- return;
- }
- if (ma_code.Text != oMakeCode && oMakeCode != null)
- {
- dt = (DataTable)dh.ExecuteSql("select ma_code,ma_prodcode,nvl(ma_softversion,ms_softversion)ma_softversion,ma_salecode,substr(pr_spec,0,50)pr_spec,nvl(pr_sendchecktype,'LineCode')pr_sendchecktype,ma_qty from makeserial left join make on ma_code=ms_makecode left join product on ma_prodcode=pr_code where ma_code='" + oMakeCode + "' and ms_sncode='" + ms_sncode.Text + "'", "select");
- if (dt.Rows.Count > 0)
- {
- BaseUtil.SetFormValue(this.Controls, dt);
- LockMakeCode.Checked = true;
- }
- }
- dt = (DataTable)dh.ExecuteSql("select ms_nextstepcode,ms_sncode,ms_reworkstatus,nvl(ms_ifrework,0)ms_ifrework,ms_stepcode,ms_status,nvl(st_ifrepair,0) st_ifrepair from makeserial left join step on ms_stepcode=st_code where ms_id='" + oMSID + "'", "select");
- string status = dt.Rows[0]["ms_status"].ToString();
- reworkstatus = dt.Rows[0]["ms_reworkstatus"].ToString();
- string stepcode = dt.Rows[0]["ms_stepcode"].ToString();
- string ifrepair = dt.Rows[0]["st_ifrepair"].ToString();
- string sncode = dt.Rows[0]["ms_sncode"].ToString();
- if (sncode != ms_sncode.Text)
- {
- OperateResult.AppendText(">>" + ms_sncode.Text + " 序列号已执行过转号,不允许使用TSN采集\n", Color.Red, ms_sncode);
- return;
- }
- ifrework = dt.Rows[0]["ms_ifrework"].ToString();
- if (GoodProduct.Checked)
- {
- if (ifrework != "0")
- {
- if (stepcode == User.CurrentStepCode && (reworkstatus == "1" || reworkstatus == "2") && ifrepair == "0")
- {
- OperateResult.AppendText(">>" + ms_sncode.Text + " 序列号已执行过" + User.CurrentStepName + "工序,采集结果为良品\n", Color.Red, ms_sncode);
- return;
- }
- }
- else
- {
- if (stepcode == User.CurrentStepCode && (status == "1" || status == "2") && ifrepair == "0")
- {
- OperateResult.AppendText(">>" + ms_sncode.Text + " 序列号已执行过" + User.CurrentStepName + "工序,采集结果为良品\n", Color.Red, ms_sncode);
- return;
- }
- }
- }
- SetCollectResult();
- }
- else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
- }
- else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
- }
- }
- private void bc_groupcode_SelectedIndexChanged(object sender, EventArgs e)
- {
- LoadBadCodeListView();
- }
- /// <summary>
- /// 填充不良组别信息
- /// </summary>
- 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;
- }
- /// <summary>
- /// 加载不良代码的ListView的信息
- /// </summary>
- 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();
- }
- /// <summary>
- /// 加载已选不良的ListView
- /// </summary>
- private void LoadChoosedBadListView()
- {
- sql.Clear();
- sql.Append("select nvl(bg_code,mb_bgcode)||':'||nvl(bg_name,mb_badcode) bg_code,nvl(mb_badcode,bc_code) bc_code,bc_name,mb_badremark from makebad ");
- sql.Append("left join badgroup on mb_bgcode=bg_code left join badcode on mb_badcode=bc_code ");
- sql.Append(" where mb_sncode='" + ms_sncode.Text + "' and mb_makecode='" + ma_code.Text + "' and mb_status=0");
- dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- ChoosedRejectList.Items.Clear();
- ChoosedRejectList.BeginUpdate();
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- ListViewItem lvi = new ListViewItem();
- //第一列是勾选列,设置列头文本为空
- lvi.Text = "";
- ChoosedList.Add(dt.Rows[i]["bc_code"].ToString());
- for (int j = 0; j < dt.Columns.Count; j++)
- lvi.SubItems.Add(dt.Rows[i][j].ToString());
- ChoosedRejectList.Items.Add(lvi);
- }
- ChoosedRejectList.EndUpdate();
- }
- /// <summary>
- /// 设置良品或者不良品的采集结果
- /// </summary>
- private void SetCollectResult()
- {
- string ErrorMessage = "";
- //如果勾选的是不良品
- if (Reject.Checked)
- {
- LoadBadCodeListView();
- LoadChoosedBadListView();
- OperateResult.AppendText(">>请采集不良代码\n", Color.Green);
- bc_code.Focus();
- }
- else if (GoodProduct.Checked)
- {
- //如果不是返修的
- if (ifrework == "0")
- {
- dt = (DataTable)dh.ExecuteSql("select mb_id,bc_name,mbr_mbid from makebad left join makebadreason on mbr_mbid=mb_id left join badcode on mb_badcode=bc_code where mb_sncode='" + ms_sncode.Text + "' and mb_makecode='" + ma_code.Text + "' and mb_status=0", "select");
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- if (dt.Rows[i]["mb_id"].ToString() != dt.Rows[i]["mbr_mbid"].ToString())
- ErrorMessage += "【" + dt.Rows[i]["bc_name"].ToString() + "】";
- }
- //存在不良记录
- if (ErrorMessage != "")
- {
- OperateResult.AppendText(">>序列号:" + ms_sncode.Text + " 已经判为不良品,不允许修改!\n", Color.Red);
- return;
- }
- else
- {
- //良品信息采集
- if (LogicHandler.SetStepResult(ma_code.Text, User.UserSourceCode, ms_sncode.Text, "良品采集", "检测合格", User.UserCode, out ErrorMessage))
- {
- if (IfTest.Checked)
- {
- dh.ExecuteSql("update makeserial set ms_iftest=-1 where ms_id='" + oMSID + "'", "update");
- }
- //提示正确返回时传递的信息
- if (ErrorMessage.Contains("AFTERSUCCESS"))
- OperateResult.AppendText(">>" + ErrorMessage + "\n");
- LastSncode = ms_sncode.Text;
- OperateResult.AppendText(">>" + ms_sncode.Text + "良品采集成功\n", Color.Green, ms_sncode);
- //恢复出厂设置
- //记录操作日志
- LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "采集良品", "采集良品成功", LastSncode, ob_checkno.Text);
- }
- else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
- }
- }
- else
- {
- if (reworkstatus != "3")
- {
- if (LogicHandler.SetStepResult(ma_code.Text, User.UserSourceCode, ms_sncode.Text, "良品采集", "检测合格", User.UserCode, out ErrorMessage))
- {
- //提示正确返回时传递的信息
- if (ErrorMessage.Contains("AFTERSUCCESS"))
- OperateResult.AppendText(">>" + ErrorMessage + "\n");
- LastSncode = ms_sncode.Text;
- OperateResult.AppendText(">>" + ms_sncode.Text + "成功采集为良品\n", Color.Green, ms_sncode);
- //记录操作日志
- LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "采集良品", "采集良品成功", LastSncode, ob_checkno.Text);
- }
- else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
- }
- else
- {
- OperateResult.AppendText(">>返修的不良序列号必须先进行维修\n", Color.Red);
- }
- }
- }
- //加载页面信息
- LoadCollectedNum();
- LoadCheckQTY();
- }
- private void 测试采集_SizeChanged(object sender, EventArgs e)
- {
- asc.controlAutoSize(this);
- }
- private void LoadCollectedNum()
- {
- dt = (DataTable)dh.ExecuteSql("select mcd_inqty,ma_qty-mcd_inqty mcd_remainqty,mcd_ngqty,mcd_okqty,mcd_totalng from make left join makecraftdetail_view on mcd_macode=ma_code where ma_code='" + ma_code.Text + "' and mcd_stepcode='" + User.CurrentStepCode + "'", "select");
- BaseUtil.SetFormValue(Controls, dt);
- }
- //重新打印的不良代码
- List<String> RePrintCode = new List<string>();
- private void Save_Click(object sender, EventArgs e)
- {
- if (ms_sncode.Text == "")
- {
- OperateResult.AppendText(">>序列号不允许为空\n", Color.Red);
- return;
- }
- if (GoodProduct.Checked)
- ms_code_KeyDown(sender, new KeyEventArgs(Keys.Enter));
- else if (Reject.Checked)
- {
- if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
- {
- //判断界面工单是否为空时的序列号是否自动归属工单
- string oStatus = "";
- if (!LogicHandler.GetMakeInfo(ms_sncode.Text, out oMakeCode, out oStatus, out ErrorMessage))
- {
- if (ma_code.Text == "")
- {
- OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
- return;
- }
- }
- if (LogicHandler.CheckStepSNAndMacode(ma_code.Text == "" ? oMakeCode : ma_code.Text, User.UserSourceCode, ms_sncode.Text, User.UserCode, out oMakeCode, out oMSID, out ErrorMessage))
- {
- dt = (DataTable)dh.ExecuteSql("select ma_code,ma_prodcode,nvl(ma_softversion,ms_softversion)ma_softversion,substr(pr_spec,0,50)pr_spec,ma_qty from makeserial left join make on ms_makecode=ma_code left join product on ma_prodcode=pr_code where ms_id='" + oMSID + "'", "select");
- if (dt.Rows.Count > 0)
- {
- BaseUtil.SetFormValue(this.Controls, dt);
- LockMakeCode.Checked = true;
- }
- }
- else
- {
- OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
- return;
- }
- }
- else
- {
- OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
- return;
- }
- 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;
- }
- }
- string ms_outboxcode = dh.getFieldDataByCondition("makeserial", "ms_outboxcode", "ms_id='" + oMSID + "'").ToString();
- if (ms_outboxcode != "")
- {
- OperateResult.AppendText(">>" + ms_sncode.Text + "已装箱" + ms_outboxcode + ",请先取消装箱\n", Color.Green);
- return;
- }
- //如果之前是良品的
- dt = dh.getFieldsDataByCondition("makeserial", new string[] { "ms_status", "ms_checkno", "ms_outboxcode" }, "ms_id='" + oMSID + "' and ms_stepcode='" + User.CurrentStepCode + "'");
- if (dt.Rows.Count > 0)
- {
- string status = dt.Rows[0]["ms_status"].ToString();
- ms_outboxcode = dt.Rows[0]["ms_outboxcode"].ToString();
- if (ms_outboxcode != "")
- {
- OperateResult.AppendText(">>" + ms_sncode.Text + "已装箱" + ms_outboxcode + ",请先取消装箱\n", Color.Green);
- return;
- }
- if (status == "1" || status == "2")
- {
- dh.UpdateByCondition("steppassed", "sp_result='不良品',sp_ifng=-1,sp_ymd=to_char(sysdate,'yyyymmdd'),sp_hm=to_char(sysdate,'hh24miss')", "sp_id=(select max(sp_id) from steppassed where sp_sncode='" + ms_sncode.Text + "')");
- dh.UpdateByCondition("makecraftdetail", "mcd_okqty=mcd_okqty-1", "mcd_macode='" + ma_code.Text + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
- dh.UpdateByCondition("makeserial", "ms_nextstepcode='',ms_badtimes=nvl(ms_badtimes,0)+1", "ms_id='" + oMSID + "'");
- LogicHandler.InsertMakeProcess(ms_sncode.Text, ma_code.Text, User.UserSourceCode, "良品采集成不良", "测试不良", User.UserCode);
- LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "测试不良", "良品采集成不良", ms_sncode.Text, ob_checkno.Text);
- }
- string checkno = dt.Rows[0]["ms_checkno"].ToString();
- //存在抽检批次更新为空
- if (checkno != "")
- dh.UpdateByCondition("makeserial", "ms_checkno=''", "ms_id='" + oMSID + "'");
- }
- else
- {
- LogicHandler.InsertMakeProcess(ms_sncode.Text, ma_code.Text, User.UserSourceCode, "采集成不良", "测试不良", User.UserCode);
- LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "采集成不良", "测试不良", ms_sncode.Text, ob_checkno.Text);
- }
- //不良信息采集,mb_status<>0的是之前维修保存的,不能删除
- dh.ExecuteSql("delete from makebad where mb_sncode='" + ms_sncode.Text + "' and mb_makecode='" + ma_code.Text + "' and nvl(mb_status,0)=0", "delete");
- if (LogicHandler.SetTestNGDetail(ms_sncode.Text, ma_code.Text, User.UserCode, User.UserSourceCode, "检查未通过", bgcode, bccode, bgname, bcname, bcremark, out ErrorMessage))
- {
- //存在的不良代码和
- dt = (DataTable)dh.ExecuteSql("select sr_badcode from STEPRETURN where sr_stepcode='" + User.CurrentStepCode + "'", "select");
- if (dt.Rows.Count > 0)
- {
- int BadCodeInStep = 0;
- string badname = "";
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- for (int j = 0; j < bccode.Length; j++)
- {
- if (dt.Rows[i]["sr_badcode"].ToString() == bccode[j])
- {
- badname += "[" + bcname[j] + "]";
- BadCodeInStep += 1;
- }
- }
- }
- //选中的不良代码必须全在工序默认的不良代码中才通过判断
- if (BadCodeInStep == bccode.Length)
- {
- dh.UpdateByCondition("makebad", "mb_status=-1", "mb_sncode='" + ms_sncode.Text + "' and mb_makecode='" + ma_code.Text + "' and mb_stepcode='" + User.CurrentStepCode + "'");
- dh.UpdateByCondition("makeserial", "ms_stepcode='',ms_status=1,ms_nextstepcode='" + User.CurrentStepCode + "'", "ms_id='" + oMSID + "'");
- LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "快速维修成功", "快速维修", "", ob_checkno.Text);
- OperateResult.AppendText(">>本次采集不良代码" + badname + "存在于本工序" + User.CurrentStepCode + "中,请解除故障后重新测试本站\n", Color.Black);
- }
- else OperateResult.AppendText(">>" + ms_sncode.Text + "成功采集为不良\n", Color.Green);
- }
- else OperateResult.AppendText(">>" + ms_sncode.Text + "成功采集为不良\n", Color.Green);
- if (IfTest.Checked)
- {
- dh.ExecuteSql("update makeserial set ms_iftest=-1 where ms_id='" + oMSID + "'", "update");
- }
- //打印不良代码贴纸
- if (EnablePrint && AutoPrintBad.Checked)
- {
- RePrintCode.Clear();
- for (int i = 0; i < bcname.Length; i++)
- {
- RePrintCode.Add(bcname[i]);
- format.SubStrings["SN1"].Value = bcname[i];
- format.PrintSetup.PrinterName = Printer.Text;
- format.PrintSetup.IdenticalCopiesOfLabel = 1;
- format.Print();
- }
- }
- LastSncode = ms_sncode.Text;
- //采集完不良,聚焦序列号
- ms_sncode.Focus();
- //记录操作日志
- ms_sncode.Text = "";
- //清除不良信息
- bc_code.Text = "";
- ChoosedRejectList.Items.Clear();
- LoadCollectedNum();
- WaitList.Clear();
- ChoosedList.Clear();
- }
- else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
- }
- }
- private void bc_code_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- {
- sql.Clear();
- sql.Append("select bg_code||':'||bg_name bg_code,bc_code,bc_name,'' bc_remark from badgroupdetail left join ");
- sql.Append("badgroup on bg_id=bgd_bgid left join badcode on bgd_badcode = bc_code where bc_code='" + bc_code.Text + "' and rownum=1 ");
- DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- if (dt.Rows.Count > 0)
- {
- for (int i = 0; i < ChoosedRejectList.Items.Count; i++)
- {
- if (ChoosedRejectList.Items[i].ListView.Items[i].SubItems[2].Text == bc_code.Text)
- {
- OperateResult.AppendText(">>已添加过不良代码" + bc_code.Text + "\n", Color.Red, bc_code);
- return;
- }
- }
- ListViewItem lvi = new ListViewItem();
- lvi.Text = "";
- for (int j = 0; j < dt.Columns.Count; j++)
- lvi.SubItems.Add(dt.Rows[0][j].ToString());
- ChoosedRejectList.Items.Add(lvi);
- bc_code.Clear();
- }
- else OperateResult.AppendText(">>" + bc_code.Text + "不良代码不存在\n", Color.Red, bc_code);
- }
- }
- private void LoadCheckQTY()
- {
- sql.Clear();
- string condition = "";
- int nowcheckqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text);
- int batchqty = int.Parse(ob_batchqty.Text == "" ? "0" : ob_batchqty.Text);
- if (nowcheckqty + 1 == batchqty && AutoCut)
- {
- condition = "and ob_status='UNCHECK' and ob_checkno='" + ob_checkno.Text + "'";
- }
- else
- {
- condition = "and ob_status='ENTERING' ";
- }
- if (pr_sendchecktype.Text == "SaleCode")
- {
- condition += " and ob_salecode='" + ma_salecode.Text + "'";
- }
- sql.Append("select ob_batchqty,ob_nowcheckqty,ob_checkno from oqcbatch where ");
- sql.Append("ob_linecode='" + User.UserLineCode + "' and ob_prodcode='" + ma_prodcode.Text + "' and ");
- sql.Append("ob_stepcode='" + User.CurrentStepCode + "' " + condition);
- DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- if (dt.Rows.Count > 0)
- {
- ob_sendqty.Text = dh.getFieldDataByCondition("oqcbatch", "sum(ob_nowcheckqty)", "ob_makecode='" + ma_code.Text + "' and ob_status<>'ENTERING'").ToString();
- ob_batchqty.Text = dt.Rows[0]["ob_batchqty"].ToString();
- ob_nowcheckqty.Text = dt.Rows[0]["ob_nowcheckqty"].ToString();
- ob_checkno.Text = dt.Rows[0]["ob_checkno"].ToString();
- nowcheckqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text);
- batchqty = int.Parse(ob_batchqty.Text == "" ? "0" : ob_batchqty.Text);
- if (nowcheckqty == batchqty)
- {
- ob_nowcheckqty.ForeColor = Color.Red;
- OperateResult.AppendText(">>当前采集数量已达到送检数量\n", Color.Red);
- if (AutoCut)
- {
- OperateResult.AppendText(">>批次" + ob_checkno.Text + "自动断批\n", Color.Blue);
- }
- }
- }
- else
- {
- BaseUtil.CleanControlsText(ob_batchqty, ob_nowcheckqty, ob_checkno);
- SendCheck.Enabled = false;
- }
- if (ob_batchqty.Text != "")
- {
- SendCheck.Enabled = true;
- }
- else
- {
- SendCheck.Enabled = false;
- }
- }
- private void GoodProduct_CheckedChanged(object sender, EventArgs e)
- {
- if (GoodProduct.Checked)
- {
- bc_code.Enabled = false;
- WaitReject.Enabled = false;
- ChooseedReject.Enabled = false;
- Save.Visible = false;
- ReleaseSN.Enabled = false;
- }
- else
- {
- ReleaseSN.Enabled = true;
- bc_code.Enabled = true;
- WaitReject.Enabled = true;
- ChooseedReject.Enabled = true;
- Save.Visible = true;
- }
- if (ms_sncode.Text == "")
- {
- ms_sncode.Focus();
- }
- }
- private void SendCheck_Click(object sender, EventArgs e)
- {
- sql.Clear();
- sql.Append("update oqcbatch set ob_status='UNCHECK' where ob_checkno ='" + ob_checkno.Text + "'");
- dh.ExecuteSql(sql.GetString(), "select");
- ob_sendqty.Text = dh.getFieldDataByCondition("oqcbatch", "sum(ob_nowcheckqty)", "ob_makecode='" + ma_code.Text + "' and ob_status<>'ENTERING'").ToString();
- ob_nowcheckqty.Text = "";
- ob_batchqty.Text = "";
- ob_nowcheckqty.ForeColor = Color.Black;
- SendCheck.Enabled = false;
- OperateResult.AppendText(">>批次" + ob_checkno.Text + "送检成功\n", Color.Blue);
- ms_sncode.Focus();
- LogicHandler.InsertMakeProcess(LastSncode, ma_code.Text, User.UserSourceCode, "手动送检", "手动送检成功", User.UserCode);
- //记录操作日志
- LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "手动送检", "手动送检成功", "", ob_checkno.Text);
- ob_checkno.Text = "";
- }
- private void ob_checkno_TextChanged(object sender, EventArgs e)
- {
- if (ob_checkno.Text != "")
- {
- string Cut = dh.getFieldDataByCondition("product left join oqcbatch on ob_prodcode=pr_code", "pr_ifautocutcheckno", "ob_checkno='" + ob_checkno.Text + "'").ToString();
- if (Cut == "" || Cut == "0")
- AutoCut = false;
- else
- AutoCut = true;
- SendCheck.Enabled = true;
- }
- }
- /// <summary>
- /// 工单变化修改数量
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void ma_code_UserControlTextChanged(object sender, EventArgs e)
- {
- if (ma_code.Text.Length > 4)
- {
- BaseUtil.CleanControlsText(mcd_inqty, mcd_remainqty, ob_batchqty, ob_nowcheckqty, ob_sendqty);
- LoadCollectedNum();
- LoadCheckQTY();
- }
- }
- private void Make_TestCollection_FormClosing(object sender, FormClosingEventArgs e)
- {
- dh.Dispose();
- }
- private void ma_prodcode_TextChanged(object sender, EventArgs e)
- {
- LoadBadGroupData();
- }
- private void Filter_UserControlTextChanged(object sender, EventArgs e)
- {
- try
- {
- DataRow[] dr = (BadInfSource.DataSource as DataTable).Select("bc_code like '%" + Filter.Text + "%' or bc_name like '%" + Filter.Text + "%'");
- DataTable dt = (BadInfSource.DataSource as DataTable).Clone();
- for (int i = 0; i < dr.Length; i++)
- {
- dt.Rows.Add(dr[i].ItemArray);
- }
- 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();
- }
- catch (Exception)
- {
- }
- }
- private void WaitRejectList_DoubleClick(object sender, EventArgs e)
- {
- for (int i = WaitRejectList.Items.Count - 1; i >= 0; i--)
- {
- if (WaitRejectList.Items[i].Checked)
- {
- //双击右移
- ChooseedReject.PerformClick();
- }
- }
- }
- private void Make_TestCollection_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.Modifiers == Keys.Control && e.KeyCode == Keys.Q)
- {
- if (!LockSn)
- {
- ControlLockTimer.Start();
- LockSn = true;
- Lock_label.Visible = true;
- }
- else
- {
- ControlLockTimer.Stop();
- LockSn = false;
- Lock_label.Visible = false;
- }
- }
- }
- private void RePrint_Click(object sender, EventArgs e)
- {
- if (EnablePrint && AutoPrintBad.Checked)
- {
- string[] bcname = RePrintCode.ToArray();
- for (int i = 0; i < bcname.Length; i++)
- {
- RePrintCode.Add(bcname[i]);
- format.SubStrings["SN1"].Value = bcname[i];
- format.PrintSetup.PrinterName = Printer.Text;
- format.PrintSetup.IdenticalCopiesOfLabel = 1;
- format.Print();
- }
- }
- }
- private void WriteSoftWare_CheckedChanged(object sender, EventArgs e)
- {
- }
- private void ReleaseSN_Click(object sender, EventArgs e)
- {
- Save_Click(sender, e);
- DataTable dt = (DataTable)dh.ExecuteSql("select ms_sncode,ms_makecode from makeserial where ms_id='" + oMSID + "'", "select");
- if (dt.Rows.Count > 0)
- {
- string ms_sncode = dt.Rows[0]["ms_sncode"].ToString();
- string ms_makecode = dt.Rows[0]["ms_makecode"].ToString();
- dh.ExecuteSql("delete from sninfo where si_sn='" + ms_sncode + "'", "delete");
- dh.ExecuteSql("delete from makesnrelation where sn='" + ms_sncode + "' and makecode='" + ms_makecode + "'", "delete");
- dh.ExecuteSql("update makeserial set ms_sncode=ms_firstsn,ms_imei1='',ms_mac='',ms_bt='',ms_netcode='',ms_imei2='',ms_beforesn='' where ms_sncode='" + ms_sncode + "' and ms_makecode='" + ma_code.Text + "'", "update");
- LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "解绑", "解绑成功", ms_sncode, ob_checkno.Text);
- OperateResult.AppendText(">>" + ms_sncode + "解绑成功\n", Color.Green);
- }
- else
- {
- OperateResult.AppendText(">>" + ms_sncode.Text + "没有需要解绑的内容\n", Color.Red);
- }
- }
- }
- }
|