Ejemplo n.º 1
0
 public MainWindow()
 {
     InitializeComponent();
     if (dataGrid.Items != null)
     {
         using (var context = new GoodContext())
         {
             goods = context.Goods.ToList();
             dataGrid.ItemsSource = goods;
         }
     }
     else if (dataGrid.Items == null)
     {
         dataGrid.ItemsSource = goods;
     }
 }
Ejemplo n.º 2
0
 private void dataGrid_PreviewKeyDown(object sender, KeyEventArgs e)
 {
     if (e.Key == Key.Enter)
     {
         using (var context = new GoodContext())
         {
             context.Goods.Add(new Good
             {
                 Id     = id,
                 Name   = name,
                 Price  = price,
                 Amount = amount
             });
             context.SaveChanges();
         }
     }
 }