Пример #1
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);
            }
        }
Пример #2
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);
        }