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 UAS_MES_NEW.Properties; using System.IO; using DevExpress.Map.BingServices; using System.Net.Sockets; using System.Net; namespace UAS_MES_NEW.Make { public partial class Make_TestCollection : Form { DataHelper dh = null; DataTable dt = null; //当前工序的名称 ExcelHandler eh; string ErrorMessage = ""; //用于保存是否之前输入的ms_sncode string LastSncode; string oMakeCode = ""; string oMSID = ""; string ifrework = ""; string reworkstatus = ""; string devicetype = ""; LogStringBuilder sql = new LogStringBuilder(); AutoSizeFormClass asc = new AutoSizeFormClass(); Boolean startcheck = false; int getcheck = 0; Dictionary dateTimeDictionary = new Dictionary(); /// /// 已选的不良 /// List ChoosedList = new List(); /// /// 待选的不良 /// List WaitList = new List(); bool AutoCut = false; bool LockSn = false; DataTable Dbfind; public Make_TestCollection() { InitializeComponent(); } private void TestCollection_Load(object sender, EventArgs e) { GoodProduct.Checked = true; asc.controllInitializeSize(this); ms_sncode.GotFocus += text_getfocus; ms_sncode.Focus(); eh = new ExcelHandler(); //设置锁定工单 LockMakeCode.GetMakeCodeCtl(ma_code); ma_code.SetLockCheckBox(LockMakeCode); ControlLockTimer.Tick += ControlLockTimer_Tick; ControlLockTimer.Interval = 100; //SMTBind.Checked = Settings.Default.SMTBIND; Control.CheckForIllegalCrossThreadCalls = false; FolderPath.Text = BaseUtil.GetCacheData("FolderPath").ToString(); //工单号放大镜配置 ma_code.TableName = "make left join product on ma_prodcode=pr_code"; ma_code.SelectField = "ma_code # 工单号,ma_prodcode # 产品编号,ma_qty # 工单数量,pr_spec # 产品规格,ma_softversion # 软件版本,ma_salecode # 销售单号,pr_sendchecktype # 产品送检方式"; ma_code.FormName = Name; ma_code.SetValueField = new string[] { "ma_code", "ma_prodcode", "ma_qty", "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(); } private void text_getfocus(object sender, EventArgs e) { ms_sncode.ImeMode = ImeMode.Close; } 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(); } /// /// 将已选不良移动到待选不良 /// /// /// 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 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,ma_softversion,ma_salecode,pr_spec,nvl(pr_sendchecktype,'LineCode')pr_sendchecktype,ma_qty from make left join product on ma_prodcode=pr_code where ma_code='" + oMakeCode + "'", "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 ms_nextstepcode = dt.Rows[0]["ms_nextstepcode"].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 && ms_nextstepcode != User.CurrentStepCode) && (reworkstatus == "1" || reworkstatus == "2") && ifrepair == "0") { OperateResult.AppendText(">>" + ms_sncode.Text + " 序列号已执行过" + User.CurrentStepCode + "工序,采集结果为良品\n", Color.Black, ms_sncode); return; } } else { if ((stepcode == User.CurrentStepCode && ms_nextstepcode != User.CurrentStepCode) && (status == "1" || status == "2") && ifrepair == "0") { OperateResult.AppendText(">>" + ms_sncode.Text + " 序列号已执行过" + User.CurrentStepCode + "工序,采集结果为良品\n", Color.Black, 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(); } /// /// 填充不良组别信息 /// 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; } /// /// 加载不良代码的ListView的信息 /// 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(); } /// /// 加载已选不良的ListView /// 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(); } /// /// 设置良品或者不良品的采集结果 /// private void SetCollectResult() { string ErrorMessage = ""; //如果勾选的是不良品 if (Reject.Checked) { LoadBadCodeListView(); LoadChoosedBadListView(); //OperateResult.AppendText(">>请采集不良代码\n", Color.Green); //bc_code.Focus(); ////勾选了自动产生代码 //if (AutoBadCode.Checked) // Save_Click(new object(), new EventArgs()); if (ms_sncode.Text == "") { OperateResult.AppendText(">>序列号不允许为空\n", Color.Red); return; } if (GoodProduct.Checked) ms_code_KeyDown_one(this, 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,ma_softversion,pr_spec,ma_qty from make left join product on ma_prodcode=pr_code where ma_code='" + oMakeCode + "'", "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 (AutoBadCode.Checked) //{ // string defaultvalue = Properties.Settings.Default.DefaultCollectionValue; // bccode = new string[] { defaultvalue }; // bcremark = new string[] { defaultvalue }; // bgcode = new string[] { defaultvalue }; // bgname = new string[] { defaultvalue }; // bcname = new string[] { defaultvalue }; //} //else //{ // 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; // } // } //} //如果之前是良品的 dt = dh.getFieldsDataByCondition("makeserial", new string[] { "ms_status", "ms_checkno" }, "ms_id='" + oMSID + "' and ms_stepcode='" + User.CurrentStepCode + "'"); if (dt.Rows.Count > 0) { string status = dt.Rows[0]["ms_status"].ToString(); 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, "检查未通过", 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); 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); } } 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)) { LastSncode = ms_sncode.Text; //提示正确返回时传递的信息 if (ErrorMessage.Contains("AFTERSUCCESS")) { OperateResult.AppendText(">>" + ms_sncode.Text + "良品采集成功 " + ErrorMessage + "\n", Color.Blue, ms_sncode); getcheck++; } else { OperateResult.AppendText(">>" + ms_sncode.Text + "良品采集成功\n", Color.Green, ms_sncode); getcheck++; } //记录操作日志 LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "采集良品", "采集良品成功", LastSncode, ob_checkno.Text); if (!startcheck) { startcheck = true; Thread thread = new Thread(NewPrint); ; thread.Start(); } } 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 NewPrint() { Thread.Sleep(9000); oneget.Text = getcheck.ToString(); getcheck = 0; startcheck = false; } 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); } private void Save_Click(object sender, EventArgs e) { if (ms_sncode.Text == "") { OperateResult.AppendText(">>序列号不允许为空\n", Color.Red); return; } if (GoodProduct.Checked) ms_code_KeyDown_one(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,ma_softversion,pr_spec,ma_qty from make left join product on ma_prodcode=pr_code where ma_code='" + oMakeCode + "'", "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 (AutoBadCode.Checked) { string defaultvalue = Properties.Settings.Default.DefaultCollectionValue; bccode = new string[] { defaultvalue }; bcremark = new string[] { defaultvalue }; bgcode = new string[] { defaultvalue }; bgname = new string[] { defaultvalue }; bcname = new string[] { defaultvalue }; } else { 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; } } } //如果之前是良品的 dt = dh.getFieldsDataByCondition("makeserial", new string[] { "ms_status", "ms_checkno" }, "ms_id='" + oMSID + "' and ms_stepcode='" + User.CurrentStepCode + "'"); if (dt.Rows.Count > 0) { string status = dt.Rows[0]["ms_status"].ToString(); 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); 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; } else { 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; } } /// /// 工单变化修改数量 /// /// /// 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 ms_code_KeyDown_one(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { if (SMTBind.Checked&& GoodProduct.Checked) { DataTable dt = (DataTable)dh.ExecuteSql("select A.SB_BARCODE from smtbind A LEFT JOIN SMTBIND B ON A.SB_MAINCODE = B.SB_MAINCODE WHERE B.SB_BARCODE = '" + ms_sncode.Text + "'", "select"); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { ms_sncode.Text = dt.Rows[i]["sb_barcode"].ToString(); ms_code_KeyDown(sender, new KeyEventArgs(Keys.Enter)); } } else { OperateResult.AppendText(">>SN" + ms_sncode.Text + "未进行分板绑定\n", Color.Red, ms_sncode); } } else { ms_code_KeyDown(sender, new KeyEventArgs(Keys.Enter)); } } } private void SMTBind_CheckedChanged(object sender, EventArgs e) { //Settings.Default.SMTBIND = SMTBind.Checked; //Settings.Default.Save(); } private void StartWatch_Click(object sender, EventArgs e) { if (FolderPath.Text == "") { OperateResult.AppendText("请选择监控文件夹\n"); return; } else { if (!Directory.Exists(FolderPath.Text)) { OperateResult.AppendText("监控文件夹不存在\n"); return; } } if (devicetype != "扭力"&&devicetype != "角度") { OperateResult.AppendText("文件解析需选择扭力或角度\n"); return; } XmlWatcher.Path = FolderPath.Text; XmlWatcher.Filter = "*.*"; XmlWatcher.EnableRaisingEvents = true; //设置缓存数据 BaseUtil.SetCacheData("FolderPath", FolderPath.Text); //设置按钮不可点击 StartWatch.Enabled = false; ChooseFolder.Enabled = false; StopWatch.Enabled = true; OperateResult.AppendText("开始执行监控\n"); } private void StopWatch_Click(object sender, EventArgs e) { XmlWatcher.EnableRaisingEvents = false; StartWatch.Enabled = true; ChooseFolder.Enabled = true; StopWatch.Enabled = false; OperateResult.AppendText("停止执行监控\n"); } private void ChooseFolder_Click(object sender, EventArgs e) { FolderBrowserDialog folder = new FolderBrowserDialog(); folder.Description = "选择监控文件夹"; DialogResult result = folder.ShowDialog(); if (result == DialogResult.OK) { FolderPath.Text = folder.SelectedPath; } } private void XmlWatcher_Created(object sender, FileSystemEventArgs e) { if (e.ChangeType == WatcherChangeTypes.Changed || e.ChangeType == WatcherChangeTypes.Created) { while (true) { try { using (Stream stream = File.Open(e.FullPath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite)) { if (stream != null) break; } } catch (Exception ex) { Console.WriteLine(ex.Message); return; } } if (!e.FullPath.ToUpper().Contains(".CSV") && !e.FullPath.ToUpper().Contains(".XLS")) { Console.WriteLine("文件" + e.FullPath + "不符合要求,退出"); } else { Console.WriteLine(e.FullPath); DataTable ddtt; ddtt = eh.ImportExcel(e.FullPath, "test"); if (devicetype == "角度") { string sn = ddtt.Rows[ddtt.Rows.Count-1]["条码"].ToString(); string result = ddtt.Rows[ddtt.Rows.Count - 1]["测试结果"].ToString(); Console.WriteLine(sn + result); if (result == "PASS") { GoodProduct.Checked = true; Reject.Checked = false; ms_sncode.Text = sn; ms_code_KeyDown(sender, new KeyEventArgs(Keys.Enter)); } else { GoodProduct.Checked = false; Reject.Checked = true; ms_sncode.Text = sn; ms_code_KeyDown(sender, new KeyEventArgs(Keys.Enter)); } } else if (devicetype == "扭力") { string sn = ddtt.Rows[ddtt.Rows.Count - 1]["条码"].ToString(); string result = ddtt.Rows[ddtt.Rows.Count - 1]["结果"].ToString(); Console.WriteLine(sn + result); if (result == "OK") { GoodProduct.Checked = true; Reject.Checked = false; ms_sncode.Text = sn; ms_code_KeyDown(sender, new KeyEventArgs(Keys.Enter)); } else { GoodProduct.Checked = false; Reject.Checked = true; ms_sncode.Text = sn; ms_code_KeyDown(sender, new KeyEventArgs(Keys.Enter)); } } } //StreamReader _Sr = new StreamReader(FolderPath.Text + @"\" + e.Name, Encoding.UTF8); //String[] strData; //string line; //while ((line = _Sr.ReadLine()) != null) //{ // strData = line.Replace("\r", "").Replace("\n", "").Replace("\t", "").Split(','); // if (strData.Length > 5 && strData[0] == "ArrayID") // { // if (strData[5] != ""&& strData[5] != "NOREAD") // { // if (strData[3] == "Good"|| strData[3] == "Pass") // { // ms_sncode.Text = strData[5]; // ms_code_KeyDown(this, new KeyEventArgs(Keys.Enter)); // } // else { // OperateResult.AppendText(">>解析数据" + strData[5] + "非良品,无法采集\n", Color.Red, ms_sncode); // } // } // } //} //_Sr.Close(); } } private void XmlWatcher_Changed(object sender, FileSystemEventArgs e) { } private void niuli_CheckedChanged(object sender, EventArgs e) { if (niuli.Checked) { devicetype = "扭力"; } else if (pingmiandu.Checked) { devicetype = "平面度"; } else if (jiaodu.Checked) { devicetype = "角度"; } else if (chicun.Checked) { devicetype = "尺寸"; } } private void normalButton2_Click(object sender, EventArgs e) { DialogResult result = openFileDialog1.ShowDialog(); if (result == DialogResult.OK) { textBox1.Text = openFileDialog1.FileName; } } private void normalButton3_Click(object sender, EventArgs e) { DataTable ddtt; ddtt = eh.ImportExcel(textBox1.Text, "test"); int number = 0; string ips = null; if (devicetype != "尺寸") { MessageBox.Show("文件导入解析需选择尺寸"); return; } IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName()); foreach (IPAddress ip in host.AddressList) { if (ip.AddressFamily == AddressFamily.InterNetwork) { ips = ip.ToString(); //Console.WriteLine(ip.ToString()); } } string maxtime = dh.getFieldDataByCondition("maxdevice", "time", "device = '" + devicetype + "' and ip = '" + ips + "'").ToString(); string lasttime = ""; for (int i = 0; i < ddtt.Rows.Count; i++) { if (ddtt.Rows[i]["时间"].ToString() != "" && string.Compare(ddtt.Rows[i]["时间"].ToString(), maxtime) > 0) { Console.WriteLine(ddtt.Rows[i]["内容"].ToString() + ddtt.Rows[i]["OK/NG"].ToString() + ddtt.Rows[i]["时间"].ToString()); if (ddtt.Rows[i]["OK/NG"].ToString() == "OK") { GoodProduct.Checked = true; Reject.Checked = false; ms_sncode.Text = ddtt.Rows[i]["内容"].ToString(); ms_code_KeyDown(sender, new KeyEventArgs(Keys.Enter)); } else { GoodProduct.Checked = false; Reject.Checked = true; ms_sncode.Text = ddtt.Rows[i]["内容"].ToString(); ms_code_KeyDown(sender, new KeyEventArgs(Keys.Enter)); } lasttime = ddtt.Rows[i]["时间"].ToString(); } } if (lasttime != "") { dh.ExecuteSql("merge into maxdevice USING (select '" + devicetype + "' aa,'" + ips + "' bb,'" + lasttime + "' cc from dual) a on " + " (device = aa and ip = bb) when matched then update set time = cc when not matched then insert values(aa,bb,cc) ", "update"); } } } }