/// <summary>
    /// Creates new <see cref="FieldMacroRule"/> object based on inputs.
    /// </summary>
    private FieldMacroRule CreateMacroRule()
    {
        if (!IsValid())
        {
            return(null);
        }

        MacroRuleTree  main = null;
        FieldMacroRule fmr  = null;

        MacroRuleInfo mri = MacroRuleInfoProvider.GetMacroRuleInfo(mSelectedRuleName);

        if (mri != null)
        {
            main = new MacroRuleTree();

            MacroRuleTree childern = new MacroRuleTree()
            {
                RuleText      = mri.MacroRuleText,
                RuleName      = mri.MacroRuleName,
                RuleCondition = mri.MacroRuleCondition,
                Parent        = main
            };
            main.Children.Add(childern);

            foreach (string paramName in formProperties.Fields)
            {
                // Load value from the form control
                FormEngineUserControl ctrl = formProperties.FieldControls[paramName];
                if (ctrl != null)
                {
                    // Convert value to EN culture
                    var dataType = ctrl.FieldInfo.DataType;

                    var convertedValue = DataTypeManager.ConvertToSystemType(TypeEnum.Field, dataType, ctrl.Value);

                    string value       = ValidationHelper.GetString(convertedValue, "", CultureHelper.EnglishCulture);
                    string displayName = ctrl.ValueDisplayName;

                    if (String.IsNullOrEmpty(displayName))
                    {
                        displayName = value;
                    }

                    MacroRuleParameter param = new MacroRuleParameter
                    {
                        Value     = value,
                        Text      = displayName,
                        ValueType = dataType
                    };

                    childern.Parameters.Add(paramName, param);
                }
            }

            string macroRule = string.Format("Rule(\"{0}\", \"{1}\")", MacroElement.EscapeSpecialChars(main.GetCondition()), MacroElement.EscapeSpecialChars(main.GetXML()));

            if (!MacroSecurityProcessor.IsSimpleMacro(macroRule))
            {
                // Sign complex macros
                macroRule = MacroSecurityProcessor.AddMacroSecurityParams(macroRule, MacroIdentityOption.FromUserInfo(MembershipContext.AuthenticatedUser));
            }

            fmr              = new FieldMacroRule();
            fmr.MacroRule    = string.Format("{{%{0}%}}", macroRule);
            fmr.ErrorMessage = txtErrorMsg.Text;
        }

        return(fmr);
    }