Exemple #1
0
        public static void ReadStContainerFromFile(string path, StudentContainer readContainer)
        {
            try
            {
                using (StreamReader sr = new StreamReader(path, System.Text.Encoding.Default))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        var infoStudent = line.Split(new char[] { '|' });

                        readContainer.AddStudent(new Student(infoStudent[0],
                                                             infoStudent[1],
                                                             infoStudent[2],
                                                             DateTime.Parse(infoStudent[3]),
                                                             DateTime.Parse(infoStudent[4]),
                                                             char.Parse(infoStudent[5]),
                                                             infoStudent[6],
                                                             infoStudent[7],
                                                             double.Parse(infoStudent[8])));
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Exemple #2
0
        public static void SaveCollectionInXML(StudentContainer studentContainer, string filename)
        {
            XmlSerializer x      = new XmlSerializer(studentContainer.Students.GetType());
            TextWriter    writer = new StreamWriter(filename);

            x.Serialize(writer, studentContainer.Students);
            writer.Close();
        }
Exemple #3
0
        public static double CalculateAverageAcademicPerformance(StudentContainer studentArray)
        {
            double sum = 0;

            foreach (var student in studentArray.Students)
            {
                sum += student.Performance;
            }

            return(sum / studentArray.Students.Length);
        }
Exemple #4
0
 public void DeleteStudents(StudentContainer removing)
 {
     for (int i = 0; i < removing.Students.Length; i++)
     {
         for (int j = 0; j < Students.Length; j++)
         {
             if (this.Students[j].Equals(removing.Students[i]))
             {
                 DeleteStudent(j);
             }
         }
     }
 }
Exemple #5
0
        public static StudentContainer Search(String criteria, StudentContainer studentArray, int category)
        {
            var    searched = new StudentContainer();
            string groupIndex;

            if (studentArray.Students != null)
            {
                switch (category)
                {
                case 0:
                {
                    foreach (Student student in studentArray.Students)
                    {
                        if (student.GroupIndex.ToString().ToLower().Contains(criteria.ToLower()))
                        {
                            searched.AddStudent(student);
                        }
                    }
                    break;
                }

                case 1:
                {
                    foreach (Student student in studentArray.Students)
                    {
                        if (student.Faculty.ToLower().Contains(criteria.ToLower()))
                        {
                            searched.AddStudent(student);
                        }
                    }

                    break;
                }

                case 2:
                {
                    foreach (Student student in studentArray.Students)
                    {
                        if (student.Specialization.ToLower().Contains(criteria.ToLower()))
                        {
                            searched.AddStudent(student);
                        }
                    }

                    break;
                }
                }
                return(searched);
            }
            return(new StudentContainer());
        }
Exemple #6
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 #7
0
 public static void WriteStContainerToFile(string path, StudentContainer writtenContainer)
 {
     try
     {
         using (StreamWriter sw = new StreamWriter(path, false, System.Text.Encoding.Default))
         {
             foreach (var i in writtenContainer)
             {
                 sw.WriteLine(i.ToInfoString());
             }
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
 }
Exemple #8
0
 public static void ShowContainer(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 #9
0
        public static void Start()
        {
            const string path    = @"C:\Users\Дмитрий Соколенко\source\repos\DotNet\sokolenko05DN\file.txt";
            const string xmlPath = @"C:\Users\Дмитрий Соколенко\source\repos\DotNet\sokolenko05DN\file.xml";
            var          pigsty  = new StudentContainer();
            char         choice  = 'a';
            int          intChoice;
            string       strChoice = "";


            Console.WriteLine("Hello World! Our copany introduces the next level of data base - AllBase");
            Console.WriteLine("The array of Student object is created, my lord.");

            Io.ReadStContainerFromFile(path, pigsty);


            while (choice != '0')
            {
                PrintMenu();
                Console.Write("Make a choice: ");
                choice = Io.InputChar();

                switch (choice)
                {
                case '1':
                    PrintOptions();
                    Console.WriteLine("3 - All students");
                    Console.Write("Make a choice: ");
                    intChoice = Io.InputInt();

                    if (intChoice != 3)
                    {
                        Console.WriteLine("Enter criteria: ");
                        strChoice = Console.ReadLine();

                        Io.ShowContainer(StudentContainer.Search(strChoice, pigsty, intChoice));
                    }
                    else
                    {
                        Io.ShowContainer(pigsty);
                    }


                    break;

                case '2':
                    pigsty.AddStudent(Io.InputStudent());
                    break;

                case '3':
                    if (pigsty.Size() > 0)
                    {
                        Console.Write("Input the index: ");
                        pigsty.DeleteStudent(Io.InputInt());
                    }
                    else
                    {
                        Console.Write("Container is empty");
                    }
                    break;

                case '4':
                    if (pigsty.Size() > 0)
                    {
                        Console.Write("Input the index: ");
                        pigsty.ShowByIndex(Io.InputInt());
                    }
                    else
                    {
                        Console.Write("Container is empty");
                    }
                    break;

                case '5':
                    if (pigsty.Size() > 0)
                    {
                        Console.Write("Input the index: ");
                        pigsty.EditByIndex(Io.InputInt());
                    }
                    else
                    {
                        Console.Write("Container is empty");
                    }
                    break;

                case '6':
                    PrintOptions();
                    Console.Write("Make a choice: ");
                    intChoice = Io.InputInt();

                    Console.WriteLine("Enter criteria: ");
                    strChoice = Console.ReadLine();
                    pigsty.DeleteStudents(StudentContainer.Search(strChoice, pigsty, intChoice));
                    break;

                case '7':
                    PrintMathematicOptions();
                    Console.Write("Make a choice: ");
                    intChoice = Io.InputInt();

                    StudentContainerProcessing.Del del = null;
                    switch (intChoice)
                    {
                    case 0:
                    {
                        del = StudentContainerProcessing.CalculateAverageAge;
                        break;
                    }

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

                    PrintOptions();

                    Console.Write("Make a choice: ");
                    intChoice = Io.InputInt();

                    Console.WriteLine("Enter criteria: ");
                    strChoice = Console.ReadLine();

                    Console.WriteLine(del?.Invoke(StudentContainer.Search(strChoice, pigsty, intChoice)));
                    break;

                case '8':
                    Serialization.SaveCollectionInXML(pigsty, xmlPath);
                    break;

                case '9':
                    pigsty = Serialization.LoadCollectionFromXML(xmlPath);
                    break;
                }
            }

            Io.WriteStContainerToFile(path, pigsty);
        }