Exemplo n.º 1
0
        /// <summary>
        /// Occours when activating the controller
        /// </summary>
        protected override void OnActivated()
        {
            base.OnActivated();

            var wizardDetailViewForm = Frame.Template as WizardDetailViewForm;

            if (wizardDetailViewForm != null)
            {
                var modelWizard = (IModelDetailViewWizard)((DetailView)View).Model;
                _wizardForm = wizardDetailViewForm;

                _wizardForm.WizardControl.CancelClick          += WizardControl_CancelClick;
                _wizardForm.WizardControl.FinishClick          += WizardControl_FinishClick;
                _wizardForm.WizardControl.NextClick            += WizardControl_NextClick;
                _wizardForm.WizardControl.SelectedPageChanged  += WizardControl_SelectedPageChanged;
                _wizardForm.WizardControl.SelectedPageChanging += WizardControl_SelectedPageChanging;
                _wizardForm.WizardControl.BeginUpdate();

                try {
                    var finishPage = _wizardForm.WizardControl.Pages[0] as CompletionWizardPage;
                    foreach (IModelDetailViewWizardPage page in modelWizard.Wizard)
                    {
                        OnWizardPageDetailViewCreating();
                        var detailView = Application.CreateDetailView(ObjectSpace, page.DetailView, false);
                        OnWizardPageDetailViewCreated();
                        detailView.CurrentObject = View.CurrentObject;

                        var wizardPage = new XafWizardPage
                        {
                            View            = detailView,
                            Text            = page.Caption,
                            DescriptionText = page.Description
                        };
                        _wizardForm.WizardControl.Pages.Insert(finishPage, wizardPage);
                    }

                    if (!modelWizard.Wizard.ShowCompletionWizardPage)
                    {
                        _wizardForm.WizardControl.Pages.Remove(finishPage);
                    }
                } finally {
                    _wizardForm.WizardControl.EndUpdate();
                }
            }
        }
Exemplo n.º 2
0
        private IList ModifiedObjects(XafWizardPage page)
        {
            IList modifiedObjects;

            if (page.View.ObjectTypeInfo.IsPersistent)
            {
                modifiedObjects = ObjectSpace.ModifiedObjects;
                if (modifiedObjects.Count == 0)
                {
                    modifiedObjects.Add(page.View.CurrentObject);
                }
            }
            else
            {
                modifiedObjects =
                    new List <object> {
                    page.View.CurrentObject
                }
            };
            return(modifiedObjects);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Fires after the next button has been clicked
        /// </summary>
        private bool Validate(XafWizardPage page)
        {
            if (page == null)
            {
                return(true);
            }
            var validationResults = new RuleSetValidationResult();
            var usedProperties = new List <string>();
            var resultsHighlightControllers = new List <ResultsHighlightController> {
                Frame.GetController <ResultsHighlightController>()
            }.Where(controller => controller != null).ToList();

            foreach (var item in page.View.GetItems <PropertyEditor>())
            {
                if (item.Control != null && ((Control)item.Control).Visible)
                {
                    usedProperties.Add(item.PropertyName);
                    var editor = item as ListPropertyEditor;
                    if (editor != null)
                    {
                        usedProperties.AddRange(editor.ListView.Editor.RequiredProperties.Select(property => property.TrimEnd('!')));

                        var nestedController = editor.Frame.GetController <ResultsHighlightController>();
                        if (nestedController != null)
                        {
                            resultsHighlightControllers.Add(nestedController);
                        }
                    }
                }
            }

            var modifiedObjects = ModifiedObjects(page);

            foreach (var obj in modifiedObjects)
            {
                IList <IRule> rules = Validator.RuleSet.GetRules(obj, ContextIdentifier.Save);
                foreach (IRule rule in rules)
                {
                    bool ruleInUse = rule.UsedProperties.Any(property => usedProperties.Contains(property) || !string.IsNullOrEmpty(usedProperties.FirstOrDefault(p => p.EndsWith(
                                                                                                                                                                      $".{property}"))));
                    string reason;
                    if (ruleInUse && RuleSet.NeedToValidateRule(ObjectSpace, rule, obj, out reason))
                    {
                        var objectSpaceLink = rule as IObjectSpaceLink;
                        if (objectSpaceLink != null)
                        {
                            objectSpaceLink.ObjectSpace = ObjectSpace;
                        }
                        RuleValidationResult result = rule.Validate(obj);
                        if (result.State == ValidationState.Invalid)
                        {
                            validationResults.AddResult(new RuleSetValidationResultItem(obj, ContextIdentifier.Save, rule, result));
                        }
                    }
                }
            }

            foreach (ResultsHighlightController resultsHighlightController in resultsHighlightControllers)
            {
                resultsHighlightController.ClearHighlighting();
                if (validationResults.State == ValidationState.Invalid)
                {
                    resultsHighlightController.HighlightResults(validationResults);
                }
            }

            return(validationResults.State != ValidationState.Invalid);
        }