123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392 |
- 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_CollectBTMAC : Form
- {
- DataHelper dh;
- AutoSizeFormClass asc = new AutoSizeFormClass();
- LogStringBuilder sql = new LogStringBuilder();
- DataTable dt;
- //当前序列号记录
- string sn_code;
- //制造单号
- string macode;
- //采集BT号
- string ms_bt;
- //采集销售单号
- string sale_code;
- //采集MAC
- string ms_mac;
- //网标查询条件ms_id
- string oMsID;
- //判断是否输入BT
- Boolean isBT = false;
- //判断是否输入BT
- Boolean isMAC = false;
- //打印计数
- int printcount;
- int ma_unlimitin;
- public Make_CollectBTMAC()
- {
- InitializeComponent();
- }
- private void Make_CollectBTMAC_Load(object sender, EventArgs e)
- {
- asc.controllInitializeSize(this);
- printcount = 0;
- sncode.Focus();
- dh = SystemInf.dh;
- StepCount.StepCode = User.CurrentStepCode;
- StepCount.Source = User.UserSourceCode;
- StepCount.LineCode = User.UserLineCode;
- StepCount.Dh = dh;
- StepCount.Start();
- }
- private void Make_CollectBTMAC_Activated(object sender, EventArgs e)
- {
- sncode.Focus();
- }
- private void Make_CollectBTMAC_SizeChanged(object sender, EventArgs e)
- {
- asc.controlAutoSize(this);
- }
- private void deleteButton1_Click(object sender, EventArgs e)
- {
- isBT = false;
- isMAC = false;
- BaseUtil.CleanForm(this);
- mcd_okqty.Text = printcount + "";
- mcd_remainqty.Text = 0 + "";
- OperateResult.AppendText(">>清除完成,请输入SN号\n", Color.Green);
- 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 > 40)
- {
- sncode.Text = sncode.Text.Trim().Substring(0, 40);
- }
- //则判断输入转换前的序列号长度是否合法,不合法则提示
- 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 sncode_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- {
- if (!isMAC)
- {
- if (!isBT)
- {
- string ErrorMessage2;
- string oMakeCode;
- //由序列号获取数据
- if (sncode.Text == "")
- {
- OperateResult.AppendText(">>序列号不能为空\n", Color.Red);
- return;
- }
- if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage2))
- {
- OperateResult.AppendText("<<" + sncode.Text + "\n", Color.Black);
- // 获取工单归属工单下一工序是否正确
- if (LogicHandler.CheckStepSNAndMacode("", 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(">>请输入BT\n", Color.Black);
- sn_code = sncode.Text;
- sncode.Text = "";
- isBT = 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);
- }
- }
- else
- //采集BT
- {
- if (sncode.Text == "")
- {
- OperateResult.AppendText(">>BT号不能为空\n", Color.Red);
- return;
- }
- OperateResult.AppendText("<<" + sncode.Text + "\n", Color.Black);
- string ErrorMessage = "";
- string result = "";
- sql.Clear();
- sql.Append("select psr_prefix,psr_length from productsnrelation where psr_prodcode = '" + ma_prodcode.Text + "' and psr_type = 'BT'");
- 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, "BT"))
- {
- sncode.Text = "";
- sncode.Focus();
- return;
- }
- }
- string checkbt = sncode.Text.Replace(":", "").Replace("-", "");
- if (dh.CheckExist("MakeAddressList", "mal_makecode = '" + ms_makecode.Text + "'"))
- {
- sql.Append("select mal_bt from MakeAddressList where mal_bt = '" + checkbt + "' and mal_makecode = '" + ms_makecode.Text + "'");
- dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- if (!(dt.Rows.Count > 0))
- {
- OperateResult.AppendText(">>BT号" + checkbt + "不符合工单导入要求\n", Color.Red, sncode);
- return;
- }
- }
- else
- {
- ////根据工单号获取销售单号
- //sale_code = dh.getFieldDataByCondition("make", "ma_salecode", "ma_code = '" + ms_makecode.Text + "'").ToString();
- //sql.Clear();
- //sql.Append("select sr_startcode,sr_endcode from SaleMacBTRange where sr_sacode = '" + sale_code + "' and sr_type = 'BT'");
- //dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- //if (dt.Rows.Count > 0)
- //{
- // if (!(dt.Rows[0]["sr_startcode"].ToString().Replace(":", "").Replace("-", "").CompareTo(checkbt) <= 0 && dt.Rows[0]["sr_endcode"].ToString().Replace(":", "").Replace("-", "").CompareTo(checkbt) >= 0))
- // {
- // OperateResult.AppendText(">>BT号" + checkbt + "不符合销售单合同范围\n", Color.Red, sncode);
- // return;
- // }
- //}
- if (!LogicHandler.checkMacOrBtRange(oMsID, checkbt, "BT"))
- {
- OperateResult.AppendText(">>BT号" + checkbt + "不符合销售单合同范围\n", Color.Red, sncode);
- return;
- }
- }
- //根据序列号获取此时BT号
- //ms_bt = dh.getFieldDataByCondition("makeserial", "ms_bt", "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_bt = '" + checkbt + "'"))
- {
- OperateResult.AppendText(">>录入错误,此BT:" + checkbt + "已被" + dh.getFieldDataByCondition("sninfo", "si_sn", "si_bt = '" + checkbt + "'").ToString() + "使用\n", Color.Red, sncode);
- OperateResult.AppendText(">>请输入BT\n", Color.Black);
- return;
- }
- if (dh.CheckExist("makeserial", "ms_bt = '" + checkbt + "'"))
- {
- OperateResult.AppendText(">>录入错误,此BT:" + checkbt + "已被" + dh.getFieldDataByCondition("makeserial", "ms_sncode", "ms_bt = '" + checkbt + "'").ToString() + "使用\n", Color.Red, sncode);
- OperateResult.AppendText(">>请输入BT\n", Color.Black);
- return;
- }
- else
- {
- ms_bt = checkbt;
- OperateResult.AppendText(">>BT采集完成\n>>请输入MAC\n", Color.Green, sncode);
- isBT = false;
- isMAC = true;
- sncode.Focus();
- return;
- }
- }
- }
- else
- {
- //采集MAC
- if (sncode.Text == "")
- {
- OperateResult.AppendText(">>MAC号不能为空\n", Color.Red);
- return;
- }
- OperateResult.AppendText("<<" + sncode.Text + "\n", Color.Black);
- string ErrorMessage = "";
- string result = "";
- sql.Clear();
- sql.Append("select psr_prefix,psr_length from productsnrelation where psr_prodcode = '" + ma_prodcode.Text + "' and psr_type = 'MAC'");
- 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, "MAC"))
- {
- sncode.Text = "";
- sncode.Focus();
- return;
- }
- }
- string checkmac = sncode.Text.Replace(":", "").Replace("-", "");
- if (dh.CheckExist("MakeAddressList", "mal_makecode = '" + ms_makecode.Text + "'"))
- {
- sql.Append("select mal_mac from MakeAddressList where mal_mac = '" + checkmac + "' and mal_makecode = '" + ms_makecode.Text + "'");
- dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- if (!(dt.Rows.Count > 0))
- {
- OperateResult.AppendText(">>MAC号" + checkmac + "不符合工单导入要求\n", Color.Red, sncode);
- return;
- }
- }
- else
- {
- ////根据工单号获取销售单号
- //sale_code = dh.getFieldDataByCondition("make", "ma_salecode", "ma_code = '" + ms_makecode.Text + "'").ToString();
- //sql.Clear();
- //sql.Append("select sr_startcode,sr_endcode from SaleMacBTRange where sr_sacode = '" + sale_code + "' and sr_type = 'MAC'");
- //dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- //if (dt.Rows.Count > 0)
- //{
- // if (!(dt.Rows[0]["sr_startcode"].ToString().Replace(":", "").Replace("-", "").CompareTo(checkmac) <= 0 && dt.Rows[0]["sr_endcode"].ToString().Replace(":", "").Replace("-", "").CompareTo(checkmac) >= 0))
- // {
- // OperateResult.AppendText(">>MAC号" + checkmac + "不符合销售单合同范围\n", Color.Red, sncode);
- // return;
- // }
- //}
- if (!LogicHandler.checkMacOrBtRange(oMsID, checkmac, "MAC"))
- {
- OperateResult.AppendText(">>MAC号" + checkmac + "不符合销售单合同范围\n", Color.Red, sncode);
- return;
- }
- }
- 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_mac = '" + checkmac + "'"))
- {
- OperateResult.AppendText(">>录入错误,此MAC:" + checkmac + "已被" + dh.getFieldDataByCondition("sninfo", "si_sn", "si_mac = '" + checkmac + "'").ToString() + "使用\n", Color.Red, sncode);
- OperateResult.AppendText(">>请输入MAC\n", Color.Black);
- return;
- }
- if (dh.CheckExist("makeserial", "ms_mac = '" + checkmac + "'"))
- {
- OperateResult.AppendText(">>录入错误,此MAC:" + checkmac + "已被" + dh.getFieldDataByCondition("makeserial", "ms_sncode", "ms_mac = '" + checkmac + "'").ToString() + "使用\n", Color.Red, sncode);
- OperateResult.AppendText(">>请输入MAC\n", Color.Black);
- return;
- }
- else
- {
- if (LogicHandler.SetStepResult(ms_makecode.Text, User.UserSourceCode, sn_code, "BT/MAC采集", "BT/MAC采集完成", User.UserCode, out ErrorMessage))
- {
- //提示正确返回时传递的信息
- if (ErrorMessage.Contains("AFTERSUCCESS"))
- OperateResult.AppendText(">>" + ErrorMessage + "\n");
- 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_mac = :mac,si_bt =:bt,si_indate = sysdate where si_id = :osiId", new String[] { "mac", "bt", "osiId" }, new string[] { checkmac }, new string[] { ms_bt }, new string[] { si_id });
- }
- else
- {
- dh.BatchInsert("insert into sninfo (si_id,si_sn,si_mac,si_bt,si_indate) values (SnInfo_seq.nextval,:si_sn,:si_mac,:si_bt,sysdate)", new String[] { "si_sn", "si_mac", "si_bt" }, new string[] { sn_code }, new string[] { checkmac }, new string[] { ms_bt });
- }
- dh.BatchInsert("update makeserial set ms_mac = :mac,ms_bt =:bt where ms_id = :oMsId", new String[] { "mac", "bt", "oMsId" }, new string[] { checkmac }, new string[] { ms_bt }, new string[] { oMsID.ToString() });
- OperateResult.AppendText(">>BT/MAC采集完成,执行更新\n", Color.Green);
- LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode.Text, User.UserLineCode, User.UserSourceCode, "BT/MAC采集", "采集成功", sn_code, "");
- if (CollectRemark.Checked && Remark.Text != "")
- {
- LogicHandler.CollectRemarkInf(sn_code, "", "", ms_makecode.Text, ma_prodcode.Text, Remark.Text);
- }
- 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 + "";
- isMAC = false;
- sncode.Text = "";
- sncode.Focus();
- }
- else
- {
- OperateResult.AppendText(">>采集错误" + ErrorMessage + "\n", Color.Red);
- return;
- }
- OperateResult.AppendText(">>请输入SN\n", Color.Black);
- }
- }
- }
- }
- }
- }
|