void SetDefaultCustomerStore() { var store = source.CustomerStores.First(); OrderPropertiesHelper.UpdateCustomerStoreIfNeeded(order, store.City, source); Invoice.Cells[CellsHelper.FindLeftCell(CellsKind.CustomerStoreName)].Value = store.City; }
public void CellValueChanged(object sender, DevExpress.XtraSpreadsheet.SpreadsheetCellEventArgs e) { if (!AllowChangeOrder()) { return; } string reference = e.Cell.GetReferenceA1(); var oldCustomerId = order.CustomerId; string shiftedRange = CellsHelper.GetActualCellRange(reference, actualOrderItems.Any() ? -actualOrderItems.Count : 0); if (OrderPropertiesHelper.Setters.ContainsKey(shiftedRange)) { OrderPropertiesHelper.Setters[shiftedRange].Invoke(order, e.Cell.Value, source); if (CellsHelper.HasDependentCells(shiftedRange)) { if (order.CustomerId != oldCustomerId) { UpdateCustomerStores(); } CellsHelper.UpdateDependentCells(Invoice, order, source); UpdateTotalValues(); } } if (IsOrderItemsRegionModified(e.Cell)) { UpdateOrderItem(e.Cell); } }
public static void InitializeOrderItem(DevExpress.Spreadsheet.Range itemRange, OrderItem orderItem) { itemRange[CellsHelper.GetOffset(CellsKind.ProductDescription)].Value = orderItem.Product != null ? orderItem.Product.Name : string.Empty; itemRange[CellsHelper.GetOffset(CellsKind.Quantity)].Value = orderItem.ProductUnits > 0 ? orderItem.ProductUnits : 1; itemRange[CellsHelper.GetOffset(CellsKind.UnitPrice)].Value = (double)orderItem.ProductPrice; itemRange[CellsHelper.GetOffset(CellsKind.Discount)].Value = (double)orderItem.Discount; }
public static CellValue GetOrderItemCellValue(CellsKind cell, Range orderItemRange, Worksheet invoice) { int offset = CellsHelper.GetOffset(cell); var cellRange = invoice.Range.FromLTRB(orderItemRange.LeftColumnIndex + offset, orderItemRange.TopRowIndex, orderItemRange.LeftColumnIndex + offset, orderItemRange.BottomRowIndex); return(cellRange.Value); }
void AsyncUpdateSummaries(OrderItem orderItem, DevExpress.Spreadsheet.Range orderItemRange) { System.Windows.Threading.Dispatcher.CurrentDispatcher.BeginInvoke((Action)(() => { orderItem.Discount = (int)CellsHelper.GetOrderItemCellValue(CellsKind.Discount, orderItemRange, Invoice).NumericValue; orderItem.Total = (int)CellsHelper.GetOrderItemCellValue(CellsKind.Total, orderItemRange, Invoice).NumericValue; UpdateTotalValues(); })); }
public static void UpdateProductPrice(Cell cell, OrderItem orderItem, DevExpress.Spreadsheet.Range orderItemRange) { if (CellsHelper.IsOrderItemProductCell(cell, orderItemRange)) { orderItemRange[CellsHelper.GetOffset(CellsKind.UnitPrice)].Value = (double)orderItem.Product.SalePrice; orderItem.ProductPrice = orderItem.Product.SalePrice; } }
void UpdateOrderItem(Cell cell) { var verticalOffset = GetOrderItemOffset(cell); Range orderItemsRange = GetOrderItemsArea().Range; var orderItem = actualOrderItems[verticalOffset]; var orderItemRange = Invoice.Range.FromLTRB(orderItemsRange.LeftColumnIndex, orderItemsRange.TopRowIndex + verticalOffset, orderItemsRange.RightColumnIndex, orderItemsRange.TopRowIndex + verticalOffset); OrderPropertiesHelper.UpdateProductUnits(orderItem, orderItemRange, Invoice); OrderPropertiesHelper.UpdateProduct(orderItem, CellsHelper.GetOrderItemCellValue(CellsKind.ProductDescription, orderItemRange, Invoice), source); OrderPropertiesHelper.UpdateProductPrice(cell, orderItem, orderItemRange); AsyncUpdateSummaries(orderItem, orderItemRange); }
static Dictionary <string, Action <Order, CellValue, OrderCollections> > CreatePropertySetters() { var result = new Dictionary <string, Action <Order, CellValue, OrderCollections> >(); result.Add(CellsHelper.FindLeftCell(CellsKind.Date), (order, value, source) => order.OrderDate = value.DateTimeValue); result.Add(CellsHelper.FindLeftCell(CellsKind.InvoiceNumber), (order, value, source) => SetIfNumericValue(value, s => order.InvoiceNumber = s)); result.Add(CellsHelper.FindLeftCell(CellsKind.PONumber), (order, value, source) => SetIfNumericValue(value, s => order.PONumber = s)); result.Add(CellsHelper.FindLeftCell(CellsKind.ShipDate), (order, value, source) => order.ShipDate = value.DateTimeValue); result.Add(CellsHelper.FindLeftCell(CellsKind.ShipVia), (order, value, source) => { order.ShipmentCourier = (ShipmentCourier)Enum.Parse(typeof(ShipmentCourier), value.TextValue); }); result.Add(CellsHelper.FindLeftCell(CellsKind.Terms), (order, value, source) => SetIfNumericValue(value, s => order.OrderTerms = string.Format("{0} Days", s))); result.Add(CellsHelper.FindLeftCell(CellsKind.CustomerName), (order, value, source) => UpdateCustomerIfNeeded(order, value, source)); result.Add(CellsHelper.FindLeftCell(CellsKind.CustomerStoreName), (order, value, source) => UpdateCustomerStoreIfNeeded(order, value, source)); result.Add(CellsHelper.FindLeftCell(CellsKind.EmployeeName), (order, value, source) => UpdateEmployeeIfNeeded(order, value, source)); result.Add(CellsHelper.FindLeftCell(CellsKind.Comments), (order, value, source) => order.Comments = value.TextValue); result.Add(CellsHelper.FindLeftCell(CellsKind.Shipping), (order, value, source) => order.ShippingAmount = (decimal)value.NumericValue); return(result); }
public InvoiceHelper(IWorkbook workbook, Tuple <OrderCollections, Order> dataSource, EditActions editActions) { this.source = dataSource.Item1; this.order = dataSource.Item2; this.editActions = editActions; SetActualOrderItems(); LoadInvoice(workbook); CellsHelper.UpdateEditableCells(Invoice, order, source); CellsHelper.UpdateDependentCells(Invoice, order, source); if (AllowChangeOrder()) { CellsHelper.GenerateEditors(CellsHelper.OrderCells, Invoice); CreateCollectionEditors(); } AddOrderItemsToSheet(); }
public void OnPreviewMouseLeftButton(Cell cell) { if (!AllowChangeOrder()) { return; } var invoiceItemsArea = GetOrderItemsArea().Range; if (!CellsHelper.IsInvoiceSheetActive(cell) || invoiceItemsArea == null) { return; } if (CellsHelper.IsAddItemRange(cell, invoiceItemsArea)) { AddOrderItem(); } if (CellsHelper.IsRemoveItemRange(cell, invoiceItemsArea)) { RemoveOrderItem(cell.TopRowIndex - invoiceItemsArea.TopRowIndex); UpdateTotalValues(); } }
void AddOrderItemToSheet(OrderItem orderItem) { var invoiceItemsArea = GetOrderItemsArea(); int rowIndex = invoiceItemsArea.Range.BottomRowIndex; Invoice.Rows.Insert(rowIndex); Invoice.Rows[rowIndex].Height = Invoice.Rows[rowIndex - 1].Height; Invoice.Rows[rowIndex + 1].Height = Invoice.Rows[rowIndex].Height; DevExpress.Spreadsheet.Range range = invoiceItemsArea.Range; DevExpress.Spreadsheet.Range itemRange = Invoice.Range.FromLTRB(range.LeftColumnIndex, range.BottomRowIndex, range.RightColumnIndex, range.BottomRowIndex); if (range.RowCount == 1) { Invoice["K24"].FormulaInvariant = "=SUM(K22:K23)"; invoiceItemsArea.Range = Invoice.Range.FromLTRB(range.LeftColumnIndex, range.TopRowIndex - 1, range.RightColumnIndex, range.BottomRowIndex) .GetRangeWithAbsoluteReference(); if (AllowChangeOrder()) { UpdateOrderItemEditors(); } } CellsHelper.CopyOrderItemRange(itemRange); OrderPropertiesHelper.InitializeOrderItem(itemRange, orderItem); }
void UpdateOrderItemEditors() { CellsHelper.RemoveAllEditors("B23:M23", Invoice); CellsHelper.GenerateEditors(CellsHelper.OrderItemCells, Invoice); CellsHelper.CreateCollectionEditor <Product>(CellsKind.ProductDescription, Invoice, source.Products, x => x.Name); }
void UpdateTotalValues() { order.SaleAmount = (decimal)CellsHelper.GetOrderCellValue(CellsKind.SubTotal, actualOrderItems, Invoice).NumericValue; order.TotalAmount = (decimal)CellsHelper.GetOrderCellValue(CellsKind.TotalDue, actualOrderItems, Invoice).NumericValue; }
public static CellValue GetOrderCellValue(CellsKind cell, List <OrderItem> orderItems, Worksheet invoice) { var range = CellsHelper.GetActualCellRange(CellsHelper.FindLeftCell(cell), orderItems.Any() ? orderItems.Count : 0); return(invoice.Cells[range].Value); }
void UpdateCollectionEditors() { CellsHelper.RemoveEditor(CellsKind.CustomerStoreName, Invoice); CellsHelper.CreateCollectionEditor <CustomerStore>(CellsKind.CustomerStoreName, Invoice, source.CustomerStores, x => x.City); }
void CreateCollectionEditors() { CellsHelper.CreateCollectionEditor <Customer>(CellsKind.CustomerName, Invoice, source.Customers, x => x.Name); CellsHelper.CreateCollectionEditor <Employee>(CellsKind.EmployeeName, Invoice, source.Employees, x => x.FullName); UpdateCollectionEditors(); }
public static bool IsOrderItemProductCell(Cell cell, Range orderItemRange) { return(cell.LeftColumnIndex - orderItemRange.LeftColumnIndex == CellsHelper.FindCell(CellsKind.ProductDescription).Offset); }
public static void UpdateProductUnits(OrderItem orderItem, DevExpress.Spreadsheet.Range orderItemRange, Worksheet invoice) { orderItem.ProductUnits = (int)CellsHelper.GetOrderItemCellValue(CellsKind.Quantity, orderItemRange, invoice).NumericValue; }