/// <summary> /// 添加新生 /// </summary> /// <param name="info">所有用户信息库</param> public static void CallAddStudent(this HeadTeacher ht) { try { ht?.AddStudent(); } catch (NullReferenceException ex) when(ex.Message.Equals("Account is Empty")) { DisplayTheInformationOfErrorCode(ErrorCode.BadAccount); } catch (NullReferenceException ex) when(ex.Message.Equals("Passwd is Empty")) { DisplayTheInformationOfErrorCode(ErrorCode.BadPasswd); } }
/// <summary> /// 移除账户 TODO: 需要更优解决方案 /// </summary> public static void RemoveAccount(this HeadTeacher ht) { Write("请输入将要移除的账户:"); string account = ReadLine(); { Student student = UserRepository.StudentLibrary.Find(stu => stu.Account == account); if (student != null) { Write("确定要删除吗?(Y/N) : "); student.ViewPersonalInformation(); string result = ReadLine(); if (result.Equals("y") || result.Equals("Y") || result.Equals(string.Empty)) { UserRepository.StudentLibrary.Remove(student); UserRepository.HeadTeacherUser.AddHistory(new Message("你", $"删除了一个学生账户({account})")); DisplayTheInformationOfSuccessfully(); } return; } } { Instructor teacher = UserRepository.TeacherLibrary.Find(t => t.Account == account); if (teacher != null) { Write("确定要删除吗?(Y/N) : "); teacher.ViewPersonalInformation(); string result = ReadLine(); if (result.Equals("y") || result.Equals("Y") || result.Equals(string.Empty)) { UserRepository.TeacherLibrary.Remove(teacher); UserRepository.HeadTeacherUser.AddHistory(new Message("你", $"删除了一个教师账户({account})")); DisplayTheInformationOfSuccessfully(); } return; } } DisplayTheInformationOfErrorCode(ErrorCode.CantFindThisAccount, account); }
/// <summary> /// 修改学生或教师的姓名(针对于班主任用户) /// </summary> /// <param name="me">执行该命令的对象</param> public static void ChangeNameOfOtherUser(this HeadTeacher ht) { Write("请输入将要更改姓名的账户:"); string account = ReadLine(); foreach (Student student in UserRepository.StudentLibrary) { if (account != student.Account) { continue; } Write("新姓名: "); string name = ReadLine(); student.Name = name; UserRepository.HeadTeacherUser.AddHistory( new Message("你", $"将{student.Account}的姓名重新设置为({name})") ); DisplayTheInformationOfSuccessfully(); return; } foreach (Instructor teacher in UserRepository.TeacherLibrary) { if (account != teacher.Account) { continue; } Write("新姓名: "); string name = ReadLine(); teacher.Name = name; UserRepository.HeadTeacherUser.AddHistory( new Message("你", $"将{teacher.Account}的姓名重新设置为({name})") ); DisplayTheInformationOfSuccessfully(); return; } }
/// <summary> /// 添加/注册新老师 /// </summary> public static void AddTeacher(this HeadTeacher ht) { WriteLine("你想创建哪一科目的任课教师? (选择: 上/下方向键 确定: 回车键) "); #region 使用动态加载 //Subject result = new Selector<Subject>( // new List<String>() // { // "C语言任课老师", // "C++任课老师", // "C#任课老师", // "HTML/Css任课老师", // "Java任课老师", // "SQL数据库任课老师" // }, // new Subject[] // { // Subject.C, // Subject.CPlusPlus, // Subject.CSharp, // Subject.HtmlAndCss, // Subject.Java, // Subject.SQL // } // ).GetSubject(); #endregion dynamic dm = Client.GetSelectorObject( info: new List <string> { "C语言任课老师", "C++任课老师", "C#任课老师", "HTML/Css任课老师", "Java任课老师", "SQL数据库任课老师" }, selects: new[] { Subject.C, Subject.CPlusPlus, Subject.CSharp, Subject.HtmlAndCss, Subject.Java, Subject.Sql }) ?? throw new NullReferenceException(); Subject result = dm.GetSelect(); Write("账号: "); string account = ReadLine(); if (account.Contains(" ") || account.Equals(string.Empty)) { throw new NullReferenceException("Account is Empty"); } if (Client.CheckAccountAvailability(account) != null) { DisplayTheInformationOfErrorCode(ErrorCode.AccountAlreadyExists, account); return; } Write("密码: "); string passwd = EnterPasswd(); if (passwd.Contains(" ") || passwd.Equals(string.Empty)) { throw new NullReferenceException("Passwd is Empty"); } Write("姓名: "); string name = ReadLine(); WriteLine("此用户从哪一年开始从事该行业?"); Write("> "); if (!int.TryParse(ReadLine(), out int years)) { throw new ArgumentException(); } UserRepository.TeacherLibrary.Add(new Instructor(account, passwd, name, years, result)); UserRepository.HeadTeacherUser.AddHistory(new Message("你", $"注册了一个教师账户({account})")); ht.ReleaseNewMsg(new Message("班主任", $"班里来了一位新老师({account}), 快去看看吧~")); DisplayTheInformationOfSuccessfully(); }
/// <summary> /// 交互(班主任用户) /// </summary> /// <param name="headTeacher"></param> /// <returns>用户对象</returns> private static UserCore RunForHeadTeacher(HeadTeacher headTeacher) { ForegroundColor = ConsoleColor.Yellow; string input = ReadLine(); ForegroundColor = ConsoleColor.Blue; if (string.IsNullOrWhiteSpace(input)) { return(null); } if (GetCmd(input, out Command cmd) == null) { return(null); } UserCore result = null; switch (cmd) { case Command.Exit: case Command.SwitchUser: case Command.GetHelp: case Command.ShowMe: case Command.ChangePasswd: case Command.ChangeAge: case Command.ChangeAddress: case Command.ChangeSex: case Command.ViewMyHistory: case Command.ViewCurriculums: case Command.LeaveAMessage: case Command.ViewLeaveMessages: case Command.UrlTest: //case Command.ViewHeadTeacher: result = RunForUser(headTeacher, cmd); break; case Command.ChangeName: headTeacher.ChangeMyName(); break; case Command.ChangeNameOfThisUser: headTeacher.ChangeNameOfOtherUser(); break; case Command.AddStudent: headTeacher.CallAddStudent(); break; case Command.AddTeacher: headTeacher.CallAddTeacher(); break; case Command.Remove: headTeacher.RemoveAccount(); break; case Command.StudentsPreview: Ui.DisplayStudentList(); break; case Command.TeachersPreview: headTeacher.DisplayTeacherList(); break; case Command.AllScore: headTeacher.DisplayAllScoreOfStudent(); break; case Command.AllScoreAndRank: headTeacher.DisplayAllScoreOfStudent(State.On, State.On); break; case Command.HighThan: headTeacher.DisplayScoreHighThan(); break; case Command.ReleaseNewCurriculum: headTeacher.AddNewCurriculum(); break; case Command.ReleaseAMsg: headTeacher.ReleaseNewMessage(); break; default: Ui.DisplayTheInformationOfErrorCode(ErrorCode.NotACommand, input); break; } return(result); }