public string updateProfessor(string ProName, int ProID, string ProTitle, int ProMaxNum, string ProInfoUrl, int ProNum) { SsContext ss = new SsContext(); List <Professor> list = ss.Professors.Where(s => s.ProID == ProID).ToList(); if (list.Count <= 0) { return("未知错误"); } Professor p = list[0]; p.ProID = ProID; p.ProInfoUrl = ProInfoUrl; p.ProMaxNum = ProMaxNum; p.ProName = ProName; p.ProNum = ProNum; if (ProTitle.Equals("讲师")) { p.ProTitle = 0; } else if (ProTitle.Equals("副教授")) { p.ProTitle = 1; } else if (ProTitle.Equals("教授")) { p.ProTitle = 2; } ss.SaveChanges(); return("成功"); }
public string deleteProfessorToStudent(int pid, string StuID) { try { SsContext db = new SsContext(); ProfessorToStudent ps = db.ProfessorToStudents.Find(pid, StuID); ProfessorToStudent pts = new ProfessorToStudent(); List <Professor> plist = db.Professors.Where(s => s.ProID == pid).ToList(); if (plist[0].ProNum > 0) { plist[0].ProNum--; } if (plist.Count <= 0) { return("未知错误"); } db.ProfessorToStudents.Remove(ps); db.SaveChanges(); } catch (Exception e) { return("操作失败"); } return("操作成功"); }
public bool addProfessor(int UserID, int ProID, string ProName, int ProTitle, string ProInfoUrl, int ProNum, int ProMaxNum) { Professor p = new Professor(); p.ProID = ProID; p.ProInfoUrl = ProInfoUrl; p.ProMaxNum = ProMaxNum; p.ProName = ProName; p.ProNum = ProNum; p.ProTitle = ProTitle; p.UserID = UserID; SsContext db = new SsContext(); try { db.Professors.Add(p); db.SaveChanges(); }catch (Exception e) { db = null; return(false); } db = null; return(true); }
internal string creatSetting(DateTime InfoStart, DateTime InfoEnd, DateTime FirstStart, DateTime FirstEnd, DateTime SecondStart, DateTime SecondEnd) { try { SsContext db = new SsContext(); List <Settings> list = db.Settingss.ToList(); Settings s; if (list.Count == 0) { s = new Settings(); s.FirstEnd = FirstEnd; s.FirstStart = FirstStart; s.InfoEnd = InfoEnd; s.InfoStart = InfoStart; s.SecondEnd = SecondEnd; s.SecondStart = SecondStart; db.Settingss.Add(s); } else { s = list[0]; s.FirstEnd = FirstEnd; s.FirstStart = FirstStart; s.InfoEnd = InfoEnd; s.InfoStart = InfoStart; s.SecondEnd = SecondEnd; s.SecondStart = SecondStart; } db.SaveChanges(); }catch (Exception e) { return(e.Message); } return("success"); }
public bool addJiaoWu(string JiaoWuName, int JiaoWuID, int JiaoWuMajorID) { SsContext db = new SsContext(); JiaoWu j = new JiaoWu(); j.UserID = addUser(JiaoWuName, 1, JiaoWuID.ToString()); j.JiaoWuID = JiaoWuID; j.JiaoWuMajorID = JiaoWuMajorID; j.JiaoWuName = JiaoWuName; db.JiaoWus.Add(j); db.SaveChanges(); return(true); }
public bool deleteUserById(int id) { try { SsContext db = new SsContext(); User p = db.Users.Find(id); db.Users.Remove(p); db.SaveChanges(); } catch (Exception e) { return(false); } return(true); }
public bool changePassword(int type, string id, string password) { int userId; SsContext db = new SsContext(); if (type == 2) { Professor p = getProfessorByPid(int.Parse(id)); userId = p.UserID; } else if (type == 3) { Student s = getStudentBySid(id); userId = s.UserID; } else if (type == 1) { if (getJiaoWuByJId(Int32.Parse(id)).Count > 0) { userId = getJiaoWuByJId(Int32.Parse(id))[0].UserID; } else { userId = -1; } } else { userId = int.Parse(id); } User u = db.Users.Find(userId); if (u != null) { try { u.UserPassword = password; db.SaveChanges(); return(true); }catch (Exception e) { return(false); } } return(false); }
internal string batchAddStudents(List <Student> listStudents) { string rel = ""; int num = 0; List <Student> list; int userId; try { SsContext db = new SsContext(); foreach (Student p in listStudents) { list = db.Students.Where(s => s.StuID == p.StuID).ToList(); if (list.Count > 0) { num++; } else { userId = addUser(p.StuName, 3, p.StuID.ToString()); if (userId != -1) { p.UserID = userId; db.Students.Add(p); } } } db.SaveChanges(); } catch (Exception e) { return(e.Message); } if (num > 0) { rel = "error:共操作" + listStudents.Count + "个数据,其中" + num + "个失败,可能存在重复的数据。"; } else { rel = "success:共操作" + listStudents.Count + "个数据,其中" + num + "个失败。"; } return(rel); }
public bool addStudent(string StuName, string StuID, int Age, int StuMajorID, string StuTel, string StuMail, bool StuIfWork) { SsContext db = new SsContext(); Student s = new Student(); s.UserID = addUser(StuName, 3, StuID.ToString()); s.StuID = StuID; s.StuName = StuName; s.Age = Age; s.StuMajorID = StuMajorID; s.StuTel = StuTel; s.StuMail = StuMail; s.StuIfWork = StuIfWork; db.Students.Add(s); db.SaveChanges(); return(true); }
public bool studentConfirm(string id) { SsContext db = new SsContext(); List <Student> list = db.Students.Where(s => s.StuID == id).ToList(); if (list.Count <= 0) { return(false); } else { Student s = list[0]; s.StuInfoChecked = true; db.SaveChanges(); return(true); } }
public bool saveResumeUrl(string id, string path) { SsContext db = new SsContext(); List <Student> list = db.Students.Where(s => s.StuID == id).ToList(); if (list.Count <= 0) { return(false); } else { Student s = list[0]; s.StuResumeUrl = path; db.SaveChanges(); return(true); } }
public bool studentConfirmWill(string id, int first, int second) { SsContext db = new SsContext(); List <Student> list = db.Students.Where(s => s.StuID == id).ToList(); if (list.Count <= 0) { return(false); } else { Student s = list[0]; s.StuFirstWill = first; s.StuSecondWill = second; db.SaveChanges(); return(true); } }
public string addProfessorToStudent(int pid, string StuID) { SsContext db = new SsContext(); try { ProfessorToStudent pts = new ProfessorToStudent(); List <Professor> plist = db.Professors.Where(s => s.ProID == pid).ToList(); if (plist.Count <= 0) { return("未知错误"); } Professor p = plist[0]; int num = db.ProfessorToStudents.Where(s => s.ProID == pid).ToList().Count; if (num >= p.ProMaxNum || p.ProNum >= p.ProMaxNum) { return("选择学生数已达最大值"); } if (p.ProNum < p.ProMaxNum) { p.ProNum++; } pts.ProID = pid; pts.StuID = StuID; db.ProfessorToStudents.Add(pts); db.SaveChanges(); }catch (Exception e) { ProfessorToStudent p = db.ProfessorToStudents.Find(pid, StuID); if (p == null) { return("操作失败"); } else { return("操作成功"); } } return("操作成功"); }
internal int addUser(string UserName, int RoleID, string password) { User t; try { SsContext db = new SsContext(); User u = new User(); u.UserName = UserName; u.UserPassword = password; u.RoleID = RoleID; t = db.Users.Add(u); db.SaveChanges(); t = db.Users.ToArray()[db.Users.Count() - 1]; } catch (Exception e) { return(-1); } return(t.UserID); }
public bool deleteJiaoWuById(int id) { try { SsContext db = new SsContext(); List <JiaoWu> ps = db.JiaoWus.Where(s => s.UserID == id).ToList(); JiaoWu p = null; for (int i = 0; i < ps.Count; i++) { p = ps[i]; db.JiaoWus.Remove(p); } deleteUserById(id); db.SaveChanges(); } catch (Exception e) { return(false); } return(true); }
public bool deleteStudentById(int id) { try { SsContext db = new SsContext(); List <Student> ss = db.Students.Where(s => s.UserID == id).ToList(); Student student = null; for (int i = 0; i < ss.Count; i++) { student = ss[i]; db.Students.Remove(student); } deleteUserById(id); db.SaveChanges(); } catch (Exception e) { return(false); } return(true); }
public string changeStudentInfo(string StuName, string StuID, int Age, int StuMajorID, string StuTel, bool StuIfWork, string StuMail) { SsContext db = new SsContext(); string rel = ""; List <Student> list = db.Students.Where(s => s.StuID == StuID).ToList(); if (list.Count < 1) { rel = "不存在此学生"; } else { Student s = list[0]; s.Age = Age; s.StuMajorID = StuMajorID; s.StuTel = StuTel; s.StuIfWork = StuIfWork; s.StuMail = StuMail; db.SaveChanges(); rel = "成功"; } return(rel); }
public bool updateStudent(string StuName, string StuID, int Age, int StuMajorID, string StuTel, string StuMail, bool StuIfWork, string StuGraSchool, string StuGraMajor) { SsContext db = new SsContext(); List <Student> list = db.Students.Where(s => s.StuID == StuID).ToList(); if (list.Count <= 0) { return(false); } else { Student s = list[0]; s.Age = Age; s.StuMajorID = StuMajorID; s.StuTel = StuTel; s.StuMail = StuMail; s.StuIfWork = StuIfWork; s.StuGraSchool = StuGraSchool; s.StuGraMajor = StuGraMajor; db.SaveChanges(); return(true); } }
public bool addProfessor(int ProID, string ProName, string ProTitle, string ProInfoUrl, int ProNum, int ProMaxNum) { Professor p = new Professor(); p.ProID = ProID; p.ProInfoUrl = ProInfoUrl; p.ProMaxNum = ProMaxNum; p.ProName = ProName; p.ProNum = ProNum; if (ProTitle.Equals("讲师")) { p.ProTitle = 0; } else if (ProTitle.Equals("副教授")) { p.ProTitle = 1; } else if (ProTitle.Equals("教授")) { p.ProTitle = 2; } SsContext db = new SsContext(); try { p.UserID = addUser(p.ProName, 2, p.ProID.ToString()); db.Professors.Add(p); db.SaveChanges(); } catch (Exception e) { db = null; return(false); } db = null; return(true); }
/** * index 1 为StuFirstWillStates , 2为StuSecondWillStates * * * * */ public bool changeStudentWilleState(int pid, string StuID, int index, int value) { SsContext db = new SsContext(); List <Student> list = db.Students.Where(s => s.StuID == StuID).ToList(); if (list.Count <= 0) { return(false); } Student student = list[0]; if (index == 1) { student.StuFirstWillStates = value; } else if (index == 2) { student.StuSecondWillStates = value; } if (value == 0) { student.StuFinalWill = 0; } else { deleteProfessorToStudent(student.StuFinalWill, StuID); addProfessorToStudent(pid, StuID); student.StuFinalWill = pid; } db.SaveChanges(); return(true); }