示例#1
0
        public static void SaveCollectionInXML(StudentArray studentArray, string filename)
        {
            XmlSerializer x      = new XmlSerializer(studentArray.Students.GetType());
            TextWriter    writer = new StreamWriter(filename);

            x.Serialize(writer, studentArray.Students);
            writer.Close();
        }
示例#2
0
        public static StudentArray SearchBySurname(String surname, StudentArray studentArray)
        {
            var searched = new StudentArray();

            if (studentArray.Students != null)
            {
                var studs = studentArray.Cast <Student>().Where(s => s.Surname.ToLower().Contains(surname.ToLower())).Select(s => s);
                foreach (var st in studs)
                {
                    searched.Add(st);
                }
                return(searched);
            }
            return(new StudentArray());
        }
示例#3
0
        public static StudentArray RemoveStudents(StudentArray studentArray, StudentArray removing)
        {
            for (int i = 0; i < removing.Students.Length; i++)
            {
                for (int j = 0; j < studentArray.Students.Length; j++)
                {
                    if (studentArray.Students[j].Equals(removing.Students[i]))
                    {
                        studentArray.DeleteStudentByIndex(j);
                    }
                }
            }

            return(studentArray);
        }
示例#4
0
        public static StudentArray LoadCollectionFromXML(string filename)
        {
            XmlSerializer formatter = new XmlSerializer(typeof(Student[]));

            using FileStream fs = new FileStream(filename, FileMode.OpenOrCreate);
            Student[] newpeople = (Student[])formatter.Deserialize(fs);
            Student[] arr       = new Student[newpeople.Length];

            var studentArray = new StudentArray
            {
                Students = newpeople,
                Empty    = newpeople.Length == 0
            };

            studentArray.RecalculateValues();
            return(studentArray);
        }
示例#5
0
        public static StudentArray Search(String predicate, StudentArray studentArray, int category)
        {
            var searched = new StudentArray();

            if (studentArray.Students != null)
            {
                switch (category)
                {
                case 0:
                {
                    var studs = from s in studentArray.Students where s.Group.ToLower().Contains(predicate.ToLower()) select s;         //отложенное выполнение запроса
                    foreach (var st in studs)
                    {
                        searched.Add(st);
                    }
                    break;
                }

                case 1:
                {
                    var studs = (from s in studentArray.Students where s.Specialty.ToLower().Contains(predicate.ToLower()) select s).ToList();         //принудительное выполнение запроса
                    foreach (var st in studs)
                    {
                        searched.Add(st);
                    }

                    break;
                }

                case 2:
                {
                    var studs = studentArray.Cast <Student>().Where(s => s.Faculty.ToLower().Contains(predicate.ToLower())).Select(s => s);       //lambda
                    foreach (var st in studs)
                    {
                        searched.Add(st);
                    }

                    break;
                }
                }
                return(searched);
            }
            return(new StudentArray());
        }
示例#6
0
 public static double CalculateAverageAcademicPerformance(StudentArray studentArray)
 {
     return((from s in studentArray.Students select s.AcademicPerformance).Average());
 }
示例#7
0
 public static double CalculateAverageAge(StudentArray studentArray)
 {
     return((from s in studentArray.Students select s.Age).Average());
 }