public void SavePackage(Sender sender, SavePackageArgs args) { try { using (ObjectProxy op = new ObjectProxy(true)) { Package obj = new Package(); obj.PackageID = args.Package.PackageID; if (op.LoadPackageByPackageID(obj) == 0) { args.Package.Created = DateTime.Now; args.Package.CreatedBy = string.Format("{0}.{1}", sender.UserCode, sender.UserName); op.InsertPackage(args.Package); } else { op.UpdatePackageByPackageID(args.Package); } if (args.PackageDetail != null) { PackageDetail item = new PackageDetail(); item.DetailID = args.PackageDetail.DetailID; if (op.LoadPackageDetailByDetailID(item) == 0) { args.PackageDetail.Created = DateTime.Now; args.PackageDetail.CreatedBy = string.Format("{0}.{1}", sender.UserCode, sender.UserName); args.PackageDetail.Modified = DateTime.Now; args.PackageDetail.ModifiedBy = string.Format("{0}.{1}", sender.UserCode, sender.UserName); op.InsertPackageDetail(args.PackageDetail); } else { args.PackageDetail.Modified = DateTime.Now; args.PackageDetail.ModifiedBy = string.Format("{0}.{1}", sender.UserCode, sender.UserName); op.UpdatePackageDetailByDetailID(args.PackageDetail); } } op.CommitTransaction(); } } catch (Exception ex) { PLogger.LogError(ex); throw ex; } }
private void btnSave_Click(object sender, EventArgs e) { try { if (this.listPackage.Items.Count == 0) { throw new Exception("未添加任何包数据。"); } using (ProxyBE bll = new ProxyBE()) { Order order = bll.Client.GetOrder(CGlobal.SenderUser, OrderID); //订单添加板件明细 List <OrderDetail> suborders = new List <OrderDetail>(); List <OrderDetail> details = bll.Client.GetOrderDetails(CGlobal.SenderUser, OrderID); Order2Cabinet cabinet = bll.Client.GetOrder2Cabinet(CGlobal.SenderUser, this.CabinetID); int itemsQty = 1; foreach (ListViewItem li in this.listPackage.Items) { int Qty = int.Parse(li.SubItems[2].Text); for (int i = 0; i < Qty; i++) { OrderDetail subOrder = new OrderDetail(); subOrder.ItemID = Guid.NewGuid(); subOrder.OrderID = this.OrderID; subOrder.BarcodeNo = order.OrderNo + ((char)(64 + cabinet.Sequence)).ToString() + (itemsQty + details.Count + 50).ToString("000"); subOrder.ItemName = li.SubItems[1].Text; subOrder.MadeBattchNum = ""; subOrder.MaterialType = ""; subOrder.MadeLength = 0; subOrder.MadeWidth = 0; subOrder.MadeHeight = 0; subOrder.Qty = 1; subOrder.TextureDirection = ""; subOrder.Edge1 = ""; subOrder.Edge2 = ""; subOrder.Edge3 = ""; subOrder.Edge4 = ""; subOrder.HoleDesc = ""; subOrder.EndLength = 0; subOrder.EndWidth = 0; subOrder.FrontLabel = ""; subOrder.BackLabel = ""; subOrder.PackageCategory = ""; subOrder.PackageSizeType = ""; subOrder.IsSpecialShap = false; subOrder.CabinetID = this.CabinetID; subOrder.Remarks = ""; subOrder.EdgeDesc = ""; subOrder.DamageQty = 0; subOrder.Created = DateTime.Now; suborders.Add(subOrder); Mes.Client.Service.BE.Package p = new Mes.Client.Service.BE.Package(); p.OrderID = OrderID; int pageNum = bll.Client.GetMaxPackageNum(CGlobal.SenderUser, OrderID, subOrder.CabinetID); p.CabinetID = subOrder.CabinetID; p.PackageNum = pageNum; p.PackageBarcode = string.Format("0{0}{1}", order.Created.ToString("yyMMddHHmmss"), pageNum.ToString("00")); p.PackageID = Guid.NewGuid(); p.ItemsQty = 1; //保存条码数据 PackageDetail obj = new PackageDetail(); obj.DetailID = Guid.NewGuid(); obj.ItemID = subOrder.ItemID; obj.PakageID = p.PackageID; obj.IsPlanning = true; obj.IsPakaged = true; obj.IsDisabled = false; obj.IsOptimized = true; obj.LayerNum = 0; obj.Qty = 1; obj.CheckedBy = CGlobal.SenderUser.UserCode + "." + CGlobal.SenderUser.UserName; SavePackageArgs saveArgs = new SavePackageArgs(); saveArgs.Package = p; PackageDetail detail = new PackageDetail(); detail.DetailID = Guid.NewGuid(); detail.CheckedBy = CGlobal.SenderUser.UserCode; detail.IsDisabled = false; detail.IsOptimized = true; detail.IsPakaged = true; detail.IsPlanning = true; detail.ItemID = subOrder.ItemID; detail.LayerNum = 0; detail.PakageID = obj.PakageID; detail.Qty = 1; saveArgs.PackageDetail = detail; bll.Client.SavePackage(CGlobal.SenderUser, saveArgs); itemsQty++; } } SaveOrderArgs saveOrderArgs = new SaveOrderArgs(); saveOrderArgs.Order = order; saveOrderArgs.OrderDetails = suborders; bll.Client.SaveOrder(CGlobal.SenderUser, saveOrderArgs); } this.DialogResult = System.Windows.Forms.DialogResult.OK; } catch (Exception ex) { MessageBox.Show(ex.Message, "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void ScanBarcode() { if (this.InvokeRequired) { this.Invoke(new dreadbarcode(ScanBarcode), null); } else { if (WorkFlowID == Guid.Empty) { throw new Exception("请在参数设置中设置班次和分拣对应的工序名称。"); } if (WorkShiftID == Guid.Empty) { throw new Exception("请在参数设置中设置班次和分拣对应的工序名称。"); } string ItemBarcode = this.txtBarcode.Text.Trim(); if (string.IsNullOrEmpty(ItemBarcode)) { this.txtBarcode.Clear(); this.txtBarcode.Focus(); lblMsg.Text = "【提示】请扫描板件条码"; PlayVoice("请扫描板件条码"); return; } #region 完成当前分包操作 if (ItemBarcode.IndexOf(FinishedBarcode) >= 0 && !string.IsNullOrEmpty(FinishedBarcode)) { try { //打印分包标签 PlayVoice("打印标签"); //PrintDocument(); StartPrint(this.CurrentPackage.PackageID); this.txtBarcode.Text = ""; this.txtBarcode.Focus(); this.CurrentPackage = null; } catch (Exception ex) { this.CurrentPackage = null; throw ex; } return; } #endregion using (ProxyBE p = new ProxyBE()) { OrderDetail subOrder = p.Client.GetOrderDetailByBarcode(CGlobal.SenderUser, ItemBarcode); if (subOrder == null) { this.txtBarcode.Clear(); this.txtBarcode.Focus(); lblMsg.Text = string.Format("提示:【{0}】条码无效", ItemBarcode); PlayVoice("条码错误"); return; } Order order = p.Client.GetOrder(CGlobal.SenderUser, subOrder.OrderID); //初始化订单数据:如果当前订单ID与条码的订单ID不一至时则重置订单信息 if (CurrentOrder == null) { this.CurrentOrder = order; this.txtOrderNo.Text = this.CurrentOrder.OrderNo; } //判断当前的板件是否为同一订单板件 else if (subOrder.OrderID != this.CurrentOrder.OrderID) { this.txtBarcode.Clear(); this.txtBarcode.Focus(); lblMsg.Text = "【错误】板件订单号不一致"; PlayVoice("订单不一致"); MessageBox.Show("板件订单号不一致"); return; } List <PackageDetail> pdsubOrder = p.Client.GetPackageDetailsByItemID(CGlobal.SenderUser, subOrder.ItemID); pdsubOrder = pdsubOrder.FindAll(li => li.IsPakaged == false); if (pdsubOrder.Count == 0) { this.txtBarcode.Clear(); this.txtBarcode.Focus(); lblMsg.Text = string.Format("提示:【{0}】条码重复扫描", ItemBarcode); PlayVoice("重复扫描"); return; } decimal weight = subOrder.MadeHeight * subOrder.MadeLength * subOrder.MadeWidth * 0.000001M * Density; if (this.CurrentPackage != null) { if (this.CurrentPackage.Weight + weight >= MaxWeight) { //打印分包标签 PlayVoice("打印标签"); StartPrint(this.CurrentPackage.PackageID); this.txtBarcode.Text = ""; this.txtBarcode.Focus(); this.CurrentPackage = null; } } Order2Cabinet cabinet = p.Client.GetOrder2Cabinet(CGlobal.SenderUser, subOrder.CabinetID); if (cabinet != null) { //初始化包数据 if (this.CurrentPackage == null) { Mes.Client.Service.BE.Package pack = new Mes.Client.Service.BE.Package(); pack.OrderID = this.CurrentOrder.OrderID; int pageNum = 0; pageNum = p.Client.GetMaxPackageNum(CGlobal.SenderUser, pack.OrderID, subOrder.CabinetID); pack.CabinetID = subOrder.CabinetID; pack.PackageNum = pageNum; pack.PackageID = Guid.NewGuid(); pack.PackageBarcode = string.Format("0{0}{1}", CurrentOrder.Created.ToString("yyMMddHHmmss"), pageNum.ToString("00")); pack.PackageLength = 0; pack.PackageHeight = 0; pack.PackageWidth = 0; pack.ItemsQty = 0; this.CurrentPackage = pack; this.txtCabinetName.Text = cabinet.CabinetName; } else if (CurrentPackage.CabinetID != cabinet.CabinetID) { this.txtBarcode.Clear(); this.txtBarcode.Focus(); lblMsg.Text = "【错误】柜体不一致!"; PlayVoice("柜体不一致"); return; } } else { lblMsg.Text = string.Format("提示:【{0}】条码所属柜体数据丢失,请查看订单是否有误!", ItemBarcode); PlayVoice("订单错误"); return; } try { p.Client.ScanBarcode(CGlobal.SenderUser, ItemBarcode, WorkShiftID, WorkFlowID); } catch (Exception ex) { PLogger.LogError(ex); this.txtBarcode.Clear(); this.txtBarcode.Focus(); lblMsg.Text = ex.Message; PlayVoice("扫描失败"); return; } this.CurrentPackage.Weight += weight; this.CurrentPackage.ItemsQty += 1; SavePackageArgs saveArgs = new SavePackageArgs(); saveArgs.Package = this.CurrentPackage; PackageDetail packageDetail = pdsubOrder[0]; packageDetail.IsPakaged = true; packageDetail.PakageID = this.CurrentPackage.PackageID; saveArgs.PackageDetail = packageDetail; p.Client.SavePackage(CGlobal.SenderUser, saveArgs); this.CurrentPackage = p.Client.GetPackage(CGlobal.SenderUser, this.CurrentPackage.PackageID); this.gbPackage.Text = string.Format("当前:第{0}包", this.CurrentPackage.PackageNum); //刷新列表 biForm(); this.txtBarcode.Clear(); this.txtBarcode.Focus(); lblMsg.Text = "扫描完成"; PlayVoice("OK"); //检查是否已经全部扫描完成 if (this.listBarcodes.Items.Count == 0) { //打印分包标签 PlayVoice("打印标签"); //PrintDocument(); StartPrint(this.CurrentPackage.PackageID); this.txtBarcode.Text = ""; this.txtBarcode.Focus(); this.CurrentPackage = null; cabinet.CabinetStatus = "F"; SaveOrder2CabinetArgs cabinetArgs = new SaveOrder2CabinetArgs(); cabinetArgs.Order2Cabinet = cabinet; p.Client.SaveOrder2Cabinet(CGlobal.SenderUser, cabinetArgs); SearchPackageDetailArgs p_args = new SearchPackageDetailArgs(); p_args.IsDisabled = false; p_args.OrderID = CurrentOrder.OrderID; p_args.IsPakaged = false; SearchResult p_sr = p.Client.SearchPackageDetail(CGlobal.SenderUser, p_args); if (p_sr.Total == 0) { //Order order = p.Client.GetOrder(CGlobal.SenderUser, CurrentOrder.OrderID); order.Status = "I"; //全部打包完成后,订单状态变成待入库 SaveOrderArgs saveOrderArgs = new SaveOrderArgs(); saveOrderArgs.Order = order; p.Client.SaveOrder(CGlobal.SenderUser, saveOrderArgs); } } //加载树 initTree(); } } }