Exemplo n.º 1
0
        private void AddTool()
        {
            var purchaseDate = DatePickerPurchaseDate.SelectedDate?.Date ?? DateTime.Now;

            decimal.TryParse(TextBoxPurchaseValue.Text, out decimal purchaseValue);
            decimal.TryParse(TextBoxPrice.Text, out decimal rentalPrice);
            int.TryParse(TextBoxWarranty.Text, out int warranty);

            var tool = new Tool()
            {
                ToolId            = Guid.NewGuid(),
                Name              = TextBoxName.Text,
                Sn                = TextBoxSn.Text,
                PurchaseDate      = purchaseDate.Add(DateTime.Now.TimeOfDay),
                PurchasesValue    = purchaseValue,
                DocumentNumber    = TextBoxDocumentNumber.Text,
                Warranty          = warranty,
                RentalPrice       = rentalPrice,
                Destroyed         = Destroyed.IsChecked != null && (bool)Destroyed.IsChecked,
                DestroyedDate     = DestroyedDate.SelectedDate?.Date.Add(DateTime.Now.TimeOfDay),
                DestroyedCustomer = (User)SelectDestroyed.SelectedItem,
                Lost              = Lost.IsChecked != null && (bool)Lost.IsChecked,
                LostDate          = DestroyedDate.SelectedDate?.Date.Add(DateTime.Now.TimeOfDay),
                LostCustomer      = (User)SelectLost.SelectedItem,
                Description       = new TextRange(TextBoxDescription.Document.ContentStart, TextBoxDescription.Document.ContentEnd).Text,
                Producer          = (Company)SelectProducer.SelectedItem
            };

            _db.AddTool(tool);
            try
            {
                _db.SaveChanges();
            }
            catch (DbEntityValidationException e)
            {
                DbExceptionValidate("Błąd zapisu narzędzi", e);
            }
            catch (Exception e)
            {
                MessageBox.Show("Błąd zapisu narzędzi: " + e.Message, "Uwaga", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            SetEdited(false);
            this.Close();
        }
Exemplo n.º 2
0
        private void RemoveTool(object sender, RoutedEventArgs e)
        {
            if (ToolsListView.SelectedItem == null)
            {
                return;
            }
            var toolToRemove = (Tool)ToolsListView.SelectedItem;

            _db.RemoveTool(toolToRemove.ToolId);
            try
            {
                _db.SaveChanges();
            }
            catch (Exception exc)
            {
                MessageBox.Show("Błąd usunięcia Firmy : " + exc.Message, "Uwaga", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            DataContext = _db.GetAll();
            RefreshList();
        }