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); }
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); } } }