/// <summary> /// 增加一个教师 /// </summary> /// <param name="teacher"></param> /// <returns></returns> public bool Addteacher(Teacher teacher) { teacher.Tpassword = "******"; if (Check(teacher) == null) { using (var dbcontext = new srContext()) { var value = dbcontext.Teacher.FirstOrDefault(u => u.Tno == teacher.Tno); if (value == null) { if (teacher.Tsex == "男" || teacher.Tsex == "女") { dbcontext.Teacher.Add(teacher); dbcontext.SaveChanges(); return(true); } else { return(false); } } else { return(false); } } } else { return(false); } }
/// <summary> /// 删除一门课程 /// </summary> /// <param name="value"></param> public void Delete(string value) { List <Score> scores = new List <Score>(); using (var dbcontext = new srContext()) { var course = dbcontext.Course.FirstOrDefault(c => c.Cno == value); foreach (var infor in dbcontext.Score)//在数据库中通过课程编号查找成绩 { if (infor.Cno == value) { scores.Add(infor); } } if (scores != null) { foreach (var infor in scores) { dbcontext.Score.Remove(infor); } } dbcontext.Course.Remove(course); dbcontext.SaveChanges(); } }
public IActionResult Insertcer(Certificate certificate) { if (certificate.Sno == null || certificate.Cerno == null || certificate.Cername == null || certificate.Cerdate == null || certificate.Certype == null || certificate.Cercompany == null) { return(Content("<script>alert('录入失败');history.go(-1);</script>", "text/html;charset=UTF-8")); } else { using (var dbcontext = new srContext()) { var infor = dbcontext.Student.FirstOrDefault(u => u.Sno == certificate.Sno); if (infor == null) { return(Content("<script>alert('录入失败,该学生不存在');history.go(-1);</script>", "text/html;charset=UTF-8")); } else { var value = dbcontext.Certificate.FirstOrDefault(C => C.Cerno == certificate.Cerno && C.Sno == certificate.Sno); if (value == null) { infor.Certificate.Add(certificate); dbcontext.SaveChanges(); return(Content("<script>alert('录入成功');window.location.href='../Teacher/Pirntcer';</script>", "text/html;charset=UTF-8")); } else { return(Content("<script>alert('录入失败,请勿录入同编号证书');history.go(-1);</script>", "text/html;charset=UTF-8")); } } } } }
/// <summary> /// 学生选课 /// </summary> /// <param name="course"></param> /// <returns></returns> public IActionResult Insertcourse(Course course) { StudentMethod userfunction = new StudentMethod(); this.Request.Cookies.TryGetValue("Sno", out string value); var score = new Score { Cno = course.Cno, Sno = value }; using (var dbcontext = new srContext()) { var infor = dbcontext.Score.FirstOrDefault(u => u == score); if (infor != null) { return(Content("<script>alert('选课失败,请勿重复选课');history.go(-1);</script>", "text/html;charset=UTF-8")); } else { Student student = dbcontext.Student.FirstOrDefault(u => u.Sno == value); student.Score.Add(score); dbcontext.SaveChanges(); return(Content("<script>alert('选课成功');window.location.href='/Student/Showcourses';</script>", "text/html;charset=UTF-8")); } } }
/// <summary> /// 退课 /// </summary> /// <param name="stu_id"></param> /// <param name="cou_id"></param> /// <returns></returns> public void Delscore(string stu_id, string cou_id) { using (var dbcontext = new srContext()) { var infor = dbcontext.Score.FirstOrDefault(u => u.Sno == stu_id && u.Cno == cou_id); dbcontext.Score.Remove(infor); dbcontext.SaveChanges(); } }
/// <summary> /// 删除一条老师授课信息 /// </summary> /// <param name="Tid"></param> /// <param name="Cid"></param> /// <returns></returns> public void DelTC(string Tid, string Cid) { using (var db = new srContext()) { var value = db.Teachercourse.FirstOrDefault(t => t.Cno == Cid && t.Tno == Tid); db.Teachercourse.Remove(value); db.SaveChanges(); } }
public IActionResult ChangeInfor(Teacher teacher) { using (var dbcontext = new srContext()) { var temp = dbcontext.Teacher.FirstOrDefault(s => s.Tno == teacher.Tno); temp.Tphone = teacher.Tphone; dbcontext.SaveChanges(); } return(RedirectToAction("Detail", "Teacher")); }
public IActionResult ChangeInfor(Student student) { using (var dbcontext = new srContext()) { var temp = dbcontext.Student.FirstOrDefault(s => s.Sno == student.Sno); temp.Sphone = student.Sphone; temp.Saddress = student.Saddress; dbcontext.SaveChanges(); } return(RedirectToAction("Detail", "Student")); }
/// <summary> /// 增加一条老师授课信息 /// </summary> /// <param name="Tid"></param> /// <param name="Cid"></param> /// <returns></returns> public bool AddTC(string Tid, string Cid) { using (var db = new srContext()) { var value = db.Teachercourse.FirstOrDefault(t => t.Cno == Cid && t.Tno == Tid); if (value != null) { return(false); } else { var TC = new Teachercourse { Tno = Tid, Cno = Cid }; db.Teachercourse.Add(TC); db.SaveChanges(); return(true); } } }
/// <summary> /// 增加一门课程 /// </summary> /// <param name="course"></param> /// <returns></returns> public bool Addcourse(Course course) { if (Check(course) == null) { using (var dbcontext = new srContext()) { var infor = FindCourse(course.Cno); if (infor == null) { dbcontext.Course.Add(course); dbcontext.SaveChanges(); return(true); } else { return(false); } } } else { return(false); } }
public IActionResult ChangePasw(Administrator admin, string newpwd, string rcnewpwd) { using (var dbcontext = new srContext()) { var temp = dbcontext.Administrator.FirstOrDefault(s => s.Ano == admin.Ano); if (temp.Apassword == admin.Apassword) { if (newpwd == rcnewpwd) { temp.Apassword = newpwd; dbcontext.SaveChanges(); return(RedirectToAction("Index", "Home")); } else { return(RedirectToAction("ChangePassword", "Administrator")); } } else { return(RedirectToAction("ChangePassword", "Administrator")); } } }
/// <summary> /// 按职工号删除教师 /// </summary> /// <param name="value"></param> public void Delete(string value) { using (var dbcontext = new srContext()) { var teacher = dbcontext.Teacher.FirstOrDefault(u => u.Tno == value); var TCs = new List <Teachercourse>(); foreach (var infor in dbcontext.Teachercourse) { if (infor.Tno == value) { TCs.Add(infor); } } if (TCs != null) { foreach (var infro in TCs) { dbcontext.Teachercourse.Remove(infro); } } dbcontext.Remove(teacher); dbcontext.SaveChanges(); } }
public IActionResult ChangePasw(Teacher teacher, string newpwd, string rcnewpwd) { using (var dbcontext = new srContext()) { var temp = dbcontext.Teacher.FirstOrDefault(u => u.Tno == teacher.Tno); if (temp.Tpassword == teacher.Tpassword) { if (newpwd == rcnewpwd) { temp.Tpassword = newpwd; dbcontext.SaveChanges(); return(RedirectToAction("Index", "Home")); } else { return(Content("<script>alert('修改失败');history.go(-1);</script>", "text/html;charset=UTF-8")); } } else { return(Content("<script>alert('原密码错误,修改失败');history.go(-1);</script>", "text/html;charset=UTF-8")); } } }
public IActionResult Insertcet(Cet cet) { if (cet.Sno == null || cet.Etype == null || cet.Egade == null) { return(Content("<script>alert('录入失败');history.go(-1);</script>", "text/html;charset=UTF-8")); } else { using (var dbcontext = new srContext()) { var infor = dbcontext.Student.FirstOrDefault(u => u.Sno == cet.Sno); if (infor == null) { return(Content("<script>alert('录入失败,该学生不存在');history.go(-1);</script>", "text/html;charset=UTF-8")); } else { infor.Cet.Add(cet); dbcontext.SaveChanges(); return(Content("<script>alert('录入成功');window.location.href='../Teacher/Pirntcet';</script>", "text/html;charset=UTF-8")); } } } }
/// <summary> /// 录入成绩 /// </summary> /// <param name="Sno"></param> /// <param name="Cno"></param> /// <param name="Grade"></param> /// <returns></returns> public bool InputScore(string Sno, string Cno, decimal?Grade) { if (Grade != null) { if (Grade > 100) { return(false); } else { using (var dbcontext = new srContext()) { var infor = dbcontext.Score.FirstOrDefault(u => u.Sno == Sno && u.Cno == Cno); infor.Grade = Grade; dbcontext.SaveChanges(); } return(true); } } else { return(false); } }