123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- 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;
- }
- }
-
- }
- }
|