123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122 |
- using LabelManager2;
- using System;
- using System.Data;
- using System.Text;
- using System.Windows.Forms;
- using UAS_MES_NEW.DataOperate;
- using UAS_MES_NEW.Entity;
- using UAS_MES_NEW.PublicMethod;
- using System.Drawing;
- using System.Threading;
- using UAS_MES_NEW.PublicForm;
- using System.IO.Ports;
- using System.IO;
- using System.Text.RegularExpressions;
- using System.Collections.Generic;
- using Seagull.BarTender.Print;
- using static System.Windows.Forms.VisualStyles.VisualStyleElement;
- namespace UAS_MES_NEW.Packing
- {
- public partial class Packing_PackageCollectionWeigh_ReadLine : Form
- {
- DataHelper dh;
- DataTable dt;
- LogStringBuilder sql = new LogStringBuilder();
- AutoSizeFormClass asc = new AutoSizeFormClass();
- Document doc;
- Engine engine;
- Thread thread;
- DataTable Dbfind;
- string ErrorMessage = "";
- string oMakeCode = "";
- string oMsID = "";
- string oMsStatus = "";
- string PR_CHECKCARTONW = "0";
- //称量的标准重量
- double Weight;
- //最大重量
- double MaxWeight;
- //最小重量
- double MinWeight;
- string ActWeigh = "0";
- Regex re = new Regex("\\d+.\\d+");
- decimal StandardQTY = 0;
- string oOutBoxCode = "";
- string LastSncode;
- //创建串口实例
- SerialPort serialPort1 = new SerialPort();
- //true的时候表示从串口读取数据
- bool GetData = true;
- public Packing_PackageCollectionWeigh_ReadLine()
- {
- InitializeComponent();
- }
- //创建打印进程
- private void NewPrint()
- {
- try
- {
- engine = new Engine(true);
- BaseUtil.WriteLbl();
- }
- catch (Exception ex)
- {
- OperateResult.AppendText("未正确安装BarTender软件\n", Color.Red);
- }
- }
- private void Make_PackageCollectionWeigh_Load(object sender, EventArgs e)
- {
- ComList.Text = BaseUtil.GetCacheData("PortName").ToString();
- Baurate.Text = BaseUtil.GetCacheData("BaudRate").ToString();
- //设置DbFind的必须的数据
- PrintNum.Text = "1";
- asc.controllInitializeSize(this);
- thread = new Thread(NewPrint);
- SetLoadingWindow stw = new SetLoadingWindow(thread, "初始化打印程序");
- BaseUtil.SetFormCenter(stw);
- stw.ShowDialog();
- try
- {
- OutBoxLength.Text = BaseUtil.GetCacheData("OutBoxLength").ToString();
- PreFix.Text = BaseUtil.GetCacheData("PreFix").ToString();
- Remark_PreFix.Text = BaseUtil.GetCacheData("Remark_PreFix").ToString();
- }
- catch (Exception) { }
- thread = new Thread(getSerialData);
- try
- {
- GetData = true;
- serialPort1.PortName = ComList.Text;
- serialPort1.BaudRate = int.Parse(Baurate.Text);
- serialPort1.Open();
- thread.Start();
- }
- catch (Exception mes)
- {
- if (Baurate.Text == "" || ComList.Text == "")
- OperateResult.AppendText(">>请先在电子秤调试界面维护波特率和串口\n", Color.Red);
- else
- OperateResult.AppendText(">>" + mes.Message + "\n", Color.Red);
- }
- sn_code.Focus();
- dh = SystemInf.dh;
- StepCount.StepCode = User.CurrentStepCode;
- StepCount.Source = User.UserSourceCode;
- StepCount.LineCode = User.UserLineCode;
- StepCount.Dh = dh;
- StepCount.Start();
- }
- private void getSerialData()
- {
- if (serialPort1.IsOpen)
- {
- if (!SystemInf.OpenPort.Contains(serialPort1.PortName))
- {
- SystemInf.OpenPort.Add(serialPort1.PortName);
- try
- {
- while (GetData)
- {
- try
- {
- int len = serialPort1.BytesToRead;
- Byte[] readBuffer = new Byte[len];
- serialPort1.Read(readBuffer, 0, len); //将数据读入缓存
- string weigh = Encoding.Default.GetString(readBuffer);
- if (weigh != "")
- {
- weight.Text = re.Match(weigh.Trim()).Groups[0].Value;
- }
- }
- catch (Exception)
- {
- GetData = false;
- }
- }
- }
- catch (IOException ex) { MessageBox.Show(ex.Message); }
- }
- else
- MessageBox.Show("端口已被占用,请关闭其他窗口");
- }
- }
- private void Make_PackageCollectionWeigh_SizeChanged(object sender, EventArgs e)
- {
- asc.controlAutoSize(this);
- }
- private void Make_PackageCollectionWeigh_Activated(object sender, EventArgs e)
- {
- pa_outboxcode.Focus();
- }
- //刷新表单的数据的数据
- private void LoadData()
- {
- //加载表单数据
- string Err = "";
- sql.Clear();
- sql.Append("select pa_prodcode,pr_cartonmaxw,pa_salecode,pa_remark,pa_makecode,pr_cartonunit,pr_code,pr_cartonminw,pr_cartongw,pa_outboxcode,pa_sccode,nvl(pa_downstatus,0) pa_downstatus,pa_checkno,");
- sql.Append("pa_status,pr_packrule,pr_detail,nvl(pr_sendchecktype,'LineCode')pr_sendchecktype,pa_packageqty,nvl(pa_standardqty,0)pa_standardqty,nvl(pr_outboxinnerqty,0)pr_outboxinnerqty,nvl(PR_CHECKCARTONW,'0') PR_CHECKCARTONW,pa_currentqty from package left join ");
- sql.Append("product on pa_prodcode=pr_code where pa_outboxcode='" + pa_outboxcode.Text + "'");
- Err = "箱号";
- DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- if (dt.Rows.Count > 0)
- {
- //重量的临时变量
- string _weight = dt.Rows[0]["pr_cartongw"].ToString();
- string _maxweight = dt.Rows[0]["pr_cartonmaxw"].ToString();
- string _minweight = dt.Rows[0]["pr_cartonminw"].ToString();
- PR_CHECKCARTONW = dt.Rows[0]["PR_CHECKCARTONW"].ToString();
- if (dt.Rows[0]["pa_salecode"].ToString() != "")
- {
- ms_salecode.Text = dt.Rows[0]["pa_salecode"].ToString();
- }
- if (PR_CHECKCARTONW != "0")
- checkweightlabel.Text = "需要检测重量";
- else
- checkweightlabel.Text = "不需检测重量";
- //赋值重量单位
- Weight = double.Parse(_weight == "" ? "0" : _weight);
- MaxWeight = double.Parse(_maxweight == "" ? "0" : _maxweight);
- MinWeight = double.Parse(_minweight == "" ? "0" : _minweight);
- //记录该数据保证在修改不被允许的前提下能偶回复之前的值
- StandardQTY = decimal.Parse(dt.Rows[0]["pr_outboxinnerqty"].ToString());
- BaseUtil.SetFormValue(this.Controls, dt);
- if (pa_standardqty.Text != "0")
- pr_outboxinnerqty.Text = pa_standardqty.Text;
- if (Weight - MinWeight == MaxWeight - Weight)
- pr_cartonboxgw.Text = Weight + "±" + (MaxWeight - Weight) + dt.Rows[0]["pr_cartonunit"].ToString();
- else
- pr_cartonboxgw.Text = MinWeight + "-" + MaxWeight + dt.Rows[0]["pr_cartonunit"].ToString();
- }
- LoadCheckQTY();
- LoadCollectedNum();
- }
- private void LoadGridData()
- {
- //加载Grid数据
- dt = (DataTable)dh.ExecuteSql("select pa_outboxcode,pa_prodcode,pd_barcode,pd_innerqty,pa_indate from packageDetail left join package on pa_id=pd_paid where pa_outboxcode='" + pa_outboxcode.Text + "'", "select");
- BaseUtil.FillDgvWithDataTable(PackageDetail, dt);
- //更新界面的采集数量
- pa_currentqty.Text = dh.getFieldDataByCondition("package", "pa_currentqty", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString();
- }
- private void Print_Click(object sender, EventArgs e)
- {
- if (PrintLabel.Items.Count != 0)
- {
- if (dh.getFieldDataByCondition("package", "pa_status", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString() == "1")
- {
- dh.ExecuteSql("update package set pa_printcount=pa_printcount+1 where pa_outboxcode='" + pa_outboxcode.Text + "'", "update");
- //doc = lbl.Documents.Open(PrintLabel.Text);
- if (Print.BarTenderS(Tag.ToString(), ref engine, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), PrintList.Text, pa_outboxcode.Text, int.Parse(PrintNum.Text), oMakeCode == "" ? pa_makecode.Text : oMakeCode, pr_code.Text, "卡通箱标", "0", out ErrorMessage))
- {
- OperateResult.AppendText(">>开始打印箱号" + pa_outboxcode.Text + "\n", Color.Black);
- }
- else
- {
- OperateResult.AppendText(ErrorMessage + "\n", Color.Red);
- }
- if (PrintSecond.Checked)
- {
- if (Print.BarTenderS(Tag.ToString(), ref engine, PrintLabel1.Text, PrintLabel1.SelectedValue.ToString(), PrintList1.Text, pa_outboxcode.Text, int.Parse(PrintNum1.Text), oMakeCode == "" ? pa_makecode.Text : oMakeCode, pr_code.Text, "卡通箱标", "0", out ErrorMessage))
- {
- OperateResult.AppendText(">>开始打印箱号" + pa_outboxcode.Text + "\n", Color.Black);
- }
- else
- {
- OperateResult.AppendText(ErrorMessage + "\n", Color.Red);
- }
- }
- if (!AutoGenBoxCode.Checked)
- {
- pa_outboxcode.Focus();
- pa_outboxcode.SelectAll();
- }
- else
- {
- sn_code.Focus();
- sn_code.SelectAll();
- }
- }
- else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "尚未封箱,请封箱后执行打印\n", Color.Red);
- }
- else OperateResult.AppendText(">>产品" + pr_code.Text + "未维护打印标签\n", Color.Red);
- }
- //加载工单信息和装箱明细信息
- private void pa_code_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- {
- if (CheckOutBoxLength())
- {
- LoadData();
- LoadGridData();
- sn_code.Focus();
- }
- }
- }
- //输入序列号的回车事件
- private void barcode_KeyDown(object sender, KeyEventArgs e)
- {
- //当用户输入回车键的时候
- if (e.KeyCode == Keys.Enter)
- {
- if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
- {
- dt = (DataTable)dh.ExecuteSql("select ms_sncode from makeserial where ms_imei1='" + sn_code.Text + "' order by ms_id desc", "select");
- if (dt.Rows.Count > 0)
- {
- sn_code.Text = dt.Rows[0]["ms_sncode"].ToString();
- }
- else
- {
- dt = (DataTable)dh.ExecuteSql("select ms_sncode from makeserial where ms_imei2='" + sn_code.Text + "' order by ms_id desc", "select");
- if (dt.Rows.Count > 0)
- {
- sn_code.Text = dt.Rows[0]["ms_sncode"].ToString();
- }
- else
- {
- dt = (DataTable)dh.ExecuteSql("select mil_sncode from makeimeilist where mil_imei1='" + sn_code.Text + "' order by mil_id desc", "select");
- if (dt.Rows.Count > 0)
- {
- sn_code.Text = dt.Rows[0]["mil_sncode"].ToString();
- }
- else
- {
- dt = (DataTable)dh.ExecuteSql("select mil_sncode from makeimeilist where mil_imei2='" + sn_code.Text + "' order by mil_id desc", "select");
- if (dt.Rows.Count > 0)
- {
- sn_code.Text = dt.Rows[0]["mil_sncode"].ToString();
- }
- }
- }
- }
- dt = (DataTable)dh.ExecuteSql("select ms_status,ms_id,ms_makecode,ms_craftcode,ms_prodcode from makeserial where ms_sncode ='" + sn_code.Text + "' order by ms_id desc", "select");
- if (LogicHandler.CheckStepSNAndMacode("", User.UserSourceCode, sn_code.Text, User.UserCode, out oMakeCode, out oMsID, out ErrorMessage) || (dt.Rows.Count > 0 && dt.Rows[0]["ms_status"].ToString() == "2"))
- {
- if (oMsID == "" || oMsID == "null" || oMsID == "0")
- {
- oMsID = dt.Rows[0]["ms_id"].ToString();
- oMsStatus = dt.Rows[0]["ms_status"].ToString();
- oMakeCode = dt.Rows[0]["ms_makecode"].ToString();
- }
- if (oMsStatus == "2")
- {
- string prodcode = dt.Rows[0]["ms_prodcode"].ToString();
- string craftcode = dt.Rows[0]["ms_craftcode"].ToString();
- string craftstepcode = dh.getFieldDataByCondition("craft left join craftdetail on cr_id =cd_crid", "cd_stepcode", "cr_prodcode='" + prodcode + "' and cr_code='" + craftcode + "' and cd_stepcode='" + User.CurrentStepCode + "'").ToString();
- if (craftstepcode == "")
- {
- OperateResult.AppendText("工序" + User.CurrentStepCode + "不在途程" + craftcode + "内,不允许采集\n", Color.Red);
- return;
- }
- }
- string nextstepcode = dh.getFieldDataByCondition("makeserial", "ms_nextstepcode", "ms_id='" + oMsID + "'").ToString();
- if (nextstepcode != "" && nextstepcode != User.CurrentStepCode)
- {
- string stname = dh.getFieldDataByCondition("step", "st_name", "st_code='" + nextstepcode + "'").ToString();
- OperateResult.AppendText("<<序列号:" + sn_code.Text + "下一工序是" + stname + ",不是当前岗位的工序\n", Color.Red, sn_code);
- return;
- }
- //PR_CHECKCARTONW = dh.getFieldDataByCondition("craftdetail left join craft on cr_id=cd_crid left join makeserial on ms_craftcode =cr_code", "nvl(cd_ifweigh,'0') cd_ifweigh", "ms_sncode='" + sn_code.Text + "' and ms_makecode='" + oMakeCode + "' and cd_stepcode = '" + User.CurrentStepCode + "'").ToString();
- sql.Clear();
- sql.Append("select nvl(ms_iostatus,0) ms_iostatus,ms_outno,ms_salecode,ms_makecode,ms_prodcode,nvl(pa_downstatus,0) pa_downstatus,pa_sccode,pa_checkno,pr_packrule,");
- sql.Append("nvl(pr_outboxinnerqty,0)pr_outboxinnerqty,nvl(pr_sendchecktype,'LineCode')pr_sendchecktype from makeserial left join product on ms_prodcode=pr_code left join packagedetail ");
- sql.Append("on pd_barcode=ms_sncode left join package on pa_id =pd_paid where ms_id='" + oMsID + "'");
- dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- string ms_makecode = "";
- string ms_prodcode = "";
- string ms_iostatus = "";
- string ms_outno = "";
- string ms_salecode_text = "";
- if (dt.Rows.Count > 0)
- {
- StandardQTY = decimal.Parse(dt.Rows[0]["pr_outboxinnerqty"].ToString());
- ms_makecode = dt.Rows[0]["ms_makecode"].ToString();
- ms_prodcode = dt.Rows[0]["ms_prodcode"].ToString();
- ms_iostatus = dt.Rows[0]["ms_iostatus"].ToString();
- ms_outno = dt.Rows[0]["ms_outno"].ToString();
- ms_salecode_text = dt.Rows[0]["ms_salecode"].ToString();
- if (locksalecode.Checked && ms_salecode.Text != "" && ms_salecode.Text != ms_salecode_text)
- {
- OperateResult.AppendText(">>序列号" + sn_code.Text + "所属订单号" + ms_salecode_text + "与界面订单号" + ms_salecode.Text + "不同,无法采集\n", Color.Red, sn_code);
- return;
- }
- BaseUtil.SetFormValue(this.Controls, dt);
- }
- if (dt.Rows[0]["ms_outno"].ToString() != "")
- {
- OperateResult.AppendText(">>序列号" + sn_code.Text + "已被出货单" + dt.Rows[0]["ms_outno"].ToString() + "采集,不允许操作\n", Color.Red, sn_code);
- return;
- }
- if (dt.Rows[0]["ms_iostatus"].ToString() != "0")
- {
- OperateResult.AppendText(">>序列号" + sn_code.Text + "已入库不允许采集\n", Color.Red, sn_code);
- return;
- }
- if (pa_standardqty.Text != "0" && pa_standardqty.Text != "")
- {
- pr_outboxinnerqty.Text = pa_standardqty.Text;
- }
- if (pa_outboxcode.Text == "")
- {
- string boxcode = dh.getFieldDataByCondition("makeserial", "ms_outboxcode", "ms_id='" + oMsID + "'").ToString();
- if (boxcode != "")
- {
- pa_outboxcode.Text = boxcode;
- LoadGridData();
- }
- else
- {
- if (AutoGenBoxCode.Checked && (pa_status.Text == "1" || pa_status.Text == ""))
- {
- pa_outboxcode.Text = LogicHandler.GetOutBoxCode("PACKAGE", ms_makecode, pr_code.Text, User.UserCode);
- LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "卡通箱采集", "卡通箱" + pa_outboxcode.Text + "自动生成", sn_code.Text, PreFix.Text + ":" + OutBoxLength.Text);
- }
- }
- }
- if (pa_outboxcode.Text == "")
- {
- OperateResult.AppendText(">>箱号不能为空\n", Color.Red, sn_code);
- return;
- }
- //判断箱内总数必须大于0
- if (pr_outboxinnerqty.Text == "" || pr_outboxinnerqty.Text == "0")
- {
- OperateResult.AppendText(">>箱内容量必须大于0\n", Color.Red);
- return;
- }
- sql.Clear();
- sql.Append("select nvl(pa_iostatus,0) pa_iostatus,pa_outno,pa_mothercode from package where pa_outboxcode='" + pa_outboxcode.Text + "'");
- dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- string MotherBoxCode = "";
- if (dt.Rows.Count > 0)
- {
- if (dt.Rows[0]["pa_mothercode"].ToString() != "")
- {
- MotherBoxCode = dt.Rows[0]["pa_mothercode"].ToString();
- }
- if (dt.Rows[0]["pa_outno"].ToString() != "")
- {
- OperateResult.AppendText(">>卡通箱" + pa_outboxcode.Text + "已被出货单" + dt.Rows[0]["pa_outno"].ToString() + "采集,不允许操作\n", Color.Red, sn_code);
- return;
- }
- if (dt.Rows[0]["pa_iostatus"].ToString() != "0")
- {
- OperateResult.AppendText(">>卡通箱" + pa_outboxcode.Text + "处于入库状态,不允许操作\n", Color.Red, sn_code);
- return;
- }
- }
- //如果未勾选了取消录入
- if (!Cancel.Checked)
- {
- string ms_outboxcode = dh.getFieldDataByCondition("makeserial", "ms_outboxcode", "ms_id='" + oMsID + "'").ToString();
- if (ms_outboxcode != "")
- {
- if (ms_outboxcode == pa_outboxcode.Text)
- OperateResult.AppendText(">>序列号" + sn_code.Text + "已在本箱内\n", Color.Red, sn_code);
- else
- OperateResult.AppendText(">>序列号" + sn_code.Text + "已采集至箱" + ms_outboxcode + "\n", Color.Red, sn_code);
- LoadData();
- }
- else
- {
- //满箱之后采集下一个之前自动清除内容,生成新的箱号
- if ((AutoGenBoxCode.Checked && pa_currentqty.Text != "" && pr_outboxinnerqty.Text == pa_currentqty.Text) || (AutoGenBoxCode.Checked && pa_status.Text == "1"))
- {
- pa_currentqty.Text = "";
- pa_outboxcode.Text = "";
- pa_status.Text = "0";
- BaseUtil.CleanDGVData(PackageDetail);
- pa_outboxcode.Text = LogicHandler.GetOutBoxCode("PACKAGE", ms_makecode, pr_code.Text, User.UserCode);
- LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "卡通箱采集", "卡通箱" + pa_outboxcode.Text + "自动生成", sn_code.Text, PreFix.Text + ":" + OutBoxLength.Text);
- }
- if (!CheckOutBoxLength(ms_salecode_text))
- {
- return;
- }
- ////箱号不存在的情况
- if (LogicHandler.Packing(sn_code.Text, pa_outboxcode.Text, AutoGenBoxCode.Checked, "标准", User.UserSourceCode, User.UserCode, pr_outboxinnerqty.Text, Cancel.Checked, out oOutBoxCode, out ErrorMessage))
- {
- //提示正确返回时传递的信息
- if (ErrorMessage.Contains("AFTERSUCCESS"))
- OperateResult.AppendText(">>" + ErrorMessage + "\n");
- LoadCheckQTY();
- LoadCollectedNum();
- OperateResult.AppendText(">>序列号" + sn_code.Text + "采集成功!\n", Color.Green);
- LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "卡通箱采集", "卡通箱" + pa_outboxcode.Text + "采集成功", sn_code.Text, "");
- LastSncode = sn_code.Text;
- //满箱更新状态为1
- LoadData();
- dh.ExecuteSql("update packagedetail set pd_innerqty=(select pa_packageqty from package where pa_outboxcode='" + pa_outboxcode.Text + "') where pd_innerboxcode='" + pa_outboxcode.Text + "'", "update");
- //如果母箱号不为空,需要更新总数
- if (MotherBoxCode != "")
- {
- DataTable dt = (DataTable)dh.ExecuteSql("select pa_mothercode,pa_type from package where pa_outboxcode='" + MotherBoxCode + "'", "select");
- if (dt.Rows.Count > 0)
- {
- if (dt.Rows[0]["pa_type"].ToString() == "2")
- {
- string MotherCode2 = dt.Rows[0]["pa_mothercode"].ToString();
- //更新大箱数量
- dh.ExecuteSql("update package set PA_TOTALQTY=(select sum(pd_innerqty) from packagedetail left join package on pa_id=pd_paid where pa_outboxcode='" + MotherBoxCode + "') where pa_outboxcode='" + MotherBoxCode + "'", "update");
- //外层有栈板则更新栈板数量
- if (MotherCode2 != "")
- {
- dh.ExecuteSql("update packagedetail set pd_innerqty=(select sum(pd_innerqty) from packagedetail where pd_outboxcode='" + MotherBoxCode + "') where pd_innerboxcode='" + MotherBoxCode + "'", "update");
- dh.ExecuteSql("update package set PA_TOTALQTY=(select sum(pd_innerqty) from packagedetail left join package on pa_id=pd_paid where pa_outboxcode='" + MotherCode2 + "') where pa_outboxcode='" + MotherCode2 + "'", "update");
- }
- }
- if (dt.Rows[0]["pa_type"].ToString() == "3")
- {
- dh.ExecuteSql("update package set PA_TOTALQTY=(select sum(pd_innerqty) from packagedetail left join package on pa_id=pd_paid where pa_outboxcode='" + MotherBoxCode + "') where pa_outboxcode='" + MotherBoxCode + "'", "update");
- }
- }
- }
- //采集完后如果是第一个装的序列号,把序列号的NextStepCode赋值给箱号
- if (pa_currentqty.Text == "1")
- {
- dh.UpdateByCondition("package", "pa_nextstep='" + User.CurrentStepCode + "', PA_CURRENTSTEP = '" + User.CurrentStepCode + "'", "pa_outboxcode='" + pa_outboxcode.Text + "'");
- }
- LoadGridData();
- sn_code.Clear();
- if (int.Parse(pa_currentqty.Text == "" ? "0" : pa_currentqty.Text) == int.Parse(pr_outboxinnerqty.Text))
- {
- ActWeigh = weight.Text == "" ? "0" : weight.Text.Replace("kg", "").Replace("g", "").Trim();
- float weigh = float.Parse(ActWeigh);
- if (PR_CHECKCARTONW != "0")
- {
- if (MinWeight == 0 || MaxWeight == 0)
- {
- OperateResult.AppendText(">>产品" + pr_code.Text + "未维护卡通箱重量范围\n", Color.Red);
- return;
- }
- if (!(weigh >= MinWeight && weigh <= MaxWeight) || weigh == 0)
- {
- OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "重量不符合标准重量\n", Color.Red);
- LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "卡通箱称重", "称量不符合要求:" + weight.Text.Trim(), pa_outboxcode.Text, "");
- LogicHandler.RecordProdWeight(pa_outboxcode.Text, "CARTON", float.Parse(ActWeigh.ToString()), "kg", User.UserLineCode, pr_code.Text, User.UserSourceCode, User.UserName);
- return;
- }
- }
- dh.UpdateByCondition("package", "pa_status=1,pa_totalqty=pa_currentqty,pa_packageqty=pa_currentqty,pa_weight=" + weigh + "", "pa_outboxcode='" + pa_outboxcode.Text + "'");
- pa_standardqty.Text = "";
- pa_status.Text = "1";
- OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "满箱封箱成功\n", Color.Green);
- LogicHandler.RecordProdWeight(pa_outboxcode.Text, "CARTON", float.Parse(ActWeigh.ToString()), "kg", User.UserLineCode, pr_code.Text, User.UserSourceCode, User.UserName);
- LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "卡通箱称重", "称量完成:" + weight.Text.Trim(), pa_outboxcode.Text, "");
- if (LogicHandler.OutBoxStepPass(pa_outboxcode.Text, ms_makecode, User.UserSourceCode, User.UserCode, "卡通箱:" + pa_outboxcode.Text + "整箱过站", "卡通箱整箱过站", out ErrorMessage))
- {
- dh.UpdateByCondition("package", "pa_nextstep='" + dh.getFieldDataByCondition("packagedetail left join makeserial on ms_sncode=pd_barcode and ms_makecode=pd_makecode", "max(ms_nextstepcode)", "pd_outboxcode='" + pa_outboxcode.Text + "'").ToString() + "', PA_CURRENTSTEP = '' ", "pa_outboxcode='" + pa_outboxcode.Text + "'");
- }
- else
- {
- OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
- }
- LoadCheckQTY();
- LoadCollectedNum();
- OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "称量完成\n", Color.Green);
- if (AutoPrint.Checked)
- Print_Click(new object(), new EventArgs());
- if (!CollecRemark.Checked)
- {
- if (!AutoGenBoxCode.Checked)
- {
- pa_outboxcode.Focus();
- pa_outboxcode.SelectAll();
- }
- else
- {
- sn_code.Focus();
- sn_code.SelectAll();
- }
- }
- else
- {
- pa_remark.SelectAll();
- pa_remark.Focus();
- }
- }
- }
- else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
- }
- }
- //勾选了取消箱号先验证箱号存不存在,存在的话移除掉,重新加载一次数据
- else
- {
- if (LogicHandler.Packing(sn_code.Text, pa_outboxcode.Text, AutoGenBoxCode.Checked, "标准", User.UserSourceCode, User.UserCode, pr_outboxinnerqty.Text, Cancel.Checked, out oOutBoxCode, out ErrorMessage))
- {
- dh.UpdateByCondition("makeserial", "ms_outboxcode=''", "ms_id='" + oMsID + "'");
- dh.ExecuteSql("update packagedetail set pd_innerqty=(select pa_packageqty from package where pa_outboxcode='" + pa_outboxcode.Text + "') where pd_innerboxcode='" + pa_outboxcode.Text + "'", "update");
- //如果母箱号不为空,需要更新总数
- if (MotherBoxCode != "")
- {
- DataTable dt = (DataTable)dh.ExecuteSql("select pa_mothercode,pa_type from package where pa_outboxcode='" + MotherBoxCode + "'", "select");
- if (dt.Rows.Count > 0)
- {
- if (dt.Rows[0]["pa_type"].ToString() == "2")
- {
- string MotherCode2 = dt.Rows[0]["pa_mothercode"].ToString();
- //更新大箱数量
- dh.ExecuteSql("update package set PA_TOTALQTY=(select sum(pd_innerqty) from packagedetail left join package on pa_id=pd_paid where pa_outboxcode='" + MotherBoxCode + "') where pa_outboxcode='" + MotherBoxCode + "'", "update");
- //外层有栈板则更新栈板数量
- if (MotherCode2 != "")
- {
- dh.ExecuteSql("update packagedetail set pd_innerqty=(select sum(pd_innerqty) from packagedetail where pd_outboxcode='" + MotherBoxCode + "') where pd_innerboxcode='" + MotherBoxCode + "'", "update");
- dh.ExecuteSql("update package set PA_TOTALQTY=(select sum(pd_innerqty) from packagedetail left join package on pa_id=pd_paid where pa_outboxcode='" + MotherCode2 + "') where pa_outboxcode='" + MotherCode2 + "'", "update");
- }
- }
- if (dt.Rows[0]["pa_type"].ToString() == "3")
- {
- dh.ExecuteSql("update package set PA_TOTALQTY=(select sum(pd_innerqty) from packagedetail left join package on pa_id=pd_paid where pa_outboxcode='" + MotherBoxCode + "') where pa_outboxcode='" + MotherBoxCode + "'", "update");
- }
- }
- }
- LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "卡通箱采集", "卡通箱" + pa_outboxcode.Text + "取消采集成功", sn_code.Text, "");
- LoadGridData();
- pa_status.Text = "0";
- OperateResult.AppendText(">>已从该箱中移除序列号" + sn_code.Text + "\n", Color.Green, sn_code);
- }
- else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, sn_code);
- }
- }
- else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, sn_code);
- }
- else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, sn_code);
- }
- }
- private void Clean_Click(object sender, EventArgs e)
- {
- OperateResult.Clear();
- }
- private void pr_code_TextChanged(object sender, EventArgs e)
- {
- LoadCheckQTY();
- DataTable _dt = (DataTable)dh.ExecuteSql("select la_id,la_url,la_isdefault,replace(LA_SOFTTYPE,';',',')LA_SOFTTYPE from label where la_prodcode='" + pr_code.Text + "' and la_templatetype='卡通箱标' and la_statuscode='AUDITED' order by la_isdefault", "select");
- if (_dt.Rows.Count == 0)
- {
- _dt = (DataTable)dh.ExecuteSql("select la_id,la_url,la_isdefault,replace(LA_SOFTTYPE,';',',')LA_SOFTTYPE from label where la_prodcode is null and la_templatetype='卡通箱标' and la_statuscode='AUDITED' order by la_isdefault", "select");
- }
- if (_dt.Rows.Count > 0)
- {
- string la_id = _dt.Rows[0]["la_id"].ToString();
- _dt = (DataTable)dh.ExecuteSql("select fp_name la_url,'" + la_id + "' la_id from FILEPATH where fp_id in (select * from table(select parsestring(LA_SOFTTYPE,';') from label where la_id='" + la_id + "') where COLUMN_VALUE is not null)", "select");
- PrintLabel.DataSource = _dt;
- PrintLabel.DisplayMember = "la_url";
- PrintLabel.ValueMember = "la_id";
- PrintLabel1.DataSource = _dt.Copy();
- PrintLabel1.DisplayMember = "la_url";
- PrintLabel1.ValueMember = "la_id";
- }
- }
- private void Make_PackageCollectionWeigh_FormClosing(object sender, FormClosingEventArgs e)
- {
- if (serialPort1.IsOpen)
- {
- GetData = false;
- serialPort1.Close();
- SystemInf.OpenPort.Remove(serialPort1.PortName);
- thread.Interrupt();
- }
- //thread.Abort();
- }
- private void Packing_Click(object sender, EventArgs e)
- {
- if (dh.CheckExist("package", "pa_outboxcode='" + pa_outboxcode.Text + "' and nvl(pa_status,0)=0"))
- {
- string Seal = MessageBox.Show(this.ParentForm, "是否确认封箱?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
- if (Seal == "Yes")
- {
- ActWeigh = weight.Text == "" ? "0" : weight.Text.Replace("kg", "").Replace("g", "").Trim();
- float weigh = float.Parse(ActWeigh);
- if (PR_CHECKCARTONW != "0" && pa_standardqty.Text == pa_currentqty.Text)
- {
- if (!(weigh >= MinWeight && weigh <= MaxWeight) || weigh == 0)
- {
- OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "重量不符合标准重量,不能完成工序过站\n", Color.Red);
- LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "卡通箱称重", "称量不符合要求:" + weight.Text.Trim(), pa_outboxcode.Text, "");
- LogicHandler.RecordProdWeight(pa_outboxcode.Text, "CARTON", float.Parse(ActWeigh.ToString()), "kg", User.UserLineCode, pr_code.Text, User.UserSourceCode, User.UserName);
- return;
- }
- }
- dh.UpdateByCondition("package", "pa_status=1,pa_totalqty=pa_currentqty,pa_packageqty=pa_currentqty,pa_weight=" + weigh + "", "pa_outboxcode='" + pa_outboxcode.Text + "'");
- pa_status.Text = "1";
- pa_standardqty.Text = "";
- LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "卡通箱采集", "封箱成功", pa_outboxcode.Text, "");
- OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "封箱成功\n", Color.Green);
- LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "卡通箱称重", "称量完成:" + weight.Text.Trim(), pa_outboxcode.Text, "");
- LogicHandler.RecordProdWeight(pa_outboxcode.Text, "CARTON", float.Parse(ActWeigh.ToString()), "kg", User.UserLineCode, pr_code.Text, User.UserSourceCode, User.UserName);
- string ms_makecode = dh.getFieldDataByCondition("packagedetail", "pd_makecode", "pd_outboxcode = '" + pa_outboxcode.Text + "'").ToString();
- if (LogicHandler.OutBoxStepPass(pa_outboxcode.Text, ms_makecode, User.UserSourceCode, User.UserCode, "卡通箱:" + pa_outboxcode.Text + "整箱过站", "卡通箱整箱过站", out ErrorMessage))
- {
- dh.UpdateByCondition("package", "pa_nextstep='" + dh.getFieldDataByCondition("packagedetail left join makeserial on ms_sncode=pd_barcode and ms_makecode=pd_makecode", "max(ms_nextstepcode)", "pd_outboxcode='" + pa_outboxcode.Text + "'").ToString() + "', PA_CURRENTSTEP = '' ", "pa_outboxcode='" + pa_outboxcode.Text + "'");
- }
- else
- {
- OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
- }
- LoadCheckQTY();
- if (!CollecRemark.Checked)
- {
- if (!AutoGenBoxCode.Checked)
- {
- pa_outboxcode.Focus();
- pa_outboxcode.SelectAll();
- }
- else
- {
- sn_code.Focus();
- sn_code.SelectAll();
- }
- }
- else
- {
- pa_remark.SelectAll();
- pa_remark.Focus();
- }
- }
- }
- else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "错误或者已封箱\n", Color.Red);
- }
- private void SendCheck_Click(object sender, EventArgs e)
- {
- if (dh.getFieldDataByCondition("package", "pa_status", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString() == "1")
- {
- DataTable dt = (DataTable)dh.ExecuteSql("select wm_concat(pa_outboxcode) pa_outboxcode from package where pa_checkno='" + ob_checkno.Text + "' and pa_status=0 ", "select");
- if (dt.Rows[0][0].ToString() != "")
- {
- OperateResult.AppendText(">>批次" + ob_checkno.Text + "存在箱号" + dt.Rows[0][0].ToString() + "未封箱,请先进行封箱\n", Color.Red);
- return;
- }
- sql.Clear();
- sql.Append("update oqcbatch set ob_status='UNCHECK',ob_breakingdate=sysdate where ob_checkno ='" + ob_checkno.Text + "'");
- dh.ExecuteSql(sql.GetString(), "select");
- ob_nowcheckqty.Text = "";
- ob_batchqty.Text = "";
- ob_nowcheckqty.ForeColor = Color.Black;
- SendCheck.Enabled = false;
- OperateResult.AppendText(">>批次" + ob_checkno.Text + "送检成功\n", Color.Green);
- LogicHandler.InsertMakeProcess(LastSncode, oMakeCode, User.UserSourceCode, "手动送检", "手动送检成功", User.UserCode);
- //记录操作日志
- LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "手动送检", "手动送检成功", "", ob_checkno.Text);
- ob_checkno.Text = "";
- }
- else OperateResult.AppendText(">>必须封箱才能送检\n", Color.Red);
- }
- bool AutoCut;
- 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='" + ms_salecode.Text + "'";
- }
- sql.Append("select ob_batchqty,ob_nowcheckqty,ob_checkno from oqcbatch where ");
- sql.Append("ob_linecode='" + User.UserLineCode + "' and ob_prodcode='" + pr_code.Text + "' and ");
- sql.Append("ob_stepcode='" + User.CurrentStepCode + "' " + condition);
- DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- if (dt.Rows.Count > 0)
- {
- 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.Green);
- }
- }
- }
- else
- {
- ob_batchqty.Text = "";
- ob_nowcheckqty.Text = "";
- ob_checkno.Text = "";
- SendCheck.Enabled = false;
- }
- if (ob_batchqty.Text != "")
- {
- SendCheck.Enabled = true;
- }
- else
- {
- SendCheck.Enabled = false;
- }
- }
- 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 PrintLabel_SelectedValueChanged(object sender, EventArgs e)
- {
- if (PrintLabel.SelectedValue != null && PrintLabel.SelectedValue.ToString() != "System.Data.DataRowView")
- {
- string PrintNums = dh.getFieldDataByCondition("label", "la_printnos", "la_id='" + PrintLabel.SelectedValue.ToString() + "'").ToString();
- PrintNum.Text = (PrintNums == "" ? "1" : PrintNums);
- }
- }
- private void DeleteAll_Click(object sender, EventArgs e)
- {
- if (pa_outboxcode.Text == "")
- {
- OperateResult.AppendText(">>箱号不能为空\n", Color.Red);
- return;
- }
- string Delete = MessageBox.Show(this.ParentForm, "是否确认拆箱?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
- if (Delete == "Yes")
- {
- DataTable dt = (DataTable)dh.ExecuteSql("select nvl(pa_iostatus,0) pa_iostatus,pa_outno,pa_checkno,ob_status,pa_mothercode,nvl(pa_downstatus,0)pa_downstatus from package left join oqcbatch on pa_checkno=ob_checkno where pa_outboxcode='" + pa_outboxcode.Text + "'", "select");
- if (dt.Rows.Count > 0)
- {
- if (dt.Rows[0]["pa_outno"].ToString() != "")
- {
- OperateResult.AppendText(">>卡通箱" + pa_outboxcode.Text + "已被出货单" + dt.Rows[0]["pa_outno"].ToString() + "采集,不允许操作\n", Color.Red);
- return;
- }
- if (dt.Rows[0]["pa_iostatus"].ToString() != "0")
- {
- OperateResult.AppendText(">>卡通箱" + pa_outboxcode.Text + "处于入库状态,不允许操作\n", Color.Red);
- return;
- }
- if (dt.Rows[0]["pa_mothercode"].ToString() == "")
- {
- if (dt.Rows[0]["pa_downstatus"].ToString() == "0")
- {
- string ob_status = dt.Rows[0]["ob_status"].ToString();
- string pa_checkno = dt.Rows[0]["pa_checkno"].ToString();
- //不存在抽检批次或者还未检验可以拆解
- if (ob_status == "" || ob_status == "ENTERING" || ob_status == "UNCHECK")
- {
- sql.Clear();
- sql.Append("select pd_makecode,count(1) num from packagedetail left join makeserial ");
- sql.Append("on ms_sncode=pd_barcode and ms_makecode=pd_makecode where pd_outboxcode='" + pa_outboxcode.Text + "' group by pd_makecode");
- dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- List<string> SQLS1 = new List<string>();
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- string ma_code = dt.Rows[i]["pd_makecode"].ToString();
- string num = dt.Rows[i]["num"].ToString();
- SQLS1.Add("delete from makeprocess where mp_sncode in (select ms_sncode from makeserial where ms_outboxcode='" + pa_outboxcode.Text + "' and ms_makecode='" + ma_code + "') and mp_makecode='" + ma_code + "' and mp_stepcode='" + User.CurrentStepCode + "'");
- SQLS1.Add("delete from steppassed where sp_sncode in (select ms_sncode from makeserial where ms_outboxcode='" + pa_outboxcode.Text + "' and ms_makecode='" + ma_code + "') and sp_makecode='" + ma_code + "' and sp_stepcode='" + User.CurrentStepCode + "'");
- SQLS1.Add("update makecraftdetail set mcd_inqty=mcd_inqty-" + num + ",mcd_outqty=mcd_outqty-" + num + ",mcd_okqty=mcd_okqty-" + num + " where mcd_macode='" + ma_code + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
- //扣减已完工数
- SQLS1.Add("update make set ma_endqty=ma_endqty-(select count(1) from makeserial where ms_outboxcode='" + pa_outboxcode.Text + "' and ms_makecode='" + ma_code + "' and ms_status=2) where ma_code='" + ma_code + "'");
- }
- if (pa_checkno != "")
- {
- SQLS1.Add("update makeserial set ms_checkno='' where ms_outboxcode='" + pa_outboxcode.Text + "'");
- SQLS1.Add("update oqcbatch set ob_nowcheckqty=ob_nowcheckqty-(select count(1) from oqcbatchdetail where obd_outboxcode='" + pa_outboxcode.Text + "') where ob_checkno='" + pa_checkno + "'");
- SQLS1.Add("delete from oqcbatchdetail where obd_outboxcode='" + pa_outboxcode.Text + "'");
- }
- //更新序列号状态
- SQLS1.Add("update makeserial set ms_status=1,ms_outboxcode='',ms_nextstepcode= (case when ms_nextstepcode='" + User.CurrentStepCode + "' then ms_nextstepcode else ms_stepcode end ),ms_paststep=replace(ms_paststep,'," + User.CurrentStepCode + "','') where ms_outboxcode='" + pa_outboxcode.Text + "'");
- //抽检批次不为空的时候进行移除
- dh.ExecuteSQLTran(SQLS1.ToArray());
- string prcode = dh.getFieldDataByCondition("packagedetail", "pd_prodcode", "pd_outboxcode = '" + pa_outboxcode.Text + "'").ToString();
- string standqty = dh.getFieldDataByCondition("product", "pr_outboxinnerqty", "pr_code = '" + prcode + "'").ToString();
- if (standqty != "")
- {
- //置空原箱
- dh.ExecuteSql("update package set pa_checkno='',pa_prodcode='',pa_packtype='',pa_salecode='',pa_packageqty=0,pa_totalqty=0,pa_currentqty=0,pa_status=0,PA_STANDARDQTY = '" + standqty + "' where pa_outboxcode='" + pa_outboxcode.Text + "'", "update");
- }
- else
- //置空原箱
- dh.ExecuteSql("update package set pa_checkno='',pa_prodcode='',pa_packtype='',pa_salecode='',pa_packageqty=0,pa_totalqty=0,pa_currentqty=0,pa_status=0 where pa_outboxcode='" + pa_outboxcode.Text + "'", "update");
- pa_status.Text = "0";
- //删除箱的明细
- dh.ExecuteSql("delete from labelprintlog where lpl_value='" + pa_outboxcode.Text + "'", "delete");
- dh.ExecuteSql("delete from packagedetail where pd_outboxcode='" + pa_outboxcode.Text + "'", "delete");
- LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "卡通箱拆解", "成功", pa_outboxcode.Text, ob_checkno.Text);
- OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "成功拆解!\n", Color.Green);
- LoadGridData();
- LoadCheckQTY();
- }
- else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "已送检,不允许解除\n", Color.Red);
- }
- else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "已下地,不允许解除\n", Color.Red);
- }
- else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "已装箱" + dt.Rows[0]["pa_mothercode"].ToString() + ",不允许解除\n", Color.Red);
- }
- else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "不存在\n", Color.Red);
- }
- }
- private void OutBoxLength_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- {
- try
- {
- if (OutBoxLength.Text != "")
- {
- int.Parse(OutBoxLength.Text);
- }
- BaseUtil.SetCacheData("OutBoxLength", OutBoxLength.Text);
- if (!AutoGenBoxCode.Checked)
- {
- pa_outboxcode.Focus();
- pa_outboxcode.SelectAll();
- }
- else
- {
- sn_code.Focus();
- }
- }
- catch (Exception)
- {
- OutBoxLength.Clear();
- MessageBox.Show("请输入正确的长度");
- }
- }
- }
- private bool CheckOutBoxLength()
- {
- //勾选了检验长度进行校验
- if (OutBoxLength.Text != "")
- {
- try
- {
- int.Parse(OutBoxLength.Text);
- }
- catch (Exception)
- {
- MessageBox.Show("请填写正确的箱号长度");
- return false;
- }
- if (pa_outboxcode.Text.Length != int.Parse(OutBoxLength.Text))
- {
- OperateResult.AppendText(">>箱号长度错误,请重新输入箱号\n", Color.Red);
- return false;
- }
- }
- if (PreFix.Text != "")
- {
- try
- {
- if (pa_outboxcode.Text.Substring(0, PreFix.Text.Length) != PreFix.Text)
- {
- OperateResult.AppendText(">>箱号前缀不匹配,请重新输入箱号\n", Color.Red);
- return false;
- }
- }
- catch (Exception)
- {
- OperateResult.AppendText(">>箱号前缀不匹配,请重新输入箱号\n", Color.Red);
- return false;
- }
- }
- return true;
- }
- private void RefreshWeigh_Click(object sender, EventArgs e)
- {
- string prcode = dh.getFieldDataByCondition("packagedetail", "pd_prodcode", "pd_outboxcode = '" + pa_outboxcode.Text + "'").ToString();
- sql.Clear();
- sql.Append("select pr_cartonmaxw,pr_cartonunit,pr_cartonminw,pr_cartongw from product where pr_code='" + prcode + "'");
- DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- if (dt.Rows.Count > 0)
- {
- //重量的临时变量
- string _weight = dt.Rows[0]["pr_cartongw"].ToString();
- string _maxweight = dt.Rows[0]["pr_cartonmaxw"].ToString();
- string _minweight = dt.Rows[0]["pr_cartonminw"].ToString();
- Weight = double.Parse(_weight == "" ? "0" : _weight);
- MaxWeight = double.Parse(_maxweight == "" ? "0" : _maxweight);
- MinWeight = double.Parse(_minweight == "" ? "0" : _minweight);
- if (Weight - MinWeight == MaxWeight - Weight)
- pr_cartonboxgw.Text = Weight + "±" + (MaxWeight - Weight) + dt.Rows[0]["pr_cartonunit"].ToString();
- else
- pr_cartonboxgw.Text = MinWeight + "-" + MaxWeight + dt.Rows[0]["pr_cartonunit"].ToString();
- }
- }
- private void LoadCollectedNum()
- {
- dt = (DataTable)dh.ExecuteSql("select mcd_inqty,ma_qty-mcd_inqty mcd_remainqty from make left join makecraftdetail on mcd_macode=ma_code where ma_code='" + ms_makecode.Text + "' and mcd_stepcode='" + User.CurrentStepCode + "'", "select");
- BaseUtil.SetFormValue(Controls, dt);
- }
- private void pa_remark_KeyDown(object sender, KeyEventArgs e)
- {
- if (Keys.Enter == e.KeyCode)
- {
- if (dh.CheckExist("package", "pa_outboxcode='" + pa_outboxcode.Text + "'"))
- {
- if (Remark_PreFix.Text != "")
- {
- try
- {
- if (pa_remark.Text.Substring(0, Remark_PreFix.Text.Length) != Remark_PreFix.Text)
- {
- OperateResult.AppendText(">>备注前缀不匹配,请重新输入备注信息\n", Color.Red);
- return;
- }
- }
- catch (Exception)
- {
- OperateResult.AppendText(">>备注前缀不匹配,请重新输入备注信息\n", Color.Red);
- return;
- }
- }
- if (!AllowRepeat.Checked)
- {
- DataTable dt = (DataTable)dh.ExecuteSql("select pa_outboxcode from package where pa_remark='" + pa_remark.Text.ToUpper() + "'", "select");
- if (dt.Rows.Count > 0)
- {
- OperateResult.AppendText(">>箱号" + dt.Rows[0][0].ToString() + "已采集关联信息" + pa_remark.Text + "\n", Color.Red);
- return;
- }
- }
- dh.UpdateByCondition("package", "pa_remark='" + pa_remark.Text.ToUpper() + "'", "pa_outboxcode='" + pa_outboxcode.Text + "'");
- OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "关联信息" + pa_remark.Text + "采集成功\n", Color.Green);
- pa_remark.Text = "";
- if (!AutoGenBoxCode.Checked)
- {
- pa_outboxcode.SelectAll();
- pa_outboxcode.Focus();
- }
- else
- {
- sn_code.Focus();
- }
- }
- else OperateResult.AppendText(">>请先采集箱内数据\n", Color.Red);
- }
- }
- private void PreFix_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- {
- BaseUtil.SetCacheData("PreFix", PreFix.Text);
- if (!AutoGenBoxCode.Checked)
- {
- pa_outboxcode.Focus();
- pa_outboxcode.SelectAll();
- }
- else
- {
- sn_code.Focus();
- }
- }
- }
- private void Remark_PreFix_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- {
- BaseUtil.SetCacheData("Remark_PreFix", Remark_PreFix.Text);
- if (CollecRemark.Checked)
- {
- pa_remark.SelectAll();
- pa_remark.Focus();
- }
- }
- }
- private bool CheckOutBoxLength(string ms_salecode_text)
- {
- if (AutoGenBoxCode.Checked)
- {
- if (ms_salecode_text != "")
- {
- DataTable dt = (DataTable)dh.ExecuteSql(" select pn_number,pn_id,pn_caller,pn_numberlength,pn_leadcode from PACKAGENUMBER where pn_caller='" + ms_salecode_text + "'", "select");
- if (dt.Rows.Count > 0)
- {
- string pn_leadcode = dt.Rows[0]["pn_leadcode"].ToString();
- int pn_numberlength = int.Parse(dt.Rows[0]["pn_numberlength"].ToString());
- if (OutBoxLength.Text != (pn_leadcode.Length + pn_numberlength).ToString())
- {
- OutBoxLength.Text = (pn_leadcode.Length + pn_numberlength).ToString();
- BaseUtil.SetCacheData("OutBoxLength", OutBoxLength.Text);
- }
- if (PreFix.Text != pn_leadcode)
- {
- PreFix.Text = pn_leadcode;
- BaseUtil.SetCacheData("PreFix", PreFix.Text);
- }
- }
- else
- {
- OperateResult.AppendText(">>订单号" + ms_salecode_text + "未维护箱号规则\n", Color.Black);
- }
- }
- return true;
- }
- return CheckOutBoxLength();
- }
- private void AutoGenBoxCode_CheckedChanged(object sender, EventArgs e)
- {
- if (AutoGenBoxCode.Checked)
- {
- OutBoxLength.Enabled = false;
- PreFix.Enabled = false;
- pa_outboxcode.Enabled = false;
- }
- else
- {
- OutBoxLength.Enabled = true;
- PreFix.Enabled = true;
- pa_outboxcode.Enabled = true;
- }
- }
- }
- }
|