123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using UAS_MES_NEW.DataOperate;
- using UAS_MES_NEW.Entity;
- using UAS_MES_NEW.PublicMethod;
- namespace UAS_MES_NEW.Make
- {
- public partial class Make_SeqProgramTransform : Form
- {
- AutoSizeFormClass asc = new AutoSizeFormClass();
- LogStringBuilder sql = new LogStringBuilder();
- DataHelper dh;
- //原序列号
- string TSN = "";
- //转换后序列号
- string SN = "";
- //错误信息
- string errorMessage;
- //存放productsnrelation表中的数据
- DataTable ListA;
- //存放工单信息
- DataTable dt;
- //存放序列号防呆规则
- DataTable rules;
- //step 记录检验规则的进度
- int step = 0;
- //存放关联信息类型
- string type;
- //存放包含IMEI的规则的值,方便拼接
- StringBuilder imei = new StringBuilder();
- LogStringBuilder logsql = new LogStringBuilder();
- //存放工单中数量
- int ma_qty;
- //存放所有关联信息的类型和录入的值
- Hashtable hs;
- string oMakecode = "";
- string oMsid = "";
- string siid = "";//存储TSN对应的sninfo记录id
- DataTable macRange;//记录macBT范围
- string macOrBt = "";//存储去掉":"或者"-"的mac和bt
- bool onlyPass = false;//自己转自己
- string imeif = "";
- bool hasSnList = false;//记录是否有转换后SN清单
- bool hasMakeRule = false;//记录是否有工单防呆规则
- public Make_SeqProgramTransform()
- {
- InitializeComponent();
- }
- private void Make_SeqProgramTransform_Load(object sender, EventArgs e)
- {
- asc.controllInitializeSize(this);
- code.Focus();
- //提示用户“>>请输入TSN号”
- OperateResult.AppendText(">>请输入TSN号\n", Color.Black);
- dh = SystemInf.dh;
- 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 code_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- {
- if (code.Text != "")
- {
- if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out errorMessage))
- {
- //为0,输入TSN
- if (step == 0)
- {
- OperateResult.AppendText(">>TSN号" + code.Text + "\n", Color.Black);
- if (!ChangeResult.Checked)//不勾选
- {
- //核对工序
- if (!LogicHandler.CheckStepSNAndMacode("", User.UserSourceCode, code.Text, User.UserCode, out oMakecode, out oMsid, out errorMessage))
- {
- OperateResult.AppendText(">>" + errorMessage + "\n", Color.Red, code);
- return;
- }
- }
- else//勾选
- {
- oMsid = dh.getFieldDataByCondition("makeserial", "max(ms_id)", "ms_sncode in (select '" + code.Text + "' from dual union select sn from makesnrelation where beforesn='" + code.Text + "' and sn<>' ' union select beforesn from makesnrelation where sn='" + code.Text + "' and beforesn<>' ')").ToString();
- if (oMsid == "")
- {
- OperateResult.AppendText("<<TSN号错误\n", Color.Red, code);
- return;
- }
- //根据ms_id查询
- sql.Clear();
- sql.Append("select ms_stepcode,nvl(ms_downstatus,'0') ms_downstatus from makeserial where ms_id='" + oMsid + "' and ms_beforesn='" + code.Text + "' and ms_nextmacode is null and ms_outboxcode is null");
- dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- //如果行数大于0则允许转号
- if (dt.Rows.Count > 0)
- {
- if (dt.Rows[0]["ms_downstatus"].ToString() != "0")
- {
- OperateResult.AppendText("<<当前TSN号处于下地状态不允许操作\n", Color.Red, code);
- return;
- }
- if (dt.Rows[0]["ms_stepcode"].ToString() == User.CurrentStepCode)
- {
- step = 1;
- TSN = code.Text;
- //显示序列号
- show_sncode.Text = TSN;
- ChangeResult.Enabled = false;
- }
- else
- {
- OperateResult.AppendText("<<当前工序不允许重新转号\n", Color.Red, code);
- return;
- }
- }
- else
- {
- OperateResult.AppendText("<<TSN号" + code.Text + "未转号不允许重新转号\n", Color.Red, code);
- return;
- }
- }
- //如果用户没有选择工单号
- if (ms_macode.Text == "" || ms_macode.Text != oMakecode || ChangeResult.Checked)
- {
- //按照out出的工单号查出工单相关信息,并赋值到相关控件
- sql.Clear();
- sql.Append("select ma_code as ms_macode,ma_softversion,mcd_okqty,ma_qty,ma_qty-mcd_inqty as remain_qty,pr_detail,pr_code as ma_prodcode ");
- sql.Append("from makeserial left join make on ms_makecode=ma_code left join product on ");
- sql.Append("ms_prodcode=pr_code left join makecraftdetail on ms_makecode=mcd_macode where ms_id='" + oMsid + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
- dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- if (dt.Rows.Count > 0)
- {
- //记录数量
- ma_qty = int.Parse(dt.Rows[0]["ma_qty"].ToString());
- BaseUtil.SetFormValue(this.Controls, dt);
- }
- else
- {
- OperateResult.AppendText("<<TSN号" + code.Text + "不存在\n", Color.Red, code);
- return;
- }
- }
- //查询TSN对应的sninfo记录id
- siid = dh.getFieldDataByCondition("sninfo", "max(si_id) si_id", "si_sn in (select '" + code.Text + "' from dual union select sn from makesnrelation where beforesn = '" + code.Text + "' )").ToString();
- //获取需要关联采集的信息,以及校验规则
- 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, code);
- OperateResult.AppendText(">>请输入TSN\n", Color.Black);
- if (ChangeResult.Checked)
- {
- clearInfo();
- }
- return;
- }
- if (ChangeResult.Checked)
- {
- OperateResult.AppendText(">>请输入SN\n", Color.Green, code);
- }
- //判断重新转换未勾选
- if (!ChangeResult.Checked)
- {
- //没有勾选,只能修改一次
- //核对TSN是否正确
- //string beforesn = dh.getFieldDataByCondition("makeserial", "ms_beforesn", "ms_sncode='" + code.Text + "'").ToString().Trim();
- if (dh.CheckExist("makeserial", "ms_id='" + oMsid + "' and ms_sncode='" + code.Text + "' and ms_beforesn is null"))
- {
- step = 1;
- //记录转换前的序列号
- TSN = code.Text;
- //显示之前的序列号
- show_sncode.Text = TSN;
- OperateResult.AppendText(">>请输入SN\n", Color.Green, code);
- ChangeResult.Enabled = false;
- }
- else
- //不为空,进行过转换。不勾选修改结果,就不能再修改
- {
- //修改转换结果时,输入两次SN直接过站
- if (dh.CheckExist("MakeSerial", "ms_id='" + oMsid + "' and ms_sncode='" + code.Text + "' and ms_beforesn is not null"))
- {
- string nextstepcode = dh.getFieldDataByCondition("makeserial", "ms_nextstepcode", "ms_id='" + oMsid + "'").ToString();
- if (nextstepcode == User.CurrentStepCode)
- {
- step = 1;
- TSN = code.Text;
- //显示序列号
- show_sncode.Text = TSN;
- OperateResult.AppendText(">>请输入SN\n", Color.Green, code);
- ChangeResult.Enabled = false;
- onlyPass = true;
- }
- else
- {
- OperateResult.AppendText("<<序列号:" + code.Text + "下一工序是" + nextstepcode + ",不是当前岗位的工序\n", Color.Red, code);
- OperateResult.AppendText(">>请重新输入TSN\n", Color.Black);
- }
- }
- else
- {
- OperateResult.AppendText("<<序列号:" + code.Text + "已转换过\n", Color.Red, code);
- OperateResult.AppendText(">>请重新输入TSN\n", Color.Black);
- }
- }
- }
- }
- else if (step == 1)
- {
- OperateResult.AppendText(">>" + code.Text + "\n", Color.Black);
- //判断工单是否导入了序列号清单
- if (hasSnList)
- {
- if (!dh.CheckExist("makesnlist", "msl_sncode='" + code.Text + "' and msl_makecode='" + ms_macode.Text + "' and msl_type='after'"))
- {
- //有序列号清单,输入的序列号却不在范围内
- OperateResult.AppendText("<<SN号" + code.Text + "错误,不在工单设定的转换后序列号清单中\n", Color.Red, code);
- return;
- }
- }
- else if (hasMakeRule)//判断工单防呆
- {
- if (!dh.CheckExist("makesnruledetail", "msd_sncode='" + code.Text + "' and msd_makecode='" + ms_macode.Text + "' and msd_type='after'"))
- {
- OperateResult.AppendText("<<SN号" + code.Text + "校验错误,不在工单防呆规则指定范围内!\n", Color.Red, code);
- return;
- }
- }
- else//判断产品防呆
- {
- //判断用户是否锁定输入SN长度,
- if (!checkLengthOrPre(SNLength_checkBox, SNLength, "长度", "SN"))
- {
- return;
- }
- //判断用户是否锁定输入SN前缀,
- if (!checkLengthOrPre(SNPre_checkBox, SNPre, "前缀", "SN"))
- {
- return;
- }
- }
- //开始录入SN
- if ((!ChangeResult.Checked && (!dh.CheckExist("makeserial", "ms_sncode='" + code.Text + "' and ms_id <>'" + oMsid + "' and nvl(ms_nextmacode,' ') =' '") && !onlyPass || onlyPass && TSN == code.Text)) || (ChangeResult.Checked && !dh.CheckExist("makeserial", "ms_sncode='" + code.Text + "' and ms_id <>'" + oMsid + "' and nvl(ms_nextmacode,' ') =' '")))
- {
- onlyPass = false;
- //SN校验成功,合法,记录下SN
- SN = code.Text;
- code.Text = "";
- //开始进行校验规则
- if (ListA.Rows.Count > 0)
- {
- OperateResult.AppendText(">>请输入" + ListA.Rows[0]["psr_type"] + "\n", Color.Green);
- //实例化hashTable的值
- hs = new Hashtable();
- }
- //step+1
- step = 2;
- }
- else
- {
- if (onlyPass)
- {
- OperateResult.AppendText("<<SN号" + code.Text + "错误,已完成转号只允许SN转SN\n", Color.Red);
- }
- else
- {
- OperateResult.AppendText("<<SN号" + code.Text + "已存在\n", Color.Red);
- }
- OperateResult.AppendText(">>请输入SN\n", Color.Black, code);
- }
- }
- else if (step < ListA.Rows.Count + 2)
- {
- OperateResult.AppendText(">>" + code.Text + "\n", Color.Black);
- //开始进行校验规则
- if (checkRules(step))
- {
- step += 1;
- code.Text = "";
- }
- }
- }
- else
- {
- OperateResult.AppendText(">>" + errorMessage + "\n", Color.Red, code);
- }
- }
- else
- {
- OperateResult.AppendText("<<输入不能为空\n", Color.Red);
- }
- }
- }
- /// <summary>
- /// 检验长度或者前缀是否合法
- /// </summary>
- /// <param name="checkbox"></param>
- /// <param name="c"></param>
- /// <param name="info"></param>
- private bool checkLengthOrPre(CheckBox checkbox, TextBox textbox, string type, string TSNorSN)
- {
- if (checkbox.Checked == true)
- {
- //如果勾选没有填值
- if (textbox.Text == "")
- {
- OperateResult.AppendText("<<勾选长度或者前缀需要填写内容\n", Color.Red);
- return false;
- }
- if (type == "长度")
- {
- //则判断输入转换前的序列号长度是否合法,不合法则提示
- if (code.Text.Trim().Length != int.Parse(textbox.Text))
- {
- //序列号校验错误,长度错误
- OperateResult.AppendText("<<" + TSNorSN + ":" + code.Text + "校验错误,长度错误\n", Color.Red, code);
- OperateResult.AppendText(">>请重新输入" + TSNorSN + "\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 : code.Text.StartsWith(pres[i]))
- {
- //满足其中一条即可
- f = true;
- break;
- }
- }
- //则判断输入转换前的序列号前缀是否合法,不合法则提示
- if (!f)
- {
- //序列号校验错误,前缀错误
- OperateResult.AppendText("<<" + TSNorSN + ":" + code.Text + "校验错误,前缀错误\n", Color.Red, code);
- OperateResult.AppendText(">>请重新输入" + TSNorSN + "\n", Color.Black);
- return false;
- }
- }
- return true;
- }
- return true;
- }
- /// <summary>
- /// 关联采集的校验
- /// </summary>
- /// <param name="step"></param>
- private bool checkRules(int step)
- {
- type = ListA.Rows[step - 2]["psr_type"].ToString();
- //将type中的mac和bt中的"-"和":"号去掉
- if (type == "MAC" || type == "BT")
- {
- if (code.Text.Length > 40)
- {
- macOrBt = code.Text.Substring(0, 40).Replace(":", "").Replace("-", "");
- }
- else
- {
- macOrBt = code.Text.Replace(":", "").Replace("-", "");
- }
- }
- else
- {
- if (code.Text.Length > 40)
- {
- imeif = code.Text.Substring(0, 40);
- }
- else
- {
- imeif = code.Text;
- }
- }
- if (code.Text.Length > 40)
- {
- //如果前缀和长度都满足的话
- if ((ListA.Rows[step - 2]["psr_length"].ToString() == "0" ? false : code.Text.Substring(0, 40).Length != int.Parse(ListA.Rows[step - 2]["psr_length"].ToString())))
- {
- OperateResult.AppendText("<<" + ListA.Rows[step - 2]["psr_type"] + "长度需为" + ListA.Rows[step - 2]["psr_length"].ToString() + "校验不通过,请重新输入\n", Color.Red);
- OperateResult.AppendText(">>请重新输入" + ListA.Rows[step - 2]["psr_type"] + "\n", Color.Black, code);
- return false;
- }
- }
- else
- {
- //如果前缀和长度都满足的话
- if ((ListA.Rows[step - 2]["psr_length"].ToString() == "0" ? false : code.Text.Length != int.Parse(ListA.Rows[step - 2]["psr_length"].ToString())))
- {
- OperateResult.AppendText("<<" + ListA.Rows[step - 2]["psr_type"] + "长度需为" + ListA.Rows[step - 2]["psr_length"].ToString() + "校验不通过,请重新输入\n", Color.Red);
- OperateResult.AppendText(">>请重新输入" + ListA.Rows[step - 2]["psr_type"] + "\n", Color.Black, code);
- return false;
- }
- }
- //以|符号分割前缀
- string[] preFixs = ListA.Rows[step - 2]["psr_prefix"].ToString().Split('|');
- //只要满足其中一个前缀条件即可
- bool isfit = false;
- for (int i = 0; i < preFixs.Length; i++)
- {
- if (preFixs[i] == "" ? true : code.Text.StartsWith(preFixs[i]))
- {
- //满足其中一条即可
- isfit = true;
- break;
- }
- }
- if (!isfit)
- {
- OperateResult.AppendText("<<" + ListA.Rows[step - 2]["psr_type"] + "前缀校验不通过,请重新输入\n", Color.Red);
- OperateResult.AppendText(">>请重新输入" + ListA.Rows[step - 2]["psr_type"] + "\n", Color.Black, code);
- return false;
- }
- switch (type)
- {
- case "IMEI1":
- case "IMEI2":
- case "IMEI3":
- string tempSn = dh.getFieldDataByCondition("makeserial", "ms_sncode", "(ms_imei1='" + imeif + "' or ms_imei2 = '" + imeif + "' or ms_imei3 = '" + imeif + "') and ms_status in (0,1,2,3) and ms_id <> '" + oMsid + "' and nvl(ms_nextmacode,' ')=' '").ToString();
- if (tempSn != "")
- {
- OperateResult.AppendText("<<" + type + ":" + imeif + "错误,已被序列号" + tempSn + "使用\n", Color.Red);
- OperateResult.AppendText(">>请输入" + type + "\n", Color.Black, code);
- return false;
- }
- else
- { //校验sninfo中是否已经存在这个
- tempSn = dh.getFieldDataByCondition("sninfo", "si_sn", "(si_imei1='" + imeif + "' or si_imei2 = '" + imeif + "' or si_imei3 = '" + imeif + "') and si_id <>'" + siid + "'").ToString();
- if (tempSn != "")
- {
- OperateResult.AppendText("<<" + type + ":" + imeif + "错误,已被序列号" + tempSn + "使用\n", Color.Red);
- OperateResult.AppendText(">>请输入" + type + "\n", Color.Black, code);
- return false;
- }
- //判断IMEI1,IMEI2,IMEI3中是否已经有这个号了
- if (imei.ToString().Contains(imeif))
- {
- OperateResult.AppendText("<<" + type + ":" + imeif + "已录,请重新输入\n", Color.Red);
- OperateResult.AppendText(">>请输入" + type + "\n", Color.Black, code);
- return false;
- }
- }
- //通过校验,将包含IMEI的值拼接
- imei.Append("'" + imeif + "',");
- break;
- case "BT":
- case "MAC":
- //验证是否符合合同防呆
- if (!LogicHandler.checkMacOrBtRange(oMsid, macOrBt, type))
- {
- OperateResult.AppendText("<<" + ListA.Rows[step - 2]["psr_type"].ToString() + ":" + code.Text + "错误,不在合同防呆范围内\n", Color.Red);
- OperateResult.AppendText(">>请输入" + ListA.Rows[step - 2]["psr_type"].ToString() + "\n", Color.Black, code);
- return false;
- }
- //验证是否MAC和BT重复
- if (hs.ContainsValue(macOrBt))
- {
- foreach (DictionaryEntry de in hs)
- {
- //拿到重复的项
- if (de.Value.ToString() == macOrBt)
- {
- OperateResult.AppendText("<<" + ListA.Rows[step - 2]["psr_type"].ToString() + ":" + code.Text + "错误," + de.Key + "已录\n", Color.Red);
- OperateResult.AppendText(">>请输入" + ListA.Rows[step - 2]["psr_type"].ToString() + "\n", Color.Black, code);
- return false;
- }
- }
- }
- //验证是否已被使用
- string temSn = dh.getFieldDataByCondition("makeserial", "ms_sncode", "(MS_mac='" + macOrBt + "'or ms_bt='" + macOrBt + "') and ms_status in (0,1,2,3) and ms_id <> '" + oMsid + "' and nvl(ms_nextmacode,' ')=' '").ToString();
- if (temSn != "")
- {
- OperateResult.AppendText("<<" + ListA.Rows[step - 2]["psr_type"].ToString() + ":" + code.Text + "错误,已被序列号" + temSn + "使用\n", Color.Red);
- OperateResult.AppendText(">>请输入" + ListA.Rows[step - 2]["psr_type"].ToString() + "\n", Color.Black, code);
- return false;
- }
- else
- {
- //校验在sninfo表中是否存在
- temSn = dh.getFieldDataByCondition("sninfo", "si_sn", "(si_mac='" + macOrBt + "' or si_bt='" + macOrBt + "') and si_id <>'" + siid + "'").ToString();
- if (temSn != "")
- {
- OperateResult.AppendText("<<" + ListA.Rows[step - 2]["psr_type"].ToString() + ":" + code.Text + "错误,已被序列号" + temSn + "使用\n", Color.Red);
- OperateResult.AppendText(">>请输入" + ListA.Rows[step - 2]["psr_type"].ToString() + "\n", Color.Black, code);
- return false;
- }
- }
- break;
- case "NETCODE":
- //验证是否MAC和BT重复
- if (hs.ContainsValue(imeif))
- {
- foreach (DictionaryEntry de in hs)
- {
- //拿到重复的项
- if (de.Value.ToString() == imeif)
- {
- OperateResult.AppendText("<<" + ListA.Rows[step - 2]["psr_type"].ToString() + ":" + imeif + "错误," + de.Key + "已录\n", Color.Red);
- OperateResult.AppendText(">>请输入" + ListA.Rows[step - 2]["psr_type"].ToString() + "\n", Color.Black, code);
- return false;
- }
- }
- }
- //校验网标是否存在
- string teSn = dh.getFieldDataByCondition("makeserial", "ms_sncode", "MS_" + type + "='" + imeif + "' and ms_status in (0,1,2,3) and ms_id <> '" + oMsid + "' and nvl(ms_nextmacode,' ')=' '").ToString();
- if (teSn != "")
- {
- OperateResult.AppendText("<<" + ListA.Rows[step - 2]["psr_type"].ToString() + ":" + imeif + "错误,已被序列号" + teSn + "使用\n", Color.Red);
- OperateResult.AppendText(">>请输入" + ListA.Rows[step - 2]["psr_type"].ToString() + "\n", Color.Black, code);
- return false;
- }
- else
- {
- //校验在sninfo表中是否存在
- teSn = dh.getFieldDataByCondition("sninfo", "si_sn", "si_" + type + "='" + imeif + "' and si_id <>'" + siid + "'").ToString();
- if (teSn != "")
- {
- OperateResult.AppendText("<<" + ListA.Rows[step - 2]["psr_type"].ToString() + ":" + imeif + "错误,已被序列号" + teSn + "使用\n", Color.Red);
- OperateResult.AppendText(">>请输入" + ListA.Rows[step - 2]["psr_type"].ToString() + "\n", Color.Black, code);
- return false;
- }
- }
- break;
- }
- if (step == ListA.Rows.Count + 1)
- {
- if (CollectRemark.Checked || SameReamrk.Checked)
- {
- if (Remark.Text == "")
- {
- OperateResult.AppendText(">>备注栏信息为空,录入备注信息\n", Color.Black);
- Remark.SelectAll();
- Remark.Focus();
- imei.Replace(code.Text, "");
- return false;
- }
- if (IFONLY.Checked)
- {
- if (!CheckPre())
- {
- imei.Replace(code.Text, "");
- return false;
- }
- 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();
- imei.Replace(code.Text, "");
- return false;
- }
- LogicHandler.CollectRemarkInf(show_sncode.Text, "", "", ms_macode.Text, ma_prodcode.Text, Remark.Text);
- OperateResult.AppendText(">>备注:" + Remark.Text + "\n", Color.Black);
- if (CollectRemark.Checked)
- {
- Remark.Text = "";
- }
- }
- else
- {
- if (!CheckPre())
- {
- imei.Replace(code.Text, "");
- return false;
- }
- LogicHandler.CollectRemarkInf(show_sncode.Text, "", "", ms_macode.Text, ma_prodcode.Text, Remark.Text);
- OperateResult.AppendText(">>备注:" + Remark.Text + "\n", Color.Black);
- if (CollectRemark.Checked)
- {
- Remark.Text = "";
- }
- }
- }
- }
- //满足规则,则采集
- if (type == "MAC" || type == "BT")
- {
- hs.Add(ListA.Rows[step - 2]["psr_type"].ToString(), macOrBt);
- }
- else
- {
- hs.Add(ListA.Rows[step - 2]["psr_type"].ToString(), imeif);
- }
- //说明已经是最后一个校验规则
- if (step == ListA.Rows.Count + 1)
- {
- return SetStepResult();
- }
- else
- {
- OperateResult.AppendText(">>请输入" + ListA.Rows[step - 1]["psr_type"] + "\n", Color.Green, code);
- return true;
- }
- }
- //校验备注前缀
- 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 Boolean SetStepResult()
- {
- if (LogicHandler.snChangeAndBurn(TSN, SN, User.UserSourceCode, User.UserCode, ms_macode.Text, ChangeResult.Checked ? 1 : 0, (hs.ContainsKey("IMEI1") ? hs["IMEI1"].ToString() : ""), (hs.ContainsKey("IMEI2") ? hs["IMEI2"].ToString() : ""), (hs.ContainsKey("IMEI3") ? hs["IMEI3"].ToString() : ""), "", (hs.ContainsKey("NETCODE") ? hs["NETCODE"].ToString() : ""), "", "", "", "", (hs.ContainsKey("MAC") ? hs["MAC"].ToString() : ""), (hs.ContainsKey("BT") ? hs["BT"].ToString() : ""), "", "", "", out errorMessage))
- {
- OperateResult.AppendText("<<序列号" + TSN + "成功转换为" + SN + "\n<<关联采集成功\n", Color.Green);
- //写入日志
- LogManager.DoLog("修改序列号:" + TSN + "为" + SN + "成功!" + "操作人:" + User.UserCode);
- //记录日志
- LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_macode.Text, User.UserLineCode, User.UserSourceCode, "序列烧录转换", TSN + "转换为" + SN, SN, "");
- //获取剩余数,刷新页面
- sql.Clear();
- sql.Append("select mcd_inqty from makecraftdetail where mcd_macode='" + ms_macode.Text + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
- dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- if (dt.Rows.Count > 0)
- {
- remain_qty.Text = ma_qty - int.Parse(dt.Rows[0]["mcd_inqty"].ToString()) + "";
- }
- //更新页面计数+1
- count.Text = int.Parse(count.Text) + 1 + "";
- //完成之后,清除信息
- clearInfo();
- OperateResult.AppendText(">>请输入TSN号\n", Color.Black);
- }
- else
- {
- OperateResult.AppendText(">>" + errorMessage + "\n", Color.Red, code);
- OperateResult.AppendText(">>请重新输入TSN\n", Color.Black, code);
- // //清空信息
- clearInfo();
- }
- code.Text = "";
- return false;
- }
- /// <summary>
- /// 工单号变化时,带出校验规则
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void ms_macode_TextChanged(object sender, EventArgs e)
- {
- hasSnList = false;
- hasMakeRule = false;
- //清空
- TSNPre.Text = "";
- TSNLength.Text = "";
- SNPre.Text = "";
- SNLength.Text = "";
- //取消勾选
- TSNPre_checkBox.Checked = false;
- TSNLength_checkBox.Checked = false;
- SNPre_checkBox.Checked = false;
- SNLength_checkBox.Checked = false;
- //设置可编辑
- TSNLength.Enabled = true;
- TSNPre.Enabled = true;
- SNLength.Enabled = true;
- SNPre.Enabled = true;
- TSNPre_checkBox.Enabled = true;
- TSNLength_checkBox.Enabled = true;
- SNPre_checkBox.Enabled = true;
- SNLength_checkBox.Enabled = true;
- //判断工单是否导入了序列号清单
- if (dh.CheckExist("makesnlist", "msl_makecode='" + ms_macode.Text + "' and msl_type='after'"))
- {
- hasSnList = true;
- return;
- }
- //查询表工单序列号防呆规则表
- rules = (DataTable)dh.ExecuteSql("select msr_startno from makesnrule where msr_makecode='" + ms_macode.Text + "' and msr_type='after'", "select");
- if (rules.Rows.Count > 0)
- {
- hasMakeRule = 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() != "")
- {
- SNPre.Text = rules.Rows[0]["psr_prefix"].ToString();
- SNPre.Enabled = false;
- SNPre_checkBox.Checked = true;
- SNPre_checkBox.Enabled = false;
- }
- if (rules.Rows[0]["psr_length"].ToString() != "")
- {
- SNLength.Text = rules.Rows[0]["psr_length"].ToString();
- SNLength.Enabled = false;
- SNLength_checkBox.Checked = true;
- SNLength_checkBox.Enabled = false;
- }
- }
- }
- }
- private bool checkExist(string fields)
- {
- //不存在
- if (!dh.CheckExist("makeserial", fields))
- {
- //则记录
- return false;
- }
- else
- {
- return true;
- }
- }
- private void clearInfo()
- {
- //步骤重置为0
- step = 0;
- //关联采集信息清空
- if (hs != null)
- {
- hs.Clear();
- }
- imei.Clear();
- logsql.Clear();
- show_sncode.Text = "";
- ChangeResult.Enabled = true;
- onlyPass = false;
- }
- private void cancel_Click(object sender, EventArgs e)
- {
- //清除已经采集的所有信息
- clearInfo();
- //提示用户输入TSN
- OperateResult.AppendText(">>请输入TSN\n", Color.Green);
- }
- private void ChangeResult_CheckedChanged(object sender, EventArgs e)
- {
- if (ChangeResult.Checked)
- {
- //勾选的时候提示输入TSN
- OperateResult.AppendText(">>请输入TSN号\n", Color.Black);
- }
- }
- private void Make_SeqProgramTransform_SizeChanged(object sender, EventArgs e)
- {
- asc.controlAutoSize(this);
- }
- 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 void Remark_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- {
- try
- {
- if (step == ListA.Rows.Count + 1 && (CollectRemark.Checked || SameReamrk.Checked) && Remark.Text != "")
- {
- code.Enabled = true;
- code.Focus();
- code_KeyDown(this, new KeyEventArgs(Keys.Enter));
- }
- else
- {
- code.Enabled = true;
- code.Focus();
- }
- }
- catch
- {
- code.Enabled = true;
- code.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 CollectRemark_CheckedChanged(object sender, EventArgs e)
- {
- if (CollectRemark.Checked)
- {
- SameReamrk.Checked = false;
- }
- }
- private void Remark_Enter(object sender, EventArgs e)
- {
- code.Enabled = false;
- }
- private void Remark_Leave(object sender, EventArgs e)
- {
- code.Enabled = true;
- }
- }
- }
|