Exemplo n.º 1
0
        static void Main(string[] args)
        {
            //Expands the console for easier viewing
            Console.SetWindowSize(150, 40);

            //Create an instance of the UserInterface class
            UserInterface userInterface = new UserInterface();

            //Create an instance of the wine database
            BeverageJAckermanEntities beverageEntities = new BeverageJAckermanEntities();

            //Display the Welcome Message to the user
            userInterface.DisplayWelcomeGreeting();

            //Display the Menu and get the response. Store the response in the choice integer
            //This is the 'primer' run of displaying and getting.
            int choice = userInterface.DisplayMenuAndGetResponse();

            while (choice != 6)
            {
                beverageEntities.SaveChanges();
                switch (choice)
                {
                    case 1:
                        //Print Entire List Of Items
                        userInterface.DisplayAllItems(beverageEntities);
                        break;

                    case 2:
                        //Search For An Item
                        string searchQuery = userInterface.GetSearchQuery();
                        Beverage foundWine = beverageEntities.Beverages.Find(searchQuery);
                        if (foundWine != null)
                        {
                            Console.WriteLine("");
                            Console.WriteLine("");
                            Console.WriteLine("Here is the wine with that ID:");
                            Console.WriteLine(foundWine.id + " " + foundWine.name + " " + foundWine.pack + " " + foundWine.price);
                        }
                        else
                        {
                            Console.WriteLine("Sorry, no wine with that ID could be found. the ID you entered may be incorrect or does not exist in the database.");
                        }

                        break;

                    case 3:
                        //Add A New Item To The List
                        string ID;
                        string Name;
                        decimal Price;
                        string Pack;

                        //Instead of passing the values to the method, we take them out of the method after it's finished
                        userInterface.GetNewItemInformation(out ID, out Name, out Price, out Pack);

                        bool WineAddedBool = false;

                        while (WineAddedBool == false)
                        {
                            //Creates an instance of beverage that will be used to see if the ID the user wants to use already exists
                            Beverage IDCheck = beverageEntities.Beverages.Find(ID);

                            if (IDCheck == null)
                            {
                                //Create an instance of beverage to eventually add to the database
                                Beverage newWine = new Beverage();

                                newWine.id = ID;
                                newWine.name = Name;
                                newWine.pack = Pack;
                                newWine.price = Price;

                                beverageEntities.Beverages.Add(newWine);
                                WineAddedBool = true;
                            }
                            else
                            {
                                Console.WriteLine("Sorry, a wine with this ID already exists. Would you like to enter a new ID?");
                                Console.WriteLine("y/n?");
                                string input = "nothing";
                                while (input != "y")
                                {
                                    input = Console.ReadLine();
                                    if (input == "y")
                                    {
                                        ID = userInterface.GetNewID();
                                    }
                                    else if (input == "n")
                                    {
                                        return;
                                    }
                                    else
                                    {
                                        Console.WriteLine("Sorry, you entered something other than a y or an n");
                                    }
                                }

                            }
                        }

                        break;

                    case 4:
                        //Delete an item from the list
                        string IDToDelete = userInterface.GetDeleteQuery();
                        Beverage deleteWine = beverageEntities.Beverages.Find(IDToDelete);

                        if(deleteWine != null)
                        {
                            beverageEntities.Beverages.Remove(deleteWine);
                            userInterface.DisplayDeleteSuccess();
                        }
                        else
                        {
                            Console.WriteLine("Error, the ID you entered does not corrospond to any Wine currently in the database.");
                        }
                        break;
                    case 5:
                        //Update an item from the database
                        string IDToUpdate = userInterface.GetUpdateQuery();
                        Beverage updateBeverage = beverageEntities.Beverages.Find(IDToUpdate);

                        if(updateBeverage != null)
                        {
                            Console.WriteLine("Would you like to change the ID of the wine?");
                            Console.WriteLine("y/n?");
                            string userInput = Console.ReadLine();
                            if(userInput == "y")
                            {
                                Console.WriteLine("What is the new ID you would like to assign to the wine?");

                                userInput = Console.ReadLine();

                                updateBeverage.id = userInput;
                            }
                            Console.WriteLine("Would you like to change the name of the wine?");
                            Console.WriteLine("y/n?");
                            userInput = Console.ReadLine();
                            if (userInput == "y")
                            {
                                Console.WriteLine("What is the new name you would like to assign to the wine?");

                                userInput = Console.ReadLine();

                                updateBeverage.name = userInput;
                            }
                            Console.WriteLine("Would you like to change the price of the wine?");
                            Console.WriteLine("y/n?");
                            userInput = Console.ReadLine();
                            if (userInput == "y")
                            {
                                Console.WriteLine("What is the new price you would like to assign to the wine?");

                                userInput = Console.ReadLine();

                                updateBeverage.price = decimal.Parse(userInput);
                            }
                            Console.WriteLine("Would you like to change the pack of the wine?");
                            Console.WriteLine("y/n?");
                            userInput = Console.ReadLine();
                            if (userInput == "y")
                            {
                                Console.WriteLine("What is the new pack you would like to assign to the wine?");

                                userInput = Console.ReadLine();

                                updateBeverage.pack = userInput;
                            }

                            userInterface.DisplayUpdateSuccess();
                        }
                        else
                        {
                            userInterface.DisplayUpdateFailure();
                        }
                        break;
                    case 6:

                        break;
                }

                //Get the new choice of what to do from the user
                choice = userInterface.DisplayMenuAndGetResponse();
            }

            beverageEntities.SaveChanges();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            //Create an instance of the UserInterface class
            UserInterface userInterface = new UserInterface();

            //Display the Welcome Message to the user
            userInterface.DisplayWelcomeGreeting();

            //Display the Menu and get the response. Store the response in the choice integer
            //This is the 'primer' run of displaying and getting.
            int choice = userInterface.DisplayMenuAndGetResponse();

            //import from the database
            BeverageYWangEntities beverageYWangEntities = new BeverageYWangEntities();

            while (choice != 7)
            {
                switch (choice)
                {
                    case 1:
                        //Gain access to the database
                        Beverage beverage = new Beverage();

                       /*
                        if (beverage != null)
                        {
                            //Display Success Message
                            userInterface.DisplayImportSuccess();
                        }
                        else
                        {
                            //Display Fail Message
                            userInterface.DisplayImportError();
                        }
                       */
                        break;

                    case 2:
                        //Print Entire List Of Items

                        userInterface.DisplayAllItems(beverageYWangEntities);

                        break;

                    case 3:
                        //Search For An Item
                        string searchQuery = userInterface.GetSearchQuery();

                        Beverage foundBeverage = beverageYWangEntities.Beverages.Find(searchQuery);

                        if (foundBeverage != null)
                        {
                            userInterface.DisplayItemFound(foundBeverage);
                        }
                        else
                        {
                            userInterface.DisplayItemFoundError();
                        }
                        break;

                    case 4:
                        //Add A New Item To The List
                        string[] newItemInformation = userInterface.GetNewItemInformation();
                        if (beverageYWangEntities.Beverages.Find(newItemInformation[0]) == null)
                        {
                            Beverage newBeverage = new Beverage();

                            newBeverage.id = newItemInformation[0];
                            newBeverage.name = newItemInformation[1];
                            newBeverage.pack = newItemInformation[2];
                            newBeverage.price = Convert.ToDecimal(newItemInformation[3]);
                            newBeverage.active = Convert.ToBoolean(newItemInformation[4]);

                            //Add to the database
                            beverageYWangEntities.Beverages.Add(newBeverage);
                            //Save Changes to the database
                            beverageYWangEntities.SaveChanges();

                            //Successful add
                            userInterface.DisplayAddWineItemSuccess();

                        }
                        else
                        {
                            userInterface.DisplayItemAlreadyExistsError();
                        }

                        break;
                    case 5:
                        //Update Item to Database
                        string updateQuery = userInterface.GetSearchQuery();
                        //locate the item by Id
                        Beverage beverageForUpdate = beverageYWangEntities.Beverages.Find(updateQuery);

                        if (beverageForUpdate != null)
                        {
                            string[] updateItemInformation = userInterface.GetUpdateItemInformation();

                                beverageForUpdate.name = updateItemInformation[0];
                                beverageForUpdate.pack = updateItemInformation[1];
                                beverageForUpdate.price = Convert.ToDecimal(updateItemInformation[2]);
                                beverageForUpdate.active = Convert.ToBoolean(updateItemInformation[3]);

                                //update to the database
                                beverageYWangEntities.Beverages.Add(beverageForUpdate);
                                //Save Changes to the database
                                beverageYWangEntities.SaveChanges();

                                //Successful update
                                userInterface.DisplayAddWineItemSuccess();
                        }
                        else
                        {
                            userInterface.DisplayItemFoundError();
                        }

                        break;
                    case 6:
                        //Delete Item from Database
                        string deleteQuery = userInterface.GetSearchQuery();
                        Beverage beverageForDelete = beverageYWangEntities.Beverages.Find(deleteQuery);

                        if (beverageForDelete != null)
                        {
                            userInterface.DisplayItemFound(beverageForDelete);
                            //Delete the Record
                            beverageYWangEntities.Beverages.Remove(beverageForDelete);
                            //Save changes to database
                            beverageYWangEntities.SaveChanges();
                        }
                        else
                        {
                            userInterface.DisplayItemFoundError();
                        }

                        break;

                }

                //Get the new choice of what to do from the user
                choice = userInterface.DisplayMenuAndGetResponse();
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            //Set a constant for the size of the collection
            const int wineItemCollectionSize = 4000;

            //Set a constant for the path to the CSV File
            const string pathToCSVFile = "../../../datafiles/winelist.csv";

            //Create an instance of the UserInterface class
            UserInterface userInterface = new UserInterface();

            //Create an instance of the WineItemCollection class
            WineItemCollection wineItemCollection = new WineItemCollection(wineItemCollectionSize);

            //Create an instance of the CSVProcessor class
            CSVProcessor csvProcessor = new CSVProcessor();

            //Display the Welcome Message to the user
            userInterface.DisplayWelcomeGreeting();

            //Display the Menu and get the response. Store the response in the choice integer
            //This is the 'primer' run of displaying and getting.
            int choice = userInterface.DisplayMenuAndGetResponse();

            while (choice != 5)
            {
                switch (choice)
                {
                case 1:
                    //Load the CSV File
                    bool success = csvProcessor.ImportCSV(wineItemCollection, pathToCSVFile);
                    if (success)
                    {
                        //Display Success Message
                        userInterface.DisplayImportSuccess();
                    }
                    else
                    {
                        //Display Fail Message
                        userInterface.DisplayImportError();
                    }
                    break;

                case 2:
                    //Print Entire List Of Items
                    string[] allItems = wineItemCollection.GetPrintStringsForAllItems();
                    if (allItems.Length > 0)
                    {
                        //Display all of the items
                        userInterface.DisplayAllItems(allItems);
                    }
                    else
                    {
                        //Display error message for all items
                        userInterface.DisplayAllItemsError();
                    }
                    break;

                case 3:
                    //Search For An Item
                    string searchQuery     = userInterface.GetSearchQuery();
                    string itemInformation = wineItemCollection.FindById(searchQuery);
                    if (itemInformation != null)
                    {
                        userInterface.DisplayItemFound(itemInformation);
                    }
                    else
                    {
                        userInterface.DisplayItemFoundError();
                    }
                    break;

                case 4:
                    //Add A New Item To The List
                    string[] newItemInformation = userInterface.GetNewItemInformation();
                    if (wineItemCollection.FindById(newItemInformation[0]) == null)
                    {
                        wineItemCollection.AddNewItem(newItemInformation[0], newItemInformation[1], newItemInformation[2]);
                        userInterface.DisplayAddWineItemSuccess();
                    }
                    else
                    {
                        userInterface.DisplayItemAlreadyExistsError();
                    }
                    break;
                }

                //Get the new choice of what to do from the user
                choice = userInterface.DisplayMenuAndGetResponse();
            }
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            //Create an instance of the UserInterface class
            UserInterface userInterface = new UserInterface();
            ////Bev item collection instance
            BevItemCollection bevCollection = new BevItemCollection();


            //Display the Welcome Message to the user
            userInterface.DisplayWelcomeGreeting();

            //Display the Menu and get the response. Store the response in the choice integer
            //This is the 'primer' run of displaying and getting.
            int choice = userInterface.DisplayMenuAndGetResponse();

            while (choice != 6)
            {
                switch (choice)
                {
                case 1:
                    //Add A New Item
                    string IDnew = userInterface.IDadd();
                    try
                    {
                        Beverage ToFind = bevCollection.searchItem(IDnew);

                        userInterface.DisplayItemAlreadyExistsError();
                    }
                    catch
                    {
                        //nothing found
                        string[] newItemInformation = userInterface.GetNewItemInformation();
                        decimal  price  = userInterface.PriceAdd();
                        bool     active = userInterface.ActiveAdd();

                        bevCollection.addItem(IDnew, newItemInformation, price, active);

                        userInterface.DisplayAddWineItemSuccess();
                    }
                    break;

                case 2:
                    //Search For An Item
                    //Get input
                    string searchResponse = userInterface.GetSearchQuery();
                    //Try and find
                    try
                    {
                        //attempt to find ID
                        Beverage ToFind = bevCollection.searchItem(searchResponse);

                        userInterface.DisplayItemFound();

                        userInterface.DisplayItemInfo(ToFind);
                    }
                    catch
                    {
                        //nothing found
                        userInterface.DisplayItemFoundError();
                    }
                    break;

                case 3:
                    //Update an existing item
                    string updateID = userInterface.getUpdateID();
                    //Try and find
                    try
                    {
                        //attempt to find ID
                        Beverage ToUpdate = bevCollection.searchItem(updateID);

                        userInterface.DisplayItemFound();
                        userInterface.DisplayItemInfo(ToUpdate);
                        //Get update info
                        string name = userInterface.updateName(ToUpdate.name);
                        //Get pack info
                        string pack = userInterface.updatePack(ToUpdate.pack);
                        //Get price info
                        decimal price = userInterface.updatePrice(ToUpdate.price);
                        //Get price info
                        bool active = userInterface.updateActive(ToUpdate.active);

                        //send to collection class
                        bevCollection.updateItem(ToUpdate, name, pack, price, active);

                        userInterface.updateSucess();
                        userInterface.DisplayItemInfo(ToUpdate);
                    }
                    catch
                    {
                        //nothing found
                        userInterface.DisplayItemFoundError();
                    }
                    break;

                case 4:
                    //Delete an Item from Database
                    string deleteID = userInterface.getDeleteID();
                    //Try and find
                    try
                    {
                        //attempt to find ID
                        Beverage ToDelete = bevCollection.searchItem(deleteID);

                        userInterface.DisplayItemFound();
                        userInterface.DisplayItemInfo(ToDelete);

                        bool input = userInterface.acceptDelete();

                        if (input == true)
                        {
                            //Delete Item
                            bevCollection.deleteItem(ToDelete);
                            //Confirm
                            userInterface.confirmDelete();
                        }
                        else
                        {
                            userInterface.canceldelete();
                            break;
                        }
                    }
                    catch
                    {
                        //nothing found
                        userInterface.DisplayItemFoundError();
                    }
                    break;

                case 5:
                    //Print Database
                    userInterface.DisplayAllItems();
                    break;
                }

                //Get the new choice of what to do from the user
                choice = userInterface.DisplayMenuAndGetResponse();
            }
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            //Create an instance of the UserInterface class
            UserInterface userInterface = new UserInterface();

            //Create an instance of the WineItemCollection class
            WineItemCollection wineItemCollection = new WineItemCollection();

            //Display the Welcome Message to the user
            userInterface.DisplayWelcomeGreeting();

            Console.BufferHeight = 5000;
            Console.BufferWidth  = 150;

            //Display the Menu and get the response. Store the response in the choice integer
            //This is the 'primer' run of displaying and getting.
            int choice = userInterface.DisplayMenuAndGetResponse();

            while (choice != 7)
            {
                switch (choice)
                {
                case 1:
                    userInterface.DisplayImportSuccess();
                    break;

                case 2:
                    //Print Entire List Of Items
                    string[] allItems = wineItemCollection.GetPrintStringsForAllItems();
                    if (allItems.Length > 0)
                    {
                        //Display all of the items
                        userInterface.DisplayAllItems(allItems);
                    }
                    else
                    {
                        //Display error message for all items
                        userInterface.DisplayAllItemsError();
                    }
                    break;

                case 3:
                    //Search For An Item
                    string searchQuery     = userInterface.GetSearchQuery();
                    string itemInformation = wineItemCollection.FindById(searchQuery);
                    if (itemInformation != null)
                    {
                        userInterface.DisplayItemFound(itemInformation);
                    }
                    else
                    {
                        userInterface.DisplayItemFoundError();
                    }
                    break;

                case 4:
                    // Add A New Item To The List
                    string[] newItemInformation = userInterface.GetItemInformation();
                    // Convert the price to a decimal:
                    decimal price = Convert.ToDecimal(newItemInformation[3]);
                    // Set a boolean to hold whether the item is active:
                    bool active = false;
                    // If the input was Y for yes, set active to true:
                    if (newItemInformation[4] == "Y")
                    {
                        active = true;
                    }
                    // Send info to WineItemCollection to add a new item:
                    if (wineItemCollection.AddNewItem(newItemInformation[0], newItemInformation[1], newItemInformation[2], price, active))
                    {
                        userInterface.DisplayAddWineItemSuccess();
                    }
                    else
                    {
                        userInterface.DisplayItemAlreadyExistsError();
                    }
                    break;

                case 5:
                    // Update an item in the list:
                    string idUpdate = userInterface.GetUpdateId();
                    if (wineItemCollection.UpdateBeverageItem(idUpdate))
                    {
                        userInterface.DisplayItemUpdateSuccess();
                    }
                    else
                    {
                        userInterface.DisplayItemUpdateError();
                    }
                    break;

                case 6:
                    // Delete an item from the list:
                    string idDelete = userInterface.GetDeleteId();
                    if (wineItemCollection.DeleteBeverageItem(idDelete))
                    {
                        userInterface.DisplayItemDeleteSuccess();
                    }
                    else
                    {
                        userInterface.DisplayItemDeleteError();
                    }
                    break;
                }

                //Get the new choice of what to do from the user
                choice = userInterface.DisplayMenuAndGetResponse();
            }
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            BeverageCollection beverageCollection = new BeverageCollection();

            //Create an instance of the UserInterface class
            UserInterface userInterface = new UserInterface();

            //Display the Welcome Message to the user
            userInterface.DisplayWelcomeGreeting();

            //Display the Menu and get the response. Store the response in the choice integer
            //This is the 'primer' run of displaying and getting.
            int choice = userInterface.DisplayMenuAndGetResponse();

            while (choice != 6)
            {
                switch (choice)
                {
                case 1:
                    //Print Entire List Of Items
                    string[] allItems = beverageCollection.GetPrintStringsForAllItems();
                    if (allItems.Length > 0)
                    {
                        //Display all of the items
                        userInterface.DisplayAllItems(allItems);
                    }
                    else
                    {
                        //Display error message for all items
                        userInterface.DisplayAllItemsError();
                    }
                    break;

                case 2:
                    //Search For An Item
                    string searchQuery     = userInterface.GetSearchQuery();
                    string itemInformation = beverageCollection.FindById(searchQuery);
                    if (itemInformation != null)
                    {
                        userInterface.DisplayItemFound(itemInformation);
                    }
                    else
                    {
                        userInterface.DisplayItemFoundError();
                    }
                    break;

                case 3:
                    //Add A New Item To The List
                    string[] newItemInformation = userInterface.GetNewItemInformation();
                    Decimal  newItemPrice       = userInterface.GetItemPrice();
                    bool     newItemActive      = userInterface.GetItemActive();
                    bool     addSuccessful      = false;
                    //check if the key already exists
                    if (beverageCollection.FindById(newItemInformation[0]) == null)
                    {
                        //add item
                        addSuccessful = beverageCollection.AddNewItem(newItemInformation[0], newItemInformation[1], newItemInformation[2], newItemPrice, newItemActive);
                        //show the user if the add was successful
                        if (addSuccessful)
                        {
                            userInterface.DisplayAddBeverageSuccess();
                        }
                        else
                        {
                            userInterface.DisplayAddBeverageFailure();
                        }
                    }
                    else
                    {
                        //shows error if item already exists
                        userInterface.DisplayItemAlreadyExistsError();
                    }

                    break;

                case 4:
                    //update an item on the list
                    string update            = userInterface.GetUpdateQuery();
                    string updateInformation = beverageCollection.FindById(update);
                    if (updateInformation != null)
                    {
                        string[] updateItemInformation = userInterface.GetUpdateItemInformation();
                        Decimal  updateItemPrice       = userInterface.GetItemPrice();
                        bool     updateItemActive      = userInterface.GetItemActive();
                        bool     updateSuccessful      = beverageCollection.UpdateRecord(update, updateItemInformation[0], updateItemInformation[1], updateItemPrice, updateItemActive);
                        //successful update?
                        if (updateSuccessful)
                        {
                            userInterface.DisplayUpdateBeverageSuccess();
                        }
                        else
                        {
                            userInterface.DisplayUpdateBeverageFailure();
                        }
                    }
                    else
                    {
                        //display if the item is not found
                        userInterface.DisplayItemFoundError();
                    }



                    break;

                case 5:
                    //delete an item from the list
                    string del = userInterface.GetDeleteQuery();
                    bool   deleteSuccessful = beverageCollection.DeleteById(del);
                    //show the user if the delete was successful
                    if (deleteSuccessful)
                    {
                        userInterface.DisplayDeleteBeverageSuccess();
                    }
                    else
                    {
                        userInterface.DisplayDeleteBeverageFailure();
                    }
                    break;
                }

                //Get the new choice of what to do from the user
                choice = userInterface.DisplayMenuAndGetResponse();
            }
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            Console.BufferHeight = Int16.MaxValue - 1;  // resets the console bufferhieght to allow the entire file
                                                        // to be read into a single console window
            Console.SetWindowSize(200, 30);             // resizes the window to fit the special output formatting

            //Create an instance of the UserInterface class
            UserInterface userInterface = new UserInterface();

            //Create an instance of the WineItemCollection class
            BeverageCollection beverageCollection = new BeverageCollection();

            //Display the Welcome Message to the user
            userInterface.DisplayWelcomeGreeting();

            //Display the Menu and get the response. Store the response in the choice integer
            //This is the 'primer' run of displaying and getting.
            int choice = userInterface.DisplayMenuAndGetResponse();

            while (choice != 6)
            {
                switch (choice)
                {
                case 1:
                    //Print Entire List Of Items
                    //Display all of the items
                    try
                    {
                        userInterface.DisplayAllItems(beverageCollection.GetPrintStringsForAllItems());
                        userInterface.DisplayImportSuccess();
                    }
                    catch
                    {
                        userInterface.DisplayImportError();
                    }

                    break;

                case 2:
                    //Search For An Item
                    string searchQuery        = userInterface.GetSearchQuery();
                    string addItemInformation = beverageCollection.FindById(searchQuery);
                    if (addItemInformation != null)
                    {
                        userInterface.DisplayItemFound(addItemInformation);
                    }
                    break;

                case 3:
                    //Add A New Item To The List
                    string[] newItemInformation   = userInterface.GetNewItemInformation();
                    decimal  newPriceInformation  = userInterface.GetNewPriceInformation();
                    bool     newActiveInformation = userInterface.GetNewActiveInformation();

                    /**
                     * if (beverageCollection.FindById(newItemInformation[0]) == null)
                     * {
                     *  //beverageCollection.AddNewItem(newItemInformation[0], newItemInformation[1], newItemInformation[2], newPriceInformation, newActiveInformation);
                     *  beverageCollection.AddToDatabase(newItemInformation[0], newItemInformation[1], newItemInformation[2], newPriceInformation, newActiveInformation);
                     *  userInterface.DisplayAddWineItemSuccess();
                     * }
                     * else
                     * {
                     *  userInterface.DisplayItemAlreadyExistsError();
                     * }
                     **/

                    try
                    {
                        beverageCollection.AddToDatabase(newItemInformation[0], newItemInformation[1], newItemInformation[2], newPriceInformation, newActiveInformation);
                        userInterface.DisplayAddWineItemSuccess();
                    }
                    catch
                    {
                        userInterface.DisplayItemAlreadyExistsError();
                    }
                    break;

                case 4:
                    // remove an item
                    string IDToRemove            = userInterface.RemoveByID();
                    string removeItemInformation = beverageCollection.FindById(IDToRemove);

                    // try catch, fails if the beverage is null

                    try
                    {
                        beverageCollection.RemoveByID(IDToRemove);
                    }
                    catch (Exception e)
                    {
                        userInterface.DisplayItemFoundError();
                    }
                    break;

                case 5:
                    //update an Item on The List
                    string[] updateBeverageInformation = userInterface.GetUpdateItemInformation();
                    decimal  updatePriceInformation    = userInterface.GetNewPriceInformation();
                    bool     updateActiveInformation   = userInterface.GetNewActiveInformation();

                    try
                    {
                        beverageCollection.updateBeverage(updateBeverageInformation[0], updateBeverageInformation[1], updateBeverageInformation[2], updatePriceInformation, updateActiveInformation);
                    }
                    catch
                    {
                        userInterface.DisplayItemFoundError();
                    }

                    //if (beverageCollection.FindById(updateBeverageInformation[0]) != null)
                    //{
                    //    beverageCollection.updateBeverage(updateBeverageInformation[0], updateBeverageInformation[1], updateBeverageInformation[2], updatePriceInformation, updateActiveInformation);
                    //    //beverageCollection.updateBeverage("12345", "1", "1", 1, true);

                    //    userInterface.DisplayAddWineItemSuccess();
                    //}
                    //else
                    //{
                    //    userInterface.DisplayItemFoundError();
                    //}
                    break;
                }

                //Get the new choice of what to do from the user
                choice = userInterface.DisplayMenuAndGetResponse();
            }
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            //Create an instance of the UserInterface class
            UserInterface userInterface = new UserInterface();

            //Create an instance of the BeverageRepository class
            BeverageRepository beverageRepository = new BeverageRepository();


            //Display the Welcome Message to the user
            userInterface.DisplayWelcomeGreeting();

            //Display the Menu and get the response. Store the response in the choice integer
            //This is the 'primer' run of displaying and getting.
            int choice = userInterface.DisplayMenuAndGetResponse();

            while (choice != 6)
            {
                switch (choice)
                {
                case 1:
                    //Print Entire List Of Items
                    userInterface.DisplayAllItems(beverageRepository.GetPrintString());
                    break;

                case 2:
                    //Search For An Item
                    string searchQuery     = userInterface.GetSearchQuery();
                    string itemInformation = beverageRepository.GetBeverageInfo(searchQuery);
                    if (itemInformation != null)
                    {
                        userInterface.DisplayItemFound(itemInformation);
                    }
                    else
                    {
                        userInterface.DisplayItemFoundError();
                    }
                    break;

                case 3:
                    //Add A New Item To The database
                    string[] newItemInformation = userInterface.GetNewItemInformation();
                    bool     activeItem;

                    // Check if they entered a "y" or "n", if not, display error message and break out of the process.
                    if (newItemInformation[4].ToLower() == "y")
                    {
                        activeItem = true;
                    }
                    else if (newItemInformation[4].ToLower() == "n")
                    {
                        activeItem = false;
                    }
                    else
                    {
                        userInterface.DisplayErrorMessage();
                        break;
                    }


                    // Check to make sure the that the id isn't in use
                    if (beverageRepository.GetBeverageInfo(newItemInformation[0]) == null)
                    {
                        try
                        {
                            beverageRepository.AddNewItem(newItemInformation[0], newItemInformation[1], newItemInformation[2], decimal.Parse(newItemInformation[3]), activeItem);
                            userInterface.DisplayAddBeverageSuccess();
                        }
                        catch (FormatException ex)    // Catch error when trying to parse the price
                        {
                            userInterface.DisplayInvalidPriceInput();
                        }
                    }
                    else
                    {
                        userInterface.DisplayItemAlreadyExistsError();
                    }
                    break;

                case 4:

                    // Update an item in the database
                    string[] updatedItemInformation = userInterface.GetUpdatedItemInformation();
                    bool     updatedActiveItem      = false;
                    if (updatedItemInformation[4].ToLower() == "y")
                    {
                        activeItem = true;
                    }
                    else if (updatedItemInformation[4].ToLower() == "n")
                    {
                        activeItem = false;
                    }
                    else
                    {
                        userInterface.DisplayErrorMessage();
                        break;
                    }

                    if (beverageRepository.GetBeverageInfo(updatedItemInformation[0]) != null)
                    {
                        try
                        {
                            beverageRepository.UpdateItem(updatedItemInformation[0], updatedItemInformation[1], updatedItemInformation[2], decimal.Parse(updatedItemInformation[3]), updatedActiveItem);
                            userInterface.DisplayAddBeverageSuccess();
                        }
                        catch (FormatException ex)
                        {
                            userInterface.DisplayInvalidPriceInput();
                        }
                    }
                    else
                    {
                        userInterface.DisplayItemNotExist();
                    }
                    break;

                case 5:
                    // Delete item from database
                    string id = userInterface.GetItemIDForDeletion();
                    if (beverageRepository.GetBeverageInfo(id) != null)
                    {
                        beverageRepository.DeleteItem(id);
                        userInterface.DisplaySuccessfullyDeletedItem();
                    }
                    else
                    {
                        userInterface.DisplayItemNotExist();
                    }
                    break;
                }

                //Get the new choice of what to do from the user
                choice = userInterface.DisplayMenuAndGetResponse();
            }
        }
Exemplo n.º 9
0
        static void Main(string[] args)
        {
            //Create an instance of the UserInterface class
            UserInterface userInterface = new UserInterface();

            //Import the database and show import message (This is done on startup by default)
            BeverageACullenEntities beverageACullenEntities = new BeverageACullenEntities();
            userInterface.DisplayImportSuccess();

            //Display the Welcome Message to the user
            userInterface.DisplayWelcomeGreeting();

            //Display the Menu and get the response. Store the response in the choice integer
            //This is the 'primer' run of displaying and getting.
            int choice = userInterface.DisplayMenuAndGetResponse();

            while (choice != 6)
            {
                switch (choice)
                {
                    case 1:

                        //Display entire list of beverages
                        userInterface.DisplayAllItems(beverageACullenEntities);
                        break;

                    case 2:
                        //Search the list for a beverage by ID
                        string searchQuery = userInterface.GetSearchQuery();

                        Beverage searchBeverage = beverageACullenEntities.Beverages.Find(searchQuery);

                        if (searchBeverage != null)
                        {
                            userInterface.DisplayItemFound();
                            userInterface.DisplayItem(searchBeverage);
                        }
                        else
                        {
                            userInterface.DisplayItemFoundError();
                        }
                        break;

                    case 3:
                        //Add a beverage item to the list

                        //Get values from user
                        string[] addItemInfo = userInterface.GetItemInformation(false,"");

                        //Make sure the user entered ID is not already on the list
                        if (beverageACullenEntities.Beverages.Find(addItemInfo[0]) == null)
                        {
                            //Create a new beverage and import values from user input
                            Beverage addBeverage = new Beverage();
                            addBeverage.id = addItemInfo[0];
                            addBeverage.name = addItemInfo[1];
                            addBeverage.pack = addItemInfo[2];
                            addBeverage.price = Convert.ToDecimal(addItemInfo[3]);
                            addBeverage.active = Convert.ToBoolean(addItemInfo[4]);

                            //Add the beverage to the database
                            beverageACullenEntities.Beverages.Add(addBeverage);
                            beverageACullenEntities.SaveChanges();
                            userInterface.DisplayAddItemSuccess();
                            userInterface.DisplayItem(addBeverage);

                        }
                        else
                        {
                            userInterface.DisplayItemAlreadyExistsError();
                        }
                        break;

                    case 4:
                        //Update a beverage item in the database

                        //Get search item ID from user
                        string updateQuery = userInterface.GetSearchQuery();

                        //Find the item by its ID
                        Beverage updateBeverage = beverageACullenEntities.Beverages.Find(updateQuery);

                        //If found...
                        if (updateBeverage != null)
                        {
                            //Display the item and directions for user reference
                            userInterface.DisplayItemFound();
                            userInterface.DisplayItem(updateBeverage);
                            userInterface.DisplayUpdateDirections();

                            //get updated values from user
                            string[] updateItemInfo = userInterface.GetItemInformation(true, updateBeverage.id);
                            updateBeverage.name = updateItemInfo[1];
                            updateBeverage.pack = updateItemInfo[2];
                            updateBeverage.price = Convert.ToDecimal(updateItemInfo[3]);
                            updateBeverage.active = Convert.ToBoolean(updateItemInfo[4]);

                            beverageACullenEntities.SaveChanges();

                            userInterface.DisplayUpdateSuccess();
                            userInterface.DisplayItem(updateBeverage);

                        }
                        else //if not found...
                        {
                            userInterface.DisplayItemFoundError();
                        }
                        break;

                    case 5:
                        //Delete beverage from database
                        string deleteQuery = userInterface.GetSearchQuery();
                        Beverage deleteBeverage = beverageACullenEntities.Beverages.Find(deleteQuery);

                        if (deleteBeverage != null)
                        {
                            userInterface.DisplayItemFound();
                            userInterface.DisplayItem(deleteBeverage);

                            beverageACullenEntities.Beverages.Remove(deleteBeverage);
                            beverageACullenEntities.SaveChanges();

                            userInterface.DisplayDeleteMessage();

                        }
                        else
                        {
                            userInterface.DisplayItemFoundError();
                        }

                        break;
                }

                //Get the new choice of what to do from the user
                choice = userInterface.DisplayMenuAndGetResponse();
            }
        }
Exemplo n.º 10
0
        static void Main(string[] args)
        {
            //Set a constant for the size of the collection
            const int wineItemCollectionSize = 4000;

            //Set a constant for the path to the CSV File
            const string pathToCSVFile = "../../../datafiles/winelist.csv";

            //Create an instance of the UserInterface class
            UserInterface userInterface = new UserInterface();

            //Create an instance of the WineItemCollection class
            IWineCollection wineItemCollection = new WineItemCollection(wineItemCollectionSize);

            //Create an instance of the CSVProcessor class
            CSVProcessor csvProcessor = new CSVProcessor();

            //Display the Welcome Message to the user
            userInterface.DisplayWelcomeGreeting();

            //Display the Menu and get the response. Store the response in the choice integer
            //This is the 'primer' run of displaying and getting.
            int choice = userInterface.DisplayMenuAndGetResponse();

            while (choice != 5)
            {
                switch (choice)
                {
                    case 1:
                        //Load the CSV File
                        bool success = csvProcessor.ImportCSV(wineItemCollection, pathToCSVFile);
                        if (success)
                        {
                            //Display Success Message
                            userInterface.DisplayImportSuccess();
                        }
                        else
                        {
                            //Display Fail Message
                            userInterface.DisplayImportError();
                        }
                        break;

                    case 2:
                        //Print Entire List Of Items
                        string[] allItems = wineItemCollection.GetPrintStringsForAllItems();
                        if (allItems.Length > 0)
                        {
                            //Display all of the items
                            userInterface.DisplayAllItems(allItems);
                        }
                        else
                        {
                            //Display error message for all items
                            userInterface.DisplayAllItemsError();
                        }
                        break;

                    case 3:
                        //Search For An Item
                        string searchQuery = userInterface.GetSearchQuery();
                        string itemInformation = wineItemCollection.FindById(searchQuery);
                        if (itemInformation != null)
                        {
                            userInterface.DisplayItemFound(itemInformation);
                        }
                        else
                        {
                            userInterface.DisplayItemFoundError();
                        }
                        break;

                    case 4:
                        //Add A New Item To The List
                        string[] newItemInformation = userInterface.GetNewItemInformation();
                        if (wineItemCollection.FindById(newItemInformation[0]) == null)
                        {
                            wineItemCollection.AddNewItem(newItemInformation[0], newItemInformation[1], newItemInformation[2]);
                            userInterface.DisplayAddWineItemSuccess();
                        }
                        else
                        {
                            userInterface.DisplayItemAlreadyExistsError();
                        }
                        break;
                }

                //Get the new choice of what to do from the user
                choice = userInterface.DisplayMenuAndGetResponse();
            }
        }
Exemplo n.º 11
0
        static void Main(string[] args)
        {
            //Creates a new connection to the Database
            BeverageJKoehlerEntities bevEntities = new BeverageJKoehlerEntities();

            //Create an instance of the UserInterface class
            UserInterface userInterface = new UserInterface();

            //Create an instance of the WineItemCollection class
            IWineCollection wineItemCollection = new WineItemCollection(bevEntities);


            //Display the Welcome Message to the user
            userInterface.DisplayWelcomeGreeting();

            //Display the Menu and get the response. Store the response in the choice integer
            //This is the 'primer' run of displaying and getting.
            int choice = userInterface.DisplayMenuAndGetResponse();

            while (choice != 7)
            {
                switch (choice)
                {
                case 1:
                    //Check the Database Connection.

                    if (bevEntities != null)
                    {
                        //Display Success Message
                        userInterface.DisplayImportSuccess();
                    }
                    else
                    {
                        //Display Fail Message
                        userInterface.DisplayImportError();
                    }
                    break;

                case 2:
                    //Print Entire List Of Items
                    string[] allItems = wineItemCollection.GetPrintStringsForAllItems();
                    if (allItems.Length > 0)
                    {
                        //Display all of the items
                        userInterface.DisplayAllItems(allItems);
                    }
                    else
                    {
                        //Display error message for all items
                        userInterface.DisplayAllItemsError();
                    }
                    break;

                case 3:
                    //Search For An Item
                    string searchQuery     = userInterface.GetSearchQuery();
                    string itemInformation = wineItemCollection.FindById(searchQuery);
                    if (itemInformation != null)
                    {
                        userInterface.DisplayItemFound(itemInformation);
                    }
                    else
                    {
                        userInterface.DisplayItemFoundError();
                    }
                    break;

                case 4:
                    //Add A New Item To The List
                    string[] newItemInformation = userInterface.GetNewItemInformation();
                    if (wineItemCollection.FindById(newItemInformation[0]) == null)
                    {
                        wineItemCollection.AddNewItem(newItemInformation[0], newItemInformation[1], newItemInformation[2], newItemInformation [3],
                                                      newItemInformation[4]);
                        userInterface.DisplayAddWineItemSuccess();
                    }
                    else
                    {
                        userInterface.DisplayItemAlreadyExistsError();
                    }
                    break;

                //Update an existing item in the database
                case 5:
                    string[] updatedItemInformation = userInterface.GetNewItemInformation();
                    if (wineItemCollection.FindById(updatedItemInformation[0]) == null)
                    {
                        userInterface.DisplayItemFoundError();
                    }
                    else
                    {
                        wineItemCollection.UpdateItem(updatedItemInformation[0], updatedItemInformation[1], updatedItemInformation[2],
                                                      updatedItemInformation[3], updatedItemInformation[4]);
                    }
                    break;

                //Remove an existing item from the database
                case 6:
                    string itemToRemove = userInterface.DisplayItemRemovalDialogue();

                    wineItemCollection.RemoveItem(itemToRemove);

                    break;
                }

                //Get the new choice of what to do from the user
                choice = userInterface.DisplayMenuAndGetResponse();
            }
        }
Exemplo n.º 12
0
        static void Main(string[] args)
        {
            //Change Height and width of console to fit everything
            Console.SetWindowSize(200, 50);

            //Create an instance of the UserInterface class
            UserInterface userInterface = new UserInterface();

            //Create an instance of the RepositoryAPI
            RepositoryAPI repositoryApi = new RepositoryAPI();

            //Display the Welcome Message to the user
            userInterface.DisplayWelcomeGreeting();

            //Display the Menu and get the response. Store the response in the choice integer
            //This is the 'primer' run of displaying and getting.
            int choice = userInterface.DisplayMenuAndGetResponse();

            while (choice != 7)
            {
                switch (choice)
                {
                case 1:
                    userInterface.DisplayImportSuccess();
                    break;

                case 2:
                    //Print Entire List Of Items
                    string[] allItems = repositoryApi.GetPrintStringsForAllItems();
                    if (allItems.Length > 0)
                    {
                        //Display all of the items
                        userInterface.DisplayAllItems(allItems);
                    }
                    else
                    {
                        //Display error message for all items
                        userInterface.DisplayAllItemsError();
                    }
                    break;

                case 3:
                    //Search For An Item
                    string searchQuery     = userInterface.GetSearchQuery();
                    string itemInformation = repositoryApi.FindById(searchQuery);
                    if (itemInformation != null)
                    {
                        userInterface.DisplayItemFound(itemInformation);
                    }
                    else
                    {
                        userInterface.DisplayItemFoundError();
                    }
                    break;

                case 4:
                    //Add A New Item To The List

                    string[] newItem = userInterface.GetNewItemInformation();

                    decimal price = Convert.ToDecimal(newItem[3]);

                    //Boolean to hold if item is active
                    bool active = false;

                    //If the user inputs Y for active the active boolean is set to true
                    if (newItem[4] == "Y")
                    {
                        active = true;
                    }

                    //Send information to RepositoryAPI to add new item
                    if (repositoryApi.AddNewItem(newItem[0], newItem[1], newItem[2], price, active))
                    {
                        userInterface.DisplayAddWineItemSuccess();
                    }
                    else
                    {
                        userInterface.DisplayItemAlreadyExistsError();
                    }
                    break;

                case 5:

                    //Update item
                    string idToUpdate = userInterface.GetIdToUpdate();

                    if (repositoryApi.UpdateItem(idToUpdate))
                    {
                        userInterface.DisplayItemUpdateSuccess();
                    }
                    else
                    {
                        userInterface.DisplayItemUpdateFailure();
                    }
                    break;

                case 6:
                    //Delete item
                    string idToDelete = userInterface.GetIdToDelete();

                    if (repositoryApi.DeleteItem(idToDelete))
                    {
                        userInterface.DisplayItemDeleteSuccess();
                    }
                    else
                    {
                        userInterface.DisplayItemDeleteFailure();
                    }
                    break;
                }

                //Get the new choice of what to do from the user
                choice = userInterface.DisplayMenuAndGetResponse();
            }
        }
Exemplo n.º 13
0
        static void Main(string[] args)
        {
            //Set a constant for the size of the collection
            const int wineItemCollectionSize = 4000;

            //Create an instance of the UserInterface class
            UserInterface userInterface = new UserInterface();

            //Create an instance of the WineItemCollection class
            IWineCollection wineItemCollection = new WineItemCollection(wineItemCollectionSize);

            //Get access to the collection of tables
            BeverageBCampbellEntities beverageEntities = new BeverageBCampbellEntities();

            //Display the Welcome Message to the user
            userInterface.DisplayWelcomeGreeting();

            //Display the Menu and get the response. Store the response in the choice integer
            //This is the 'primer' run of displaying and getting.
            int choice = userInterface.DisplayMenuAndGetResponse();

            while (choice != 7)
            {
                switch (choice)
                {
                case 1:
                    //Load the CSV File
                    //bool success = csvProcessor.ImportCSV(wineItemCollection, pathToCSVFile);
                    bool success;

                    try
                    {
                        foreach (Beverage bev in beverageEntities.Beverages)
                        {
                            wineItemCollection.AddNewItem(bev.id, bev.name, bev.pack);
                        }
                        success = true;
                    }
                    catch
                    {
                        success = false;
                    }

                    if (success)
                    {
                        //Display Success Message
                        userInterface.DisplayImportSuccess();
                    }
                    else
                    {
                        //Display Fail Message
                        userInterface.DisplayImportError();
                    }
                    break;

                case 2:
                    //Print Entire List Of Items
                    string[] allItems = wineItemCollection.GetPrintStringsForAllItems();
                    if (allItems.Length > 0)
                    {
                        //Display all of the items
                        userInterface.DisplayAllItems(allItems);
                    }
                    else
                    {
                        //Display error message for all items
                        userInterface.DisplayAllItemsError();
                    }
                    break;

                case 3:
                    //Search For An Item
                    string searchQuery     = userInterface.GetSearchQuery();
                    string itemInformation = wineItemCollection.FindById(searchQuery);
                    if (itemInformation != null)
                    {
                        userInterface.DisplayItemFound(itemInformation);
                    }
                    else
                    {
                        userInterface.DisplayItemFoundError();
                    }
                    break;

                case 4:
                    //Add A New Item To The List
                    //ID Description Pack
                    string[] newItemInformation = userInterface.GetNewItemInformation();
                    if (wineItemCollection.FindById(newItemInformation[0]) == null)
                    {
                        wineItemCollection.AddNewItem(newItemInformation[0], newItemInformation[1], newItemInformation[2]);
                        userInterface.DisplayAddWineItemSuccess();
                    }
                    else
                    {
                        userInterface.DisplayItemAlreadyExistsError();
                    }
                    break;

                case 5:
                    //Update an existing item
                    searchQuery     = userInterface.GetSearchQuery();
                    itemInformation = wineItemCollection.FindById(searchQuery);
                    if (itemInformation != null)
                    {
                        userInterface.DisplayItemFound(itemInformation);
                        string[] replaceItemInformation = userInterface.GetNewItemInformation();
                        wineItemCollection.Overwrite(searchQuery, replaceItemInformation[0], replaceItemInformation[1], replaceItemInformation[2]);
                    }
                    else
                    {
                        userInterface.DisplayItemFoundError();
                    }


                    break;

                case 6:
                    //Delete an existing item
                    searchQuery = userInterface.GetSearchQuery();
                    wineItemCollection.Delete(searchQuery);
                    break;
                }

                //Get the new choice of what to do from the user
                choice = userInterface.DisplayMenuAndGetResponse();
            }
        }