private void addProductButton_Click(object sender, EventArgs e)
        {
            try
            {
                selectedID = listViewAllProducts.SelectedItems[0].SubItems[0].Text;
                quantity   = int.Parse(textBoxQuantity.Text);


                ProductListElement pe = shop.Products.Find(x => x.ProductId == selectedID);
                if (pe != null)
                {
                    pe.ProductQuantity = pe.ProductQuantity + quantity;
                    PopulateInfos();
                }
                else
                {
                    ProductListElement pe1 = new ProductListElement();
                    pe1.ProductId       = selectedID;
                    pe1.ProductQuantity = quantity;
                    shop.Products.Add(pe1);

                    Product p = _allProducts.Find(x => x.Id == selectedID);
                    shopProducts.Add(p);


                    PopulateInfos();
                }
            }
            catch (Exception ec)
            {
                MessageBox.Show("Select a warewhouse");
            }
        }
Beispiel #2
0
        ProductListElementDto CreateDto(ProductListElement product)
        {
            var dto = _mapper.Map <ProductListElementDto>(product);

            dto.Url = Url.Link(nameof(GetProduct), new { product.Id });
            return(dto);
        }
        public void AddProduct(ProductListElement NewProduct)
        {
            if (this.Products == null)
            {
                Products = new List <ProductListElement>();
            }

            this.Products.Add(NewProduct);
        }
Beispiel #4
0
        private void PopulateINfos()
        {
            GetShopReceipts();
            listViewReceipts.Items.Clear();
            foreach (Receipt op in receipts)
            {
                ProductListElement pe = shop.Products.Find(x => x.ProductId == op.Id);

                ListViewItem item = new ListViewItem(new string[] { op.FullCost.ToString(), op.DateOfBill.ToString(), op.Id.ToString() });

                listViewReceipts.Items.Add(item);
            }
            listViewReceipts.Refresh();
        }
        private void buttonAddProduct_Click(object sender, EventArgs e)
        {
            try
            {
                string             id       = listViewProducts.SelectedItems[0].SubItems[3].Text;
                int                quantity = int.Parse(textBoxQuantity.Text);
                ProductListElement pl       = new ProductListElement();
                pl.ProductId       = id;
                pl.ProductQuantity = quantity;

                transferProducts.Add(pl);
                PopulateTransferProduct();
            }
            catch (Exception ec)
            {
                MessageBox.Show("Select a product");
            }
        }
Beispiel #6
0
        public bool DeleteProduct(string ShopId, string ProductId, int Quantity)
        {
            try
            {
                if (_shopCollection == null || GetShop(ShopId) == null)
                {
                    return(false);
                }

                Shop Shop = GetShop(ShopId);

                if (Shop.Products == null)
                {
                    Shop.Products = new List <ProductListElement>();
                }

                ProductListElement ProductToDelete = Shop.Products.Find(product => product.ProductId == ProductId);

                if (ProductToDelete == null)
                {
                    return(false);
                }
                else if (Quantity > ProductToDelete.ProductQuantity)
                {
                    return(false);
                }

                ProductToDelete.ProductQuantity -= Quantity;

                if (ProductToDelete.ProductQuantity == 0)
                {
                    Shop.Products.Remove(ProductToDelete);
                }

                UpdateDefinition <Shop> UpdateShop = Builders <Shop> .Update.Set("Products", Shop.Products);

                _shopCollection.UpdateOne(Builders <Shop> .Filter.Eq("Id", Shop.Id.ToString()), UpdateShop);
                return(true);
            }
            catch
            {
                return(false);
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                selectedID       = listViewProductsInShop.SelectedItems[0].SubItems[0].Text;
                selectedQuantity = int.Parse(listViewProductsInShop.SelectedItems[0].SubItems[1].Text);
                quantityToAdd    = int.Parse(textBoxQuantity.Text);



                if (selectedQuantity >= quantityToAdd)
                {
                    ProductListElement current = currentProducts.Find(x => x.ProductId == selectedID);
                    if (current == null)
                    {
                        ProductListElement product = new ProductListElement();
                        product.ProductId       = selectedID;
                        product.ProductQuantity = quantityToAdd;
                        currentProducts.Add(product);
                    }
                    else
                    {
                        current.ProductQuantity = current.ProductQuantity + quantityToAdd;
                    }



                    selectedQuantity -= quantityToAdd;
                    shop.Products.Find(x => x.ProductId == selectedID).ProductQuantity = selectedQuantity;
                    PopulateChangedShop();
                    PopulateCurrentProducts();
                }
                else
                {
                    MessageBox.Show("Inserted quantity is greater than selected");
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Select a product");
            }
        }
Beispiel #8
0
        public bool CheckProductQuantity(string WarehouseId, string ProductId, int ProductQuantity)
        {
            if (!WarehouseExists(WarehouseId))
            {
                return(false);
            }

            Warehouse          TargetedWarehouse = GetWarehouse(WarehouseId);
            ProductListElement TargetedProduct   = TargetedWarehouse.Products.Find(SingleProduct => SingleProduct.ProductId == ProductId);

            if (TargetedProduct == null)
            {
                return(false);
            }
            else if (TargetedProduct.ProductQuantity > ProductQuantity)
            {
                return(true);
            }

            return(false);
        }
Beispiel #9
0
        public bool DeleteProduct(string WarehouseId, string ProductId, int Quantity)
        {
            try
            {
                if (_warehouseCollection == null || !WarehouseExists(WarehouseId))
                {
                    return(false);
                }

                Warehouse Warehouse = GetWarehouse(WarehouseId);

                if (Warehouse.Products == null)
                {
                    return(false);
                }

                ProductListElement ProductToDelete = Warehouse.Products.Find(product => product.ProductId == ProductId);

                if (ProductToDelete == null || Quantity > ProductToDelete.ProductQuantity)
                {
                    return(false);
                }

                ProductToDelete.ProductQuantity -= Quantity;

                if (ProductToDelete.ProductQuantity == 0)
                {
                    Warehouse.Products.Remove(ProductToDelete);
                }

                UpdateDefinition <Warehouse> UpdateWarehouse = Builders <Warehouse> .Update.Set("Products", Warehouse.Products);

                _warehouseCollection.UpdateOne(Builders <Warehouse> .Filter.Eq("Id", Warehouse.Id.ToString()), UpdateWarehouse);
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Beispiel #10
0
        public bool AddProduct(string ShopId, string ProductId, int Quantity)
        {
            try
            {
                if (_shopCollection == null || GetShop(ShopId) == null)
                {
                    return(false);
                }
                Shop ShopToAdd = GetShop(ShopId);

                if (ShopToAdd.Products == null)
                {
                    ShopToAdd.Products = new List <ProductListElement>();
                }

                ProductListElement ProductToChange = ShopToAdd.Products.Find(SingleProduct => SingleProduct.ProductId == ProductId);

                if (ProductToChange != null)
                {
                    ProductToChange.ProductQuantity += Quantity;
                }
                else
                {
                    ShopToAdd.Products.Add(new ProductListElement(ProductId, Quantity));
                }

                UpdateDefinition <Shop> UpdateShop = Builders <Shop> .Update.Set("Products", ShopToAdd.Products);

                _shopCollection.UpdateOne(Builders <Shop> .Filter.Eq("Id", ShopToAdd.Id.ToString()), UpdateShop);
                return(true);
            }
            catch
            {
                return(false);
            }
        }
        private void PopulateInfos()
        {
            listViewProducts.Items.Clear();
            listViewAllProducts.Items.Clear();


            foreach (Product op in shopProducts)
            {
                ProductListElement pe = shop.Products.Find(x => x.ProductId == op.Id);

                ListViewItem item = new ListViewItem(new string[] { op.Id.ToString(), op.Name.ToString(), pe.ProductQuantity.ToString() });

                listViewProducts.Items.Add(item);
            }
            listViewProducts.Refresh();

            foreach (Product op in _allProducts)
            {
                ListViewItem item = new ListViewItem(new string[] { op.Id.ToString(), op.Name.ToString() });

                listViewAllProducts.Items.Add(item);
            }
            listViewAllProducts.Refresh();
        }
Beispiel #12
0
        public bool AddProduct(string WarehouseId, string ProductId, int Quantity)
        {
            try
            {
                if (_warehouseCollection == null || WarehouseExists(WarehouseId) == false)
                {
                    return(false);
                }
                Warehouse Warehouse = GetWarehouse(WarehouseId);

                if (Warehouse.Products == null)
                {
                    Warehouse.Products = new List <ProductListElement>();
                }

                ProductListElement ProductToChange = Warehouse.Products.Find(SingleProduct => SingleProduct.ProductId == ProductId);

                if (ProductToChange != null)
                {
                    ProductToChange.ProductQuantity += Quantity;
                }
                else
                {
                    Warehouse.Products.Add(new ProductListElement(ProductId, Quantity));
                }

                UpdateDefinition <Warehouse> UpdateWarehouse = Builders <Warehouse> .Update.Set("Products", Warehouse.Products);

                _warehouseCollection.UpdateOne(Builders <Warehouse> .Filter.Eq("Id", Warehouse.Id), UpdateWarehouse);
                return(true);
            }
            catch
            {
                return(false);
            }
        }