/// <summary>
    /// Loads the from definition from selected parameter into a BasicForm control.
    /// </summary>
    /// <param name="actual">If true, data from actual hiddens are loaded</param>
    private void LoadFormDefinition(bool actual)
    {
        MacroRuleTree selected = GetSelected((actual ? hdnParamSelected.Value : hdnLastSelected.Value));

        if (selected != null)
        {
            string             paramName = (actual ? hdnParam.Value.ToLowerCSafe() : hdnLastParam.Value.ToLowerCSafe());
            MacroRuleParameter param     = selected.Parameters[paramName];
            if (param != null)
            {
                FormInfo      fi  = new FormInfo(selected.RuleParameters);
                FormFieldInfo ffi = fi.GetFormField(paramName);
                if (ffi != null)
                {
                    fi = new FormInfo();
                    fi.AddFormItem(ffi);

                    // Add fake DisplayName field
                    FormFieldInfo displayName = new FormFieldInfo();
                    displayName.Visible  = false;
                    displayName.Name     = "DisplayName";
                    displayName.DataType = FieldDataType.Text;
                    fi.AddFormItem(displayName);

                    DataRow row = fi.GetDataRow().Table.NewRow();

                    if (ffi.AllowEmpty && String.IsNullOrEmpty(param.Value))
                    {
                        if (!DataTypeManager.IsString(TypeEnum.Field, ffi.DataType))
                        {
                            row[paramName] = DBNull.Value;
                        }
                    }
                    else
                    {
                        // Convert to a proper type
                        var val = DataTypeManager.ConvertToSystemType(TypeEnum.Field, ffi.DataType, param.Value, CultureHelper.EnglishCulture);
                        if (val != null)
                        {
                            row[paramName] = val;
                        }
                    }

                    formElem.DataRow         = row;
                    formElem.FormInformation = fi;
                    formElem.ReloadData();
                }
            }
        }
    }
示例#2
0
    /// <summary>
    /// Validates database configuration. Returns error message if validation fails.
    /// </summary>
    public string Validate()
    {
        var fieldType = AttributeType;

        var dataType = DataTypeManager.GetDataType(TypeEnum.Field, fieldType);

        if (dataType != null)
        {
            int attributeSize = ValidationHelper.GetInteger(AttributeSize, 0);

            if (dataType.VariableSize && (fieldType != FieldDataType.DocAttachments))
            {
                // Attribute size is invalid -> error
                if ((attributeSize <= 0) || (attributeSize > dataType.MaxSize))
                {
                    return(String.Format(GetString("TemplateDesigner.ErrorInvalidAttributeSize"), dataType.MaxSize));
                }

                // Validate default value size for string field
                if (!txtDefaultValue.IsMacro && DataTypeManager.IsString(TypeEnum.Field, fieldType))
                {
                    string defaultValue = ValidationHelper.GetString(txtDefaultValue.Value, String.Empty);
                    if (defaultValue.Length > attributeSize)
                    {
                        return(String.Format(GetString("TemplateDesigner.ErrorDefaultValueSize"), dataType.MaxSize));
                    }
                }
            }

            if (dataType.VariablePrecision)
            {
                int attributePrec = ValidationHelper.GetInteger(AttributePrecision, 0);

                var maxPrecision = dataType.MaxPrecision;
                if (dataType.VariableSize && (attributeSize < maxPrecision))
                {
                    maxPrecision = attributeSize;
                }

                // Attribute size is invalid -> error
                if ((attributePrec < 0) || (attributePrec > maxPrecision))
                {
                    return(String.Format(GetString("TemplateDesigner.ErrorInvalidAttributePrecision"), maxPrecision));
                }
            }
        }

        return(null);
    }
示例#3
0
        /// <summary>
        /// Loads columns from given data class info.
        /// </summary>
        /// <param name="dci">DataClassInfo containing columns definitions</param>
        private void LoadColumns(DataClassInfo dci)
        {
            // Get info object based on form definition
            FormInfo fi = FormHelper.GetFormInfo(dci.ClassName, false);

            // Get column names from form info
            List <string> columnNames = fi.GetColumnNames();

            if (columnNames != null)
            {
                foreach (string name in columnNames)
                {
                    var ffi = fi.GetFormField(name);

                    // Add text fields to collection
                    if (DataTypeManager.IsString(TypeEnum.Field, ffi.DataType) && !ExcludeFields.Contains(name))
                    {
                        CMSUserProperties.Add(name);
                    }
                }
            }
        }
示例#4
0
    /// <summary>
    /// Loads custom fields collisions.
    /// </summary>
    private void LoadCustomFields()
    {
        // Check if account has any custom fields
        FormInfo formInfo = FormHelper.GetFormInfo(mParentAccount.ClassName, false);
        var      list     = formInfo.GetFormElements(true, false, true);

        if (list.OfType <FormFieldInfo>().Any())
        {
            FormFieldInfo  ffi;
            Literal        content;
            LocalizedLabel lbl;
            CMSTextBox     txt;
            content      = new Literal();
            content.Text = "<div class=\"form-horizontal\">";
            plcCustomFields.Controls.Add(content);

            // Display all custom fields
            foreach (IField item in list)
            {
                ffi = item as FormFieldInfo;
                if (ffi != null)
                {
                    // Display layout
                    content      = new Literal();
                    content.Text = "<div class=\"form-group\"><div class=\"editing-form-label-cell\">";
                    plcCustomFields.Controls.Add(content);
                    lbl                     = new LocalizedLabel();
                    lbl.Text                = ffi.GetPropertyValue(FormFieldPropertyEnum.FieldCaption, MacroContext.CurrentResolver);
                    lbl.DisplayColon        = true;
                    lbl.EnableViewState     = false;
                    lbl.CssClass            = "control-label";
                    content                 = new Literal();
                    content.Text            = "</div><div class=\"editing-form-control-cell\"><div class=\"control-group-inline-forced\">";
                    txt                     = new CMSTextBox();
                    txt.ID                  = "txt" + ffi.Name;
                    lbl.AssociatedControlID = txt.ID;
                    plcCustomFields.Controls.Add(lbl);
                    plcCustomFields.Controls.Add(content);
                    plcCustomFields.Controls.Add(txt);
                    mCustomFields.Add(ffi.Name, new object[]
                    {
                        txt,
                        ffi.DataType
                    });
                    DataTable dt;

                    // Get grouped dataset
                    if (DataTypeManager.IsString(TypeEnum.Field, ffi.DataType))
                    {
                        dt = SortGroupAccountsByColumn(ffi.Name + SqlHelper.ORDERBY_ASC, ffi.Name + " NOT LIKE ''", ffi.Name);
                    }
                    else
                    {
                        dt = SortGroupAccountsByColumn(ffi.Name + SqlHelper.ORDERBY_ASC, ffi.Name + " IS NOT NULL", ffi.Name);
                    }

                    // Load value into textbox
                    txt.Text = ValidationHelper.GetString(mParentAccount.GetValue(ffi.Name), null);
                    if (string.IsNullOrEmpty(txt.Text) && (dt.Rows.Count > 0))
                    {
                        txt.Text = ValidationHelper.GetString(dt.Rows[0][ffi.Name], null);
                    }

                    // Display tooltip
                    var img = new HtmlGenericControl("i");
                    img.Attributes["class"] = "validation-warning icon-exclamation-triangle form-control-icon";
                    DisplayTooltip(img, dt, ffi.Name, ValidationHelper.GetString(mParentAccount.GetValue(ffi.Name), ""), ffi.DataType);
                    plcCustomFields.Controls.Add(img);
                    content      = new Literal();
                    content.Text = "</div></div></div>";
                    plcCustomFields.Controls.Add(content);
                    mMergedAccounts.Tables[0].DefaultView.RowFilter = null;
                }
            }
            content      = new Literal();
            content.Text = "</div>";
            plcCustomFields.Controls.Add(content);
        }
        else
        {
            tabCustomFields.Visible    = false;
            tabCustomFields.HeaderText = null;
        }
    }
示例#5
0
    /// <summary>
    /// Validates database configuration. Returns error message if validation fails.
    /// </summary>
    /// <param name="originalFieldInfo">Original field info</param>
    public string Validate(FormFieldInfo originalFieldInfo)
    {
        var fieldType = AttributeType;

        var dataType = DataTypeManager.GetDataType(TypeEnum.Field, fieldType);

        if (dataType != null)
        {
            int attributeSize = ValidationHelper.GetInteger(AttributeSize, 0);

            if (dataType.VariableSize)
            {
                // Attribute size is invalid -> error
                if ((attributeSize <= 0) || (attributeSize > dataType.MaxSize))
                {
                    return(String.Format(GetString("TemplateDesigner.ErrorInvalidAttributeSize"), dataType.MaxSize));
                }

                // Validate default value size for string field
                if (!txtDefaultValue.IsMacro && DataTypeManager.IsString(TypeEnum.Field, fieldType))
                {
                    var defValue = ValidationHelper.GetString(txtDefaultValue.Value, String.Empty);
                    if (defValue.Length > attributeSize)
                    {
                        return(String.Format(GetString("TemplateDesigner.ErrorDefaultValueSize"), dataType.MaxSize));
                    }
                }
            }

            if (dataType.VariablePrecision)
            {
                int attributePrec = ValidationHelper.GetInteger(AttributePrecision, 0);

                var maxPrecision = dataType.MaxPrecision;
                if (dataType.VariableSize && (attributeSize < maxPrecision))
                {
                    maxPrecision = attributeSize;
                }

                // Attribute size is invalid -> error
                if ((attributePrec < 0) || (attributePrec > maxPrecision))
                {
                    return(String.Format(GetString("TemplateDesigner.ErrorInvalidAttributePrecision"), maxPrecision));
                }
            }
        }

        // Validate configuration for dependent page type
        var msg = ValidateDependentPageTypes(originalFieldInfo, dataType);

        if (!String.IsNullOrEmpty(msg))
        {
            return(msg);
        }

        UpdateDefaultValueControlSettings();

        // Get the default value
        var ctrl = GetDefaultValueControl();

        // Validate the value through control itself
        if (!ctrl.IsValid())
        {
            return(GetString("TemplateDesigner.ErrorDefaultValue") + " " + ctrl.ValidationError);
        }

        // Validate the default value for proper type
        bool   isMacro;
        string defaultValue = GetDefaultValue(out isMacro);

        if (!isMacro && !IsNowOrToday(defaultValue))
        {
            // Validate input value
            var checkType = new DataTypeIntegrity(defaultValue, AttributeType);

            var result = checkType.ValidateDataType();
            if (!String.IsNullOrEmpty(result))
            {
                return(GetString("TemplateDesigner.ErrorDefaultValue") + " " + result);
            }
        }

        return(null);
    }