示例#1
0
        public List <Student> SearchByGenderAndType(string gender, StudentType stype)
        {
            List <Student> result = new List <Student>();

            Type otype = null;

            switch (stype)
            {
            case StudentType.Elementary:
                otype = new ElementaryStudent().GetType();
                break;

            case StudentType.High:
                otype = new HighStudent().GetType();
                break;

            case StudentType.Kinder:
                otype = new KinderStudent().GetType();
                break;

            case StudentType.University:
                otype = new UniversityStudent().GetType();
                break;
            }

            result = StudentsList.Where(i => i.GetType().Equals(otype) && i.Gender.ToLower().Equals(gender.ToLower())).OrderByDescending(o => o.RegistrationDate).ToList();
            return(result);
        }
示例#2
0
        public static List <Student> ReadStudentFile(string fileName)
        {
            List <Student> stList = new List <Student>();
            var            path   = "..//..//Files//st.csv";

            if (File.Exists(path))
            {
                using (TextFieldParser parser = new TextFieldParser(path))
                {
                    parser.TextFieldType = FieldType.Delimited;
                    parser.SetDelimiters(",");
                    while (!parser.EndOfData)
                    {
                        string[] fields  = parser.ReadFields();
                        string   name    = fields[1];
                        string   gender  = fields[2].ToLower().Equals("M") ? "Male" : "Female";
                        var      regDate = DateTime.ParseExact(fields[3], "yyyyMMddHHmmss", CultureInfo.InvariantCulture);
                        switch (fields[0].ToLower())
                        {
                        case "kinder":
                            var kstudent = new KinderStudent();
                            kstudent.CreateStudent(name, regDate, gender);
                            stList.Add(kstudent);
                            break;

                        case "high":
                            var hstudent = new HighStudent();
                            hstudent.CreateStudent(name, regDate, gender);
                            stList.Add(hstudent);
                            break;

                        case "university":
                            var ustudent = new UniversityStudent();
                            ustudent.CreateStudent(name, regDate, gender);
                            stList.Add(ustudent);
                            break;

                        case "elementary":
                            var estudent = new ElementaryStudent();
                            estudent.CreateStudent(name, regDate, gender);
                            stList.Add(estudent);
                            break;
                        }
                    }
                }
            }

            return(stList);
        }