コード例 #1
0
        private void OnUpdateProduct()
        {
            if (!ProductValidation())
            {
                return;
            }

            using (MFSContext context = new MFSContext())
            {
                Product product = new Product();
                if (SelectedProduct.Id != 0)
                {
                    product = context.Products.Include(p => p.Category).Single(p => p.ProductId == SelectedProduct.Id);
                }
                product.Name                 = SelectedProduct.Name;
                product.MinStock             = SelectedProduct.MinStock;
                product.Category             = context.Categories.Find(SelectedProduct.CategoryId);
                product.SellPrice            = SelectedProduct.SellPrice;
                product.Mesurement           = context.Measurements.Find(SelectedProduct.MeasurementId);
                context.Entry(product).State = SelectedProduct.Id == 0 ?
                                               EntityState.Added : EntityState.Modified;

                context.SaveChanges();


                LoadProduct();
                SelectedProduct = new ProductAux();
            }
        }
コード例 #2
0
        private void OnUpdateOrder()
        {
            using (MFSContext context = new MFSContext())
            {
                Order order = new Order()
                {
                    OrderId = 0
                };
                int isNewOrder = 0;
                if (SelectedOrder.OrderID != 0)
                {
                    isNewOrder = 1;
                    order      = context.Orders.Include(o => o.User).Include(o => o.Suplier).Single(o => o.OrderId == SelectedOrder.OrderID);
                }
                order.User                 = context.Users.Find(UserLogin.Id);
                order.Date                 = SelectedOrder.Date;
                order.Suplier              = context.Supliers.Find(SelectedOrder.SuplierId);
                order.CodOrder             = SelectedOrder.CodOrder;
                context.Entry(order).State = SelectedOrder.OrderID == 0 ?
                                             EntityState.Added : EntityState.Modified;

                context.SaveChanges();


                LoadOrder();
                //Nueva order
                if (isNewOrder == 0)
                {
                    OrderDetailView orderDetailView = new OrderDetailView();
                    orderDetailView.OrderId.Text = Convert.ToString(order.OrderId);
                    orderDetailView.ShowDialog();
                }
            }
        }
コード例 #3
0
        private void OnDeleteSale()
        {
            Sale saleSelected;

            using (MFSContext context = new MFSContext())
            {
                saleSelected        = context.Sales.Find(SelectedSale.SaleID);
                saleSelected.Remove = 1;
                ICollection <SaleDetail> orderDetail = saleSelected.SaleDetails;
                if (orderDetail != null)
                {
                    foreach (var od in orderDetail)
                    {
                        od.Remove = 1;
                        context.Entry(od).State = System.Data.Entity.EntityState.Modified;
                    }
                }

                context.Entry(saleSelected).State = System.Data.Entity.EntityState.Modified;
                context.SaveChanges();


                MessageBox.Show("Venta eliminada correctamente");
            }
        }
コード例 #4
0
        private void OnUpdateSale()
        {
            using (MFSContext context = new MFSContext())
            {
                Sale order = new Sale()
                {
                    SaleId = 0
                };
                int isNewSale = 0;
                if (SelectedSale.SaleID != 0)
                {
                    isNewSale = 1;
                    order     = context.Sales.Include(o => o.User).Include(o => o.Customer).Single(o => o.SaleId == SelectedSale.SaleID);
                }
                order.Date                 = SelectedSale.Date;
                order.Customer             = context.Customers.Find(SelectedSale.CustomerId);
                order.User                 = context.Users.Find(UserLogin.Id);
                order.CodSale              = SelectedSale.CodSale;
                context.Entry(order).State = SelectedSale.SaleID == 0 ?
                                             System.Data.Entity.EntityState.Added : System.Data.Entity.EntityState.Modified;

                context.SaveChanges();


                LoadSale();
                //Nueva venta
                if (isNewSale == 0)
                {
                    SaleDetailView orderDetailView = new SaleDetailView();
                    orderDetailView.SaleId.Text = Convert.ToString(order.SaleId);
                    orderDetailView.ShowDialog();
                }
            }
        }
コード例 #5
0
 public void OnUpdateSuplier()
 {
     using (MFSContext context = new MFSContext())
     {
         context.Entry(selectedSuplier).State = (selectedSuplier.SuplierId == 0) ?
                                                System.Data.Entity.EntityState.Added :
                                                System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
     LoadSupliers();
 }
コード例 #6
0
 public void OnUpdateCustomer()
 {
     if (!CustomerValidation())
     {
         return;
     }
     using (MFSContext context = new MFSContext())
     {
         SelectedCustomer.User = context.Users.Find(UserLogin.Id);
         context.Entry(selectedCustomer).State = (selectedCustomer.CustomerId == 0) ?
                                                 System.Data.Entity.EntityState.Added :
                                                 System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
     LoadCustomers();
 }
コード例 #7
0
 public void OnUpdateCategory()
 {
     if (!CategoryValidation())
     {
         return;
     }
     using (MFSContext context = new MFSContext())
     {
         SelectedCategory.User = context.Users.Find(UserLogin.Id);
         context.Entry(selectedCategory).State = (selectedCategory.CategoryId == 0) ?
                                                 System.Data.Entity.EntityState.Added :
                                                 System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
     LoadCategories();
     SelectedCategory = new Category();
 }
コード例 #8
0
 public void OnUpdateUser()
 {
     if (!UserValidation())
     {
         return;
     }
     using (MFSContext context = new MFSContext())
     {
         SelectedUser.Role = context.Roles.Where(r => r.Name == ComboBoxRole.Content.ToString()).FirstOrDefault();
         context.Entry(selectedUser).State = (selectedUser.UserId == 0) ?
                                             System.Data.Entity.EntityState.Added :
                                             System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
     LoadUsers();
     SelectedUser = new User();
 }
コード例 #9
0
 public void OnUpdateMeasurement()
 {
     if (!MeasurementValidation())
     {
         return;
     }
     using (MFSContext context = new MFSContext())
     {
         SelectedMeasurement.User = context.Users.Find(UserLogin.Id);
         context.Entry(selectedMeasurement).State = (selectedMeasurement.MeasurementId == 0) ?
                                                    System.Data.Entity.EntityState.Added :
                                                    System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
     LoadMeasurements();
     SelectedMeasurement = new Measurement();
 }