예제 #1
0
 static void Main(string[] args)
 {
     //Initializes Each of the other classes
     EntityProcessor onlyRunOneCSVProcessor = new EntityProcessor(upPath(3,Environment.CurrentDirectory) + "\\datafiles\\WineList.csv");
     BeverageCollection theWineCollection = new BeverageCollection(onlyRunOneCSVProcessor);
     controlClass controlTheProgram = new controlClass(theWineCollection, onlyRunOneCSVProcessor);
     //repeats the ui
     while(true)
     {
         controlTheProgram.PrintPrompt();
     }
 }
예제 #2
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();
            }
        }
예제 #3
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();
            }
        }
예제 #4
0
        static void Main(string[] args)
        {
            //Set a constant for the size of the collection
            const int wineItemCollectionSize = 4000;
            // path to BevCollection class
            BeverageCollection dbBev = new BeverageCollection();
            // path to bev item class
            BeverageItem beverageItem = new BeverageItem();
            //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 != 6)
            {
                switch (choice)
                {
                    case 111:
                        //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 112:
                        //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 113:
                        //Search For An Item
                        string searchQuery = userInterface.GetSearchQuery();
                        string itemInformation = wineItemCollection.FindById(searchQuery);
                        if (itemInformation != null)
                        {
                            userInterface.DisplayItemFound(itemInformation);
                        }
                        else
                        {
                            userInterface.DisplayItemFoundError();
                        }
                        break;

                    case 114:
                        //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;

                    case 1:
                        // calls print method
                        dbBev.printBeverage();
                        break;

                    case 2:
                        // calls add method
                        dbBev.AddBeverage();
                        break;
                    case 3:
                        // calls search method
                        dbBev.SearchBeverage();
                        break;
                    case 4:
                        // calls update method
                        beverageItem.UpdateBeverge();
                        break;
                    case 5:
                        //calls delte method
                        beverageItem.DeleteBeverage();
                        break;

                }

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