Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Test        testToWrite = new Test();
            List <Test> allTests    = new List <Test>();

            Memo memoToAdd = new Memo();

            //To not jump ahead in the menu
            bool loggedInStudent = false;
            bool activeTeacher   = false;

            //TestIDTemp for test selects
            int testSelect = 0;

            SqlConnection dbConn           = new SqlConnection();
            string        connectionString = Properties.Settings.Default.ConnectionString;

            dbConn = DataAccessTest(connectionString, dbConn);

            Console.WriteLine("Welcome to the multiple choice application\nAre you a:\n(1) Teacher\n(2) Student\n Or would you like to:\n(0) Exit");
            DisplayUserFunctionality();

            //Response acts as LCV
            int response = ValidateRange(Console.ReadLine(), 0, 2);

            while (response != 0)
            {
                if (response == 1)//Teacher
                {
                    response      = Convert.ToInt16(DisplayTeacherInterfaceAsync());
                    activeTeacher = true;
                }
                else if (response == 2)//Student
                {
                    Console.WriteLine(String.Format(
                                          "{0}\n{1}\n{2}\n", "----------------------", "Student", "----------------------\n"));
                    response        = Convert.ToInt16(DisplayStudentLoginInterface());
                    loggedInStudent = true;
                }
                else if (response == 3 && loggedInStudent == true)//New Student
                {
                    Console.WriteLine(String.Format(
                                          "{0}\n{1}\n{2}\n", "----------------------", "Student", "----------------------\n"));
                    response = NewStudentMenu(dbConn);
                }
                else if (response == 5 && loggedInStudent == true)//Student Interface
                {
                    Console.WriteLine(String.Format(
                                          "{0}\n{1}\n{2}\n", "----------------------", "Student", "----------------------\n"));
                    response = DisplayStudentInterface();
                }
                else if (response == 6 && activeTeacher == true)//Teacher views student's marks
                {
                    ViewStudentsMarks(dbConn);

                    Console.WriteLine("(1) To return");
                    int intialresponse = ValidateRange(Console.ReadLine(), 1, 1);

                    switch (intialresponse)
                    {
                    case 1:
                        response = 1;
                        break;
                    }
                }
                else if (response == 7 && activeTeacher == true)//Prep Test (Author, subject)
                {
                    tempTeacher = PrepTest(dbConn);
                    response    = 8;
                }
                else if (response == 8 && activeTeacher == true)//Make the multiple choice question
                {
                    MakeTest(dbConn, tempTeacher);
                    response = 1;
                }
                else if (response == 9 && loggedInStudent == true)//Look at test menu
                {
                    if (ViewTests(dbConn) == null)
                    {
                        Console.WriteLine("No tests currently available\nPress (1) to return");
                        int intialresponse = ValidateRange(Console.ReadLine(), 1, 1);

                        switch (intialresponse)
                        {
                        case 1:
                            response = 5;
                            break;
                        }
                    }
                    else
                    {
                        List <string> testNames = new List <string>();
                        DataSet       tempTests = ViewTests(dbConn);
                        int           maxCount  = 1;

                        Console.WriteLine(String.Format(
                                              "{0}\n{1}\n{2}\n", "----------------------", "Tests", "----------------------"));

                        object[] row;

                        for (int i = 0; i < tempTests.Tables[0].Rows.Count; i++)
                        {
                            //Loops through arrays as rows so it resets index
                            row = tempTests.Tables[0].Rows[i].ItemArray;
                            testNames.Add("" + row[1]);
                            maxCount++;
                        }

                        for (int i = 0; i < tempTests.Tables[0].Rows.Count; i++)
                        {
                            Console.WriteLine(string.Format("({0}) {1}", i + 1, testNames[i]));
                        }


                        Console.WriteLine("\nEnter Number by entering corresponding number in brackets");
                        testSelect = ValidateRange(Console.ReadLine(), 1, (maxCount));
                        dbConn.Close();
                        response = 11;
                    }
                }
                else if (response == 10 && loggedInStudent == true)//Student views marks
                {
                    //Student obj passed through to view own marks
                    ViewOwnMarks(tempStd, dbConn);
                    Console.WriteLine("(1) To return");
                    int intialresponse = ValidateRange(Console.ReadLine(), 1, 1);

                    switch (intialresponse)
                    {
                    case 1:
                        response = 5;
                        break;
                    }
                }
                else if (response == 11 && loggedInStudent == true)//Student takes selected test
                {
                    //Change for ADO
                    //Push through to database
                    int testID = TakeSelectedTest(dbConn, testSelect);

                    //TODO:
                    //DisplayMemo
                    memoToAdd.DisplayMemo(dbConn, Convert.ToInt16(tempStd.GetID()), testID);

                    Console.WriteLine("Press 1 to return to student menu");
                    response = ValidateRange(Console.ReadLine(), 1, 1);

                    switch (response)
                    {
                    case 1:
                        response = 5;
                        break;
                    }
                }
                else if (response == 4)
                {
                    Console.Clear();
                    loggedInStudent = false;
                    activeTeacher   = false;
                    Console.WriteLine("Welcome to the multiple choice application\nAre you a:\n(1) Teacher\n(2) Student\n Or would you like to: \n(0) Exit");
                    DisplayUserFunctionality();
                    response = ValidateRange(Console.ReadLine(), 0, 2);
                }
                else if (response == 12)//Student Login Added in assignment 3, hence weird number allocation
                {
                    int exitResponse = 0;

                    Console.Clear();
                    Console.WriteLine("Please enter your student number : ");
                    string num = CheckStringNotNull(Console.ReadLine());
                    Console.WriteLine("Please enter your password : "******"Invalid Credentials");
                        Console.ForegroundColor = ConsoleColor.White;
                        Console.WriteLine("Would you like to return to the main menu or try again?\n(1) To return to main menu\n(0) To Retry");
                        //Short circuts and exits
                        exitResponse = ValidateRange(Console.ReadLine(), 0, 1);

                        if (exitResponse == 0)
                        {
                            Console.Clear();
                            Console.WriteLine("Please enter your student number : ");
                            num = CheckStringNotNull(Console.ReadLine());
                            Console.WriteLine("Please enter your password : "******"" + row[0]);
                            tempStd.SetName("" + row[1]);
                            tempStd.SetStudentNumber("" + row[2]);
                            tempStd.SetPassword("" + row[3]);
                        }
                    }
                    else
                    {
                        response = 4;
                    }
                }
            }
        }