示例#1
0
 private void ProductGrid_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
 {
     if (CurrentProduct != null)
     {
         if (CurrentProduct.ProductNumber != 0)
         {
             using (var con = new naukaEntities()) //update
             {
                 Product curr = (from item in con.Product
                                 where item.ProductNumber == CurrentProduct.ProductNumber
                                 select item).First();
                 curr.Name        = CurrentProduct.Name;
                 curr.Description = CurrentProduct.Description;
                 curr.Cost        = CurrentProduct.Cost;
                 con.SaveChanges();
             }
         }
         else
         {
             using (var con = new naukaEntities()) //create
             {
                 con.Product.Add(new Product
                 {
                     Cost        = CurrentProduct.Cost,
                     Name        = CurrentProduct.Name,
                     Description = CurrentProduct.Description
                 });
                 con.SaveChanges();
             }
         }
         CurrentProduct = null;
     }
 }
示例#2
0
 private void WarehouseGrid_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
 {
     if (CurrentWarehouse != null)
     {
         if (CurrentWarehouse.WarehouseID != 0)
         {
             using (var con = new naukaEntities()) //update
             {
                 Warehouse curr = (from item in con.Warehouse
                                   where item.WarehouseID == CurrentWarehouse.WarehouseID
                                   select item).First();
                 curr.Address = CurrentWarehouse.Address;
                 con.SaveChanges();
             }
         }
         else
         {
             using (var con = new naukaEntities()) //create
             {
                 con.Warehouse.Add(new Warehouse
                 {
                     Address = CurrentWarehouse.Address
                 });
                 con.SaveChanges();
             }
         }
         CurrentWarehouse = null;
     }
 }
 private void ProviderGrid_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
 {
     if (CurrentProvider != null)
     {
         if (CurrentProvider.ProviderID != 0)
         {
             using (var con = new naukaEntities()) //update
             {
                 Provider curr = (from item in con.Provider
                                  where item.ProviderID == CurrentProvider.ProviderID
                                  select item).First();
                 curr.Name = CurrentProvider.Name;
                 con.SaveChanges();
             }
         }
         else
         {
             using (var con = new naukaEntities()) //create
             {
                 con.Provider.Add(new Provider
                 {
                     Name = CurrentProvider.Name,
                 });
                 con.SaveChanges();
             }
         }
         CurrentProvider = null;
     }
 }
示例#4
0
 private void RefreshDB() //read
 {
     using (var con = new naukaEntities())
     {
         ProductGrid.ItemsSource = (from prods in con.Product
                                    select prods).ToList();
     }
 }
示例#5
0
 private void RefreshDB() //read
 {
     using (var con = new naukaEntities())
     {
         WarehouseGrid.ItemsSource = (from item in con.Warehouse
                                      select item).ToList();
     }
 }
 private void RefreshDB() //read
 {
     using (var con = new naukaEntities())
     {
         ProviderGrid.ItemsSource = (from item in con.Provider
                                     select item).ToList();
     }
 }
        private void RefreshDB() //read
        {
            using (var con = new naukaEntities())
            {
                OrderGrid.ItemsSource = (from x in con.ReceiptOrder
                                         select x).ToList();

                OrderProductGrid.ItemsSource = (from x in con.ReceiptOrder_Product
                                                select x).ToList();
            }
        }
        private void OrderProductGrid_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
        {
            if (CurrentOrderProduct != null)
            {
                try
                {
                    if (CurrentOrderProduct.ID != 0)
                    {
                        using (var con = new naukaEntities()) //update
                        {
                            ReceiptOrder_Product curr = (from item in con.ReceiptOrder_Product
                                                         where item.ID == CurrentOrderProduct.ID
                                                         select item).First();
                            curr.OrderNum      = CurrentOrderProduct.OrderNum;
                            curr.ProductNumber = CurrentOrderProduct.ProductNumber;
                            curr.Quantity      = CurrentOrderProduct.Quantity;
                            curr.WarehouseID   = CurrentOrderProduct.WarehouseID;

                            con.SaveChanges();
                        }
                    }
                    else
                    {
                        using (var con = new naukaEntities()) //create
                        {
                            con.ReceiptOrder_Product.Add(new ReceiptOrder_Product
                            {
                                OrderNum      = CurrentOrderProduct.OrderNum,
                                ProductNumber = CurrentOrderProduct.ProductNumber,
                                Quantity      = CurrentOrderProduct.Quantity,
                                WarehouseID   = CurrentOrderProduct.WarehouseID
                            });
                            con.SaveChanges();
                        }
                    }
                    CurrentOrderProduct = null;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
 private void ButtonRemove_Click(object sender, RoutedEventArgs e)
 {
     if (OrderGrid.SelectedItem != null)
     {
         try
         {
             ReceiptOrder row = (ReceiptOrder)OrderGrid.SelectedItem;
             using (var con = new naukaEntities())
             {
                 ReceiptOrder curr = (from item in con.ReceiptOrder
                                      where item.OrderNum == row.OrderNum
                                      select item).First();
                 con.ReceiptOrder.Remove(curr);
                 con.SaveChanges();
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
         RefreshDB();
     }
     if (OrderProductGrid.SelectedItem != null)
     {
         try
         {
             ReceiptOrder_Product row = (ReceiptOrder_Product)OrderProductGrid.SelectedItem;
             using (var con = new naukaEntities())
             {
                 ReceiptOrder_Product curr = (from item in con.ReceiptOrder_Product
                                              where item.ID == row.ID
                                              select item).First();
                 con.ReceiptOrder_Product.Remove(curr);
                 con.SaveChanges();
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
         RefreshDB();
     }
 }
示例#10
0
 private void ButtonRemove_Click(object sender, RoutedEventArgs e) //delete
 {
     try
     {
         Product row = (Product)ProductGrid.SelectedItem;
         using (var con = new naukaEntities())
         {
             Product curr = (from item in con.Product
                             where item.ProductNumber == row.ProductNumber
                             select item).First();
             con.Product.Remove(curr);
             con.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
     RefreshDB();
 }
示例#11
0
 private void ButtonRemove_Click(object sender, RoutedEventArgs e) //delete
 {
     try
     {
         Warehouse row = (Warehouse)WarehouseGrid.SelectedItem;
         using (var con = new naukaEntities())
         {
             Warehouse curr = (from item in con.Warehouse
                               where item.WarehouseID == row.WarehouseID
                               select item).First();
             con.Warehouse.Remove(curr);
             con.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
     RefreshDB();
 }
 private void OrderGrid_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
 {
     if (CurrentOrder != null)
     {
         try
         {
             if (CurrentOrder.OrderNum != 0)
             {
                 using (var con = new naukaEntities()) //update
                 {
                     ReceiptOrder curr = (from item in con.ReceiptOrder
                                          where item.OrderNum == CurrentOrder.OrderNum
                                          select item).First();
                     curr.OrderDate        = CurrentOrder.OrderDate;
                     curr.ProviderID       = CurrentOrder.ProviderID;
                     curr.DeliveryContract = CurrentOrder.DeliveryContract;
                     curr.TotalPrice       = CurrentOrder.TotalPrice;
                     con.SaveChanges();
                 }
             }
             else
             {
                 using (var con = new naukaEntities()) //create
                 {
                     con.ReceiptOrder.Add(new ReceiptOrder
                     {
                         OrderDate        = CurrentOrder.OrderDate,
                         ProviderID       = CurrentOrder.ProviderID,
                         DeliveryContract = CurrentOrder.DeliveryContract,
                         TotalPrice       = CurrentOrder.TotalPrice
                     });
                     con.SaveChanges();
                 }
             }
             CurrentOrder = null;
         }
         catch (Exception ex) {
             MessageBox.Show(ex.Message);
         }
     }
 }