Пример #1
0
        public void EditInventory(Store store)
        {
            bool editting = true;

            while (editting)
            {
                int option = 0;
                while (!(option > 0 && option < 7))
                {
                    Outputter.WriteLine("Select an action:\n[1] Add a new product\n[2] Add inventory for existing product\n[3] Delete product from inventory\n[4] View Inventory\n[5] Quit back to main menu");
                    option = Inputter.GetIntegerInput();
                }
                switch (option)
                {
                case 1:
                    Outputter.Write("Enter a product name: ");
                    string name = Inputter.GetStringInput();
                    Outputter.Write("Enter a price: ");
                    decimal price = Inputter.GetDecimalInput();
                    Outputter.Write("How many do you want to add to inventory: ");
                    int quantity = Inputter.GetIntegerInput();
                    try
                    {
                        Product toAdd = new Product(name, price);
                        ProductRepo.AddProduct(toAdd);
                        toAdd = ProductRepo.GetProductByNameAndPrice(name, Convert.ToDecimal(price)); // This is necessary to get the ID of the product we just added
                        store.AddToInventory(toAdd, quantity);                                        // Don't think I need this
                        StoreRepo.AddToInventory(toAdd, store, quantity);
                        Outputter.WriteLine("Product added to inventory successfully!");
                    }
                    catch (ArgumentException)
                    {
                        Outputter.WriteLine("Couldn't add product to inventory.");
                    }
                    break;

                case 2:
                    PrintInventory(store.ID);
                    Outputter.Write("Enter a product ID: ");
                    try
                    {
                        int     productID = Inputter.GetIntegerInput();
                        Product p         = GetProductFromStoreByID(store, productID);
                        Outputter.Write("How many do you want to add to inventory: ");
                        int quantity2 = Inputter.GetIntegerInput();
                        if (quantity2 > 0)
                        {
                            StoreRepo.UpdateItemQuantity(p, store, quantity2);
                            Outputter.WriteLine("Product inventory added successfully!");
                        }
                        else
                        {
                            Outputter.WriteLine("Can't add 0 or negative inventory amount");
                        }
                    }
                    catch (Exception)
                    {
                        Outputter.WriteLine("Couldn't add inventory for product.");
                    }
                    break;

                case 3:
                    PrintInventory(store.ID);
                    Outputter.Write("Enter a product ID to remove: ");
                    int idRemove = Inputter.GetIntegerInput();
                    try
                    {
                        Product remove = GetProductFromStoreByID(store, idRemove);
                        StoreRepo.RemoveItemFromInventory(remove, store);
                        Outputter.WriteLine("Product successfully removed from inventory!");
                    }
                    catch (Exception)
                    {
                        Outputter.WriteLine("Couldn't remove product from inventory!");
                    }
                    break;

                case 4:
                    PrintInventory(store.ID);
                    break;

                case 5:
                    editting = false;
                    break;
                }
            }
        }
Пример #2
0
 private void cmbStore_SelectedIndexChanged(object sender, EventArgs e)
 {
     this.store = StoreRepo.getStoreId(cmbStore.Text);
 }
Пример #3
0
        public void PlaceNewOrder(Store store)
        {
            Outputter.Write("Enter a customer id to order for them: ");
            int id = Inputter.GetIntegerInput();

            try
            {
                Customer customer = CustomerRepo.GetCustomerByID(id);
                bool     ordering = true;
                Dictionary <Product, int> cart    = new Dictionary <Product, int>();
                Dictionary <Product, int> tempInv = store.Inventory;
                while (ordering)
                {
                    int option = 0;
                    while (!(option > 0 && option < 6))
                    {
                        Outputter.WriteLine("Choose an action\n[1] Add item to cart\n[2] Remove item from cart\n[3] Show cart\n[4] Submit order\n[5] Cancel");
                        option = Inputter.GetIntegerInput();
                    }
                    switch (option)
                    {
                    case 1:
                        PrintInventory(store.ID, cart);
                        Outputter.Write("Enter an item to add to cart: ");
                        int item = Inputter.GetIntegerInput();
                        Outputter.Write("Enter how many you would like: ");
                        int quantity = Inputter.GetIntegerInput();
                        try
                        {
                            Product p = GetProductFromStoreByID(store, item);
                            if (cart.ContainsKey(p) && tempInv[p] >= quantity)
                            {
                                cart[p]    += quantity;
                                tempInv[p] -= quantity;
                            }
                            else if (!cart.ContainsKey(p) && tempInv[p] >= quantity)
                            {
                                cart[p]     = quantity;
                                tempInv[p] -= quantity;
                            }
                            else
                            {
                                throw new ArgumentException("Trying to add too many!");
                            }
                            Outputter.WriteLine("Item added successfully!");
                        }
                        catch (Exception)
                        {
                            Outputter.WriteLine("Couldn't find product to add to cart or too much quantity trying to be added.");
                        }
                        break;

                    case 2:
                        PrintCart(cart);
                        Outputter.Write("Enter an item to remove from cart: ");
                        int item2 = Inputter.GetIntegerInput();
                        Outputter.Write("Enter how many you would like to remove: ");
                        int quantity2 = Inputter.GetIntegerInput();
                        try
                        {
                            Product p = GetProductFromStoreByID(store, item2);
                            foreach (var cartItem in cart)
                            {
                                if (cartItem.Key.ID == p.ID)
                                {
                                    if (cartItem.Value <= quantity2)
                                    {
                                        cart.Remove(cartItem.Key);
                                        tempInv[cartItem.Key] += cartItem.Value;
                                        Outputter.WriteLine("Item removed successfully!");
                                    }
                                    else
                                    {
                                        cart[cartItem.Key]    -= quantity2;
                                        tempInv[cartItem.Key] += quantity2;
                                        Outputter.WriteLine($"Removed {quantity2} {p.Name}'s from cart successfully!");
                                    }
                                }
                            }
                        }
                        catch (Exception)
                        {
                            Outputter.WriteLine("Couldn't find product to remove from cart.");
                        }
                        break;

                    case 3:
                        PrintCart(cart);
                        break;

                    case 4:
                        try
                        {
                            Order order = new Order(customer, store);
                            order.Items = cart;
                            order.CalculateOrderTotal();
                            order.SubmitOrder();
                            StoreRepo.UpdateStore(order.Store);
                            StoreRepo.ProcessInventoryForOrder(order.Store, cart);
                            ordering = false;
                            OrderRepo.AddOrder(order);
                            order = OrderRepo.GetMostRecentOrder();
                            foreach (var orderItem in cart)
                            {
                                OrderRepo.AddOrderItem(orderItem.Key, order, orderItem.Value);
                            }
                            Outputter.WriteLine("Order placed successfully!");
                        }
                        catch (Exception)
                        {
                            Outputter.WriteLine("Couldn't process order");
                        }
                        break;

                    case 5:
                        ordering = false;
                        Outputter.WriteLine("Order cancelled.");
                        break;
                    }
                }
            }
            catch (Exception)
            {
                Outputter.WriteLine("Couldn't find customer with that ID.");
            }
        }
Пример #4
0
        public void initCombo()
        {
            var unitOfMeasurement = UnitOfMeasurementRepo.retrieve();

            if (unitOfMeasurement.Count > 0)
            {
                foreach (var item in unitOfMeasurement)
                {
                    cmbUnitOfMeasurement.Items.Add(item.UnitOfMeasurementName.ToString());
                }
            }
            var categories = CategoryRepo.retrieve();

            if (categories.Count > 0)
            {
                foreach (var item in categories)
                {
                    cmbCategory.Items.Add(item.CategoryValue);
                }
            }

            var subcategory = SubCategoryRepo.retrieve();

            if (subcategory.Count > 0)
            {
                foreach (var item in subcategory)
                {
                    cmbSubCategory.Items.Add(item.SubCategoryValue);
                }
            }

            var supplier = SupplierRepo.suppliers();

            if (supplier.Count > 0)
            {
                foreach (var item in supplier)
                {
                    cmbSupplier.Items.Add(item.SupplierName);
                }
            }

            var warehouse = WarehouseRepo.retrieve();

            if (warehouse.Count > 0)
            {
                foreach (var item in warehouse)
                {
                    cmbWarehouse.Items.Add(item.WarehouseName);
                }
            }

            var status = StatusRepo.retrieve();

            if (status.Count > 0)
            {
                foreach (var item in status)
                {
                    cmbStatus.Items.Add(item.StatusValue);
                }
            }

            List <SMLIB.Entity.ProductAttribute> attributes = ProductAttributeRepo.retrieve();

            if (attributes.Count > 0)
            {
                foreach (var item in attributes)
                {
                    cmbAttributes.Items.Add(item.AttributeName);
                }
            }

            var store = StoreRepo.retrieve();

            if (store.Count > 0)
            {
                foreach (var item in store)
                {
                    cmbStore.Items.Add(item.StoreName);
                }
            }
        }