public string AddModel() { string theDay = Request["TheDay"]; string classTime = Request["ClassTime"]; string useTime = Request["UseTime"]; string courseName = Request["CourseName"]; string courseId = Request["CourseId"]; string orgId = Request["OrgId"]; string orgName = Request["OrgName"]; string classRoomNo = Request["ClassRoomNo"]; string classRoomId = Request["ClassRoomId"]; string teacherNames = Request["TeacherNames"]; string teacherIds = Request["TeacherIds"]; var model = new SchedulingModel(); model.Id = Guid.NewGuid(); model.TheDay = theDay; model.ClassTime = classTime; model.UseTime = useTime; model.CourseName = courseName; model.CourseId = new Guid(courseId); model.ClassRoomNo = classRoomNo; model.ClassRoomId =new Guid(classRoomId); model.TeacherNames = teacherNames; model.TeacherIds = teacherIds; model.OrgId = orgId; model.OrgName = orgName; model.CreateId = CurrentUser.UserId; model.CreateName = CurrentUser.UserName; model.CreateTime = System.DateTime.Now; model.IsValid = true; try { Expression<Func<SchedulingModel, bool>> where = PredicateExtensionses.True<SchedulingModel>(); where = where.And(m => m.OrgId == model.OrgId && m.TheDay == model.TheDay && m.ClassTime == classTime && m.ClassRoomNo == classRoomNo); var models = unitOfWork.SchedulingModelBLL.GetEntitys(where); if (models.Any()) //时间一样,教室一样 { return "同时间的信息已存在:" + models.ToArray()[0].TheDay; } unitOfWork.SchedulingModelBLL.InsertEntity(model); unitOfWork.Save(); return ""; } catch (Exception ex) { Log.Error("保存课表信息异常:" + ex.Message, ex); return "系统异常,请联系管理员!"; } }
private string SchedulingModelImport(DataTable dt, string filename) { if (dt != null) { string preDate=string.Empty; int i = 0; foreach (DataRow row in dt.Rows) { //天数 时间 班级 科目 课时 培训师 教室 教研室 i++; SchedulingModel model; string theDay = string.Empty; if (!string.IsNullOrEmpty(row["天数"].ToString())) { theDay =row["天数"].ToString(); preDate = theDay; } else { if (!string.IsNullOrEmpty(preDate)) { theDay = preDate; } } var classTime = row["时间"].ToString(); var classNo = row["班级"].ToString(); var classRoom = row["教室"].ToString(); var orgName= row["教研室"].ToString(); var modeles = unitOfWork.SchedulingModelBLL.GetEntitys(m => m.IsValid && m.TheDay == theDay && m.OrgName == orgName && m.ClassRoomNo == classRoom && m.ClassTime.Equals(classTime)); if (modeles.Any()) //冲突了更新 { model = modeles.ToArray()[0]; model.TheDay = theDay; model.ClassTime = classTime; model.CourseName = row["科目"].ToString(); model.CourseId = unitOfWork.CourseInfoBLL.GetIdFromName(model.CourseName); model.UseTime = row["课时"].ToString(); model.TeacherNames = row["培训师"].ToString(); model.TeacherIds = unitOfWork.TeacherBLL.GetIdFromName(model.TeacherNames).ToString(); model.ClassRoomNo = classRoom; model.ClassRoomId = unitOfWork.ClassRoomBLL.GetIdFromName(model.ClassRoomNo); model.OrgId = unitOfWork.SysCodeBLL.GetCodeFromName(orgName); model.OrgName = orgName; model.ClassNo = classNo; model.LastModifyTime = System.DateTime.Now; model.LastModifyId = CurrentUser.UserId; model.LastModifyName = CurrentUser.UserName; model.IsValid = true; unitOfWork.SchedulingModelBLL.UpdateEntity(model); } else { model = new SchedulingModel(); model.TheDay = theDay; model.ClassTime = classTime; model.CourseName = row["科目"].ToString(); model.CourseId = unitOfWork.CourseInfoBLL.GetIdFromName(model.CourseName); model.UseTime = row["课时"].ToString(); model.TeacherNames = row["培训师"].ToString(); model.TeacherIds = unitOfWork.TeacherBLL.GetIdFromName(model.TeacherNames).ToString(); model.ClassRoomNo = classRoom; model.ClassRoomId = unitOfWork.ClassRoomBLL.GetIdFromName(model.ClassRoomNo); model.OrgId = unitOfWork.SysCodeBLL.GetCodeFromName(orgName); model.OrgName = orgName; model.ClassNo = classNo; model.Id = Guid.NewGuid(); model.CreateTime = System.DateTime.Now; model.CreateId = CurrentUser.UserId; model.CreateName = CurrentUser.UserName; model.IsValid = true; model.ShowOrder = i; unitOfWork.SchedulingModelBLL.InsertEntity(model); } } unitOfWork.Save(); } return ""; }