Example #1
0
        /// <summary>
        /// 迭代一个VcClsLesson的构成元素,包含组;不包含VcClsLesson自身和VcLesson
        /// </summary>
        private IEnumerable <BaseEntity> eachClsLsnComponent(EnClsLesson clsLsn)
        {
            yield return(clsLsn.Lesson.Course);

            foreach (EnCourseGroup crsGrp in DataRule.Crs.GetGroups(clsLsn.Lesson.Course))
            {
                yield return(crsGrp);
            }

            yield return(clsLsn.Squad);

            foreach (EnSquadGroup sqdGrp in DataRule.Sqd.GetGroups(clsLsn.Squad))
            {
                yield return(sqdGrp);
            }

            if (clsLsn.Teacher != null)
            {
                yield return(clsLsn.Teacher);

                foreach (EnTeacherGroup tchGrp in DataRule.Tch.GetGroups(clsLsn.Teacher))
                {
                    yield return(tchGrp);
                }
            }
        }
Example #2
0
        public IList <EnLsnAct> GetLsnActs(EnClsLesson ClsLsn)
        {
            IList <EnLsnAct> Result = new List <EnLsnAct>();

            foreach (EnLsnAct act in ClsLsns[ClsLsn.Id].Acts)
            {
                Result.Add(act);
            }

            return(Result);
        }
Example #3
0
        private void LoadClsLesson()
        {
            foreach (OleDbDataReader reader in ThisModule.OleDB.EachRows(
                         "select Id, FLesson, FSharedTime, FSquad, FTeacher"
                         + " from TClsLesson"))
            {
                EnClsLesson ClsLsn = new EnClsLesson();
                ClsLsn.Id         = Convert.ToInt64(reader[0]);
                ClsLsn.SharedTime = Convert.ToInt32(reader[2]);
                if (ClsLsn.SharedTime < 0 || ClsLsn.SharedTime > VcTimeLogic.cMaxSharedTime)
                {
                    ThisModule.ErrorLog.Error("VcClsLesson恢复错误:SharedTime越界"
                                              + "  ClsLsn: " + ClsLsn.SharedTime);
                    continue;
                }

                Int64        LsnId = Convert.ToInt64(reader[1]);
                LsnContainer LsnCnt;
                if (!Lsns.TryGetValue(LsnId, out LsnCnt))
                {
                    ThisModule.ErrorLog.Error("VcClsLesson恢复错误:ID对应的实体不存在  "
                                              + "  Lesson: " + LsnId);
                    continue;
                }
                ClsLsn.Lesson = LsnCnt.Lsn;

                ClsLsn.Squad = ThisModule.Sqd.MbrDAC.Get(Convert.ToInt64(reader[3]));
                if (ClsLsn.Squad == null)
                {
                    ThisModule.ErrorLog.Error("VcClsLesson恢复错误:ID对应的实体不存在  "
                                              + "  Squad: " + reader[3]);
                    continue;
                }

                Int64 TchID = Convert.ToInt64(reader[4]);
                if (TchID > 0)
                {
                    ClsLsn.Teacher = ThisModule.Tch.MbrDAC.Get(TchID);
                    if (ClsLsn.Teacher == null)
                    {
                        ThisModule.ErrorLog.Error("VcClsLesson恢复错误:ID对应的实体不存在  "
                                                  + "  Teacher: " + TchID);
                        continue;
                    }
                }

                LsnCnt.ClsLessons.Add(ClsLsn);
                ClsLsnContainer ClsLsnCnt = new ClsLsnContainer();
                ClsLsnCnt.ClsLsn = ClsLsn;
                ClsLsns.Add(ClsLsn.Id, ClsLsnCnt);
            }
        }
Example #4
0
        /// <summary>
        /// 生成班级课表的规则,应用clsLsn的规则并标记出教师授课冲突
        /// </summary>
        private void SetSqdScheduleListRule()
        {
            //没课的单元格必须设为eRule.common
            foreach (SqdSchedule sqdSch in SqdScheduleList.Values)
            {
                foreach (ScheduleNode node in sqdSch.Matrix.eachElement())
                {
                    node.Rule = eRule.common;
                }
            }

            DtMatrix <Boolean>             Times        = new DtMatrix <bool>(DataRule.Solution);
            IDictionary <EnTeacher, Int32> TchsClsCount = new Dictionary <EnTeacher, Int32>();

            foreach (VcTime time in Times.eachTime())
            {
                TchsClsCount.Clear();
                foreach (ScheduleNode schNode in eachEnabledScheduleNode(time))
                {
                    EnClsLesson clsLsn = schNode.LsnAct.ClsLesson;
                    schNode.Rule = ClsLsnRuleList[clsLsn][time];   //程序逻辑正常则必定存在

                    if (clsLsn.Teacher != null)
                    {
                        if (TchsClsCount.ContainsKey(clsLsn.Teacher))
                        {
                            TchsClsCount[clsLsn.Teacher]++;
                        }
                        else
                        {
                            TchsClsCount.Add(clsLsn.Teacher, 1);
                        }
                    }
                }

                foreach (KeyValuePair <EnTeacher, Int32> pair in TchsClsCount)
                {
                    if (pair.Value > 1)
                    {
                        foreach (ScheduleNode schNode in eachEnabledScheduleNode(time))
                        {
                            if (schNode.LsnAct.ClsLesson.Teacher == pair.Key)
                            {
                                schNode.Rule = eRule.crisscross;
                            }
                        }
                    }
                }
            }
        }
        public void SquadRelationIsCreate(EnSquadGroup grp, EnSquad mbr)
        {
            //增加班级与班级组关系后,此班级组的课务安排会自动应用到此班级
            IList <EnLesson> Lsns = GetLessons(grp);

            foreach (EnLesson lsn in Lsns)
            {
                EnClsLesson clsLsn = new EnClsLesson();
                clsLsn.Lesson     = lsn;
                clsLsn.SharedTime = lsn.SharedTime;
                clsLsn.Squad      = mbr;
                SaveClsLsnTree(clsLsn);
            }
        }
Example #6
0
        public EnClsLesson SaveClsLesson(EnClsLesson Value)
        {
            //这样更高效但难理解
            //foreach(VcClsLesson clsLsn in Lsns[Value.Lesson.Id].ClsLessons)
            //    if (clsLsn.Squad == Value.Squad)
            //    {
            //        ClsLsnContainer clsLsnCnt = ClsLsns[clsLsn.Id];

            foreach (ClsLsnContainer clsLsnCnt in this.ClsLsns.Values)
            {
                if (clsLsnCnt.ClsLsn.Squad == Value.Squad &&
                    clsLsnCnt.ClsLsn.Lesson.Id == Value.Lesson.Id)
                {
                    clsLsnCnt.ClsLsn.SharedTime = Value.SharedTime;
                    clsLsnCnt.ClsLsn.Teacher    = Value.Teacher;

                    ThisModule.OleDB.ExecuteNonQuery("update TClsLesson set "
                                                     + " FSharedTime = " + Value.SharedTime
                                                     + ", FTeacher = " + (Value.Teacher == null ? 0 : Value.Teacher.Id)
                                                     + " where Id = " + clsLsnCnt.ClsLsn.Id);

                    return(clsLsnCnt.ClsLsn);
                }
            }

            EnClsLesson ClsLsn = new EnClsLesson();

            ClsLsn.Lesson     = Lsns[Value.Lesson.Id].Lsn;
            ClsLsn.SharedTime = Value.SharedTime;
            ClsLsn.Squad      = Value.Squad;
            ClsLsn.Teacher    = Value.Teacher;
            ClsLsn.Id         = Convert.ToInt64(ThisModule.OleDB.InsertAndReturnId_MS("insert into TClsLesson"
                                                                                      + " (FLesson, FSharedTime, FSquad, FTeacher) values ("
                                                                                      + Value.Lesson.Id
                                                                                      + ", " + Value.SharedTime
                                                                                      + ", " + Value.Squad.Id
                                                                                      + ", " + (Value.Teacher == null ? 0 : Value.Teacher.Id)
                                                                                      + ")"));

            ClsLsnContainer clc = new ClsLsnContainer();

            clc.ClsLsn = ClsLsn;
            ClsLsns.Add(ClsLsn.Id, clc);
            Lsns[ClsLsn.Lesson.Id].ClsLessons.Add(ClsLsn);

            return(ClsLsn);
        }
Example #7
0
        public void DeleteClsLesson(EnClsLesson Value)
        {
            IList <EnClsLesson> clsLsns = Lsns[Value.Lesson.Id].ClsLessons;

            for (Int32 i = 0; i < clsLsns.Count; i++)
            {
                if (clsLsns[i].Id == Value.Id)
                {
                    clsLsns.RemoveAt(i);
                    break;
                }
            }

            ClsLsns.Remove(Value.Id);
            ThisModule.OleDB.ExecuteNonQuery("delete from TLsnAct where FClsLesson = " + Value.Id);
            ThisModule.OleDB.ExecuteNonQuery("delete from TClsLesson where Id = " + Value.Id);
        }
        internal void SaveClsLsnTree(EnClsLesson ClsLsn)
        {
            EnClsLesson clsLsn = ThisModule.Dac.Lsn.SaveClsLesson(ClsLsn);

            IList <EnLsnAct> Acts = ThisModule.Dac.Lsn.GetLsnActs(clsLsn);

            if (ClsLsn.SharedTime > Acts.Count)
            {
                IList <EnLsnAct> WAdd = new List <EnLsnAct>();
                for (Int32 i = 0; i < ClsLsn.SharedTime - Acts.Count; i++)
                {
                    EnLsnAct act = new EnLsnAct();
                    act.ClsLesson = clsLsn;
                    WAdd.Add(act);
                }
                ThisModule.Lsn.SaveLsnActs(WAdd);
            }
            else if (ClsLsn.SharedTime < Acts.Count)
            {
                //课时减少,优先移除时间无效的课
                IList <EnLsnAct> WDel      = new List <EnLsnAct>();
                Int32            WDelCount = Acts.Count - ClsLsn.SharedTime;

                foreach (EnLsnAct act in Acts)
                {
                    if (!act.Time.HasValue && WDel.Count < WDelCount)
                    {
                        WDel.Add(act);
                    }
                }

                foreach (EnLsnAct act in Acts)
                {
                    if (act.Time.HasValue && WDel.Count < WDelCount)
                    {
                        WDel.Add(act);
                    }
                }

                ThisModule.Dac.Lsn.DeleteLsnActs(WDel);
            }

            ThisModule.SendDataChanged();
        }
        public void Save()
        {
            //删除课程
            IList <EnLesson> Lessons = DataRule.Lsn.GetLessons(Grp);

            foreach (EnLesson Lsn in Lessons)
            {
                if (!InLsns(Lsn.Course))
                {
                    DataRule.Lsn.RemoveLsn(Lsn);
                }
            }

            //保存与更新
            foreach (FcLesson FcLsn in this.FcLsns)
            {
                EnLesson            Lsn     = new EnLesson();
                IList <EnClsLesson> ClsLsns = new List <EnClsLesson>();
                Lsn.SquadGroup  = this.Grp;
                Lsn.Course      = FcLsn.course;
                Lsn.IsSelfStudy = FcLsn.IsSelfStudy;
                Lsn.SharedTime  = FcLsn.SharedTime;
                foreach (FcClsLesson FcClsLsn in FcLsn.FcClsLsns)
                {
                    EnClsLesson ClsLsn = new EnClsLesson();
                    ClsLsn.Lesson     = Lsn;
                    ClsLsn.Squad      = FcClsLsn.squad;
                    ClsLsn.Teacher    = FcClsLsn.teacher;
                    ClsLsn.SharedTime = FcClsLsn.SharedTime;
                    ClsLsns.Add(ClsLsn);
                }

                DataRule.Lsn.SaveLsnTree(Lsn, ClsLsns);
            }

            Modify = false;
        }
 //以下方法为本层服务
 public void RemoveClsLsn(EnClsLesson clsLsn)
 {
     ThisModule.Dac.Rule.DeleteRuleOfEty(clsLsn);
     ThisModule.Dac.Lsn.DeleteClsLesson(clsLsn);
 }
Example #11
0
        /// <summary>
        /// 仅负责把空课安排到合适的位置,不会动已排的课
        /// </summary>
        private Boolean Automatic(EnSquad squad)
        {
            if (SqdScheduleList[squad].FailLsnActs.Count == 0)
            {
                return(false);
            }

            //策略:
            //第一步:整理FailLsnActs到有序(同VcClsLesson相邻,为提高速度)
            //对每一VcLsnAct:计算优势值(靠评价函数),安排到优势值最大的Time

            SqdSchedule sch = SqdScheduleList[squad];

            sch.Modified = true;
            IList <EnLsnAct> OrderFailLsnActs = GetOrderFailLsnActs(sch.FailLsnActs);
            Int32            DaySum           = 0;

            foreach (Boolean bl in DataRule.Solution.ActiveWeekArr)
            {
                if (bl)
                {
                    DaySum++;
                }
            }

            EnClsLesson        frontClsLsn  = null;
            DtMatrix <Boolean> TchConcretes = null;
            DtMatrix <eRule>   ClsLsnRules  = null;

            Int32[] CourseCnt     = new Int32[7];
            Int32   CourseAverage = 0;

            foreach (EnLsnAct act in OrderFailLsnActs)
            {
                if (frontClsLsn == null || frontClsLsn != act.ClsLesson)
                {
                    frontClsLsn  = act.ClsLesson;
                    TchConcretes = new DtMatrix <bool>(DataRule.Solution);
                    ClsLsnRules  = this.ClsLsnRuleList[act.ClsLesson];

                    if (act.ClsLesson.Teacher != null)
                    {
                        foreach (VcTime time in sch.Matrix.eachTime())
                        {
                            if (sch.Matrix[time].LsnAct == null)
                            {
                                foreach (SqdSchedule sqdSch in SqdScheduleList.Values)
                                {
                                    if (sqdSch.Matrix[time].LsnAct != null &&
                                        sqdSch.Matrix[time].LsnAct.ClsLesson.Teacher == act.ClsLesson.Teacher)
                                    {
                                        TchConcretes[time] = true;
                                        break;
                                    }
                                }
                            }
                        }
                    }

                    //foreach (Int32 cnt in CourseCnt)
                    //    cnt = 0;
                    for (Int32 i = 0; i <= 6; i++)
                    {
                        CourseCnt[i] = 0;
                    }
                    Int32 CourseSum = 0;
                    foreach (VcTime time in sch.Matrix.eachTime())
                    {
                        if (sch.Matrix[time].LsnAct != null &&
                            sch.Matrix[time].LsnAct.ClsLesson.Lesson.Course == act.ClsLesson.Lesson.Course)
                        {
                            CourseCnt[(Int32)time.Week]++;
                            CourseSum++;
                        }
                    }
                    foreach (EnLsnAct failAct in sch.FailLsnActs)
                    {
                        if (failAct.ClsLesson.Lesson.Course == act.ClsLesson.Lesson.Course)
                        {
                            CourseSum++;
                        }
                    }
                    if (DaySum == 0)
                    {
                        CourseAverage = 0;
                    }
                    else
                    {
                        CourseAverage = (CourseSum + DaySum - 1) / DaySum;
                    }
                }

                //TchConcretes true教师冲突
                //ClsLsnRules 规则
                //CourseCnt 此课每天已经上的节数(数组)
                //CourseSum 此课每周总课时
                //CourseAverage 每天平均上课节数

                DtMatrix <Int32> Advantages = new DtMatrix <Int32>(DataRule.Solution);
                foreach (VcTime time in sch.Matrix.eachTime())
                {
                    if (sch.Matrix[time].LsnAct != null)
                    {
                        Advantages[time] = Int32.MinValue;
                    }
                    else
                    {
                        Advantages[time] = TchConcretes[time] ? -2 : (Int32)ClsLsnRules[time];
                        if (CourseCnt[(Int32)time.Week] >= CourseAverage)
                        {
                            if (Advantages[time] > -1)
                            {
                                Advantages[time] = -1;   //这一天上课比较多
                            }
                        }
                    }
                }

                Int32 MaxAdvantage      = Int32.MinValue;
                VcTime MaxAdvantageTime = new VcTime();
                foreach (VcTime time in Advantages.eachTime())
                {
                    if (MaxAdvantage < Advantages[time])
                    {
                        MaxAdvantage = Advantages[time];
                        time.CopyFieldTo(MaxAdvantageTime);
                    }
                }

                if (MaxAdvantage == Int32.MinValue)
                {
                    return(true); //没地方排了
                }
                if (MaxAdvantage >= -1)
                {
                    CourseCnt[(Int32)MaxAdvantageTime.Week]++;
                    sch.Matrix[MaxAdvantageTime].LsnAct = act;
                    sch.FailLsnActs.Remove(act);
                }
            }

            foreach (VcTime time in sch.Matrix.eachTime())
            {
                if (sch.FailLsnActs.Count > 0 && sch.Matrix[time].LsnAct == null)
                {
                    sch.Matrix[time].LsnAct = sch.FailLsnActs[sch.FailLsnActs.Count - 1];
                    sch.FailLsnActs.RemoveAt(sch.FailLsnActs.Count - 1);
                }
            }

            return(true);
        }