Example #1
0
        public string ArrCourse()
        {
            try
            {
                var id = Request["Id"];
                var entity = unitOfWork.SchedulingPlanBLL.GetEntityByID(new Guid(id));

                TimeSpan span =(TimeSpan)(entity.EndTime-entity.StartTime);

                var schedulModel = unitOfWork.SchedulingModelBLL.GetEntitys(m => m.OrgId == entity.OrgId&&m.ClassNo==entity.ClassNo).OrderBy(m=>m.ShowOrder);
                if (!schedulModel.Any())
                {
                    return "未找到教研室:" + entity.OrgName + ",班级:"+entity.ClassNo+" 的课表信息,无法排课!请先在课表信息中维护该教研室课表信息!";
                }
                unitOfWork.SchedulingDetailBLL.DeleteEntity(m => m.ParentId == entity.Id);
                var num = 0;
                var n = 0;
                for (int i = 0; i < span.Days; i++)
                {
                    var peDay = "";
                    peDay = schedulModel.ToArray()[num].TheDay;
                    for(int k=0; k<4;k++)
                    {
                        var model = new SchedulingDetail();
                        if (num > schedulModel.Count() - 1) break;
                        if (peDay == schedulModel.ToArray()[num].TheDay)
                        {
                            var schModel = schedulModel.ToArray()[num];
                            model.ClassNo = entity.ClassNo;
                            model.HeadmasterId = entity.HeadmasterId;
                            model.HeadmasterName = entity.HeadmasterName;
                            model.ClassDate = Convert.ToDateTime(entity.StartTime).AddDays(i);
                            model.UseTime = schModel.UseTime;
                            model.WeekInfo = GetDayOfWeek(Convert.ToDateTime(model.ClassDate));
                            model.CourseName = schModel.CourseName;
                            model.CourseId = schModel.CourseId;
                            model.ClassTime = schModel.ClassTime;
                            model.ClassRoomNo = schModel.ClassRoomNo;
                            model.ClassRoomId = schModel.ClassRoomId;
                            model.TeacherNames = schModel.TeacherNames;
                            model.TeacherIds = schModel.TeacherIds;
                            model.ParentId = entity.Id;
                            model.ParentName = entity.Name;
                            model.CreateId = CurrentUser.UserId;
                            model.CreateName = CurrentUser.UserName;
                            model.CreateTime = System.DateTime.Now;
                            model.IsValid = true;
                            model.ShowOrder = n;
                            model.Id = Guid.NewGuid();
                            unitOfWork.SchedulingDetailBLL.InsertEntity(model);
                            n++;
                            num++;
                            unitOfWork.Save();
                        }
                        else
                        {
                            break;
                        }
                    }

                }

            }
            catch (Exception ex)
            {
                Log.Error("排课失败:" + ex.Message, ex);
                return "排课失败:" + ex.Message;
            }
            return "";
        }
Example #2
0
        public string Addc()
        {
            var pid = new Guid(Request["pid"]);

            string classNo = Request["ClassNo"];
            string headmasterName = Request["HeadmasterName"];
            string headmasterId = Request["HeadmasterId"];
            string classDate = Request["ClassDate"];
            string courseName = Request["CourseName"];
            string courseId = Request["CourseId"];
            string classTime = Request["ClassTime"];
            string classRoomNo = Request["ClassRoomNo"];
            string classRoomId = Request["ClassRoomId"];
            string teacherNames = Request["TeacherNames"];
            string teacherIds = Request["TeacherIds"];
            string parentName = Request["ParentName"];
            string useTime = Request["UseTime"];
            var model = new SchedulingDetail();
            model.Id = Guid.NewGuid();
            model.ClassNo = classNo;
            model.HeadmasterId = new Guid(headmasterId);
            model.HeadmasterName = headmasterName;
            model.ClassDate = Convert.ToDateTime(classDate);
            model.UseTime = useTime;
            model.WeekInfo = GetDayOfWeek(Convert.ToDateTime(model.ClassDate));
            model.CourseName = courseName;
            model.CourseId = new Guid(courseId);
            model.ClassTime = classTime;
            model.ClassRoomNo = classRoomNo;
            model.ClassRoomId =new Guid(classRoomId);
            model.TeacherNames = teacherNames;
            model.TeacherIds = teacherIds;
            model.ParentId = pid;
            model.ParentName = parentName;
            model.CreateId = CurrentUser.UserId;
            model.CreateName = CurrentUser.UserName;
            model.CreateTime = System.DateTime.Now;
            model.IsValid = true;
            try
            {
                // var cd = Convert.ToDateTime(classDate);
                Expression<Func<SchedulingDetail, bool>> where = PredicateExtensionses.True<SchedulingDetail>();
                where = where.And(m => m.ClassTime == classTime && m.ClassDate == model.ClassDate && m.ClassRoomNo == classRoomNo);
                var models = unitOfWork.SchedulingDetailBLL.GetEntitys(where);
                if (models.Any())  //时间一样,教室一样
                {
                    return "同时间的教室已被占用,占用班级:" + models.ToArray()[0].ClassNo;
                }

                Expression<Func<SchedulingDetail, bool>> where1 = PredicateExtensionses.True<SchedulingDetail>();
                where1 = where1.And(m => m.ClassTime == classTime && m.ClassDate == model.ClassDate && m.TeacherNames == teacherNames);
                var models1 = unitOfWork.SchedulingDetailBLL.GetEntitys(where1);

                if (models1.Any())  //时间一样,培训师一样
                {
                    return "同时间的老师已有课程安排,已安排班级:" + models1.ToArray()[0].ClassNo;
                }

                Expression<Func<SchedulingDetail, bool>> where2= PredicateExtensionses.True<SchedulingDetail>();
                where2 = where2.And(m => m.ClassTime == classTime && m.ClassDate == model.ClassDate && m.ClassNo == classNo);
                var models2 = unitOfWork.SchedulingDetailBLL.GetEntitys(where2);

                if (models2.Any())  //时间一样,班级一样
                {
                    return "同时间的班级已有课程安排,已安排课程:" + models1.ToArray()[0].CourseName;
                }

                unitOfWork.SchedulingDetailBLL.InsertEntity(model);
                unitOfWork.Save();
                return "";
            }
            catch (Exception ex)
            {
                Log.Error("保存排班计划信息异常:" + ex.Message, ex);
                return "系统异常,请联系管理员!";
            }
        }
Example #3
0
        private string SchedulingDetailImport(DataTable dt, string filename)
        {
            if (dt != null)
            {
                DateTime preDate=DateTime.MinValue;
                foreach (DataRow row in dt.Rows)
                {
                    //日期	时间	培训班名称	班级编号	班主任	科目	培训师	课时	教室

                    SchedulingDetail model;
                    DateTime classDate=DateTime.MinValue;
                    if (!string.IsNullOrEmpty(row["日期"].ToString()))
                    {
                        classDate = Convert.ToDateTime(row["日期"].ToString());
                        preDate = classDate;
                    }
                    else
                    {
                        if (preDate != DateTime.MinValue)
                        {
                            classDate = preDate;
                        }
                    }

                    var classTime = row["时间"].ToString();
                    var classRoom = row["教室"].ToString();
                    var weekinfo = "";
                    if (classDate != DateTime.MinValue)
                    {
                       weekinfo = GetDayOfWeek(classDate);
                    }
                    var modeles = unitOfWork.SchedulingDetailBLL.GetEntitys(m => m.IsValid && m.ClassDate == classDate
                        && m.ClassTime == classTime &&m.ClassRoomNo == classRoom);
                    if (modeles.Any()) //冲突了更新
                    {
                        model = modeles.ToArray()[0];
                        model.ParentName = row["培训班名称"].ToString();
                        model.ParentId = unitOfWork.SchedulingPlanBLL.GetIdFromName(model.ParentName);
                        model.ClassNo = row["班级编号"].ToString();
                        model.HeadmasterName = row["班主任"].ToString();
                        model.HeadmasterId = unitOfWork.HeadmasterBLL.GetIdFromName(model.HeadmasterName);
                        model.CourseName = row["科目"].ToString();
                        model.CourseId = unitOfWork.CourseInfoBLL.GetIdFromName(model.CourseName);
                        model.TeacherNames = row["培训师"].ToString();
                        model.TeacherIds = unitOfWork.TeacherBLL.GetIdFromName(model.TeacherNames).ToString();
                        model.UseTime = row["课时"].ToString();
                        model.LastModifyTime = System.DateTime.Now;
                        model.LastModifyId = CurrentUser.UserId;
                        model.LastModifyName = CurrentUser.UserName;
                        model.WeekInfo = weekinfo;
                        model.IsValid = true;
                        unitOfWork.SchedulingDetailBLL.UpdateEntity(model);
                    }
                    else
                    {
                        model = new SchedulingDetail();
                        model.ClassDate = classDate;
                        model.ClassTime = classTime;
                        model.ClassRoomNo = classRoom;
                        model.ClassRoomId = unitOfWork.ClassRoomBLL.GetIdFromName(model.ClassRoomNo);
                        model.ParentName = row["培训班名称"].ToString();
                        model.ParentId = unitOfWork.SchedulingPlanBLL.GetIdFromName(model.ParentName);
                        model.ClassNo = row["班级编号"].ToString();
                        model.HeadmasterName = row["班主任"].ToString();
                        model.HeadmasterId = unitOfWork.HeadmasterBLL.GetIdFromName(model.HeadmasterName);
                        model.CourseName = row["科目"].ToString();
                        model.CourseId = unitOfWork.CourseInfoBLL.GetIdFromName(model.CourseName);
                        model.TeacherNames = row["培训师"].ToString();
                        model.TeacherIds = unitOfWork.TeacherBLL.GetIdFromName(model.TeacherNames).ToString();
                        model.UseTime = row["课时"].ToString();
                        model.WeekInfo = weekinfo;
                        model.Id = Guid.NewGuid();
                        model.CreateTime = System.DateTime.Now;
                        model.CreateId = CurrentUser.UserId;
                        model.CreateName = CurrentUser.UserName;
                        model.IsValid = true;
                        unitOfWork.SchedulingDetailBLL.InsertEntity(model);
                    }
                }
                unitOfWork.Save();
            }

            return "";
        }