123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- using System;
- 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_CollectNetCode : Form
- {
- DataHelper dh;
- AutoSizeFormClass asc = new AutoSizeFormClass();
- LogStringBuilder sql = new LogStringBuilder();
- DataTable dt;
- //当前序列号记录
- string sn_code;
- //制造单号
- string macode;
- //采集网标号
- string net_code;
- //网标查询条件ms_id
- string oMsID;
- //判断是否输入网标
- Boolean isnetcode = false;
- //打印计数
- int printcount = 0;
- int ma_unlimitin;
- public Make_CollectNetCode()
- {
- InitializeComponent();
- }
- private void Make_CollectNetCode_Load(object sender, EventArgs e)
- {
- asc.controllInitializeSize(this);
- sncode.Focus();
- dh = SystemInf.dh;
- StepCount.StepCode = User.CurrentStepCode;
- StepCount.Source = User.UserSourceCode;
- StepCount.LineCode = User.UserLineCode;
- StepCount.Dh = dh;
- StepCount.Start();
- }
- private void sncode_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- {
- string ErrorMessage2;
- string oMakeCode;
- //采集序列号
- if (!isnetcode)
- {
- if (sncode.Text == "")
- {
- OperateResult.AppendText(">>序列号不能为空\n", Color.Red);
- return;
- }
- if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage2))
- {
- //判断界面工单是否为空时的序列号是否自动归属工单
- string oStatus = "";
- if (!LogicHandler.GetMakeInfo(sncode.Text, out oMakeCode, out oStatus, out ErrorMessage2))
- {
- if (ms_makecode.Text == "")
- {
- OperateResult.AppendText(">>" + ErrorMessage2 + "\n", Color.Red, sncode);
- return;
- }
- }
- OperateResult.AppendText("<<" + sncode.Text + "\n", Color.Black);
- // 获取工单归属工单下一工序是否正确
- if (LogicHandler.CheckStepSNAndMacode(ms_makecode.Text == "" ? oMakeCode : ms_makecode.Text, User.UserSourceCode, sncode.Text, User.UserCode, out oMakeCode, out oMsID, out ErrorMessage2))
- {
- string nextstepcode = dh.getFieldDataByCondition("makeserial", "ms_nextstepcode", "ms_id='" + oMsID + "'").ToString();
- if (nextstepcode != User.CurrentStepCode)
- {
- OperateResult.AppendText("<<序列号:" + sncode.Text + "下一工序是" + nextstepcode + ",不是当前岗位的工序\n", Color.Red, sncode);
- return;
- }
- sql.Clear();
- sql.Append("select ma_code as ms_makecode,nvl(mcd_okqty,0),ma_prodcode,pr_detail,");
- sql.Append("pr_spec,ma_qty - nvl(mcd_inqty, 0) mcd_remainqty,nvl(ma_unlimitin,0) ma_unlimitin from make left join makecraftdetail on ");
- sql.Append("mcd_maid=ma_id left join product on pr_code=ma_prodcode where ma_code='" + oMakeCode + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
- dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- if (dt.Rows.Count > 0)
- {
- ma_unlimitin = int.Parse(dt.Rows[0]["ma_unlimitin"].ToString());
- BaseUtil.SetFormValue(this.Controls, dt);
- //dh.UpdateByCondition("makeserial", "ms_currentstepcode = '" + User.CurrentStepCode + "'", "ms_id = '" + oMsID + "'");
- OperateResult.AppendText(">>请输入网标\n", Color.Black);
- sn_code = sncode.Text;
- sncode.Text = "";
- isnetcode = true;
- return;
- }
- else OperateResult.AppendText(">>序列号" + sncode.Text + "没有对应工序\n", Color.Red, sncode);
- }
- else OperateResult.AppendText(">>" + ErrorMessage2 + "\n", Color.Red, sncode);
- }
- else OperateResult.AppendText(">>" + ErrorMessage2 + "\n", Color.Red, sncode);
- }
- //采集netcode
- else
- {
- if (sncode.Text == "")
- {
- OperateResult.AppendText(">>网标号不能为空\n", Color.Red);
- return;
- }
- #region
- sql.Clear();
- sql.Append("select psr_prefix,psr_length from productsnrelation where psr_prodcode = '" + ma_prodcode.Text + "' and psr_type = 'NETCODE'");
- dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- if (dt.Rows.Count > 0)
- {
- int psr_length = int.Parse(dt.Rows[0][1].ToString());
- string psr_prefix = dt.Rows[0][0].ToString();
- if (!checkLengthOrPre(psr_length, psr_prefix, "网标"))
- {
- sncode.Text = "";
- sncode.Focus();
- return;
- }
- }
- else {
- OperateResult.AppendText("<<产品" + ma_prodcode.Text + "未维护网标关联信息\n", Color.Red,sncode);
- }
- #endregion
- OperateResult.AppendText("<<" + sncode.Text + "\n", Color.Black);
- string ErrorMessage = "";
- string result = "";
- ////根据序列号获取此时网标号
- //net_code = dh.getFieldDataByCondition("makeserial", "ms_netcode", "ms_id = '" + oMsID + "'").ToString();
- if (int.Parse(mcd_remainqty.Text) <= 0 && ma_unlimitin == 0)
- {
- ErrorMessage = "工单" + ms_makecode.Text + "剩余采集数不足\n>>>请输入SN";
- OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
- return;
- }
- if (dh.CheckExist("sninfo", "si_netcode = '" + sncode.Text + "'"))
- {
- OperateResult.AppendText(">>录入错误,此网标:" + sncode.Text + "已被" + dh.getFieldDataByCondition("sninfo", "si_sn", "si_netcode = '" + sncode.Text + "'").ToString() + "使用\n", Color.Red, sncode);
- OperateResult.AppendText(">>请输入网标\n", Color.Black);
- return;
- }
- if (dh.CheckExist("makeserial", "ms_netcode = '" + sncode.Text + "'"))
- {
- OperateResult.AppendText(">>录入错误,此网标:" + sncode.Text + "已被" + dh.getFieldDataByCondition("makeserial", "ms_sncode", "ms_netcode = '" + sncode.Text + "'").ToString() + "使用\n", Color.Red, sncode);
- OperateResult.AppendText(">>请输入网标\n", Color.Black);
- return;
- }
- else
- {
- if (LogicHandler.SetStepResult(ms_makecode.Text, User.UserSourceCode, sn_code, "网标采集", "网标采集完成", User.UserCode, out ErrorMessage))
- {
- //提示正确返回时传递的信息
- if (ErrorMessage.Contains("AFTERSUCCESS"))
- OperateResult.AppendText(">>" + ErrorMessage + "\n");
- //dh.UpdateByCondition("makeserial", "ms_netcode = '" + sncode.Text + "'", "ms_id = '" + oMsID + "'");
- string si_id = dh.getFieldDataByCondition("sninfo", "max(si_id) si_id", " si_sn in (select '" + sn_code + "' from dual union select sn from makesnrelation where beforesn = '" + sn_code + "' and sn <> ' ' union select beforesn from makesnrelation where sn = '" + sn_code + "' and beforesn <> ' ') ").ToString();
- if (si_id != "")
- {
- dh.BatchInsert("update sninfo set si_netcode = :netcode,si_indate = sysdate where si_id = :osiId", new String[] { "netcode", "osiId" }, new string[] { sncode.Text },new string[] { si_id });
- }
- else
- {
- dh.BatchInsert("insert into sninfo (si_id,si_sn,si_netcode,si_indate) values (SnInfo_seq.nextval,:si_sn,:netcode,sysdate)", new String[] { "si_sn", "netcode"}, new string[] { sn_code }, new string[] { sncode.Text });
- }
- dh.BatchInsert("update makeserial set ms_netcode = :netcode where ms_id = :oMsId", new String[] { "netcode", "oMsId" }, new string[] { sncode.Text }, new string[] { oMsID.ToString() });
- OperateResult.AppendText(">>网标采集完成,执行更新\n", Color.Green);
- LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode.Text, User.UserLineCode, User.UserSourceCode, "网标采集", "采集成功", sn_code, "");
- sql.Clear();
- sql.Append("select ma_qty - nvl(mcd_inqty, 0) mcd_remainqty from make left join makecraftdetail on ");
- sql.Append("mcd_maid=ma_id left join product on pr_code=ma_prodcode where ma_code='" + ms_makecode.Text + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
- dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- BaseUtil.SetFormValue(Controls, dt);
- printcount++;
- mcd_okqty.Text = printcount + "";
- isnetcode = false;
- sncode.Text = "";
- sncode.Focus();
- }
- else
- {
- OperateResult.AppendText(">>更新错误" + ErrorMessage + "\n", Color.Red);
- }
- OperateResult.AppendText(">>请输入SN\n", Color.Black);
- }
- }
- }
- }
- private void Make_CollectNetCode_SizeChanged(object sender, EventArgs e)
- {
- asc.controlAutoSize(this);
- }
- private void Make_CollectNetCode_Activated(object sender, EventArgs e)
- {
- sncode.Focus();
- }
- /// <summary>
- /// 检验长度或者前缀是否合法
- /// </summary>
- /// <param name="checkbox"></param>
- /// <param name="c"></param>
- /// <param name="info"></param>
- private bool checkLengthOrPre(int psr_length, string psr_prefix, string TSNorSN)
- {
- //则判断输入转换前的序列号长度是否合法,不合法则提示
- if (sncode.Text.Trim().Length != psr_length && psr_length != 0)
- {
- //序列号校验错误,长度错误
- OperateResult.AppendText("<<" + TSNorSN + ":" + sncode.Text + "校验错误,长度错误\n", Color.Red, sncode);
- OperateResult.AppendText(">>请重新输入" + TSNorSN + "\n", Color.Black);
- return false;
- }
- string[] pres = psr_prefix.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("<<" + TSNorSN + ":" + sncode.Text + "校验错误,前缀错误\n", Color.Red, sncode);
- OperateResult.AppendText(">>请重新输入" + TSNorSN + "\n", Color.Black);
- return false;
- }
- return true;
- }
- private void deleteButton1_Click(object sender, EventArgs e)
- {
- if (isnetcode)
- {
- BaseUtil.CleanForm(this);
- mcd_okqty.Text = printcount + "";
- mcd_remainqty.Text = 0 + "";
- OperateResult.AppendText(">>清除完成,清重新输入SN号\n", Color.Green);
- isnetcode = false;
- sncode.Focus();
- }
- }
- }
- }
|