void ShowMainMenu() { int selectedIndex = 0; for (; ;) { Console.SetCursorPosition(0, 0); ConsoleHelper.WriteCenter("Администратор"); menu.Clear(); menu.StartY = 2; menu.Update(mainMenu, false); selectedIndex = menu.Choice(selectedIndex); if (selectedIndex != 4) { ConsoleHelper.ClearArea(0, 0, Console.WindowWidth - 1, 0); menu.Clear(); menu.StartY = 0; } switch (selectedIndex) { case 0: ShowGroupsMenu(); break; case 1: ShowAccountsMenu(); break; case 2: ShowAccountAddMenu(); break; case 3: ShowGroupAddMenu(); break; case 4: string pass = CurrentAccount.Password; if (UIFunctions.ChangePassword(ref pass, 2 + mainMenu.Length + 1)) { CurrentAccount.Password = pass; using (BinaryWriter writer = settings.GetAccountFileWriter(CurrentAccount.Login)) CurrentAccount.Export(writer); } Console.SetCursorPosition(0, 0); break; case 5: return; } } }
void ShowMainMenu() { int selectedIndex = 0; for (; ;) { ConsoleHelper.WriteCenter($"{UIFunctions.GetFullName(CurrentAccount)} - преподаватель"); menu.Clear(); menu.StartY = 2; menu.Update(mainMenu, false); selectedIndex = menu.Choice(selectedIndex); if (selectedIndex != 1) { ConsoleHelper.ClearArea(0, 0, Console.WindowWidth - 1, 0); menu.Clear(); menu.StartY = 0; } switch (selectedIndex) { case 0: ShowGroupsMenu(); break; case 1: string pass = CurrentAccount.Password; if (UIFunctions.ChangePassword(ref pass, 6)) { CurrentAccount.Password = pass; using (BinaryWriter writer = settings.GetAccountFileWriter(CurrentAccount.Login)) CurrentAccount.Export(writer); } Console.SetCursorPosition(0, 0); break; case 2: return; } } }
bool EditDiscipline(int disciplineIndex) { string[] choices = Group_.Students .Select( studentLogin => { Student st = Settings_.LoadAccount(studentLogin) as Student; return(UIFunctions.GetInitials(st)); } ) .Append("Сохранить") .ToArray(); ConsoleSelect menu = new(choices, startY : 2, write : false); void WriteMarks() { int marksStartX = menu.CurrentMaxWidth + 4; for (int i = 0; i < Group_.Marks.Count; i++) { Console.SetCursorPosition(marksStartX, 2 + i); string smarks = Group_.Marks[i][disciplineIndex].Aggregate("", (acc, mark) => acc += $"{mark.mark} "); if (Console.WindowWidth - 1 - marksStartX - smarks.Length < 0) { smarks = smarks.Substring(0, Console.WindowWidth - 1 - marksStartX); } Console.Write(smarks); } } WriteMarks(); void ClearThis() { ConsoleHelper.ClearArea(0, 0, Console.WindowWidth - 1, 1 + choices.Length); Console.SetCursorPosition(0, 0); } int select = 0; while (true) { Console.SetCursorPosition(0, 0); ConsoleHelper.WriteCenter(Group_.Disciplines[disciplineIndex]); select = menu.Choice(select, (ConsoleKeyInfo key, int selectedIndex) => { if (key.Key == ConsoleKey.Escape) { return(-1); } return(null); }, true); if (select == -1) { ClearThis(); return(false); } if (select == choices.Length - 1) { break; } ClearThis(); EditStudentMarks(disciplineIndex, select); WriteMarks(); } ClearThis(); return(true); }