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.PublicForm;
using LabelManager2;
using System.IO;
using System.Text.RegularExpressions;
namespace UAS_MES_NEW.Make
{
public partial class Make_TestCollectionOh : 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();
///
/// 已选的不良
///
List ChoosedList = new List();
///
/// 待选的不良
///
List WaitList = new List();
bool AutoCut = false;
bool LockSn = false;
string labelname;
DataTable Dbfind;
ApplicationClass lbl;
Thread thread;
// Document doc;
public Make_TestCollectionOh()
{
InitializeComponent();
}
private void TestCollection_Load(object sender, EventArgs e)
{
GoodProduct.Checked = true;
asc.controllInitializeSize(this);
ms_sncode.Focus();
//设置锁定工单
LockMakeCode.GetMakeCodeCtl(ma_code);
ma_code.SetLockCheckBox(LockMakeCode);
ControlLockTimer.Tick += ControlLockTimer_Tick;
ControlLockTimer.Interval = 100;
labelname = System.Windows.Forms.Application.StartupPath + @"\badsn.lab";
//thread = new Thread(NewPrint);
// SetLoadingWindow stw = new SetLoadingWindow(thread, "初始化打印程序");
//BaseUtil.SetFormCenter(stw);
// stw.ShowDialog();
//工单号放大镜配置
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 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)
{
if (bidui.Checked && biduisn.Text != ms_sncode.Text)
{
OperateResult.AppendText(">>SN比对不一致\n", Color.Red, ms_sncode);
return;
}
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 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,biduisn);
}
else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode, biduisn);
}
}
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();
}
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 (AutoBadCode.Checked)
{
string str = BaseUtil.GetDataFromDevice("DEVICES");
str = str.Replace("LIST OF DEVICES ATTACHED", "").Replace("\n", "");
if (!(str.Length == 0))
{
Console.WriteLine("有链接");
BaseUtil.GetDataFromDevice("RESET");
}
else
{
OperateResult.AppendText(">>无设备链接,无法恢复出厂设置,采集失败\n", Color.Red, ms_sncode);
return;
}
}
//良品信息采集
if (LogicHandler.SetStepResult(ma_code.Text, User.UserSourceCode, ms_sncode.Text, "良品采集", "检测合格", User.UserCode, out ErrorMessage))
{
//if (WriteSoftWare.Checked)
//{
// string Message = BaseUtil.GetDataFromDevice("INSTALL", SoftWarePath.Text);
// OperateResult.AppendText(">>" + Message + "\n");
//}
//提示正确返回时传递的信息
if (ErrorMessage.Contains("AFTERSUCCESS"))
OperateResult.AppendText(">>" + ErrorMessage + "\n");
////恢复出厂设置
//if (AutoBadCode.Checked)
// BaseUtil.GetDataFromDevice("RESET");
LastSncode = ms_sncode.Text;
OperateResult.AppendText(">>" + ms_sncode.Text + "良品采集成功\n", Color.Green, ms_sncode, biduisn);
if (bidui.Checked)
biduisn.Focus();
//记录操作日志
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, biduisn);
}
}
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, biduisn);
if (bidui.Checked)
biduisn.Focus();
//记录操作日志
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, biduisn);
}
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);
}
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,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 (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_outboxcode" }, "ms_id='" + oMSID + "' and ms_stepcode='" + User.CurrentStepCode + "'");
if (dt.Rows.Count > 0)
{
string status = dt.Rows[0]["ms_status"].ToString();
string outboxcode = dt.Rows[0]["ms_outboxcode"].ToString();
if (outboxcode != "")
{
OperateResult.AppendText(">>序列号:" + ms_sncode.Text + "已装箱,请先进行拆箱\n", Color.Red);
BaseUtil.CleanForm(this);
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");
//normalButton1_Click(this, e);
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)
{
BaseUtil.ClosePrint(lbl);
//if (engine != null)
// engine.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);
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 NewPrint()
{
try
{
// engine = new BarTender.Application();
lbl = new ApplicationClass();
BaseUtil.WriteLbl();
}
catch (Exception ex)
{
OperateResult.AppendText("未正确安装CodeSoft软件\n" + ex.Message, Color.Red);
}
}
private void normalButton1_Click(object sender, EventArgs e)
{
//if (ChoosedRejectList.Items.Count == 0 || ms_sncode.Text == "")
//{
// MessageBox.Show("未录入不良或SN为空");
//}
//string BADINFO = "";
//for (int i = 0; i < ChoosedRejectList.Items.Count; i++)
//{
// BADINFO = BADINFO + ChoosedRejectList.Items[i].ListView.Items[i].SubItems[3].Text + " ";
//}
//BADINFO = BADINFO.Substring(0, BADINFO.Length - 1);
//FileInfo PrintFile = new FileInfo(labelname);
//if (!PrintFile.Exists)
//{
// MessageBox.Show("打印文件不存在");
// return ;
//}
//doc = lbl.Documents.Open(labelname, true);
//if (doc == null)
//{
// MessageBox.Show("标签文件打开失败");
// return ;
//}
//for (int j = 1; j < doc.Variables.FormVariables.Count+1; j++)
//{
// switch (doc.Variables.FormVariables.Item(j).Name)
// {
// case "SN":
// doc.Variables.FormVariables.Item(j).Value = ms_sncode.Text;
// break;
// case "BAD":
// doc.Variables.FormVariables.Item(j).Value = BADINFO;
// break;
// }
// // doc.Variables.FormVariables.Item(1).Value = (Prefix.Text + Date.Value.ToString("yyMMdd") + lpad(4, (i).ToString()));
//}
////保存本次赋值进行打印
//doc.Printer.SwitchTo(PrintList.Text);
//doc.PrintDocument(1);
}
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;
}
}
XmlWatcher.Path = FolderPath.Text;
XmlWatcher.Filter = "*.HTML";
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 XmlWatcher_Created(object sender, FileSystemEventArgs e)
{
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);
}
}
StreamReader _Sr = new StreamReader(FolderPath.Text + @"\" + e.Name, Encoding.UTF8);
string line;
string ssn = "";
string barcode = "";
string pass = "";
try
{
while ((line = _Sr.ReadLine()) != null)
{
if (line.Contains("
[^>]*>.*?|");
barcode = regex.Matches(line)[1].Value.Replace("\"", "").Replace(" ","").Replace("UUTID:","").Replace("", "");
pass = regex.Matches(line)[2].Value.Replace("\"", "");
}
}
if (pass.Contains("PASS"))
{
ssn = dh.getFieldDataByCondition("craftmaterial", "cm_sncode", "cm_barcode = '" + barcode + "' and cm_status = 0").ToString();
if (ssn == "")
{
OperateResult.AppendText("主板号"+barcode+"未读取到上料记录,过站失败\n", Color.Red);
}
else
{
ms_sncode.Text = ssn;
ms_code_KeyDown(this, new KeyEventArgs(Keys.Enter));
}
}
else {
OperateResult.AppendText("未读取到PASS检测结果,过站失败\n", Color.Red);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
_Sr.Close();
}
_Sr.Close();
}
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 biduisn_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
if (bidui.Checked&&biduisn.Text!="")
{
ms_sncode.Focus();
ms_sncode.SelectAll();
}
}
}
}
}