public void Start() { int choice = 0; do { Console.WriteLine(COMMANDS); String line = Console.ReadLine(); if (int.TryParse(line, out choice)) { choice = Convert.ToInt32(line); } else { Console.WriteLine("Incorrect command"); continue; } switch (choice) { case 1: binaryTree = BinaryFileUtil.Read(); if (binaryTree != null) { ExecuteData(); } break; case 2: BinaryFileUtil.Write(dataStudents); break; case 3: break; default: Console.WriteLine("Incorrect command"); break; } } while (choice != 3); }
public void ExecuteData() { int choice = 0; do { Console.WriteLine(SUB_COMMANDS); String line = Console.ReadLine(); if (int.TryParse(line, out choice)) { choice = Convert.ToInt32(line); } else { Console.WriteLine("Incorrect command"); continue; } numberLines = null; orderBy = 0; orderType = 0; switch (choice) { case 1: Console.WriteLine("Enter date in format dd-mm-YYYY"); String lineDate = Console.ReadLine(); DateTime date; if (DateTime.TryParse(lineDate, out date)) { PreSettings(); allStudents = BinaryFileUtil.GetByDate(binaryTree, date); students = BinaryFileUtil.GetByNumberLines(allStudents, numberLines); CheckData(students); foreach (Student student in BinaryFileUtil.OrderStudents(students, orderBy, orderType)) { Console.WriteLine(student.ToString()); } } else { Console.WriteLine("Incorrect format date"); } Console.ReadKey(); break; case 2: Console.WriteLine("Enter name test or part of name: "); String nameOfTest = Console.ReadLine(); PreSettings(); allStudents = BinaryFileUtil.GetByNameTest(binaryTree, nameOfTest); students = BinaryFileUtil.GetByNumberLines(allStudents, numberLines); CheckData(students); foreach (Student student in BinaryFileUtil.OrderStudents(students, orderBy, orderType)) { Console.WriteLine(student.ToString()); } Console.ReadKey(); break; case 3: Console.WriteLine("Enter rating: "); String lineRating = Console.ReadLine(); int rating; if (Int32.TryParse(lineRating, out rating)) { PreSettings(); allStudents = BinaryFileUtil.GetByRating(binaryTree, rating); students = BinaryFileUtil.GetByNumberLines(allStudents, numberLines); CheckData(students); foreach (Student student in BinaryFileUtil.OrderStudents(students, orderBy, orderType)) { Console.WriteLine(student.ToString()); } } else { Console.WriteLine("Incorrect rating"); } Console.ReadKey(); break; case 4: Console.WriteLine("Enter first name of student or part of first name: "); String firstName = Console.ReadLine(); PreSettings(); allStudents = BinaryFileUtil.GetByFirstName(binaryTree, firstName); students = BinaryFileUtil.GetByNumberLines(allStudents, numberLines); CheckData(students); foreach (Student student in BinaryFileUtil.OrderStudents(students, orderBy, orderType)) { Console.WriteLine(student.ToString()); } Console.ReadKey(); break; case 5: Console.WriteLine("Enter second name of student or part of second name: "); String secondName = Console.ReadLine(); PreSettings(); allStudents = BinaryFileUtil.GetBySecondName(binaryTree, secondName); students = BinaryFileUtil.GetByNumberLines(allStudents, numberLines); CheckData(students); foreach (Student student in BinaryFileUtil.OrderStudents(students, orderBy, orderType)) { Console.WriteLine(student.ToString()); } Console.ReadKey(); break; case 6: PreSettings(); students = BinaryFileUtil.OrderStudents(BinaryFileUtil.GetByNumberLines(binaryTree, numberLines), orderBy, orderType); CheckData(students); foreach (Student student in students) { Console.WriteLine(student.ToString()); } Console.ReadKey(); break; case 7: break; default: Console.WriteLine("Incorrect command"); break; } } while (choice != 7); }