Exemplo n.º 1
0
    /// <summary>
    /// Loads text into textbox from value or from 'QueryColumnName' column.
    /// </summary>
    /// <param name="value">Value parameter</param>
    /// <returns>Returns text of options or query</returns>
    private string LoadTextFromData(string value)
    {
        InitOptions();
        txtValue.Editor.ValueIsMacro = false;

        // Options data
        if (!String.IsNullOrEmpty(value))
        {
            lstOptions.SelectedIndex = ListSourceIndex;

            // Get string representation
            SpecialFieldsDefinition def = new SpecialFieldsDefinition(null, FieldInfo, ContextResolver);
            def.LoadFromText(value);
            return(def.ToString());
        }

        // Query selected
        if (ContainsColumn(QueryColumnName))
        {
            string query = ValidationHelper.GetString(Form.Data.GetValue(QueryColumnName), string.Empty).Trim();
            if (!String.IsNullOrEmpty(query))
            {
                lstOptions.SelectedIndex = SqlSourceIndex;
                if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("CMS.Form", "EditSQLQueries"))
                {
                    mDisabledSql = true;
                }
                return(query);
            }
        }

        // Macro data source selected
        if (ContainsColumn(MacroColumnName))
        {
            string macro = ValidationHelper.GetString(Form.Data.GetValue(MacroColumnName), string.Empty).Trim();
            if (!String.IsNullOrEmpty(macro))
            {
                lstOptions.SelectedIndex     = MacroSourceIndex;
                txtValue.Editor.ValueIsMacro = true;

                return(MacroProcessor.RemoveDataMacroBrackets(macro));
            }
        }

        return(null);
    }
    /// <summary>
    /// Prepares new field.
    /// </summary>
    /// <param name="controlName">Code name of used control</param>
    private FormFieldInfo PrepareNewField(string controlName)
    {
        FormFieldInfo ffi = new FormFieldInfo();

        string[] controlDefaultDataType = FormUserControlInfoProvider.GetUserControlDefaultDataType(controlName);
        ffi.DataType  = controlDefaultDataType[0];
        ffi.Size      = ValidationHelper.GetInteger(controlDefaultDataType[1], 0);
        ffi.FieldType = FormFieldControlTypeEnum.CustomUserControl;

        FormUserControlInfo control = FormUserControlInfoProvider.GetFormUserControlInfo(controlName);

        if (control != null)
        {
            ffi.SetPropertyValue(FormFieldPropertyEnum.FieldCaption, control.UserControlDisplayName);
        }

        ffi.AllowEmpty              = true;
        ffi.PublicField             = true;
        ffi.Name                    = GetUniqueFieldName(controlName);
        ffi.Settings["controlname"] = controlName;

        // For list controls create three default options
        if (FormHelper.HasListControl(ffi))
        {
            SpecialFieldsDefinition optionDefinition = new SpecialFieldsDefinition();

            for (int i = 1; i <= 3; i++)
            {
                optionDefinition.Add(new SpecialField
                {
                    Value = OptionsDesigner.DEFAULT_OPTION + i,
                    Text  = OptionsDesigner.DEFAULT_OPTION + i
                });
            }

            ffi.Settings["Options"] = optionDefinition.ToString();
        }

        if (controlName.EqualsCSafe("CalendarControl"))
        {
            ffi.Settings["EditTime"] = false;
        }

        return(ffi);
    }
    /// <summary>
    /// Loads text into textbox from value or from 'QueryColumnName' column.
    /// </summary>
    /// <param name="value">Value parameter</param>
    /// <returns>Returns text of options or query</returns>
    private string LoadTextFromData(string value)
    {
        InitOptions();

        // Options data
        if (!String.IsNullOrEmpty(value))
        {
            lstOptions.SelectedIndex = ListSourceIndex;

            // Get string representation
            SpecialFieldsDefinition def = new SpecialFieldsDefinition(null, FieldInfo, ContextResolver);
            def.LoadFromText(value);
            return def.ToString();
        }
        // Query selected
        else if (ContainsColumn(QueryColumnName))
        {
            string query = ValidationHelper.GetString(Form.Data.GetValue(QueryColumnName), string.Empty).Trim();
            if (!String.IsNullOrEmpty(query))
            {
                lstOptions.SelectedIndex = SqlSourceIndex;
                if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("CMS.Form", "EditSQLQueries"))
                {
                    disabledSql = true;
                }
                return query;
            }
            // Macro data source selected
            else if (ContainsColumn(MacroColumnName))
            {
                string macro = ValidationHelper.GetString(Form.Data.GetValue(MacroColumnName), string.Empty).Trim();
                if (!String.IsNullOrEmpty(macro))
                {
                    lstOptions.SelectedIndex = MacroSourceIndex;
                    return macro;
                }
            }
        }

        return null;
    }
    /// <summary>
    /// Prepares new field.
    /// </summary>
    /// <param name="controlName">Code name of used control</param>
    private FormFieldInfo PrepareNewField(string controlName)
    {
        FormFieldInfo ffi = new FormFieldInfo();

        string[] controlDefaultDataType = FormUserControlInfoProvider.GetUserControlDefaultDataType(controlName);
        ffi.DataType = controlDefaultDataType[0];
        ffi.Size = ValidationHelper.GetInteger(controlDefaultDataType[1], 0);
        ffi.FieldType = FormFieldControlTypeEnum.CustomUserControl;

        FormUserControlInfo control = FormUserControlInfoProvider.GetFormUserControlInfo(controlName);
        if (control != null)
        {
            ffi.SetPropertyValue(FormFieldPropertyEnum.FieldCaption, control.UserControlDisplayName);
        }

        ffi.AllowEmpty = true;
        ffi.PublicField = true;
        ffi.Name = GetUniqueFieldName(controlName);
        ffi.Settings["controlname"] = controlName;

        // For list controls create three default options
        if (FormHelper.HasListControl(ffi))
        {
            SpecialFieldsDefinition optionDefinition = new SpecialFieldsDefinition();

            for (int i = 1; i <= 3; i++)
            {
                optionDefinition.Add(new SpecialField
                {
                    Value = OptionsDesigner.DEFAULT_OPTION + i,
                    Text = OptionsDesigner.DEFAULT_OPTION + i
                });
            }

            ffi.Settings["Options"] = optionDefinition.ToString();
        }

        if (controlName.EqualsCSafe("CalendarControl"))
        {
            ffi.Settings["EditTime"] = false;
        }

        return ffi;
    }