コード例 #1
0
        protected override async void Delete(object sender, RoutedEventArgs e)
        {
            try
            {
                // Gets the product to be deleted
                ProductOverviewItem ToBeDeleted = ((FrameworkElement)sender).DataContext as ProductOverviewItem;

                string messageboxTitle   = String.Format(LangResource.MBTitleDeleteObj, ToBeDeleted.ProductName);
                string messageboxContent = String.Format(LangResource.MBContentDeleteObj, LangResource.TheProduct.ToLower(), ToBeDeleted.ProductName);

                MessageBoxManager.Yes = LangResource.Yes;
                MessageBoxManager.No  = LangResource.No;
                MessageBoxManager.Register();

                // Shows a messagebox with localized content to propmpt if the user is sure he wants to delete the product
                if (MessageBox.Show(messageboxContent,
                                    messageboxTitle,
                                    MessageBoxButton.YesNo,
                                    MessageBoxImage.Warning)
                    == MessageBoxResult.Yes)
                {
                    MessageBoxManager.Unregister();

                    // Delete the product from the database and the ProductList
                    _prodRepo.Delete(ToBeDeleted.ID);
                    ProductList.Remove(ToBeDeleted);
                    await _prodRepo.SaveChangesAsync();

                    // Refreshes the grid
                    BindData();
                }
                else
                {
                    MessageBoxManager.Unregister();
                }
            }
            catch (Exception)
            {
                MessageBoxManager.Unregister();
                MessageBox.Show(LangResource.ErrUpdateOverviewFailed);
            }
        }
コード例 #2
0
        protected override void Update(object sender, RoutedEventArgs e)
        {
            ProductOverviewItem ToBeUpdated = ((FrameworkElement)sender).DataContext as ProductOverviewItem;

            ShowUpdateForm <ProductForm>(ToBeUpdated.ID);
        }