public string DropCourse(string sno, string cno) { string result = null; SelectCourseDBContext selectDbCourse = new SelectCourseDBContext(); SelectedCourse selectedCourse = new SelectedCourse(); SelectedCourseDBContext selectedDbCourse = new SelectedCourseDBContext(); var selectedResult = selectedDbCourse.SelectedCourses.Where(u => u.SNO == sno && u.CNO == cno).FirstOrDefault(); int id = selectedResult.ID; var deleteResult = selectedDbCourse.SelectedCourses.First(u => u.ID == id); selectedDbCourse.SelectedCourses.Remove(deleteResult); var selectResult = selectDbCourse.SelectCourses.Where(u => u.CNO == cno).FirstOrDefault(); selectedDbCourse.SaveChanges(); selectResult.SELECTEDNUM--; selectDbCourse.SaveChanges(); result = "退课成功!"; return(result); }
public string StudentSelectCourse(string sno, string cno, string cname, string tname, string cdept, string credit, string time) { string result = null; SelectCourseDBContext selectDbContext = new SelectCourseDBContext(); var message = selectDbContext.SelectCourses.Where(u => u.CNO == cno && u.CNAME == cname).FirstOrDefault(); SelectedCourseDBContext selectedDbContext = new SelectedCourseDBContext(); var isSelected = selectedDbContext.SelectedCourses.Where(u => u.CNO == cno && u.SNO == sno).FirstOrDefault(); var classTime = selectedDbContext.SelectedCourses.Where(u => u.SNO == sno).ToList(); if (message == null) { result = "该课程不存在,请核实该课程信息!"; } else if (message.SELECTEDNUM == message.CAPACITY) { result = "该课程所选人数已达人数上限!"; } else if (isSelected != null) { result = "您已经选过该课程!"; } else if (classTime != null) { if (IsConflict(classTime, time)) { result = "课时冲突"; } else { SelectedCourse selectedCourse = new SelectedCourse() { SNO = sno, CNO = cno, CNAME = cname, CREDIT = Convert.ToInt32(credit), CDEPT = cdept, TNAME = tname, TIME = time, SEMESTER = "15-16春" }; selectedDbContext.SelectedCourses.Add(selectedCourse); selectedDbContext.SaveChanges(); message.SELECTEDNUM++; selectDbContext.SaveChanges(); result = "选课成功!"; } } return(result); }
public string Dilatation(string classNumber, string className, string classCapacity) { string message = null; SelectCourseDBContext selectDbCourse = new SelectCourseDBContext(); var result = selectDbCourse.SelectCourses.Where(u => u.CNO == classNumber && u.CNAME == className).FirstOrDefault(); if (result == null) { message = "没有查到该课程!"; } else { int number = result.CAPACITY; result.CAPACITY = number + Convert.ToInt32(classCapacity); selectDbCourse.SaveChanges(); message = "扩容成功"; } return(message); }
public string AddCourse(string tno, string tname, string cno, string cname, string credit, string cdept, string time, string selectednum, string capacity) { string lastResult = null; BasicInfoDBContext basicDbInfo = new BasicInfoDBContext(); SelectCourse selectcourse; SelectCourseDBContext selectDbContext = new SelectCourseDBContext(); var result = basicDbInfo.Basics.Where(u => u.ID == tno && u.NAME == tname).FirstOrDefault(); //判断教师是否存在 //教师是否存在 if (result == null) { lastResult = "该教师不存在,请核实!"; } //教师存在 else { var teacherTeachCourse = selectDbContext.SelectCourses.Where(u => u.TNAME == tname).ToList(); //该教师自己课程间是否冲突 foreach (var t in teacherTeachCourse) { if (t.TIME.ToString().Trim() == time || t.CNO.ToString().Trim() == cno) { lastResult = "该教师课时或课号冲突,请重新确认!"; break; } } if (lastResult == null) { selectcourse = new SelectCourse() { CNO = cno, TNO = tno, CNAME = cname, CREDIT = Convert.ToInt32(credit), CDEPT = cdept, TNAME = tname, TIME = time, SELECTEDNUM = Convert.ToInt32(selectednum), CAPACITY = Convert.ToInt32(capacity) }; selectDbContext.SelectCourses.Add(selectcourse); selectDbContext.SaveChanges(); lastResult = "添加成功!"; } } return(lastResult); }