static void Main(string[] args)
        {
            Console.Clear();
            Console.ForegroundColor = ConsoleColor.Green;

            //instantiate classes that contain the methods used in the main class
            GeneralMethods generalMethod = new GeneralMethods();
            StudentMethods studentMethod = new StudentMethods();
            TeacherMethods teacherMethod = new TeacherMethods();

            // variable choice to determine main switch menu

            int choice = 1;

            // variable bool access to determine if login password has been correct or not

            bool access;

            //Header method to give appearance

            generalMethod.Header();


            //Option to choose to login or exit;
            if (generalMethod.YesNo("Login", "Exit"))
            {
                choice = 1;
            }
            else
            {
                choice = 0;
            }


            while (choice == 1)
            {
                //assigning bool value to the returned value of the login method

                access = generalMethod.Login();

                if (access == true)
                {
                    //Populate lists with example items for demonstrative purposes
                    studentMethod.PopulateStudentList();

                    teacherMethod.PopulateTeacherList();

                    Console.WriteLine("Lists have been populated with example entries");

                    //Method for any key to continue
                    generalMethod.AnyKey();


                    while (choice != 0)
                    {
menu:
                        Console.WriteLine("********************Welcome to DBS Management Software********************\n\n");
                        Console.WriteLine("Please select choice\n\n*********************\n1: Student Options.\n2: Teacher Options\n3: Compare Teachers to Students\n0: Exit.");

                        //user inputs choice to select menu option. try catch to ensure input is int format, if 0 is entered the program will complete and close
                        try
                        {
                            choice = int.Parse(Console.ReadLine());
                        }
                        catch
                        {
                            Console.WriteLine("\nInvalid input\n");
                            generalMethod.AnyKey();
                            goto menu;
                        }

                        // switch statement to call different menu methods in different classes or to exit
                        switch (choice)
                        {
                        case 1: studentMethod.StudentMenu();
                            break;

                        case 2: teacherMethod.TeacherMenu();
                            break;

                        case 3: generalMethod.Comparison();
                            break;

                        case 0: break;

                        default: Console.WriteLine("\nInvalid input\n");
                            generalMethod.AnyKey();
                            goto menu;
                        }
                    }
                }

                //if login method returns false (invalid login) then this else statement will run

                else
                {
                    Console.WriteLine("********************Welcome to DBS Management Software********************\n\n");
                    Console.WriteLine("Do you wish to try login again?\n");

                    if (generalMethod.YesNo("Yes", "No"))
                    {
                        choice = 1;
                    }
                    else
                    {
                        choice = 0;
                    }
                    Console.Clear();
                }
            }
        }
示例#2
0
        //method to compare the two lists
        //method to compare the two lists
        public void Comparison()
        {
            Header();

            Console.WriteLine("The system will now compare the two lists and determine if there are any matching names.\n\n");

            // instantiate the two classes to this method can call each list using the GetStudentList() and GetTeacherList() methods in each class

            TeacherMethods tea     = new TeacherMethods();
            StudentMethods stu     = new StudentMethods();
            List <int>     indexes = new List <int>();

            //assign the returned array from the Compare() method to indexes

            indexes = Compare(stu.GetStudentList(), tea.GetTeacherList());

            //list indexes then holds the index numbers for the items in the student list and the items in the teacher which share the same names
            //see Compare() comments for more info



            if (indexes.Count != 0)
            {
                int p = 0;
                int q = 1;
                int r = 0;

                int arraySize = (indexes.Count() / 2);

                int[] studentMatchIndex = new int[arraySize];
                int[] teacherMatchIndex = new int[arraySize];

                for (int i = 0; i < arraySize; i++)
                {
                    studentMatchIndex[p] = indexes[r];
                    teacherMatchIndex[p] = indexes[q];

                    Console.WriteLine(stu.GetStudentList()[studentMatchIndex[p]].Display());
                    Console.WriteLine(tea.GetTeacherList()[teacherMatchIndex[p]].Display());

                    //boolean decision so that user can decide if they want to ensure that the teacher list item and the student list item share the same phone and email by overwriting

                    Console.WriteLine("\n\nDo you wish ensure matching phone and emails for these two instances?");
                    if (YesNo("Yes", "No"))
                    {
                        Console.WriteLine("\nDo you wish to keep the Teacher instance details or the Student instance details?");
                        if (YesNo("Teacher", "Student"))
                        {
                            //Overwriting the student phone and email with the teacher phone and email

                            stu.GetStudentList()[p].Email = tea.GetTeacherList()[p].Email;
                            stu.GetStudentList()[p].Phone = tea.GetTeacherList()[p].Phone;

                            Console.WriteLine("\n\n The Teacher details have replaced the Student details");
                        }
                        else
                        {
                            //overwriting the teacher phone and email with the student phone and email

                            tea.GetTeacherList()[p].Email = stu.GetStudentList()[p].Email;
                            tea.GetTeacherList()[p].Phone = stu.GetStudentList()[p].Phone;

                            Console.WriteLine("\n\n The Student details have replaced the Teacher details");
                        }
                    }

                    else
                    {
                        Console.WriteLine("\nNo details have been overwritten");
                    }

                    //p increases by 1, p represents the instance of matching names, p = 0 is first instance of mathcing names, p = 1 is second instance of matching names etc
                    p++;

                    //r to increase by 2 to skip to the next index value in list indexes which contains a student index
                    r = r + 2;
                    //q increases by 2 to skip to he next index value in list indexes which contains a teacher index
                    q = q + 2;
                }
            }
            else
            {
                Console.WriteLine("\nNo Matching names have been found\n");
            }

            AnyKey();
        }