Пример #1
0
        private void EditButton_Click(object sender, RoutedEventArgs e)
        {
            Product selectedItem = (Product)productDataGrid.SelectedItem;

            if (selectedItem != null)
            {
                var newProduct = new EditProductWindow(selectedItem);

                if (newProduct.ShowDialog() == true)
                {
                    var update = (from product in MainWindow.db.Products where product.ID == selectedItem.ID select product).Single();
                    update.Name       = newProduct.P_Name;
                    update.CategoryID = newProduct.P_CategoryID;
                    update.Price      = newProduct.P_Price;
                    update.Weight     = newProduct.P_Weight;
                    update.Picture    = newProduct.P_Picture;
                    MainWindow.db.SaveChanges();

                    productDataGrid.ItemsSource = MainWindow.db.Products.ToList();
                }
            }
        }
Пример #2
0
        private void productDataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            DataGridRow row = ItemsControl.ContainerFromElement((DataGrid)sender, e.OriginalSource as DependencyObject) as DataGridRow;

            if (row != null)
            {
                Product selectedItem = (Product)row.Item;

                var newProduct = new EditProductWindow(selectedItem);

                if (newProduct.ShowDialog() == true)
                {
                    var update = (from product in MainWindow.db.Products where product.ID == selectedItem.ID select product).Single();
                    update.Name       = newProduct.P_Name;
                    update.CategoryID = newProduct.P_CategoryID;
                    update.Price      = newProduct.P_Price;
                    update.Weight     = newProduct.P_Weight;
                    update.Picture    = newProduct.P_Picture;
                    MainWindow.db.SaveChanges();

                    productDataGrid.ItemsSource = MainWindow.db.Products.ToList();
                }
            }
        }