Beispiel #1
0
        ///// <summary>
        ///// 1 April 2014
        ///// Jonathan Sanborn
        /////
        ///// Gets the assignements and assignments of the passed in student.
        ///// </summary>
        ///// <param name="student">The Student to load with the assignment</param>
        //public void GetStudentAssignments(ref Student student)
        //{
        //    student.Assignments.Clear();
        //    student.AssignmentAttempts.Clear();

        //    student.Assignments.AddRange(FileHandler.GetAssignmentsByUser(student));

        //    foreach (Assignment assign in student.Assignments)
        //    {
        //        student.AssignmentAttempts.AddRange(FileHandler.GetAssignmentAttemptsByAssignmentID(assign.ID));
        //    }

        //}

        /// <summary>
        /// 22 March 2014
        /// Jonathan Sanborn & Harvey Mercado
        /// Called to login the user currently set
        ///
        /// 21 April 2014
        /// Jeff Bunce
        /// Refactored
        ///
        /// </summary>
        internal void UserLogin()
        {
            if (currentUser == null)
            {
                MessageBox.Show("Please Select a user.", "Select User", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;  // must select a user
            }


            TextBox txtPassword = LoginForm.Controls.Find("txtPassword", true)[0] as TextBox;

            if (AuthenticateUser(CurrentUser, txtPassword.Text))
            {
                txtPassword.Text = string.Empty;
                currentUser.Login();
            }
            else
            {
                MessageBox.Show("Wrong Password", "Wrong Password", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtPassword.Text = String.Empty;
                return;  // selected user must authenticate
            }


            if (currentUser.UserType == UserType.Student)
            {
                currentStudent = StudentList.Where(w => currentUser.ID == w.ID).First();

                ProblemSetList.Clear();

                if (currentStudent.IncompleteAssignments > 0)
                {
                    LoginForm.Hide();
                    LoginForm.Close();
                    Assignment assign = CurrentStudent.Assignments.Where(w => !w.IsCompleted).First();
                    assignmentSession  = new AssignmentSession(this, ref assign);
                    StudentWelcomeForm = new Forms.frmStudentWelcome(this);
                    StudentWelcomeForm.ShowDialog();
                }
                else
                {
                    MessageBox.Show(currentUser.ScreenName + " currently has no assignments. Please go see your teacher.", "Go See Teacher", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    currentUser.Logout(this);
                }
            }
            else if (currentUser.UserType == UserType.Administrator)
            {
                LoginForm.Hide();
                LoginForm.Close();

                ProblemSetList = FileHandler.GetAllProblemSets();

                AdminForm = new frmAdminControl(this);
                AdminForm.ShowDialog();
            }
        }
        ///// <summary>
        ///// 1 April 2014
        ///// Jonathan Sanborn
        ///// 
        ///// Gets the assignements and assignments of the passed in student.
        ///// </summary>
        ///// <param name="student">The Student to load with the assignment</param>
        //public void GetStudentAssignments(ref Student student)
        //{
        //    student.Assignments.Clear();
        //    student.AssignmentAttempts.Clear();

        //    student.Assignments.AddRange(FileHandler.GetAssignmentsByUser(student));

        //    foreach (Assignment assign in student.Assignments)
        //    {
        //        student.AssignmentAttempts.AddRange(FileHandler.GetAssignmentAttemptsByAssignmentID(assign.ID));
        //    }

        //}

        /// <summary>
        /// 22 March 2014
        /// Jonathan Sanborn & Harvey Mercado
        /// Called to login the user currently set
        /// 
        /// 21 April 2014
        /// Jeff Bunce
        /// Refactored
        /// 
        /// </summary>
        internal void UserLogin()
        {
            if (currentUser == null) 
            {
                MessageBox.Show("Please Select a user.", "Select User", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;  // must select a user
            }


            TextBox txtPassword = LoginForm.Controls.Find("txtPassword", true)[0] as TextBox;
            if (AuthenticateUser(CurrentUser, txtPassword.Text)) 
            {
                txtPassword.Text = string.Empty;
                currentUser.Login();
            }
            else
            {                
                MessageBox.Show("Wrong Password", "Wrong Password", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtPassword.Text = String.Empty;
                return;  // selected user must authenticate
            }


            if (currentUser.UserType == UserType.Student)
            {
                    currentStudent = StudentList.Where(w => currentUser.ID == w.ID).First();

                    ProblemSetList.Clear();

                    if (currentStudent.IncompleteAssignments > 0)
                    {
                        LoginForm.Hide();
                        LoginForm.Close();
                        Assignment assign = CurrentStudent.Assignments.Where(w => !w.IsCompleted).First();
                        assignmentSession = new AssignmentSession(this, ref assign);
                        StudentWelcomeForm = new Forms.frmStudentWelcome(this);
                        StudentWelcomeForm.ShowDialog();
                    }
                    else
                    {
                        MessageBox.Show(currentUser.ScreenName + " currently has no assignments. Please go see your teacher.", "Go See Teacher", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        currentUser.Logout(this);
                    }
            }
            else if (currentUser.UserType == UserType.Administrator)
            {
                    LoginForm.Hide();
                    LoginForm.Close();

                    ProblemSetList = FileHandler.GetAllProblemSets();

                    AdminForm = new frmAdminControl(this);
                    AdminForm.ShowDialog();
            }
        }