using Seagull.BarTender.Print; using System; using System.Data; using System.Drawing; using System.Threading; using System.Windows.Forms; using UAS_MES_NEW.CustomControl.TextBoxWithIcon; using UAS_MES_NEW.DataOperate; using UAS_MES_NEW.Entity; using UAS_MES_NEW.PublicForm; using UAS_MES_NEW.PublicMethod; namespace UAS_MES_NEW.Make { public partial class Make_SeqTransformPrint : Form { AutoSizeFormClass asc = new AutoSizeFormClass(); DataHelper dh; DataTable dt; DataTable rules; LogStringBuilder sql = new LogStringBuilder(); string bsncode = "";//转换前序列号 string errorMessage = ""; DataTable ListA; //存放工单中数量 int ma_qty; string oMakeCode = ""; Engine engine; Thread InitPrint; string oMsId = ""; bool onlyPass = false; bool hasSnList = false;//记录是否有转换后SN清单 bool hasMakeRule = false;//记录是否有工单防呆规则 bool hasSaleRule = false;//记录是否有合同防呆规则 public Make_SeqTransformPrint() { InitializeComponent(); } private void InPrint() { try { engine = new Engine(true); } catch (Exception) { OperateResult.AppendText("未正确安装BarTender软件\n", Color.Red); } } private void sncode_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { if (sncode.Text != "") { if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out errorMessage)) { OperateResult.AppendText(">>" + sncode.Text + "\n", Color.Black); //如果用户没有输入工单号自行去后台查询 //通过工单序列号关系验证 //bsncode为空,就说明是输入转换之前的序列号 if (bsncode == "") { if (!ChangeResult.Checked) { //用户填写了工单号,那么序列号必须要是该工单的,否则提示错误 if (!LogicHandler.CheckStepSNAndMacode("", User.UserSourceCode, sncode.Text, User.UserCode, out oMakeCode, out oMsId, out errorMessage)) { OperateResult.AppendText("<<" + errorMessage + "\n", Color.Red, sncode); return; } } else//勾选 { oMsId = dh.getFieldDataByCondition("makeserial", "max(ms_id)", "ms_sncode in (select '" + sncode.Text + "' from dual union select sn from makesnrelation where beforesn='" + sncode.Text + "' and sn<>' ' union select beforesn from makesnrelation where sn='" + sncode.Text + "' and beforesn<>' ')").ToString(); if (oMsId == "") { OperateResult.AppendText("< 0) { if (dt.Rows[0]["ms_downstatus"].ToString() != "0") { OperateResult.AppendText("<<当前TSN号处于下地状态不允许操作\n", Color.Red, sncode); return; } if (dt.Rows[0]["ms_stepcode"].ToString() == User.CurrentStepCode) { bsncode = sncode.Text; //显示序列号 show_sncode.Text = bsncode; ChangeResult.Enabled = false; } else { OperateResult.AppendText("<<当前工序不允许重新转号\n", Color.Red, sncode); return; } } else { OperateResult.AppendText("< 0) { //记录数量 ma_qty = int.Parse(dt.Rows[0]["ma_qty"].ToString()); BaseUtil.SetFormValue(this.Controls, dt); } } //获取需要关联采集的信息,以及校验规则 ListA = (DataTable)dh.ExecuteSql("select * from productsnrelation where psr_prodcode='" + ma_prodcode.Text + "' order by psr_detno", "select"); //没有获取到就提示错误请维护产品对应的关联采集信息 if (ListA.Rows.Count > 0) { OperateResult.AppendText("<<产品已维护关联采集信息,不允许只做转号\n", Color.Red, sncode); OperateResult.AppendText(">>请输入TSN\n", Color.Black); if (ChangeResult.Checked) { bsncode = ""; ChangeResult.Enabled = true; show_sncode.Text = ""; } return; } if (ChangeResult.Checked) { OperateResult.AppendText(">>请输入SN号\n", Color.Green, sncode); } switch (ChangeResult.CheckState) { //勾选是修改已转换的序列,矫正修改错了的序列号 case CheckState.Checked: break; case CheckState.Unchecked: //string beforesn = dh.getFieldDataByCondition("makeserial", "ms_beforesn", "ms_sncode='" + sncode.Text + "'").ToString().Trim(); //为空,就说明,没有进行过序列号的转换 if (dh.CheckExist("makeserial", "ms_id='" + oMsId + "' and ms_sncode='" + sncode.Text + "' and ms_beforesn is null")) { //记录转换前的序列号 bsncode = sncode.Text; //显示序列号 show_sncode.Text = bsncode; OperateResult.AppendText(">>请输入SN号\n", Color.Green, sncode); ChangeResult.Enabled = false; } else //不为空,进行过转换。不勾选修改结果,就不能再修改 { //修改转换结果时,输入两次SN直接过站 if (dh.CheckExist("MakeSerial", "ms_id='" + oMsId + "' and ms_sncode='" + sncode.Text + "' and ms_beforesn is not null")) { string nextstepcode = dh.getFieldDataByCondition("makeserial", "ms_nextstepcode", "ms_id='" + oMsId + "'").ToString(); if (nextstepcode == User.CurrentStepCode) { bsncode = sncode.Text; //显示序列号 show_sncode.Text = bsncode; OperateResult.AppendText(">>请输入SN号\n", Color.Green, sncode); ChangeResult.Enabled = false; onlyPass = true; } else { nextstepcode = dh.getFieldDataByCondition("step", "st_name", "st_code='" + nextstepcode + "'").ToString(); OperateResult.AppendText("<<序列号:" + sncode.Text + "下一工序是" + nextstepcode + ",不是当前岗位的工序\n", Color.Red, sncode); OperateResult.AppendText(">>请重新输入TSN号\n", Color.Black); } } else { OperateResult.AppendText("<<序列号:" + sncode.Text + "已转换过\n", Color.Red, sncode); OperateResult.AppendText(">>请重新输入TSN号\n", Color.Black); } } break; default: break; } } //bsncode不为空,说明输入的是转换后的序列号 else { //判断工单是否导入了序列号清单 if (hasSnList) { if (!dh.CheckExist("makesnlist", "msl_sncode='" + sncode.Text + "' and msl_makecode='" + ma_code.Text + "' and msl_type='after'")) { //有序列号清单,输入的序列号却不在范围内 OperateResult.AppendText("<'" + oMsId + "' and nvl(ms_nextmacode,' ') =' '") && !onlyPass || onlyPass && bsncode == sncode.Text)) || (ChangeResult.Checked && !dh.CheckExist("makeserial", "ms_sncode='" + sncode.Text + "' and ms_id <>'" + oMsId + "' and nvl(ms_nextmacode,' ') =' '"))) { if (CollectRemark.Checked || SameReamrk.Checked) { if (Remark.Text == "") { OperateResult.AppendText(">>备注栏信息为空,录入备注信息\n", Color.Black); Remark.SelectAll(); Remark.Focus(); return; } if (IFONLY.Checked) { if (!CheckPre()) { return; } string UsedSncode = dh.getFieldDataByCondition("SNRELATIONINFORECORD", "SIR_SNCODE", "sir_remark = '" + Remark.Text + "'").ToString(); if (UsedSncode != "") { OperateResult.AppendText(">>备注信息" + Remark.Text + "已被" + UsedSncode + "采集,不可重复采集\n", Color.Red); Remark.SelectAll(); Remark.Focus(); return; } LogicHandler.CollectRemarkInf(show_sncode.Text, "", "", oMakeCode, ma_prodcode.Text, Remark.Text); OperateResult.AppendText(">>备注:" + Remark.Text + "\n", Color.Black); if (CollectRemark.Checked) { Remark.Text = ""; } } else { if (!CheckPre()) { return; } LogicHandler.CollectRemarkInf(show_sncode.Text, "", "", oMakeCode, ma_prodcode.Text, Remark.Text); OperateResult.AppendText(">>备注:" + Remark.Text + "\n", Color.Black); if (CollectRemark.Checked) { Remark.Text = ""; } } } if (/*!ChangeResult.Checked && */!onlyPass) { string firstsn = ""; string updateSql = ""; //勾选了修改转换结果 if (ChangeResult.Checked) { //查询ms_firstsn firstsn = dh.getFieldDataByCondition("makeserial", "ms_firstsn", "ms_id='" + oMsId + "' and ms_beforesn='" + bsncode + "'").ToString(); //记录本次修改,存入makesnrelation表中 updateSql = "update makeserial set ms_sncode='" + sncode.Text + "',ms_beforesn='' where ms_id='" + oMsId + "' and ms_beforesn='" + bsncode + "'"; //删除最近一条转换记录 dh.ExecuteSql("delete from makesnrelation where BEFORESN='" + bsncode + "' and makecode='" + ma_code.Text + "'", "delete"); } //未勾选修改转换结果 else { //查询ms_firstsn firstsn = dh.getFieldDataByCondition("makeserial", "ms_firstsn", "ms_id='" + oMsId + "' and ms_sncode='" + bsncode + "'").ToString(); //记录本次修改,存入makesnrelation表中 updateSql = "update makeserial set ms_sncode='" + sncode.Text + "', ms_beforesn='" + bsncode + "' where ms_id='" + oMsId + "' and ms_sncode='" + bsncode + "'"; } string insertSql = "insert into makesnrelation (BEFORESN,SN,FIRSTSN,MAKECODE,msr_indate, msr_inman)values('" + bsncode + "','" + sncode.Text + "','" + firstsn + "','" + ma_code.Text + "', sysdate ,'" + User.UserCode + "')"; dh.ExecuteSQLTran(updateSql, insertSql); } onlyPass = false; OperateResult.AppendText("<<序列号" + bsncode + "成功转换为" + sncode.Text + "\n", Color.Green); //记录日志 LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "序列转换", bsncode + "转换为" + sncode.Text, sncode.Text, ""); //if (CollectRemark.Checked && Remark.Text != "") //{ // LogicHandler.CollectRemarkInf(sncode.Text, "", "", oMakeCode, ma_prodcode.Text, Remark.Text); //} LogManager.DoLog("修改序列号:" + bsncode + "为" + sncode.Text + "成功!" + "操作人:" + User.UserCode); //写入日志 if (!LogicHandler.SetStepResult(ma_code.Text, User.UserSourceCode, sncode.Text, "序列转换", "序列转换成功", User.UserCode, out errorMessage)) { OperateResult.AppendText(">>" + errorMessage + "\n", Color.Red, sncode); } for (int i = 0; i < _dt.Rows.Count; i++) { if (Print.BarTender(Tag.ToString(), ref engine, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), Printer.Text, sncode.Text, int.Parse(PrintNum.Text), oMakeCode, ma_prodcode.Text, "机身标", "0", out errorMessage)) { //提示用户打印成功 OperateResult.AppendText(">>序列号:" + sncode.Text + "打印结束\n", Color.Green); } else { OperateResult.AppendText(errorMessage + "\n", Color.Red); } } OperateResult.AppendText(">>请输入TSN号\n", Color.Black); //置空 bsncode = ""; show_sncode.Text = ""; //获取剩余数,刷新页面 sql.Clear(); sql.Append("select mcd_inqty from makecraftdetail_view where mcd_macode='" + ma_code.Text + "' and mcd_stepcode='" + User.CurrentStepCode + "'"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); if (dt.Rows.Count > 0) { BaseUtil.SetFormValue(this.Controls, dt); remain_qty.Text = ma_qty - int.Parse(dt.Rows[0]["mcd_inqty"].ToString()) + ""; } //更新数量 changenum.Text = int.Parse(changenum.Text) + 1 + ""; ChangeResult.Enabled = true; } else { if (onlyPass) { OperateResult.AppendText("<>请输入TSN号\n", Color.Green, show_sncode); ChangeResult.Enabled = true; onlyPass = false; } /// /// 工单号keydown /// /// /// private void ms_makecode_KeyDown(object sender, KeyEventArgs e) { } /// /// 如果清空了工单号,或者更换了工单号则将 : 转换前序列号长度,转换前序列号前缀 ///转换后序列号长度,转换后序列号前缀 四个字段值清空。 /// /// /// private void ms_makecode_UserControlTextChanged(object sender, EventArgs e) { hasSnList = false; hasMakeRule = false; hasSaleRule = false; //清空 beforeTransSNPre.Text = ""; beforeTransSNLength.Text = ""; afterTransSNPre.Text = ""; afterTransSNLength.Text = ""; //取消勾选 beforeTransSNPre_checkBox.Checked = false; beforeTransSNLength_checkBox.Checked = false; afterTransSNPre_checkBox.Checked = false; afterTransSNLength_checkBox.Checked = false; //设置可编辑 beforeTransSNLength.Enabled = true; beforeTransSNPre.Enabled = true; afterTransSNLength.Enabled = true; afterTransSNPre.Enabled = true; beforeTransSNPre_checkBox.Enabled = true; beforeTransSNLength_checkBox.Enabled = true; afterTransSNPre_checkBox.Enabled = true; afterTransSNLength_checkBox.Enabled = true; //判断工单是否导入了序列号清单 if (dh.CheckExist("makesnlist", "msl_makecode='" + ma_code.Text + "' and msl_type='after'")) { hasSnList = true; return; } //查询表工单序列号防呆规则表 rules = (DataTable)dh.ExecuteSql("select msr_startno from makesnrule where msr_makecode='" + ma_code.Text + "' and msr_type='after'", "select"); if (rules.Rows.Count > 0) { hasMakeRule = true; } else { ma_salecode.Text = dh.getFieldDataByCondition("make", "ma_salecode", "ma_code='" + ma_code.Text + "'").ToString(); //查询表合同序列号防呆规则表 rules = (DataTable)dh.ExecuteSql("select msr_startno from makesnrule where msr_salecode='" + ma_salecode.Text + "' and msr_type='after'", "select"); if (rules.Rows.Count > 0) { hasSaleRule = true; } else { /* 如果转换前没有值,则取 select productsnrule where psr_prodcode=? 产品编号, * 有值则赋值到 转换前,并且自动勾选不可编辑。*/ rules = (DataTable)dh.ExecuteSql("select psr_prefix ,psr_length from productsnrule where psr_prodcode = '" + dt.Rows[0]["ma_prodcode"].ToString() + "' and psr_type='after'", "select"); if (rules.Rows.Count > 0) { //将产品序列号防呆规则查出的数据填充 if (rules.Rows[0]["psr_prefix"].ToString() != "") { afterTransSNPre.Text = rules.Rows[0]["psr_prefix"].ToString(); afterTransSNPre.Enabled = false; afterTransSNPre_checkBox.Checked = true; //afterTransSNPre_checkBox.Enabled = false; } if (rules.Rows[0]["psr_length"].ToString() != "") { afterTransSNLength.Text = rules.Rows[0]["psr_length"].ToString(); afterTransSNLength.Enabled = false; afterTransSNLength_checkBox.Checked = true; //afterTransSNLength_checkBox.Enabled = false; } } } } } /// /// 检验长度或者前缀是否合法 /// /// /// /// private bool checkLengthOrPre(CheckBox checkbox, TextBox textbox, string type) { if (checkbox.Checked == true) { //如果勾选没有填值 if (textbox.Text == "") { OperateResult.AppendText("<<勾选长度或者前缀需要填写内容\n", Color.Red); return false; } if (type == "长度") { //则判断输入转换前的序列号长度是否合法,不合法则提示 if (sncode.Text.Trim().Length != int.Parse(textbox.Text)) { //序列号校验错误,长度错误 OperateResult.AppendText("<<序列号" + sncode.Text + "校验错误,长度错误\n", Color.Red, sncode); OperateResult.AppendText(">>请重新输入SN号\n", Color.Black); return false; } } else if (type == "前缀") { string[] pres = textbox.Text.Split('|'); bool f = false; for (int i = 0; i < pres.Length; i++) { if (pres[i] == "" ? true : sncode.Text.StartsWith(pres[i])) { //满足其中一条即可 f = true; break; } } //则判断输入转换前的序列号前缀是否合法,不合法则提示 if (!f) { //序列号校验错误,前缀错误 OperateResult.AppendText("<<序列号" + sncode.Text + "校验错误,前缀错误\n", Color.Red, sncode); OperateResult.AppendText(">>请重新输入SN号\n", Color.Black); return false; } } return true; } return true; } private void ChangeResult_CheckedChanged(object sender, EventArgs e) { if (ChangeResult.Checked) { //勾选的时候提示输入TSN OperateResult.AppendText(">>请输入TSN号\n", Color.Black); } } private void Make_SeqTransform_Load(object sender, EventArgs e) { asc.controllInitializeSize(this); InitPrint = new Thread(InPrint); SetLoadingWindow stw = new SetLoadingWindow(InitPrint, "初始化打印程序"); BaseUtil.SetFormCenter(stw); stw.ShowDialog(); dh = SystemInf.dh; sncode.Focus(); OperateResult.AppendText(">>请输入TSN号\n", Color.Black); StepCount.StepCode = User.CurrentStepCode; StepCount.Source = User.UserSourceCode; StepCount.LineCode = User.UserLineCode; StepCount.Dh = dh; StepCount.Start(); Seq_Remark_PreFix.Text = BaseUtil.GetCacheData("Seq_Remark_PreFix").ToString(); } private void Make_SeqTransform_SizeChanged(object sender, EventArgs e) { asc.controlAutoSize(this); } private void Remark_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { try { if ((CollectRemark.Checked || SameReamrk.Checked) && Remark.Text != "") { sncode.Enabled = true; sncode.Focus(); sncode_KeyDown(this, new KeyEventArgs(Keys.Enter)); } else { sncode.Enabled = true; sncode.Focus(); } } catch { sncode.Enabled = true; sncode.Focus(); } } } private void IFONLY_CheckedChanged(object sender, EventArgs e) { if (IFONLY.Checked) { SameReamrk.Checked = false; CollectRemark.Checked = true; } } private void SameReamrk_CheckedChanged(object sender, EventArgs e) { if (SameReamrk.Checked) { IFONLY.Checked = false; CollectRemark.Checked = false; } } private void Seq_Remark_PreFix_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { BaseUtil.SetCacheData("Seq_Remark_PreFix", Seq_Remark_PreFix.Text); if (CollectRemark.Checked || SameReamrk.Checked) { Remark.SelectAll(); Remark.Focus(); } } } //校验备注前缀 private Boolean CheckPre() { try { if (Remark.Text.Substring(0, Seq_Remark_PreFix.Text.Length) != Seq_Remark_PreFix.Text) { OperateResult.AppendText(">>备注前缀不匹配,请重新输入备注信息\n", Color.Red); Remark.SelectAll(); Remark.Focus(); return false; } } catch (Exception) { OperateResult.AppendText(">>备注前缀不匹配,请重新输入备注信息\n", Color.Red); Remark.SelectAll(); Remark.Focus(); return false; } return true; } private void CollectRemark_CheckedChanged(object sender, EventArgs e) { if (CollectRemark.Checked) { SameReamrk.Checked = false; } } private void Remark_Leave(object sender, EventArgs e) { sncode.Enabled = true; } private void Remark_Enter(object sender, EventArgs e) { sncode.Enabled = false; } DataTable _dt; private void ma_prodcode_TextChanged(object sender, EventArgs e) { _dt = (DataTable)dh.ExecuteSql("select la_id,la_url,la_isdefault from label where la_prodcode='" + ma_prodcode.Text + "' and la_templatetype='机身标' and la_statuscode='AUDITED' order by la_isdefault", "select"); PrintLabel.DataSource = _dt; PrintLabel.DisplayMember = "la_url"; PrintLabel.ValueMember = "la_id"; } } }