示例#1
0
        private void AttemptLogIn()
        {
            LoginValidation login = new LoginValidation(Username, Password, this.ActionOnError);

            User user = null;

            if (LoginValidation.ValidateUserInput(ref user))
            {
                Student student = StudentValidation.GetStudentDataByUser(user);

                if (student == null)
                {
                    MessageBox.Show("User '" + user.Username + "' does not have field facultyNumber.");
                    Password = "";
                    OnPropertyChanged("Password");
                    return;
                }
                OnSuccessfulLogin(student);
            }
            else
            {
                Password = "";
                OnPropertyChanged("Password");
            }
        }
示例#2
0
        void AddStud()
        {
            Student stud = new Student(
                Name,
                CivilNumber,
                FacNum,
                StudFaculty,
                CourseName,
                TypeStudy,
                TypeDegree,
                Group,
                StudySubjects.ToList(),
                ImageUri
                );

            StudentValidation.ActionOnError act = Error;
            StudentValidation sv = new StudentValidation(act);

            if (sv.isStudentValid(stud))
            {
                studList.Add(stud);
                ErrMsg = "Student " + stud.Name + " added!";
                Factory.GetStudents().InsertOne(stud);
            }
        }
示例#3
0
 public override void Delete(int studentId)
 {
     if (StudentValidation.IsValidStudentId(studentId))
     {
         DataAccessProvider.ExecuteNonQuery($"DELETE Students " +
                                            $"WHERE StudentID = {studentId}");
     }
 }
示例#4
0
 public void IsStudentIDValidTest()
 {
     Assert.AreEqual((false, "Missing student ID!"), StudentValidation.IsStudentIDValid(7, ""));
     Assert.AreEqual((false, "Invalid student ID, only numeric digits allowed!"), StudentValidation.IsStudentIDValid(7, "1A*2"));
     Assert.AreEqual((false, "Invalid student ID, no more than 4 digits allowed!"), StudentValidation.IsStudentIDValid(7, "13245"));
     Assert.AreEqual((false, "Invalid student ID for Year 7 student!"), StudentValidation.IsStudentIDValid(7, "1736"));
     Assert.AreEqual((true, ""), StudentValidation.IsStudentIDValid(7, "0050"));
 }
示例#5
0
 public void IsStudentNameValidTest()
 {
     Assert.AreEqual((false, "Missing student name type!"), StudentValidation.IsStudentNameValid("Carlos", null));
     Assert.AreEqual((false, "Missing student first name!"), StudentValidation.IsStudentNameValid(null, "first name"));
     Assert.AreEqual((false, "Invalid student name type!"), StudentValidation.IsStudentNameValid("Tyler", "forename"));
     Assert.AreEqual((false, "Invalid student first name, no special or numeric characters allowed!"), StudentValidation.IsStudentNameValid("Martin/James", "first name"));
     Assert.AreEqual((false, "Invalid student first name!"), StudentValidation.IsStudentNameValid("Ryan--Mark", "first name"));
     Assert.AreEqual((true, ""), StudentValidation.IsStudentNameValid("Stuart", "first name"));
 }
示例#6
0
 public void CheckStudentIDRangeTest()
 {
     Assert.IsFalse(StudentValidation.CheckStudentIDRange(7, "2001"));
     Assert.IsTrue(StudentValidation.CheckStudentIDRange(8, "1412"));
     Assert.IsFalse(StudentValidation.CheckStudentIDRange(9, "8920"));
     Assert.IsTrue(StudentValidation.CheckStudentIDRange(10, "4500"));
     Assert.IsFalse(StudentValidation.CheckStudentIDRange(11, "0050"));
     Assert.IsTrue(StudentValidation.CheckStudentIDRange(12, "7056"));
     Assert.IsFalse(StudentValidation.CheckStudentIDRange(13, "5012"));
 }
示例#7
0
 public override void Create(Student student)
 {
     if (StudentValidation.IsValidStudent(student))
     {
         DataAccessProvider.ExecuteNonQuery($"INSERT INTO Students " +
                                            $"(StudentName, StudentSurname, StudentAge, GroupID) " +
                                            $"values (\'{student.StudentName}\'," +
                                            $"\'{student.StudentSurname}\'," +
                                            $"  {student.StudentAge}, " +
                                            $"  {student.GroupId})");
     }
 }
示例#8
0
 public override void Update(Student student)
 {
     if (StudentValidation.IsValidStudent(student) &&
         StudentValidation.IsValidStudentId(student.StudentId))
     {
         DataAccessProvider.ExecuteNonQuery($"UPDATE Students " +
                                            $"SET StudentName = \'{student.StudentName}\'," +
                                            $" StudentSurname = \'{student.StudentSurname}\', " +
                                            $" StudentAge = {student.StudentAge}, " +
                                            $" GroupID = {student.GroupId} " +
                                            $"WHERE StudentID = {student.StudentId}");
     }
 }
示例#9
0
        private void Login(object parameter)
        {
            var _loginValidation = new LoginValidation(Username, Password, ActionOnError);

            if (_loginValidation.ValidateUserInput(ref _user))
            {
                var studentValidation = new StudentValidation(ActionOnError);

                if (_user != null)
                {
                    var student = studentValidation.GetStudentDataByUser(_user);

                    var mainWindow = new MainWindow(student);
                    mainWindow.Show();
                    _loginWindow.Close();
                }
            }
        }
        public HttpResponseMessage CreateStudent(StudentViewModel studentViewModel)
        {
            TransactionStatus transactionStatus;
            var results = new StudentValidation().Validate(studentViewModel);

            if (!results.IsValid)
            {
                studentViewModel.Errors    = GenerateErrorMessage.Built(results.Errors);
                studentViewModel.ErrorType = ErrorTypeEnum.Error.ToString().ToLower();
                studentViewModel.Status    = false;
                var badResponse = Request.CreateResponse(HttpStatusCode.BadRequest, studentViewModel);
                return(badResponse);
            }

            var stundentBo = BuiltStudentBo(studentViewModel);

            stundentBo.PaymentMethods = string.Join(",", studentViewModel.SelectedPaymentMethods);
            stundentBo.Gender         = studentViewModel.SelectedGender;

            transactionStatus = _studentService.CreateStudent(stundentBo);

            if (transactionStatus.Status == false)
            {
                var badResponse = Request.CreateResponse(HttpStatusCode.BadRequest, JsonConvert.SerializeObject(studentViewModel));
                return(badResponse);
            }
            else
            {
                transactionStatus.ErrorType = ErrorTypeEnum.Success.ToString();
                transactionStatus.ReturnMessage.Add("Record successfully inserted to database");

                var badResponse = Request.CreateResponse(HttpStatusCode.Created, transactionStatus);

                return(badResponse);
            }
        }
示例#11
0
        // Custom Constructor.

        /**
         * <summary>This custom constructor is responsible for creating a Student object.</summary>
         *
         * <param name="ID">A student's unique 4-digit ID number.</param>
         * <param name="f_name">A student's first name.</param>
         * <param name="l_name">A student's last name.</param>
         * <param name="year">A student's current school year.</param>
         * <param name="clName">A student's class name.</param>
         *
         * <example>
         * <code>Student sd = new Student("0007", "John", "Smith", 9, "Grey");</code>
         * This creates a Student object with the ID value as "0007", first name as "John", last name as "Smith", school year as '9' and class name as "Grey".
         * </example>
         */
        public Student(string ID, string f_name, string l_name, int year, string clName)
        {
            if (!StudentValidation.IsStudentIDValid(year, ID).Item1)
            {
                // Throws an exception with a message dependent on what invalidates the student ID.
                throw new ArgumentException(StudentValidation.IsStudentIDValid(year, ID).Item2);
            }
            else
            {
                GetStudentID = ID;
            }

            if (!StudentValidation.IsStudentNameValid(f_name, "first name").Item1)
            {
                // Throws an exception with a message dependent on what invalidates the student's first name.
                throw new ArgumentException(StudentValidation.IsStudentNameValid(f_name, "first name").Item2);
            }
            else
            {
                GetForename = f_name;
            }

            if (!StudentValidation.IsStudentNameValid(l_name, "last name").Item1)
            {
                // Throws an exception with a message dependent on what invalidates the student's last name.
                throw new ArgumentException(StudentValidation.IsStudentNameValid(l_name, "last name").Item2);
            }
            else
            {
                GetSurname = l_name;
            }

            if (year > 13 || year < 1)
            {
                // Throws an exception if 'year' is equal to a value less than 1 or greater than 13.
                throw new ArgumentException("Invalid academic year, only 1 - 13 are allowed!");
            }
            else
            {
                GetYear = year;
            }

            if (string.IsNullOrWhiteSpace(clName))
            {
                // Throws an exception if the 'clname' string is null, empty or only contains whitespaces.
                throw new ArgumentException("Missing student class name!");
            }
            else
            {
                bool notLetter = false;

                foreach (char c in clName)
                {
                    if (!char.IsLetter(c))
                    {
                        notLetter = true;
                    }
                }

                if (notLetter)
                {
                    // Throws an exception if the 'clname' string contains a disallowed character.
                    throw new ArgumentException("Invalid student class name, no special or numeric characters allowed!");
                }
                else
                {
                    GetClassName = clName;
                }
            }

            // Creates an empty list to be populated by subjects studied by the student.
            GetSubjects = new List <Subject>();

            // Sets the unique file path for the student.
            GetFilePath = "C:/Users/Student Results/Year " + GetYear + "/" + GetFullName + ".txt";
        }
示例#12
0
 public Student(IStudent student,
                StudentValidation StudentValidation)
 {
     _student           = student;
     _StudentValidation = StudentValidation;
 }
示例#13
0
 public FlatFileStudentSerializer(StudentValidation studentValidation)
 {
     _studentValidation = studentValidation;
 }
示例#14
0
        public static List <Student> convertFileToListStudents(string FileName)
        {
            List <Student> students = new List <Student>();

            StreamReader sr = new StreamReader(FileName);
            string       line;
            Validation   validation = new Validation();

            while ((line = sr.ReadLine()) != null)
            {
                string[] items = line.Split('|');

                //Dinh dang
                //1 | 111 | Truong Dep Trai | 11/11/2001 12:00:00 AM | xxxxxx
                // sai dinh dang thi bo qua
                if (items.Length < 4 || items.Length > 5)
                {
                    continue;
                }
                //check xem co phai la 1-2-3 (Stu, Foreign, VN) hay khong
                if (validation.checkRangNumber(1, 3, items[0].Trim()) == -1)
                {
                    continue;
                }
                //check id phai la so hay khong, neu khong phai so thi bo qua
                if (validation.checkRangNumber(0, Int32.MaxValue, items[1].Trim()) == -1)
                {
                    continue;
                }

                //check format name
                if (!StudentValidation.isValidNameFormat(items[2].Trim()))
                {
                    continue;
                }

                //check id da ton tai hay chua
                if (FindById(Convert.ToInt32(items[1].Trim()), students))
                {
                    continue;
                }
                Student s = null;
                if (items[0].Trim().Equals("1"))
                {
                    s = new Student(Convert.ToInt32(items[1].Trim()), items[2].Trim(), Convert.ToDateTime(items[3].Trim()));
                }
                else if (items[0].Trim().Equals("2"))
                {
                    //ten quoc gia khong duoc chua ky tu dac biet va so
                    if (!validation.isValidNameFormat(items[4].Trim()))
                    {
                        continue;
                    }

                    s = new ForeignStudent(Convert.ToInt32(items[1].Trim()), items[2].Trim(), Convert.ToDateTime(items[3].Trim()), items[4].Trim());
                }
                else if (items[0].Trim().Equals("3"))
                {
                    //identity only number
                    if (!validation.isValidNumberFormat(items[4].Trim()))
                    {
                        continue;
                    }
                    s = new VietNamStudent(Convert.ToInt32(items[1].Trim()), items[2].Trim(), Convert.ToDateTime(items[3].Trim()), Convert.ToInt32(items[4].Trim()));
                }
                else
                {
                    throw new Exception("Invalid student type");
                }
                students.Add(s);
            }
            sr.Close();
            return(students);
        }
        /**
         * <summary>This method effectively stores the raw subject data in the appropriate model classes.</summary>
         *
         * <param name="ay">The AcademicYear object where the data will be stored to.</param>
         */
        public void LoadSubjectData(AcademicYear ay)
        {
            // IF statement checks that the AcademicYear object parameter is not null and has at least 1 Student obect stored inside it.
            if (ay != null && ay.GetStudents.Count > 0)
            {
                // Stores each line of the subjectData2.txt file as a strings into an array.
                string[] lines = System.IO.File.ReadAllLines("C:/Users/Yash/source/repos/SchoolReportSystem/view/import/subjectData2.txt");

                // IF statement checks that there is at least 1 line of text within the file.
                if (lines.Length > 0)
                {
                    // Creates an empty Student object.
                    Student sd = null;

                    // Breaks up each string inside the array and iterates through each one.
                    foreach (string line in lines)
                    {
                        // Splits each line into an array with comma delimited values.
                        string[] elements = line.Split(",");

                        // IF statement checks the length of the non-empty array.
                        if (elements.Length != 5)
                        {
                            // An exception is thrown if the length of the array not equal to 5.
                            throw new ArgumentException("Invalid subject data!");
                        }
                        else
                        {
                            // An exception will be thrown if the 'elements' array has any missing data.
                            HelperMethods.CheckArray(elements, "Missing subject data!");

                            if (!elements[4].All(char.IsDigit))
                            {
                                // An exception is thrown if the last element of the array contains anything other than digits.
                                throw new ArgumentException("Invalid student ID!");
                            }
                            else if (StudentValidation.CheckStudentIDRange(ay.GetYearNo, elements[4]))
                            {
                                // Passes the ID of the student into 'GetStudentByID' method, which returns the matching Student object and stores it into a new object.
                                sd = ay.GetStudentById(elements[4]);

                                // Invokes the 'StoreSubjectDetails' method of the ImportMethods utility class.
                                ImportMethods.StoreSubjectDetails(sd, elements);

                                // Removes any duplicate subjects stored within the Student object.
                                sd.RemoveDuplicateSubjects();
                            }
                        }
                    }
                }

                ay.GetStudents.ForEach(_ =>
                {
                    if (_.GetSubjects.Count != ImportMethods.CheckNoSubjectsForYear(_.GetYear))
                    {
                        // Throws an exception if the student does not have the required number of subjects for their academic year.
                        throw new ArgumentException("Invalid number of subjects for a student in year " + _.GetYear);
                    }
                });
            }
        }