using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; namespace OUP { public partial class Qwerty : Window { private Context _context; public Qwerty() { InitializeComponent(); _context = new Context(); Load(); } private void Load() { ProductsGrid.ItemsSource = _context.products.ToList(); } private void BtnInsert_Click(object sender, RoutedEventArgs e) { if (!decimal.TryParse(TbPrice.Text, out decimal price)) { return; } Product2 product = new Product2() { Name = TbProduct.Text, Price = price, Supplier = TbSupplier.Text, Dates = TbDate.Text, }; // _context.products.Add(product); _context.SaveChanges(); Load(); } private void BtnUpdate_Click(object sender, RoutedEventArgs e) { if (ProductsGrid.SelectedItem is Product2 selectedProduct2) { if (!decimal.TryParse(TbPrice.Text, out decimal price)) { return; } selectedProduct2.Name = TbProduct.Text; selectedProduct2.Price = price; selectedProduct2.Supplier = TbSupplier.Text; selectedProduct2.Dates = TbDate.Text; _context.SaveChanges(); Load(); } } private void BtnDelete_Click(object sender, RoutedEventArgs e) { if (ProductsGrid.SelectedItem is Product2 selectedproducts) { //_context.products.Remove(selectedproducts); _context.SaveChanges(); Load(); } } private void BooksGrid_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (ProductsGrid.SelectedItem is Product2 selectedproducts) { TbProduct.Text = selectedproducts.Name; TbPrice.Text = selectedproducts.Price.ToString(); TbSupplier.Text = selectedproducts.Supplier; TbDate.Text = selectedproducts.Dates; } } } }