예제 #1
0
        internal static void DeleteProduct(ProductViewModel product)
        {
            WarehouseEntities entity = new WarehouseEntities();

            var productToDelete =
                from ptd in entity.Products
                where ptd.Name.Contains(product.Name) && ptd.Vendor1.Name.Contains(product.Vendor.Name)
                select ptd;

            if (productToDelete.Count() != 0)
            {
                foreach (var item in productToDelete)
                {
                    entity.Products.Remove(item);
                }

                MessageBox.Show("Product " + product.Name + " deleted", "Confirmation", MessageBoxButton.OK);

                entity.SaveChanges();
            }
            else
            {
                MessageBox.Show("Product " + product.Name + " doesn't exist", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
예제 #2
0
        internal static void AddProduct(ProductViewModel product)
        {
            WarehouseEntities entity = new WarehouseEntities();

            var productToAdd =
                from pta in entity.Products
                where ((pta.Name == product.Name) && (pta.Vendor1.Name == product.Vendor.Name))
                select pta;

            if (productToAdd.Count() != 0)
            {

                UpdateProduct(product);

            }
            else
            {
                var productVendor =
                    (from pv in entity.Vendors
                    where pv.Name == product.Vendor.Name
                    select pv).First();

                entity.Products.Add(new Product()
                                    {
                                        Name = product.Name,
                                        BuyPrice = product.BuyPrice,
                                        SellPrice = product.SellPrice,
                                        Quantity = product.Quantity,
                                        DayOfPurchase = DateTime.Now,
                                        Vendor = productVendor.VendorID
                                    });

                MessageBox.Show("Product " + product.Name + " added!", "Confirmation", MessageBoxButton.OK);

                entity.SaveChanges();
            }
        }
예제 #3
0
 public WarehouseViewModel()
 {
     this.newProductViewModel = new ProductViewModel();
     this.newVendorViewModel = new VendorViewModel();
     this.newUserViewModel = new UserViewModel();
 }
예제 #4
0
        internal static void UseProduct(ProductViewModel product)
        {
            WarehouseEntities entity = new WarehouseEntities();

            var productToUse =
                    from ptu in entity.Products
                    where ptu.Name.Contains(product.Name) && ptu.Vendor1.Name.Contains(product.Vendor.Name)
                    select ptu;

            if (productToUse.Count() != 0)
            {
                foreach (var item in productToUse)
                {
                    item.Quantity -= product.Quantity;
                    item.DayOfSale = DateTime.Now;
                    if (item.SaleQuantity == null)
                    {
                        item.SaleQuantity = product.Quantity;
                    }
                    else
                    {
                        item.SaleQuantity += product.Quantity;
                    }
                }

                MessageBox.Show("Product " + product.Name + " used", "Confirmation", MessageBoxButton.OK);

                entity.SaveChanges();
            }
            else
            {
                MessageBox.Show("Product " + product.Name + " doesn't exist", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
예제 #5
0
        internal static void UpdateProduct(ProductViewModel product)
        {
            WarehouseEntities entity = new WarehouseEntities();

            var productToUpdate =
                    from ptu in entity.Products
                    where ptu.Name.Contains(product.Name) && ptu.Vendor1.Name.Contains(product.Vendor.Name)
                    select ptu;

            if (productToUpdate.Count() != 0)
            {
                foreach (var item in productToUpdate)
                {
                    item.Quantity += product.Quantity;
                    item.BuyPrice = product.BuyPrice;

                }

                MessageBox.Show("Product " + product.Name + " updated", "Confirmation", MessageBoxButton.OK);

                entity.SaveChanges();
            }
            else
            {
                MessageBox.Show("Product " + product.Name + " doesn't exist", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
예제 #6
0
        internal static IEnumerable<ProductViewModel> GetProductReportSales(ProductViewModel product)
        {
            WarehouseEntities entity = new WarehouseEntities();

            var productReportSales =
                (from prs in entity.Products
                 where prs.DayOfSale.Day.Equals(product.DayOfSale.Day)
                       && prs.DayOfSale.Month.Equals(product.DayOfSale.Month)
                       && prs.DayOfSale.Year.Equals(product.DayOfSale.Year)
                 select new ProductViewModel()
                 {
                     Name = prs.Name,
                     Quantity = prs.Quantity,
                     SaleQuantity = prs.SaleQuantity,
                     BuyPrice = prs.BuyPrice,
                     SellPrice = prs.SellPrice,
                     DayOfSale = prs.DayOfSale,
                     Vendor = new VendorViewModel()
                     {
                         Name = prs.Vendor1.Name
                     }
                 }).ToList();

            return productReportSales;
        }