示例#1
0
        private void BtnSaveUpdateShop_OnClick(object sender, RoutedEventArgs e)
        {
            var btn = (Button)sender;

            // Tag attribute on button is bound to Id
            int shopId = (int)btn.Tag;

            // Get Inmate object from collection
            var shop = ToolTrackerService.Shops.SingleOrDefault(i => i.Id == shopId);

            var result = NotifyUser.AskToConfirm("Are you sure you want to save?", "Confirm Update");

            if (result != System.Windows.Forms.DialogResult.Yes)
            {
                return;
            }

            if (string.IsNullOrEmpty(shop?.Name))
            {
                NotifyUser.InvalidEntry("Please enter the new shop name", "Invalid Entry");
                return;
            }

            shop.Name = ToolTrackerService.MakeEveryWordUppercase(shop.Name);
            UpdateShop(shop);
        }
示例#2
0
        private void BtnSave_OnClick(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(textBoxShopName.Text))
            {
                textBlockStatus.Text = "Please enter the shop name.";
                textBoxShopName.Focus();
                return;
            }

            var newShop = new Shop {
                Name = textBoxShopName.Text.Trim()
            };

            newShop.Name = ToolTrackerService.MakeEveryWordUppercase(newShop.Name);

            try
            {
                using (var db = new UnitOfWork())
                {
                    bool shopExists = db.ShopsRepo.Exists(s => s.Name == newShop.Name);
                    if (shopExists)
                    {
                        textBlockStatus.Text = "This shop already exists.";
                        return;
                    }
                    else
                    { // add to db and collection
                        db.ShopsRepo.Add(newShop);
                        db.Commit();
                    }
                }
            }
            catch (EntityException ex)
            {
                ExceptionHandler.LogAndNotifyOfException(ex, ex.Message);
            }
            catch (Exception ex)
            {
                ExceptionHandler.LogAndNotifyOfException(ex, ex.Message);
            }

            ToolTrackerService.Shops.Add(newShop);

            // change text in cancel button to "I'm Finished"
            btnCancel.Content = "I'm Finished";

            // update status
            textBlockStatus.Text = $"{newShop.Name} has been added.";

            textBoxShopName.Clear();
            textBoxShopName.Focus();

            // Updates the ShopIndex prop in view models to correct combobox selection
            ToolTrackerService.UpdateIndicesAfterShopUpdate();
        }
        private void BtnSave_OnClick(object sender, RoutedEventArgs e)
        {
            TextBlockStatus.Text = "";

            // Validate tool
            if (ValidateToolData())
            {
                return;
            }

            // Persist update to db
            using (var db = new UnitOfWork())
            {
                try
                {
                    var newTool = new Tool
                    {
                        ToolNumber  = textBoxToolNo.Text.Trim(),
                        Description = ToolTrackerService.MakeEveryWordUppercase(textBoxToolDesc.Text.Trim())
                    };

                    var toolNoExists = db.ToolsRepo.Exists(t => t.ToolNumber.Equals(newTool.ToolNumber));
                    if (toolNoExists)
                    {
                        TextBlockStatus.Text = "Tool number already exists.";
                        textBoxToolNo.Focus();
                        return;
                    }

                    var shop = (Shop)ComboBoxShops.SelectedItem;
                    newTool.ShopId = shop.Id;

                    db.ToolsRepo.Add(newTool);
                    db.Commit();

                    // Update observable collection
                    ToolTrackerService.MapToolToViewModel(newTool);
                    ToolTrackerService.SortTools();

                    TextBlockStatus.Text = $"{newTool.ToolNumber} added successfully.";
                }
                catch (EntityException ex)
                {
                    ExceptionHandler.LogAndNotifyOfException(ex, ex.Message);
                }
                catch (Exception ex)
                {
                    ExceptionHandler.LogAndNotifyOfException(ex, ex.Message);
                }

                btnCancel.Content = "I'm Finished";
                ResetForm();
            }
        }
示例#4
0
        private void BtnSaveUpdateTool_OnClick(object sender, RoutedEventArgs e)
        {
            var btn = (Button)sender;

            // Tag attribute on button is bound to Id
            int toolId = (int)btn.Tag;

            // Get tool obj from collection
            var tool = ToolTrackerService.Tools.SingleOrDefault(t => t.Id == toolId);

            // Ensure description is uppercase
            if (tool != null)
            {
                tool.Description = ToolTrackerService.MakeEveryWordUppercase(tool.Description);
            }

            // update/save tool
            UpdateTool(tool);
        }