예제 #1
0
        public void ViewSchedules()
        {
            while (true)
            {
                Console.Clear();
                if (this.GetSchedules().Count() == 0)
                {
                    Console.WriteLine("There are no schedules for this project.");
                    Console.WriteLine("If you would like to add a schedule, press 'c'\nElse, press any other key");
                    string key = Console.ReadLine();
                    if (key == "c")
                    {
                        ISchedule newSchedule = new Schedule();
                        newSchedule.CreateSchedule(this);
                        this.AddSchedule(newSchedule);
                    }
                    return;
                }

                int scheduleCount = this.DisplaySchedules();
                Console.WriteLine("Enter 1 if you would like to edit a schedule.");
                Console.WriteLine("Enter 2 if you would like to delete a schedule.");

                Console.WriteLine("Enter 0 to return to the menu");
                string response = Console.ReadLine();
                int    choice   = int.Parse(response);

                if (choice == 0)
                {
                    return;
                }
                else if (choice == 1 || choice == 2)
                {
                    Console.Clear();
                    scheduleCount = this.DisplaySchedules();
                    if (choice == 1)
                    {
                        Console.WriteLine("Enter the number of the project to edit.");
                    }
                    if (choice == 2)
                    {
                        Console.WriteLine("Enter the number of the project to delete.");
                    }

                    response = Console.ReadLine();
                    int.TryParse(response, out int op);


                    if (op <= scheduleCount)
                    {
                        op--;
                        ISchedule schedule = this.schedules[op];

                        if (choice == 2)
                        {
                            this.RemoveSchedule(schedule);
                        }
                        else
                        {
                            int choice2 = 0;
                            do
                            {
                                Console.Clear();
                                Console.WriteLine("Editing Schedule: {0}", schedule.GetName());
                                Console.WriteLine("\n\n1. Edit Name");
                                Console.WriteLine("2. Edit Description");
                                Console.WriteLine("3. Edit Start Date");
                                Console.WriteLine("4. Edit End Date");
                                Console.WriteLine("5. Edit Hours Needed");
                                Console.WriteLine("9. Exit");

                                response = Console.ReadLine();
                                choice2  = int.Parse(response);

                                switch (choice2)
                                {
                                case 1:
                                    Console.WriteLine("Editing Schedule name");
                                    Console.WriteLine("Current Name: {0}", schedule.GetName());
                                    Console.Write("New Name: ");
                                    string newName = Console.ReadLine();
                                    schedule.SetName(newName);
                                    Console.WriteLine("Done.");
                                    break;

                                case 2:
                                    Console.WriteLine("Editing Schedule Description.");
                                    Console.WriteLine("Current Description: {0}", schedule.GetDescription());
                                    Console.Write("New Description: ");
                                    string newDescription = Console.ReadLine();
                                    schedule.SetDescription(newDescription);
                                    Console.WriteLine("Done.");
                                    break;

                                case 3:
                                    Console.WriteLine("Editing Start Date");
                                    Console.WriteLine("Current Start Date: {0}", schedule.GetStartDate().Date);
                                    Console.Write("New Start Date (MM-DD-YYYY): ");
                                    string input = Console.ReadLine();
                                    schedule.SetStartDate(input);
                                    Console.WriteLine("Done.");
                                    break;

                                case 4:
                                    Console.WriteLine("Editing End Date");
                                    Console.WriteLine("Current End Date: {0}", schedule.GetEndDate().Date);
                                    Console.Write("New End Date (MM-DD-YYYY): ");
                                    input = Console.ReadLine();
                                    schedule.SetEndDate(input);
                                    Console.WriteLine("Done.");
                                    break;

                                case 5:
                                    Console.WriteLine("Editing Hours Needed");
                                    Console.WriteLine("Current Hours Needed: {0}", schedule.GetHoursNeeded());
                                    Console.Write("New Hours Needed: ");
                                    input = Console.ReadLine();
                                    schedule.SetHoursNeeded(input);

                                    // updating total hours and percent complete too
                                    schedule.UpdateTotalHours();
                                    schedule.UpdatePercentComplete();

                                    Console.WriteLine("Done.");
                                    break;

                                case 9:
                                    break;

                                default:
                                    Console.WriteLine("Invalid selection, try again.");
                                    choice2 = 0;
                                    break;
                                }
                            } while (choice2 != 9);
                        }
                    }
                }
            }
        }