Beispiel #1
0
 void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
 {
     switch (connectionId)
     {
     case 1:
         this.win = ((OSKernel.Presentation.Arranging.Mixed.Dialog.SetPatternWindow)(target));
         return;
     }
     this._contentLoaded = true;
 }
        void cancelCommand(object obj)
        {
            SetPatternWindow win = obj as SetPatternWindow;

            win.DialogResult = false;
        }
        void saveCommand(object obj)
        {
            if (this.SelectPattern == null)
            {
                this.ShowDialog("提示信息", "模式为空!", CustomControl.Enums.DialogSettingType.OnlyOkButton, CustomControl.Enums.DialogType.Warning);
                return;
            }

            var clModel  = base.LocalID.DeSerializeCL();
            var algoRule = base.LocalID.DeSerializePatternAlgo();
            var rule     = base.LocalID.DeSerializeMixedRule();

            // 1.获取操作
            // 1.1 去除组合
            var combinationView    = this.sourceOperators.FirstOrDefault(p => p.Operator == UIPatternOperator.OperatorEnum.RemoveCombination);
            var removeCombinations = (combinationView.View.DataContext as RemoveCombinationViewModel).GetRemovedCombination();

            // 1.2 班额调整
            var classView      = this.sourceOperators.FirstOrDefault(p => p.Operator == UIPatternOperator.OperatorEnum.ClassCapacity);
            var classCapacitys = (classView.View.DataContext as ClassCapacityViewModel).GetCapacitys();

            // 1.3 课位调整
            var positionView = this.sourceOperators.FirstOrDefault(p => p.Operator == UIPatternOperator.OperatorEnum.Position);
            var positions    = (positionView.View.DataContext as PositionViewModel).GetCoursePositions();

            object         severialPattern = null;
            DataProcessing dataProcess     = new DataProcessing();

            MixedModel.CLCase               patternCase          = null;
            MixedModel.AlgoRule.AlgoRule    patternAlgoRule      = null;
            MixedModel.Rule.Rule            patternRule          = null;
            List <DataValidationResultInfo> validationResultInfo = new List <DataValidationResultInfo>()
            {
            };

            switch (this.SelectPattern.Pattern)
            {
            case Models.Enums.PatternTypeEnum.Normal:

                NormalModel normal = new NormalModel()
                {
                    ClassCapacity      = classCapacitys,
                    Positions          = positions,
                    RemovedCombination = removeCombinations
                };
                severialPattern = normal;

                Tuple <MixedModel.CLCase, bool, List <DataValidationResultInfo> > normalTuple = dataProcess.GetModelByNormal(clModel, rule, algoRule, normal);
                if (normalTuple.Item2)
                {
                    patternCase = normalTuple.Item1;
                }
                else
                {
                    StringBuilder message = new StringBuilder();
                    normalTuple.Item3?.ForEach(m =>
                    {
                        message.Append($"描述:{m.ErrorCode}-{m.Description}");
                    });
                    this.ShowDialog("错误消息", message.ToString(), CustomControl.Enums.DialogSettingType.OnlyOkButton, CustomControl.Enums.DialogType.Error);
                    return;
                }

                break;

            case Models.Enums.PatternTypeEnum.Extraction:

                ExtractionViewModel value = this.SelectPattern.View.DataContext as ExtractionViewModel;

                StudentExtractionModel extraction = new StudentExtractionModel()
                {
                    ExtractionRatio    = value.ExtractionRate,
                    IncreasedCapacity  = value.ClassCapacity,
                    Positions          = positions,
                    RemovedCombination = removeCombinations
                };
                severialPattern = extraction;
                Tuple <MixedModel.CLCase, bool, List <DataValidationResultInfo> > extractionTuple = dataProcess.GetModelByStudentExtraction(clModel, rule, algoRule, extraction);
                if (extractionTuple.Item2)
                {
                    patternCase = extractionTuple.Item1;
                }
                else
                {
                    StringBuilder message = new StringBuilder();
                    extractionTuple.Item3?.ForEach(m =>
                    {
                        message.Append($"描述:{m.ErrorCode}-{m.Description}");
                    });
                    this.ShowDialog("错误消息", message.ToString(), CustomControl.Enums.DialogSettingType.OnlyOkButton, CustomControl.Enums.DialogType.Error);
                    return;
                }

                break;

            case Models.Enums.PatternTypeEnum.OptimizedExtraction:

                OptimizedExtractionViewModel optimizedExtractionVM = this.SelectPattern.View.DataContext as OptimizedExtractionViewModel;

                if (optimizedExtractionVM.SelectResult == null)
                {
                    this.ShowDialog("提示信息", "没有选择结果", CustomControl.Enums.DialogSettingType.OnlyOkButton, CustomControl.Enums.DialogType.Warning);
                    return;
                }

                var result = Core.Http.OSHttpClient.Instance.GetResult(optimizedExtractionVM.SelectResult.TaskID);
                if (result.Item1)
                {
                    UIOptimizedExtraction optimizedExtraction = new UIOptimizedExtraction()
                    {
                        ClassCapacity      = optimizedExtractionVM.ClassCapacity,
                        Result             = result.Item2,
                        RemovedCombination = removeCombinations
                    };
                    severialPattern = optimizedExtraction;

                    var extractionOptimzeTuple = dataProcess.GetModelByFixedClassTimeTable(clModel, rule, algoRule, new NormalModel()
                    {
                        RemovedCombination = removeCombinations
                    }, optimizedExtraction.Result, optimizedExtraction.ClassCapacity);

                    if (extractionOptimzeTuple.Item3)
                    {
                        patternCase     = extractionOptimzeTuple.Item1;
                        patternAlgoRule = extractionOptimzeTuple.Item2;
                    }
                    else
                    {
                        StringBuilder message = new StringBuilder();
                        extractionOptimzeTuple.Item4?.ForEach(m =>
                        {
                            message.Append($"描述:{m.ErrorCode}-{m.Description}");
                        });
                        this.ShowDialog("错误消息", message.ToString(), CustomControl.Enums.DialogSettingType.OnlyOkButton, CustomControl.Enums.DialogType.Error);
                        return;
                    }
                }

                break;

            case Models.Enums.PatternTypeEnum.Compression:

                CompressionViewModel compressionVM = this.SelectPattern.View.DataContext as CompressionViewModel;

                TimeCompressionModel compression = new TimeCompressionModel()
                {
                    CompressionRatio   = compressionVM.Compression,
                    ClassCapacity      = classCapacitys,
                    RemovedCombination = removeCombinations
                };
                severialPattern = compression;

                var compressionTuple = dataProcess.GetModelByTimeCompression(clModel, rule, algoRule, compression);

                if (compressionTuple.Item4)
                {
                    patternCase     = compressionTuple.Item1;
                    patternRule     = compressionTuple.Item2;
                    patternAlgoRule = compressionTuple.Item3;
                }
                else
                {
                    StringBuilder message = new StringBuilder();
                    compressionTuple.Item5?.ForEach(m =>
                    {
                        message.Append($"描述:{m.ErrorCode}-{m.Description}");
                    });
                    this.ShowDialog("错误消息", message.ToString(), CustomControl.Enums.DialogSettingType.OnlyOkButton, CustomControl.Enums.DialogType.Error);
                    return;
                }

                break;

            case Models.Enums.PatternTypeEnum.OptimizedCompression:

                OptimizedCompressionViewModel optimizedCompressionVM = this.SelectPattern.View.DataContext as OptimizedCompressionViewModel;
                severialPattern = optimizedCompressionVM.SelectResult;

                if (optimizedCompressionVM.SelectResult == null)
                {
                    this.ShowDialog("提示信息", "没有选择结果", CustomControl.Enums.DialogSettingType.OnlyOkButton, CustomControl.Enums.DialogType.Warning);
                    return;
                }

                var optimizedResult = Core.Http.OSHttpClient.Instance.GetResult(optimizedCompressionVM.SelectResult.TaskID);
                if (optimizedResult != null)
                {
                    var compressionOptimize = dataProcess.GetModelByStudentsClassificationResult(clModel, rule, algoRule, optimizedResult.Item2);
                    if (compressionOptimize.Item4)
                    {
                        patternCase     = compressionOptimize.Item1;
                        patternRule     = compressionOptimize.Item2;
                        patternAlgoRule = compressionOptimize.Item3;
                    }
                    else
                    {
                        StringBuilder message = new StringBuilder();
                        compressionOptimize.Item5?.ForEach(m =>
                        {
                            message.Append($"描述:{m.ErrorCode}-{m.Description}");
                        });
                        this.ShowDialog("错误消息", message.ToString(), CustomControl.Enums.DialogSettingType.OnlyOkButton, CustomControl.Enums.DialogType.Error);
                        return;
                    }
                }

                break;

            case Models.Enums.PatternTypeEnum.Validation:

                ValidationViewModel validationVM = this.SelectPattern.View.DataContext as ValidationViewModel;
                UIValidation        validation   = new UIValidation()
                {
                    AssignedStudents = validationVM.IncludeAssinged,
                    OnlyTeacher      = validationVM.OnlyTeacher
                };
                severialPattern = validation;

                if (validationVM.IncludeAssinged)
                {
                    var IncludeAssingedTuple = dataProcess.GetModelWithOnlyStudentsAssignedToClass(clModel, rule, algoRule);
                    if (IncludeAssingedTuple.Item2)
                    {
                        patternCase = IncludeAssingedTuple.Item1;
                    }
                    else
                    {
                        StringBuilder message = new StringBuilder();
                        IncludeAssingedTuple.Item3?.ForEach(m =>
                        {
                            message.Append($"描述:{m.ErrorCode}-{m.Description}");
                        });
                        this.ShowDialog("错误消息", message.ToString(), CustomControl.Enums.DialogSettingType.OnlyOkButton, CustomControl.Enums.DialogType.Error);
                        return;
                    }
                }
                else
                {
                    var OnlyTeacherTuple = dataProcess.GetModelWithoutStudents(clModel, rule, algoRule);
                    if (OnlyTeacherTuple.Item2)
                    {
                        patternCase = OnlyTeacherTuple.Item1;
                    }
                    else
                    {
                        StringBuilder message = new StringBuilder();
                        OnlyTeacherTuple.Item3?.ForEach(m =>
                        {
                            message.Append($"描述:{m.ErrorCode}-{m.Description}");
                        });
                        this.ShowDialog("错误消息", message.ToString(), CustomControl.Enums.DialogSettingType.OnlyOkButton, CustomControl.Enums.DialogType.Error);
                        return;
                    }
                }

                break;
            }

            if (patternCase != null)
            {
                var local = CommonDataManager.GetLocalCase(base.LocalID);
                local.Pattern = this.SelectPattern.Pattern;
                local.Serialize();

                base.LocalID.Serialize(severialPattern);

                patternCase.SerializePatternCase(base.LocalID);
                PatternDataManager.AddCase(base.LocalID, patternCase);

                if (patternAlgoRule == null)
                {
                    if (algoRule != null)
                    {
                        algoRule.SerializePatternAlgo(base.LocalID);
                        PatternDataManager.AddAlgoRule(base.LocalID, algoRule);
                    }
                }
                else
                {
                    patternAlgoRule.SerializePatternAlgo(base.LocalID);
                    PatternDataManager.AddAlgoRule(base.LocalID, patternAlgoRule);
                }

                if (patternRule == null)
                {
                    if (rule != null)
                    {
                        rule.SerializePatternRule(base.LocalID);
                        PatternDataManager.AddRule(base.LocalID, rule);
                    }
                }
                else
                {
                    patternRule.SerializePatternRule(base.LocalID);
                    PatternDataManager.AddRule(base.LocalID, patternRule);
                }

                SetPatternWindow win = obj as SetPatternWindow;
                win.PatternType  = this.SelectPattern.Pattern;
                win.DialogResult = true;
            }
            else
            {
                this.ShowDialog("提示信息", "模式实体转换失败!", CustomControl.Enums.DialogSettingType.OnlyOkButton, CustomControl.Enums.DialogType.Warning);
            }
        }