private void Page_ButtonSave_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrWhiteSpace(_textBoxProductId.Text) || _textBoxProductId.Text.Length > 4) { _labelError.Visibility = Visibility.Visible; _labelError.Content = "Enter 4 char Product Id"; _textBoxProductId.Focus(); return; } _product.Id = _textBoxProductId.Text; if (string.IsNullOrWhiteSpace(_textBoxProductName.Text)) { _labelError.Visibility = Visibility.Visible; _labelError.Content = "Enter Product Name"; _textBoxProductName.Focus(); return; } _product.Name = _textBoxProductName.Text; if (CurrentRegime == PageRegime.Add) { _database.Products.Local.Add(_product); } _database.SaveChanges(); _database.Products.Load(); NavigationService.Navigate(Pages.ProductsPage); }
private void Page_ButtonSave_Click(object sender, RoutedEventArgs e) { decimal price; if (!decimal.TryParse(_textBoxProductSellingPrice.Text, out price)) { _labelError.Visibility = Visibility.Visible; _labelError.Content = "Enter Product Selling Price"; _textBoxProductSellingPrice.Focus(); return; } _productprice.SellingPrice = price; if (!decimal.TryParse(_textBoxProductPurchasePrice.Text, out price)) { _labelError.Visibility = Visibility.Visible; _labelError.Content = "Enter Product Purchase Price"; _textBoxProductPurchasePrice.Focus(); return; } _productprice.PurchasePrice = price; if (_productprice.PurchasePrice >= _productprice.SellingPrice) { _labelError.Visibility = Visibility.Visible; _labelError.Content = "Product Selling Price should be greater than Purchase Price"; _textBoxProductSellingPrice.Focus(); return; } if (!_datePickerProductDate.SelectedDate.HasValue || _datePickerProductDate.SelectedDate.Value.Date <= System.DateTime.Today) { _labelError.Visibility = Visibility.Visible; _labelError.Content = "Price activation date should be larger than current date"; _datePickerProductDate.Focus(); return; } _productprice.Date = _datePickerProductDate.SelectedDate.Value.Date; if (CurrentRegime == PageRegime.Add) { _database.ProductPrices.Local.Add(_productprice); } _database.SaveChanges(); _database.ProductPrices.Load(); NavigationService.Navigate(Pages.ProductsPage); }
private void Page_ButtonSave_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrWhiteSpace(_textBoxTerminalLocation.Text)) { _labelError.Visibility = Visibility.Visible; _labelError.Content = "Enter terminal location"; _textBoxTerminalLocation.Focus(); return; } _terminal.Location = _textBoxTerminalLocation.Text; _terminal.BillsCapacity = 100; _terminal.CoinsLoadedQty = 1000; _terminal.ProductsLoadedQty = 120; _terminal.TerminalsBills.Clear(); _terminal.TerminalsBills.Add(new TerminalsBill { TerminalId = _terminal.Id, BillId = 1, InsertedQuantity = 0 }); _terminal.TerminalsBills.Add(new TerminalsBill { TerminalId = _terminal.Id, BillId = 2, InsertedQuantity = 0 }); _terminal.TerminalsBills.Add(new TerminalsBill { TerminalId = _terminal.Id, BillId = 3, InsertedQuantity = 0 }); _terminal.TerminalsBills.Add(new TerminalsBill { TerminalId = _terminal.Id, BillId = 4, InsertedQuantity = 0 }); _terminal.TerminalsBills.Add(new TerminalsBill { TerminalId = _terminal.Id, BillId = 5, InsertedQuantity = 0 }); _terminal.TerminalsCoins.Clear(); _terminal.TerminalsCoins.Add(new TerminalsCoin { TerminalId = _terminal.Id, CoinId = 1, ReturnedQuantity = 0, LoadedQuantity = 400 }); _terminal.TerminalsCoins.Add(new TerminalsCoin { TerminalId = _terminal.Id, CoinId = 2, ReturnedQuantity = 0, LoadedQuantity = 300 }); _terminal.TerminalsCoins.Add(new TerminalsCoin { TerminalId = _terminal.Id, CoinId = 3, ReturnedQuantity = 0, LoadedQuantity = 200 }); _terminal.TerminalsCoins.Add(new TerminalsCoin { TerminalId = _terminal.Id, CoinId = 4, ReturnedQuantity = 0, LoadedQuantity = 100 }); _terminal.TerminalsProducts.Clear(); foreach (var p in _database.Products.Local) { _terminal.TerminalsProducts.Add(new TerminalsProduct { TerminalId = _terminal.Id, ProductId = p.Id, Quantity = 10 }); } if (CurrentRegime == PageRegime.Add) { _database.Terminals.Local.Add(_terminal); } _database.SaveChanges(); _database.Terminals.Load(); NavigationService.Navigate(Pages.TerminalsPage); }
protected override void OnClosing(System.ComponentModel.CancelEventArgs e) { base.OnClosing(e); _database.SaveChanges(); _database.Dispose(); }