示例#1
0
        internal void EditRoom()
        {
            int roomCount = roomController.RoomCount();

            if (roomCount > 0)
            {
                Console.WriteLine("Please enter only one room name as displayed below");
                DisplayRoom();
                Console.Write("> ");
                var roomNameToChange = Console.ReadLine();
                while (roomController.SearchRoom(roomNameToChange) == null)
                {
                    Console.WriteLine("Sorry! The room you wanna edit does not exist. Try again!");
                    Console.Write("> ");
                    roomNameToChange = Console.ReadLine();
                }
                Room oldRoom = roomController.SearchRoom(roomNameToChange);
                Console.Write("You will change old name \"{0}\" to new name or press [Enter] to unchange: ", oldRoom.RoomNo);
                string updatedName = Console.ReadLine();
                if (updatedName == "")
                {
                    updatedName = oldRoom.RoomNo;
                }
                // Keep old name of room to modify if it happens error during updating
                string name = oldRoom.RoomNo;

                // Delete course to edit by its id
                roomController.DeleteRoom(roomNameToChange);

                if (roomController.UpdateRoom(updatedName))
                {
                    Console.WriteLine("You updated new information for room name: " + updatedName);
                }
                else
                {
                    // this condition will run if update name duplicate with other room name
                    roomController.CreateRoom(name);
                    Console.WriteLine("You failed to update new information for room name: " + name);
                    Console.WriteLine();
                }
            }
            else
            {
                Console.WriteLine("Opp! empty room list. You should use selection 1 to add a room.");
            }
            Console.WriteLine("Press[Enter] button to continue...");
            Console.ReadLine();
        }
示例#2
0
        private ClassPeriod CreateClassPeriod()
        {
            ClassPeriod classPeriod = null;

            Console.WriteLine();
            Console.WriteLine("\t\tRoom List\t\t");
            rmv.DisplayRoom();
            Console.Write("\nEnter room name: ");
            string roomName = Console.ReadLine();
            Room   room     = roomController.SearchRoom(roomName);

            while (roomController.SearchRoom(roomName) == null)
            {
                Console.Write("\nThis room never exists. Enter room id: ");
                roomName = Console.ReadLine();
            }

            Console.Write("\nEnter a day of week(Monday - Friday): ");
            string dayOfWeek = Console.ReadLine();

            dayOfWeek = dayOfWeek.ToLower();
            while (!Validate.ValidWeekDayString(dayOfWeek))
            {
                Console.Write("\nInvalid day of week. Please enter again(Monday - Friday): ");
                dayOfWeek = Console.ReadLine();
            }
            dayOfWeek = dayOfWeek.ToLower();
            bool isLogic = false;

            while (!isLogic)
            {
                try
                {
                    Console.Write("\nEnter start time class(HH:MM)\nTime must satisfy block of 30 minutes: ");
                    var      st        = Console.ReadLine();
                    DateTime startTime = DateTime.Parse(st);
                    while (!Validate.ValidMinute(st))
                    {
                        Console.WriteLine("Please follow format(HH:MM) and block of 30 minutes(eg. 9:30)");
                        Console.Write("> ");
                        st        = Console.ReadLine();
                        startTime = DateTime.Parse(st);
                    }

                    Console.Write("\nEnter end time class(HH:MM)\nTime must satisfy block of 30 minutes: ");
                    var      et      = Console.ReadLine();
                    DateTime endTime = DateTime.Parse(et);
                    while (!Validate.ValidMinute(et))
                    {
                        Console.WriteLine("Please follow format(HH:MM) and block of 30 minutes(eg. 9:30)");
                        Console.Write("> ");
                        et      = Console.ReadLine();
                        endTime = DateTime.Parse(et);
                    }
                    if (classController.ValidateClassTime(startTime, endTime))
                    {
                        classPeriod = new ClassPeriod(room, dayOfWeek, startTime, endTime);
                        isLogic     = true;
                        //return classPeriod;
                    }
                    else
                    {
                        Console.WriteLine("*************** Instruction *********************");
                        Console.WriteLine("Start time or end time you entered was not logic.");
                        Console.WriteLine("Minimun start time must be 8:00");
                        Console.WriteLine("Maximun start time must be 17:30");
                        Console.WriteLine("Minimun end time must be 8:30");
                        Console.WriteLine("Minimun end time must be 18:00");
                        Console.WriteLine("Start time must be earlier than end time.");
                        Console.WriteLine("*************************************************");
                    }
                }
                catch (Exception)
                {
                    isLogic = false;
                }
            }
            return(classPeriod);
            //return classPeriod;
        }