Ejemplo n.º 1
0
        private void ToFocusedState(EnLsnAct sendAct)
        {
            foreach (SqdScheduleCell cell in Matrix.eachCell())
            {
                if (cell.Act != null && cell.Act.ClsLesson == sendAct.ClsLesson)
                {
                    cell.CellState = eCellState.focused;
                }
                else
                {
                    cell.CellState = eCellState.common;
                }
            }

            RenewRuleGrid(new VcTime());
            this.schState = eSchState.focused;

            if (sendAct == null || sendAct.ClsLesson == null)
            {
                VC2WinFmApp.MessageSwitch.SetLastTch(null, null);
            }
            else
            {
                VC2WinFmApp.MessageSwitch.SetLastTch(sendAct.ClsLesson.Teacher, sendAct.Time);
            }
        }
Ejemplo n.º 2
0
        public void SaveLsnActs(IList <EnLsnAct> Values)
        {
            foreach (EnLsnAct act in Values)
            {
                IList <EnLsnAct> Acts = ClsLsns[act.ClsLesson.Id].Acts;
                if (Acts.Contains(act))
                {
                    ThisModule.OleDB.ExecuteNonQuery("update TLsnAct set"
                                                     + " FLocked = " + (act.Locked ? "True" : "false")
                                                     + ", FTime = " + VcTimeLogic.TimeToInt32(act.Time)
                                                     + " where Id = " + act.Id);
                }
                else
                {
                    Debug.Assert(act.Id == 0, "act.Id != 0");

                    EnLsnAct nAct = new EnLsnAct();
                    nAct.Locked    = act.Locked;
                    nAct.ClsLesson = act.ClsLesson;
                    act.Time.CopyFieldTo(nAct.Time);
                    nAct.Id = Convert.ToInt64(ThisModule.OleDB.InsertAndReturnId_MS("Insert into TLsnAct"
                                                                                    + "(FClsLesson, FLocked, FTime) values ("
                                                                                    + nAct.ClsLesson.Id
                                                                                    + ", " + (act.Locked ? "True" : "false")
                                                                                    + ", " + VcTimeLogic.TimeToInt32(nAct.Time)
                                                                                    + ")"));

                    Acts.Add(nAct);
                }
            }
        }
Ejemplo n.º 3
0
        private void ToCommonState(VcTime focuseTime)
        {
            EnLsnAct         Act = null;
            DtMatrix <eRule> rles
                = VC2WinFmApp.Engine.GetSqdRule(this.squad);

            foreach (SqdScheduleCell cell in Matrix.eachCell())
            {
                if (cell.Time == focuseTime)
                {
                    cell.CellState = eCellState.focused;
                    Act            = cell.Act;
                }
                else
                {
                    cell.CellState = eCellState.common;
                }

                cell.Rule = rles[cell.Time];
            }

            RenewRuleGrid(focuseTime);

            schState = eSchState.common;
            if (Act == null || Act.ClsLesson == null)
            {
                VC2WinFmApp.MessageSwitch.SetLastTch(null, null);
            }
            else
            {
                VC2WinFmApp.MessageSwitch.SetLastTch(Act.ClsLesson.Teacher, Act.Time);
            }
        }
Ejemplo n.º 4
0
        private void ToInDropState(EnLsnAct Act, VcTime sTime)
        {
            DtMatrix <eRule> rles
                = VC2WinFmApp.Engine.GetActChangeRule(this.squad, Act, sTime);

            foreach (SqdScheduleCell cell in Matrix.eachCell())
            {
                //存在重复更新,为简化逻辑,不要管
                if (cell.Time == sTime)
                {
                    cell.CellState = eCellState.isDropSrc;
                }
                else if (cell.Act != null && cell.Act.ClsLesson == Act.ClsLesson)
                {
                    cell.CellState = eCellState.likeDropSrc;
                }
                else
                {
                    cell.CellState = eCellState.inDrop;
                    cell.Rule      = rles[cell.Time];
                }
            }

            RenewRuleGrid(sTime);
            sTime.CopyFieldTo(DropSrcTime);
            schState = eSchState.inDrop;  //进入拖放状态
            if (Act == null || Act.ClsLesson == null)
            {
                VC2WinFmApp.MessageSwitch.SetLastTch(null, null);
            }
            else
            {
                VC2WinFmApp.MessageSwitch.SetLastTch(Act.ClsLesson.Teacher, Act.Time);
            }
        }
Ejemplo n.º 5
0
        private void LoadAct()
        {
            foreach (OleDbDataReader reader in ThisModule.OleDB.EachRows(
                         "select Id, FActTimes from TClsLesson"))
            {
                Int64           ClsLsnId = Convert.ToInt64(reader[0]);
                ClsLsnContainer ClsLsnCnt;
                if (!ClsLsns.TryGetValue(ClsLsnId, out ClsLsnCnt))
                {
                    ThisModule.ErrorLog.Error("VcLsnAct恢复错误:ID对应的实体不存在  "
                                              + "  ClsLesson: " + ClsLsnId);
                    continue;
                }

                String ActTimes = reader[1].ToString();
                if (String.IsNullOrEmpty(ActTimes))
                {
                    continue;
                }

                for (Int32 i = 0; i < ActTimes.Length; i++)
                {
                    //for (Int32 i = ActTimes.Length - 1; i >= 0; i--)
                    if (ActTimes[i] != '_')
                    {
                        EnLsnAct Act = new EnLsnAct();

                        ActId++;
                        Act.Id              = ActId;
                        Act.Time.Week       = (DayOfWeek)(i / (4 * 7));
                        Act.Time.BetideNode = (eBetideNode)((i % (4 * 7)) / 7);
                        Act.Time.Order      = i % 7;

                        Act.Locked = ActTimes[i] == 'A';

                        Act.ClsLesson = ClsLsnCnt.ClsLsn;
                        if (ClsLsnCnt.Acts.Count < ClsLsnCnt.ClsLsn.SharedTime)
                        {
                            ClsLsnCnt.Acts.Add(Act);
                        }
                    }
                }

                Int32 cntDec = ClsLsnCnt.ClsLsn.SharedTime - ClsLsnCnt.Acts.Count;
                for (Int32 cnt = 0; cnt < cntDec; cnt++)
                {
                    EnLsnAct Act = new EnLsnAct();

                    ActId++;
                    Act.Id        = ActId;
                    Act.ClsLesson = ClsLsnCnt.ClsLsn;
                    ClsLsnCnt.Acts.Add(Act);
                }

                if (ClsLsnCnt.Acts.Count != ClsLsnCnt.ClsLsn.SharedTime)
                {
                    ExUI.ShowInfo(ClsLsnCnt.Acts.Count + "/" + ClsLsnCnt.ClsLsn.SharedTime);
                }
            }
        }
Ejemplo n.º 6
0
        private static string[] GetMatrixStringArray(VCExportMatrix Matrix, BaseEntity entity)
        {
            String[] result = new String[VCExportMatrix.cFlatIdxLen];
            if (entity is EnTeacher)
            {
                DtMatrix <IList <EnLsnAct> > DtMatrix = VC2WinFmApp.Engine.GetTchMatrix(entity as EnTeacher);

                foreach (VcTime time in DtMatrix.eachTime())
                {
                    IList <EnLsnAct> acts = DtMatrix[time];
                    if (acts != null && acts.Count > 0)
                    {
                        MatrixCoordinate mc;
                        mc.Enabled = true;
                        mc.Week    = (Int32)time.Week;
                        mc.Section = (Int32)time.BetideNode;
                        mc.Idx     = time.Order - 1;
                        Int32  idx   = VCExportMatrix.MatrixCoordinateToFlat(mc);
                        String value = null;
                        foreach (EnLsnAct act in acts)
                        {
                            value = (String.IsNullOrEmpty(value) ? "" : value + "  ") + act.Squad + " " + act.ClsLesson.Lesson.Course.Name;
                        }

                        result[idx] = value;
                    }
                }
            }
            else if (entity is EnSquad)
            {
                DtMatrix <EnLsnAct> DtMatrix = VC2WinFmApp.Engine.GetSqdMatrix(entity as EnSquad);

                foreach (VcTime time in DtMatrix.eachTime())
                {
                    EnLsnAct act = DtMatrix[time];
                    if (act != null)
                    {
                        MatrixCoordinate mc;
                        mc.Enabled = true;
                        mc.Week    = (Int32)time.Week;
                        mc.Section = (Int32)time.BetideNode;
                        mc.Idx     = time.Order - 1;
                        Int32  idx   = VCExportMatrix.MatrixCoordinateToFlat(mc);
                        String value = act.ClsLesson.Lesson.Course.Name;

                        result[idx] = value;
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 7
0
        /// <summary>
        ///  获得当前虚拟态的课表某节的规则列表与冲突
        /// </summary>
        public IList <VcActEtyRelation> GetSqdClash(EnSquad squad, VcTime time)
        {
            List <VcActEtyRelation> Result = new List <VcActEtyRelation>();

            if (!this.TimeIsEnabled(time))
            {
                return(Result);
            }

            //获得VcLsnAct
            EnLsnAct act = SqdScheduleList[squad].Matrix[time].LsnAct;

            if (act == null)
            {
                return(Result);
            }

            //添加授课教师
            if (act.ClsLesson.Teacher != null)
            {
                Result.Add(new VcActEtyRelation(act.ClsLesson.Teacher, eActEtyRelation.teach));

                //整理出冲突课程
                foreach (SqdSchedule sch in SqdScheduleList.Values)
                {
                    if (sch.Matrix[time].LsnAct != null &&
                        sch.Matrix[time].LsnAct.ClsLesson.Squad != squad &&
                        sch.Matrix[time].LsnAct.ClsLesson.Teacher == act.ClsLesson.Teacher)
                    {
                        Result.Add(new VcActEtyRelation(sch.Matrix[time].LsnAct.ClsLesson,
                                                        eActEtyRelation.clash, eRule.crisscross));
                    }
                }
            }

            //添加Lsn/ClsLsn的Rule
            Result.Add(new VcActEtyRelation(act.ClsLesson.Lesson, eActEtyRelation.rule,
                                            DataRule.Rule.GetRuleOfTime(act.ClsLesson.Lesson, time)));

            Result.Add(new VcActEtyRelation(act.ClsLesson, eActEtyRelation.rule,
                                            DataRule.Rule.GetRuleOfTime(act.ClsLesson, time)));

            //迭代Act的元素,添加Rule
            foreach (BaseEntity ety in this.eachClsLsnComponent(act.ClsLesson))
            {
                Result.Add(new VcActEtyRelation(ety, eActEtyRelation.rule,
                                                DataRule.Rule.GetRuleOfTime(ety, time)));
            }

            return(Result);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 课表拖放后
        /// </summary>
        public void Move(EnSquad squad, EnLsnAct sAct, VcTime tTime)
        {
            SqdSchedule sch = SqdScheduleList[squad];

            //获得来源的act的时间sTime
            VcTime sTime = new VcTime();

            if (!sch.FailLsnActs.Contains(sAct))
            {
                foreach (VcTime tt in sch.Matrix.eachTime())
                {
                    if (sch.Matrix[tt].LsnAct == sAct)
                    {
                        tt.CopyFieldTo(sTime);
                        break;
                    }
                }
            }


            if (sTime == tTime)   //原地拖
            {
                return;
            }
            else if (sTime.HasValue && !tTime.HasValue)  //从课表拖到FailLsnActs
            {
                EnLsnAct ta = sch.Matrix[sTime].LsnAct;
                sch.FailLsnActs.Add(ta);
                sch.Matrix[sTime].LsnAct = null;
            }
            else if (!sTime.HasValue && tTime.HasValue)    //从FailLsnActs拖到课表
            {
                if (sch.Matrix[tTime].LsnAct != null)
                {
                    return;
                }

                sch.Matrix[tTime].LsnAct = sAct;
                sch.FailLsnActs.Remove(sAct);
            }
            else if (sTime.HasValue && tTime.HasValue)    //课表拖到课表
            {
                EnLsnAct ta = sch.Matrix[sTime].LsnAct;
                sch.Matrix[sTime].LsnAct = sch.Matrix[tTime].LsnAct;
                sch.Matrix[tTime].LsnAct = ta;
            }

            sch.Modified  = true;
            this.Modified = true;
            this.AfterScheduleChanged(squad);
        }
Ejemplo n.º 9
0
        private void thisDragDrop(object sender, DragEventArgs e)
        {
            EnLsnAct act   = e.Data.GetData(typeof(EnLsnAct)) as EnLsnAct;
            VcTime   tTime = new VcTime();

            if (sender is SqdScheduleCell)
            {
                (sender as SqdScheduleCell).Time.CopyFieldTo(tTime);
            }

            //Move将触发更新,存在重复更新,为简化逻辑,不要管
            ToCommonState(tTime);
            VC2WinFmApp.Engine.Move(this.squad, act, tTime);
        }
Ejemplo n.º 10
0
        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();
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 把sqdSch.FailLsnActs中所有LsnAct安排进sqdSch.Matrix
        ///   不准备环境(即不清除各单元的Rule、LsnAct)
        /// </summary>
        private void PutActToMatrix(SqdSchedule sqdSch)
        {
            EnLsnAct         FillAct = new EnLsnAct();
            IList <EnLsnAct> tmpActs = sqdSch.FailLsnActs == null ? null : new List <EnLsnAct>(sqdSch.FailLsnActs);

            sqdSch.FailLsnActs.Clear();

            foreach (EnLsnAct act in tmpActs)
            {
                if (sqdSch.Matrix.TestTime(act.Time))
                {
                    ScheduleNode node = sqdSch.Matrix[act.Time];
                    if (node.LsnAct == null)
                    {
                        node.LsnAct = act;
                    }
                    else
                    {
                        sqdSch.FailLsnActs.Add(act);

                        if (node.LsnAct != FillAct)
                        {
                            sqdSch.FailLsnActs.Add(node.LsnAct);
                            node.LsnAct = FillAct;
                        }
                    }
                }
                else
                {
                    sqdSch.FailLsnActs.Add(act);
                }
            }

            foreach (ScheduleNode node in sqdSch.Matrix.eachElement())
            {
                if (node.LsnAct == FillAct)
                {
                    node.LsnAct = null;
                }
            }
        }
Ejemplo n.º 12
0
        private void thisMouseMove(object sender, MouseEventArgs e)
        {
            CheckFocusTch(sender, e.Location);  //取当前聚焦的

            if (ReadOnly ||
                (schState != eSchState.common && schState != eSchState.focused) ||
                e.Button != MouseButtons.Left ||
                schState == eSchState.inDrop)
            {
                return;
            }

            if (Math.Abs(e.X - DownXY.X) < 5 && Math.Abs(e.Y - DownXY.Y) < 5)
            {
                return;
            }

            EnLsnAct Act   = null;
            VcTime   sTime = new VcTime();

            if (sender == TaskGrid && TaskGridBind.Count > 0)
            {
                DataGridView.HitTestInfo hi = TaskGrid.HitTest(e.X, e.Y);
                TaskGridBind.Position = hi.RowIndex;

                TaskGrid.Refresh(); //有用的,让TaskGrid更新当前选中行为被选中状态
                Act = TaskGridBind.Current as EnLsnAct;
            }
            else if (sender is SqdScheduleCell)
            {
                Act = (sender as SqdScheduleCell).Act;
                (sender as SqdScheduleCell).Time.CopyFieldTo(sTime);
            }

            if (Act != null)
            {
                ToInDropState(Act, sTime);

                (sender as Control).DoDragDrop(Act, DragDropEffects.Move);
            }
        }
Ejemplo n.º 13
0
        private void LoadAct()
        {
            foreach (OleDbDataReader reader in ThisModule.OleDB.EachRows(
                         "select Id, FClsLesson, FTime, FLocked"
                         + " from TLsnAct"))
            {
                EnLsnAct Act = new EnLsnAct();
                Act.Id = Convert.ToInt64(reader[0]);
                VcTimeLogic.GetTimeFromInt32(Convert.ToInt32(reader[2])).CopyFieldTo(Act.Time);
                Act.Locked = Convert.ToBoolean(reader[3]);
                Int64 ClsLsnId = Convert.ToInt64(reader[1]);

                ClsLsnContainer ClsLsnCnt;
                if (!ClsLsns.TryGetValue(ClsLsnId, out ClsLsnCnt))
                {
                    ThisModule.ErrorLog.Error("VcLsnAct恢复错误:ID对应的实体不存在  "
                                              + "  ClsLesson: " + ClsLsnId);
                    continue;
                }

                Act.ClsLesson = ClsLsnCnt.ClsLsn;
                ClsLsnCnt.Acts.Add(Act);
            }
        }
Ejemplo n.º 14
0
 public EnFailAct(EnLsnAct act, VcTime time)
 {
     this.act = act;
     time.CopyFieldTo(this.time);
 }
Ejemplo n.º 15
0
 public EnFailAct(EnLsnAct act)
 {
     this.act = act;
 }
Ejemplo n.º 16
0
        /// <summary>
        /// 获取交换时优势
        /// </summary>
        public DtMatrix <eRule> GetActChangeRule(EnSquad squad,
                                                 EnLsnAct sAct, VcTime sTime)
        {
            Debug.Assert(sAct != null, "为简化程序逻辑,空课不可拖。");

            //这个方法是本程序中最复杂的逻辑
            //步骤:
            //一、获得所有位置当前优势
            //二、获得sAct当前优势
            //三、获得所有位置的Act移动到sTime的优势值
            //四、获得sAct移动到所有位置的优势值
            //五、比较当前优势和移动后的优势,获得交换的价值

            SqdSchedule NowSch = SqdScheduleList[squad];

            //一、获得所有位置当前优势
            DtMatrix <eRule> NowRules = this.GetSqdRule(squad);

            //二、获得sAct当前优势
            eRule sActNowRule;

            if (NowRules.TestTime(sTime))
            {
                sActNowRule = NowRules[sTime];
            }
            else
            {
                sActNowRule = eRule.common;  //未排
            }
            //三、获得所有位置的Act移动到sTime的优势值
            DtMatrix <eRule> FutureRules = new DtMatrix <eRule>(DataRule.Solution);

            if (FutureRules.TestTime(sTime))
            {
                IList <EnTeacher> sTimeTchs = new List <EnTeacher>();
                foreach (SqdSchedule sch in this.SqdScheduleList.Values)
                {
                    if (sch != NowSch && sch.Matrix[sTime].LsnAct != null)
                    {
                        EnLsnAct act = sch.Matrix[sTime].LsnAct;
                        if (act.ClsLesson.Teacher != null &&
                            !sTimeTchs.Contains(act.ClsLesson.Teacher))
                        {
                            sTimeTchs.Add(act.ClsLesson.Teacher);
                        }
                    }
                }

                foreach (VcTime time in FutureRules.eachTime())
                {
                    if (NowSch.Matrix[time].LsnAct != null)
                    {
                        EnLsnAct act = NowSch.Matrix[time].LsnAct;
                        if (act.ClsLesson.Teacher != null &&
                            sTimeTchs.Contains(act.ClsLesson.Teacher))
                        {
                            FutureRules[time] = eRule.crisscross;  //此课程移到sTime后导致教师冲突
                        }
                        else
                        {
                            FutureRules[time] = ClsLsnRuleList[act.ClsLesson][sTime]; //移到sTime后的优势
                        }
                    }
                }
            }
            else
            {
                //所有Act移动到未排,则优势一定是eRule.common
                foreach (VcTime time in FutureRules.eachTime())
                {
                    FutureRules[time] = eRule.common;
                }
            }

            //四、获得sAct移动到所有位置的优势值
            DtMatrix <eRule> sActFutureRules = new DtMatrix <eRule>(DataRule.Solution);

            DtMatrix <eRule> TmpRules = ClsLsnRuleList[sAct.ClsLesson];

            foreach (VcTime time in TmpRules.eachTime())
            {
                sActFutureRules[time] = TmpRules[time];
            }

            //检测课程冲突
            if (sAct.ClsLesson.Teacher != null)
            {
                EnTeacher NowTch = sAct.ClsLesson.Teacher;
                DtMatrix <IList <EnLsnAct> > sTchLsns = this.GetTchMatrix(NowTch);
                foreach (VcTime time in sTchLsns.eachTime())
                {
                    if (sTchLsns[time] != null && sTchLsns[time].Count > 0)
                    {
                        foreach (EnLsnAct act in sTchLsns[time])
                        {
                            if (act != NowSch.Matrix[time].LsnAct && //当前课表的,会被移走
                                act.ClsLesson.Teacher == NowTch)
                            {
                                sActFutureRules[time] = eRule.crisscross;  //sAct移到time后将导致冲突
                                break;
                            }
                        }
                    }
                }
            }

            //五、比较当前优势和移动后的优势,获得交换的价值矩阵
            DtMatrix <eRule> Result = new DtMatrix <eRule>(DataRule.Solution);

            //NowRules、sActNowRule、FutureRules、sActFutureRules
            //所有位置当前优势\拖动源当前优势\所有位置在拖动源的优势\拖动源拖到所有位置的优势

            foreach (VcTime time in Result.eachTime())
            {
                if (NowSch.Matrix[time].LsnAct != null &&
                    NowSch.Matrix[time].LsnAct.ClsLesson == sAct.ClsLesson)
                {
                    Result[time] = eRule.crisscross; //同样的课移动没意义的
                    continue;
                }

                Result[time] = ComparerActChangeRule(NowRules[time], sActNowRule,
                                                     FutureRules[time], sActFutureRules[time]);
            }

            return(Result);
        }