コード例 #1
0
 public AddBarcodeViewModel(IEventAggregator eventAggregator, IDatabaseHandlerService databaseHandlerService, IProductsViewModel productsViewModel, Product product)
 {
     this.eventAggregator = eventAggregator;
     this.databaseHandlerService = databaseHandlerService;
     this.productsViewModel = productsViewModel;
     Product = product;
 }
コード例 #2
0
        public AddQuantityViewModel(IEventAggregator eventAggregator, IDatabaseHandlerService databaseHandlerService, IProductsViewModel productsViewModel, Product product)
        {
            this.eventAggregator = eventAggregator;
            this.databaseHandlerService = databaseHandlerService;
            this.productsViewModel = productsViewModel;
            this.product = product;

            AddQuantityCommand = new DelegateCommand<Window>(AddQuantity);
        }
コード例 #3
0
        public void AddBarcodeAsync(Product originalProduct, Barcode barcode)
        {
            using (var worker = new BackgroundWorker())
            {
                worker.DoWork += (object sender, DoWorkEventArgs e) =>
                {
                    using (var context = new EugenieEntities(connectionStringAsString))
                    {
                        var product = context.Products.FirstOrDefault(x => x.ID == originalProduct.ID);

                        product.Barcodes.Add(barcode);
                        context.SaveChanges();
                    }
                };

                worker.RunWorkerAsync();
            }
        }
コード例 #4
0
        private void OnProductChangedEvent(int id)
        {
            product = productsViewModel.AllProducts.FirstOrDefault(x => x.ID == id);

            if (product == null)
            {
                SaveChangesCommand = new DelegateCommand<object>(SaveChanges, s => false);
                Name = null;
                BuyingPrice = null;
                SellingPrice = null;

                return;
            }

            SaveChangesCommand = new DelegateCommand<object>(SaveChanges);
            OpenAddQuantityWindowCommand = new DelegateCommand<object>(OpenAddQuantityWindow);
            OpenAddBarcodeWindowCommand = new DelegateCommand<object>(OpenAddBarcodeWindow);

            Name = product.Name;
            BuyingPrice = $"{product.BuyingPrice:0.00}";
            SellingPrice = $"{product.SellingPrice:0.00}";
        }
コード例 #5
0
        public void UpdateProductAsync(Product originalProduct, double quantity = 0)
        {
            using (var worker = new BackgroundWorker())
            {
                worker.DoWork += (object sender, DoWorkEventArgs e) =>
                {
                    using (var context = new EugenieEntities(connectionStringAsString))
                    {
                        var product = context.Products.FirstOrDefault(x => x.ID == originalProduct.ID);

                        product.Name = originalProduct.Name;
                        product.BuyingPrice = originalProduct.BuyingPrice;
                        product.SellingPrice = originalProduct.SellingPrice;
                        product.Measure = originalProduct.Measure;
                        product.Quantity += quantity;

                        context.SaveChanges();
                    }
                };

                worker.RunWorkerAsync();
            }
        }
コード例 #6
0
        public void DeleteProductAsync(Product originalProduct)
        {
            using (var worker = new BackgroundWorker())
            {
                worker.DoWork += (s, e) =>
                {
                    using (var context = new EugenieEntities(connectionStringAsString))
                    {
                        var product = context.Products.FirstOrDefault(x => x.ID == originalProduct.ID);

                        var barcodes = product.Barcodes.ToList();
                        foreach (var barcode in barcodes)
                        {
                            context.Barcodes.Remove(barcode);
                        }

                        var shipments = product.Shipments.ToList();
                        foreach (var shipment in shipments)
                        {
                            context.Shipments.Remove(shipment);
                        }

                        var expirationDates = product.ExpirationDates.ToList();
                        foreach (var date in expirationDates)
                        {
                            context.ExpirationDates.Remove(date);
                        }

                        context.Products.Remove(product);
                        context.SaveChanges();
                    }
                };

                worker.RunWorkerAsync();
            }
        }
コード例 #7
0
        public void AddShipmentAsync(Product product, double quantity)
        {
            using (var worker = new BackgroundWorker())
            {
                worker.DoWork += (object sender, DoWorkEventArgs e) =>
                {
                    using (var context = new EugenieEntities(connectionStringAsString))
                    {
                        var shipment = new Shipment();
                        shipment.Quantity = quantity;
                        shipment.Date = DateTime.Today;
                        shipment.ProductID = product.ID;

                        var existingShipment =
                            context.Shipments.FirstOrDefault(
                                x => x.ProductID == shipment.ProductID && x.Date.CompareTo(DateTime.Today) == 0);
                        if (existingShipment == null)
                        {
                            context.Shipments.Add(shipment);
                        }
                        else
                        {
                            existingShipment.Quantity += shipment.Quantity;
                        }

                        context.SaveChanges();
                    }
                };

                worker.RunWorkerAsync();
            }
        }
コード例 #8
0
        public void AddProductAsync(Product originalProduct)
        {
            using (var worker = new BackgroundWorker())
            {
                worker.DoWork += (object sender, DoWorkEventArgs e) =>
                {
                    using (var context = new EugenieEntities(connectionStringAsString))
                    {
                        context.Products.Add(originalProduct);
                        context.SaveChanges();
                    }
                };

                worker.RunWorkerAsync();
            }
        }
コード例 #9
0
 private void SetSelectedItemToFirst()
 {
     if (CurrentProducts.Count() != 0)
     {
         SelectedItem = CurrentProducts.First();
     }
 }
コード例 #10
0
        public void UpdateProduct(Product productToUpdate)
        {
            var oldProduct = AllProducts.FirstOrDefault(x => x.ID == productToUpdate.ID);
            if (oldProduct != null)
            {
                AllProducts.Remove(oldProduct);
            }

            AllProducts.Add(productToUpdate);

            RepeatSearch();
        }