示例#1
0
        private static void DisplaySkiRunDetail()
        {
            SkiRunBusiness skiRunBusiness = new SkiRunBusiness(skiRunRepository);

            List <SkiRun> skiRuns;
            SkiRun        skiRun;
            int           skiRunID;

            using (skiRunBusiness)
            {
                skiRuns  = skiRunBusiness.SelectAll();
                skiRunID = ConsoleView.GetSkiRunID(skiRuns);
                skiRun   = skiRunBusiness.SelectById(skiRunID);
            }

            ConsoleView.DisplaySkiRun(skiRun);
            ConsoleView.DisplayContinuePrompt();
        }
示例#2
0
        private static void QuerySkiRunsByVertical()
        {
            SkiRunRepositoryXML_DS skiRunRepository = new SkiRunRepositoryXML_DS();
            List <SkiRun>          matchingSkiRuns  = new List <SkiRun>();

            int minimumVertical;
            int maximumVertical;

            ConsoleView.GetVerticalQueryMinMaxValues(out minimumVertical, out maximumVertical);

            using (skiRunRepository)
            {
                matchingSkiRuns = skiRunRepository.QueryByVertical(minimumVertical, maximumVertical);
            }

            ConsoleView.DisplayQueryResults(matchingSkiRuns);
            ConsoleView.DisplayContinuePrompt();
        }
示例#3
0
 /// <summary>
 /// Handles errors for File I/O operations.
 /// </summary>
 /// <param name="exc"></param>
 private static void CatchIOExceptions(Exception exc)
 {
     if (exc is DriveNotFoundException)
     {
         //Display the error message on the screen.
         ConsoleView.DisplayErrorMessage(exc.Message.ToString());
         Console.ReadKey();
         return;
     }
     else if (exc is DirectoryNotFoundException)
     {
         //Display the error message on the screen.
         ConsoleView.DisplayErrorMessage(exc.Message.ToString());
         Console.ReadKey();
         return;
     }
     else if (exc is FileNotFoundException)
     {
         //Display the error message on the screen.
         ConsoleView.DisplayErrorMessage(exc.Message.ToString());
         Console.ReadKey();
         return;
     }
     else if (exc is EndOfStreamException)
     {
         //Display the error message on the screen.
         ConsoleView.DisplayErrorMessage(exc.Message.ToString());
         Console.ReadKey();
         return;
     }
     else if (exc is ArgumentException)
     {
         //Display the error message on the screen.
         ConsoleView.DisplayErrorMessage(exc.Message.ToString());
         Console.ReadKey();
         return;
     }
     else if (exc is Exception)
     {
         //Display the error message on the screen.
         ConsoleView.DisplayErrorMessage(exc.Message.ToString());
         Console.ReadKey();
     }
 }
示例#4
0
        public static int ValidateIntegerResponse(string promptMessage, string userResponse)
        {
            int userResponseInteger = 0;

            while (!(int.TryParse(userResponse, out userResponseInteger)))
            {
                ConsoleView.DisplayReset();

                ConsoleView.DisplayMessage("");
                ConsoleView.DisplayMessage("It appears you have not entered a valid integer.");

                ConsoleView.DisplayMessage("");
                ConsoleView.DisplayPromptMessage(promptMessage);
                userResponse = Console.ReadLine();
            }


            return(userResponseInteger);
        }
示例#5
0
        public void DisplayQueriedVertical(List <SkiRun> matchingSkiRuns)
        {
            if (matchingSkiRuns.Count > 0)
            {
                foreach (SkiRun queriedSkiRun in matchingSkiRuns)
                {
                    StringBuilder skiRunInfo = new StringBuilder();

                    skiRunInfo.Append(queriedSkiRun.ID.ToString().PadRight(8));
                    skiRunInfo.Append(queriedSkiRun.Name.PadRight(25));
                    skiRunInfo.Append(queriedSkiRun.Vertical.ToString().PadRight(5));
                    ConsoleView.DisplayMessage(skiRunInfo.ToString());
                }
            }
            else
            {
                Console.WriteLine();
                Console.WriteLine("There were no ski runs that matched your query.");
            }
        }
示例#6
0
        /// <summary>
        /// Displays a list of all ski runs
        /// </summary>
        /// <param name="skiRunRepository"></param>
        private static void DisplaySkiRunDetail()
        {
            SkiRunBusiness skiRunBusiness = new SkiRunBusiness(skiRunRepository);

            ConsoleView.DisplayReset();
            //ConsoleView.DisplayHeader("Display Ski Run Information");
            using (skiRunBusiness)
            {
                try
                {
                    //Display the ski run information on the screen.
                    ConsoleView.DisplaySkiRunDetail(skiRunRepository.SelectById(ConsoleView.GetIntegerFromUser("Enter the ID for the Ski Run: ")));
                    ConsoleView.DisplayContinuePrompt();
                }
                catch (Exception ex)
                {
                    ConsoleView.DisplayErrorMessage(ex.Message);
                    ConsoleView.DisplayContinuePrompt();
                }
            }
        }
示例#7
0
        private static void DeleteSkiRun()
        {
            int    skiRunID;
            string message;

            SkiRunRepositoryXML_DS skiRunRepository = new SkiRunRepositoryXML_DS();
            SkiRun        skiRun  = new SkiRun();
            List <SkiRun> skiRuns = skiRunRepository.SelectAllRuns();

            skiRunID = ConsoleView.GetSkiRunID(skiRuns);

            using (skiRunRepository)
            {
                skiRunRepository.DeleteSkiRun(skiRunID);
            }

            ConsoleView.DisplayReset();
            message = String.Format("Ski Run ID: {0} had been deleted.", skiRunID);
            ConsoleView.DisplayMessage(message);
            ConsoleView.DisplayContinuePrompt();
        }
示例#8
0
        private static void UpdateSkiRun()
        {
            SkiRunRepositoryXML_DS skiRunRepository = new SkiRunRepositoryXML_DS();
            List <SkiRun>          skiRuns          = skiRunRepository.SelectAllRuns();
            SkiRun skiRun = new SkiRun();
            int    skiRunID;

            skiRunID = ConsoleView.GetSkiRunID(skiRuns);

            using (skiRunRepository)
            {
                skiRun = skiRunRepository.SelectByID(skiRunID);
            }

            skiRun = ConsoleView.UpdateSkiRun(skiRun);

            using (skiRunRepository)
            {
                skiRunRepository.UpdateSkiRun(skiRun);
            }
        }
示例#9
0
        private static void DisplaySkiRunDetail()
        {
            SkiRunRepositoryXML_DS skiRunRepository = new SkiRunRepositoryXML_DS();
            List <SkiRun>          skiRuns;
            SkiRun skiRun = new SkiRun();
            int    skiRunID;

            using (skiRunRepository)
            {
                skiRuns = skiRunRepository.SelectAllRuns();
            }
            skiRunID = ConsoleView.GetSkiRunID(skiRuns);

            using (skiRunRepository)
            {
                skiRun = skiRunRepository.SelectByID(skiRunID);
            }

            ConsoleView.DisplaySkiRun(skiRun);
            ConsoleView.DisplayContinuePrompt();
        }
示例#10
0
        private static void DeleteSkiRun()
        {
            SkiRunBusiness skiRunBusiness = new SkiRunBusiness(skiRunRepository);

            List <SkiRun> skiRuns;
            int           skiRunID;
            string        message;

            using (skiRunBusiness)
            {
                skiRuns  = skiRunBusiness.SelectAll();
                skiRunID = ConsoleView.GetSkiRunID(skiRuns);
                skiRunBusiness.Delete(skiRunID);
            }

            ConsoleView.DisplayReset();

            // TODO refactor to confirm
            message = String.Format("Ski Run ID: {0} had been deleted.", skiRunID);

            ConsoleView.DisplayMessage(message);
            ConsoleView.DisplayContinuePrompt();
        }
示例#11
0
        /// <summary>
        /// Deletes a record from the data source using the ID value entered by the user
        /// </summary>
        /// <param name="skiRunRepository"></param>
        /// <param name="skiRuns"></param>
        private static void DeleteSkiRun()
        {
            SkiRunBusiness skiRunBusiness = new SkiRunBusiness(skiRunRepository);
            List <SkiRun>  skiRuns        = skiRunRepository.SelectAll();
            //Variable declarations.
            int skiRunID = 0;

            //reset display
            ConsoleView.DisplayReset();
            using (skiRunBusiness)
            {
                //Display all ski runs.
                ConsoleView.DisplayAllSkiRuns(skiRuns, false);
                Console.WriteLine();
                Console.WriteLine();

                //Get the ID for the ski run from the user.
                skiRunID = ConsoleView.GetIntegerFromUser("Enter Ski Run ID to delete: ");

                try
                {
                    //Delete the ski run entered.
                    skiRunRepository.Delete(skiRunID);

                    //Display a message to the user that the ski run has been deleted.
                    ConsoleView.DisplayReset();
                    ConsoleView.DisplayMessage($"Ski Run ID: {skiRunID} had been deleted.");
                    ConsoleView.DisplayContinuePrompt();
                }
                catch (Exception ex)
                {
                    //Display the error message for the error that occurred.
                    CatchIOExceptions(ex);
                }
            }
        }
示例#12
0
        private void ApplicationControl()
        {
            SkiRunRepositoryXML skiRunRepository = new SkiRunRepositoryXML();

            ConsoleView.DisplayWelcomeScreen();

            using (skiRunRepository)
            {
                List <SkiRun> skiRuns = skiRunRepository.GetSkiAllRuns();

                int    skiRunID;
                SkiRun skiRun;
                string message;

                while (active)
                {
                    AppEnum.ManagerAction userActionChoice;

                    userActionChoice = ConsoleView.GetUserActionChoice();

                    switch (userActionChoice)
                    {
                    case AppEnum.ManagerAction.None:
                        break;

                    case AppEnum.ManagerAction.ListAllSkiRuns:
                        ConsoleView.DisplayAllSkiRuns(skiRuns);

                        ConsoleView.DisplayContinuePrompt();
                        break;

                    case AppEnum.ManagerAction.DisplaySkiRunDetail:
                        skiRunID = ConsoleView.GetSkiRunID(skiRuns);
                        skiRun   = skiRunRepository.GetSkiRunByID(skiRunID);

                        ConsoleView.DisplaySkiRun(skiRun);
                        ConsoleView.DisplayContinuePrompt();
                        break;

                    case AppEnum.ManagerAction.AddSkiRun:
                        skiRun = ConsoleView.AddSkiRun();
                        skiRunRepository.InsertSkiRun(skiRun);

                        ConsoleView.DisplayContinuePrompt();
                        break;

                    case AppEnum.ManagerAction.UpdateSkiRun:
                        skiRunID = ConsoleView.GetSkiRunID(skiRuns);
                        skiRun   = skiRunRepository.GetSkiRunByID(skiRunID);

                        skiRun = ConsoleView.UpdateSkiRun(skiRun);

                        skiRunRepository.UpdateSkiRun(skiRun);
                        break;

                    case AppEnum.ManagerAction.DeleteSkiRun:
                        skiRunID = ConsoleView.GetSkiRunID(skiRuns);
                        skiRunRepository.DeleteSkiRun(skiRunID);

                        ConsoleView.DisplayReset();
                        message = String.Format("Ski Run ID: {0} had been deleted.", skiRunID);
                        ConsoleView.DisplayMessage(message);
                        ConsoleView.DisplayContinuePrompt();
                        break;

                    case AppEnum.ManagerAction.QuerySkiRunsByVertical:
                        List <SkiRun> matchingSkiRuns = new List <SkiRun>();

                        int minimumVertical;
                        int maximumVertical;
                        ConsoleView.GetVerticalQueryMinMaxValues(out minimumVertical, out maximumVertical);

                        matchingSkiRuns = skiRunRepository.QueryByVertical(minimumVertical, maximumVertical);

                        ConsoleView.DisplayQueryResults(matchingSkiRuns);
                        ConsoleView.DisplayContinuePrompt();
                        break;

                    case AppEnum.ManagerAction.Quit:
                        active = false;
                        break;

                    default:
                        break;
                    }
                }
            }

            ConsoleView.DisplayExitPrompt();
        }
示例#13
0
        private void ApplicationControl()
        {
            SkiRunRepository skiRunRepository = new SkiRunRepository();

            ConsoleView.DisplayWelcomeScreen();

            using (skiRunRepository)
            {
                List <SkiRun> skiRuns = skiRunRepository.GetSkiAllRuns();

                while (active)
                {
                    AppEnum.ManagerAction userActionChoice;
                    int           vertical;
                    int           skiRunID;
                    SkiRun        skiRun;
                    string        skiRunString;
                    List <SkiRun> ski2 = new List <SkiRun>();

                    userActionChoice = ConsoleView.GetUserActionChoice();

                    switch (userActionChoice)
                    {
                    case AppEnum.ManagerAction.None:
                        break;

                    case AppEnum.ManagerAction.ListAllSkiRuns:
                        ConsoleView.DisplayAllSkiRuns(skiRuns);
                        ConsoleView.DisplayContinuePrompt();
                        break;

                    case AppEnum.ManagerAction.DisplaySkiRunDetail:
                        ConsoleView.DisplayAllSkiRuns(skiRuns);
                        ski2 = skiRunRepository.GetSkiRunByID(ConsoleView.DisplayGetSkiRunIDChoice(skiRuns));
                        ConsoleView.DisplaySkiRunDetails(ski2);
                        ConsoleView.DisplayContinuePrompt();

                        break;

                    case AppEnum.ManagerAction.DeleteSkiRun:
                        skiRunRepository.DeleteSkiRun(ConsoleView.DisplayGetSkiRunIDChoice(skiRuns));
                        ConsoleView.DisplayReset();
                        ConsoleView.DisplayMessage("Ski Run has been deleted.");
                        ConsoleView.DisplayContinuePrompt();
                        break;

                    case AppEnum.ManagerAction.AddSkiRun:

                        skiRun          = new SkiRun();
                        skiRun.ID       = ConsoleView.DisplayGetSkiRunID();
                        skiRun.Name     = ConsoleView.DisplayGetSkiRunName();
                        skiRun.Vertical = ConsoleView.DisplayGetSkiRunVertical();
                        skiRunRepository.InsertSkiRun(skiRun);
                        ConsoleView.DisplayAllSkiRuns(skiRuns);
                        ConsoleView.DisplayNewSkiRunMessage();

                        break;

                    case AppEnum.ManagerAction.UpdateSkiRun:

                        skiRun    = new SkiRun();
                        skiRun.ID = ConsoleView.DisplayGetSkiRunIDChoice(skiRuns);
                        skiRunRepository.UpdateSkiRun(skiRun);

                        Console.WriteLine();

                        break;

                    case AppEnum.ManagerAction.QuerySkiRunsByVertical:
                        int minimumVertical = skiRunRepository.GetMinimumVertical();
                        int maximumVertical = skiRunRepository.GetMaximumVertical();

                        //Sorts all the available entries and pushes out those that match into a new list.
                        List <SkiRun> matchingSkiRuns = skiRunRepository.QueryByVertical(minimumVertical, maximumVertical);
                        ConsoleView.DisplayReset();

                        //Displays the new list.
                        Console.WriteLine("Ski Runs with a vertical between " + minimumVertical + " and " + maximumVertical + ".");
                        skiRunRepository.DisplayQueriedVertical(matchingSkiRuns);
                        ConsoleView.DisplayContinuePrompt();
                        break;

                    case AppEnum.ManagerAction.Quit:
                        active = false;
                        break;

                    default:
                        break;
                    }
                }
            }

            ConsoleView.DisplayExitPrompt();
        }
示例#14
0
        private void ApplicationControl()
        {
            SkiRunRepository skiRunRepository = new SkiRunRepository();

            ConsoleView.DisplayWelcomeScreen();

            using (skiRunRepository)
            {
                List <SkiRun> skiRuns = skiRunRepository.GetSkiAllRuns();

                while (active)
                {
                    AppEnum.ManagerAction userActionChoice;

                    int    skiRunID = 1;
                    SkiRun skiRun   = new SkiRun();
                    string message;

                    userActionChoice = ConsoleView.GetUserActionChoice();

                    switch (userActionChoice)
                    {
                    case AppEnum.ManagerAction.None:
                        break;

                    case AppEnum.ManagerAction.ListAllSkiRuns:
                        ConsoleView.DisplayAllSkiRuns(skiRuns);
                        ConsoleView.DisplayContinuePrompt();
                        break;

                    case AppEnum.ManagerAction.DisplaySkiRunDetail:
                        ConsoleView.GetSkiRunID(skiRuns);
                        skiRunRepository.GetSkiRunByID(skiRunID);
                        break;

                    case AppEnum.ManagerAction.DeleteSkiRun:
                        ConsoleView.GetSkiRunID(skiRuns);
                        skiRunRepository.DeleteSkiRun(skiRunID);
                        ConsoleView.DisplayReset();
                        ConsoleView.DisplayMessage($"Ski Run ID:" + skiRunID + "has been deleted.");
                        ConsoleView.DisplayContinuePrompt();
                        break;

                    case AppEnum.ManagerAction.AddSkiRun:
                        ConsoleView.DisplayReset();
                        ConsoleView.GetAddSkiRun(skiRun);
                        skiRunRepository.InsertSkiRun(skiRun);

                        break;

                    case AppEnum.ManagerAction.UpdateSkiRun:
                        break;

                    case AppEnum.ManagerAction.QuerySkiRunsByVertical:

                        break;

                    case AppEnum.ManagerAction.Quit:
                        active = false;
                        break;

                    default:
                        break;
                    }
                }
            }

            ConsoleView.DisplayExitPrompt();
        }