Example #1
0
        public void RunClassAdmin()
        {
            int choice;
            Console.WriteLine ("||||||||||||||||||| Class Control |||||||||||||||||||");
            bool cont = true;
            while (cont) {
                try {
                    Console.WriteLine ("1 - Add Class");
                    Console.WriteLine ("2 - Modify Class");
                    Console.WriteLine ("3 - List Class");
                    Console.WriteLine ("4 - Quit");
                    choice = Convert.ToInt32 (Console.ReadLine ());
                    Console.Clear ();
                    switch (choice) {
                    case 1:
                        {
                            Console.Write ("Course ID: ");
                            string cid = Console.ReadLine ();
                            if (courseAdmin.CheckUniqueID (cid)) {
                                throw new Exception ("Course ID not Existed");

                            }
                            Console.Write ("Lecturer ID: ");
                            string lid = Console.ReadLine ();
                            if (lecturerAdmin.CheckUniqueID (lid)) {
                                throw new Exception ("Lecturer ID not Existed");
                            }

                            classAdmin.Adds (new Class (lid, cid));
                            break;
                        }
                    case 2:
                        {
                            classAdmin.List ();
                            String timeFormat = "^([0][8-9]|[1][0-8]):(00|30)$";
                            Console.Write ("Class index: ");
                            int cid = Convert.ToInt32 (Console.ReadLine ());
                            Class cla = classAdmin.GetClassFromIndex (cid);
                            Console.WriteLine ("Old value: " + ((cla).ToString ()));

                            Console.WriteLine ("1 - Modify Lecturer ID");
                            Console.WriteLine ("2 - Modify Course ID");
                            Console.WriteLine ("3 - Add class period to class");
                            string newValue;
                            int modifychoice = Convert.ToInt32 (Console.ReadLine ());
                            Console.Clear ();
                            switch (modifychoice) {

                            case 1:
                                {
                                    Console.Write ("New Lecturer ID value: ");
                                    newValue = Console.ReadLine ();
                                    cla.LecturerID = newValue;
                                    break;
                                }
                            case 2:
                                {
                                    Console.Write ("New Course ID value: ");
                                    newValue = Console.ReadLine ();
                                    cla.CourseID = newValue;
                                    break;
                                }
                            case 3:
                                {
                                    Converter conv = new Converter ();
                                    roomAdmin.List ();
                                    Console.Write ("Choose A room by index");

                                    int chosenRoom = Convert.ToInt32 (Console.ReadLine ());
                                    Room cr = roomAdmin.GetRoomFromIndex (chosenRoom);

                                    Console.Write ("Week day: ");
                                    string cd = Console.ReadLine ();
                                    Match match;
                                    double st=0;
                                    while (true) {
                                        Console.Write ("Start time HH:MM");
                                        string sstime = Console.ReadLine ();
                                        match = Regex.Match (sstime, timeFormat);
                                        if (match.Success) {
                                            st = conv.s2d (sstime);
                                            break;
                                        }
                                    }

                                    double et=0;
                                    while (true) {
                                        Console.Write ("End time HH:MM");
                                        string setime = Console.ReadLine ();
                                        match = Regex.Match (setime, timeFormat);
                                        if (match.Success) {
                                            et = conv.s2d (setime);
                                            break;
                                        }
                                    }
                                    Lecturer lec = lecturerAdmin.GetLecturerFromID (cla.LecturerID);
                                    lec.timetable.ReserveTime (cla.CourseID, cd, st, et);
                                    cla.AddClassPeriod (cr, cd, st, et);
                                    Course cou = courseAdmin.GetCourseFromID (cla.CourseID);
                                    string info = courseAdmin.GetNameFromID (cla.CourseID) + "-" + lecturerAdmin.GetNameFromID (cla.LecturerID);
                                    cou.timetable.ReserveTime (info, cd, st, et);

                                    break;
                                }

                            default:
                                break;

                            }
                            Console.Clear ();

                            break;
                        }
                    case 3:
                        classAdmin.List ();

                        break;

                    case 4:
                        cont = false;
                        break;
                    default:
                        Console.WriteLine ("Wrong choice");
                        break;

                    }
                } catch (Exception e) {
                    Console.WriteLine ("Exception: " + e.Message);
                }
            }
        }
Example #2
0
        public void Printme()
        {
            Converter conv = new Converter ();
            Daytimetable dtb;
            int counter;
            Console.WriteLine (String.Format ("              {0,-15}{1,-15}{2,-15}{3,-15}{4,-15}{5,-15}{6,-15}", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"));
            for (double i = 8; i < 18; i += 0.5) {
                Console.Write ((conv.d2s (i)) + "-" + (conv.d2s (i + 0.5))+"   ");
                counter = 0;
                foreach (KeyValuePair<string, Daytimetable> element in weektimetable) {
                    dtb = element.Value;
                    Console.Write (String.Format("{"+counter+",-15}", conv.FormatResult(dtb.daytimetable[i])));

                }
                Console.WriteLine();

            }
        }