protected override object GetItemFromInput() { StackInSheet sheet = UpdatingItem as StackInSheet; if (sheet == null) { sheet = new StackInSheet(); if (txtSheetNo.Text == "自动创建") { sheet.ID = string.Empty; } sheet.ClassID = StackInSheetType.InventorySheet; } else { sheet.ID = this.txtSheetNo.Text; } sheet.SupplierID = Supplier != null ? Supplier.ID : null; sheet.WareHouseID = WareHouse != null ? WareHouse.ID : null; sheet.SheetDate = dtSheetDate.Value; sheet.Memo = txtMemo.Text; sheet.Items = new List <StackInItem>(); foreach (DataGridViewRow row in ItemsGrid.Rows) { if (row.Tag != null) { StackInItem item = row.Tag as StackInItem; item.SheetNo = sheet.ID; sheet.Items.Add(item); } } return(sheet); }
private void ItemsGrid_CellEndEdit(object sender, DataGridViewCellEventArgs e) { DataGridViewColumn col = ItemsGrid.Columns[e.ColumnIndex]; DataGridViewRow row = ItemsGrid.Rows[e.RowIndex]; if (row.Tag != null) { StackInItem item = row.Tag as StackInItem; 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, StackInItem 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.Trim(); row.Cells["colOrderID"].Value = item.OrderID; row.Cells["colPurchaseOrder"].Value = item.PurchaseOrder; row.Cells["colTotal"].Value = item.Amount; }
public void AddInventoryItem(Product product) { List <StackInItem> sources = GetDeliveryItemsFromGrid(); if (!sources.Exists(it => it.ProductID == product.ID && it.PurchaseItem == null)) { StackInItem item = new StackInItem() { ID = Guid.NewGuid(), ProductID = product.ID, Unit = product.Unit, Price = product.Cost, Count = 0 }; sources.Add(item); } ShowSheetItemsOnGrid(sources); }
public void AddInventoryItem(PurchaseItemRecord pi) { List <StackInItem> sources = GetDeliveryItemsFromGrid(); if (!sources.Exists(it => it.ProductID == pi.ProductID && it.PurchaseItem == pi.ID)) { StackInItem item = new StackInItem(); item.ID = Guid.NewGuid(); item.ProductID = pi.ProductID; item.PurchaseItem = pi.ID; item.PurchaseOrder = pi.SheetNo; item.OrderItem = pi.OrderItem; item.OrderID = pi.OrderID; item.Unit = pi.Unit; item.Price = pi.Price; item.Count = pi.OnWay; item.Amount = item.Price * item.Count; sources.Add(item); } ShowSheetItemsOnGrid(sources); }
protected override void UpdatingItem(StackInSheet newVal, StackInSheet original, DataContext dc) { dc.GetTable <StackInSheet>().Attach(newVal, original); foreach (StackInItem item in newVal.Items) { StackInItem old = original.Items.SingleOrDefault(it => it.ID == item.ID); if (old != null) { dc.GetTable <StackInItem>().Attach(item, old); } else { dc.GetTable <StackInItem>().InsertOnSubmit(item); } } foreach (StackInItem item in original.Items) { if (newVal.Items.SingleOrDefault(it => it.ID == item.ID) == null) { dc.GetTable <StackInItem>().Attach(item); dc.GetTable <StackInItem>().DeleteOnSubmit(item); } } }