/// <summary> /// 下载数据到客户端 /// </summary> /// <param name="MethodsName"></param> /// <returns></returns> public List <OutboundOrder> HproseDownDataDBCK() { List <OutboundOrder> OutboundOrderList = new List <OutboundOrder>(); try { DataTable DataTable = new PDAServer().GetOutOrderDBCK(); if (DataTable != null && DataTable.Rows.Count > 0) { //public OutboundOrder(string KCSWZ_SWKCBH, string KCSWZ_RCKDH, string KCSWZ_BCCK, string KCSWZ_BRCK, string KCSWZ_JZRQ, string KCSWZMX_FZCKSL, string KCSWZMX_SFSL) foreach (DataRow row in DataTable.Rows) { //OutboundOrderList.Add(new OutboundOrder(row["KCSWZ_SWKCBH"].ToString(), row["KCSWZ_KHID"].ToString(), row["KCSWZ_JZRQ"].ToString(), row["KH_MC"].ToString(), row["KCSWZMX_FZCKSL"].ToString(), row["yfsl"].ToString())); OutboundOrderList.Add(new OutboundOrder(row["KCSWZ_SWKCBH"].ToString(), row["KCSWZ_RCKDH"].ToString(), row["BCCK"].ToString(), row["BRCK"].ToString(), row["KCSWZ_JZRQ"].ToString(), row["KCSWZMX_FZCKSL"].ToString(), row["yfsl"].ToString(), row["KCSWZ_SWLX"].ToString(), row["KCSWZ_DFCK"].ToString(), row["WL_FJLDW"].ToString().Trim(), row["Comment"].ToString())); } } } catch (Exception ex) { OutboundOrder _product = new OutboundOrder(); _product.KH_MC1 = ex.Message; OutboundOrderList.Add(_product); } return(OutboundOrderList); }
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (!DataGridViewUtil.CheckPerrmisson(this, sender, e)) { return; } if (e.RowIndex < 0 || e.ColumnIndex < 0) { return; } try { List <OutboundOrder> list = (List <OutboundOrder>) this.dataGridView1.DataSource; OutboundOrder item = list[e.RowIndex]; if (this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].OwningColumn.DataPropertyName == iDDataGridViewTextBoxColumn1.DataPropertyName) { this.skinSplitContainer1.Panel2Collapsed = false; this.OutboundDetailClick?.Invoke(item, this.skinSplitContainer1.Panel2); } if (sourceOrderIDDataGridViewTextBoxColumn1.Index == e.ColumnIndex) { this.skinSplitContainer1.Panel2Collapsed = false; this.SourceDetailClick?.Invoke(item.SourceOrderID, this, this.skinSplitContainer1.Panel2); } } catch (Exception ee) { CommonGlobalUtil.ShowError(ee); } }
/// <summary> /// 对出库单进行关闭前检查。 /// </summary> /// <param name="outboundOrder"></param> private async Task CheckOnCloseAsync(OutboundOrder outboundOrder) { // 应始终检查出库单是否挂在出货口上 var ports = await _session.Query <Port>().Where(x => x.CurrentUat == outboundOrder).Select(x => x.PortCode).ToListAsync(); if (ports.Count() > 0) { string str = string.Join(", ", ports.Select(x => x)); string msg = string.Format("出库单正在下架。在出口 {1}。", outboundOrder.OutboundOrderCode, str); throw new InvalidOperationException(msg); } // 出库单下有分配的货载时不允许关闭,否则,货载将无法释放。 if (outboundOrder.Unitloads.Count > 0) { string msg = string.Format("出库单下有分配的库存。", outboundOrder.OutboundOrderCode); throw new InvalidOperationException(msg); } // 应始终检查是否有移动的货载 if (outboundOrder.Unitloads.Any(x => x.BeingMoved)) { string msg = string.Format("出库单下有任务。", outboundOrder.OutboundOrderCode); throw new InvalidOperationException(msg); } //// TODO 考虑是否在库外有托盘时禁止取消 //if (outboundOrder.UnitloadsAllocated.Any(x => x.InRack() == false)) //{ // string msg = string.Format("出库单下有任务。", outboundOrder.OutboundOrderCode); // throw new InvalidOperationException(msg); //} }
private void accordionControlElement63_Click(object sender, EventArgs e) { obo = new OutboundOrder(); obo.Show(); obo.Dock = DockStyle.Fill; panel2.Controls.Clear(); panel2.Controls.Add(obo); }
private void SetOutboundOrder(object sender, FilterEventArgs e) { OutboundOrder _OutboundOrder = e.Item as OutboundOrder; if (_OutboundOrder != null) { e.Accepted = (Convert.ToInt32(_OutboundOrder.KCSWZMX_SFSL1) == 0); } }
/// <summary> /// 确定工作单号 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ButtonConfirm_Click(object sender, RoutedEventArgs e) { if (ListboxP.SelectedIndex != -1) { OutboundOrder order = Product_Observable.GetOutOrderFind(CheckoutInfo.CKD_CKBH); SetOutOrderWord(order); } Button _button = sender as Button; if (_button != null) { int sjcount = (int)double.Parse(CheckoutInfo.YFSL); int sfsl = Convert.ToInt32(CheckoutInfo.SFSL); if (CheckoutInfo.KCSWZ_FJLDW == "") { sjcount = new PDAServer().GetERP_KcswzCount(CheckoutInfo.CKD_CKBH); textnum.Text = CheckoutInfo.YFSL = sjcount.ToString(); } if (textpici.Text != "") { if (sfsl <= sjcount) { sjcount = sjcount - sfsl; } int count = Convert.ToInt32(textpici.Text); if (count > sjcount) { MessageBox.Show("填写的发货数量不能大于等于发货单上的出库数量"); textpici.Text = ""; Tools.SFCount = 0; return; } else { Tools.SFCount = count;// Convert.ToInt32(textpici.Text);} CheckoutInfo.PDSL = sjcount.ToString(); } } else { Tools.SFCount = 0; CheckoutInfo.PDSL = (sjcount - sfsl).ToString(); } ListboxP.SelectedItem = null; ButtonConfirm.IsEnabled = false; ReadButton.IsEnabled = true; CodeText.IsEnabled = true; ListboxP.IsEnabled = false; TextBoxP.IsEnabled = false; butviewFill.IsEnabled = false; ButtonConfirmRE.IsEnabled = true; CodeText.Focus(); } }
public async Task <ApiData> DeallocateInRack(int id) { OutboundOrder outboundOrder = await _session.GetAsync <OutboundOrder>(id); if (outboundOrder == null || outboundOrder.Closed) { throw new InvalidOperationException("出库单不存在或已关闭。"); } await _outboundOrderAllocator.DeallocateInRackAsync(outboundOrder); return(this.Success()); }
/// <summary> /// 选择产品 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ListBox_SelectionChanged_1(object sender, SelectionChangedEventArgs e) { ListBox listbox = sender as ListBox; if (listbox.SelectedItem != null) { OutboundOrder OutboundOrderOK = listbox.SelectedItem as OutboundOrder; if (OutboundOrderOK != null) { Tools.SFCount = 0; SetOutOrderWord(OutboundOrderOK); } } }
private Outbound BuildOutbound() { if (this.curReplenishOrder == null || this.curReplenishDetailList == null || this.curReplenishDetailList.Count == 0) { return(null); } int totalCount = 0; decimal totalPrice = 0; decimal totalCost = 0; List <BoundDetail> details = new List <BoundDetail>(); //使用补货申请单的店铺ID信息 Shop shop = GlobalCache.ShopList.Find(t => t.ID == this.curReplenishOrder.ShopID); string id = IDHelper.GetID(OrderPrefix.OutboundOrder, shop.AutoCode); string replenishOrderid = IDHelper.GetID(OrderPrefix.ReplenishOrder, shop.AutoCode); foreach (ReplenishDetail detail in this.curReplenishDetailList) { if (detail.SumCount <= 0) { continue; } totalCost += detail.SumCost; totalCount += detail.SumCount; totalPrice += detail.SumMoney; details.Add(this.ReplenishDetailConvertToOutboundDetail(detail, id)); } OutboundOrder order = new OutboundOrder() { SourceOrderID = curReplenishOrder.IsRedo? replenishOrderid:this.curReplenishOrder.ID, ID = id, OperatorUserID = GlobalCache.CurrentUserID, ShopID = GlobalCache.ServerProxy.GetGeneralStoreShopID(), CreateTime = DateTime.Now, TotalCount = totalCount, TotalPrice = totalPrice, TotalCost = totalCost, Remarks = this.skinTextBox_Remarks.SkinTxt.Text }; return(new Outbound() { OutboundDetails = details, OutboundOrder = order }); }
public async Task <ApiData> DeleteOutboundOrder(int id) { OutboundOrder outboundOrder = await _session.GetAsync <OutboundOrder>(id); if (outboundOrder.Lines.Any(x => x.Dirty)) { throw new InvalidOperationException("出库单已发生过操作。"); } await _session.DeleteAsync(outboundOrder); _logger.Information("已删除出库单 {outboundOrder}", outboundOrder); await _opHelper.SaveOpAsync(outboundOrder.OutboundOrderCode); return(this.Success()); }
private void ListboxEndOut_SelectionChanged(object sender, SelectionChangedEventArgs e) { ListBox listbox = sender as ListBox; if (listbox.SelectedItem != null) { OutboundOrder OutboundOrderOK = listbox.SelectedItem as OutboundOrder; if (OutboundOrderOK != null) { EndTextkhNmae.Text = OutboundOrderOK.KH_MC1; EndTextOrder.Text = OutboundOrderOK.KCSWZ_SWKCBH1; EndTextSfsl.Text = OutboundOrderOK.KCSWZMX_SFSL1; EndTextYfsl.Text = OutboundOrderOK.KCSWZMX_FZCKSL1.ToString(); EndTextJzrq.Text = OutboundOrderOK.KCSWZ_JZRQ1; } } }
/// <summary> /// 关键字过滤器 索引 出库单号 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void GetOutboundOrder(object sender, FilterEventArgs e) { OutboundOrder _OutboundOrder = e.Item as OutboundOrder; if (_OutboundOrder == null) { return; } else { if (SearchNum == "") { return; } e.Accepted = (_OutboundOrder.KCSWZ_SWKCBH1.ToLower().Trim().Contains(SearchNum)); } }
public async Task <ApiData> CreateOutboundOrder(CreateOutboundOrderArgs args) { OutboundOrder outboundOrder = new OutboundOrder(); string prefix = $"OBO{DateTime.Now:yyMMdd}"; int next = await _appSeqService.GetNextAsync(prefix); outboundOrder.OutboundOrderCode = $"{prefix}{next:00000}"; outboundOrder.BizType = args.BizType; outboundOrder.BizOrder = args.BizOrder; outboundOrder.Comment = args.Comment; if (args.Lines == null || args.Lines.Count == 0) { throw new InvalidOperationException("出库单应至少有一个出库行。"); } foreach (var lineInfo in args.Lines) { OutboundLine line = new OutboundLine(); var material = await _session.Query <Material>() .Where(x => x.MaterialCode == lineInfo.MaterialCode) .SingleOrDefaultAsync(); if (material == null) { throw new InvalidOperationException($"未找到编码为 {lineInfo.MaterialCode} 的物料。"); } line.Material = material; line.QuantityRequired = lineInfo.QuantityRequired; line.QuantityDelivered = 0; line.Batch = lineInfo.Batch; line.StockStatus = lineInfo.StockStatus; line.Uom = lineInfo.Uom; outboundOrder.AddLine(line); _logger.Information("已添加出库单明细,物料 {materialCode},批号 {batch},需求数量 {quantity}", line.Material.MaterialCode, line.Batch, line.QuantityRequired); } await _session.SaveAsync(outboundOrder); _logger.Information("已创建出库单 {outboundOrder}", outboundOrder); _ = await _opHelper.SaveOpAsync(outboundOrder.OutboundOrderCode); return(this.Success()); }
public OutboundDetailCtrl(OutboundOrder outboundOrder) { InitializeComponent(); dataGridViewPagingSumCtrl = new DataGridViewPagingSumCtrl(dataGridView1, new string[] { xSDataGridViewTextBoxColumn.DataPropertyName, sDataGridViewTextBoxColumn.DataPropertyName, mDataGridViewTextBoxColumn.DataPropertyName, lDataGridViewTextBoxColumn.DataPropertyName, xLDataGridViewTextBoxColumn.DataPropertyName, xL2DataGridViewTextBoxColumn.DataPropertyName, xL3DataGridViewTextBoxColumn.DataPropertyName, xL4DataGridViewTextBoxColumn.DataPropertyName, xL5DataGridViewTextBoxColumn.DataPropertyName, xL6DataGridViewTextBoxColumn.DataPropertyName, fDataGridViewTextBoxColumn.DataPropertyName, sumMoneyDataGridViewTextBoxColumn.DataPropertyName, sumCountDataGridViewTextBoxColumn.DataPropertyName }); dataGridViewPagingSumCtrl.Initialize(); this.curOutboundOrder = outboundOrder; Initialize(); }
private void SetOutOrderWord(OutboundOrder OutboundOrderOK) { textPgx.Text = CheckoutInfo.PRODUCTID_JZRQ = OutboundOrderOK.KCSWZ_JZRQ1; textPname.Text = CheckoutInfo.StockOut_KHMC = OutboundOrderOK.KH_MC1; textPid.Text = CheckoutInfo.AGEENID_KHID = OutboundOrderOK.KCSWZ_KHID1; textnum.Text = CheckoutInfo.YFSL = OutboundOrderOK.KCSWZMX_FZCKSL1.ToString(); OrderText.Text = CheckoutInfo.CKD_CKBH = OutboundOrderOK.KCSWZ_SWKCBH1; SOutnumText.Text = CheckoutInfo.SFSL = OutboundOrderOK.KCSWZMX_SFSL1; TextStoreIN.Text = CheckoutInfo.KCSWZ_BRCK1 = OutboundOrderOK.KCSWZ_BRCK1; TextStoreOUT.Text = CheckoutInfo.KCSWZ_BCCK1 = OutboundOrderOK.KCSWZ_BCCK1; CheckoutInfo.KCSWZ_FJLDW = OutboundOrderOK.KCSWZ_FJLDW; CheckoutInfo.KCSWZ_BRCKID = OutboundOrderOK.KCSWZ_BRCKID1; CheckoutInfo.Remarks = OutboundOrderOK.Remarks; if (OutboundOrderOK.KCSWZ_SWLX1 == "DBCK") { OrderTypeText.Text = CheckoutInfo.KCSWZ_SWLX1 = OutboundOrderOK.KCSWZ_SWLX1 + "|调拨出库"; } else { OrderTypeText.Text = CheckoutInfo.KCSWZ_SWLX1 = OutboundOrderOK.KCSWZ_SWLX1 + "|销售出库"; } }
public async Task <ApiData> Deallocate(int id, OutboundOrderDeallocateArgs args) { if (args == null || args.PalletCodes == null || args.PalletCodes.Length == 0) { throw new InvalidOperationException("未指定要取消分配的托盘。"); } OutboundOrder outboundOrder = await _session.GetAsync <OutboundOrder>(id); if (outboundOrder == null || outboundOrder.Closed) { throw new InvalidOperationException("出库单不存在或已关闭。"); } List <Unitload> unitloads = await _session .Query <Unitload>() .Where(x => args.PalletCodes.Contains(x.PalletCode)) .ToListAsync(); foreach (var u in unitloads) { await _outboundOrderAllocator.DeallocateAsync(outboundOrder, u); } return(this.Success()); }
public async Task <ApiData> Close(int id) { OutboundOrder outboundOrder = await _session.GetAsync <OutboundOrder>(id); if (outboundOrder == null) { throw new InvalidOperationException("出库单不存在。"); } if (outboundOrder.Closed) { throw new InvalidOperationException($"出库单已关闭。"); } // 关闭前检查 await CheckOnCloseAsync(outboundOrder); outboundOrder.Closed = true; outboundOrder.ClosedAt = DateTime.Now; _session.Update(outboundOrder); await _opHelper.SaveOpAsync(outboundOrder.OutboundOrderCode); // 取消分配,以免关单后有未释放的货载 foreach (var u in outboundOrder.Unitloads.ToList()) { await _outboundOrderAllocator.DeallocateAsync(outboundOrder, u); } await _session.UpdateAsync(outboundOrder); _logger.Information("已关闭出库单 {outboundOrder}", outboundOrder); await _simpleEventBus.FireEventAsync(EventTypes.OutboundOrderClosed, outboundOrder); return(this.Success()); }
/// <summary> /// 加载单号数据 /// </summary> /// <returns></returns> public List <OutboundOrder> HproseDownDataOrder() { List <OutboundOrder> OutboundOrderList = new List <OutboundOrder>(); try { //DataTable DataTable = new PDAServer().GetOutboundOrder(); DataTable DataTable = new GJPERPinterface().GetOutboundOrder(); if (DataTable != null && DataTable.Rows.Count > 0) { foreach (DataRow row in DataTable.Rows) { OutboundOrderList.Add(new OutboundOrder(row["KCSWZMX_SWKCBH"].ToString(), row["KCSWZ_KHID"].ToString(), row["KCSWZMX_JZRQ"].ToString(), row["KH_MC"].ToString(), row["KCSWZMX_FZCKSL"].ToString(), row["yfsl"].ToString(), row["KCSWZ_SWLX"].ToString(), row["WL_FJLDW"].ToString().Trim(), row["Comment"].ToString())); } } } catch (Exception ex) { OutboundOrder _product = new OutboundOrder(); _product.KH_MC1 = ex.Message; OutboundOrderList.Add(_product); } return(OutboundOrderList); }
private ScrapCostume Build() { if (this.curOutboundDetailList == null || this.curOutboundDetailList.Count == 0) { return(null); } int totalCount = 0; decimal totalPrice = 0; decimal totalCost = 0; List <BoundDetail> outboundDetails = new List <BoundDetail>(); //使用报损单的店铺ID信息 // Shop shop = GlobalCache.ShopList.Find(t => t.ID == this.curReplenishOrder.ShopID); Shop shop = (Shop)this.skinComboBoxShopID.SelectedItem; string id = IDHelper.GetID(OrderPrefix.OutboundOrder, shop.AutoCode); string pOrderID = IDHelper.GetID(OrderPrefix.ScrapOrder, shop.AutoCode); foreach (BoundDetail detail in this.curOutboundDetailList) { if (detail.SumCount <= 0) { continue; } if (detail.Comment == null) { detail.Comment = ""; } totalCount += detail.SumCount; totalPrice += detail.SumMoney; totalCost += detail.SumCost; detail.BoundOrderID = id; outboundDetails.Add(detail); } OutboundOrder order = new OutboundOrder() { SourceOrderID = pOrderID, ID = id, OperatorUserID = GlobalCache.CurrentUserID, ShopID = ValidateUtil.CheckEmptyValue(this.skinComboBoxShopID.SelectedValue), CreateTime = dateTimePicker_Start.Value, EntryTime = DateTime.Now, TotalCount = totalCount, TotalCost = totalCost, TotalPrice = totalPrice, Remarks = this.skinTextBox_Remarks.SkinTxt.Text }; ScrapOrder pOrder = new ScrapOrder() { // GuideID = ValidateUtil.CheckEmptyValue(this.guideComboBox1.SelectedValue), ID = pOrderID, OperatorUserID = GlobalCache.CurrentUserID, OutboundOrderID = order.ID, ShopID = order.ShopID, CreateTime = dateTimePicker_Start.Value, EntryTime = DateTime.Now, TotalCount = totalCount, TotalPrice = totalPrice, Remarks = this.skinTextBox_Remarks.SkinTxt.Text }; List <ScrapDetail> scrapDetails = OutboundDetail2ScrapDetail(outboundDetails, pOrderID); return(new ScrapCostume() { ScrapOrder = pOrder, OutboundOrder = order, OutboundDetails = outboundDetails, ScrapDetails = scrapDetails }); }
private AllocateOutboundPara Build() { if (this.curDetailList == null || this.curDetailList.Count == 0) { return(null); } int totalCount = 0; decimal totalCost = 0; decimal totalPrice = 0; List <BoundDetail> details = new List <BoundDetail>(); string id = IDHelper.GetID(OrderPrefix.OutboundOrder, shop.AutoCode); String pOrderID = IDHelper.GetID(OrderPrefix.AllocateOrder, shop.AutoCode); if (action == OperationEnum.Pick) { pOrderID = this.order.ID; } foreach (BoundDetail detail in this.curDetailList) { if (detail.SumCount <= 0) { continue; } totalCost += detail.SumCost; totalCount += detail.SumCount; totalPrice += detail.SumMoney; detail.BoundOrderID = id; details.Add(detail); // details.Add(this.InboundDetailConvertToOutboundDetail(detail, id)); } OutboundOrder order = new OutboundOrder() { SourceOrderID = pOrderID, ID = id, OperatorUserID = operatorId, ShopID = shop.ID, CreateTime = dateTimePicker_Start.Value, EntryTime = DateTime.Now, TotalCount = totalCount, TotalPrice = totalPrice, TotalCost = totalCost, Remarks = this.skinTextBox_Remarks.SkinTxt.Text }; AllocateOrder pOrder = new AllocateOrder() { AllocateType = (byte)this.curAllocateType, ID = pOrderID, SourceUserID = order.OperatorUserID, OutboundOrderID = order.ID, InboundOrderID = String.Empty, DestShopID = ValidateUtil.CheckEmptyValue(this.skinComboBoxShopID.SelectedValue), CreateTime = dateTimePicker_Start.Value, EntryTime = DateTime.Now, TotalCount = totalCount, TotalPrice = totalPrice, State = 0, SourceShopID = order.ShopID, Remarks = this.skinTextBox_Remarks.SkinTxt.Text // InboundOrderID= }; return(new AllocateOutboundPara() { AllocateOrder = pOrder, OutboundOrder = order, OutboundDetailList = details }); }
private ReturnCostume Build() { if ( this.curDetailList == null || this.curDetailList.Count == 0) { return(null); } int totalCount = 0; decimal totalPrice = 0; decimal totalCost = 0; List <BoundDetail> details = new List <BoundDetail>(); //使用补货申请单的店铺ID信息 // Shop shop = GlobalCache.ShopList.Find(t => t.ID == this.curReplenishOrder.ShopID); Shop shop = (Shop)this.skinComboBoxShopID.SelectedItem; string id = IDHelper.GetID(OrderPrefix.OutboundOrder, shop.AutoCode); string returnOrderId = IDHelper.GetID(OrderPrefix.ReturnOrder, shop.AutoCode); if (action == OperationEnum.Pick) { returnOrderId = this.order?.ID; } foreach (BoundDetail detail in this.curDetailList) { if (detail.SumCount <= 0) { continue; } detail.SumCount = -detail.SumCount; detail.SumMoney = -detail.SumMoney; // detail.SumCount = -detail.SumMoney; totalCount += detail.SumCount; totalPrice += detail.SumMoney; totalCost += detail.SumCost; detail.BoundOrderID = id; detail.SupplierID = ValidateUtil.CheckEmptyValue(skinComboBoxSupplierID.SelectedValue); details.Add(detail); // details.Add(this.OutboundDetailConvertToOutboundDetail(detail, id)); } OutboundOrder order = new OutboundOrder() { SourceOrderID = returnOrderId, ID = id, OperatorUserID = GlobalCache.CurrentUserID, ShopID = ValidateUtil.CheckEmptyValue(this.skinComboBoxShopID.SelectedValue), CreateTime = dateTimePicker_Start.Value, EntryTime = DateTime.Now, TotalCount = totalCount, TotalPrice = totalPrice, TotalCost = totalCost, Remarks = this.skinTextBox_Remarks.SkinTxt.Text }; PurchaseOrder pOrder = new PurchaseOrder() { SupplierID = ValidateUtil.CheckEmptyValue(this.skinComboBoxSupplierID.SelectedValue), ID = returnOrderId, AdminUserID = GlobalCache.CurrentUserID, InboundOrderID = order.ID, DestShopID = order.ShopID, CreateTime = dateTimePicker_Start.Value, EntryTime = DateTime.Now, TotalCount = totalCount, TotalPrice = totalPrice, TotalCost = totalCost, Remarks = this.skinTextBox_Remarks.SkinTxt.Text }; return(new ReturnCostume() { ReturnOrder = pOrder, OutboundOrder = order, OutboundDetailList = details }); }
public async Task <ApiData> Edit(int id, EditOutboundOrderArgs args) { OutboundOrder outboundOrder = _session.Get <OutboundOrder>(id); if (outboundOrder == null) { String errMsg = String.Format("出库单不存在。", id); throw new InvalidOperationException(errMsg); } if (outboundOrder.Closed) { String errMsg = String.Format("出库单已关闭,不能编辑。单号:{0}。", outboundOrder.OutboundOrderCode); throw new InvalidOperationException(errMsg); } var movingDown = await _session.Query <Port>().AnyAsync(x => x.CurrentUat == outboundOrder); if (movingDown) { String errMsg = String.Format("出库单正在下架,不能编辑。单号:{0}。", outboundOrder.OutboundOrderCode); throw new InvalidOperationException(errMsg); } outboundOrder.Comment = args.Comment; if (args.Lines == null || args.Lines.Count == 0) { throw new InvalidOperationException("出库单应至少有一个出库行。"); } foreach (var lineInfo in args.Lines) { switch (lineInfo.Op) { case "delete": { var line = outboundOrder.Lines.Single(x => x.OutboundLineId == lineInfo.OutboundLineId); if (line.Dirty) { string errMsg = String.Format("已发生过出库操作的明细不能删除。出库行#{0}。", line.OutboundLineId); throw new InvalidOperationException(errMsg); } outboundOrder.RemoveLine(line); _logger.Information("已删除出库单明细 {outboundLineId}", line.OutboundLineId); } break; case "edit": { var line = outboundOrder.Lines.Single(x => x.OutboundLineId == lineInfo.OutboundLineId); line.QuantityRequired = lineInfo.QuantityRequired; if (line.QuantityRequired < line.QuantityDelivered) { _logger.Warning("出库单明细 {outboundLineId} 的需求数量修改后小于已出数量", line.OutboundLineId); } } break; case "add": { OutboundLine line = new OutboundLine(); var material = await _session.Query <Material>() .Where(x => x.MaterialCode == lineInfo.MaterialCode) .SingleOrDefaultAsync(); if (material == null) { throw new InvalidOperationException($"未找到物料。编码 {lineInfo.MaterialCode}。"); } line.Material = material; line.QuantityRequired = lineInfo.QuantityRequired; line.QuantityDelivered = 0; line.Batch = lineInfo.Batch; line.StockStatus = lineInfo.StockStatus; line.Uom = lineInfo.Uom; outboundOrder.AddLine(line); _logger.Information("已添加出库单明细,物料 {materialCode},批号 {batch},需求数量 {quantity}", line.Material.MaterialCode, line.Batch, line.QuantityRequired); } break; default: break; } } await _session.UpdateAsync(outboundOrder); _logger.Information("已更新出库单 {outboundOrder}", outboundOrder); _ = await _opHelper.SaveOpAsync("{0}", outboundOrder); // TODO //// 取消库内分配 //_deliveryOrderAllocator.Value.CancelUnitLoadsOnRack(m); //foreach (var line in m.Lines) //{ // if (line.ComputeNumberAllocated() > line.NumberRequired) // { // String errMsg = String.Format("取消库内分配后,分配数量仍然大于应出数量,请处理完此出库单下所有路上和库外的货载再编辑。出库行#{0}。", line.Id); // throw new InvalidOperationException(errMsg); // } //} return(this.Success()); }