using LabelManager2; using System; using System.Collections.Generic; using System.Data; using System.Drawing; using System.IO; using System.IO.Ports; using System.Threading; using System.Windows.Forms; using UAS_MES_NEW.DataOperate; using UAS_MES_NEW.Entity; using UAS_MES_NEW.PublicForm; using UAS_MES_NEW.PublicMethod; using UAS_MES_NEW.Packing; namespace UAS_MES_NEW.Packing { public partial class Packing_PalletWightCollection : Form { AutoSizeFormClass asc = new AutoSizeFormClass(); DataHelper dh; DataTable dt; LogStringBuilder sql = new LogStringBuilder(); Packing_NewPallet NewPallet; //称量的标准重量 Double Weight; //最大重量 Double MaxWeight; //最小重量 Double MinWeight; //true的时候表示从串口读取数据 bool GetData = true; string pa_nextstep = ""; //箱类型 string pa_type; //Package表的主键 string pa_id; string PR_CHECKCARTONW = "0"; ApplicationClass lbl; Document doc; Thread InitPrint; Thread thread; string ErrorMessage = ""; //创建串口实例 SerialPort serialPort1 = new SerialPort(); public Packing_PalletWightCollection() { InitializeComponent(); } //创建打印进程 private void InPrint() { try { lbl = new ApplicationClass(); BaseUtil.WriteLbl(); } catch { OperateResult.AppendText("未正确安装CodeSoft软件\n", Color.Red); } } private void Make_PalletCollection_Load(object sender, EventArgs e) { asc.controllInitializeSize(this); ComList.Text = BaseUtil.GetCacheData("PortName").ToString(); BaudRate.Text = BaseUtil.GetCacheData("BaudRate").ToString(); InitPrint = new Thread(InPrint); SetLoadingWindow stw = new SetLoadingWindow(InitPrint, "初始化打印程序"); BaseUtil.SetFormCenter(stw); stw.ShowDialog(); OutBoxLength.Text = BaseUtil.GetCacheData("PalletLength").ToString(); PalletPreFix.Text = BaseUtil.GetCacheData("PalletPreFix").ToString(); StartWeight.PerformClick(); dh = SystemInf.dh; StepCount.StepCode = User.CurrentStepCode; StepCount.Source = User.UserSourceCode; StepCount.LineCode = User.UserLineCode; StepCount.Dh = dh; StepCount.Start(); } private void Clean_Click(object sender, EventArgs e) { OperateResult.Clear(); } private void palletcode_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { LoadGridData(); sql.Clear(); sql.Append("select pa_makecode,pa_id,pa_status,nvl(pa_standardqty,PR_PALLETQTY)pa_standardqty,pa_prodcode,pa_packageqty,pa_totalqty,pa_salecode,pa_currentqty,pr_code pa_prodcode,pa_outboxcode,pa_totalqty,pa_custcode "); sql.Append("from package left join packagedetail on pa_id =pd_paid left join product on pr_code=pd_prodcode where pa_outboxcode='" + pa_outboxcode.Text + "' and pa_type =3"); DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); if (dt.Rows.Count > 0) { BaseUtil.SetFormValue(Controls, dt); pa_id = dt.Rows[0]["pa_id"].ToString(); } if (CheckOutBoxLength()) { if (pa_standardqty.Text == "") pa_standardqty.Focus(); else outboxcode.Focus(); } } } //箱号Enter事件 private void outboxcode_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage)) { if (outboxcode.Text == "") { OperateResult.AppendText(">>箱号不能为空\n", Color.Red); return; } //根据箱号查询表单数据 sql.Clear(); sql.Append("select pa_totalqty,ma_code,ma_qty,ma_salecode,PA_STANDARDQTY PA_STANDARDQTYCARTON,PA_CURRENTQTY,pr_detail,pr_cartonunit,pr_code,pr_cartongw,"); sql.Append("pr_cartonmaxw,pr_cartonminw,nvl(PR_CHECKCARTONW,'0') PR_CHECKCARTONW,nvl(pr_sendchecktype,'LineCode')pr_sendchecktype from package left join packagedetail "); sql.Append("on pa_id=pd_paid left join makeserial on ms_sncode=pd_barcode and ms_makecode=pa_makecode left join product on pr_code=pd_prodcode left join make on ma_code=pd_makecode "); sql.Append(" where pa_outboxcode='" + outboxcode.Text + "' and pa_nextstep='" + User.CurrentStepCode + "'"); DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); //填充打印文件选项的DataGridView if (dt.Rows.Count > 0) { BaseUtil.SetFormValue(this.Controls, dt); string ErrorMessage; //重量的临时变量 PR_CHECKCARTONW = dt.Rows[0]["PR_CHECKCARTONW"].ToString(); string _weight = dt.Rows[0]["pr_cartongw"].ToString(); string _maxweight = dt.Rows[0]["pr_cartonmaxw"].ToString(); string _minweight = dt.Rows[0]["pr_cartonminw"].ToString(); string pa_pr_cartonunit = dt.Rows[0]["pr_cartonunit"].ToString(); string PA_STANDARDQTY = dt.Rows[0]["PA_STANDARDQTYCARTON"].ToString(); string PA_CURRENTQTY = dt.Rows[0]["PA_CURRENTQTY"].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_cartongw.Text = Weight + "±" + (MaxWeight - Weight) + dt.Rows[0]["pr_cartonunit"].ToString(); else pr_cartongw.Text = MinWeight + "-" + MaxWeight + dt.Rows[0]["pr_cartonunit"].ToString(); double ActualWeight = double.Parse(weight.Text == "" ? "0" : weight.Text.Replace("kg", "").Trim()); //需要检查称重重量 if (PR_CHECKCARTONW != "0" && PA_STANDARDQTY == PA_CURRENTQTY) { //称量合格或不合格都记录重量 if (ActualWeight >= MinWeight && ActualWeight <= MaxWeight && ActualWeight != 0) { LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "卡通箱称重", "称量合格:" + weight.Text.Trim(), outboxcode.Text, ""); LogicHandler.RecordProdWeight(outboxcode.Text, "CARTON", float.Parse(ActualWeight.ToString()), "kg", User.UserLineCode, pr_code.Text, User.UserSourceCode, User.UserName); OperateResult.AppendText(">>箱号" + outboxcode.Text + "检测合格\n", Color.Green); } else { LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "卡通箱称重", "称量不合格:" + weight.Text.Trim(), outboxcode.Text, ""); LogicHandler.RecordProdWeight(outboxcode.Text, "CARTON", float.Parse(ActualWeight.ToString()), "kg", User.UserLineCode, pr_code.Text, User.UserSourceCode, User.UserName); OperateResult.AppendText(">>箱号" + outboxcode.Text + "检测未通过\n", Color.Red, outboxcode); return; } } else { LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "卡通箱称重", "称量完成:" + weight.Text.Trim(), outboxcode.Text, ""); LogicHandler.RecordProdWeight(outboxcode.Text, "CARTON", float.Parse(ActualWeight.ToString()), "kg", User.UserLineCode, pr_code.Text, User.UserSourceCode, User.UserName); } OperateResult.AppendText(">>箱号" + outboxcode.Text + "称重完成\n", Color.Green); if (LogicHandler.CartonBoxStepPass(ma_code.Text, User.UserSourceCode, outboxcode.Text, User.UserCode, "卡通箱:" + outboxcode.Text + "整箱过站", out ErrorMessage)) { dh.UpdateByCondition("package", "pa_printcount= nvl(pa_printcount,0)+1,pa_weight='" + ActualWeight + "',pa_status=1,pa_packageqty=pa_currentqty,pa_totalqty=pa_currentqty", "pa_outboxcode='" + outboxcode.Text + "'"); 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='" + outboxcode.Text + "'").ToString() + "' ,PA_CURRENTSTEP = '' ", "pa_outboxcode='" + outboxcode.Text + "'"); } else { OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red); } } else OperateResult.AppendText(">>箱号" + outboxcode.Text + "当前执行工序不是" + User.CurrentStepCode + "\n", Color.Black); sql.Clear(); sql.Append("select nvl(pa_iostatus,0)pa_iostatus,pa_outno,pa_makecode pd_makecode,nvl(pa_downstatus,0)pa_downstatus,pa_salecode pd_salecode,pr_packrule,pa_id,pa_prodcode pd_prodcode,pa_status,pa_mothercode,pa_nextstep "); sql.Append("from packagedetail left join package on pd_paid=pa_id left join product on pd_prodcode=pr_code where pd_outboxcode='" + outboxcode.Text + "'"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); if (dt.Rows.Count > 0) { BaseUtil.SetFormValue(this.Controls, dt); if (dt.Rows[0]["pa_downstatus"].ToString() != "0") { OperateResult.AppendText(">>箱号" + outboxcode.Text + "下地状态不允许采集\n", Color.Red, outboxcode); return; } if (dt.Rows[0]["pa_outno"].ToString() != "") { OperateResult.AppendText(">>箱号" + outboxcode.Text + "已被出货单" + dt.Rows[0]["pa_outno"].ToString() + "采集,不允许操作\n", Color.Red); return; } if (dt.Rows[0]["pa_iostatus"].ToString() != "0") { OperateResult.AppendText(">>箱号" + outboxcode.Text + "已入库不允许采集\n", Color.Red, outboxcode); return; } if (dt.Rows[0]["pa_mothercode"].ToString() != "") { if (pa_outboxcode.Text == "") { pa_outboxcode.Text = dt.Rows[0]["pa_mothercode"].ToString(); palletcode_KeyDown(sender, e); } } string unfinpack = dh.getFieldDataByCondition("Line", "nvl(li_allowUnFinPack,0)", "li_code='" + User.UserLineCode + "'").ToString(); pa_nextstep = dt.Rows[0]["pa_nextstep"].ToString(); if (pa_nextstep != User.CurrentStepCode && pa_nextstep != "" && (unfinpack == "0" || unfinpack == "")) { OperateResult.AppendText(">>箱号" + outboxcode.Text + "的下一工序不是当前岗位资源对应工序\n", Color.Red, outboxcode); return; } sql.Clear(); sql.Append("select nvl(pa_iostatus,0) pa_iostatus,pa_outno from package where pa_outboxcode='" + pa_outboxcode.Text + "'"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "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 (pa_nextstep == "") { //判断线外,必须已完工并且未入库 dt = (DataTable)dh.ExecuteSql("select wm_concat(ms_sncode) from mes_package_view left join makeserial on v_barcode=ms_sncode where v_outboxcode='" + outboxcode.Text + "' and ms_status<>2", "select"); if (dt.Rows[0][0].ToString() != "" && (unfinpack != "0" || unfinpack == "")) { OperateResult.AppendText(">>序列号" + dt.Rows[0][0].ToString() + "尚未完工\n", Color.Red); return; } } } else { OperateResult.AppendText(">>箱号" + outboxcode.Text + "未采集内容或不存在,不允许装栈板\n", Color.Red, outboxcode); return; } if (!Cancel.Checked) { pa_status.Text = dh.getFieldDataByCondition("package", "nvl(pa_status,0)pa_status", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString(); if (pa_outboxcode.Text == "" && AutoOutBoxCode.Checked) { //箱已采集满并且未勾选自动生成 if (pa_standardqty.Text == pa_totalqty.Text && !AutoOutBoxCode.Checked) { OperateResult.AppendText(">>栈板" + pa_outboxcode.Text + "已采集满\n", Color.Red, outboxcode); return; } else { pa_outboxcode.Text = LogicHandler.GetOutBoxCode("PALLET", "", pa_prodcode.Text, User.UserCode); } } else if (pa_outboxcode.Text != "" && pa_status.Text == "1" && AutoOutBoxCode.Checked) { pa_outboxcode.Text = LogicHandler.GetOutBoxCode("PALLET", "", pa_prodcode.Text, User.UserCode); } else if (pa_outboxcode.Text == "") { OperateResult.AppendText(">>栈板号不能为空\n", Color.Red); return; } if (!CheckOutBoxLength()) { return; } dt = (DataTable)dh.ExecuteSql("select pa_id from package where pa_outboxcode='" + pa_outboxcode.Text + "'", "select"); if (dt.Rows.Count == 0) { pa_id = dh.GetSEQ("package_seq"); sql.Clear(); sql.Append("insert into package (pa_id,pa_outboxcode,PA_STANDARDQTY,pa_makecode,pa_indate,pa_packageqty,pa_type,pa_prodcode,pa_level,PA_STATUS,pa_sccode,pa_currentstep,pa_salecode)values"); sql.Append("(" + pa_id + ",'" + pa_outboxcode.Text + "','" + pa_standardqty.Text + "','" + pd_makecode.Text + "',sysdate,'0',3,'" + pd_prodcode.Text + "',0,0,'" + User.UserSourceCode + "','" + User.CurrentStepCode + "','" + pd_salecode.Text + "')"); dh.ExecuteSql(sql.GetString(), "insert"); } else { pa_id = dt.Rows[0]["pa_id"].ToString(); } palletcode_KeyDown(sender, e); if (int.Parse(pa_totalqty.Text == "" ? "0" : pa_totalqty.Text) > 0) { if (!LogicHandler.CheckPackRule(pr_packrule.Text, pa_outboxcode.Text, outboxcode.Text, pa_makecode.Text, pa_salecode.Text, pa_prodcode.Text, "栈板", out ErrorMessage)) { OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, outboxcode); return; } } dt = (DataTable)dh.ExecuteSql("select pa_totalqty,pa_mothercode,nvl(pa_status,0) pa_status from package where pa_outboxcode='" + outboxcode.Text + "'", "select"); if (dt.Rows.Count > 0) { //判断是否已经装箱 int sonboxtotalqty = int.Parse(dt.Rows[0]["pa_totalqty"].ToString()); if (dt.Rows[0]["pa_mothercode"].ToString() == "") { if (dt.Rows[0]["pa_status"].ToString() == "1") { pa_totalqty.Text = dh.getFieldDataByCondition("package", "pa_totalqty", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString(); if (int.Parse(pa_totalqty.Text == "" ? "0" : pa_totalqty.Text) + sonboxtotalqty > int.Parse(pa_standardqty.Text == "" ? "0" : pa_standardqty.Text)) { OperateResult.AppendText(">>采集箱号" + outboxcode.Text + "后超出容量\n", Color.Red, outboxcode); return; } if (int.Parse(pa_totalqty.Text == "" ? "0" : pa_totalqty.Text) == 0) { dh.ExecuteSql("update package set pa_prodcode='" + pd_prodcode.Text + "',pa_salecode='" + pd_salecode.Text + "',pa_makecode='" + pd_makecode.Text + "' where pa_outboxcode='" + pa_outboxcode.Text + "'", "update"); } List SQLS = new List(); sql.Clear(); sql.Append("insert into packagedetail(pd_id, pd_paid, pd_outboxcode,pd_makecode,pd_prodcode,pd_innerboxcode, pd_innerqty,pd_builddate)"); sql.Append("select packagedetail_seq.nextval,'" + pa_id + "','" + pa_outboxcode.Text + "','" + pd_makecode.Text + "','" + pd_prodcode.Text + "','" + outboxcode.Text + "' "); sql.Append(",(select nvl(sum(pd_innerqty),0) from packagedetail left join package on pa_id=pd_paid where pa_outboxcode="); sql.Append("'" + outboxcode.Text + "'),sysdate from package where pa_outboxcode='" + outboxcode.Text + "'"); SQLS.Add(sql.GetString()); //如果采集完这个超出了容量提示 SQLS.Add("update package set PA_CURRENTQTY=nvl(PA_CURRENTQTY,0)+1,PA_PACKAGEQTY=nvl(PA_PACKAGEQTY,0)+1,PA_TOTALQTY=(select sum(pd_innerqty) from packagedetail left join package on pa_id=pd_paid where pa_outboxcode='" + pa_outboxcode.Text + "') where pa_outboxcode='" + pa_outboxcode.Text + "' and pa_type=3"); SQLS.Add("update package set pa_mothercode='" + pa_outboxcode.Text + "' where pa_outboxcode='" + outboxcode.Text + "'"); dh.ExecuteSQLTran(SQLS.ToArray()); //更新大箱的栈板号 if (dh.getFieldDataByCondition("package", "pa_makecode", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString() == "") { string carton_macode = dh.getFieldDataByCondition("package", "pa_makecode", "pa_outboxcode='" + outboxcode.Text + "'").ToString(); pa_makecode.Text = carton_macode; dh.ExecuteSql("update package set pa_makecode='" + carton_macode + "' where pa_outboxcode='" + pa_outboxcode.Text + "'", "update"); } //如果是线内并且下一工序等于当前岗位资源工序 if (pa_nextstep != "" && pa_nextstep == User.CurrentStepCode) { LogicHandler.OutBoxStepPass(outboxcode.Text, pa_makecode.Text, User.UserSourceCode, User.UserCode, "栈板采集成功,栈板号:" + pa_outboxcode.Text, "栈板采集", out ErrorMessage); } if (pa_totalqty.Text == "1") { string nextstepcode = dh.getFieldDataByCondition("mes_package_view left join makeserial on ms_sncode=v_barcode", "ms_nextstepcode", "v_outboxcode='" + outboxcode.Text + "'").ToString(); dh.UpdateByCondition("package", "pa_nextstep='" + nextstepcode + "'", "pa_outboxcode='" + pa_outboxcode.Text + "'"); } LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, "", User.UserLineCode, User.UserSourceCode, "栈板采集", "栈板" + pa_outboxcode.Text + "采集箱" + outboxcode.Text + "成功", pa_outboxcode.Text, ""); OperateResult.AppendText(">>箱号" + outboxcode.Text + "采集成功!\n", Color.Green, outboxcode); LoadCollectNum(); palletcode_KeyDown(sender, e); if (pa_standardqty.Text == pa_totalqty.Text) { dh.ExecuteSql("update package set pa_status=1 where pa_outboxcode='" + pa_outboxcode.Text + "'", "update"); OperateResult.AppendText("栈板" + pa_outboxcode.Text + "已装满,封栈板成功\n"); pa_outboxcode.Focus(); pa_outboxcode.SelectAll(); if (AutoPrint.Checked) { OperateResult.AppendText(">>打印栈板" + pa_outboxcode.Text + ",自动打印!\n", Color.Green); Printlab.PerformClick(); } } } else OperateResult.AppendText(">>箱号" + outboxcode.Text + "尚未封箱\n", Color.Red, outboxcode); } else { if (dt.Rows[0]["pa_mothercode"].ToString() == pa_outboxcode.Text) OperateResult.AppendText(">>箱号" + outboxcode.Text + "已在本栈板内\n", Color.Red, outboxcode); else OperateResult.AppendText(">>箱号" + outboxcode.Text + "已采集至栈板" + dt.Rows[0]["pa_mothercode"].ToString() + "\n", Color.Red, outboxcode); } } else OperateResult.AppendText(">>箱号" + outboxcode.Text + "不存在\n", Color.Red, outboxcode); } //进行拆箱操作 else { sql.Clear(); sql.Append("select nvl(pa_iostatus,0)pa_iostatus from packagedetail left join package on pa_id =pd_paid where pd_outboxcode='" + pa_outboxcode.Text + "' "); sql.Append("and pd_innerboxcode='" + outboxcode.Text + "'"); DataTable dta = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); if (dta.Rows.Count > 0) { if (dta.Rows[0]["pa_iostatus"].ToString() == "0") { List SQLS = new List(); //删除明细 SQLS.Add("delete from packagedetail where pd_outboxcode='" + pa_outboxcode.Text + "' and pd_innerboxcode='" + outboxcode.Text + "'"); //减少箱内容量 SQLS.Add("update package set pa_packageqty=pa_packageqty-1,pa_totalqty=pa_totalqty-(select pa_totalqty from package where pa_outboxcode='" + outboxcode.Text + "'),pa_currentqty=pa_currentqty-1,pa_status=0 where pa_outboxcode='" + pa_outboxcode.Text + "'"); SQLS.Add("update package set pa_mothercode='' where pa_outboxcode='" + outboxcode.Text + "'"); dh.ExecuteSQLTran(SQLS.ToArray()); OperateResult.AppendText(">>箱号" + outboxcode.Text + "取消采集成功\n", Color.Green); LoadCollectNum(); palletcode_KeyDown(sender, e); outboxcode.Clear(); } else OperateResult.AppendText(">>栈板" + pa_outboxcode.Text + "已入库,不允许取消采集\n", Color.Red); } else OperateResult.AppendText(">>箱号" + outboxcode.Text + "不在栈板" + pa_outboxcode.Text + "\n", Color.Red); } } } } private void LoadGridData() { sql.Clear(); sql.Append("select pd_prodcode,nvl(pd_barcode,PD_INNERBOXCODE) code ,pd_innerqty,pa_salecode"); sql.Append(",pd_makecode,pa_prodcode,pa_custcode,pa_packageqty from packagedetail left join package on pd_paid=pa_id left "); sql.Append("join product on pr_code=pa_prodcode where pa_outboxcode ='" + pa_outboxcode.Text + "' and pa_type=3"); DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); if (dt.Rows.Count == 0 && dh.CheckExist("package", "pa_outboxcode ='" + pa_outboxcode.Text + "' and pa_type=3")) { dh.ExecuteSql("update package set pa_checkno='',pa_prodcode='',pa_packtype='',pa_salecode='',pa_makecode='',pa_packageqty=0,pa_totalqty=0,pa_currentqty=0,pa_status=0 where pa_outboxcode='" + pa_outboxcode.Text + "'", "update"); } BaseUtil.FillDgvWithDataTable(PackageInf, dt); } private void FillPrintLabel() { DataTable _dt = (DataTable)dh.ExecuteSql("select la_id,substr(la_url,instr(la_url,'\\',-1)+1)la_name,la_url,la_isdefault from label where la_prodcode='" + pa_prodcode.Text + "' and la_templatetype='栈板标' and la_statuscode='AUDITED' order by la_isdefault", "select"); PrintLabel.DataSource = _dt; PrintLabel.DisplayMember = "la_url"; PrintLabel.ValueMember = "la_id"; } private void LoadCollectNum() { pa_totalqty.Text = dh.getFieldDataByCondition("package", "pa_totalqty", "pa_outboxcode='" + pa_outboxcode.Text + "' and pa_type=3").ToString(); } private void Make_PalletCollection_SizeChanged(object sender, EventArgs e) { weight.Location = new Point(weight_label.Location.X + weight_label.Size.Width - 10, weight_label.Location.Y - 20); asc.controlAutoSize(this); } private void NewPallet_Click(object sender, EventArgs e) { NewPallet = new Packing_NewPallet("PALLET", pa_makecode.Text); NewPallet.Controls["Confirm"].Click += Make_PalletCollection_Click; BaseUtil.SetFormCenter(NewPallet); NewPallet.ShowDialog(); } private void Make_PalletCollection_Click(object sender, EventArgs e) { pa_outboxcode.Text = NewPallet.OutBoxCode; palletcode_KeyDown(new object(), new KeyEventArgs(Keys.Enter)); NewPallet.Close(); } 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") { if (!AutoOutBoxCode.Checked) { pa_outboxcode.Focus(); pa_outboxcode.SelectAll(); } //doc = lbl.Documents.Open(PrintLabel.Text); if (Print.CodeSoft(Tag.ToString(), ref lbl, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), PrinterList.Text, pa_outboxcode.Text, int.Parse(PrintNum.Text), pa_makecode.Text, pa_prodcode.Text, "栈板标", "0", out ErrorMessage)) { OperateResult.AppendText(">>打印栈板" + pa_outboxcode.Text + "\n", Color.Black); } else { OperateResult.AppendText(ErrorMessage + "\n", Color.Red); } } else OperateResult.AppendText(">>必须封栈板才能进行打印\n", Color.Red); } else OperateResult.AppendText(">>产品" + pa_prodcode.Text + "未维护打印标签\n", Color.Red); } private void ReleasePallet_Click(object sender, EventArgs e) { if (dh.getRowCount("packagedetail", "pd_outboxcode='" + pa_outboxcode.Text + "'") > 0) { string Delete = MessageBox.Show(this.ParentForm, "是否确认拆栈板?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString(); if (Delete == "Yes") { sql.Clear(); sql.Append("select nvl(pa_iostatus,0) pa_iostatus,pa_outno from package where pa_outboxcode='" + pa_outboxcode.Text + "'"); dt = (DataTable)dh.ExecuteSql(sql.GetString(), "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 (dh.getFieldDataByCondition("package", "pa_nextstep", "pa_mothercode='" + pa_outboxcode.Text + "'").ToString() != "") LogicHandler.OutBoxDrawStepPass(pa_outboxcode.Text, pa_makecode.Text, User.UserSourceCode); else { List SQLS = new List(); SQLS.Add("delete from packagedetail where pd_outboxcode='" + pa_outboxcode.Text + "'"); SQLS.Add("update package set pa_packageqty=0,pa_totalqty=0,pa_currentqty=0,pa_status=0 where pa_outboxcode='" + pa_outboxcode.Text + "'"); SQLS.Add("update package set pa_mothercode='' where pa_mothercode='" + pa_outboxcode.Text + "'"); dh.ExecuteSQLTran(SQLS.ToArray()); } LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "栈板采集", "解除栈板" + pa_outboxcode.Text + "成功", pa_outboxcode.Text, ""); OperateResult.AppendText(">>栈板号" + pa_outboxcode.Text + "解除成功\n", Color.Green); palletcode_KeyDown(new object(), new KeyEventArgs(Keys.Enter)); } } else OperateResult.AppendText(">>栈板号" + pa_outboxcode.Text + "未采集箱\n", Color.Red); } private void Make_PalletCollection_FormClosing(object sender, FormClosingEventArgs e) { BaseUtil.ClosePrint(lbl); StopWeight.PerformClick(); InitPrint.Abort(); 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 (pa_outboxcode.Text != "") { sql.Clear(); sql.Append("select nvl(pa_status,0) pa_status from packagedetail left join package "); sql.Append("on pa_id=pd_paid where pd_outboxcode='" + pa_outboxcode.Text + "'"); DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); if (dt.Rows.Count > 0) { if (dt.Rows[0]["pa_status"].ToString() == "0") { string Seal = MessageBox.Show(this.ParentForm, "是否确认封栈板?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString(); if (Seal == "Yes") { OperateResult.AppendText(">>栈板号" + pa_outboxcode.Text + "装栈板成功\n", Color.Green); LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "栈板采集", "封栈板" + pa_outboxcode.Text + "成功", outboxcode.Text, ""); dh.ExecuteSql("update package set pa_status=1 where pa_outboxcode='" + pa_outboxcode.Text + "'", "update"); pa_status.Text = "1"; } } else OperateResult.AppendText(">>栈板号" + pa_outboxcode.Text + "已封栈板\n", Color.Red); } else OperateResult.AppendText(">>栈板号" + pa_outboxcode.Text + "未采集内容\n", Color.Red); } else OperateResult.AppendText(">>栈板号不能为空\n", Color.Red); } 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 pa_prodcode_TextChanged(object sender, EventArgs e) { FillPrintLabel(); } private void pa_standardqty_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { ResetPackageQTY(); } } private void ResetPackageQTY() { if (pa_outboxcode.Text != "") { DataTable dt = (DataTable)dh.ExecuteSql("select pa_totalqty,pa_status from package where pa_outboxcode='" + pa_outboxcode.Text + "'", "select"); if (dt.Rows.Count > 0) { string total = dt.Rows[0]["pa_totalqty"].ToString(); if (int.Parse(pa_standardqty.Text) >= int.Parse(total)) { dh.UpdateByCondition("package", "pa_standardqty='" + pa_standardqty.Text + "'", "pa_outboxcode='" + pa_outboxcode.Text + "'"); OperateResult.AppendText(">>栈板" + pa_outboxcode.Text + "修改容量成功,已修改为" + pa_standardqty.Text + "\n", Color.Green); outboxcode.Focus(); return; } else OperateResult.AppendText(">>容量不能小于已装数量\n", Color.Red); } else outboxcode.Focus(); } } 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; } else return true; } if (PalletPreFix.Text != "") { try { if (pa_outboxcode.Text.Substring(0, PalletPreFix.Text.Length) != PalletPreFix.Text) { OperateResult.AppendText(">>箱号前缀不匹配,请重新输入箱号\n", Color.Red); return false; } } catch (Exception) { OperateResult.AppendText(">>箱号前缀不匹配,请重新输入箱号\n", Color.Red); return false; } } return true; } private void OutBoxLength_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { try { if (OutBoxLength.Text != "") { int.Parse(OutBoxLength.Text); } BaseUtil.SetCacheData("PalletLength", OutBoxLength.Text); pa_outboxcode.Focus(); } catch (Exception) { OutBoxLength.Clear(); MessageBox.Show("请输入正确的长度"); } } } private void PalletPreFix_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { BaseUtil.SetCacheData("PalletPreFix", PalletPreFix.Text); pa_outboxcode.Focus(); } } private void StartWeight_Click(object sender, EventArgs e) { thread = new Thread(getSerialData); try { GetData = true; serialPort1.PortName = this.ComList.Text; serialPort1.BaudRate = int.Parse(BaudRate.Text); serialPort1.Open(); thread.Start(); } catch (Exception mes) { if (BaudRate.Text == "" || ComList.Text == "") OperateResult.AppendText(">>请先在电子秤调试界面维护波特率和串口\n", Color.Red); else OperateResult.AppendText(">>" + mes.Message + "\n", Color.Red); } } private void getSerialData() { if (serialPort1.IsOpen) { if (!SystemInf.OpenPort.Contains(serialPort1.PortName)) { SystemInf.OpenPort.Add(serialPort1.PortName); try { while (GetData) { try { weight.Text = serialPort1.ReadLine(); //weight.Text = Regex.Replace(serialPort1.ReadLine(), "\\D+", ""); } catch (Exception) { GetData = false; } } } catch (IOException ex) { OperateResult.AppendText(">>" + ex.Message + "\n", Color.Red, outboxcode); } } else OperateResult.AppendText(">>端口已被占用,请关闭其他窗口\n", Color.Red, outboxcode); } } private void StopWeight_Click(object sender, EventArgs e) { if (serialPort1.IsOpen) { GetData = false; serialPort1.Close(); SystemInf.OpenPort.Remove(serialPort1.PortName); thread.Abort(); } } private void RefreshWeigh_Click(object sender, EventArgs e) { sql.Clear(); sql.Append("select pr_cartonmaxw,pr_cartonunit,pr_cartonminw,pr_cartongw from product where pr_code='" + pr_code.Text + "'"); DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select"); //填充打印文件选项的DataGridView 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_cartongw.Text = Weight + "±" + (MaxWeight - Weight) + dt.Rows[0]["pr_cartonunit"].ToString(); else pr_cartongw.Text = MinWeight + "-" + MaxWeight + dt.Rows[0]["pr_cartonunit"].ToString(); } } } }