public void Initilize()
        {
            Messenger.Default.Register <HostView>(this, save);

            this.Comments = CommonDataManager.GetAdminRuleComments(AdministrativeRuleEnum.OddDualWeek);

            var cp   = CommonDataManager.GetCPCase(base.LocalID);
            var rule = CommonDataManager.GetAminRule(base.LocalID);

            rule.OddDualWeeks.ForEach(m =>
            {
                UIOddDualWeek oddDual = new UIOddDualWeek();
                oddDual.OddCourseID   = m.OddWeekCourseID;
                oddDual.DualCourseID  = m.DualWeekCourseID;
                oddDual.ClassID       = m.ClassID;

                var firstClass    = cp.Classes.FirstOrDefault(c => c.ID.Equals(m.ClassID));
                oddDual.ClassName = firstClass?.Name;

                var oddCourse     = cp.Courses.FirstOrDefault(c => c.ID.Equals(m.OddWeekCourseID));
                oddDual.OddCourse = oddCourse?.Name;

                var dualCourse     = cp.Courses.FirstOrDefault(c => c.ID.Equals(m.DualWeekCourseID));
                oddDual.DualCourse = dualCourse?.Name;

                this.Rules.Add(oddDual);
            });
        }
        void deleteRule(object obj)
        {
            var result = this.ShowDialog("提示信息", "确认删除?", CustomControl.Enums.DialogSettingType.OkAndCancel, CustomControl.Enums.DialogType.Warning);

            if (result == CustomControl.Enums.DialogResultType.OK)
            {
                UIOddDualWeek rule = obj as UIOddDualWeek;
                this.Rules.Remove(rule);
            }
        }
        void createCommand()
        {
            Dialog.CreateOddDualWeek createWin = new Dialog.CreateOddDualWeek();
            createWin.Closed += (s, arg) =>
            {
                if (createWin.DialogResult.Value)
                {
                    var last  = this.Rules.LastOrDefault();
                    var index = last == null ? 0 : last.NO;

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

                    var classes = createWin.SelectClasses?.ToList();
                    var odd     = createWin.OddCourse;
                    var dual    = createWin.DualCourse;

                    classes.ForEach(c =>
                    {
                        var model = new UIOddDualWeek()
                        {
                            NO           = ++index,
                            ClassID      = c.ID,
                            ClassName    = c.Name,
                            OddCourseID  = odd?.ID,
                            DualCourseID = dual?.ID,
                        };

                        var dualCourse = cp.Courses.FirstOrDefault(d => d.ID.Equals(model.DualCourseID));
                        var oddCourse  = cp.Courses.FirstOrDefault(d => d.ID.Equals(model.OddCourseID));

                        model.OddCourse  = oddCourse?.Name;
                        model.DualCourse = dualCourse?.Name;

                        this.Rules.Add(model);
                    });
                }
            };
            createWin.ShowDialog();
        }
Пример #4
0
        void createCommand()
        {
            Dialog.CreateOddDualWeek createWin = new Dialog.CreateOddDualWeek();
            createWin.Closed += (s, arg) =>
            {
                if (createWin.DialogResult.Value)
                {
                    var last  = this.Rules.LastOrDefault();
                    var index = last == null ? 0 : last.NO;

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

                    var classes = createWin.SelectClasses?.ToList();
                    var odd     = createWin.OddCourse;
                    var dual    = createWin.DualCourse;

                    classes.ForEach(c =>
                    {
                        var model = new UIOddDualWeek()
                        {
                            NO           = ++index,
                            ClassID      = c.ID,
                            ClassName    = c.Name,
                            OddCourseID  = odd?.ID,
                            DualCourseID = dual?.ID,
                        };

                        var dualCourse = cp.Courses.FirstOrDefault(d => d.ID.Equals(model.DualCourseID));
                        var oddCourse  = cp.Courses.FirstOrDefault(d => d.ID.Equals(model.OddCourseID));

                        model.OddCourse  = oddCourse?.Name;
                        model.DualCourse = dualCourse?.Name;

                        var classRules = this.Rules.Where(r => r.ClassName.Equals(model.ClassName));
                        if (classRules == null)
                        {
                            this.Rules.Add(model);
                        }
                        else
                        {
                            var hasOdd = classRules.Any(r =>
                            {
                                var isDual = false;
                                var isOdd  = false;

                                if (r.DualCourse != null)
                                {
                                    isDual = r.DualCourse.Equals(model.OddCourse);
                                }
                                else if (r.OddCourse != null)
                                {
                                    isOdd = r.OddCourse.Equals(model.OddCourse);
                                }

                                if (isOdd || isDual)
                                {
                                    return(true);
                                }
                                else
                                {
                                    return(false);
                                }
                            });

                            var hasDual = classRules.Any(r =>
                            {
                                var isDual = false;
                                var isOdd  = false;

                                if (r.DualCourse != null)
                                {
                                    isDual = r.DualCourse.Equals(model.DualCourse);
                                }
                                else if (r.OddCourse != null)
                                {
                                    isOdd = r.OddCourse.Equals(model.DualCourse);
                                }

                                if (isOdd || isDual)
                                {
                                    return(true);
                                }
                                else
                                {
                                    return(false);
                                }
                            });

                            if (hasOdd || hasDual)
                            {
                                this.ShowDialog("提示信息", "同班级单周或双周只能有一条规则!", CustomControl.Enums.DialogSettingType.OnlyOkButton, CustomControl.Enums.DialogType.Warning);
                                return;
                            }
                            else
                            {
                                this.Rules.Add(model);
                            }
                        }
                    });
                }
            };
            createWin.ShowDialog();
        }