/// <summary>
        /// 生成课时
        /// </summary>
        /// <param name="classCourse"></param>
        void createClassHours(UIClassCourse classCourse)
        {
            // 清除
            classCourse.ClassHours.Clear();

            // 课时
            var lessons = classCourse.Lessons;

            for (int i = 1; i <= lessons; i++)
            {
                // 课时
                UIClassHour classHour = new UIClassHour()
                {
                    // 生成的时候当做序号使用
                    ID       = i,
                    ClassID  = classCourse.ClassID,
                    Class    = classCourse.ClassName,
                    CourseID = classCourse.CourseID,
                    Course   = classCourse.Course,
                    Teachers = classCourse.Teachers,
                    Active   = true,
                };
                classCourse.ClassHours.Add(classHour);
            }
        }
        void classHourDetailsCommand(object obj)
        {
            UIClassCourse classCourse = obj as UIClassCourse;

            int no = 0;

            classCourse.ClassHours.ForEach(ch =>
            {
                ch.No = ++no;
            });

            ClassHourSettingWindow classsHourWindow = new ClassHourSettingWindow(classCourse.ClassHours);

            classsHourWindow.Closed += (s, arg) =>
            {
                var firstClassHour = classCourse.ClassHours.FirstOrDefault();
                if (firstClassHour != null)
                {
                    var allSame = classCourse.ClassHours.All(ch => ch.TeacherString.Equals(firstClassHour.TeacherString));
                    if (allSame)
                    {
                        classCourse.Teachers = firstClassHour.Teachers;
                        classCourse.RaiseChanged();
                    }
                }
            };
            classsHourWindow.ShowDialog();
        }
        void selectClassHourCountCommand(object obj)
        {
            UIClassCourse classCourse = obj as UIClassCourse;

            this.createClassHours(classCourse);

            // 刷新界面课时
            var firstClass = this.Classes.FirstOrDefault(c => c.ID.Equals(classCourse.ClassID));

            if (firstClass != null)
            {
                firstClass.RaiseLessons();
            }
        }
        void chooseTeacherCommand(object obj)
        {
            UIClassCourse classCourse = obj as UIClassCourse;

            var cpCase = CommonDataManager.GetCPCase(base.LocalID);

            var currentTeachers = classCourse.Teachers.Select(s =>
            {
                return(new UITeacher
                {
                    ID = s.ID,
                    Name = s.Name
                });
            })?.ToList();

            var allTeachers = cpCase.Teachers.Select(s =>
            {
                return(new UITeacher
                {
                    ID = s.ID,
                    Name = s.Name
                });
            })?.ToList();

            ChooseTeacherWindow window = new ChooseTeacherWindow(currentTeachers, allTeachers);

            window.Closed += (s, arg) =>
            {
                if (window.DialogResult.Value)
                {
                    // 清空教师
                    classCourse.Teachers.Clear();

                    var selectedTeachers = window.Teachers.Select(st =>
                    {
                        return(new XYKernel.OS.Common.Models.Administrative.TeacherModel()
                        {
                            ID = st.ID,
                            Name = st.Name
                        });
                    })?.ToList();
                    classCourse.Teachers = selectedTeachers;
                    classCourse.RaiseChanged();

                    this.createClassHours(classCourse);
                }
            };
            window.ShowDialog();
        }
        void classHourDetailsCommand(object obj)
        {
            UIClassCourse classCourse = obj as UIClassCourse;

            int no = 0;

            classCourse.ClassHours.ForEach(ch =>
            {
                ch.No = ++no;
            });

            ClassHourSettingWindow classsHourWindow = new ClassHourSettingWindow(classCourse.ClassHours);

            classsHourWindow.ShowDialog();
        }
        void deleteCourseCommand(object obj)
        {
            var confirm = this.ShowDialog("提示信息", "确认删除?", CustomControl.Enums.DialogSettingType.OkAndCancel, CustomControl.Enums.DialogType.Warning);

            if (confirm == CustomControl.Enums.DialogResultType.OK)
            {
                UIClassCourse model      = obj as UIClassCourse;
                var           classModel = this.Classes.FirstOrDefault(c => c.ID.Equals(model.ClassID));
                if (classModel != null)
                {
                    classModel.Courses.Remove(model);
                    this.RaisePropertyChanged(() => ShowUniform);
                }
            }
        }
        void selectClassHourCountCommand(object obj)
        {
            UIClassCourse classCourse = obj as UIClassCourse;

            this.createClassHours(classCourse);
        }
        public void Initilize()
        {
            GalaSoft.MvvmLight.Messaging.Messenger.Default.Register <UICourse>(this, Receive);

            GalaSoft.MvvmLight.Messaging.Messenger.Default.Register <UITeacher>(this, ReceiveTeacher);

            var cpCase = CommonDataManager.GetCPCase(base.LocalID);

            this.ClassHourCounts = new List <UIClassHourCount>()
            {
                new UIClassHourCount()
                {
                    Lessons = 1
                },
                new UIClassHourCount()
                {
                    Lessons = 2
                },
                new UIClassHourCount()
                {
                    Lessons = 3
                },
                new UIClassHourCount()
                {
                    Lessons = 4
                },
                new UIClassHourCount()
                {
                    Lessons = 5
                },
                new UIClassHourCount()
                {
                    Lessons = 6
                },
                new UIClassHourCount()
                {
                    Lessons = 7
                },
                new UIClassHourCount()
                {
                    Lessons = 8
                },
                new UIClassHourCount()
                {
                    Lessons = 9
                },
                new UIClassHourCount()
                {
                    Lessons = 10
                },
                new UIClassHourCount()
                {
                    Lessons = 11
                },
                new UIClassHourCount()
                {
                    Lessons = 12
                },
            };

            cpCase.Classes.ForEach(c =>
            {
                UIClass classModel = new UIClass()
                {
                    ID   = c.ID,
                    Name = c.Name,
                };

                c.Settings.ForEach(set =>
                {
                    // 1.获取课程
                    var course = cpCase.Courses.FirstOrDefault(fc => fc.ID.Equals(set.CourseID));

                    // 2.获取教师
                    var teachers = (from t in cpCase.Teachers from st in set.TeacherIDs where st.Equals(t.ID) select t)?.ToList();

                    // 3.获取课时
                    var classHours = (from h in cpCase.ClassHours
                                      where h.ClassID == c.ID && h.CourseID == set.CourseID
                                      select new UIClassHour()
                    {
                        Class = c.Name,
                        ClassID = c.ID,
                        Course = course.Name,
                        ID = h.ID,
                        CourseID = course.ID,
                        Teachers = cpCase.GetTeachersByIds(h.TeacherIDs),
                    })?.ToList();

                    // 3.添加班级课程绑定
                    UIClassCourse classCourse = new UIClassCourse();
                    classCourse.ClassID       = c.ID;
                    classCourse.ClassName     = c.Name;
                    classCourse.CourseID      = set.CourseID;
                    classCourse.Course        = course?.Name;
                    classCourse.Lessons       = set.Lessons;
                    classCourse.Teachers      = teachers;
                    classCourse.ClassHours    = classHours;


                    classModel.Courses.Add(classCourse);
                });

                this.Classes.Add(classModel);
            });
        }