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

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

            if (studentArray.Students != null)
            {
                var studs = studentArray.Cast <Student>().Where(s => s.LastName.ToLower().Contains(surname.ToLower())).Select(s => s);
                foreach (var st in studs)
                {
                    searched.Add(st);
                }
                return(searched);
            }
            return(new StudentContainer());
        }
Exemple #3
0
        public static StudentContainer RemoveStudents(StudentContainer studentArray, StudentContainer 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);
        }
Exemple #4
0
        public static StudentContainer 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 StudentContainer
            {
                Students = newpeople,
                Empty    = newpeople.Length == 0
            };

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

            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.Specialization.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 StudentContainer());
        }
Exemple #6
0
 public static void PrintStudents(StudentContainer students)
 {
     if (students != null)
     {
         Console.WriteLine("-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
         Console.WriteLine("|  №  |     Surname     |      Name       |    Patronymic    |  Date of birth  |  Enter date  |  Group index  |            Faculty            |          Specialty        |    Academic performance   |");
         Console.WriteLine("-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
         int i = 0;
         foreach (Student student in students)
         {
             String output = String.Format("| {0,-3} | {1,-15} | {2,-15} | {3,-16} | {4,-15} | {5,-12} | {6,-13} | {7,-29} | {8,-25} | {9,-25} |",
                                           (++i), student.LastName, student.FirstName, student.Patronymic, student.BirthDate.ToString("dd.MM.yyyy"), student.EnterDate.ToString("dd.MM.yyyy"), student.GroupIndex, student.Faculty, student.Specialization, student.Performance);
             Console.WriteLine(output);
         }
         Console.WriteLine("-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
     }
     else
     {
         Console.WriteLine("Array is empty");
     }
 }
Exemple #7
0
        public static StudentContainer ReadList(string fileName)
        {
            try
            {
                if (fileName == null)
                {
                    fileName = DefaultFilename;
                }

                var    file     = new StreamReader(fileName);
                var    students = new StudentContainer();
                string line;
                int    i = 1;
                while ((line = file.ReadLine()) != null)
                {
                    var student = new Student(line, file.ReadLine(), file.ReadLine(),
                                              DateTime.ParseExact(file.ReadLine(), "dd MM yyyy", CultureInfo.InvariantCulture),
                                              DateTime.ParseExact(file.ReadLine(), "dd MM yyyy", CultureInfo.InvariantCulture),
                                              file.ReadLine(), file.ReadLine(), file.ReadLine(), Convert.ToInt32(file.ReadLine()));
                    line = file.ReadLine();
                    if (line.Equals(""))
                    {
                        Console.WriteLine(i++ + " students read");
                    }
                    students.AddStudent(student);
                }
                ;

                file.Close();

                return(students);
            }
            catch (Exception e)
            {
                Console.WriteLine("An error occured while reading file: " + e.Message);
            }

            return(new StudentContainer());
        }
Exemple #8
0
        public static void WriteList(StudentContainer students, string fileName)
        {
            if (fileName == null)
            {
                fileName = DefaultFilename;
            }

            var file = new StreamWriter(fileName, false);

            foreach (Student student in students)
            {
                file.WriteLine(student.LastName);
                file.WriteLine(student.FirstName);
                file.WriteLine(student.Patronymic);
                file.WriteLine(student.BirthDate.ToString("dd MM yyyy"));
                file.WriteLine(student.EnterDate.ToString("dd MM yyyy"));
                file.WriteLine(student.GroupIndex);
                file.WriteLine(student.Faculty);
                file.WriteLine(student.Specialization);
                file.WriteLine(student.Performance);
                file.WriteLine();
            }
            file.Close();
        }
Exemple #9
0
 public static double CalculateAverageAcademicPerformance(StudentContainer studentArray)
 {
     return((from s in studentArray.Students select s.Performance).Average());
 }
Exemple #10
0
 public static double CalculateAverageAge(StudentContainer studentArray)
 {
     return((from s in studentArray.Students select s.Age).Average());
 }
Exemple #11
0
        public static void Start()
        {
            var pigsty = new StudentContainer();


            const string fileName = @"C:\Users\Дмитрий Соколенко\source\repos\DotNet\sokolenko05DN\file.txt";

            pigsty = FilesIO.ReadList(fileName);

            const string fileNameXml = @"C:\Users\Дмитрий Соколенко\source\repos\DotNet\sokolenko05DN\file.xml";

            while (true)
            {
                PrintMainMenu();
                int choice;
                try
                {
                    choice = Io.EnterInt("choice");
                    switch (choice)
                    {
                    case 1:
                    {
                        PrintStudents();
                        int printChoice = Io.EnterInt("printChoice");
                        switch (printChoice)
                        {
                        case 0:
                        {
                            Io.PrintStudents(pigsty);
                            break;
                        }

                        case 1:
                        {
                            Io.PrintStudents(StudentContainerProcessing.Search(Io.EnterString("group"), pigsty, printChoice - 1));
                            break;
                        }

                        case 2:
                        {
                            Io.PrintStudents(StudentContainerProcessing.Search(Io.EnterString("specialty"), pigsty, printChoice - 1));
                            break;
                        }

                        case 3:
                        {
                            Io.PrintStudents(StudentContainerProcessing.Search(Io.EnterString("faculty"), pigsty, printChoice - 1));
                            break;
                        }
                        }

                        break;
                    }

                    case 2:
                    {
                        pigsty.AddStudent(CreateStudent());
                        break;
                    }

                    case 3:
                    {
                        Io.PrintStudents(pigsty);
                        pigsty.DeleteStudentByIndex(Io.EnterInt("index") - 1);
                        break;
                    }

                    case 4:
                    {
                        var index   = GetIndex(pigsty);
                        var student = pigsty.GetStudent(index);
                        Console.WriteLine(student.ToString());
                        int edit = Io.EnterInt("1 if you want to edit");
                        if (edit == 1)
                        {
                            student = CreateStudent();
                            pigsty.SetStudent(index, student);
                        }
                        break;
                    }

                    case 5:
                    {
                        RemoveStudents();
                        int deleteChoice = Io.EnterInt("deleteChoice");
                        pigsty = StudentContainerProcessing.RemoveStudents(pigsty, StudentContainerProcessing.Search(Io.EnterString("choice"), pigsty, deleteChoice));
                        break;
                    }

                    case 6:
                    {
                        AvgCalculateOperations();
                        int avgOperations = Io.EnterInt("avgChoice");;
                        StudentContainerProcessing.Del del = null;
                        switch (avgOperations)
                        {
                        case 0:
                        {
                            del = StudentContainerProcessing.CalculateAverageAge;
                            break;
                        }

                        case 1:
                        {
                            del = StudentContainerProcessing.CalculateAverageAcademicPerformance;
                            break;
                        }
                        }

                        RemoveStudents();
                        int searchChoice = Io.EnterInt("searchChoice");
                        Console.WriteLine(del?.Invoke(StudentContainerProcessing.Search(Io.EnterString("choice"), pigsty, searchChoice)));
                        break;
                    }

                    case 7:
                    {
                        FilesIO.SaveCollectionInXML(pigsty, fileNameXml);
                        break;
                    }

                    case 8:
                    {
                        pigsty = FilesIO.LoadCollectionFromXML(fileNameXml);
                        break;
                    }

                    case 0:
                    {
                        FilesIO.WriteList(pigsty, fileName);
                        return;
                    }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }
Exemple #12
0
 private static int GetIndex(StudentContainer studentArray)
 {
     Io.PrintStudents(studentArray);
     return(Io.EnterInt("index") - 1);
 }