Exemple #1
0
    /// <summary>
    /// Show default value control and required control according to attribute type.
    /// </summary>
    public void ShowDefaultControl()
    {
        plcDefaultValue.Visible = true;
        SetFieldForTranslations();
        SetReferenceToField();

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

        HandleRequiredVisibility(dataType);

        // Hide all default value controls first
        txtDefaultValue.Visible      = false;
        chkDefaultValue.Visible      = false;
        rbDefaultValue.Visible       = false;
        txtLargeDefaultValue.Visible = false;
        datetimeDefaultValue.Visible = false;

        if ((dataType != null) && dataType.HasConfigurableDefaultValue)
        {
            var systemType = dataType.Type;

            // Date and time types
            if (systemType == typeof(DateTime))
            {
                // Use date time picker for date and time types
                datetimeDefaultValue.Visible = true;

                var calendarControl = ((FormEngineUserControl)datetimeDefaultValue.NestedControl);

                lblDefaultValue.AssociatedControlClientID = EditingFormControl.GetInputClientID(calendarControl.Controls);
            }
            else if (systemType == typeof(bool))
            {
                // Use checkbox or radio button for boolean types
                chkDefaultValue.Visible = !AllowEmpty;
                rbDefaultValue.Visible  = AllowEmpty;
                lblDefaultValue.AssociatedControlClientID = AllowEmpty ? EditingFormControl.GetInputClientID(rbDefaultValue.NestedControl.Controls) : EditingFormControl.GetInputClientID(chkDefaultValue.NestedControl.Controls);
            }
            else if (AttributeType == FieldDataType.LongText)
            {
                // Special case for long text to provide rich editor
                txtLargeDefaultValue.Visible = true;
                lblDefaultValue.AssociatedControlClientID = EditingFormControl.GetInputClientID(txtLargeDefaultValue.NestedControl.Controls);
            }
            else
            {
                // Use textbox for other types
                txtDefaultValue.Visible = true;
                lblDefaultValue.AssociatedControlClientID = EditingFormControl.GetInputClientID(txtDefaultValue.NestedControl.Controls);
            }
        }
        else
        {
            // Hide default value for types without default value
            plcDefaultValue.Visible = false;
        }
    }
Exemple #2
0
    /// <summary>
    /// Visible or hides size attribute.
    /// </summary>
    public void EnableOrDisableAttributeSize()
    {
        var fieldType = AttributeType;

        // Check if data type has variable size
        var dataType = DataTypeManager.GetDataType(TypeEnum.Field, fieldType);

        if ((dataType != null) && dataType.VariableSize)
        {
            if (IsSystemFieldSelected)
            {
                plcAttributeSize.Visible = false;
            }
            else
            {
                plcAttributeSize.Visible = true;

                // Set default size for new field
                if ((IsNewItemEdited || String.IsNullOrEmpty(txtAttributeSize.Text)) &&
                    (dataType.DefaultSize > 0))
                {
                    txtAttributeSize.Text = dataType.DefaultSize.ToString();
                }
            }
        }
        else
        {
            plcAttributeSize.Visible = false;
            txtAttributeSize.Text    = String.Empty;
        }

        if ((dataType != null) && dataType.VariablePrecision)
        {
            if (IsSystemFieldSelected)
            {
                plcAttributePrecision.Visible = false;
            }
            else
            {
                plcAttributePrecision.Visible = true;

                // Set default precision for new field
                if ((IsNewItemEdited || String.IsNullOrEmpty(txtAttributePrecision.Text)) &&
                    (dataType.DefaultPrecision > 0))
                {
                    txtAttributePrecision.Text = dataType.DefaultPrecision.ToString();
                }
            }
        }
        else
        {
            plcAttributePrecision.Visible = false;
            txtAttributePrecision.Text    = String.Empty;
        }
    }
Exemple #3
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);
    }
    /// <summary>
    /// Reloads control with data.
    /// </summary>
    public void Reload()
    {
        // Check if provided class name exists
        DataClassInfo dci = DataClassInfoProvider.GetDataClassInfo(ClassName);

        if (dci == null)
        {
            return;
        }

        // Display or hide source field selection
        if (dci.ClassIsDocumentType && (FormInfo != null) && !IsAlternativeForm && !IsInheritedForm)
        {
            // Fill source field drop down list
            pnlSourceField.Visible = true;

            // Add document name source field
            drpSourceField.Items.Clear();
            drpSourceField.Items.Add(new ListItem(GetString(dci.ClassIsProduct ? "TemplateDesigner.ImplicitProductSourceField" : "TemplateDesigner.ImplicitSourceField"), ""));

            // Add alias name source field
            drpSourceAliasField.Items.Clear();
            drpSourceAliasField.Items.Add(new ListItem(GetString("TemplateDesigner.DefaultSourceField"), ""));

            AddField(drpSourceAliasField, "NodeID");
            AddField(drpSourceAliasField, "DocumentID");

            var columnNames = FormInfo.GetColumnNames();
            if (columnNames != null)
            {
                // Add attribute list item to the list of attributes
                foreach (string name in columnNames)
                {
                    FormFieldInfo ffiColumn = FormInfo.GetFormField(name);

                    // Add only text fields
                    if (ffiColumn.IsNodeNameSourceCandidate())
                    {
                        AddField(drpSourceField, name);
                    }

                    // Add all fields which allow to be used as alias
                    var dataType = DataTypeManager.GetDataType(TypeEnum.Field, ffiColumn.DataType);
                    if ((dataType != null) && dataType.AllowAsAliasSource)
                    {
                        AddField(drpSourceAliasField, name);
                    }
                }
            }

            // Set selected value
            if (drpSourceField.Items.FindByValue(dci.ClassNodeNameSource) != null)
            {
                drpSourceField.SelectedValue = dci.ClassNodeNameSource;
            }

            if (drpSourceAliasField.Items.FindByValue(dci.ClassNodeAliasSource) != null)
            {
                drpSourceAliasField.SelectedValue = dci.ClassNodeAliasSource;
            }
        }
    }
Exemple #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);
    }
    /// <summary>
    /// Visible or hides size attribute.
    /// </summary>
    public void EnableOrDisableAttributeSize()
    {
        var fieldType = AttributeType;

        // Check if data type has variable size
        var dataType = DataTypeManager.GetDataType(TypeEnum.Field, fieldType);

        if ((dataType != null) && dataType.VariableSize && (fieldType != FieldDataType.DocAttachments))
        {
            if (IsSystemFieldSelected)
            {
                plcAttributeSize.Visible = false;
            }
            else
            {
                plcAttributeSize.Visible = true;

                // Set default size
                if (String.IsNullOrEmpty(txtAttributeSize.Text) && (dataType.DefaultSize > 0))
                {
                    txtAttributeSize.Text = dataType.DefaultSize.ToString();
                }
            }
        }
        else
        {
            plcAttributeSize.Visible = false;
            txtAttributeSize.Text    = String.Empty;
        }

        if ((dataType != null) && dataType.VariablePrecision)
        {
            if (IsSystemFieldSelected)
            {
                plcAttributePrecision.Visible = false;
            }
            else
            {
                plcAttributePrecision.Visible = true;

                // Set default size
                if (String.IsNullOrEmpty(txtAttributePrecision.Text) && (dataType.DefaultPrecision > 0))
                {
                    txtAttributePrecision.Text = dataType.DefaultPrecision.ToString();
                }
            }
        }
        else
        {
            plcAttributePrecision.Visible = false;
            txtAttributePrecision.Text    = String.Empty;
        }

        if (fieldType.Equals(FieldDataType.DocAttachments, StringComparison.InvariantCultureIgnoreCase))
        {
            chkRequired.Checked = false;
        }

        plcRequired.Visible = chkRequired.Enabled = !fieldType.Equals(FieldDataType.DocAttachments, StringComparison.InvariantCultureIgnoreCase) &&
                                                    ((Mode == FieldEditorModeEnum.AlternativeSystemTable) || (Mode != FieldEditorModeEnum.SystemTable) ||
                                                     ((Mode == FieldEditorModeEnum.SystemTable) && IsNewItemEdited && SystemContext.DevelopmentMode));

        if (!IsNewItemEdited && (IsAlternativeForm || IsInheritedForm) && !IsDummyField && !IsExtraField && !GetFormAllowEmpty())
        {
            plcRequired.Visible = false;
        }
    }