Exemplo n.º 1
0
    /// <summary>
    /// UIForm OnBeforeSave event handler.
    /// </summary>
    protected void EditForm_OnBeforeSave(object sender, EventArgs e)
    {
        // Store parent score ID
        EditForm.Data["RuleScoreID"] = scoreId;

        // Store site ID
        if (EditForm.EditedObject.Generalized.ObjectID == 0)
        {
            EditForm.Data["RuleSiteID"] = CMSContext.CurrentSiteID;
        }

        // Store attribute or activity rule
        EditForm.Data["RuleType"] = ValidationHelper.GetInteger(radType.SelectedValue, 0);

        // For activity rule store validity
        if (!AttributeRuleSelected)
        {
            EditForm.Data["RuleValidity"] = validity.Validity;
            if (validity.Validity == ValidityEnum.Until)
            {
                if (validity.ValidUntil != DateTimeHelper.ZERO_TIME)
                {
                    EditForm.Data["RuleValidUntil"] = validity.ValidUntil;
                }
                else
                {
                    EditForm.Data["RuleValidUntil"] = null;
                }
            }
            else
            {
                EditForm.Data["RuleValidFor"]   = validity.ValidFor;
                EditForm.Data["RuleValidUntil"] = null;
            }

            // Store contact column for attribute rule
            EditForm.Data["RuleParameter"] = ucActivityType.SelectedValue;

            // Store xml with where condition
            activityFormCondition.SaveData(null);
            string whereCond = "ActivityType='" + SqlHelperClass.GetSafeQueryString(ucActivityType.SelectedValue, false) + "'";
            whereCond = SqlHelperClass.AddWhereCondition(whereCond, activityFormCondition.GetWhereCondition());
            EditForm.Data["RuleCondition"] = RuleHelper.GetConditionFromData(activityFormCondition.Data, whereCond, RuleTypeEnum.Activity, ucActivityType.SelectedValue);
        }
        // For attribute rule don't store validity
        else
        {
            EditForm.Data["RuleValidity"]   = null;
            EditForm.Data["RuleValidUntil"] = null;
            EditForm.Data["RuleValidFor"]   = null;

            // Store contact column for attribute rule
            EditForm.Data["RuleParameter"] = selectedField.Name;

            // Store xml with where condition
            formCondition.SaveData(null);
            EditForm.Data["RuleCondition"] = RuleHelper.GetConditionFromData(formCondition.Data, formCondition.GetWhereCondition(), RuleTypeEnum.Attribute, null);
        }

        // Get rule's parent object (score)
        ScoreInfo score = ScoreInfoProvider.GetScoreInfo(scoreId);

        if (score != null)
        {
            // Change status to 'Recalculation required'
            score.ScoreStatus = ScoreStatusEnum.New;
            ScoreInfoProvider.SetScoreInfo(score);
        }
    }