protected override bool CheckInput() { if (string.IsNullOrEmpty(txtSheetNo.Text) && UpdatingItem != null) { MessageBox.Show("送货单号不能为空"); txtSheetNo.Focus(); return(false); } if (WareHouse == null) { MessageBox.Show("请选择收货的仓库"); txtWareHouse.Focus(); return(false); } if (ItemsGrid.Rows.Count == 0) { MessageBox.Show("收货单没有填写收货项"); return(false); } foreach (DataGridViewRow row in ItemsGrid.Rows) { StackOutItem item = row.Tag as StackOutItem; if (item != null && item.Count == 0) { MessageBox.Show(string.Format("收货单第 {0} 项收货数量为零", row.Index + 1)); row.Selected = true; return(false); } } return(true); }
private void Assign(StackOutItem si, InventoryOutType inventoryOutType, List <ProductInventoryItem> inventoryItems, List <ProductInventoryItem> addingItems) { List <ProductInventoryItem> items = new List <ProductInventoryItem>(); if (si.OrderItem != null) //如果出货单项有相关的订单项,那么出货时只扣除与此订单项相关的库存项和未分配给任何订单的库存项 { items.AddRange(inventoryItems.Where(item => item.ProductID == si.ProductID && item.DeliveryItem == null && item.OrderItem == si.OrderItem)); } if (inventoryOutType == InventoryOutType.FIFO) //根据产品的出货方式将未指定订单项的库存排序 { items.AddRange(from item in inventoryItems where item.ProductID == si.ProductID && item.DeliveryItem == null && item.OrderItem == null orderby item.AddDate ascending select item); } else { items.AddRange(from item in inventoryItems where item.ProductID == si.ProductID && item.DeliveryItem == null && item.OrderItem == null orderby item.AddDate descending select item); } if (items.Sum(item => item.Count) < si.Count) { throw new Exception(string.Format("产品 {0} 库存不足,出货失败!", si.ProductID)); } decimal count = si.Count; foreach (ProductInventoryItem item in items) { if (count > 0) { if (item.Count > count) //对于部分出货的情况,一条库存记录拆成两条,其中一条表示出货的,另一条表示未出货部分,即要保证DelvieryItem不为空的都是未出货的,为空的都是已经出货的 { ProductInventoryItem pii = item.Clone(); pii.ID = Guid.NewGuid(); pii.OrderItem = si.OrderItem; pii.OrderID = si.OrderID; pii.DeliveryItem = si.ID; pii.DeliverySheet = si.SheetNo; pii.Count = count; addingItems.Add(pii); item.Count -= count; count = 0; } else { item.OrderItem = si.OrderItem; item.OrderID = si.OrderID; item.DeliveryItem = si.ID; item.DeliverySheet = si.SheetNo; count -= item.Count; } } } }
private void ItemsGrid_CellEndEdit(object sender, DataGridViewCellEventArgs e) { DataGridViewColumn col = ItemsGrid.Columns[e.ColumnIndex]; DataGridViewRow row = ItemsGrid.Rows[e.RowIndex]; if (row.Tag != null) { StackOutItem item = row.Tag as StackOutItem; if (col.Name == "colPrice") { decimal price; if (decimal.TryParse(row.Cells[e.ColumnIndex].Value.ToString(), out price)) { if (price < 0) { price = 0; } item.Price = price; item.Amount = price * item.Count; row.Cells[e.ColumnIndex].Value = price; } } if (col.Name == "colTotal") { decimal amount; if (decimal.TryParse(row.Cells[e.ColumnIndex].Value.ToString(), out amount)) { if (amount < 0) { amount = 0; } item.Amount = amount; row.Cells[e.ColumnIndex].Value = amount; } } else if (col.Name == "colCount") { int count; if (int.TryParse(row.Cells[e.ColumnIndex].Value.ToString(), out count)) { if (count < 0) { count = 0; } item.Count = count; item.Amount = count * item.Price; row.Cells[e.ColumnIndex].Value = count; } } row.Cells["colTotal"].Value = item.Amount; ItemsGrid.Rows[ItemsGrid.Rows.Count - 1].Cells["colTotal"].Value = GetTotalAmount(); } }
private void ShowDeliveryItemOnRow(DataGridViewRow row, StackOutItem item, Product p) { row.Tag = item; row.Cells["colHeader"].Value = this.ItemsGrid.Rows.Count; row.Cells["colProductID"].Value = item.ProductID; row.Cells["colProductName"].Value = p != null ? p.Name : string.Empty; row.Cells["colSpecification"].Value = p != null ? p.Specification : string.Empty; row.Cells["colCategory"].Value = p != null && p.Category != null ? p.Category.Name : string.Empty; row.Cells["colUnit"].Value = item.Unit; row.Cells["colPrice"].Value = item.Price; row.Cells["colCount"].Value = item.Count; row.Cells["colTotal"].Value = item.Amount; row.Cells["colOrderID"].Value = item.OrderID; row.Cells["colMemo"].Value = item.Memo; }
public void AddDeliveryItem(ProductInventory p) { List <StackOutItem> sources = GetDeliveryItemsFromGrid(); if (!sources.Exists(it => it.ProductID == p.ProductID)) { StackOutItem item = new StackOutItem(); item.ID = Guid.NewGuid(); item.ProductID = p.ProductID; item.Unit = p.Unit; item.Price = p.Product != null ? p.Product.Price : 0; item.Count = 0; item.Amount = item.Price * item.Count; sources.Add(item); } ShowDeliveryItemsOnGrid(sources); }
public void AddDeliveryItem(OrderItemRecord oi) { List <StackOutItem> sources = GetDeliveryItemsFromGrid(); if (!sources.Exists(it => it.OrderItem != null && it.OrderItem.Value == oi.ID)) { StackOutItem item = new StackOutItem(); item.ID = Guid.NewGuid(); item.ProductID = oi.ProductID; item.Unit = oi.Unit; item.Price = oi.Price; item.Count = oi.NotShipped; item.Amount = item.Price * item.Count; item.OrderItem = oi.ID; item.OrderID = oi.SheetNo; sources.Add(item); } ShowDeliveryItemsOnGrid(sources); }
protected override object GetItemFromInput() { StackOutSheet sheet = UpdatingItem as StackOutSheet; if (sheet == null) { sheet = new StackOutSheet(); sheet.ID = txtSheetNo.Text == "自动创建" ? string.Empty : this.txtSheetNo.Text; sheet.ClassID = StackOutSheetType.DeliverySheet; } else { sheet = UpdatingItem as StackOutSheet; } sheet.CustomerID = Customer != null ? Customer.ID : null; if (cmbSheetType.SelectedIndex == 0) { sheet.ClassID = StackOutSheetType.DeliverySheet; } if (cmbSheetType.SelectedIndex == 1) { sheet.ClassID = StackOutSheetType.CustomerBorrow; } sheet.WareHouseID = WareHouse != null ? WareHouse.ID : null; sheet.SheetDate = dtSheetDate.Value; sheet.Linker = txtLinker.Text.Trim(); sheet.LinkerPhoneCall = txtLinkerPhone.Text.Trim(); sheet.Address = txtAddress.Text.Trim(); sheet.Memo = txtMemo.Text; sheet.Items = new List <StackOutItem>(); foreach (DataGridViewRow row in ItemsGrid.Rows) { if (row.Tag != null) { StackOutItem item = row.Tag as StackOutItem; item.SheetNo = sheet.ID; sheet.Items.Add(item); } } return(sheet); }
protected override void UpdatingItem(StackOutSheet newVal, StackOutSheet original, DataContext dc) { dc.GetTable <StackOutSheet>().Attach(newVal, original); foreach (StackOutItem item in newVal.Items) { StackOutItem old = original.Items.SingleOrDefault(it => it.ID == item.ID); if (old != null) { dc.GetTable <StackOutItem>().Attach(item, old); } else { dc.GetTable <StackOutItem>().InsertOnSubmit(item); } } foreach (StackOutItem item in original.Items) { if (newVal.Items.SingleOrDefault(it => it.ID == item.ID) == null) { dc.GetTable <StackOutItem>().Attach(item); dc.GetTable <StackOutItem>().DeleteOnSubmit(item); } } }