Ejemplo n.º 1
0
 // удаление товара
 static public void RemoveItem(Item removeEntry)
 {
     try
     {
         using (var context = new ComputerShopEntities())
         {
             var original = context.Items.Remove(context.Items.Single(a => a.ItemID == removeEntry.ItemID));
             context.Entry(original).Collection(r => r.OrderItems).CurrentValue = null;
             context.Entry(original).State = EntityState.Deleted;
             context.SaveChanges();
             MessageBox.Show($"{removeEntry.Name} удален из базы!", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
     catch
     {
         MessageBox.Show("На товар оформлен заказ!", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Ejemplo n.º 2
0
 // изменение продавца
 static public void EditSeller(Seller editSeller)
 {
     using (var context = new ComputerShopEntities())
     {
         var original = context.Sellers.Find(editSeller.SellerID);
         context.Entry(original).CurrentValues.SetValues(editSeller);
         context.SaveChanges();
         MessageBox.Show($"Продавец {editSeller.Name} обновлен!", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Ejemplo n.º 3
0
 // редактирование поставщика
 static public void EditSupplier(Supplier toEdit)
 {
     using (var context = new ComputerShopEntities())
     {
         var original = context.Suppliers.Find(toEdit.SupplierID);
         context.Entry(original).CurrentValues.SetValues(toEdit);
         context.SaveChanges();
         MessageBox.Show($"Поставщик {toEdit.Name} обновлен!", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Ejemplo n.º 4
0
 // редактирование категории
 static public void EditCategory(Category toEdit)
 {
     using (var context = new ComputerShopEntities())
     {
         var original = context.Categories.Find(toEdit.CategoryID);
         context.Entry(original).CurrentValues.SetValues(toEdit);
         context.SaveChanges();
         MessageBox.Show($"Категория {toEdit.Name} обновлена!", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Ejemplo n.º 5
0
 // поиск заказа по ID
 static public Order SearchOrderByID(int orderId)
 {
     using (var context = new ComputerShopEntities())
     {
         var order = context.Orders.Find(orderId);
         context.Entry(order).Reference(p => p.Seller).Load();
         //var order = context.Orders.Where(x => x.OrderID == orderId).Include("Seller");
         //var data = context.Items.Where(x => x.Name == itemName).Include("Category").Include("Supplier").ToList<Item>();
         return(order);
     }
 }
Ejemplo n.º 6
0
 // удаление заказа
 static public void RemoveOrder(ItemOrdersEntity toRemove)
 {
     using (var context = new ComputerShopEntities())
     {
         var original = context.Orders.Find(toRemove.OrderID);
         context.OrderItems.RemoveRange(original.OrderItems);
         context.Entry(original).State = EntityState.Deleted;
         context.SaveChanges();
         MessageBox.Show("Заказ с ID " + toRemove.OrderID + " удален из базы данных!", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }