Пример #1
0
    /// <summary>
    /// Loads the data row data from given web part instance.
    /// </summary>
    /// <param name="dr">DataRow to fill</param>
    private void LoadDataRowFromWidget(DataRow dr, FormInfo fi)
    {
        if (mWidgetInstance != null)
        {
            foreach (DataColumn column in dr.Table.Columns)
            {
                try
                {
                    bool load = true;
                    // switch by xml version
                    switch (mXmlVersion)
                    {
                    case 1:
                        load = mWidgetInstance.Properties.Contains(column.ColumnName.ToLowerCSafe()) || column.ColumnName.EqualsCSafe("webpartcontrolid", true);
                        break;

                    // Version 0
                    default:
                        // Load default value for Boolean type in old XML version
                        if ((column.DataType == typeof(bool)) && !mWidgetInstance.Properties.Contains(column.ColumnName.ToLowerCSafe()))
                        {
                            FormFieldInfo ffi = fi.GetFormField(column.ColumnName);
                            if (ffi != null)
                            {
                                mWidgetInstance.SetValue(column.ColumnName, ffi.GetPropertyValue(FormFieldPropertyEnum.DefaultValue));
                            }
                        }
                        break;
                    }

                    if (load)
                    {
                        object value = mWidgetInstance.GetValue(column.ColumnName);

                        // Convert value into default format
                        if ((value != null) && (value.ToString() != ""))
                        {
                            if (column.DataType == typeof(decimal))
                            {
                                value = ValidationHelper.GetDouble(value, 0, "en-us");
                            }

                            if (column.DataType == typeof(DateTime))
                            {
                                value = ValidationHelper.GetDateTime(value, DateTime.Now, "en-us");
                            }
                        }

                        if (!DataHelper.IsEmpty(value))
                        {
                            DataHelper.SetDataRowValue(dr, column.ColumnName, value);
                        }
                    }
                }
                catch
                {
                }
            }
        }
    }
Пример #2
0
        public IControl Create(FormFieldInfo info)
        {
            var control = new T
            {
                Name            = info.Name,
                Label           = info.Caption,
                IsRequired      = !info.AllowEmpty,
                DefaultValue    = info.DefaultValue,
                ExplanationText = info.GetPropertyValue(FormFieldPropertyEnum.ExplanationText),
                Tooltip         = info.GetPropertyValue(FormFieldPropertyEnum.FieldDescription)
            };

            foreach (var validationInfo in info.FieldMacroRules)
            {
                var validation = _validationFactory.Create(validationInfo);
                if (validation == null)
                {
                    continue;
                }

                control.Validation.Add(validation);
            }

            return(control);
        }
Пример #3
0
    /// <summary>
    /// Returns name of the primary key column.
    /// </summary>
    /// <param name="fi">Form info</param>
    /// <param name="bizFormName">Bizform code name</param>
    private static string GetPrimaryColumn(FormInfo fi, string bizFormName)
    {
        string result = null;

        if ((fi != null) && (!string.IsNullOrEmpty(bizFormName)))
        {
            // Try to get field with the name 'bizformnameID'
            FormFieldInfo ffi = fi.GetFormField(bizFormName + "ID");
            if ((ffi != null) && ffi.PrimaryKey)
            {
                result = ffi.Name;
            }
            else
            {
                // Seek primary key column in all fields
                FormFieldInfo[] fields = fi.GetFields(true, true);
                foreach (FormFieldInfo field in fields)
                {
                    if (field.PrimaryKey)
                    {
                        result = field.Name;
                        break;
                    }
                }
            }
        }

        return(result);
    }
Пример #4
0
    /// <summary>
    /// Returns field caption of the specified column.
    /// </summary>
    /// <param name="ffi">Form field info</param>
    /// <param name="columnName">Column name</param>
    /// <param name="resolver">Macro resolver</param>
    protected string GetFieldCaption(FormFieldInfo ffi, string columnName, MacroResolver resolver)
    {
        // Get field caption
        string caption = ffi.GetPropertyValue(FormFieldPropertyEnum.FieldCaption, resolver);

        return(((ffi == null) || (caption == string.Empty)) ? columnName : caption);
    }
        public IControl Create(FormFieldInfo info)
        {
            var control = new T
            {
                Name       = info.Name,
                Label      = info.Caption,
                IsRequired = !info.AllowEmpty,
                HasMultipleDefaultValues = true,
                ExplanationText          = info.GetPropertyValue(FormFieldPropertyEnum.ExplanationText),
                Tooltip = info.GetPropertyValue(FormFieldPropertyEnum.FieldDescription)
            };

            var defaultValues = info.GetPropertyValue(FormFieldPropertyEnum.DefaultValue)?
                                .Split(new[] { "|" }, StringSplitOptions.RemoveEmptyEntries);

            control.DefaultValues = info.Settings["Options"].ToString()
                                    .Replace("##EMPTY##1;", " ")
                                    .Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries)
                                    .ToDictionary(item => item,
                                                  item => defaultValues?.Contains(item) ?? false);

            foreach (var validationInfo in info.FieldMacroRules)
            {
                var validation = _validationFactory.Create(validationInfo);
                if (validation == null)
                {
                    continue;
                }

                control.Validation.Add(validation);
            }

            return(control);
        }
Пример #6
0
    /// <summary>
    /// Checks datatype of given form field and return name of control which should be used with fields; sets up form field info
    /// with DataType related setting.
    /// </summary>
    /// <param name="ffi">Form field to be examined</param>
    /// <returns>Name of appropriate control name</returns>
    private static string GetControlNameForFieldDataType(FormFieldInfo ffi)
    {
        string controlName = null;

        switch (ffi.DataType)
        {
        case FieldDataType.Text:
        case FieldDataType.LongText:
            controlName = "textfilter";
            ffi.Settings["OperatorFieldName"] = ffi.Name + ".operator";
            break;

        case FieldDataType.DateTime:
            controlName = "datetimefilter";
            ffi.Settings["SecondDateFieldName"] = ffi.Name + ".seconddatetime";
            break;

        case FieldDataType.Integer:
        case FieldDataType.LongInteger:
            controlName = "numberfilter";
            ffi.Settings["OperatorFieldName"] = ffi.Name + ".operator";
            break;
        }
        return(controlName);
    }
Пример #7
0
    /// <summary>
    /// Loads custom properties to given list.
    /// </summary>
    /// <param name="properties">ArrayList to load properties to</param>
    private void LoadCustomProperties(ArrayList properties)
    {
        properties.Clear();

        // Load DataClass
        DataClassInfo productClass = DataClassInfoProvider.GetDataClass("ecommerce.sku");

        if (productClass != null)
        {
            // Load XML definition
            FormInfo fi = FormHelper.GetFormInfo(productClass.ClassName, false);
            // Get all fields
            List <IFormItem> itemList = fi.GetFormElements(true, true, true);

            if (itemList != null)
            {
                FormFieldInfo formField = null;

                // Store each field to array
                foreach (object item in itemList)
                {
                    if (item is FormFieldInfo)
                    {
                        formField = ((FormFieldInfo)(item));
                        properties.Add(formField);
                    }
                }
            }
        }
    }
Пример #8
0
    /// <summary>
    /// Initializes controls for attributre rule.
    /// </summary>
    private void InitAttributeRuleControls(int selectedFieldIndex)
    {
        FormInfo filterFieldsForm = FormHelper.GetFormInfo(OnlineMarketingObjectType.CONTACT + ".ScoringAttributeRule", false);

        var query = from formField in filterFieldsForm.GetFields(true, false)
                    orderby ResHelper.LocalizeString(formField.Caption)
                    select formField;

        fields = query.ToList <FormFieldInfo>();

        if ((fields != null) && (drpAttribute.Items.Count == 0))
        {
            foreach (FormFieldInfo field in fields)
            {
                drpAttribute.Items.Add(new ListItem(field.Caption, field.Name));
            }
        }

        if ((EditForm.EditedObject != null) && !RequestHelper.IsPostBack())
        {
            drpAttribute.SelectedValue = ValidationHelper.GetString(EditForm.Data["RuleParameter"], null);
            selectedFieldIndex         = drpAttribute.SelectedIndex;
            PreviousField = selectedFieldIndex;
        }

        selectedField = fields[selectedFieldIndex];
        FormInfo fi = new FormInfo(null);

        fi.AddFormField(selectedField);

        LoadForm(formCondition, fi, null);
    }
Пример #9
0
        public IControl Create(FormFieldInfo info)
        {
            var control = new T
            {
                Name       = info.Name,
                Label      = info.Caption,
                IsRequired = !info.AllowEmpty,
                HasMultipleDefaultValues = true,
                ExplanationText          = info.GetPropertyValue(FormFieldPropertyEnum.ExplanationText),
                Tooltip = info.GetPropertyValue(FormFieldPropertyEnum.FieldDescription)
            };

            var defaultValues = info.GetPropertyValue(FormFieldPropertyEnum.DefaultValue)?
                                .Split(new[] { "|" }, StringSplitOptions.RemoveEmptyEntries);

            control.Settings = info.Settings
                               .Cast <DictionaryEntry>()
                               .ToDictionary(item => (string)item.Key, item => (string)item.Value);

            foreach (var validationInfo in info.FieldMacroRules)
            {
                var validation = _validationFactory.Create(validationInfo);
                if (validation == null)
                {
                    continue;
                }

                control.Validation.Add(validation);
            }

            return(control);
        }
Пример #10
0
    /// <summary>
    /// Saves properties to given form field info.
    /// </summary>
    /// <param name="ffi">Form field info</param>
    public void SaveProperties(FormFieldInfo ffi)
    {
        if (ffi != null)
        {
            // Save caption
            SaveProperty(ffi, FormFieldPropertyEnum.FieldCaption, txtLabel);

            // Save explanation text
            SaveProperty(ffi, FormFieldPropertyEnum.ExplanationText, txtExplanationText);

            // Save description
            SaveProperty(ffi, FormFieldPropertyEnum.FieldDescription, txtTooltip);

            // Save default value
            SaveProperty(ffi, FormFieldPropertyEnum.DefaultValue, defaultValue.EditingControl);

            // Save if the field is required
            ffi.AllowEmpty = !chkRequired.Checked;

            // Save options
            if (plcOptions.Visible)
            {
                ffi.Settings["Options"] = optionsDesigner.OptionsDefinition;
                SaveProperty(ffi, FormFieldPropertyEnum.DefaultValue, optionsDesigner);
            }
        }
    }
    /// <summary>
    /// Saves properties to given form field info.
    /// </summary>
    /// <param name="ffi">Form field info</param>
    public void SaveProperties(FormFieldInfo ffi)
    {
        if (ffi != null)
        {
            // Save caption
            SaveProperty(ffi, FormFieldPropertyEnum.FieldCaption, txtLabel);

            // Save explanation text
            SaveProperty(ffi, FormFieldPropertyEnum.ExplanationText, txtExplanationText);

            // Save description
            SaveProperty(ffi, FormFieldPropertyEnum.FieldDescription, txtTooltip);

            // Save default value
            SaveProperty(ffi, FormFieldPropertyEnum.DefaultValue, defaultValue.EditingControl);

            // Save if the field is required
            ffi.AllowEmpty = !chkRequired.Checked;

            // Save options
            if (plcOptions.Visible)
            {
                ffi.Settings["Options"] = optionsDesigner.OptionsDefinition;
                SaveProperty(ffi, FormFieldPropertyEnum.DefaultValue, optionsDesigner);
            }
        }
    }
Пример #12
0
    /// <summary>
    /// Initializes controls for attributre rule.
    /// </summary>
    private void InitAttributeRuleControls(int selectedFieldIndex)
    {
        FormInfo filterFieldsForm = FormHelper.GetFormInfo(OnlineMarketingObjectType.CONTACT + ".ScoringAttributeRule", false);

        fields = filterFieldsForm.GetFields(true, false);

        // Sort alphabetically
        Array.Sort(fields, delegate(FormFieldInfo a, FormFieldInfo b) { return(String.Compare(ResHelper.LocalizeString(a.Caption), ResHelper.LocalizeString(b.Caption))); });

        if (filterFieldsForm != null)
        {
            if ((fields != null) && (fields.Length > 0) && (drpAttribute.Items.Count <= 0))
            {
                for (int i = 0; i < fields.Length; i++)
                {
                    drpAttribute.Items.Add(new ListItem(fields[i].Caption, fields[i].Name));
                }
            }
        }

        if ((EditForm.EditedObject != null) && !RequestHelper.IsPostBack())
        {
            drpAttribute.SelectedValue = ValidationHelper.GetString(EditForm.Data["RuleParameter"], null);
            selectedFieldIndex         = drpAttribute.SelectedIndex;
            PreviousField = selectedFieldIndex;
        }

        selectedField = fields[selectedFieldIndex];
        FormInfo fi = new FormInfo(null);

        fi.AddFormField(selectedField);

        LoadForm(formCondition, fi, null);
    }
Пример #13
0
    /// <summary>
    /// Used only for alternative forms. If current field in class allows empty then it returns TRUE.
    /// </summary>
    private bool GetFormAllowEmpty()
    {
        // Check if field exists in class
        FormInfo      fi  = FormHelper.GetFormInfo(this.ClassName, false);
        FormFieldInfo ffi = null;

        if (fi != null)
        {
            ffi = fi.GetFormField(this.ffi.Name);
            if (ffi != null)
            {
                return(ffi.AllowEmpty);
            }
        }

        // Check if field exists in coupled class
        if (!String.IsNullOrEmpty(this.CoupledClassName))
        {
            fi = FormHelper.GetFormInfo(this.CoupledClassName, false);
            if (fi != null)
            {
                ffi = fi.GetFormField(this.ffi.Name);
                if (ffi != null)
                {
                    return(ffi.AllowEmpty);
                }
            }
        }

        return(false);
    }
 public void SaveValidation(FormFieldInfo ffi)
 {
     if (ffi != null)
     {
         ffi.FieldMacroRules = ruleDesigner.Value;
     }
 }
Пример #15
0
    /// <summary>
    /// Raise callback method.
    /// </summary>
    public void RaiseCallbackEvent(string eventArgument)
    {
        if (!string.IsNullOrEmpty(eventArgument) && (mFormInfo != null))
        {
            string[] data = eventArgument.Split(':');

            // Check that data are in proper format
            if (data.Length >= 3)
            {
                switch (data[0])
                {
                case "move":
                    int    position  = ValidationHelper.GetInteger(data[3], -1);
                    string category  = data[2];
                    string fieldName = data[1];

                    // Check field existence
                    FormFieldInfo field = mFormInfo.GetFormField(fieldName);
                    string        errorMessage;
                    if (field != null)
                    {
                        // Move field to new position
                        mFormInfo.MoveFormFieldToPositionInCategory(fieldName, category, position);
                        errorMessage = SaveFormDefinition();
                    }
                    else
                    {
                        errorMessage = GetString("editedobject.notexists");
                    }
                    mCallbackResult = PrepareCallbackResult(string.Empty, errorMessage);
                    break;
                }
            }
        }
    }
Пример #16
0
    /// <summary>
    /// Loads field settings to the Settings panel.
    /// </summary>
    /// <param name="fieldName">Field name</param>
    private void LoadSettings(string fieldName)
    {
        FormFieldInfo ffi = mFormInfo.GetFormField(fieldName);

        pnlSettings.LoadSettings(ffi);
        pnlSettings.Update();
    }
Пример #17
0
    private void ProcessAjaxPostBack()
    {
        if (RequestHelper.IsPostBack())
        {
            string eventArgument = Request.Params.Get("__EVENTARGUMENT");

            if (!string.IsNullOrEmpty(eventArgument))
            {
                string[] data = eventArgument.Split(':');

                FormFieldInfo ffi;
                switch (data[0])
                {
                case "loadSettings":
                {
                    FieldName = data[1];
                    LoadSettings(FieldName);
                }
                break;

                case "remove":
                {
                    // Hide selected field from form
                    FieldName = string.Empty;
                    HideField(data[2]);
                    mReloadForm = true;
                    pnlSettings.Update();
                }
                break;

                case "hideSettingsPanel":
                {
                    FieldName = string.Empty;
                    pnlSettings.Update();
                }
                break;

                case "saveSettings":
                {
                    ffi = mFormInfo.GetFormField(FieldName);
                    FormFieldInfo originalFieldInfo = (FormFieldInfo)ffi.Clone();
                    pnlSettings.SaveSettings(ffi);
                    SaveFormDefinition(originalFieldInfo, ffi);
                    mReloadField = true;
                }
                break;

                case "addField":
                {
                    ffi       = PrepareNewField(data[1]);
                    FieldName = ffi.Name;
                    AddField(ffi, data[2], ValidationHelper.GetInteger(data[3], -1));
                    LoadSettings(FieldName);
                    mReloadForm = true;
                }
                break;
                }
            }
        }
    }
Пример #18
0
    /// <summary>
    /// Exports properties given in the array list.
    /// </summary>
    /// <param name="elem">List of properties to export</param>
    /// <param name="webPart">WebPart instance with data</param>
    private string GetProperties(ArrayList elem, WebPartInstance webPart)
    {
        StringBuilder sb = new StringBuilder();

        // Iterate through all fields
        foreach (object o in elem)
        {
            FormCategoryInfo fci = o as FormCategoryInfo;
            if (fci != null)
            {
                // We have category now
                sb.Append(Environment.NewLine + fci.CategoryCaption + Environment.NewLine + Environment.NewLine + Environment.NewLine);
            }
            else
            {
                // Form element
                FormFieldInfo ffi = o as FormFieldInfo;
                if (ffi != null)
                {
                    object value = webPart.GetValue(ffi.Name);
                    sb.Append(ffi.Caption + ": " + (value == null ? "" : value.ToString()) + Environment.NewLine + Environment.NewLine);
                }
            }
        }

        return(sb.ToString());
    }
    /// <summary>
    /// Saves form definition. Updates database column if both original and changed info is passed and the change requires database update.
    /// </summary>
    /// <param name="oldFieldInfo">Form field info prior to the change</param>
    /// <param name="updatedFieldInfo">Form field info after the change has been made.</param>
    /// <returns>Error message if an error occurred</returns>
    private string SaveFormDefinition(FormFieldInfo oldFieldInfo = null, FormFieldInfo updatedFieldInfo = null)
    {
        if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("cms.form", "EditForm"))
        {
            if (RequestHelper.IsCallback())
            {
                return(GetString("formbuilder.missingeditpermission"));
            }

            RedirectToAccessDenied("cms.form", "EditForm");
        }

        string result = SaveFormDefinitionInternal(oldFieldInfo, updatedFieldInfo);

        if (String.IsNullOrEmpty(result) && (oldFieldInfo != null) && (updatedFieldInfo != null))
        {
            // Update current field name
            FieldName = updatedFieldInfo.Name;

            // Reload the whole form if field name changed
            mReloadForm = !oldFieldInfo.Name.Equals(FieldName, StringComparison.InvariantCultureIgnoreCase);
        }

        return(result);
    }
Пример #20
0
    /// <summary>
    /// Exports properties given in the array list.
    /// </summary>
    /// <param name="elem">List of properties to export</param>
    /// <param name="webPart">WebPart instance with data</param>
    private string GetProperties(IEnumerable <IDataDefinitionItem> elem, WebPartInstance webPart)
    {
        StringBuilder sb = new StringBuilder();

        // Iterate through all fields
        foreach (object o in elem)
        {
            FormCategoryInfo fci = o as FormCategoryInfo;
            if (fci != null)
            {
                // We have category now
                sb.Append(Environment.NewLine + fci.GetPropertyValue(FormCategoryPropertyEnum.Caption, MacroContext.CurrentResolver) + Environment.NewLine + Environment.NewLine + Environment.NewLine);
            }
            else
            {
                // Form element
                FormFieldInfo ffi = o as FormFieldInfo;
                if (ffi != null)
                {
                    object value = webPart.GetValue(ffi.Name);
                    sb.Append(ffi.GetPropertyValue(FormFieldPropertyEnum.FieldCaption, MacroContext.CurrentResolver) + ": " + (value == null ? "" : value.ToString()) + Environment.NewLine + Environment.NewLine);
                }
            }
        }

        return(sb.ToString());
    }
Пример #21
0
    private void LoadOptions(FormFieldInfo ffi)
    {
        bool showOptions = FormHelper.HasListControl(ffi);

        plcOptions.Visible      = showOptions;
        plcDefaultValue.Visible = !showOptions;

        if (showOptions)
        {
            // Query means that options contains sql select statement
            bool isSqlQuery = ffi.Settings.Contains("Query");
            bool isMacro    = ffi.SettingIsMacro("Options");
            optionsDesigner.Visible = !isMacro && !isSqlQuery;

            if (isMacro)
            {
                mphOptions.ShowInformation(GetString("FormBuilder.PropertyIsMacro"));
            }
            else if (isSqlQuery)
            {
                mphOptions.ShowInformation(GetString("FormBuilder.PropertyIsNotOption"));
            }
            else
            {
                optionsDesigner.OptionsDefinition = ValidationHelper.GetString(ffi.Settings["Options"], string.Empty);
            }
        }
    }
Пример #22
0
    /// <summary>
    /// Validates database configuration of field if the class has dependent children
    /// </summary>
    /// <param name="originalFieldInfo">Original field info object</param>
    /// <param name="dataType">Field data type</param>
    /// <returns>Error message if occurs, otherwise returns null</returns>
    private string ValidateDependentPageTypes(FormFieldInfo originalFieldInfo, DataType dataType)
    {
        if ((originalFieldInfo == null) || !HasDependentChildren)
        {
            return(null);
        }

        int attributeSize        = ValidationHelper.GetInteger(AttributeSize, 0);
        var fieldHasVariableSize = (dataType != null) && dataType.VariableSize;

        // Size of the attribute can't be decreased
        if (fieldHasVariableSize && originalFieldInfo.Size > attributeSize)
        {
            return(String.Format(GetString("TemplateDesigner.SizeDecreasedError")));
        }

        var defValue = ValidationHelper.GetString(txtDefaultValue.Value, String.Empty);

        // Change field to required is not allowed without specifying default value
        if (plcRequired.Visible && originalFieldInfo.AllowEmpty && chkRequired.Checked && String.IsNullOrEmpty(defValue))
        {
            return(String.Format(GetString("TemplateDesigner.RequiredWithoutDefaultValueError")));
        }

        return(null);
    }
 public void SaveValidation(FormFieldInfo ffi)
 {
     if (ffi != null)
     {
         ffi.FieldMacroRules = ruleDesigner.Value;
     }
 }
    /// <summary>
    /// Handles OnFieldCreated action and updates form definition of all widgets based on current webpart.
    /// Newly created field is set to be disabled in widget definition for security reasons.
    /// </summary>
    /// <param name="newField">Newly created field</param>
    protected void UpdateWidgetsDefinition(object sender, FormFieldInfo newField)
    {
        if ((webPartInfo != null) && (newField != null))
        {
            // Get widgets based on this webpart
            DataSet ds = WidgetInfoProvider.GetWidgets()
                         .WhereEquals("WidgetWebPartID", WebPartID)
                         .Columns("WidgetID");

            // Continue only if there are some widgets
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    int        widgetId = ValidationHelper.GetInteger(dr["WidgetID"], 0);
                    WidgetInfo widget   = WidgetInfoProvider.GetWidgetInfo(widgetId);
                    if (widget != null)
                    {
                        // Prepare disabled field definition
                        string disabledField = String.Format("<form><field column=\"{0}\" visible=\"false\" /></form>", newField.Name);

                        // Incorporate disabled field into original definition of widget
                        widget.WidgetProperties = FormHelper.CombineFormDefinitions(widget.WidgetProperties, disabledField);

                        // Update widget
                        WidgetInfoProvider.SetWidgetInfo(widget);
                    }
                }
            }
        }
    }
Пример #25
0
    /// <summary>
    /// Reloads control with data.
    /// </summary>
    public void Reload()
    {
        // Display or hide source field selection
        if ((Mode == FieldEditorModeEnum.ClassFormDefinition) && (fi != null) && !IsAlternativeForm)
        {
            // Fill source field drop down list
            pnlSourceField.Visible = true;

            // Add document name source field
            drpSourceField.Items.Clear();

            DataClassInfo dci = DataClassInfoProvider.GetDataClass(ClassName);
            if ((dci != null) && dci.ClassIsProduct)
            {
                drpSourceField.Items.Add(new ListItem(GetString("TemplateDesigner.ImplicitProductSourceField"), ""));
            }
            else
            {
                drpSourceField.Items.Add(new ListItem(GetString("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 = fi.GetColumnNames();
            if (columnNames != null)
            {
                // Add attribute list item to the list of attributes
                foreach (string name in columnNames)
                {
                    FormFieldInfo ffiColumn = fi.GetFormField(name);
                    // Don't add primary key field
                    if (!ffiColumn.PrimaryKey)
                    {
                        AddField(drpSourceField, name);
                    }
                    AddField(drpSourceAliasField, name);
                }
            }

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

                if (drpSourceAliasField.Items.FindByValue(dci.ClassNodeAliasSource) != null)
                {
                    drpSourceAliasField.SelectedValue = dci.ClassNodeAliasSource;
                }
            }
        }
    }
Пример #26
0
    /// <summary>
    /// Loads the data row data from given web part instance.
    /// </summary>
    /// <param name="dr">DataRow to fill</param>
    /// <param name="webPart">Source web part</param>
    /// <param name="formInfo">Web part form info</param>
    private void LoadDataRowFromWebPart(DataRow dr, WebPartInstance webPart, FormInfo formInfo)
    {
        if (webPart != null)
        {
            foreach (DataColumn column in dr.Table.Columns)
            {
                try
                {
                    var  safeColumnName = column.ColumnName.ToLowerInvariant();
                    bool load           = true;
                    // switch by xml version
                    switch (xmlVersion)
                    {
                    case 1:
                        load = webPart.Properties.Contains(safeColumnName) || string.Equals("webpartcontrolid", safeColumnName, StringComparison.OrdinalIgnoreCase);
                        break;

                    // Version 0
                    default:
                        // Load default value for Boolean type in old XML version
                        if ((column.DataType == typeof(bool)) && !webPart.Properties.Contains(safeColumnName))
                        {
                            FormFieldInfo ffi = formInfo.GetFormField(column.ColumnName);
                            if (ffi != null)
                            {
                                webPart.SetValue(column.ColumnName, ffi.GetPropertyValue(FormFieldPropertyEnum.DefaultValue));
                            }
                        }
                        break;
                    }

                    if (load)
                    {
                        var value = webPart.GetValue(column.ColumnName);

                        // Convert value into default format
                        if ((value != null) && (ValidationHelper.GetString(value, String.Empty) != String.Empty))
                        {
                            if (column.DataType == typeof(decimal))
                            {
                                value = ValidationHelper.GetDouble(value, 0, "en-us");
                            }

                            if (column.DataType == typeof(DateTime))
                            {
                                value = ValidationHelper.GetDateTime(value, DateTime.MinValue, "en-us");
                            }
                        }

                        DataHelper.SetDataRowValue(dr, column.ColumnName, value);
                    }
                }
                catch (Exception ex)
                {
                    EventLogProvider.LogException("WebPartProperties", "LOADDATAROW", ex);
                }
            }
        }
    }
Пример #27
0
    protected void Page_Load(object sender, EventArgs e)
    {
        gridElem.IsLiveSite = IsLiveSite;

        // Get score ID from query string
        scoreId = QueryHelper.GetInteger("ScoreID", 0);

        // Initialize score filter
        FormFieldInfo ffi = new FormFieldInfo();

        ffi.Name                           = "SUM(Value)";
        ffi.DataType                       = FieldDataType.Integer;
        ucScoreFilter.FieldInfo            = ffi;
        ucScoreFilter.DefaultOperator      = ">=";
        ucScoreFilter.WhereConditionFormat = "{0} {2} {1}";

        // Get modify permission of current user
        modifyPermission = AuthorizationHelper.AuthorizedModifyContact(false);

        var sourceData = GetContactsWithScore();

        if (DataHelper.GetItemsCount(sourceData) >= MAX_RECORDS)
        {
            ShowInformation(GetString("om.contact.notallrecords"));
        }
        gridElem.DataSource = sourceData;


        // Register OnExternalDataBound
        gridElem.OnExternalDataBound += gridElem_OnExternalDataBound;
        gridElem.OnBeforeFiltering   += gridElem_OnBeforeFiltering;

        // Initialize dropdown lists
        if (!RequestHelper.IsPostBack())
        {
            drpAction.Items.Add(new ListItem(GetString("general." + Action.SelectAction), Convert.ToInt32(Action.SelectAction).ToString()));
            if (modifyPermission)
            {
                if (AuthorizationHelper.AuthorizedReadContact(false))
                {
                    drpAction.Items.Add(new ListItem(GetString("om.account." + Action.AddToGroup), Convert.ToInt32(Action.AddToGroup).ToString()));
                }
                drpAction.Items.Add(new ListItem(GetString("om.account." + Action.ChangeStatus), Convert.ToInt32(Action.ChangeStatus).ToString()));
            }
            drpWhat.Items.Add(new ListItem(GetString("om.contact." + What.Selected), Convert.ToInt32(What.Selected).ToString()));
            drpWhat.Items.Add(new ListItem(GetString("om.contact." + What.All), Convert.ToInt32(What.All).ToString()));
        }
        else
        {
            if (ControlsHelper.CausedPostBack(btnOk))
            {
                // Set delayed reload for unigrid if mass action is performed
                gridElem.DelayedReload = true;
            }
        }

        // Register JS scripts
        RegisterScripts();
    }
Пример #28
0
 /// <summary>
 /// Saves field settings to given form field info.
 /// </summary>
 /// <param name="ffi">Form field info</param>
 public void SaveSettings(FormFieldInfo ffi)
 {
     pnlProperties.SaveProperties(ffi);
     if (!FieldIsPrimary)
     {
         pnlValidation.SaveValidation(ffi);
     }
 }
 public void LoadRules(FormFieldInfo ffi)
 {
     if (ffi != null)
     {
         ruleDesigner.Value = ffi.FieldMacroRules;
         ruleDesigner.DefaultErrorMessage = ffi.GetPropertyValue(FormFieldPropertyEnum.ValidationErrorMessage);
     }
 }
 public void LoadRules(FormFieldInfo ffi)
 {
     if (ffi != null)
     {
         ruleDesigner.Value = ffi.FieldMacroRules;
         ruleDesigner.DefaultErrorMessage = ffi.GetPropertyValue(FormFieldPropertyEnum.ValidationErrorMessage);
     }
 }
 /// <summary>
 /// Saves field settings to given form field info.
 /// </summary>
 /// <param name="ffi">Form field info</param>
 public void SaveSettings(FormFieldInfo ffi)
 {
     pnlProperties.SaveProperties(ffi);
     if (!FieldIsPrimary)
     {
         pnlValidation.SaveValidation(ffi);
     }
 }
Пример #32
0
    /// <summary>
    /// Saves form definition. Updates database column if both original and changed info is passed and the change requires database update.
    /// </summary>
    /// <param name="oldFieldInfo">Form field info prior to the change</param>
    /// <param name="updatedFieldInfo">Form field info after the change has been made.</param>
    /// <returns>Error message if an error occurred</returns>
    protected string SaveFormDefinition(FormFieldInfo oldFieldInfo = null, FormFieldInfo updatedFieldInfo = null)
    {
        if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("cms.form", "EditForm"))
        {
            if (RequestHelper.IsCallback())
            {
                return(GetString("formbuilder.missingeditpermission"));
            }

            RedirectToAccessDenied("cms.form", "EditForm");
        }

        DataClassInfo dci = DataClassInfoProvider.GetDataClassInfo(ClassName);

        if ((FormInfo != null) && (dci != null))
        {
            RaiseBeforeDefinitionUpdate();

            // Raise event for field change
            using (var h = DataDefinitionItemEvents.ChangeItem.StartEvent(dci, oldFieldInfo, updatedFieldInfo))
            {
                // Update database column of the changed field
                if (IsDatabaseChangeRequired(oldFieldInfo, updatedFieldInfo))
                {
                    // Ensure the transaction
                    using (var tr = new CMSLateBoundTransaction())
                    {
                        TableManager tm = new TableManager(dci.ClassConnectionString);
                        tr.BeginTransaction();

                        UpdateDatabaseColumn(dci, oldFieldInfo, updatedFieldInfo, tm, dci.ClassTableName);

                        // Commit the transaction
                        tr.Commit();
                    }
                }

                // Update form definition
                dci.ClassFormDefinition = FormInfo.GetXmlDefinition();

                // Save the class data
                DataClassInfoProvider.SetDataClassInfo(dci);

                h.FinishEvent();
            }

            ClearHashtables();

            RaiseAfterDefinitionUpdate();

            // Update inherited classes with new fields
            FormHelper.UpdateInheritedClasses(dci);

            return(string.Empty);
        }

        return(GetString("FormBuilder.ErrorSavingForm"));
    }
    /// <summary>
    /// Clones given field <paramref name="ffi"/>, adds the clone next to the original field and returns name of new field in <paramref name="newFieldName"/> out parameter.
    /// </summary>
    /// <param name="ffi">Form field to be cloned</param>
    /// <param name="newFieldName">Field name of new field</param>
    private string CloneField(FormFieldInfo ffi, out string newFieldName)
    {
        if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("cms.form", "EditForm"))
        {
            RedirectToAccessDenied("cms.form", "EditForm");
        }

        return(CloneFieldInternal(ffi, out newFieldName));
    }
Пример #34
0
    /// <summary>
    /// Selected field changed
    /// </summary>
    protected void drpAttribute_SelectedIndexChanged(object sender, EventArgs e)
    {
        PreviousField = drpAttribute.SelectedIndex;
        selectedField = fields[PreviousField];
        FormInfo fi = new FormInfo(null);

        fi.AddFormField(selectedField);
        LoadForm(formCondition, fi, null);
    }
    /// <summary>
    /// Returns field caption of the specified column.
    /// </summary>
    /// <param name="ffi">Form field info</param>
    /// <param name="columnName">Column name</param>    
    protected string GetFieldCaption(FormFieldInfo ffi, string columnName)
    {
        string fieldCaption = "";

        // get field caption
        if ((ffi == null) || (ffi.Caption == ""))
        {
            fieldCaption = columnName;
        }
        else
        {
            fieldCaption = ffi.Caption;
        }

        return fieldCaption;
    }
    /// <summary>
    /// Returns field caption of the specified column.
    /// </summary>
    /// <param name="ffi">Form field info</param>
    /// <param name="columnName">Column name</param>    
    protected string GetFieldCaption(FormFieldInfo ffi, string columnName)
    {
        string fieldCaption = string.Empty;

        // get field caption
        if ((ffi == null) || (string.IsNullOrEmpty(ffi.Caption)))
        {
            fieldCaption = columnName;
        }
        else
        {
            fieldCaption = ffi.Caption;
        }

        return fieldCaption;
    }
    /// <summary>
    /// Returns field caption of the specified column.
    /// </summary>
    /// <param name="ffi">Form field info</param>
    /// <param name="columnName">Column name</param>    
    protected string GetFieldCaption(FormFieldInfo ffi, string columnName, MacroResolver resolver)
    {
        string fieldCaption = string.Empty;

        // get field caption
        if (ffi != null)
        {
            fieldCaption = ffi.GetDisplayName(resolver);
        }
        if (string.IsNullOrEmpty(fieldCaption))
        {
            fieldCaption = columnName;
        }

        return fieldCaption;
    }
    protected void editForm_OnBeforeDataLoad(object sender, EventArgs e)
    {
        if ((Variant == null) || !Variant.IsProductVariant)
        {
            EditedObject = null;
            return;
        }

        CheckEditedObjectSiteID(Variant.SKUSiteID);

        var optionsDs = SKUInfoProvider.GetSKUs()
              .WhereIn("SKUID",
                  VariantOptionInfoProvider.GetVariantOptions()
                    .Column("OptionSKUID")
                    .WhereEquals("VariantSKUID", Variant.SKUID)
               );

        var attrPos = GetAttributesPosition();
        foreach (var option in optionsDs)
        {
            if (option.Parent != null)
            {
                string categoryCodeName = option.Parent.Generalized.ObjectCodeName;
                options.Add(categoryCodeName, option);

                FormFieldInfo ffOption = new FormFieldInfo
                {
                    Name = categoryCodeName,
                    AllowEmpty = true,
                    Size = 400,
                    FieldType = FormFieldControlTypeEnum.LabelControl,
                    DataType = FieldDataType.Text,
                    IsDummyField = true,
                };

                OptionCategoryInfo parentOptionCategory = (OptionCategoryInfo)option.Parent;

                ffOption.SetPropertyValue(FormFieldPropertyEnum.DefaultValue, HTMLHelper.HTMLEncode(ResHelper.LocalizeString(option.SKUName)));

                // Show category live site display name instead of category display name in case it is available
                ffOption.SetPropertyValue(FormFieldPropertyEnum.FieldCaption, HTMLHelper.HTMLEncode(ResHelper.LocalizeString(parentOptionCategory.CategoryTitle)));

                //Insert field to the form on specified position
                editForm.FormInformation.AddFormItem(ffOption, attrPos++);
            }
        }
    }
    /// <summary>
    /// Loads settings from form field info.
    /// </summary>
    /// <param name="ffi">Form field info</param>
    public void LoadSettings(FormFieldInfo ffi)
    {
        FieldIsPrimary = ffi.PrimaryKey;

        pnlProperties.LoadProperties(ffi);
        if (!FieldIsPrimary)
        {
            pnlValidation.LoadRules(ffi);
        }
        else
        {
            // Reset selected tab value
            hdnSelectedTab.Value = null;
        }

        pnlValidation.Visible = !FieldIsPrimary;
    }
    /// <summary>
    /// Loads properties from given form field info.
    /// </summary>
    /// <param name="ffi">Form field info</param>
    public void LoadProperties(FormFieldInfo ffi)
    {
        if (ffi != null)
        {
            // Load caption
            LoadProperty(ffi, FormFieldPropertyEnum.FieldCaption, txtLabel, mphLabel);

            // Load explanation text
            LoadProperty(ffi, FormFieldPropertyEnum.ExplanationText, txtExplanationText, mphExplanationText);

            // Load tooltip
            LoadProperty(ffi, FormFieldPropertyEnum.FieldDescription, txtTooltip, mphTooltip);

            // Load default value
            LoadDefaultValue(ffi);

            // Set required checkbox
            chkRequired.Checked = !ffi.AllowEmpty;
            plcRequired.Visible = !FormHelper.IsFieldOfType(ffi, FormFieldControlTypeEnum.CheckBoxControl);

            LoadOptions(ffi);
        }
    }
    /// <summary>
    /// Sets all values of form to defaults.
    /// </summary>
    /// <param name="partialReload">True - indicates that only some controls should be loaded, False - reload all controls</param>
    private void LoadDefaultAttributeEditForm(bool partialReload)
    {
        ffi = null;
        plcCategory.Visible = false;
        chkDisplayInForm.Checked = true;

        if (!partialReload)
        {
            databaseConfiguration.DevelopmentMode = DevelopmentMode;
            databaseConfiguration.ShowSystemFields = IsSystemField;
            databaseConfiguration.IsDocumentType = IsDocumentType;
            databaseConfiguration.Mode = Mode;
            databaseConfiguration.ClassName = ClassName;
            databaseConfiguration.CoupledClassName = CoupledClassName;
            databaseConfiguration.IsAlternativeForm = IsAlternativeForm;
            databaseConfiguration.IsInheritedForm = IsInheritedForm;
            databaseConfiguration.IsDummyField = IsDummyField;
            databaseConfiguration.IsDummyFieldFromMainForm = IsDummyFieldFromMainForm;
            databaseConfiguration.IsExtraField = IsExtraField;
            databaseConfiguration.Reload(null, IsNewItemEdited);
            databaseConfiguration.ShowDefaultControl();
        }

        if (IsSystemField)
        {
            LoadSystemField();
        }

        string defaultControl = FormHelper.GetFormFieldDefaultControlType(databaseConfiguration.AttributeType);

        fieldAppearance.AttributeType = databaseConfiguration.AttributeType;
        fieldAppearance.FieldType = defaultControl;
        fieldAppearance.LoadFieldTypes(IsPrimaryField);
        fieldAppearance.ClassName = ClassName;
        fieldAppearance.Reload();
        fieldAdvancedSettings.Reload();
        cssSettings.Reload();
        htmlEnvelope.Reload();
        LoadValidationSettings();
        validationSettings.DisplayControls();
        validationSettings.Reload();
    }
    private string ValidatePrimaryKey(FormFieldInfo updatedFieldInfo)
    {
        string errorMessage = null;

        // If attribute is a primary key
        if (ffi.PrimaryKey)
        {
            // Check if the attribute type is integer number
            if (updatedFieldInfo.DataType != FieldDataType.Integer)
            {
                errorMessage += ResHelper.GetString("TemplateDesigner.ErrorPKNotInteger") + " ";
            }

            // Check if allow empty is disabled
            if (updatedFieldInfo.AllowEmpty)
            {
                errorMessage += ResHelper.GetString("TemplateDesigner.ErrorPKAllowsNulls") + " ";
            }

            // Check that the field type is label
            if (!IsLabelControlSelected(updatedFieldInfo))
            {
                errorMessage += ResHelper.GetString("TemplateDesigner.ErrorPKisNotLabel") + " ";
            }

            // An error has occurred
            if (!String.IsNullOrEmpty(errorMessage))
            {
                errorMessage = ResHelper.GetString("TemplateDesigner.ErrorPKThisIsPK") + " " + errorMessage;
            }
        }

        return errorMessage;
    }
Пример #43
0
    /// <summary>
    /// Save selected field.
    /// </summary>
    private void SaveSelectedField()
    {
        // FormFieldInfo structure with data from updated form
        FormFieldInfo ffiUpdated = null;
        // FormCategoryInfo structure with data from updated form
        FormCategoryInfo fciUpdated = null;
        // Determines whether it is a new attribute (or attribute to update)
        bool isNewItem = false;
        string errorMessage = null;
        DataClassInfo dci = null;
        WebPartInfo wpi = null;

        // Variables for changes in DB tables
        string tableName = null;
        string oldColumnName = null;
        string newColumnName = null;
        string newColumnSize = null;
        string newColumnType = null;
        string newColumnDefaultValue = null;  // No default value
        bool newColumnAllowNull = true;

        if (!IsAlternativeForm)
        {
            switch (mMode)
            {
                case FieldEditorModeEnum.WebPartProperties:
                    // Fill WebPartInfo structure with data from database
                    wpi = WebPartInfoProvider.GetWebPartInfo(mWebPartId);
                    break;

                case FieldEditorModeEnum.ClassFormDefinition:
                case FieldEditorModeEnum.BizFormDefinition:
                case FieldEditorModeEnum.SystemTable:
                case FieldEditorModeEnum.CustomTable:
                    // Fill ClassInfo structure with data from database
                    dci = DataClassInfoProvider.GetDataClass(mClassName);
                    if (dci != null)
                    {
                        // Set table name
                        tableName = dci.ClassTableName;
                    }
                    else
                    {
                        lblError.Visible = true;
                        lblError.ResourceString = "fieldeditor.notablename";
                        return;
                    }
                    break;
            }
        }

        // Load current xml form definition
        LoadFormDefinition();

        if (SelectedItemType == FieldEditorSelectedItemEnum.Field)
        {
            // Fill FormFieldInfo structure with original data
            ffi = fi.GetFormField(SelectedItemName);

            // Fill FormFieldInfo structure with updated form data
            ffiUpdated = FillFormFieldInfoStructure(ffi);

            // Determine whether it is a new attribute or not
            isNewItem = (ffi == null);

            // Check if the attribute name already exists
            if (isNewItem || (ffi.Name.ToLower() != ffiUpdated.Name.ToLower()))
            {
                columnNames = fi.GetColumnNames();

                if (columnNames != null)
                {
                    foreach (string colName in columnNames)
                    {
                        // If name already exists
                        if (ffiUpdated.Name.ToLower() == colName.ToLower())
                        {
                            lblError.Visible = true;
                            lblError.ResourceString = "TemplateDesigner.ErrorExistingColumnName";
                            return;
                        }
                    }
                }

                // Check column name duplicity in JOINed tables
                if (!IsSystemFieldSelected)
                {
                    // Check whether current column already exists in 'View_CMS_Tree_Joined'
                    if (IsDocumentType && DocumentHelper.ColumnExistsInSystemTable(ffiUpdated.Name))
                    {
                        lblError.Visible = true;
                        lblError.ResourceString = "TemplateDesigner.ErrorExistingColumnInJoinedTable";
                        return;
                    }

                    // Check whether current column is uniquie in tables used to create views - applied only for system tables
                    if ((Mode == FieldEditorModeEnum.SystemTable) && FormHelper.ColumnExistsInView(mClassName, ffiUpdated.Name))
                    {
                        lblError.Visible = true;
                        lblError.ResourceString = "TemplateDesigner.ErrorExistingColumnInJoinedTable";
                        return;
                    }
                }
            }

            // New node
            if (isNewItem)
            {
                ffiUpdated.PrimaryKey = this.IsPrimaryField;
                newColumnName = ffiUpdated.Name;
                newColumnAllowNull = ffiUpdated.AllowEmpty;

                // Set implicit default value
                if (!(newColumnAllowNull) && (string.IsNullOrEmpty(ffiUpdated.DefaultValue)))
                {
                    if (!this.DevelopmentMode)
                    {
                        switch (ffiUpdated.DataType)
                        {
                            case FormFieldDataTypeEnum.Integer:
                            case FormFieldDataTypeEnum.LongInteger:
                            case FormFieldDataTypeEnum.Decimal:
                            case FormFieldDataTypeEnum.Boolean:
                                newColumnDefaultValue = "0";
                                break;

                            case FormFieldDataTypeEnum.Text:
                            case FormFieldDataTypeEnum.LongText:
                            case FormFieldDataTypeEnum.DocumentAttachments:
                                newColumnDefaultValue = "";
                                break;

                            case FormFieldDataTypeEnum.DateTime:
                                newColumnDefaultValue = new DateTime(1970, 1, 1, 0, 0, 0).ToString();
                                break;

                            case FormFieldDataTypeEnum.File:
                            case FormFieldDataTypeEnum.GUID:
                                // 32 digits, empty Guid
                                newColumnDefaultValue = Guid.Empty.ToString();
                                break;

                            case FormFieldDataTypeEnum.Binary:
                                newColumnDefaultValue = null;
                                break;
                        }
                    }
                }
                // Check if default value is in required format
                else if (!string.IsNullOrEmpty(ffiUpdated.DefaultValue))
                {
                    // If default value is macro, don't try to ensure the type
                    if (!ffiUpdated.IsMacro)
                    {
                        switch (ffiUpdated.DataType)
                        {
                            case FormFieldDataTypeEnum.Integer:
                                try
                                {
                                    int i = Int32.Parse(ffiUpdated.DefaultValue);
                                    newColumnDefaultValue = i.ToString();
                                }
                                catch
                                {
                                    newColumnDefaultValue = "0";
                                    errorMessage = GetString("TemplateDesigner.ErrorDefaultValueInteger");
                                }
                                break;

                            case FormFieldDataTypeEnum.LongInteger:
                                try
                                {
                                    long longInt = long.Parse(ffiUpdated.DefaultValue);
                                    newColumnDefaultValue = longInt.ToString();
                                }
                                catch
                                {
                                    newColumnDefaultValue = "0";
                                    errorMessage = GetString("TemplateDesigner.ErrorDefaultValueLongInteger");
                                }
                                break;

                            case FormFieldDataTypeEnum.Decimal:
                                if (ValidationHelper.IsDouble(ffiUpdated.DefaultValue))
                                {
                                    newColumnDefaultValue = FormHelper.GetDoubleValueInDBCulture(ffiUpdated.DefaultValue);
                                }
                                else
                                {
                                    newColumnDefaultValue = "0";
                                    errorMessage = GetString("TemplateDesigner.ErrorDefaultValueDouble");
                                }
                                break;

                            case FormFieldDataTypeEnum.DateTime:
                                if ((ffiUpdated.DefaultValue.ToLower() == DateTimePicker.DATE_TODAY.ToLower()) || (ffiUpdated.DefaultValue.ToLower() == DateTimePicker.TIME_NOW.ToLower()))
                                {
                                    newColumnDefaultValue = ffiUpdated.DefaultValue;
                                }
                                else
                                {
                                    try
                                    {
                                        DateTime dat = DateTime.Parse(ffiUpdated.DefaultValue);
                                        newColumnDefaultValue = dat.ToString();
                                    }
                                    catch
                                    {
                                        newColumnDefaultValue = DateTime.Now.ToString();
                                        errorMessage = GetString("TemplateDesigner.ErrorDefaultValueDateTime");
                                    }
                                }
                                break;

                            case FormFieldDataTypeEnum.File:
                            case FormFieldDataTypeEnum.GUID:
                                try
                                {
                                    Guid g = new Guid(ffiUpdated.DefaultValue);
                                    newColumnDefaultValue = g.ToString();
                                }
                                catch
                                {
                                    newColumnDefaultValue = Guid.Empty.ToString();
                                    errorMessage = GetString("TemplateDesigner.ErrorDefaultValueGuid");
                                }
                                break;

                            case FormFieldDataTypeEnum.LongText:
                            case FormFieldDataTypeEnum.Text:
                            case FormFieldDataTypeEnum.Boolean:

                                newColumnDefaultValue = ffiUpdated.DefaultValue;
                                break;
                        }
                    }
                }

                // Set column type and size
                LoadColumnTypeAndSize(ffiUpdated.DataType, ffiUpdated.Size, ref newColumnType, ref newColumnSize);

                if (string.IsNullOrEmpty(errorMessage))
                {
                    if (!IsAlternativeForm)
                    {
                        switch (mMode)
                        {
                            case FieldEditorModeEnum.ClassFormDefinition:
                            case FieldEditorModeEnum.BizFormDefinition:
                            case FieldEditorModeEnum.SystemTable:
                            case FieldEditorModeEnum.CustomTable:

                                // Add new column to specified table
                                try
                                {
                                    string newDBDefaultValue = null;

                                    // Check if it is not a macro
                                    if (ffiUpdated.IsMacro)
                                    {
                                        newDBDefaultValue = newColumnDefaultValue;
                                    }
                                    else
                                    {
                                        switch (ffiUpdated.DataType)
                                        {
                                            case FormFieldDataTypeEnum.Decimal:
                                                newDBDefaultValue = FormHelper.GetDoubleValueInDBCulture(newColumnDefaultValue);
                                                break;

                                            case FormFieldDataTypeEnum.DateTime:
                                                newDBDefaultValue = FormHelper.GetDateTimeValueInDBCulture(newColumnDefaultValue);
                                                break;
                                            default:
                                                newDBDefaultValue = newColumnDefaultValue;
                                                break;
                                        }
                                    }

                                    if (!ffiUpdated.External)
                                    {
                                        if (this.DevelopmentMode)
                                        {
                                            TableManager.AddTableColumn(tableName, newColumnName, newColumnType, newColumnAllowNull, newDBDefaultValue, false);
                                        }
                                        else
                                        {
                                            TableManager.AddTableColumn(tableName, newColumnName, newColumnType, newColumnAllowNull, newDBDefaultValue);
                                        }

                                        // Recreate the table PK constraint
                                        if (IsPrimaryField)
                                        {
                                            int pos = 0;
                                            FormFieldInfo[] pkFields = fi.GetFields(true, true, false, true);
                                            string[] primaryKeys = new string[pkFields.Length + 1];
                                            foreach (FormFieldInfo pk in pkFields)
                                            {
                                                if (pk != null)
                                                {
                                                    primaryKeys[pos++] = "[" + pk.Name + "]";
                                                }
                                            }
                                            primaryKeys[pos] = "[" + newColumnName + "]";
                                            TableManager.RecreatePKConstraint(tableName, primaryKeys, null);
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    lblError.Visible = true;
                                    lblError.Text = ex.Message;
                                    return;
                                }

                                break;
                        }
                    }
                }
                // Some error has occurred
                else
                {
                    lblError.Visible = true;
                    lblError.Text = errorMessage;
                    return;
                }
            }
            // Existing node
            else
            {
                // Get info whether it is a primary key or system fild
                ffiUpdated.PrimaryKey = ffi.PrimaryKey;

                // If attribute is a primary key
                if (ffi.PrimaryKey)
                {
                    // Check if the attribute type is integer number
                    if (ffiUpdated.DataType != FormFieldDataTypeEnum.Integer)
                    {
                        errorMessage += GetString("TemplateDesigner.ErrorPKNotInteger") + " ";
                    }

                    // Check if allow empty is disabled
                    if (ffiUpdated.AllowEmpty)
                    {
                        errorMessage += GetString("TemplateDesigner.ErrorPKAllowsNulls") + " ";
                    }

                    // Check that the field type is label
                    string labelControlName = Enum.GetName(typeof(FormFieldControlTypeEnum), FormFieldControlTypeEnum.LabelControl).ToLower();
                    if ((ffiUpdated.FieldType != FormFieldControlTypeEnum.LabelControl) && ((ffiUpdated.FieldType != FormFieldControlTypeEnum.CustomUserControl) && (ffiUpdated.Settings["controlname"].ToString().ToLower() != labelControlName)))
                    {
                        errorMessage += GetString("TemplateDesigner.ErrorPKisNotLabel") + " ";
                    }

                    // Some error has occurred
                    if (!string.IsNullOrEmpty(errorMessage))
                    {
                        lblError.Visible = true;
                        lblError.Text = GetString("TemplateDesigner.ErrorPKThisIsPK") + " " + errorMessage;
                        return;
                    }
                }

                // If table column update is needed
                if (((ffi.PrimaryKey) && (ffi.Name != ffiUpdated.Name)) ||
                     ((!ffi.PrimaryKey) &&
                        ((ffi.Name != ffiUpdated.Name) ||
                         (ffi.DataType != ffiUpdated.DataType) ||
                         (ffi.AllowEmpty != ffiUpdated.AllowEmpty) ||
                         (ffi.Size != ffiUpdated.Size) ||
                         ((ffi.DefaultValue != ffiUpdated.DefaultValue) || (ffiUpdated.DataType == FormFieldDataTypeEnum.Decimal)))
                     )
                   )
                {
                    // Set variables needed for changes in DB
                    oldColumnName = ffi.Name;
                    newColumnName = ffiUpdated.Name;
                    newColumnAllowNull = ffiUpdated.AllowEmpty;

                    // Set implicit default value
                    if (!(newColumnAllowNull) && (string.IsNullOrEmpty(ffiUpdated.DefaultValue)))
                    {
                        switch (ffiUpdated.DataType)
                        {
                            case FormFieldDataTypeEnum.Integer:
                            case FormFieldDataTypeEnum.LongInteger:
                            case FormFieldDataTypeEnum.Decimal:
                            case FormFieldDataTypeEnum.Boolean:
                                newColumnDefaultValue = "0";
                                break;

                            case FormFieldDataTypeEnum.Text:
                            case FormFieldDataTypeEnum.LongText:
                                newColumnDefaultValue = "";
                                break;

                            case FormFieldDataTypeEnum.DateTime:
                                newColumnDefaultValue = DateTime.Now.ToString();
                                break;

                            case FormFieldDataTypeEnum.File:
                            case FormFieldDataTypeEnum.GUID:
                                // 32 digits, empty Guid
                                newColumnDefaultValue = Guid.Empty.ToString();
                                break;

                            case FormFieldDataTypeEnum.Binary:
                                newColumnDefaultValue = null;
                                break;
                        }
                    }

                    // Check if default value is in required format
                    else if (!string.IsNullOrEmpty(ffiUpdated.DefaultValue))
                    {
                        // If default value is macro, don't try to ensure the type
                        if (!ffiUpdated.IsMacro)
                        {
                            switch (ffiUpdated.DataType)
                            {
                                case FormFieldDataTypeEnum.Integer:
                                    try
                                    {
                                        int i = Int32.Parse(ffiUpdated.DefaultValue);
                                        newColumnDefaultValue = i.ToString();
                                    }
                                    catch
                                    {
                                        newColumnDefaultValue = "0";
                                        errorMessage = GetString("TemplateDesigner.ErrorDefaultValueInteger");
                                    }
                                    break;

                                case FormFieldDataTypeEnum.LongInteger:
                                    try
                                    {
                                        long longInt = long.Parse(ffiUpdated.DefaultValue);
                                        newColumnDefaultValue = longInt.ToString();
                                    }
                                    catch
                                    {
                                        newColumnDefaultValue = "0";
                                        errorMessage = GetString("TemplateDesigner.ErrorDefaultValueLongInteger");
                                    }
                                    break;

                                case FormFieldDataTypeEnum.Decimal:
                                    if (ValidationHelper.IsDouble(ffiUpdated.DefaultValue))
                                    {
                                        newColumnDefaultValue = FormHelper.GetDoubleValueInDBCulture(ffiUpdated.DefaultValue);
                                    }
                                    else
                                    {
                                        newColumnDefaultValue = "0";
                                        errorMessage = GetString("TemplateDesigner.ErrorDefaultValueDouble");
                                    }
                                    break;

                                case FormFieldDataTypeEnum.DateTime:
                                    if ((ffiUpdated.DefaultValue.ToLower() == DateTimePicker.DATE_TODAY.ToLower()) || (ffiUpdated.DefaultValue.ToLower() == DateTimePicker.TIME_NOW.ToLower()))
                                    {
                                        newColumnDefaultValue = ffiUpdated.DefaultValue;
                                    }
                                    else
                                    {
                                        try
                                        {
                                            DateTime dat = DateTime.Parse(ffiUpdated.DefaultValue);
                                            newColumnDefaultValue = dat.ToString();
                                        }
                                        catch
                                        {
                                            newColumnDefaultValue = DateTime.Now.ToString();
                                            errorMessage = GetString("TemplateDesigner.ErrorDefaultValueDateTime");
                                        }
                                    }
                                    break;

                                case FormFieldDataTypeEnum.File:
                                case FormFieldDataTypeEnum.GUID:
                                    try
                                    {
                                        Guid g = new Guid(ffiUpdated.DefaultValue);
                                        newColumnDefaultValue = g.ToString();
                                    }
                                    catch
                                    {
                                        newColumnDefaultValue = Guid.Empty.ToString();
                                        errorMessage = GetString("TemplateDesigner.ErrorDefaultValueGuid");
                                    }
                                    break;

                                case FormFieldDataTypeEnum.LongText:
                                case FormFieldDataTypeEnum.Text:
                                case FormFieldDataTypeEnum.Boolean:

                                    newColumnDefaultValue = ffiUpdated.DefaultValue;
                                    break;
                            }
                        }
                    }

                    // Set column type and size
                    LoadColumnTypeAndSize(ffiUpdated.DataType, ffiUpdated.Size, ref newColumnType, ref newColumnSize);

                    if (string.IsNullOrEmpty(errorMessage))
                    {
                        if (!IsAlternativeForm)
                        {
                            switch (mMode)
                            {
                                case FieldEditorModeEnum.ClassFormDefinition:
                                case FieldEditorModeEnum.BizFormDefinition:
                                case FieldEditorModeEnum.SystemTable:
                                case FieldEditorModeEnum.CustomTable:

                                    try
                                    {
                                        string newDBDefaultValue = null;

                                        // Check if it is not a macro
                                        if (ffiUpdated.IsMacro)
                                        {
                                            newDBDefaultValue = newColumnDefaultValue;
                                        }
                                        else
                                        {
                                            switch (ffiUpdated.DataType)
                                            {
                                                case FormFieldDataTypeEnum.Decimal:
                                                    newDBDefaultValue = FormHelper.GetDoubleValueInDBCulture(newColumnDefaultValue);
                                                    break;

                                                case FormFieldDataTypeEnum.DateTime:
                                                    newDBDefaultValue = FormHelper.GetDateTimeValueInDBCulture(newColumnDefaultValue);
                                                    break;
                                                default:
                                                    newDBDefaultValue = newColumnDefaultValue;
                                                    break;
                                            }
                                        }

                                        if (ffiUpdated.External)
                                        {
                                            if (!ffi.External)
                                            {
                                                // Drop old column from table
                                                TableManager.DropTableColumn(tableName, ffi.Name);
                                            }
                                        }
                                        else
                                        {
                                            if (ffi.External)
                                            {
                                                // Add table column
                                                TableManager.AddTableColumn(tableName, newColumnName, newColumnType, newColumnAllowNull, newDBDefaultValue);
                                            }
                                            else
                                            {
                                                // Change table column
                                                TableManager.AlterTableColumn(tableName, oldColumnName, newColumnName, newColumnType, newColumnAllowNull, newDBDefaultValue);
                                                if (OnFieldNameChanged != null)
                                                {
                                                    OnFieldNameChanged(this, oldColumnName, newColumnName);
                                                }
                                            }
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        // User friendly message for not null setting of column
                                        if (ffi.AllowEmpty && !newColumnAllowNull)
                                        {
                                            lblError.Visible = true;
                                            lblError.ResourceString = "FieldEditor.ColumnNotAcceptNull";
                                            lblError.ToolTip = ex.Message;
                                        }
                                        else
                                        {
                                            lblError.Visible = true;
                                            lblError.Text = ex.Message;
                                        }
                                        return;
                                    }

                                    break;
                            }
                        }
                    }
                    // Some error has occurred
                    else
                    {
                        lblError.Visible = true;
                        lblError.Text = errorMessage;
                        return;
                    }
                } // End update needed
            } // End existing node

            // Insert new field
            if (isNewItem)
            {
                InsertFormItem(ffiUpdated);
            }
            // Update current field
            else
            {
                fi.UpdateFormField(ffi.Name, ffiUpdated);
            }
        }
        else if (SelectedItemType == FieldEditorSelectedItemEnum.Category)
        {
            // Fill FormCategoryInfo structure with original data
            fci = fi.GetFormCategory(SelectedItemName);
            // Determine whether it is a new attribute or not
            isNewItem = (fci == null);

            // Fill FormCategoryInfo structure with updated form data
            fciUpdated = new FormCategoryInfo();
            fciUpdated.CategoryCaption = categoryEdit.Value.Replace("'", "");

            // Check if the category caption is empty
            if (string.IsNullOrEmpty(fciUpdated.CategoryCaption))
            {
                lblError.Visible = true;
                lblError.ResourceString = "TemplateDesigner.ErrorCategoryNameEmpty";
                return;
            }

            if (isNewItem)
            {
                // Use category caption for name attribut
                fciUpdated.CategoryName = fciUpdated.CategoryCaption;
            }
            else
            {
                fciUpdated.CategoryName = SelectedItemName;
            }

            if (isNewItem)
            {
                // Get form category names
                string[] categoryNames = fi.GetCategoryNames();

                if (categoryNames != null)
                {
                    // Check if the category name is unique
                    foreach (string name in categoryNames)
                    {
                        // If name already exists return error
                        if (fciUpdated.CategoryName == name)
                        {
                            lblError.Visible = true;
                            lblError.ResourceString = "TemplateDesigner.ErrorExistingCategoryName";
                            return;
                        }
                    }
                }

                // Insert new category
                InsertFormItem(fciUpdated);
            }
            else
            {
                // Update current
                fi.UpdateFormCategory(fci.CategoryName, fciUpdated);
            }
        }

        // Make changes in database
        if (SelectedItemType != 0)
        {
            // Get updated definition
            FormDefinition = fi.GetXmlDefinition();

            string error = null;

            if (!IsAlternativeForm)
            {
                switch (mMode)
                {
                    case FieldEditorModeEnum.WebPartProperties:
                        if (wpi != null)
                        {
                            // Update xml definition
                            wpi.WebPartProperties = FormDefinition;

                            try
                            {
                                WebPartInfoProvider.SetWebPartInfo(wpi);
                            }
                            catch (Exception ex)
                            {
                                error = ex.Message;
                            }
                        }
                        else
                        {
                            error = GetString("FieldEditor.WebpartNotFound");
                        }
                        break;

                    case FieldEditorModeEnum.ClassFormDefinition:
                    case FieldEditorModeEnum.BizFormDefinition:
                    case FieldEditorModeEnum.SystemTable:
                    case FieldEditorModeEnum.CustomTable:
                        if (dci != null)
                        {
                            // Update xml definition
                            dci.ClassFormDefinition = FormDefinition;

                            // Update xml schema
                            dci.ClassXmlSchema = TableManager.GetXmlSchema(dci.ClassTableName);

                            // When updating existing field
                            if (ffi != null)
                            {
                                // Update ClassNodeNameSource field
                                if (dci.ClassNodeNameSource == ffi.Name)
                                {
                                    dci.ClassNodeNameSource = ffiUpdated.Name;
                                }
                            }

                            bool fieldType = (SelectedItemType == FieldEditorSelectedItemEnum.Field);

                            // Update changes in DB
                            try
                            {
                                // Save the data class
                                DataClassInfoProvider.SetDataClass(dci);

                                // Generate the class code
                                GenerateCode();

                                // Update inherited classes with new fields
                                FormHelper.UpdateInheritedClasses(dci);
                            }
                            catch (Exception ex)
                            {
                                error = ex.Message;
                            }

                            if (fieldType)
                            {
                                // Generate default view
                                if (mMode == FieldEditorModeEnum.BizFormDefinition)
                                {
                                    SqlGenerator.GenerateDefaultView(dci, CMSContext.CurrentSiteName);
                                }
                                else
                                {
                                    SqlGenerator.GenerateDefaultView(dci, null);
                                }

                                // Regenerate queries
                                SqlGenerator.GenerateDefaultQueries(dci, true, true);
                            }

                            // Updates custom views
                            if ((mMode == FieldEditorModeEnum.SystemTable) || (mMode == FieldEditorModeEnum.ClassFormDefinition))
                            {
                                try
                                {
                                    TableManager.RefreshCustomViews(dci.ClassTableName);

                                    string lowClassName = dci.ClassName.ToLower();
                                    if (lowClassName == "cms.document" || lowClassName == "cms.tree")
                                    {
                                        TableManager.RefreshDocumentViews();
                                    }
                                }
                                catch (Exception ex)
                                {
                                    error = ResHelper.GetString("fieldeditor.refreshingviewsfailed");
                                    EventLogProvider ev = new EventLogProvider();
                                    ev.LogEvent("Field Editor", "EXCEPTION", ex);
                                }
                            }
                        }
                        else
                        {
                            error = GetString("FieldEditor.ClassNotFound");
                        }
                        break;
                }
            }

            if (!string.IsNullOrEmpty(error))
            {
                lblError.Visible = true;
                lblError.Text = "[FieldEditor.SaveSelectedField()]: " + error;
            }
            else
            {
                IsNewItemEdited = false;

                if (SelectedItemType == FieldEditorSelectedItemEnum.Category)
                {
                    Reload(categPreffix + fciUpdated.CategoryName);
                }
                else if (SelectedItemType == FieldEditorSelectedItemEnum.Field)
                {
                    Reload(fieldPreffix + ffiUpdated.Name);
                }

                lblError.Visible = false;
                lblInfo.Visible = true;
                lblInfo.ResourceString = "general.changessaved";
            }
        }

        // All done and new item, fire OnFieldCreated  event
        if (isNewItem && (ffiUpdated != null))
        {
            RaiseOnFieldCreated(ffiUpdated);
        }
    }
Пример #44
0
    /// <summary>
    /// Loads inner FieldEditor controls.
    /// </summary>
    /// <returns>Returns TRUE if any item is selected</returns>
    private bool LoadInnerControls(string selectedValue, bool partialReload)
    {
        bool isItemSelected = false;
        LoadFormDefinition();
        if (!partialReload)
        {
            LoadAttributesList(selectedValue);
        }

        documentSource.FormInfo = this.fi;
        documentSource.Mode = this.Mode;
        documentSource.IsAlternativeForm = this.IsAlternativeForm;
        documentSource.ClassName = this.ClassName;

        fieldAppearance.IsAlternativeForm = this.IsAlternativeForm;
        fieldAppearance.AlternativeFormFullName = this.AlternativeFormFullName;

        if (SelectedItemType == FieldEditorSelectedItemEnum.Field)
        {
            isItemSelected = true;
            DisplaySelectedTabContent();
            ffi = fi.GetFormField(SelectedItemName);
            LoadSelectedField(partialReload);
        }
        else if (SelectedItemType == FieldEditorSelectedItemEnum.Category)
        {
            isItemSelected = true;
            LoadSelectedCategory();
        }

        return isItemSelected;
    }
Пример #45
0
    /// <summary>
    /// Returns FormFieldInfo structure with form data.
    /// </summary>   
    /// <param name="ffiOriginal">Original field info</param>
    private FormFieldInfo FillFormFieldInfoStructure(FormFieldInfo ffiOriginal)
    {
        // Field info with updated information
        FormFieldInfo ffi = new FormFieldInfo();
        // Ensure field GUID
        if (ffiOriginal != null)
        {
            ffi.Guid = ffiOriginal.Guid;
        }
        if (ffi.Guid == Guid.Empty)
        {
            ffi.Guid = Guid.NewGuid();
        }

        // Load FormFieldInfo with data from simple control
        if (this.SelectedMode == FieldEditorSelectedModeEnum.Simplified)
        {
            string selectedType = simpleMode.FieldType;
            // Part of database section
            ffi.Name = simpleMode.AttributeName;
            ffi.Caption = simpleMode.FieldCaption;
            ffi.AllowEmpty = simpleMode.AllowEmpty;
            ffi.System = simpleMode.IsSystem;
            ffi.DefaultValue = simpleMode.GetDefaultValue(ffiOriginal);
            ffi.IsMacro = EnableMacrosForDefaultValue && ValidationHelper.IsMacro(ffi.DefaultValue);

            // Get control data type
            string[] controlDefaultDataType = FormUserControlInfoProvider.GetUserControlDefaultDataType(selectedType);
            ffi.DataType = FormHelper.GetFormFieldDataType(controlDefaultDataType[0]);

            if (simpleMode.AttributeType == "text")
            {
                ffi.Size = simpleMode.AttributeSize;
            }
            else
            {
                ffi.Size = ValidationHelper.GetInteger(controlDefaultDataType[1], 0);
            }

            // Remove control prefix if exists
            if (selectedType.Contains(controlPrefix))
            {
                selectedType = selectedType.Substring(controlPrefix.Length);
            }

            // Store field type
            ffi.Settings.Add("controlname", selectedType);
            if ((simpleMode.FormData != null) && (simpleMode.FormData.ItemArray.Length > 0))
            {
                foreach (System.Data.DataColumn column in simpleMode.FormData.Table.Columns)
                {
                    ffi.Settings[column.ColumnName] = simpleMode.FormData.Table.Rows[0][column.Caption];
                }
            }

            if ((Mode == FieldEditorModeEnum.BizFormDefinition) || (DisplayedControls == FieldEditorControlsEnum.Bizforms))
            {
                ffi.PublicField = simpleMode.PublicField;
            }
            else
            {
                ffi.PublicField = false;
            }

            ffi.Visible = true;

            // Existing field -> set advanced settings to original settings
            if (ffiOriginal != null)
            {
                ffi.DataType = ffiOriginal.DataType;
                ffi.Visible = ffiOriginal.Visible;

                // Part of database section
                ffi.Description = ffiOriginal.Description;

                // Validation section
                ffi.RegularExpression = ffiOriginal.RegularExpression;
                ffi.MinStringLength = ffiOriginal.MinStringLength;
                ffi.MaxStringLength = ffiOriginal.MaxStringLength;
                ffi.MinValue = ffiOriginal.MinValue;
                ffi.MaxValue = ffiOriginal.MaxValue;
                ffi.MinDateTimeValue = ffiOriginal.MinDateTimeValue;
                ffi.MaxDateTimeValue = ffiOriginal.MaxDateTimeValue;
                ffi.ValidationErrorMessage = ffiOriginal.ValidationErrorMessage;

                // Design section
                ffi.CaptionStyle = ffiOriginal.CaptionStyle;
                ffi.InputControlStyle = ffiOriginal.InputControlStyle;
                ffi.ControlCssClass = ffiOriginal.ControlCssClass;
            }
        }
        // Load FormFieldInfo with data from advanced control
        else
        {
            string selectedType = fieldAppearance.FieldType;
            string attributeType = databaseConfiguration.AttributeType;
            // Part of database section
            ffi.Name = databaseConfiguration.GetAttributeName();
            ffi.Caption = fieldAppearance.FieldCaption;
            ffi.AllowEmpty = databaseConfiguration.AllowEmpty;
            ffi.System = databaseConfiguration.IsSystem;
            ffi.DefaultValue = GetDefaultValue();
            ffi.IsMacro = EnableMacrosForDefaultValue && ValidationHelper.IsMacro(ffi.DefaultValue);

            // Save user visibility
            ffi.AllowUserToChangeVisibility = fieldAppearance.ChangeVisibility;
            ffi.Visibility = fieldAppearance.VisibilityValue;
            ffi.VisibilityControl = fieldAppearance.VisibilityDDL;

            if ((Mode == FieldEditorModeEnum.BizFormDefinition) ||
                DisplayedControls == FieldEditorControlsEnum.Bizforms)
            {
                ffi.PublicField = fieldAppearance.PublicField;
            }
            else
            {
                ffi.PublicField = false;
            }

            // Remove control prefix if exists
            if (selectedType.Contains(controlPrefix))
            {
                selectedType = selectedType.Substring(controlPrefix.Length);
            }

            // Store field type
            ffi.Settings.Add("controlname", selectedType);

            // Store settings
            if ((controlSettings.FormData != null) && (controlSettings.FormData.ItemArray.Length > 0))
            {
                foreach (System.Data.DataColumn column in controlSettings.FormData.Table.Columns)
                {
                    ffi.Settings[column.ColumnName] = controlSettings.FormData.Table.Rows[0][column.Caption];
                }
            }
            // Determine if it external column
            ffi.External = IsSystemFieldSelected;

            if (((Mode == FieldEditorModeEnum.BizFormDefinition) || (Mode == FieldEditorModeEnum.SystemTable))
                && (databaseConfiguration.AttributeType == FormFieldDataTypeCode.FILE))
            {
                // Allow to save <guid>.<extension>
                ffi.DataType = FormFieldDataTypeEnum.Text;
                ffi.Size = 500;
            }
            else if (databaseConfiguration.AttributeType == FormFieldDataTypeCode.DOCUMENT_ATTACHMENTS)
            {
                ffi.DataType = FormFieldDataTypeEnum.DocumentAttachments;
                ffi.Size = 200;
            }
            else
            {
                ffi.DataType = FormHelper.GetFormFieldDataType(databaseConfiguration.AttributeType);
                ffi.Size = ValidationHelper.GetInteger(databaseConfiguration.AttributeSize, 0);
            }

            // Part of database section
            ffi.Visible = chkDisplayInForm.Checked;
            ffi.Description = fieldAppearance.Description;
            ffi.SpellCheck = validationSettings.SpellCheck;

            // Control dependencies
            ffi.HasDependingFields = fieldAppearance.HasDependingFields;
            ffi.DependsOnAnotherField = fieldAppearance.DependsOnAnotherField;

            ffi.DisplayIn = String.Empty;
            if (chkDisplayInDashBoard.Checked)
            {
                ffi.DisplayIn = this.DisplayIn;
            }

            // Validation section
            ffi.RegularExpression = validationSettings.RegularExpression;
            ffi.MinStringLength = (string.IsNullOrEmpty(validationSettings.MinLengthText)) ? -1 : Convert.ToInt32(validationSettings.MinLengthText);
            ffi.MaxStringLength = (string.IsNullOrEmpty(validationSettings.MaxLengthText)) ? -1 : Convert.ToInt32(validationSettings.MaxLengthText);

            ffi.MinValue = validationSettings.MinValueText;
            ffi.MaxValue = validationSettings.MaxValueText;

            ffi.MinDateTimeValue = validationSettings.DateFrom;
            ffi.MaxDateTimeValue = validationSettings.DateTo;
            ffi.ValidationErrorMessage = validationSettings.ErrorMessage;

            // Design section
            ffi.CaptionStyle = cssSettings.CaptionStyle;
            ffi.InputControlStyle = cssSettings.InputStyle;
            ffi.ControlCssClass = cssSettings.ControlCssClass;
        }

        ffi.FieldType = FormFieldControlTypeEnum.CustomUserControl;

        return ffi;
    }
    /// <summary>
    /// Used only for alternative forms. If current field in class allows empty then it returns TRUE.
    /// </summary>
    private bool GetFormAllowEmpty()
    {
        // Check if field exists in class
        FormInfo fi = FormHelper.GetFormInfo(this.ClassName, false);
        FormFieldInfo ffi = null;
        if (fi != null)
        {
            ffi = fi.GetFormField(this.ffi.Name);
            if (ffi != null)
            {
                return ffi.AllowEmpty;
            }
        }

        // Check if field exists in coupled class
        if (!String.IsNullOrEmpty(this.CoupledClassName))
        {
            fi = FormHelper.GetFormInfo(this.CoupledClassName, false);
            if (fi != null)
            {
                ffi = fi.GetFormField(this.ffi.Name);
                if (ffi != null)
                {
                    return ffi.AllowEmpty;
                }
            }
        }

        return false;
    }
    private string UpdateDependencies(DataClassInfo dci, TableManager tm, FormFieldInfo updatedFieldInfo, out bool updateInheritedForms)
    {
        updateInheritedForms = false;
        string error = null;

        if (dci != null)
        {
            // Update XML definition
            dci.ClassFormDefinition = FormDefinition;

            // When updating existing field
            if ((ffi != null) && (dci.ClassNodeNameSource == ffi.Name))
            {
                // Update ClassNodeNameSource field
                dci.ClassNodeNameSource = updatedFieldInfo.Name;
            }

            bool isNotDummyOrField = (SelectedItemType != FieldEditorSelectedItemEnum.Field) || !updatedFieldInfo.IsDummyField;
            if (isNotDummyOrField)
            {
                // Update XML schema
                dci.ClassXmlSchema = tm.GetXmlSchema(dci.ClassTableName);
            }

            // Update changes in DB
            try
            {
                // Save the data class
                DataClassInfoProvider.SetDataClassInfo(dci);

                updateInheritedForms = true;
            }
            catch (Exception ex)
            {
                EventLogProvider.LogException("FieldEditor", "SAVE", ex);
                error = ex.Message;
            }

            if ((SelectedItemType == FieldEditorSelectedItemEnum.Field) && !updatedFieldInfo.IsDummyField)
            {
                // Generate default view
                SqlGenerator.GenerateDefaultView(dci, mMode == FieldEditorModeEnum.BizFormDefinition ? SiteContext.CurrentSiteName : null);

                QueryInfoProvider.ClearDefaultQueries(dci, true, true);
            }

            // Updates custom views
            if (isNotDummyOrField && ((mMode == FieldEditorModeEnum.SystemTable) || (mMode == FieldEditorModeEnum.ClassFormDefinition)) && IsDatabaseChangeRequired(ffi, updatedFieldInfo))
            {
                error = RefreshViews(tm, dci);
            }
        }
        else
        {
            error = GetString("FieldEditor.ClassNotFound");
        }

        return error;
    }
    public static void Update60()
    {
        EventLogProvider evp = new EventLogProvider();
        evp.LogEvent("I", DateTime.Now, "Upgrade to 6.0", "Upgrade - Start");

        DataClassInfo dci = null;

        #region "CMS.UserSettings"

        try
        {
            dci = DataClassInfoProvider.GetDataClass("cms.usersettings");
            if (dci != null)
            {
                FormInfo fi = new FormInfo(dci.ClassFormDefinition);
                if (fi != null)
                {
                    FormFieldInfo ffi = new FormFieldInfo();
                    ffi.Name = "UserAuthenticationGUID";
                    ffi.DataType = FormFieldDataTypeEnum.GUID;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "UserBounces";
                    ffi.DataType = FormFieldDataTypeEnum.Integer;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.TextBoxControl;
                    ffi.Visible = false;
                    ffi.Caption = "UserBounces";

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "UserLinkedInID";
                    ffi.DataType = FormFieldDataTypeEnum.Text;
                    ffi.Size = 100;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "UserLogActivities";
                    ffi.DataType = FormFieldDataTypeEnum.Boolean;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "UserPasswordRequestHash";
                    ffi.DataType = FormFieldDataTypeEnum.Text;
                    ffi.Size = 100;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    dci.ClassFormDefinition = fi.GetXmlDefinition();

                    TableManager tm = new TableManager(dci.ClassConnectionString);
                    dci.ClassXmlSchema = tm.GetXmlSchema("CMS_UserSettings");

                    DataClassInfoProvider.SetDataClass(dci);

                    // Generate queries
                    SqlGenerator.GenerateDefaultQueries(dci, true, false);
                    tm.RefreshCustomViews("CMS_UserSettings");
                }
            }
        }
        catch (Exception ex)
        {
            evp.LogEvent("CMS.UserSettings - Upgrade", "Upgrade", ex);
        }

        #endregion

        #region "Ecommerce - Customer"

        try
        {
            dci = DataClassInfoProvider.GetDataClass("ecommerce.customer");
            if (dci != null)
            {
                FormInfo fi = new FormInfo(dci.ClassFormDefinition);
                if (fi != null)
                {
                    FormFieldInfo ffi = new FormFieldInfo();
                    ffi.Name = "CustomerSiteID";
                    ffi.DataType = FormFieldDataTypeEnum.Integer;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.TextBoxControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    TableManager tm = new TableManager(dci.ClassConnectionString);

                    dci.ClassFormDefinition = fi.GetXmlDefinition();
                    dci.ClassXmlSchema = tm.GetXmlSchema("COM_Customer");

                    DataClassInfoProvider.SetDataClass(dci);

                    // Generate queries
                    SqlGenerator.GenerateDefaultQueries(dci, true, false);

                    tm.RefreshCustomViews("COM_Customer");
                }
            }
        }
        catch (Exception ex)
        {
            evp.LogEvent("Ecommerce.Customer - Upgrade", "Upgrade", ex);
        }

        #endregion

        #region "Ecommerce - Order"

        try
        {
            dci = DataClassInfoProvider.GetDataClass("ecommerce.order");
            if (dci != null)
            {
                FormInfo fi = new FormInfo(dci.ClassFormDefinition);
                if (fi != null)
                {
                    FormFieldInfo ffi = new FormFieldInfo();
                    ffi.Name = "OrderCulture";
                    ffi.DataType = FormFieldDataTypeEnum.Text;
                    ffi.Size = 10;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "OrderIsPaid";
                    ffi.DataType = FormFieldDataTypeEnum.Boolean;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "OrderTotalPriceInMainCurrency";
                    ffi.DataType = FormFieldDataTypeEnum.Decimal;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = fi.GetFormField("OrderStatusID");
                    if (ffi != null)
                    {
                        ffi.AllowEmpty = true;
                        fi.UpdateFormField("OrderStatusID", ffi);
                    }

                    ffi = fi.GetFormField("OrderShippingAddressID");
                    if (ffi != null)
                    {
                        ffi.AllowEmpty = true;
                        fi.UpdateFormField("OrderShippingAddressID", ffi);
                    }

                    dci.ClassFormDefinition = fi.GetXmlDefinition();

                    TableManager tm = new TableManager(dci.ClassConnectionString);
                    dci.ClassXmlSchema = tm.GetXmlSchema("COM_Order");

                    DataClassInfoProvider.SetDataClass(dci);

                    // Generate queries
                    SqlGenerator.GenerateDefaultQueries(dci, true, false);
                    tm.RefreshCustomViews("COM_Order");
                }
            }
        }
        catch (Exception ex)
        {
            evp.LogEvent("Ecommerce.Order - Upgrade", "Upgrade", ex);
        }

        #endregion

        #region "Ecommerce - OrderItem"

        try
        {
            dci = DataClassInfoProvider.GetDataClass("ecommerce.orderitem");
            if (dci != null)
            {
                FormInfo fi = new FormInfo(dci.ClassFormDefinition);
                if (fi != null)
                {
                    FormFieldInfo ffi = new FormFieldInfo();
                    ffi.Name = "OrderItemBundleGUID";
                    ffi.DataType = FormFieldDataTypeEnum.GUID;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "OrderItemIsPrivate";
                    ffi.DataType = FormFieldDataTypeEnum.Boolean;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "OrderItemPrice";
                    ffi.DataType = FormFieldDataTypeEnum.Decimal;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "OrderItemSendNotification";
                    ffi.DataType = FormFieldDataTypeEnum.Boolean;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "OrderItemSKU";
                    ffi.DataType = FormFieldDataTypeEnum.LongText;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "OrderItemText";
                    ffi.DataType = FormFieldDataTypeEnum.LongText;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "OrderItemTotalPriceInMainCurrency";
                    ffi.DataType = FormFieldDataTypeEnum.Decimal;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "OrderItemValidTo";
                    ffi.DataType = FormFieldDataTypeEnum.DateTime;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    dci.ClassFormDefinition = fi.GetXmlDefinition();

                    TableManager tm = new TableManager(dci.ClassConnectionString);
                    dci.ClassXmlSchema = tm.GetXmlSchema("COM_OrderItem");

                    DataClassInfoProvider.SetDataClass(dci);

                    // Generate queries
                    SqlGenerator.GenerateDefaultQueries(dci, true, false);
                    tm.RefreshCustomViews("COM_OrderItem");
                }
            }
        }
        catch (Exception ex)
        {
            evp.LogEvent("Ecommerce.OrderItem - Upgrade", "Upgrade", ex);
        }

        #endregion

        #region "Ecommerce - Shopping cart item"

        try
        {
            dci = DataClassInfoProvider.GetDataClass("ecommerce.shoppingcartitem");
            if (dci != null)
            {
                FormInfo fi = new FormInfo(dci.ClassFormDefinition);
                if (fi != null)
                {
                    FormFieldInfo ffi = new FormFieldInfo();
                    ffi.Name = "CartItemBundleGUID";
                    ffi.DataType = FormFieldDataTypeEnum.GUID;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "CartItemIsPrivate";
                    ffi.DataType = FormFieldDataTypeEnum.Boolean;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "CartItemPrice";
                    ffi.DataType = FormFieldDataTypeEnum.Decimal;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "CartItemText";
                    ffi.DataType = FormFieldDataTypeEnum.LongText;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "CartItemValidTo";
                    ffi.DataType = FormFieldDataTypeEnum.DateTime;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = fi.GetFormField("CartItemGuid");
                    if (ffi != null)
                    {
                        ffi.AllowEmpty = true;
                        fi.UpdateFormField("CartItemGuid", ffi);
                    }

                    dci.ClassFormDefinition = fi.GetXmlDefinition();

                    TableManager tm = new TableManager(dci.ClassConnectionString);
                    dci.ClassXmlSchema = tm.GetXmlSchema("COM_ShoppingCartSKU");

                    DataClassInfoProvider.SetDataClass(dci);

                    // Generate queries
                    SqlGenerator.GenerateDefaultQueries(dci, true, false);
                    tm.RefreshCustomViews("COM_ShoppingCartSKU");
                }
            }
        }
        catch (Exception ex)
        {
            evp.LogEvent("Ecommerce.ShoppingCartItem - Upgrade", "Upgrade", ex);
        }

        #endregion

        #region "Ecommerce - SKU"

        try
        {
            dci = DataClassInfoProvider.GetDataClass("ecommerce.sku");
            if (dci != null)
            {
                FormInfo fi = new FormInfo(dci.ClassFormDefinition);
                if (fi != null)
                {
                    FormFieldInfo ffi = new FormFieldInfo();
                    ffi.Name = "SKUBundleInventoryType";
                    ffi.DataType = FormFieldDataTypeEnum.Text;
                    ffi.Size = 50;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "SKUConversionName";
                    ffi.DataType = FormFieldDataTypeEnum.Text;
                    ffi.Size = 100;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "SKUConversionValue";
                    ffi.DataType = FormFieldDataTypeEnum.Text;
                    ffi.Size = 200;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "SKUMaxDownloads";
                    ffi.DataType = FormFieldDataTypeEnum.Integer;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "SKUMaxItemsInOrder";
                    ffi.DataType = FormFieldDataTypeEnum.Integer;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "SKUMaxPrice";
                    ffi.DataType = FormFieldDataTypeEnum.Decimal;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "SKUMembershipGUID";
                    ffi.DataType = FormFieldDataTypeEnum.GUID;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "SKUMinPrice";
                    ffi.DataType = FormFieldDataTypeEnum.Decimal;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "SKUNeedsShipping";
                    ffi.DataType = FormFieldDataTypeEnum.Boolean;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "SKUPrivateDonation";
                    ffi.DataType = FormFieldDataTypeEnum.Boolean;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "SKUProductType";
                    ffi.DataType = FormFieldDataTypeEnum.Text;
                    ffi.Size = 50;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "SKUSiteID";
                    ffi.DataType = FormFieldDataTypeEnum.Integer;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "SKUValidFor";
                    ffi.DataType = FormFieldDataTypeEnum.Integer;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "SKUValidity";
                    ffi.DataType = FormFieldDataTypeEnum.Text;
                    ffi.Size = 50;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = new FormFieldInfo();
                    ffi.Name = "SKUValidUntil";
                    ffi.DataType = FormFieldDataTypeEnum.DateTime;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    ffi = fi.GetFormField("SKUDepartmentID");
                    if (ffi != null)
                    {
                        ffi.AllowEmpty = true;
                        fi.UpdateFormField("SKUDepartmentID", ffi);
                    }

                    dci.ClassFormDefinition = fi.GetXmlDefinition();

                    TableManager tm = new TableManager(dci.ClassConnectionString);
                    dci.ClassXmlSchema = tm.GetXmlSchema("COM_SKU");

                    DataClassInfoProvider.SetDataClass(dci);

                    // Generate queries
                    SqlGenerator.GenerateDefaultQueries(dci, true, false);
                    tm.RefreshCustomViews("COM_SKU");
                }
            }
        }
        catch (Exception ex)
        {
            evp.LogEvent("Ecommerce.SKU - Upgrade", "Upgrade", ex);
        }

        #endregion

        #region "Community - Group"

        try
        {
            dci = DataClassInfoProvider.GetDataClass("Community.Group");
            if (dci != null)
            {
                FormInfo fi = new FormInfo(dci.ClassFormDefinition);
                if (fi != null)
                {
                    FormFieldInfo ffi = new FormFieldInfo();
                    ffi.Name = "GroupLogActivity";
                    ffi.DataType = FormFieldDataTypeEnum.Boolean;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.CheckBoxControl;
                    ffi.Visible = true;
                    ffi.DefaultValue = "true";
                    ffi.Caption = "GroupLogActivity";

                    fi.AddFormField(ffi);

                    dci.ClassFormDefinition = fi.GetXmlDefinition();

                    TableManager tm = new TableManager(dci.ClassConnectionString);
                    dci.ClassXmlSchema = tm.GetXmlSchema("Community_Group");

                    DataClassInfoProvider.SetDataClass(dci);

                    // Generate queries
                    SqlGenerator.GenerateDefaultQueries(dci, true, false);
                    tm.RefreshCustomViews("Community_Group");
                }
            }
        }
        catch (Exception ex)
        {
            evp.LogEvent("Community.Group - Upgrade", "Upgrade", ex);
        }

        #endregion

        #region "Newsletter - Subscriber"

        try
        {
            dci = DataClassInfoProvider.GetDataClass("newsletter.subscriber");
            if (dci != null)
            {
                FormInfo fi = new FormInfo(dci.ClassFormDefinition);
                if (fi != null)
                {
                    FormFieldInfo ffi = new FormFieldInfo();
                    ffi.Name = "SubscriberBounces";
                    ffi.DataType = FormFieldDataTypeEnum.Boolean;
                    ffi.AllowEmpty = true;
                    ffi.PublicField = false;
                    ffi.System = true;
                    ffi.FieldType = FormFieldControlTypeEnum.LabelControl;
                    ffi.Visible = false;

                    fi.AddFormField(ffi);

                    dci.ClassFormDefinition = fi.GetXmlDefinition();

                    TableManager tm = new TableManager(dci.ClassConnectionString);
                    dci.ClassXmlSchema = tm.GetXmlSchema("Newsletter_Subscriber");

                    DataClassInfoProvider.SetDataClass(dci);

                    // Generate queries
                    SqlGenerator.GenerateDefaultQueries(dci, true, false);
                    tm.RefreshCustomViews("Newsletter_Subscriber");
                }
            }
        }
        catch (Exception ex)
        {
            evp.LogEvent("Newsletter.Subscriber - Upgrade", "Upgrade", ex);
        }

        #endregion

        #region "CMS.Document"

        try
        {
            dci = DataClassInfoProvider.GetDataClass("cms.document");
            if (dci != null)
            {
                SearchSettings ss = dci.ClassSearchSettingsInfos;
                SearchSettingsInfo ssi = ss.GetSettingsInfo("42f446ee-9818-4596-8124-54a38f64aa05");
                if (ssi != null)
                {
                    ssi.Searchable = true;
                    ss.SetSettingsInfo(ssi);
                }

                DataClassInfoProvider.SetDataClass(dci);
            }
        }
        catch (Exception ex)
        {
            evp.LogEvent("CMS.Document - Upgrade", "Upgrade", ex);
        }

        #endregion

        // Set the path to the upgrade package
        mUpgradePackagePath = HttpContext.Current.Server.MapPath("~/CMSSiteUtils/Import/upgrade_55R2_60.zip");

        mWebsitePath = HttpContext.Current.Server.MapPath("~/");

        TableManager dtm = new TableManager(null);

        // Update all views
        dtm.RefreshDocumentViews();

        // Set data version
        ObjectHelper.SetSettingsKeyValue("CMSDataVersion", "6.0");

        // Clear hashtables
        CMSObjectHelper.ClearHashtables();

        // Clear the cache
        CacheHelper.ClearCache(null, true);

        // Drop the routes
        CMSMvcHandler.DropAllRoutes();

        // Init the Mimetype helper (required for the Import)
        MimeTypeHelper.LoadMimeTypes();

        CMSThread thread = new CMSThread(Upgrade60Import);
        thread.Start();
    }
    private string UpdateFormField(TableManager tm, string tableName, FormFieldInfo updatedFieldInfo)
    {
        // Validate whether column with this name already exists
        string errorMessage = ValidateFieldColumn(updatedFieldInfo);
        if (!String.IsNullOrEmpty(errorMessage))
        {
            return errorMessage;
        }

        // Create or update form field
        errorMessage = IsNewItemEdited ? CreateDatabaseColumn(tm, tableName, updatedFieldInfo) : UpdateDatabaseColumn(tm, tableName, updatedFieldInfo);
        if (!String.IsNullOrEmpty(errorMessage))
        {
            return errorMessage;
        }

        if (IsNewItemEdited)
        {
            // Insert new field
            InsertFormItem(updatedFieldInfo);

            // Hide new field in alternative and inherited forms if necessary
            if (IsMainForm)
            {
                DataClassInfo dci = DataClassInfoProvider.GetDataClassInfo(ClassName);
                HideFieldInAlternativeForms(updatedFieldInfo, dci);
            }
        }
        else
        {
            // Update current field
            FormInfo.UpdateFormField(ffi.Name, updatedFieldInfo);
        }

        return null;
    }
Пример #50
0
    protected void EditForm_OnBeforeSave(object sender, EventArgs e)
    {
        MacroRuleInfo info = EditForm.EditedObject as MacroRuleInfo;
        if (info != null)
        {
            // Generate automatic fields when present in UserText
            FormEngineUserControl control = EditForm.FieldControls["MacroRuleText"];
            if (control != null)
            {
                string userText = ValidationHelper.GetString(control.Value, "");
                if (!string.IsNullOrEmpty(userText))
                {
                    Regex regex = RegexHelper.GetRegex("\\{[-_a-zA-Z0-9]*\\}");
                    MatchCollection match = regex.Matches(userText);
                    if (match.Count > 0)
                    {
                        FormInfo fi = new FormInfo(info.MacroRuleParameters);
                        foreach (Match m in match)
                        {
                            foreach (Capture c in m.Captures)
                            {
                                string name = c.Value.Substring(1, c.Value.Length - 2).ToLowerCSafe();
                                FormFieldInfo ffi = fi.GetFormField(name);
                                if (ffi == null)
                                {
                                    ffi = new FormFieldInfo();
                                    ffi.Name = name;
                                    ffi.DataType = FormFieldDataTypeEnum.Text;
                                    ffi.Size = 100;
                                    ffi.FieldType = FormFieldControlTypeEnum.CustomUserControl;
                                    ffi.Caption = "select operation";
                                    ffi.AllowEmpty = true;
                                    switch (name)
                                    {
                                        case "_is":
                                            ffi.DefaultValue = ";is";
                                            ffi.Settings["controlname"] = "MacroNegationOperator";
                                            ffi.Settings["EditText"] = "false";
                                            ffi.Settings["Options"] = ";is\r\n!;is not";
                                            break;

                                        case "_was":
                                            ffi.DefaultValue = ";was";
                                            ffi.Settings["controlname"] = "MacroNegationOperator";
                                            ffi.Settings["EditText"] = "false";
                                            ffi.Settings["Options"] = ";was\r\n!;was not";
                                            break;

                                        case "_will":
                                            ffi.DefaultValue = ";will";
                                            ffi.Settings["controlname"] = "MacroNegationOperator";
                                            ffi.Settings["EditText"] = "false";
                                            ffi.Settings["Options"] = ";will\r\n!;will not";
                                            break;

                                        case "_has":
                                            ffi.DefaultValue = ";has";
                                            ffi.Settings["controlname"] = "MacroNegationOperator";
                                            ffi.Settings["EditText"] = "false";
                                            ffi.Settings["Options"] = ";has\r\n!;does not have";
                                            break;

                                        case "_perfectum":
                                            ffi.DefaultValue = ";has";
                                            ffi.Settings["controlname"] = "MacroNegationOperator";
                                            ffi.Settings["EditText"] = "false";
                                            ffi.Settings["Options"] = ";has\r\n!;has not";
                                            break;

                                        case "_any":
                                            ffi.DefaultValue = "false;any";
                                            ffi.Settings["controlname"] = "macro_any-all_bool_selector";
                                            ffi.Settings["EditText"] = "false";
                                            ffi.Settings["Options"] = "false;any\r\ntrue;all";
                                            break;

                                        default:
                                            ffi.FieldType = FormFieldControlTypeEnum.TextBoxControl;
                                            ffi.Size = 1000;
                                            ffi.Caption = "enter text";
                                            break;
                                    }

                                    fi.AddFormField(ffi);
                                }
                            }
                        }
                        info.MacroRuleParameters = fi.GetXmlDefinition();
                    }
                }
            }
        }

        if (!string.IsNullOrEmpty(ResourceName))
        {
            EditForm.EditedObject.SetValue("MacroRuleResourceName", ResourceName);
        }
        EditForm.EditedObject.SetValue("MacroRuleIsCustom", !SettingsKeyProvider.DevelopmentMode);
    }
 /// <summary>
 /// Returns field caption of the specified column.
 /// </summary>
 /// <param name="ffi">Form field info</param>
 /// <param name="columnName">Column name</param>
 /// <param name="resolver">Macro resolver</param>
 protected string GetFieldCaption(FormFieldInfo ffi, string columnName, MacroResolver resolver)
 {
     // Get field caption
     string caption = ffi.GetPropertyValue(FormFieldPropertyEnum.FieldCaption, resolver);
     return ((ffi == null) || (caption == string.Empty)) ? columnName : caption;
 }
    /// <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();
                }
            }
        }
    }
Пример #53
0
 /// <summary>
 /// Raises OnFieldCreated event.
 /// </summary>
 /// <param name="newField">Newly created field</param>
 protected void RaiseOnFieldCreated(FormFieldInfo newField)
 {
     if (OnFieldCreated != null)
     {
         OnFieldCreated(this, newField);
     }
 }
    private string UpdateDatabaseColumn(TableManager tm, string tableName, FormFieldInfo updatedFieldInfo)
    {
        // Get info whether it is a primary key or system field
        updatedFieldInfo.PrimaryKey = ffi.PrimaryKey;

        string errorMessage = ValidatePrimaryKey(updatedFieldInfo);
        if (!String.IsNullOrEmpty(errorMessage))
        {
            return errorMessage;
        }

        // If table column update is needed
        if ((ffi.PrimaryKey && (ffi.Name != updatedFieldInfo.Name)) ||
           (!ffi.PrimaryKey && (IsDatabaseChangeRequired(ffi, updatedFieldInfo) || (updatedFieldInfo.DataType == FieldDataType.Double))))
        {
            if (IsMainForm && !updatedFieldInfo.IsDummyField && !updatedFieldInfo.IsExtraField && (tm != null))
            {
                switch (mMode)
                {
                    case FieldEditorModeEnum.ClassFormDefinition:
                    case FieldEditorModeEnum.BizFormDefinition:
                    case FieldEditorModeEnum.SystemTable:
                    case FieldEditorModeEnum.CustomTable:
                        errorMessage = UpdateDatabaseColumn(ffi, updatedFieldInfo, tm, tableName);
                        break;

                }
            }
            else
            {
                RaiseOnFieldNameChanged(ffi.Name, updatedFieldInfo.Name);
            }
        }

        return errorMessage;
    }
Пример #55
0
    /// <summary>
    /// Sets all values of form to defaults.
    /// </summary>
    /// <param name="system">True - empty form for node or document attribute should be loaded, False - standard form should be loaded</param>
    /// <param name="partialReload">True - indicates that only some controls should be loaded, False - reload all controls</param>
    private void LoadDefaultAttributeEditForm(bool system, bool partialReload)
    {
        ffi = null;
        plcCategory.Visible = false;
        chkDisplayInForm.Checked = true;
        chkDisplayInDashBoard.Checked = true;

        if ((this.SelectedMode == FieldEditorSelectedModeEnum.Advanced) && !partialReload)
        {
            databaseConfiguration.DevelopmentMode = this.DevelopmentMode;
            databaseConfiguration.ShowSystemFields = system;
            databaseConfiguration.IsDocumentType = this.IsDocumentType;
            databaseConfiguration.Mode = this.Mode;
            databaseConfiguration.ClassName = this.ClassName;
            databaseConfiguration.CoupledClassName = this.CoupledClassName;
            databaseConfiguration.IsAlternativeForm = this.IsAlternativeForm;
            databaseConfiguration.Reload("", this.IsNewItemEdited);
            databaseConfiguration.ShowDefaultControl();
        }

        if (system)
        {
            LoadSystemField();
        }

        if (this.SelectedMode == FieldEditorSelectedModeEnum.Advanced)
        {
            fieldAppearance.ClassName = this.ClassName;
            fieldAppearance.AttributeType = databaseConfiguration.AttributeType;
            fieldAppearance.Reload();
            cssSettings.Reload();
            validationSettings.AttributeType = databaseConfiguration.AttributeType;
            validationSettings.Mode = this.Mode;
            validationSettings.DisplayControls();
            validationSettings.Reload();
            chkDisplayInForm.Checked = true;
            chkDisplayInDashBoard.Checked = true;
        }
        else
        {
            simpleMode.FieldInfo = null;
            simpleMode.DisplayedControls = this.DisplayedControls;
            simpleMode.Mode = this.Mode;
            simpleMode.ClearForm();
            simpleMode.LoadTypes();
            simpleMode.LoadControlSettings(null, true);
        }
    }
    /// <summary>
    /// Save selected field.
    /// </summary>
    private bool SaveSelectedField()
    {
        DataClassInfo dci = null;
        bool updateInherited = false;

        // Ensure the transaction
        using (var tr = new CMSLateBoundTransaction())
        {
            // FormFieldInfo structure with data from updated form
            FormFieldInfo ffiUpdated = null;

            // FormCategoryInfo structure with data from updated form
            FormCategoryInfo fciUpdated = null;

            // For some types of forms initialize table manager
            string tableName = null;
            TableManager tm = null;

            if (IsMainForm)
            {
                switch (mMode)
                {
                    // Do nothing for WebPart
                    case FieldEditorModeEnum.ClassFormDefinition:
                    case FieldEditorModeEnum.BizFormDefinition:
                    case FieldEditorModeEnum.SystemTable:
                    case FieldEditorModeEnum.CustomTable:
                        {
                            // Fill ClassInfo structure with data from database
                            dci = DataClassInfoProvider.GetDataClassInfo(ClassName);
                            if (dci != null)
                            {
                                // Set table name
                                tableName = dci.ClassTableName;

                                tm = new TableManager(dci.ClassConnectionString);
                                tr.BeginTransaction();
                            }
                            else
                            {
                                ShowError(GetString("fieldeditor.notablename"));
                                return false;
                            }
                        }
                        break;

                }
            }

            // Load current XML form definition
            if (!LoadFormDefinition())
            {
                // Form definition was not loaded
                return false;
            }

            string error = null;

            switch (SelectedItemType)
            {
                case FieldEditorSelectedItemEnum.Field:
                    // Fill FormFieldInfo structure with original data
                    ffi = FormInfo.GetFormField(SelectedItemName);

                    // Fill FormFieldInfo structure with updated form data
                    ffiUpdated = FillFormFieldInfoStructure(ffi);

                    try
                    {
                        error = UpdateFormField(tm, tableName, ffiUpdated);
                    }
                    catch (Exception ex)
                    {
                        EventLogProvider.LogException("FieldEditor", "SAVE", ex);

                        // User friendly message for not null setting of column
                        if (!IsNewItemEdited && ffi.AllowEmpty && !ffiUpdated.AllowEmpty)
                        {
                            ShowError(GetString("FieldEditor.ColumnNotAcceptNull"), ex.Message);
                        }
                        else
                        {
                            ShowError(GetString("general.saveerror"), ex.Message);
                        }
                        return false;
                    }
                    break;

                case FieldEditorSelectedItemEnum.Category:
                    // Fill FormCategoryInfo structure with original data
                    fci = FormInfo.GetFormCategory(SelectedItemName);

                    // Initialize new FormCategoryInfo structure
                    fciUpdated = new FormCategoryInfo();

                    error = UpdateFormCategory(fciUpdated);
                    break;
            }

            if (!String.IsNullOrEmpty(error))
            {
                ShowError(error);
                return false;
            }

            // Make changes in database
            if (SelectedItemType != 0)
            {
                // Get updated definition
                FormDefinition = FormInfo.GetXmlDefinition();

                if (IsMainForm)
                {
                    switch (mMode)
                    {
                        case FieldEditorModeEnum.WebPartProperties:
                            error = UpdateWebPartProperties();
                            break;

                        case FieldEditorModeEnum.ClassFormDefinition:
                        case FieldEditorModeEnum.BizFormDefinition:
                        case FieldEditorModeEnum.SystemTable:
                        case FieldEditorModeEnum.CustomTable:
                            error = UpdateDependencies(dci, tm, ffiUpdated, out updateInherited);
                            break;

                    }
                }

                if (!String.IsNullOrEmpty(error))
                {
                    ShowError("[FieldEditor.SaveSelectedField()]: " + error);
                    return false;
                }
            }

            // All done and new item, fire OnFieldCreated  event
            RaiseOnFieldCreated(ffiUpdated);

            // Reload field/category
            switch (SelectedItemType)
            {
                case FieldEditorSelectedItemEnum.Category:
                    Reload(categPreffix + fciUpdated.CategoryName);
                    break;

                case FieldEditorSelectedItemEnum.Field:
                    Reload(fieldPreffix + ffiUpdated.Name);
                    break;
            }

            // Commit the transaction
            tr.Commit();
        }

        // Update inherited classes with new fields
        if (updateInherited)
        {
            FormHelper.UpdateInheritedClasses(dci);
        }

        return true;
    }
Пример #57
0
 /// <summary>
 /// Loads system field either from database colum data or from field XML definition.
 /// </summary>
 private void LoadSystemField()
 {
     string tableName = databaseConfiguration.GroupValue;
     string columnName = databaseConfiguration.SystemValue;
     if (SelectedItemName.ToLower() != columnName.ToLower())
     {
         // Get field info from database column
         ffi = FormHelper.GetFormFieldInfo(tableName, columnName);
     }
     else
     {
         // Get field info from XML definition
         LoadFormDefinition();
         ffi = fi.GetFormField(SelectedItemName);
     }
     LoadSelectedField(false);
 }
    /// <summary>
    /// Loads system field either from database column data or from field XML definition.
    /// </summary>
    private void LoadSystemField()
    {
        string tableName = databaseConfiguration.GroupValue;
        string columnName = databaseConfiguration.SystemValue;

        if (SelectedItemName.ToLowerCSafe() != columnName.ToLowerCSafe())
        {
            DataClassInfo dci = DataClassInfoProvider.GetDataClassInfo(ClassName);

            // Get field info from database column
            ffi = FormHelper.GetFormFieldInfo(dci, tableName, columnName);
        }
        else
        {
            // Get field info from XML definition
            LoadFormDefinition();
            ffi = FormInfo.GetFormField(SelectedItemName);
        }

        LoadSelectedField(false);
    }
Пример #59
0
    /// <summary>
    /// Validates form and returns validation errorr message.
    /// </summary>
    private string ValidateForm()
    {
        const string INVALIDCHARACTERS = @".,;'`:/\*|?""&%$!-+=()[]{} ";
        string attributeName = null;
        string fieldCaption = null;
        string control = null;
        bool MinAndMaxLengthInCorrectFormat = true;
        bool MinAndMaxValueInCorrectFormat = true;

        if (this.SelectedMode == FieldEditorSelectedModeEnum.Simplified)
        {
            attributeName = simpleMode.AttributeName;
            fieldCaption = simpleMode.FieldCaption;
            control = simpleMode.FieldType;
        }
        else
        {
            attributeName = databaseConfiguration.GetAttributeName();
            fieldCaption = fieldAppearance.FieldCaption;
            control = fieldAppearance.FieldType;
        }

        // Check if attribute name isn't empty
        if (string.IsNullOrEmpty(attributeName))
        {
            return GetString("TemplateDesigner.ErrorEmptyAttributeName") + " ";
        }

        // Check if attribute name starts with a letter or '_' (if it is an identificator)
        if (!ValidationHelper.IsIdentifier(attributeName))
        {
            return GetString("TemplateDesigner.ErrorAttributeNameDoesNotStartWithLetter") + " ";
        }

        // Check attribute name for invalid characters
        for (int i = 0; i <= INVALIDCHARACTERS.Length - 1; i++)
        {
            if (attributeName.Contains(Convert.ToString(INVALIDCHARACTERS[i])))
            {
                return GetString("TemplateDesigner.ErrorInvalidCharacter") + INVALIDCHARACTERS + ". ";
            }
        }

        if (chkDisplayInForm.Checked)
        {
            // Check if field caption is entered
            if (string.IsNullOrEmpty(fieldCaption))
            {
                return GetString("TemplateDesigner.ErrorEmptyFieldCaption") + " ";
            }
            // Check if control is selected
            if (String.IsNullOrEmpty(control))
            {
                return GetString("fieldeditor.selectformcontrol");
            }
        }

        // Validation of the advanced mode controls
        if (SelectedMode == FieldEditorSelectedModeEnum.Advanced)
        {
            // Check attribute size value
            if (databaseConfiguration.AttributeType == FormFieldDataTypeCode.TEXT)
            {
                string attSize = databaseConfiguration.AttributeSize;
                // Attribute size is empty -> error
                if (string.IsNullOrEmpty(attSize))
                {
                    return GetString("TemplateDesigner.ErrorEmptyAttributeSize") + " ";
                }

                int attributeSize = ValidationHelper.GetInteger(attSize, 0);

                // Attribute size is invalid -> error
                if ((attributeSize <= 0) || (attributeSize > ValidationHelper.MAX_NVARCHAR_LENGTH))
                {
                    return GetString("TemplateDesigner.ErrorInvalidAttributeSize") + " ";
                }

                if ((databaseConfiguration.DefaultValueText.Length > attributeSize) ||
                    (databaseConfiguration.LargeDefaultValueText.Length > attributeSize))
                {
                    return GetString("TemplateDesigner.ErrorDefaultValueSize") + " ";
                }
            }

            // Check min length value
            string minLength = validationSettings.MinLengthText;
            if (!string.IsNullOrEmpty(minLength))
            {
                if ((!ValidationHelper.IsInteger(minLength)) ||
                     ((ValidationHelper.IsInteger(minLength)) && (Convert.ToInt32(minLength) < 0)))
                {
                    MinAndMaxLengthInCorrectFormat = false;
                    return GetString("TemplateDesigner.ErrorMinLengthNotInteger") + " ";
                }
            }

            // Check max length value
            string maxLength = validationSettings.MaxLengthText;
            if (!string.IsNullOrEmpty(maxLength))
            {
                if ((!ValidationHelper.IsInteger(maxLength)) ||
                     ((ValidationHelper.IsInteger(maxLength)) && (Convert.ToInt32(maxLength) < 0)))
                {
                    MinAndMaxLengthInCorrectFormat = false;
                    return GetString("TemplateDesigner.ErrorMaxLengthNotInteger") + " ";
                }
            }

            // Min and max length are specified and in correct format -> check if min length is less than max length
            if ((!string.IsNullOrEmpty(minLength)) && (!string.IsNullOrEmpty(maxLength)) && (MinAndMaxLengthInCorrectFormat))
            {
                if ((Convert.ToInt32(minLength)) > (Convert.ToInt32(maxLength)))
                {
                    return GetString("TemplateDesigner.ErrorMinLengthGreater") + " ";
                }
            }

            if (databaseConfiguration.AttributeType == FormFieldDataTypeCode.DOUBLE)
            {
                string strMinValue = validationSettings.MinValueText;
                string strMaxValue = validationSettings.MaxValueText;

                double minValue = 0.0;
                double maxValue = 0.0;

                // Check min value
                if (!string.IsNullOrEmpty(strMinValue))
                {
                    minValue = ValidationHelper.GetDouble(strMinValue, Double.NaN);

                    if (Double.IsNaN(minValue))
                    {
                        MinAndMaxValueInCorrectFormat = false;
                        return GetString("TemplateDesigner.ErrorMinValueNotDouble") + " ";
                    }
                }

                // Check max value
                if (!string.IsNullOrEmpty(strMaxValue))
                {
                    maxValue = ValidationHelper.GetDouble(strMaxValue, Double.NaN);

                    if (Double.IsNaN(maxValue))
                    {
                        MinAndMaxValueInCorrectFormat = false;
                        return GetString("TemplateDesigner.ErrorMaxValueNotDouble") + " ";
                    }
                }

                // Min and max value are specified and in correct format -> check if min value is less than max value
                if ((!string.IsNullOrEmpty(strMinValue)) && (!string.IsNullOrEmpty(strMaxValue)) && (MinAndMaxValueInCorrectFormat))
                {
                    if (minValue > maxValue)
                    {
                        return GetString("TemplateDesigner.ErrorMinValueGreater") + " ";
                    }
                }
            }
            else if (databaseConfiguration.AttributeType == FormFieldDataTypeCode.INTEGER)
            {
                // Check min value
                if (!string.IsNullOrEmpty(validationSettings.MinValueText))
                {
                    if (!ValidationHelper.IsInteger(validationSettings.MinValueText))
                    {
                        MinAndMaxValueInCorrectFormat = false;
                        return GetString("TemplateDesigner.ErrorMinValueNotInteger") + " ";
                    }
                }

                // Check max value
                if (!string.IsNullOrEmpty(validationSettings.MaxValueText))
                {
                    if (!ValidationHelper.IsInteger(validationSettings.MaxValueText))
                    {
                        MinAndMaxValueInCorrectFormat = false;
                        return GetString("TemplateDesigner.ErrorMaxValueNotInteger") + " ";
                    }
                }

                // Min and max value are specified and in correct format -> check if min value is less than max value
                if ((!string.IsNullOrEmpty(validationSettings.MinValueText)) && (!string.IsNullOrEmpty(validationSettings.MaxValueText)) && (MinAndMaxValueInCorrectFormat))
                {
                    if ((Convert.ToInt32(validationSettings.MinValueText)) > (Convert.ToInt32(validationSettings.MaxValueText)))
                    {
                        return GetString("TemplateDesigner.ErrorMinValueGreater") + " ";
                    }
                }
            }
            else if (databaseConfiguration.AttributeType == FormFieldDataTypeCode.LONGINTEGER)
            {
                string minValue = validationSettings.MinValueText;
                string maxValue = validationSettings.MaxValueText;
                // Check min value
                if (!string.IsNullOrEmpty(minValue))
                {
                    if (!ValidationHelper.IsLong(minValue))
                    {
                        MinAndMaxValueInCorrectFormat = false;
                        return GetString("TemplateDesigner.ErrorMinValueNotLongInteger") + " ";
                    }
                }

                // Check max value
                if (!string.IsNullOrEmpty(maxValue))
                {
                    if (!ValidationHelper.IsLong(maxValue))
                    {
                        MinAndMaxValueInCorrectFormat = false;
                        return GetString("TemplateDesigner.ErrorMaxValueNotLongInteger") + " ";
                    }
                }

                // Min and max value are specified and in correct format -> check if min value is less than max value
                if ((!string.IsNullOrEmpty(minValue)) && (!string.IsNullOrEmpty(maxValue)) && (MinAndMaxValueInCorrectFormat))
                {
                    if ((Convert.ToInt64(minValue)) > (Convert.ToInt64(maxValue)))
                    {
                        return GetString("TemplateDesigner.ErrorMinValueGreater") + " ";
                    }
                }
            }
        }
        // Validate simple mode
        else
        {
            // Check that textbox field has some minimum length set
            if (simpleMode.AttributeType == FormFieldDataTypeCode.TEXT)
            {
                if (simpleMode.AttributeSize <= 0 || simpleMode.AttributeSize > ValidationHelper.MAX_NVARCHAR_LENGTH)
                {
                    return GetString("TemplateDesigner.ErrorInvalidTextBoxMaxLength");
                }

                ffi = fi.GetFormField(SelectedItemName);
                if (simpleMode.GetDefaultValue(ffi).Length > simpleMode.AttributeSize)
                {
                    return GetString("TemplateDesigner.ErrorDefaultValueSize");
                }
            }
        }

        return null;
    }
    private string ValidateFieldColumn(FormFieldInfo fieldInfo)
    {
        // Check if the attribute name already exists
        if (IsNewItemEdited || (!ffi.Name.EqualsCSafe(fieldInfo.Name, StringComparison.InvariantCultureIgnoreCase)))
        {
            var columnNames = FormInfo.GetColumnNames();

            // If name already exists
            if ((columnNames != null) && (columnNames.Any(c => fieldInfo.Name.EqualsCSafe(c, StringComparison.InvariantCultureIgnoreCase))))
            {
                return GetString("TemplateDesigner.ErrorExistingColumnName");
            }

            // Check column name duplicity in JOINed tables
            if (!IsSystemFieldSelected)
            {
                // Check whether current column already exists in 'View_CMS_Tree_Joined'
                if (IsDocumentType && DocumentHelper.ColumnExistsInDocumentView(fieldInfo.Name))
                {
                    return GetString("TemplateDesigner.ErrorExistingColumnInJoinedTable");
                }

                // Check whether current column is unique in tables used to create views - applied only for system tables
                if ((Mode == FieldEditorModeEnum.SystemTable) && FormHelper.ColumnExistsInView(ClassName, fieldInfo.Name))
                {
                    return GetString("TemplateDesigner.ErrorExistingColumnInJoinedTable");
                }
            }
        }

        return null;
    }