Exemple #1
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);
        }
        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);
        }
Exemple #3
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);
        }
Exemple #4
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
                {
                }
            }
        }
    }
Exemple #5
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());
    }
Exemple #6
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);
    }
Exemple #7
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);
                }
            }
        }
    }
 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);
     }
 }
Exemple #10
0
 /// <summary>
 /// Load field.
 /// </summary>
 public void Reload()
 {
     if (ffi != null)
     {
         bool isMacro;
         txtCaptionStyle.SetValue(ffi.GetPropertyValue(FormFieldPropertyEnum.CaptionStyle, out isMacro), isMacro);
         txtCaptionCssClass.SetValue(ffi.GetPropertyValue(FormFieldPropertyEnum.CaptionCssClass, out isMacro), isMacro);
         txtCaptionCellCssClass.SetValue(ffi.GetPropertyValue(FormFieldPropertyEnum.CaptionCellCssClass, out isMacro), isMacro);
         txtInputStyle.SetValue(ffi.GetPropertyValue(FormFieldPropertyEnum.InputControlStyle, out isMacro), isMacro);
         txtControlCssClass.SetValue(ffi.GetPropertyValue(FormFieldPropertyEnum.ControlCssClass, out isMacro), isMacro);
         txtControlCellCssClass.SetValue(ffi.GetPropertyValue(FormFieldPropertyEnum.ControlCellCssClass, out isMacro), isMacro);
         txtFieldCssClass.SetValue(ffi.GetPropertyValue(FormFieldPropertyEnum.FieldCssClass, out isMacro), isMacro);
         pnlCss.Enabled = ffi.Visible;
     }
     else
     {
         txtCaptionStyle.SetValue(null, false);
         txtCaptionCssClass.SetValue(null, false);
         txtCaptionCellCssClass.SetValue(null, false);
         txtInputStyle.SetValue(null, false);
         txtControlCssClass.SetValue(null, false);
         txtControlCellCssClass.SetValue(null, false);
         txtFieldCssClass.SetValue(null, false);
         pnlCss.Enabled = true;
     }
 }
Exemple #11
0
    /// <summary>
    /// Prepares caption for custom property.
    /// </summary>
    protected string PrepareCaption(FormFieldInfo field)
    {
        string caption = field.GetPropertyValue(FormFieldPropertyEnum.FieldCaption, MacroContext.CurrentResolver);

        if (string.IsNullOrEmpty(caption))
        {
            caption = field.Name;
        }
        return(ResHelper.LocalizeString(caption, null, true));
    }
Exemple #12
0
    /// <summary>
    /// Retrieves a display name of the specified CMS user settings field, and returns it.
    /// </summary>
    /// <param name="fieldName">The CMS user settings field name.</param>
    /// <returns>A display name of the specified CMS user settings field, if found; otherwise, an empty string.</returns>
    protected string GetUserSettingsFieldDisplayName(string fieldName)
    {
        FormFieldInfo field = UserSettingsFormInfo.GetFormField(fieldName);

        if (field == null)
        {
            return(String.Empty);
        }

        return(ResHelper.LocalizeString(field.GetPropertyValue(FormFieldPropertyEnum.FieldCaption, MacroContext.CurrentResolver)));
    }
Exemple #13
0
    private string GetFieldCaption(string name)
    {
        FormFieldInfo field = FormInfo.GetFormField(name);

        if (field == null)
        {
            return(String.Empty);
        }

        return(ResHelper.LocalizeString(field.GetPropertyValue(FormFieldPropertyEnum.FieldCaption, MacroContext.CurrentResolver)));
    }
    protected void MappingItemRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        LocalizedLabel  literal      = e.Item.FindControl("FieldNameLiteral") as LocalizedLabel;
        CMSDropDownList dropDownList = e.Item.FindControl("AttributeNamesDropDownList") as CMSDropDownList;
        FormFieldInfo   fieldInfo    = e.Item.DataItem as FormFieldInfo;

        literal.Text = ResHelper.LocalizeString(fieldInfo.GetPropertyValue(FormFieldPropertyEnum.FieldCaption, MacroContext.CurrentResolver));
        dropDownList.Items.Add(new ListItem(String.Empty, String.Empty));
        dropDownList.Items.AddRange(mContext.EntityInfo.Items.Select(x => new ListItem(ResHelper.LocalizeString(x.DisplayName), x.Name)).ToArray());
        mAttributeNamesDropDownLists.Add(fieldInfo.Name, dropDownList);
    }
Exemple #15
0
 /// <summary>
 /// Loads field with values from FormFieldInfo.
 /// </summary>
 public void Reload()
 {
     if (ffi != null)
     {
         chkHasDepending.Checked        = ffi.HasDependingFields;
         chkDependsOn.Checked           = ffi.DependsOnAnotherField;
         VisibleMacro                   = ffi.GetPropertyValue(FormFieldPropertyEnum.VisibleMacro);
         EnabledMacro                   = ffi.GetPropertyValue(FormFieldPropertyEnum.EnabledMacro);
         chkDisplayInSimpleMode.Checked = ffi.DisplayInSimpleMode;
     }
     // If FormFieldInfo is not specified then clear form
     else
     {
         chkHasDepending.Checked        = false;
         chkDependsOn.Checked           = false;
         chkDisplayInSimpleMode.Checked = false;
         VisibleMacro = String.Empty;
         EnabledMacro = String.Empty;
     }
 }
 private void LoadProperty(FormFieldInfo ffi, FormFieldPropertyEnum property, FormEngineUserControl control, MessagesPlaceHolder msgPlaceHolder)
 {
     if (control != null)
     {
         bool isMacro = ffi.IsMacro(property);
         control.Visible = !isMacro;
         if (!isMacro)
         {
             control.Value = ffi.GetPropertyValue(property);
         }
         else
         {
             msgPlaceHolder.ShowInformation(GetString("FormBuilder.PropertyIsMacro"));
         }
     }
 }
    /// <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.GetPropertyValue(FormFieldPropertyEnum.FieldCaption, resolver);
        }
        if (string.IsNullOrEmpty(fieldCaption))
        {
            fieldCaption = columnName;
        }

        return(fieldCaption);
    }
Exemple #18
0
    /// <summary>
    /// Creates and initializes a new instance of the Panel class with the specified Data.com company mapping, and returns it.
    /// </summary>
    /// <param name="formInfo">The CMS account form info.</param>
    /// <param name="entityInfo">The Data.com company entity info.</param>
    /// <param name="mapping">The Data.com company mapping.</param>
    /// <returns>A new instance of the Panel class initialized with the specified Data.com company mapping.</returns>
    private Panel CreateMappingPanel(FormInfo formInfo, EntityInfo entityInfo, EntityMapping mapping)
    {
        Panel mappingPanel = new Panel {
            CssClass = "mapping"
        };

        mappingPanel.Controls.Add(CreateHeaderPanel());
        foreach (IField formItem in formInfo.ItemsList)
        {
            FormFieldInfo formField = formItem as FormFieldInfo;
            if (formField != null)
            {
                EntityMappingItem mappingItem = mapping.GetItem(formField.Name);
                if (mappingItem != null)
                {
                    EntityAttributeInfo entityAttribute = entityInfo.GetAttributeInfo(mappingItem.EntityAttributeName);
                    if (entityAttribute != null)
                    {
                        Panel row = new Panel {
                            CssClass = "control-group-inline"
                        };
                        mappingPanel.Controls.Add(row);

                        Panel formFieldPanel = new Panel {
                            CssClass = "input-width-60 cms-form-group-text"
                        };
                        row.Controls.Add(formFieldPanel);
                        formFieldPanel.Controls.Add(new Literal {
                            Text = ResHelper.LocalizeString(formField.GetPropertyValue(FormFieldPropertyEnum.FieldCaption, MacroContext.CurrentResolver))
                        });

                        Panel entityAttributePanel = new Panel {
                            CssClass = "input-width-60 cms-form-group-text"
                        };
                        row.Controls.Add(entityAttributePanel);
                        entityAttributePanel.Controls.Add(new Literal {
                            Text = ResHelper.LocalizeString(entityAttribute.DisplayName)
                        });
                    }
                }
            }
        }

        return(mappingPanel);
    }
    /// <summary>
    /// Returns default value set for given form field or a default value according to the field data type if required. This default value will be in the same culture as the database.
    /// </summary>
    /// <param name="fieldInfo">Form field with default value</param>
    /// <param name="errorMessage">Error that occurred during stored default value validation.</param>
    /// <param name="forceDefaultValue">Indicates whether data type default value should be used when no default value is stored in the form field.</param>
    protected static string GetDefaultValueInDBCulture(FormFieldInfo fieldInfo, out string errorMessage, bool forceDefaultValue = true)
    {
        errorMessage = null;
        bool   isMacro;
        string defaultValue = fieldInfo.GetPropertyValue(FormFieldPropertyEnum.DefaultValue, out isMacro);

        // Set implicit default value
        if (!fieldInfo.AllowEmpty && String.IsNullOrEmpty(defaultValue))
        {
            if (forceDefaultValue)
            {
                defaultValue = GetColumnDefaultValue(fieldInfo.DataType);
            }
        }
        else
        {
            // Check if default value is in required format
            defaultValue = ValidateColumnDefaultValue(fieldInfo.DataType, defaultValue, isMacro, out errorMessage);
        }

        string result = defaultValue;

        // Check if it is not a macro
        if (!isMacro && String.IsNullOrEmpty(errorMessage))
        {
            switch (fieldInfo.DataType)
            {
            case FieldDataType.Double:
                result = FormHelper.GetDoubleValueInDBCulture(defaultValue);
                break;

            case FieldDataType.DateTime:
                result = FormHelper.GetDateTimeValueInDBCulture(defaultValue);
                break;

            default:
                result = defaultValue;
                break;
            }
        }

        return(result);
    }
    /// <summary>
    /// Indicates whether such a change has been made to the field, it requires database structure update.
    /// </summary>
    /// <param name="oldFieldInfo">Field prior to the change.</param>
    /// <param name="updatedFieldInfo">Field after the change.</param>
    /// <returns></returns>
    protected static bool IsDatabaseChangeRequired(FormFieldInfo oldFieldInfo, FormFieldInfo updatedFieldInfo)
    {
        if ((oldFieldInfo == null) || (updatedFieldInfo == null))
        {
            return(false);
        }

        bool   originalIsMacro;
        string originalDefaultValue = oldFieldInfo.GetPropertyValue(FormFieldPropertyEnum.DefaultValue, out originalIsMacro);

        bool   isMacro;
        string defaultValue = updatedFieldInfo.GetPropertyValue(FormFieldPropertyEnum.DefaultValue, out isMacro);

        return((oldFieldInfo.Name != updatedFieldInfo.Name) ||
               (oldFieldInfo.DataType != updatedFieldInfo.DataType) ||
               (oldFieldInfo.Size != updatedFieldInfo.Size) ||
               (oldFieldInfo.AllowEmpty != updatedFieldInfo.AllowEmpty) ||
               (originalDefaultValue != defaultValue) ||
               (originalIsMacro != isMacro));
    }
 /// <summary>
 /// Prepares caption for custom property.
 /// </summary>
 protected string PrepareCaption(FormFieldInfo field)
 {
     string caption = field.GetPropertyValue(FormFieldPropertyEnum.FieldCaption, MacroContext.CurrentResolver);
     if (string.IsNullOrEmpty(caption))
     {
         caption = field.Name;
     }
     return ResHelper.LocalizeString(caption, null, true);
 }
Exemple #22
0
        private static void ImportWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                BackgroundWorker worker = (BackgroundWorker)sender;

                // Save import profile
                if (ImportProfile.SaveImportProfile && !ImportProfile.UsesConsole)
                {
                    SaveFile(SaveImportProfile);
                }

                // Decide whether to import
                if (!ImportProfile.ImportNow && !ImportProfile.UsesConsole)
                {
                    return;
                }

                using (new CMSActionContext()
                {
                    LogEvents = false, ContinuousIntegrationAllowObjectSerialization = false
                })
                {
                    #region "Initialization"

                    // Import canceled
                    if (worker.CancellationPending)
                    {
                        e.Cancel = true;
                        return;
                    }

                    DateTime start = DateTime.Now;

                    // Initialize CMS context
                    CMSInit();

                    if (ImportProfile.UsesConsole)
                    {
                        // Ensure object in case they are not present in import profile
                        EnsureObjects();
                    }

                    if (ImportProfile.ImportUsersOnlyFromSelectedRoles)
                    {
                        // Narrow down imported users according to imported roles
                        ImportProfile.Users.Clear();
                    }

                    // Import canceled
                    if (worker.CancellationPending)
                    {
                        e.Cancel = true;
                        return;
                    }

                    // Initialize cumulative changed users and roles storages
                    var rolesChanged = new CumulatedChanges(WellKnownEventLogEventsEnum.RolesCreated, WellKnownEventLogEventsEnum.RolesUpdated, WellKnownEventLogEventsEnum.RolesDeleted);
                    var usersChanged = new CumulatedChanges(WellKnownEventLogEventsEnum.UsersCreated, WellKnownEventLogEventsEnum.UsersUpdated, WellKnownEventLogEventsEnum.UsersDeleted);

                    #endregion

                    // Delete non-existing objects (this also prevents conflicting code names)
                    if (ImportProfile.DeleteNotExistingObjects)
                    {
                        DeleteNonExistingObjects(usersChanged, rolesChanged);
                    }

                    #region "Role import"

                    foreach (var siteInfo in ImportProfile
                             .Sites
                             .Select(site => SiteInfo.Provider.Get(site.Key))
                             .Where(info => info != null))
                    {
                        foreach (Guid groupGuid in ImportProfile.Groups)
                        {
                            // Import canceled
                            if (worker.CancellationPending)
                            {
                                e.Cancel = true;
                                return;
                            }

                            // Try to get group
                            IPrincipalObject group = PrincipalProvider.GetPrincipalObject(groupGuid);

                            // If group is still null
                            if (group == null)
                            {
                                MessageLog.LogEvent(ResHelper.GetString("Log_SkippingNonExistingObject"));
                                warnings++;
                                // If deleting of not existing objects is enabled
                                if (ImportProfile.DeleteNotExistingObjects)
                                {
                                    DeleteRole(siteInfo, groupGuid);
                                }
                            }
                            else
                            {
                                // Get role description
                                string roleDescription = String.Empty;
                                if (ImportProfile.ImportRoleDescription && (group.Description != null))
                                {
                                    roleDescription = group.Description;
                                }

                                // Get correct role name format
                                string roleCodeName = group.GetCMSCodeName(true);

                                // Get role display name
                                string roleDisplayName = group.GetCMSDisplayName();

                                // Get safe role name
                                roleCodeName = ValidationHelper.GetSafeRoleName(roleCodeName, siteInfo.SiteName);

                                if (!String.IsNullOrEmpty(roleCodeName))
                                {
                                    // Add message to log
                                    MessageLog.LogEvent(ResHelper.GetString("Log_ImportingRole", roleDisplayName, CMS.Helpers.ResHelper.LocalizeString(siteInfo.DisplayName)));

                                    // Import role
                                    ImportRole(roleCodeName, roleDisplayName, siteInfo.SiteID, roleDescription, groupGuid, ImportProfile.UpdateObjectData, rolesChanged);

                                    if (ImportProfile.ImportUsersOnlyFromSelectedRoles)
                                    {
                                        ImportProfile.Users.AddRange(PrincipalProvider.GetUsersOf(group).Select(u => u.Identifier));
                                    }
                                }
                                else
                                {
                                    // Add message to log
                                    MessageLog.LogEvent(ResHelper.GetString("Log_SkippingEmptyRolename", group.Identifier));
                                    warnings++;
                                }
                            }
                        }
                    }

                    // Log created and updated and removed roles to EventLog
                    rolesChanged.WriteEventsToEventLog();

                    #endregion

                    #region "User import"

                    foreach (var user in ImportProfile
                             .Users
                             .Distinct()
                             .Select(userGuid => PrincipalProvider.GetPrincipalObject(userGuid)))
                    {
                        // Import canceled
                        if (worker.CancellationPending)
                        {
                            e.Cancel = true;
                            return;
                        }

                        if (user == null)
                        {
                            MessageLog.LogEvent(ResHelper.GetString("Log_SkippingNonExistingObject"));
                            continue;
                        }

                        string domainName = user.GetCMSCodeName(true);

                        if (!String.IsNullOrEmpty(domainName))
                        {
                            // Get user info object
                            UserInfo userInfo = (UserInfo.Provider.Get((Guid)user.Identifier) ?? UserInfo.Provider.Get(domainName));
                            bool     newUser  = (userInfo == null);

                            // When is desired to import new users only from selected roles
                            if (newUser && ImportProfile.ImportNewUsersOnlyFromSelectedRoles)
                            {
                                // Skip users that does not belong to one of selected role
                                bool skip = ImportProfile.Groups.Cast <Guid>().All(groupGuid => !user.IsPrincipalInGroup(groupGuid));
                                if (skip)
                                {
                                    MessageLog.LogEvent(ResHelper.GetString("Log_SkippingDoesNotBelongToSelectedRole", domainName));
                                    continue;
                                }
                            }

                            if (ImportProfile.UpdateObjectData || newUser)
                            {
                                if (userInfo == null)
                                {
                                    userInfo = new UserInfo();
                                    // Add message to log
                                    MessageLog.LogEvent(ResHelper.GetString("Log_ImportingUser", domainName));
                                }
                                else
                                {
                                    // Add message to log
                                    MessageLog.LogEvent(ResHelper.GetString("Log_UpdatingUser", domainName));
                                }

                                using (var transaction = new CMSTransactionScope())
                                {
                                    if (newUser)
                                    {
                                        userInfo.UserIsDomain = true;
                                        userInfo.UserGUID     = (Guid)user.Identifier;

                                        // Set privilege level
                                        UserPrivilegeLevelEnum privilegeLevel = ImportProfile.ConfigureAsCMSEditor ? UserPrivilegeLevelEnum.Editor : UserPrivilegeLevelEnum.None;
                                        userInfo.SiteIndependentPrivilegeLevel = privilegeLevel;
                                    }

                                    if (userInfo.UserIsDomain)
                                    {
                                        // Set user's properties
                                        userInfo.UserIsExternal = true;
                                        userInfo.UserName       = domainName;
                                        userInfo.Enabled        = ValidationHelper.GetBoolean(user.Enabled, true);

                                        // Bind properties
                                        foreach (KeyValuePair <string, string> property in ImportProfile.UserProperties)
                                        {
                                            // Get attribute
                                            object attribute = user.GetProperty(property.Value);

                                            if (attribute != null)
                                            {
                                                try
                                                {
                                                    string attrValue;

                                                    // Get string representation of the attribute
                                                    if (attribute is float || attribute is double || attribute is decimal)
                                                    {
                                                        attrValue = String.Format(CultureInfo.InvariantCulture, "{0}", attribute);
                                                    }
                                                    else if (attribute.GetType() == typeof(byte[]))
                                                    {
                                                        attrValue = PrincipalProvider.GetSID(attribute);
                                                    }
                                                    else if (attribute.GetType().BaseType == typeof(MarshalByRefObject))
                                                    {
                                                        attrValue = PrincipalProvider.GetTimeFromInterval(attribute);
                                                    }
                                                    else
                                                    {
                                                        attrValue = attribute.ToString();
                                                    }

                                                    // Set property
                                                    userInfo.SetValue(property.Key, LimitLengthForField(attrValue, property.Key));
                                                }
                                                catch
                                                {
                                                    MessageLog.LogEvent(ResHelper.GetString("Log_ErrorParsingAttr", property.Value));
                                                    warnings++;
                                                }
                                            }
                                            else
                                            {
                                                FormFieldInfo field = UserFormInfo.GetFormField(property.Key);
                                                userInfo.SetValue(property.Key, field.GetPropertyValue(FormFieldPropertyEnum.DefaultValue));
                                            }
                                        }

                                        // Create full name if empty
                                        if (String.IsNullOrEmpty(userInfo.FullName))
                                        {
                                            userInfo.FullName = user.GetCMSDisplayName();
                                        }

                                        // Store user info object and its user-settings
                                        if (userInfo.ChangedColumns().Any())
                                        {
                                            // Store created/updated user for EventLog
                                            // User name is used, because AD accounts does not have to have first and/or given name specified (e.g. Guest, …)
                                            usersChanged.Add(userInfo.UserGUID, userInfo.UserName, newUser ? ChangeActionEnum.Created : ChangeActionEnum.Updated);

                                            UserInfo.Provider.Set(userInfo);
                                        }
                                    }
                                    else
                                    {
                                        MessageLog.LogEvent(ResHelper.GetString("Log_UserIsNotDomain", userInfo.UserName));
                                        warnings++;
                                    }

                                    transaction.Commit();
                                }
                            }
                            else
                            {
                                MessageLog.LogEvent(ResHelper.GetString("Log_SkippingExistingUser", domainName));
                            }

                            // Import canceled
                            if (worker.CancellationPending)
                            {
                                e.Cancel = true;
                                return;
                            }

                            // Assign user to sites and roles (for domain users only)
                            if (!userInfo.UserIsDomain)
                            {
                                continue;
                            }


                            #region "Membership (roles) synchronization"

                            if (!newUser && !ImportProfile.UpdateMemberships && !ImportProfile.UpdateMemberships)
                            {
                                // No membership synchronization will be performed
                                continue;
                            }

                            // Initialize collection to cumulate membership changes
                            var memberShipChanges = new CumulatedRolesMembership();

                            // Load all user roles from DB
                            var userRoles = new HashSet <RoleInfo>(newUser
                                ? Enumerable.Empty <RoleInfo>() // non-existing user cannot be present in a single role (in DB)
                                : RoleInfo.Provider
                                                                   .Get()
                                                                   .WhereIn("RoleID",
                                                                            UserRoleInfo.Provider
                                                                            .Get()
                                                                            .WhereEquals("UserID", userInfo.UserID)
                                                                            .Column("RoleID"))
                                                                   .Columns("RoleID", "RoleGUID", "RoleDisplayName", "RoleIsDomain"));

                            // Store user's roles before membership synchronization
                            memberShipChanges.SetRolesBefore(userRoles);
                            foreach (KeyValuePair <string, List <Guid> > site in ImportProfile.Sites)
                            {
                                // Get site info object
                                var siteInfo = SiteInfo.Provider.Get(site.Key);
                                if (siteInfo != null)
                                {
                                    try
                                    {
                                        // Add user to this site
                                        UserSiteInfo.Provider.Add(userInfo.UserID, siteInfo.SiteID);
                                    }
                                    catch (Exception ex)
                                    {
                                        MessageLog.LogEvent(ResHelper.GetString("Log_GeneralWarning", ex.Message));
                                        warnings++;
                                    }

                                    // Assign user to roles already existing in CMS
                                    if (newUser || ImportProfile.UpdateMemberships)
                                    {
                                        SetMemberships(user, userInfo, siteInfo, userRoles, site);
                                    }

                                    // Remove user from roles they is member no more
                                    if (!newUser && ImportProfile.UpdateMemberships)
                                    {
                                        RemoveExcessiveMemberships(user, userInfo, userRoles);
                                    }
                                }
                                else
                                {
                                    MessageLog.LogEvent(ResHelper.GetString("Log_SiteNotExist", site.Key));
                                    warnings++;
                                }
                            }

                            // Store user's roles after membership synchronization
                            memberShipChanges.SetRolesAfter(userRoles);

                            // Log created and removed memberships to EventLog
                            memberShipChanges.WriteEventsToEventLog(userInfo.UserName);

                            #endregion
                        }
                        else
                        {
                            // Add message to log
                            MessageLog.LogEvent(ResHelper.GetString("Log_SkippingEmptyUsername", user.Identifier));
                            warnings++;
                        }
                    }

                    // Log created and updated and deleted users to EventLog
                    usersChanged.WriteEventsToEventLog();

                    #endregion

                    // Import canceled
                    if (worker.CancellationPending)
                    {
                        e.Cancel = true;
                        return;
                    }

                    TimeSpan duration = DateTime.Now - start;

                    if (!worker.CancellationPending)
                    {
                        // Add message to log
                        MessageLog.LogEvent(warnings == 0
                            ? ResHelper.GetString("Log_ImportComplete", duration.Hours, duration.Minutes, duration.Seconds)
                            : ResHelper.GetString("Log_ImportCompleteWithWarnings", warnings, duration.Hours, duration.Minutes, duration.Seconds));
                    }
                }
            }
            catch (Exception ex)
            {
                MessageLog.LogError(ResHelper.GetString("Error_General"), ex);
            }
        }
    protected void gridData_OnLoadColumns()
    {
        if ((CustomTableClassInfo != null) && (FormInfo != null))
        {
            // Update the actions command argument
            foreach (Action action in gridData.GridActions.Actions)
            {
                action.CommandArgument = ti.IDColumn;
            }

            string        columnNames = null;
            List <string> columnList;

            string columns = CustomTableClassInfo.ClassShowColumns;
            if (string.IsNullOrEmpty(columns))
            {
                columnList = new List <string>();
                columnList.AddRange(GetExistingColumns(false).Take(5));

                // Show info message
                ShowInformation(GetString("customtable.columnscount.default"));
            }
            else
            {
                // Get existing columns names
                List <string> existingColumns = GetExistingColumns(true);

                // Get selected columns
                List <string> selectedColumns = GetSelectedColumns(columns);

                columnList = new List <string>();
                StringBuilder sb = new StringBuilder();

                // Remove non-existing columns
                foreach (string col in selectedColumns)
                {
                    int index = existingColumns.BinarySearch(col, StringComparer.InvariantCultureIgnoreCase);
                    if (index >= 0)
                    {
                        string colName = existingColumns[index];
                        columnList.Add(colName);
                        sb.Append(",[", colName, "]");
                    }
                }

                // Ensure item order column
                selectedColumns.Sort();
                if ((selectedColumns.BinarySearch("ItemOrder", StringComparer.InvariantCultureIgnoreCase) < 0) && HasItemOrderField)
                {
                    sb.Append(",[ItemOrder]");
                }

                // Ensure itemid column
                if (selectedColumns.BinarySearch(ti.IDColumn, StringComparer.InvariantCultureIgnoreCase) < 0)
                {
                    sb.Insert(0, ",[" + ti.IDColumn + "]");
                }

                columnNames = sb.ToString().TrimStart(',');
            }

            // Get macro resolver
            MacroResolver resolver = MacroResolverStorage.GetRegisteredResolver(FormHelper.FORM_PREFIX + CustomTableClassInfo.ClassName);

            // Loop trough all columns
            for (int i = 0; i < columnList.Count; i++)
            {
                string column = columnList[i];

                // Get field caption
                FormFieldInfo ffi          = FormInfo.GetFormField(column);
                string        fieldCaption = string.Empty;
                if (ffi == null)
                {
                    fieldCaption = column;
                }
                else
                {
                    string caption = ffi.GetPropertyValue(FormFieldPropertyEnum.FieldCaption, resolver);
                    fieldCaption = (caption == string.Empty) ? column : ResHelper.LocalizeString(caption);
                }

                Column columnDefinition = new Column
                {
                    Caption            = fieldCaption,
                    Source             = column,
                    ExternalSourceName = column,
                    AllowSorting       = true,
                    Wrap = false
                };

                if (i == columnList.Count - 1)
                {
                    // Stretch last column
                    columnDefinition.Width = "100%";
                }

                gridData.GridColumns.Columns.Add(columnDefinition);
            }

            // Set column names
            gridData.Columns = columnNames;
        }
    }
Exemple #24
0
 private object GetElementGuidelines(FormFieldInfo field)
 {
     return(field.GetPropertyValue(FormFieldPropertyEnum.ExplanationText));
 }
    protected void gridData_OnLoadColumns()
    {
        if (bfi != null)
        {
            var    columnList = new List <string>();
            string columns    = bfi.FormReportFields;
            if (string.IsNullOrEmpty(columns))
            {
                columnList = GetExistingColumns();
            }
            else
            {
                // Get existing columns names
                var existingColumns = GetExistingColumns();

                // Get selected columns
                var selectedColumns = GetSelectedColumns(columns);

                columns     = string.Empty;
                columnNames = string.Empty;
                StringBuilder sb = new StringBuilder();

                // Remove nonexisting columns
                foreach (string col in selectedColumns)
                {
                    if (existingColumns.Contains(col))
                    {
                        columnList.Add(col);
                        sb.Append(",[").Append(col).Append("]");
                    }
                }
                columnNames = sb.ToString();

                // Ensure primary key
                if (!(columnNames.Contains(primaryColumn) || columnNames.Contains(primaryColumn)))
                {
                    columnNames = ",[" + primaryColumn + "]" + columnNames;
                }

                columnNames = columnNames.TrimStart(',');
            }

            // Get macro resolver for current form
            MacroResolver resolver = MacroResolverStorage.GetRegisteredResolver(FormHelper.FORM_PREFIX + dci.ClassName);

            // Loop trough all columns
            for (int i = 0; i < columnList.Count; i++)
            {
                string column = columnList[i];

                // Get field caption
                FormFieldInfo ffi = FormInfo.GetFormField(column);

                string fieldCaption = null;
                if (ffi == null)
                {
                    fieldCaption = column;
                }
                else
                {
                    string caption = ffi.GetPropertyValue(FormFieldPropertyEnum.FieldCaption, resolver);
                    fieldCaption = (string.IsNullOrEmpty(caption)) ? column : ResHelper.LocalizeString(caption);
                }

                Column columnDefinition = new Column
                {
                    Caption      = fieldCaption,
                    Source       = column,
                    AllowSorting = true,
                    Wrap         = false
                };

                if (i == columnList.Count - 1)
                {
                    // Stretch last column
                    columnDefinition.Width = "100%";
                }

                gridData.GridColumns.Columns.Add(columnDefinition);
            }
        }
    }
    private MappingItem GetMappingItem()
    {
        string name = SourceDropDownList.SelectedValue;

        if (!String.IsNullOrEmpty(name))
        {
            if (name.StartsWithCSafe("Field-"))
            {
                name = name.Remove(0, "Field-".Length);
                FormFieldInfo fieldInfo = FormInfo.GetFormField(name);
                if (fieldInfo != null)
                {
                    return(new MappingItem(EntityAttributeModel, name, ResHelper.LocalizeString(fieldInfo.GetPropertyValue(FormFieldPropertyEnum.FieldCaption, MacroContext.CurrentResolver)), MappingItemSourceTypeEnum.Field));
                }
            }
            else if (name.StartsWithCSafe("MetaField-"))
            {
                name = name.Remove(0, "MetaField-".Length);
                switch (name)
                {
                case "CompanyName":
                    return(new MappingItem(EntityAttributeModel, name, GetString("sf.metasource.companyname"), MappingItemSourceTypeEnum.MetaField));

                case "Description":
                    return(new MappingItem(EntityAttributeModel, name, GetString("sf.metasource.description"), MappingItemSourceTypeEnum.MetaField));

                case "Country":
                    return(new MappingItem(EntityAttributeModel, name, GetString("sf.metasource.country"), MappingItemSourceTypeEnum.MetaField));

                case "State":
                    return(new MappingItem(EntityAttributeModel, name, GetString("sf.metasource.state"), MappingItemSourceTypeEnum.MetaField));
                }
            }
            else if (name.StartsWithCSafe("PicklistEntry-"))
            {
                name = name.Remove(0, "PicklistEntry-".Length);
                PicklistEntry entry = EntityAttributeModel.PicklistEntries.SingleOrDefault(x => x.IsActive && x.Value == name);
                if (entry != null)
                {
                    return(new MappingItem(EntityAttributeModel, name, entry.Label, MappingItemSourceTypeEnum.PicklistEntry));
                }
            }
        }

        return(null);
    }
 private void LoadProperty(FormFieldInfo ffi, FormFieldPropertyEnum property, FormEngineUserControl control, MessagesPlaceHolder msgPlaceHolder)
 {
     if (control != null)
     {
         bool isMacro = ffi.IsMacro(property);
         control.Visible = !isMacro;
         if (!isMacro)
         {
             control.Value = ffi.GetPropertyValue(property);
         }
         else
         {
             msgPlaceHolder.ShowInformation(GetString("FormBuilder.PropertyIsMacro"));
         }
     }
 }
Exemple #28
0
    /// <summary>
    /// Generate properties.
    /// </summary>
    protected void GenerateProperties(FormInfo fi)
    {
        ltlProperties.Text = String.Empty;

        // Generate script to display and hide  properties groups
        ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "ShowHideProperties", ScriptHelper.GetScript(@"
            function ShowHideProperties(id) {
                var obj = document.getElementById(id);
                var objlink = document.getElementById(id+'_link');
                if ((obj != null)&&(objlink != null)){
                   if (obj.style.display == 'none' ) { obj.style.display=''; objlink.innerHTML = '<img border=""0"" src=""" + minImg + @""" >'; } 
                   else {obj.style.display='none'; objlink.innerHTML = '<img border=""0"" src=""" + plImg + @""" >';}
                objlink.blur();}}"));

        // Get defintion elements
        var infos = fi.GetFormElements(true, false);

        bool isOpenSubTable   = false;
        bool firstLoad        = true;
        bool hasAnyProperties = false;

        string currentGuid = "";
        string newCategory = null;

        // Check all items in object array
        foreach (IField contrl in infos)
        {
            // Generate row for form category
            if (contrl is FormCategoryInfo)
            {
                // Load castegory info
                FormCategoryInfo fci = contrl as FormCategoryInfo;
                if (fci != null)
                {
                    if (isOpenSubTable)
                    {
                        ltlProperties.Text += "<tr class=\"PropertyBottom\"><td class=\"PropertyLeftBottom\">&nbsp;</td><td colspan=\"2\" class=\"Center\">&nbsp;</td><td class=\"PropertyRightBottom\">&nbsp;</td></tr></table>";
                        isOpenSubTable      = false;
                    }

                    if (currentGuid == "")
                    {
                        currentGuid = Guid.NewGuid().ToString().Replace("-", "_");
                    }

                    // Generate properties content
                    newCategory = @"<br />
                        <table cellpadding=""0"" cellspacing=""0"" class=""CategoryTable"">
                          <tr>
                            <td class=""CategoryLeftBorder"">&nbsp;</td>
                            <td class=""CategoryTextCell"">" + HTMLHelper.HTMLEncode(ResHelper.LocalizeString(fci.GetPropertyValue(FormCategoryPropertyEnum.Caption, MacroContext.CurrentResolver))) + @"</td>
                            <td class=""HiderCell"">
                              <a id=""" + currentGuid + "_link\" href=\"#\" onclick=\"ShowHideProperties('" + currentGuid + @"'); return false;"">
                              <img border=""0"" src=""" + minImg + @""" ></a>
                            </td>
                           <td class=""CategoryRightBorder"">&nbsp;</td>
                         </tr>
                       </table>";
                }
            }
            else
            {
                hasAnyProperties = true;
                // Get form field info
                FormFieldInfo ffi = contrl as FormFieldInfo;

                if (ffi != null)
                {
                    // If display only in dashboard and not dashbord zone (or none for admins) dont show
                    if ((ffi.DisplayIn == "dashboard") && ((zoneType != WidgetZoneTypeEnum.Dashboard) && (zoneType != WidgetZoneTypeEnum.None)))
                    {
                        continue;
                    }
                    if (newCategory != null)
                    {
                        ltlProperties.Text += newCategory;
                        newCategory         = null;

                        firstLoad = false;
                    }
                    else if (firstLoad)
                    {
                        if (currentGuid == "")
                        {
                            currentGuid = Guid.NewGuid().ToString().Replace("-", "_");
                        }

                        // Generate properties content
                        firstLoad           = false;
                        ltlProperties.Text += @"<br />
                        <table cellpadding=""0"" cellspacing=""0"" class=""CategoryTable"">
                          <tr>
                            <td class=""CategoryLeftBorder"">&nbsp;</td>
                            <td class=""CategoryTextCell"">Default</td>
                            <td class=""HiderCell"">
                               <a id=""" + currentGuid + "_link\" href=\"#\" onclick=\"ShowHideProperties('" + currentGuid + @"'); return false;"">
                               <img border=""0"" src=""" + minImg + @""" ></a>
                            </td>
                            <td class=""CategoryRightBorder"">&nbsp;</td>
                         </tr>
                       </table>";
                    }

                    if (!isOpenSubTable)
                    {
                        isOpenSubTable      = true;
                        ltlProperties.Text += "" +
                                              "<table cellpadding=\"0\" cellspacing=\"0\" id=\"" + currentGuid + "\" class=\"PropertiesTable\" >";
                        currentGuid = "";
                    }

                    string doubleDot = "";
                    if (!ffi.GetPropertyValue(FormFieldPropertyEnum.FieldCaption, MacroContext.CurrentResolver).EndsWithCSafe(":"))
                    {
                        doubleDot = ":";
                    }

                    string fieldDescription = ResHelper.LocalizeString(ffi.GetPropertyValue(FormFieldPropertyEnum.FieldDescription, MacroContext.CurrentResolver));

                    ltlProperties.Text +=
                        @"<tr>
                            <td class=""PropertyLeftBorder"" >&nbsp;</td>
                            <td class=""PropertyContent"" style=""width:200px;"">" + HTMLHelper.HTMLEncode(ResHelper.LocalizeString(ffi.GetPropertyValue(FormFieldPropertyEnum.FieldCaption, MacroContext.CurrentResolver))) + doubleDot + @"</td>
                            <td class=""PropertyRow"">" + HTMLHelper.HTMLEncode(DataHelper.GetNotEmpty(fieldDescription, GetString("WebPartDocumentation.DescriptionNoneAvailable"))) + @"</td>
                            <td class=""PropertyRightBorder"">&nbsp;</td>
                        </tr>";
                }
            }
        }

        if (isOpenSubTable)
        {
            ltlProperties.Text += "<tr class=\"PropertyBottom\"><td class=\"PropertyLeftBottom\">&nbsp;</td><td colspan=\"2\" class=\"Center\">&nbsp;</td><td class=\"PropertyRightBottom\">&nbsp;</td></tr></table>";
        }

        if (!hasAnyProperties)
        {
            ltlProperties.Text = "<br /><div style=\"padding-left:5px;padding-right:5px; font-weight: bold;\">" + GetString("documentation.nopropertiesavaible") + "</div>";
        }
    }
Exemple #29
0
    /// <summary>
    /// Loads field with values from FormFieldInfo.
    /// </summary>
    public void Reload()
    {
        if (ffi != null)
        {
            bool isMacro;
            txtDescription.SetValue(ffi.GetPropertyValue(FormFieldPropertyEnum.FieldDescription, out isMacro), isMacro);
            txtFieldCaption.SetValue(ffi.GetPropertyValue(FormFieldPropertyEnum.FieldCaption, out isMacro), isMacro);
            txtExplanationText.SetValue(ffi.GetPropertyValue(FormFieldPropertyEnum.ExplanationText, out isMacro), isMacro);

            if (ShowInheritanceSettings)
            {
                chkControlInheritable.Checked = ffi.Inheritable;
            }

            // Field visibility
            if (ShowFieldVisibility)
            {
                chkChangeVisibility.Checked = ffi.AllowUserToChangeVisibility;
                Visibility = ffi.Visibility;

                // Load controls for user visibility
                drpVisibilityControl.DataSource = FormUserControlInfoProvider.GetFormUserControls("UserControlCodeName, UserControlDisplayName", "UserControlForVisibility = 1", "UserControlDisplayName");
                drpVisibilityControl.DataBind();

                try
                {
                    drpVisibilityControl.Items.FindByValue(ffi.VisibilityControl);
                    drpVisibilityControl.SelectedValue = ffi.VisibilityControl;
                }
                catch
                {
                }
            }

            plcVisibility.Visible = ShowFieldVisibility;

            if ((Mode == FieldEditorModeEnum.BizFormDefinition) || (Mode == FieldEditorModeEnum.AlternativeBizFormDefinition))
            {
                chkPublicField.Checked = ffi.PublicField;
            }

            string selectedItem;
            // Get control name from settings
            if (!String.IsNullOrEmpty(Convert.ToString(ffi.Settings["controlname"])))
            {
                selectedItem = Convert.ToString(ffi.Settings["controlname"]);
            }
            // Or get control name from field type
            else
            {
                selectedItem = FormHelper.GetFormFieldControlTypeString(ffi.FieldType);
            }

            FormUserControlInfo fi = FormUserControlInfoProvider.GetFormUserControlInfo(selectedItem);

            if (fi != null)
            {
                // Preselect options for specific control
                FieldType = selectedItem;
            }
            else
            {
                // Preselect default control for attribute type
                FieldType = FormHelper.GetFormFieldDefaultControlType(AttributeType);
            }

            LoadFieldTypes(ffi.PrimaryKey);
        }
        // If FormFieldInfo is not specified then clear form
        else
        {
            chkPublicField.Checked = true;
            ctrlVisibility.Value   = null;
            drpVisibilityControl.ClearSelection();
            chkChangeVisibility.Checked = false;
            txtFieldCaption.SetValue(null, false);
            txtDescription.SetValue(null, false);
            txtExplanationText.SetValue(null, false);
            drpControl.Reload(false);
            drpControl.Value = FormHelper.GetFormFieldDefaultControlType(AttributeType);
        }
    }
 /// <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;
 }
Exemple #31
0
    /// <summary>
    /// Generate document content.
    /// </summary>
    /// <param name="wpi">WebPart info</param>
    /// <param name="gd">Guid</param>
    /// <param name="category">Category</param>
    protected void GenerateDocContent(FormInfo fi)
    {
        if (fi == null)
        {
            return;
        }
        // Get defintion elements
        var infos = fi.GetFormElements(true, false);

        bool isOpenSubTable = false;

        string currentGuid = "";

        // Used for filter empty categories
        String categoryHeader = String.Empty;

        // Check all items in object array
        foreach (object contrl in infos)
        {
            // Generate row for form category
            if (contrl is FormCategoryInfo)
            {
                // Load castegory info
                FormCategoryInfo fci = contrl as FormCategoryInfo;
                if (fci != null)
                {
                    // Close table from last category
                    if (isOpenSubTable)
                    {
                        content       += "<tr class=\"PropertyBottom\"><td class=\"PropertyLeftBottom\">&nbsp;</td><td colspan=\"2\" class=\"Center\">&nbsp;</td><td class=\"PropertyRightBottom\">&nbsp;</td></tr></table>";
                        isOpenSubTable = false;
                    }

                    if (currentGuid == "")
                    {
                        currentGuid = Guid.NewGuid().ToString().Replace("-", "_");
                    }

                    // Generate table for current category
                    categoryHeader = @"<br />
                        <table cellpadding=""0"" cellspacing=""0"" class=""CategoryTable"">
                          <tr>
                           <td class=""CategoryLeftBorder"">&nbsp;</td>
                           <td class=""CategoryTextCell"">" + HTMLHelper.HTMLEncode(ResHelper.LocalizeString(fci.CategoryName)) + @"</td>
                           <td class=""CategoryRightBorder"">&nbsp;</td>
                         </tr>
                       </table>";
                }
            }
            else
            {
                // Get form field info
                FormFieldInfo ffi = contrl as FormFieldInfo;

                if (ffi != null)
                {
                    if (categoryHeader != String.Empty)
                    {
                        content       += categoryHeader;
                        categoryHeader = String.Empty;
                    }

                    if (!isOpenSubTable)
                    {
                        // Generate table for properties under one category
                        isOpenSubTable = true;
                        content       += "" +
                                         "<table cellpadding=\"0\" cellspacing=\"0\" id=\"_" + currentGuid + "\" class=\"PropertiesTable\" >";
                        currentGuid = "";
                    }

                    // Add ':' to caption
                    string doubleDot = "";
                    if (!ffi.GetPropertyValue(FormFieldPropertyEnum.FieldCaption, MacroContext.CurrentResolver).EndsWithCSafe(":"))
                    {
                        doubleDot = ":";
                    }

                    string fieldDescription = ffi.GetPropertyValue(FormFieldPropertyEnum.FieldDescription, resolver);

                    content +=
                        @"<tr>
                            <td class=""PropertyLeftBorder"" >&nbsp;</td>
                            <td class=""PropertyContent"" style=""width:200px;"">" + HTMLHelper.HTMLEncode(ResHelper.LocalizeString(ffi.GetPropertyValue(FormFieldPropertyEnum.FieldCaption, MacroContext.CurrentResolver))) + doubleDot + @"</td>
                            <td class=""PropertyRow"">" + HTMLHelper.HTMLEncode(DataHelper.GetNotEmpty(ResHelper.LocalizeString(fieldDescription), GetString("WebPartDocumentation.DescriptionNoneAvailable"))) + @"</td>
                            <td class=""PropertyRightBorder"">&nbsp;</td>
                        </tr>";

                    if (fieldDescription == null || fieldDescription.Trim() == "")
                    {
                        undocumentedProperties++;
                    }
                }
            }
        }

        // Close last category (if has any properties)
        if (isOpenSubTable)
        {
            content += "<tr class=\"PropertyBottom\"><td class=\"PropertyLeftBottom\">&nbsp;</td><td colspan=\"2\" class=\"Center\">&nbsp;</td><td class=\"PropertyRightBottom\">&nbsp;</td></tr></table>";
        }
    }