/// <Summary>
        /// CreateEditControl creates the appropriate Control based on the EditorField or
        /// TypeDataField
        /// </Summary>
        /// <Param name="editorInfo">An EditorInfo object</Param>
        public static EditControl CreateEditControl( EditorInfo editorInfo )
        {
            EditControl propEditor;

            if (editorInfo.Editor == "UseSystemType")
            {
                Type type = Type.GetType(editorInfo.Type);
                //Use System Type

                switch (type.FullName)
                {
                    case "System.Boolean":

                        propEditor = new CheckEditControl();
                        break;
                    case "System.Int32":
                        propEditor = new IntegerEditControl();
                        break;

                    case "System.Int16":

                        propEditor = new IntegerEditControl();
                        break;
                    default:

                        if (type.IsEnum)
                        {
                            propEditor = new EnumEditControl(editorInfo.Type);
                        }
                        else
                        {
                            propEditor = new TextEditControl(editorInfo.Type);
                        }
                        break;
                }
            }
            else
            {
                //Use Editor
                Type editType = Type.GetType(editorInfo.Editor, true, true);
                propEditor = (EditControl)Activator.CreateInstance(editType, null);
            }

            propEditor.ID = editorInfo.Name;
            propEditor.Name = editorInfo.Name;

            propEditor.EditMode = editorInfo.EditMode;
            propEditor.Required = editorInfo.Required;

            propEditor.Value = editorInfo.Value;
            propEditor.OldValue = editorInfo.Value;

            propEditor.CustomAttributes = editorInfo.Attributes;

            return propEditor;
        }
示例#2
0
        /// <Summary>Constructs a new SettingInfo obect</Summary>
        /// <Param name="name">The name of the setting</Param>
        /// <Param name="value">The value of the setting</Param>
        public SettingInfo(object name, object value)
        {
            _Name   = Convert.ToString(name);
            _Value  = value;
            _Type   = value.GetType();
            _Editor = EditorInfo.GetEditor(-1);

            string strValue = Convert.ToString(value);
            bool   IsFound  = false;

            if (_Type.IsEnum)
            {
                IsFound = true;
            }

            if (!IsFound)
            {
                try
                {
                    bool boolValue = bool.Parse(strValue);
                    Editor  = EditorInfo.GetEditor("TrueFalse");
                    IsFound = true;
                }
                catch (Exception)
                {
                }
            }
            if (!IsFound)
            {
                try
                {
                    int intValue = int.Parse(strValue);
                    Editor  = EditorInfo.GetEditor("Integer");
                    IsFound = true;
                }
                catch (Exception)
                {
                }
            }
        }
示例#3
0
        /// <summary>
        /// BuildLabel creates the label part of the Control
        /// </summary>
        /// <param name="editInfo">The EditorInfo object for this control</param>
        private PropertyLabelControl BuildLabel(EditorInfo editInfo)
        {
            var propLabel = new PropertyLabelControl {
                ID = editInfo.Name + "_Label"
            };

            propLabel.HelpStyle.CopyFrom(HelpStyle);
            propLabel.LabelStyle.CopyFrom(LabelStyle);
            var strValue = editInfo.Value as string;

            switch (HelpDisplayMode)
            {
            case HelpDisplayMode.Always:
                propLabel.ShowHelp = true;
                break;

            case HelpDisplayMode.EditOnly:
                if (editInfo.EditMode == PropertyEditorMode.Edit || (editInfo.Required && string.IsNullOrEmpty(strValue)))
                {
                    propLabel.ShowHelp = true;
                }
                else
                {
                    propLabel.ShowHelp = false;
                }
                break;

            case HelpDisplayMode.Never:
                propLabel.ShowHelp = false;
                break;
            }
            propLabel.Caption     = editInfo.Name;
            propLabel.HelpText    = editInfo.Name;
            propLabel.ResourceKey = editInfo.ResourceKey;
            if (editInfo.LabelMode == LabelMode.Left || editInfo.LabelMode == LabelMode.Right)
            {
                propLabel.Width = LabelWidth;
            }
            return(propLabel);
        }
示例#4
0
        public SettingInfo(object name, object value)
        {
            Name   = Convert.ToString(name);
            Value  = value;
            _Type  = value.GetType();
            Editor = EditorInfo.GetEditor(-1);
            string strValue = Convert.ToString(value);
            bool   IsFound  = false;

            if (_Type.IsEnum)
            {
                IsFound = true;
            }
            if (!IsFound)
            {
                try
                {
                    bool boolValue = bool.Parse(strValue);
                    Editor  = EditorInfo.GetEditor("Checkbox");
                    IsFound = true;
                }
                catch (Exception exc)
                {
                    DnnLog.Error(exc);
                }
            }
            if (!IsFound)
            {
                try
                {
                    int intValue = int.Parse(strValue);
                    Editor  = EditorInfo.GetEditor("Integer");
                    IsFound = true;
                }
                catch (Exception exc)
                {
                    DnnLog.Error(exc);
                }
            }
        }
示例#5
0
        /// <summary>
        /// BuildValidators creates the validators part of the Control.
        /// </summary>
        /// <param name="editInfo">The EditorInfo object for this control.</param>
        private Image BuildRequiredIcon(EditorInfo editInfo)
        {
            Image img      = null;
            var   strValue = editInfo.Value as string;

            if (this.ShowRequired && editInfo.Required && (editInfo.EditMode == PropertyEditorMode.Edit || (editInfo.Required && string.IsNullOrEmpty(strValue))))
            {
                img = new Image();
                if (string.IsNullOrEmpty(this.RequiredUrl) || this.RequiredUrl == Null.NullString)
                {
                    img.ImageUrl = "~/images/required.gif";
                }
                else
                {
                    img.ImageUrl = this.RequiredUrl;
                }

                img.Attributes.Add("resourcekey", editInfo.ResourceKey + ".Required");
            }

            return(img);
        }
示例#6
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// CreateEditControl creates the appropriate Control based on the EditorField or
        /// TypeDataField.
        /// </summary>
        /// <param name="editorInfo">An EditorInfo object.</param>
        /// <returns></returns>
        /// -----------------------------------------------------------------------------
        public static EditControl CreateEditControl(EditorInfo editorInfo)
        {
            EditControl propEditor;

            if (editorInfo.Editor == "UseSystemType")
            {
                // Use System Type
                propEditor = CreateEditControlInternal(editorInfo.Type);
            }
            else
            {
                // Use Editor
                try
                {
                    Type editType = Type.GetType(editorInfo.Editor, true, true);
                    propEditor = (EditControl)Activator.CreateInstance(editType);
                }
                catch (TypeLoadException)
                {
                    // Use System Type
                    propEditor = CreateEditControlInternal(editorInfo.Type);
                }
            }

            propEditor.ID        = editorInfo.Name;
            propEditor.Name      = editorInfo.Name;
            propEditor.DataField = editorInfo.Name;
            propEditor.Category  = editorInfo.Category;

            propEditor.EditMode = editorInfo.EditMode;
            propEditor.Required = editorInfo.Required;

            propEditor.Value    = editorInfo.Value;
            propEditor.OldValue = editorInfo.Value;

            propEditor.CustomAttributes = editorInfo.Attributes;

            return(propEditor);
        }
示例#7
0
        /// <summary>
        /// BuildEditor creates the editor part of the Control
        /// </summary>
        /// <param name="editInfo">The EditorInfo object for this control</param>
        /// <history>
        ///     [cnurse]	05/08/2006	created
        /// </history>
        private EditControl BuildEditor(EditorInfo editInfo)
        {
            EditControl propEditor = EditControlFactory.CreateEditControl(editInfo);

            propEditor.ControlStyle.CopyFrom(EditControlStyle);
            propEditor.LocalResourceFile = LocalResourceFile;
            propEditor.User = User;
            if (editInfo.ControlStyle != null)
            {
                propEditor.ControlStyle.CopyFrom(editInfo.ControlStyle);
            }
            propEditor.ItemAdded    += CollectionItemAdded;
            propEditor.ItemDeleted  += CollectionItemDeleted;
            propEditor.ValueChanged += ValueChanged;
            if (propEditor is DNNListEditControl)
            {
                var listEditor = (DNNListEditControl)propEditor;
                listEditor.ItemChanged += ListItemChanged;
            }
            Editor = propEditor;

            return(propEditor);
        }
示例#8
0
        public virtual EditorInfo CreateEditControl()
        {
            SettingInfo info     = (SettingInfo)DataMember;
            EditorInfo  editInfo = new EditorInfo();

            //Get the Name of the property
            editInfo.Name = info.Name;

            //Get the Category
            editInfo.Category = string.Empty;

            //Get Value Field
            editInfo.Value = info.Value;

            //Get the type of the property
            editInfo.Type = info.Type.AssemblyQualifiedName;

            //Get Editor Field
            editInfo.Editor = info.Editor;

            //Get LabelMode Field
            editInfo.LabelMode = LabelMode.Left;

            //Get Required Field
            editInfo.Required = false;

            //Set ResourceKey Field
            editInfo.ResourceKey = editInfo.Name;

            //Get Style
            editInfo.ControlStyle = new Style();

            //Get Validation Expression Field
            editInfo.ValidationExpression = string.Empty;

            return(editInfo);
        }
        public EditorInfo CreateEditControl()
        {

            var info = (SettingInfo) DataMember;
            var editInfo = new EditorInfo();

            //Get the Name of the property
            editInfo.Name = info.Name;

			editInfo.Category = string.Empty;

            //Get Value Field
            editInfo.Value = info.Value;

            //Get the type of the property
            editInfo.Type = info.Type.AssemblyQualifiedName;

            //Get Editor Field
            editInfo.Editor = info.Editor;

            //Get LabelMode Field
            editInfo.LabelMode = LabelMode.Left;

            //Get Required Field
            editInfo.Required = false;

            //Set ResourceKey Field
            editInfo.ResourceKey = editInfo.Name;

            //Get Style
            editInfo.ControlStyle = new Style();

            //Get Validation Expression Field
            editInfo.ValidationExpression = string.Empty;

            return editInfo;
        }
示例#10
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// GetEditorInfo builds an EditorInfo object for a propoerty
        /// </summary>
        /// <history>
        ///     [cnurse]	05/05/2006	Created
        /// </history>
        /// -----------------------------------------------------------------------------
        private EditorInfo GetEditorInfo()
        {
            string CategoryDataField             = Convert.ToString(FieldNames["Category"]);
            string EditorDataField               = Convert.ToString(FieldNames["Editor"]);
            string NameDataField                 = Convert.ToString(FieldNames["Name"]);
            string RequiredDataField             = Convert.ToString(FieldNames["Required"]);
            string TypeDataField                 = Convert.ToString(FieldNames["Type"]);
            string ValidationExpressionDataField = Convert.ToString(FieldNames["ValidationExpression"]);
            string ValueDataField                = Convert.ToString(FieldNames["Value"]);
            string VisibilityDataField           = Convert.ToString(FieldNames["ProfileVisibility"]);
            string MaxLengthDataField            = Convert.ToString(FieldNames["Length"]);

            var          editInfo = new EditorInfo();
            PropertyInfo property;

            //Get the Name of the property
            editInfo.Name = string.Empty;
            if (!String.IsNullOrEmpty(NameDataField))
            {
                property = DataSource.GetType().GetProperty(NameDataField);
                if (!(property == null || (property.GetValue(DataSource, null) == null)))
                {
                    editInfo.Name = Convert.ToString(property.GetValue(DataSource, null));
                }
            }

            //Get the Category of the property
            editInfo.Category = string.Empty;

            //Get Category Field
            if (!String.IsNullOrEmpty(CategoryDataField))
            {
                property = DataSource.GetType().GetProperty(CategoryDataField);
                if (!(property == null || (property.GetValue(DataSource, null) == null)))
                {
                    editInfo.Category = Convert.ToString(property.GetValue(DataSource, null));
                }
            }

            //Get Value Field
            editInfo.Value = string.Empty;
            if (!String.IsNullOrEmpty(ValueDataField))
            {
                property = DataSource.GetType().GetProperty(ValueDataField);
                if (!(property == null || (property.GetValue(DataSource, null) == null)))
                {
                    editInfo.Value = Convert.ToString(property.GetValue(DataSource, null));
                }
            }

            //Get the type of the property
            editInfo.Type = "System.String";
            if (!String.IsNullOrEmpty(TypeDataField))
            {
                property = DataSource.GetType().GetProperty(TypeDataField);
                if (!(property == null || (property.GetValue(DataSource, null) == null)))
                {
                    editInfo.Type = Convert.ToString(property.GetValue(DataSource, null));
                }
            }

            //Get Editor Field
            editInfo.Editor = "DotNetNuke.UI.WebControls.TextEditControl, DotNetNuke";
            if (!String.IsNullOrEmpty(EditorDataField))
            {
                property = DataSource.GetType().GetProperty(EditorDataField);
                if (!(property == null || (property.GetValue(DataSource, null) == null)))
                {
                    editInfo.Editor = EditorInfo.GetEditor(Convert.ToInt32(property.GetValue(DataSource, null)));
                }
            }

            //Get LabelMode Field
            editInfo.LabelMode = LabelMode.Left;

            //Get Required Field
            editInfo.Required = false;
            if (!String.IsNullOrEmpty(RequiredDataField))
            {
                property = DataSource.GetType().GetProperty(RequiredDataField);
                if (!((property == null) || (property.GetValue(DataSource, null) == null)))
                {
                    editInfo.Required = Convert.ToBoolean(property.GetValue(DataSource, null));
                }
            }

            //Set ResourceKey Field
            editInfo.ResourceKey = editInfo.Name;
            editInfo.ResourceKey = string.Format("{0}_{1}", Name, editInfo.Name);

            //Set Style
            editInfo.ControlStyle = new Style();

            //Get Visibility Field
            editInfo.ProfileVisibility = new ProfileVisibility
            {
                VisibilityMode = UserVisibilityMode.AllUsers
            };
            if (!String.IsNullOrEmpty(VisibilityDataField))
            {
                property = DataSource.GetType().GetProperty(VisibilityDataField);
                if (!(property == null || (property.GetValue(DataSource, null) == null)))
                {
                    editInfo.ProfileVisibility = (ProfileVisibility)property.GetValue(DataSource, null);
                }
            }

            //Get Validation Expression Field
            editInfo.ValidationExpression = string.Empty;
            if (!String.IsNullOrEmpty(ValidationExpressionDataField))
            {
                property = DataSource.GetType().GetProperty(ValidationExpressionDataField);
                if (!(property == null || (property.GetValue(DataSource, null) == null)))
                {
                    editInfo.ValidationExpression = Convert.ToString(property.GetValue(DataSource, null));
                }
            }

            //Get Length Field
            if (!String.IsNullOrEmpty(MaxLengthDataField))
            {
                property = DataSource.GetType().GetProperty(MaxLengthDataField);
                if (!(property == null || (property.GetValue(DataSource, null) == null)))
                {
                    int length     = Convert.ToInt32(property.GetValue(DataSource, null));
                    var attributes = new object[1];
                    attributes[0]       = new MaxLengthAttribute(length);
                    editInfo.Attributes = attributes;
                }
            }

            //Remove spaces from name
            editInfo.Name = editInfo.Name.Replace(" ", "_");
            return(editInfo);
        }
        /// <Summary>GetEditorInfo builds an EditorInfo object for a propoerty</Summary>
        private EditorInfo GetEditorInfo()
        {
            string CategoryDataField = Convert.ToString(FieldNames["Category"]);
            string EditorDataField = Convert.ToString(FieldNames["Editor"]);
            string NameDataField = Convert.ToString(FieldNames["Name"]);
            string RequiredDataField = Convert.ToString(FieldNames["Required"]);
            string TypeDataField = Convert.ToString(FieldNames["Type"]);
            string ValidationExpressionDataField = Convert.ToString(FieldNames["ValidationExpression"]);
            string ValueDataField = Convert.ToString(FieldNames["Value"]);
            string VisibilityDataField = Convert.ToString(FieldNames["Visibility"]);

            EditorInfo editInfo = new EditorInfo();
            PropertyInfo objProperty;

            //Get the Name of the property
            editInfo.Name = string.Empty;
            //Get Name Field
            if (!String.IsNullOrEmpty(NameDataField))
            {
                objProperty = DataSource.GetType().GetProperty(NameDataField);
                if (!((objProperty == null) || (objProperty.GetValue(DataSource, null) == null)))
                {
                    editInfo.Name = Convert.ToString(objProperty.GetValue(DataSource, null));
                }
            }

            //Get the Category of the property
            editInfo.Category = string.Empty;
            //Get Category Field
            if (!String.IsNullOrEmpty(CategoryDataField))
            {
                objProperty = DataSource.GetType().GetProperty(CategoryDataField);
                if (!((objProperty == null) || (objProperty.GetValue(DataSource, null) == null)))
                {
                    editInfo.Category = Convert.ToString(objProperty.GetValue(DataSource, null));
                }
            }

            //Get Value Field
            editInfo.Value = string.Empty;
            if (!String.IsNullOrEmpty(ValueDataField))
            {
                objProperty = DataSource.GetType().GetProperty(ValueDataField);
                if (!((objProperty == null) || (objProperty.GetValue(DataSource, null) == null)))
                {
                    editInfo.Value = Convert.ToString(objProperty.GetValue(DataSource, null));
                }
            }

            //Get the type of the property
            editInfo.Type = "System.String";
            if (!String.IsNullOrEmpty(TypeDataField))
            {
                objProperty = DataSource.GetType().GetProperty(TypeDataField);
                if (!((objProperty == null) || (objProperty.GetValue(DataSource, null) == null)))
                {
                    editInfo.Type = Convert.ToString(objProperty.GetValue(DataSource, null));
                }
            }

            //Get Editor Field
            editInfo.Editor = "DotNetNuke.UI.WebControls.TextEditControl, DotNetNuke";
            if (!String.IsNullOrEmpty(EditorDataField))
            {
                objProperty = DataSource.GetType().GetProperty(EditorDataField);
                if (!((objProperty == null) || (objProperty.GetValue(DataSource, null) == null)))
                {
                    editInfo.Editor = EditorInfo.GetEditor(Convert.ToInt32(objProperty.GetValue(DataSource, null)));
                }
            }

            //Get LabelMode Field
            editInfo.LabelMode = LabelMode.Left;

            //Get Required Field
            editInfo.Required = false;
            if (!String.IsNullOrEmpty(RequiredDataField))
            {
                objProperty = DataSource.GetType().GetProperty(RequiredDataField);
                if (!((objProperty == null) || (objProperty.GetValue(DataSource, null) == null)))
                {
                    editInfo.Required = Convert.ToBoolean(objProperty.GetValue(DataSource, null));
                }
            }

            //Set ResourceKey Field
            editInfo.ResourceKey = editInfo.Name;
            editInfo.ResourceKey = string.Format("{0}_{1}", Name, editInfo.Name);

            //Get Style
            editInfo.ControlStyle = new Style();

            //Get Visibility Field
            editInfo.Visibility = UserVisibilityMode.AllUsers;
            if (!String.IsNullOrEmpty(VisibilityDataField))
            {
                objProperty = DataSource.GetType().GetProperty(VisibilityDataField);
                if (!((objProperty == null) || (objProperty.GetValue(DataSource, null) == null)))
                {
                    editInfo.Visibility = (UserVisibilityMode)objProperty.GetValue(DataSource, null);
                }
            }

            //Get Validation Expression Field
            editInfo.ValidationExpression = string.Empty;
            if (!String.IsNullOrEmpty(ValidationExpressionDataField))
            {
                objProperty = DataSource.GetType().GetProperty(ValidationExpressionDataField);
                if (!((objProperty == null) || (objProperty.GetValue(DataSource, null) == null)))
                {
                    editInfo.ValidationExpression = Convert.ToString(objProperty.GetValue(DataSource, null));
                }
            }

            return editInfo;
        }
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// GetEditorInfo builds an EditorInfo object for a propoerty
        /// </summary>
        /// <history>
        /// 	[cnurse]	05/05/2006	Created
        /// </history>
        /// -----------------------------------------------------------------------------
        private EditorInfo GetEditorInfo(object dataSource, PropertyInfo objProperty)
        {
            var editInfo = new EditorInfo();

            //Get the Name of the property
            editInfo.Name = objProperty.Name;

            //Get the value of the property
            editInfo.Value = objProperty.GetValue(dataSource, null);

            //Get the type of the property
            editInfo.Type = objProperty.PropertyType.AssemblyQualifiedName;

            //Get the Custom Attributes for the property
            editInfo.Attributes = objProperty.GetCustomAttributes(true);

            //Get Category Field
            editInfo.Category = string.Empty;
            object[] categoryAttributes = objProperty.GetCustomAttributes(typeof (CategoryAttribute), true);
            if (categoryAttributes.Length > 0)
            {
                var category = (CategoryAttribute) categoryAttributes[0];
                editInfo.Category = category.Category;
            }
			
            //Get EditMode Field

            if (!objProperty.CanWrite)
            {
                editInfo.EditMode = PropertyEditorMode.View;
            }
            else
            {
                object[] readOnlyAttributes = objProperty.GetCustomAttributes(typeof (IsReadOnlyAttribute), true);
                if (readOnlyAttributes.Length > 0)
                {
                    var readOnlyMode = (IsReadOnlyAttribute) readOnlyAttributes[0];
                    if (readOnlyMode.IsReadOnly)
                    {
                        editInfo.EditMode = PropertyEditorMode.View;
                    }
                }
            }
			
            //Get Editor Field
            editInfo.Editor = "UseSystemType";
            object[] editorAttributes = objProperty.GetCustomAttributes(typeof (EditorAttribute), true);
            if (editorAttributes.Length > 0)
            {
                EditorAttribute editor = null;
                for (int i = 0; i <= editorAttributes.Length - 1; i++)
                {
                    if (((EditorAttribute) editorAttributes[i]).EditorBaseTypeName.IndexOf("DotNetNuke.UI.WebControls.EditControl") >= 0)
                    {
                        editor = (EditorAttribute) editorAttributes[i];
                        break;
                    }
                }
                if (editor != null)
                {
                    editInfo.Editor = editor.EditorTypeName;
                }
            }
			
            //Get Required Field
            editInfo.Required = false;
            object[] requiredAttributes = objProperty.GetCustomAttributes(typeof (RequiredAttribute), true);
            if (requiredAttributes.Length > 0)
            {
                //The property may contain multiple edit mode types, so make sure we only use DotNetNuke editors.
                var required = (RequiredAttribute) requiredAttributes[0];
                if (required.Required)
                {
                    editInfo.Required = true;
                }
            }
			
            //Get Css Style
            editInfo.ControlStyle = new Style();
            object[] StyleAttributes = objProperty.GetCustomAttributes(typeof (ControlStyleAttribute), true);
            if (StyleAttributes.Length > 0)
            {
                var attribute = (ControlStyleAttribute) StyleAttributes[0];
                editInfo.ControlStyle.CssClass = attribute.CssClass;
                editInfo.ControlStyle.Height = attribute.Height;
                editInfo.ControlStyle.Width = attribute.Width;
            }
			
            //Get LabelMode Field
            editInfo.LabelMode = LabelMode.Left;
            object[] labelModeAttributes = objProperty.GetCustomAttributes(typeof (LabelModeAttribute), true);
            if (labelModeAttributes.Length > 0)
            {
                var mode = (LabelModeAttribute) labelModeAttributes[0];
                editInfo.LabelMode = mode.Mode;
            }
			
            //Set ResourceKey Field
            editInfo.ResourceKey = string.Format("{0}_{1}", dataSource.GetType().Name, objProperty.Name);

            //Get Validation Expression Field
            editInfo.ValidationExpression = string.Empty;
            object[] regExAttributes = objProperty.GetCustomAttributes(typeof (RegularExpressionValidatorAttribute), true);
            if (regExAttributes.Length > 0)
            {
                var regExAttribute = (RegularExpressionValidatorAttribute) regExAttributes[0];
                editInfo.ValidationExpression = regExAttribute.Expression;
            }
			
            //Set Visibility
            editInfo.ProfileVisibility = new ProfileVisibility
                                             {
                                                 VisibilityMode = UserVisibilityMode.AllUsers
                                             };

            return editInfo;
        }
		/// <summary>
		/// BuildVisibility creates the visibility part of the Control
		/// </summary>
		/// <param name="editInfo">The EditorInfo object for this control</param>
		/// <history>
		///     [cnurse]	05/08/2006	created
		/// </history>
		private VisibilityControl BuildVisibility(EditorInfo editInfo)
		{
			VisibilityControl visControl = null;

			if (ShowVisibility)
			{
			    visControl = new VisibilityControl
			                     {
			                         ID = "_visibility", 
                                     Name = editInfo.Name, 
                                     User = User, 
                                     Value = editInfo.ProfileVisibility
			                     };
			    visControl.ControlStyle.CopyFrom(VisibilityStyle);
				visControl.VisibilityChanged += VisibilityChanged;
			}
			return visControl;
		}
		/// -----------------------------------------------------------------------------
		/// <summary>
		/// BuildTable creates the Control as a Table
		/// </summary>
		/// <param name="editInfo">The EditorInfo object for this control</param>
		/// <history>
		///     [cnurse]	05/08/2006	created
		/// </history>
		/// -----------------------------------------------------------------------------
		private void BuildTable(EditorInfo editInfo)
		{
			var tbl = new Table();
			var labelCell = new TableCell();
			var editorCell = new TableCell();

			//Build Label Cell
			labelCell.VerticalAlign = VerticalAlign.Top;
			labelCell.Controls.Add(BuildLabel(editInfo));
			if (editInfo.LabelMode == LabelMode.Left || editInfo.LabelMode == LabelMode.Right)
			{
				labelCell.Width = LabelWidth;
			}
			//Build Editor Cell
			editorCell.VerticalAlign = VerticalAlign.Top;
			EditControl propEditor = BuildEditor(editInfo);
			Image requiredIcon = BuildRequiredIcon(editInfo);
			editorCell.Controls.Add(propEditor);
			if (requiredIcon != null)
			{
				editorCell.Controls.Add(requiredIcon);
			}
			if (editInfo.LabelMode == LabelMode.Left || editInfo.LabelMode == LabelMode.Right)
			{
				editorCell.Width = EditControlWidth;
			}
			VisibilityControl visibility = BuildVisibility(editInfo);
			if (visibility != null)
			{
				editorCell.Controls.Add(new LiteralControl("&nbsp;&nbsp;"));
				editorCell.Controls.Add(visibility);
			}
			
			//Add cells to table
			var editorRow = new TableRow();
			var labelRow = new TableRow();
			if (editInfo.LabelMode == LabelMode.Bottom || editInfo.LabelMode == LabelMode.Top || editInfo.LabelMode == LabelMode.None)
			{
				editorCell.ColumnSpan = 2;
				editorRow.Cells.Add(editorCell);
				if (editInfo.LabelMode == LabelMode.Bottom || editInfo.LabelMode == LabelMode.Top)
				{
					labelCell.ColumnSpan = 2;
					labelRow.Cells.Add(labelCell);
				}
				if (editInfo.LabelMode == LabelMode.Top)
				{
					tbl.Rows.Add(labelRow);
				}
				tbl.Rows.Add(editorRow);
				if (editInfo.LabelMode == LabelMode.Bottom)
				{
					tbl.Rows.Add(labelRow);
				}
			}
			else if (editInfo.LabelMode == LabelMode.Left)
			{
				editorRow.Cells.Add(labelCell);
				editorRow.Cells.Add(editorCell);
				tbl.Rows.Add(editorRow);
			}
			else if (editInfo.LabelMode == LabelMode.Right)
			{
				editorRow.Cells.Add(editorCell);
				editorRow.Cells.Add(labelCell);
				tbl.Rows.Add(editorRow);
			}
			
			//Build the Validators
			BuildValidators(editInfo, propEditor.ID);

			var validatorsRow = new TableRow();
			var validatorsCell = new TableCell();
			validatorsCell.ColumnSpan = 2;
			//Add the Validators to the editor cell
			foreach (BaseValidator validator in Validators)
			{
				validatorsCell.Controls.Add(validator);
			}
			validatorsRow.Cells.Add(validatorsCell);
			tbl.Rows.Add(validatorsRow);

			//Add the Table to the Controls Collection
			Controls.Add(tbl);
		}
		/// <summary>
		/// BuildLabel creates the label part of the Control
		/// </summary>
		/// <param name="editInfo">The EditorInfo object for this control</param>
		/// <history>
		///     [cnurse]	05/08/2006	created
		/// </history>
		private PropertyLabelControl BuildLabel(EditorInfo editInfo)
		{
			var propLabel = new PropertyLabelControl {ID = editInfo.Name + "_Label"};
		    propLabel.HelpStyle.CopyFrom(HelpStyle);
			propLabel.LabelStyle.CopyFrom(LabelStyle);
			var strValue = editInfo.Value as string;
			switch (HelpDisplayMode)
			{
				case HelpDisplayMode.Always:
					propLabel.ShowHelp = true;
					break;
				case HelpDisplayMode.EditOnly:
					if (editInfo.EditMode == PropertyEditorMode.Edit || (editInfo.Required && string.IsNullOrEmpty(strValue)))
					{
						propLabel.ShowHelp = true;
					}
					else
					{
						propLabel.ShowHelp = false;
					}
					break;
				case HelpDisplayMode.Never:
					propLabel.ShowHelp = false;
					break;
			}
			propLabel.Caption = editInfo.Name;
			propLabel.HelpText = editInfo.Name;
			propLabel.ResourceKey = editInfo.ResourceKey;
			if (editInfo.LabelMode == LabelMode.Left || editInfo.LabelMode == LabelMode.Right)
			{
				propLabel.Width = LabelWidth;
			}
			return propLabel;
		}
        /// <Summary>BuildDiv creates the Control as a Div</Summary>
        /// <Param name="editInfo">The EditorInfo object for this control</Param>
        private void BuildDiv( EditorInfo editInfo )
        {
            HtmlGenericControl divLabel = null;

            if (editInfo.LabelMode != LabelMode.None)
            {
                divLabel = new HtmlGenericControl("div");
                string style = "float: " + editInfo.LabelMode.ToString().ToLower();
                if (editInfo.LabelMode == LabelMode.Left || editInfo.LabelMode == LabelMode.Right)
                {
                    style += "; width: " + LabelWidth.ToString();
                }
                divLabel.Attributes.Add("style", style);
                divLabel.Controls.Add(BuildLabel(editInfo));
            }

            HtmlGenericControl divEdit = new HtmlGenericControl("div");
            string side = GetOppositeSide(editInfo.LabelMode);
            // HACK : Modified to not error if object is null.
            //if (side.Length > 0)
            if (!String.IsNullOrEmpty(side))
            {
                string style = "float: " + side;
                style += "; width: " + EditControlWidth.ToString();
                divEdit.Attributes.Add("style", style);
            }

            EditControl propEditor = BuildEditor(editInfo);
            VisibilityControl visibility = BuildVisibility(editInfo);
            if (visibility != null)
            {
                visibility.Attributes.Add("style", "float: right;");
                divEdit.Controls.Add(visibility);
            }
            divEdit.Controls.Add(propEditor);
            Image requiredIcon = BuildRequiredIcon(editInfo);
            divEdit.Controls.Add(propEditor);
            if (requiredIcon != null)
            {
                divEdit.Controls.Add(requiredIcon);
            }

            if (editInfo.LabelMode == LabelMode.Left || editInfo.LabelMode == LabelMode.Top)
            {
                Controls.Add(divLabel);
                Controls.Add(divEdit);
            }
            else
            {
                Controls.Add(divEdit);
                if (divLabel != null)
                {
                    Controls.Add(divLabel);
                }
            }

            //Build the Validators
            BuildValidators(editInfo, propEditor.ID);

            if (Validators.Count > 0)
            {
                //Add the Validators to the editor cell
                foreach (BaseValidator validator in Validators)
                {
                    validator.Width = this.Width;
                    Controls.Add(validator);
                }
            }
        }
        /// <Summary>
        /// BuildVisibility creates the visibility part of the Control
        /// </Summary>
        /// <Param name="editInfo">The EditorInfo object for this control</Param>
        private VisibilityControl BuildVisibility( EditorInfo editInfo )
        {
            VisibilityControl visControl = null;

            if (ShowVisibility)
            {
                visControl = new VisibilityControl();
                visControl.ID = this.ID + "_vis";
                visControl.Caption = Localization.GetString("Visibility");
                visControl.Name = editInfo.Name;
                visControl.Value = editInfo.Visibility;
                visControl.ControlStyle.CopyFrom(VisibilityStyle);
                visControl.VisibilityChanged += new PropertyChangedEventHandler(this.VisibilityChanged);
            }

            return visControl;
        }
        /// <Summary>
        /// BuildValidators creates the validators part of the Control
        /// </Summary>
        /// <Param name="editInfo">The EditorInfo object for this control</Param>
        private Image BuildRequiredIcon( EditorInfo editInfo )
        {
            Image img = null;

            string strValue = editInfo.Value as string;
            if (ShowRequired && editInfo.Required && (editInfo.EditMode == PropertyEditorMode.Edit | (editInfo.Required & string.IsNullOrEmpty(strValue))))
            {

                img = new Image();
                // HACK : Modified to catch a null or an empty value for
                // RequiredUrl.
                //if (RequiredUrl == Null.NullString)
                if (String.IsNullOrEmpty(RequiredUrl))
                {
                    img.ImageUrl = "~/images/required.gif";
                }
                else
                {
                    img.ImageUrl = RequiredUrl;
                }
                img.Attributes.Add("resourcekey", editInfo.ResourceKey + ".Required");
            }

            return img;
        }
        /// <Summary>BuildLabel creates the label part of the Control</Summary>
        /// <Param name="editInfo">The EditorInfo object for this control</Param>
        private PropertyLabelControl BuildLabel( EditorInfo editInfo )
        {
            PropertyLabelControl propLabel = new PropertyLabelControl();
            propLabel.ID = editInfo.Name + "_Label";
            propLabel.HelpStyle.CopyFrom(HelpStyle);
            propLabel.LabelStyle.CopyFrom(LabelStyle);
            string strValue = editInfo.Value as string;
            if (editInfo.EditMode == PropertyEditorMode.Edit | (editInfo.Required & string.IsNullOrEmpty(strValue)))
            {
                propLabel.ShowHelp = true;
            }
            else
            {
                propLabel.ShowHelp = false;
            }
            propLabel.Caption = editInfo.Name;
            propLabel.HelpText = editInfo.Name;
            propLabel.ResourceKey = editInfo.ResourceKey;
            if (editInfo.LabelMode == LabelMode.Left || editInfo.LabelMode == LabelMode.Right)
            {
                propLabel.Width = LabelWidth;
            }

            return propLabel;
        }
        /// <Summary>BuildEditor creates the editor part of the Control</Summary>
        /// <Param name="editInfo">The EditorInfo object for this control</Param>
        private EditControl BuildEditor( EditorInfo editInfo )
        {
            EditControl propEditor = EditControlFactory.CreateEditControl(editInfo);
            propEditor.ControlStyle.CopyFrom(EditControlStyle);
            propEditor.LocalResourceFile = LocalResourceFile;
            if (editInfo.ControlStyle != null)
            {
                propEditor.ControlStyle.CopyFrom(editInfo.ControlStyle);
            }
            propEditor.ValueChanged += new PropertyChangedEventHandler(this.ValueChanged);
            if (propEditor is DNNListEditControl)
            {
                DNNListEditControl listEditor = (DNNListEditControl)propEditor;
                listEditor.ItemChanged += new PropertyChangedEventHandler(this.ListItemChanged);
            }

            _Editor = propEditor;

            return propEditor;
        }
		/// <summary>
		/// BuildDiv creates the Control as a Div
		/// </summary>
		/// <param name="editInfo">The EditorInfo object for this control</param>
		/// <history>
		///     [cnurse]	05/08/2006	created
		/// </history>
		private void BuildDiv(EditorInfo editInfo)
		{
			var propLabel = new PropertyLabelControl();

			var propEditor = BuildEditor(editInfo);
			var visibility = BuildVisibility(editInfo);

			if (editInfo.LabelMode != LabelMode.None)
			{
				propLabel = BuildLabel(editInfo);
				propLabel.EditControl = propEditor;
			}

			var strValue = editInfo.Value as string; 
			if (ShowRequired && editInfo.Required && (editInfo.EditMode == PropertyEditorMode.Edit || (editInfo.Required && string.IsNullOrEmpty(strValue))))
			{
                propLabel.Required = true;
			}

			if (editInfo.LabelMode == LabelMode.Left || editInfo.LabelMode == LabelMode.Top)
			{
				Controls.Add(propLabel);
				Controls.Add(propEditor);
				if (visibility != null)
				{
					Controls.Add(visibility);
				}
			}
			else
			{
				Controls.Add(propEditor);
				if (visibility != null)
				{
					Controls.Add(visibility);
				}
				if ((propLabel != null))
				{
					Controls.Add(propLabel);
				}
			}
			
			//Build the Validators
			BuildValidators(editInfo, propEditor.ID);
			if (Validators.Count > 0)
			{
				//Add the Validators to the editor cell
				foreach (BaseValidator validator in Validators)
				{
					validator.Width = Width;
					Controls.Add(validator);
				}
			}
		}
		/// <summary>
		/// BuildEditor creates the editor part of the Control
		/// </summary>
		/// <param name="editInfo">The EditorInfo object for this control</param>
		/// <history>
		///     [cnurse]	05/08/2006	created
		/// </history>
		private EditControl BuildEditor(EditorInfo editInfo)
		{
			EditControl propEditor = EditControlFactory.CreateEditControl(editInfo);
			propEditor.ControlStyle.CopyFrom(EditControlStyle);
			propEditor.LocalResourceFile = LocalResourceFile;
		    propEditor.User = User;
			if (editInfo.ControlStyle != null)
			{
				propEditor.ControlStyle.CopyFrom(editInfo.ControlStyle);
			}
			propEditor.ItemAdded += CollectionItemAdded;
			propEditor.ItemDeleted += CollectionItemDeleted;
			propEditor.ValueChanged += ValueChanged;
			if (propEditor is DNNListEditControl)
			{
				var listEditor = (DNNListEditControl) propEditor;
				listEditor.ItemChanged += ListItemChanged;
			}
			Editor = propEditor;

			return propEditor;
		}
 /// -----------------------------------------------------------------------------
 /// <summary>
 /// Constructs a new PropertyEditorItemEventArgs
 /// </summary>
 /// <param name="editor">The editor created</param>
 /// <history>
 ///     [cnurse]	02/20/2007	created
 /// </history>
 /// -----------------------------------------------------------------------------
 public PropertyEditorItemEventArgs(EditorInfo editor)
 {
     Editor = editor;
 }
		/// <summary>
		/// BuildValidators creates the validators part of the Control
		/// </summary>
		/// <param name="editInfo">The EditorInfo object for this control</param>
		/// <history>
		///     [cnurse]	05/08/2006	created
		/// </history>
		private Image BuildRequiredIcon(EditorInfo editInfo)
		{
			Image img = null;
			var strValue = editInfo.Value as string;
			if (ShowRequired && editInfo.Required && (editInfo.EditMode == PropertyEditorMode.Edit || (editInfo.Required && string.IsNullOrEmpty(strValue))))
			{
				img = new Image();
				if (String.IsNullOrEmpty(RequiredUrl) || RequiredUrl == Null.NullString)
				{
					img.ImageUrl = "~/images/required.gif";
				}
				else
				{
					img.ImageUrl = RequiredUrl;
				}
				img.Attributes.Add("resourcekey", editInfo.ResourceKey + ".Required");
			}
			return img;
		}
示例#25
0
        /// <Summary>GetEditorInfo builds an EditorInfo object for a propoerty</Summary>
        private EditorInfo GetEditorInfo()
        {
            string CategoryDataField             = Convert.ToString(FieldNames["Category"]);
            string EditorDataField               = Convert.ToString(FieldNames["Editor"]);
            string NameDataField                 = Convert.ToString(FieldNames["Name"]);
            string RequiredDataField             = Convert.ToString(FieldNames["Required"]);
            string TypeDataField                 = Convert.ToString(FieldNames["Type"]);
            string ValidationExpressionDataField = Convert.ToString(FieldNames["ValidationExpression"]);
            string ValueDataField                = Convert.ToString(FieldNames["Value"]);
            string VisibilityDataField           = Convert.ToString(FieldNames["Visibility"]);

            EditorInfo   editInfo = new EditorInfo();
            PropertyInfo objProperty;

            //Get the Name of the property
            editInfo.Name = string.Empty;
            //Get Name Field
            if (!String.IsNullOrEmpty(NameDataField))
            {
                objProperty = DataSource.GetType().GetProperty(NameDataField);
                if (!((objProperty == null) || (objProperty.GetValue(DataSource, null) == null)))
                {
                    editInfo.Name = Convert.ToString(objProperty.GetValue(DataSource, null));
                }
            }

            //Get the Category of the property
            editInfo.Category = string.Empty;
            //Get Category Field
            if (!String.IsNullOrEmpty(CategoryDataField))
            {
                objProperty = DataSource.GetType().GetProperty(CategoryDataField);
                if (!((objProperty == null) || (objProperty.GetValue(DataSource, null) == null)))
                {
                    editInfo.Category = Convert.ToString(objProperty.GetValue(DataSource, null));
                }
            }

            //Get Value Field
            editInfo.Value = string.Empty;
            if (!String.IsNullOrEmpty(ValueDataField))
            {
                objProperty = DataSource.GetType().GetProperty(ValueDataField);
                if (!((objProperty == null) || (objProperty.GetValue(DataSource, null) == null)))
                {
                    editInfo.Value = Convert.ToString(objProperty.GetValue(DataSource, null));
                }
            }

            //Get the type of the property
            editInfo.Type = "System.String";
            if (!String.IsNullOrEmpty(TypeDataField))
            {
                objProperty = DataSource.GetType().GetProperty(TypeDataField);
                if (!((objProperty == null) || (objProperty.GetValue(DataSource, null) == null)))
                {
                    editInfo.Type = Convert.ToString(objProperty.GetValue(DataSource, null));
                }
            }

            //Get Editor Field
            editInfo.Editor = "DotNetNuke.UI.WebControls.TextEditControl, DotNetNuke";
            if (!String.IsNullOrEmpty(EditorDataField))
            {
                objProperty = DataSource.GetType().GetProperty(EditorDataField);
                if (!((objProperty == null) || (objProperty.GetValue(DataSource, null) == null)))
                {
                    editInfo.Editor = EditorInfo.GetEditor(Convert.ToInt32(objProperty.GetValue(DataSource, null)));
                }
            }

            //Get LabelMode Field
            editInfo.LabelMode = LabelMode.Left;

            //Get Required Field
            editInfo.Required = false;
            if (!String.IsNullOrEmpty(RequiredDataField))
            {
                objProperty = DataSource.GetType().GetProperty(RequiredDataField);
                if (!((objProperty == null) || (objProperty.GetValue(DataSource, null) == null)))
                {
                    editInfo.Required = Convert.ToBoolean(objProperty.GetValue(DataSource, null));
                }
            }

            //Set ResourceKey Field
            editInfo.ResourceKey = editInfo.Name;
            editInfo.ResourceKey = string.Format("{0}_{1}", Name, editInfo.Name);

            //Get Style
            editInfo.ControlStyle = new Style();

            //Get Visibility Field
            editInfo.Visibility = UserVisibilityMode.AllUsers;
            if (!String.IsNullOrEmpty(VisibilityDataField))
            {
                objProperty = DataSource.GetType().GetProperty(VisibilityDataField);
                if (!((objProperty == null) || (objProperty.GetValue(DataSource, null) == null)))
                {
                    editInfo.Visibility = (UserVisibilityMode)objProperty.GetValue(DataSource, null);
                }
            }

            //Get Validation Expression Field
            editInfo.ValidationExpression = string.Empty;
            if (!String.IsNullOrEmpty(ValidationExpressionDataField))
            {
                objProperty = DataSource.GetType().GetProperty(ValidationExpressionDataField);
                if (!((objProperty == null) || (objProperty.GetValue(DataSource, null) == null)))
                {
                    editInfo.ValidationExpression = Convert.ToString(objProperty.GetValue(DataSource, null));
                }
            }

            return(editInfo);
        }
		/// -----------------------------------------------------------------------------
		/// <summary>
		/// BuildValidators creates the validators part of the Control
		/// </summary>
		/// <param name="editInfo">The EditorInfo object for this control</param>
		/// <param name="targetId">Target Control Id.</param>
		/// <history>
		///     [cnurse]	05/08/2006	created
		/// </history>
		/// -----------------------------------------------------------------------------
		private void BuildValidators(EditorInfo editInfo, string targetId)
		{
			Validators.Clear();

			//Add Required Validators
			if (editInfo.Required)
			{
				var reqValidator = new RequiredFieldValidator();
				reqValidator.ID = editInfo.Name + "_Req";
				reqValidator.ControlToValidate = targetId;
				reqValidator.Display = ValidatorDisplay.Dynamic;
				reqValidator.ControlStyle.CopyFrom(ErrorStyle);
			    if(String.IsNullOrEmpty(reqValidator.CssClass))
			    {
			        reqValidator.CssClass = "dnnFormMessage dnnFormError";
			    }
				reqValidator.EnableClientScript = EnableClientValidation;
				reqValidator.Attributes.Add("resourcekey", editInfo.ResourceKey + ".Required");
				reqValidator.ErrorMessage = editInfo.Name + " is Required";
				Validators.Add(reqValidator);
			}
			
			//Add Regular Expression Validators
			if (!String.IsNullOrEmpty(editInfo.ValidationExpression))
			{
				var regExValidator = new RegularExpressionValidator();
				regExValidator.ID = editInfo.Name + "_RegEx";
				regExValidator.ControlToValidate = targetId;
				regExValidator.ValidationExpression = editInfo.ValidationExpression;
				regExValidator.Display = ValidatorDisplay.Dynamic;
				regExValidator.ControlStyle.CopyFrom(ErrorStyle);
			    if(String.IsNullOrEmpty(regExValidator.CssClass))
			    {
                    regExValidator.CssClass = "dnnFormMessage dnnFormError";
			    }
				regExValidator.EnableClientScript = EnableClientValidation;
				regExValidator.Attributes.Add("resourcekey", editInfo.ResourceKey + ".Validation");
				regExValidator.ErrorMessage = editInfo.Name + " is Invalid";
				Validators.Add(regExValidator);
			}
		}
示例#27
0
        /// <Summary>BuildDiv creates the Control as a Div</Summary>
        /// <Param name="editInfo">The EditorInfo object for this control</Param>
        private void BuildDiv(EditorInfo editInfo)
        {
            HtmlGenericControl divLabel = null;

            if (editInfo.LabelMode != LabelMode.None)
            {
                divLabel = new HtmlGenericControl("div");
                string style = "float: " + editInfo.LabelMode.ToString().ToLower();
                if (editInfo.LabelMode == LabelMode.Left || editInfo.LabelMode == LabelMode.Right)
                {
                    style += "; width: " + LabelWidth.ToString();
                }
                divLabel.Attributes.Add("style", style);
                divLabel.Controls.Add(BuildLabel(editInfo));
            }

            HtmlGenericControl divEdit = new HtmlGenericControl("div");
            string             side    = GetOppositeSide(editInfo.LabelMode);

            // HACK : Modified to not error if object is null.
            //if (side.Length > 0)
            if (!String.IsNullOrEmpty(side))
            {
                string style = "float: " + side;
                style += "; width: " + EditControlWidth.ToString();
                divEdit.Attributes.Add("style", style);
            }

            EditControl       propEditor = BuildEditor(editInfo);
            VisibilityControl visibility = BuildVisibility(editInfo);

            if (visibility != null)
            {
                visibility.Attributes.Add("style", "float: right;");
                divEdit.Controls.Add(visibility);
            }
            divEdit.Controls.Add(propEditor);
            Image requiredIcon = BuildRequiredIcon(editInfo);

            divEdit.Controls.Add(propEditor);
            if (requiredIcon != null)
            {
                divEdit.Controls.Add(requiredIcon);
            }

            if (editInfo.LabelMode == LabelMode.Left || editInfo.LabelMode == LabelMode.Top)
            {
                Controls.Add(divLabel);
                Controls.Add(divEdit);
            }
            else
            {
                Controls.Add(divEdit);
                if (divLabel != null)
                {
                    Controls.Add(divLabel);
                }
            }

            //Build the Validators
            BuildValidators(editInfo, propEditor.ID);

            if (Validators.Count > 0)
            {
                //Add the Validators to the editor cell
                foreach (BaseValidator validator in Validators)
                {
                    validator.Width = this.Width;
                    Controls.Add(validator);
                }
            }
        }
示例#28
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// BuildTable creates the Control as a Table
        /// </summary>
        /// <param name="editInfo">The EditorInfo object for this control</param>
        /// -----------------------------------------------------------------------------
        private void BuildTable(EditorInfo editInfo)
        {
            var tbl        = new Table();
            var labelCell  = new TableCell();
            var editorCell = new TableCell();

            //Build Label Cell
            labelCell.VerticalAlign = VerticalAlign.Top;
            labelCell.Controls.Add(BuildLabel(editInfo));
            if (editInfo.LabelMode == LabelMode.Left || editInfo.LabelMode == LabelMode.Right)
            {
                labelCell.Width = LabelWidth;
            }
            //Build Editor Cell
            editorCell.VerticalAlign = VerticalAlign.Top;
            EditControl propEditor   = BuildEditor(editInfo);
            Image       requiredIcon = BuildRequiredIcon(editInfo);

            editorCell.Controls.Add(propEditor);
            if (requiredIcon != null)
            {
                editorCell.Controls.Add(requiredIcon);
            }
            if (editInfo.LabelMode == LabelMode.Left || editInfo.LabelMode == LabelMode.Right)
            {
                editorCell.Width = EditControlWidth;
            }
            VisibilityControl visibility = BuildVisibility(editInfo);

            if (visibility != null)
            {
                editorCell.Controls.Add(new LiteralControl("&nbsp;&nbsp;"));
                editorCell.Controls.Add(visibility);
            }

            //Add cells to table
            var editorRow = new TableRow();
            var labelRow  = new TableRow();

            if (editInfo.LabelMode == LabelMode.Bottom || editInfo.LabelMode == LabelMode.Top || editInfo.LabelMode == LabelMode.None)
            {
                editorCell.ColumnSpan = 2;
                editorRow.Cells.Add(editorCell);
                if (editInfo.LabelMode == LabelMode.Bottom || editInfo.LabelMode == LabelMode.Top)
                {
                    labelCell.ColumnSpan = 2;
                    labelRow.Cells.Add(labelCell);
                }
                if (editInfo.LabelMode == LabelMode.Top)
                {
                    tbl.Rows.Add(labelRow);
                }
                tbl.Rows.Add(editorRow);
                if (editInfo.LabelMode == LabelMode.Bottom)
                {
                    tbl.Rows.Add(labelRow);
                }
            }
            else if (editInfo.LabelMode == LabelMode.Left)
            {
                editorRow.Cells.Add(labelCell);
                editorRow.Cells.Add(editorCell);
                tbl.Rows.Add(editorRow);
            }
            else if (editInfo.LabelMode == LabelMode.Right)
            {
                editorRow.Cells.Add(editorCell);
                editorRow.Cells.Add(labelCell);
                tbl.Rows.Add(editorRow);
            }

            //Build the Validators
            BuildValidators(editInfo, propEditor.ID);

            var validatorsRow  = new TableRow();
            var validatorsCell = new TableCell();

            validatorsCell.ColumnSpan = 2;
            //Add the Validators to the editor cell
            foreach (BaseValidator validator in Validators)
            {
                validatorsCell.Controls.Add(validator);
            }
            validatorsRow.Cells.Add(validatorsCell);
            tbl.Rows.Add(validatorsRow);

            //Add the Table to the Controls Collection
            Controls.Add(tbl);
        }
示例#29
0
 /// -----------------------------------------------------------------------------
 /// <summary>
 /// Constructs a new PropertyEditorItemEventArgs
 /// </summary>
 /// <param name="editor">The editor created</param>
 /// <history>
 ///     [cnurse]	02/20/2007	created
 /// </history>
 /// -----------------------------------------------------------------------------
 public PropertyEditorItemEventArgs(EditorInfo editor)
 {
     Editor = editor;
 }
示例#30
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// GetEditorInfo builds an EditorInfo object for a propoerty.
        /// </summary>
        /// -----------------------------------------------------------------------------
        private EditorInfo GetEditorInfo(object dataSource, PropertyInfo objProperty)
        {
            var editInfo = new EditorInfo();

            // Get the Name of the property
            editInfo.Name = objProperty.Name;

            // Get the value of the property
            editInfo.Value = objProperty.GetValue(dataSource, null);

            // Get the type of the property
            editInfo.Type = objProperty.PropertyType.AssemblyQualifiedName;

            // Get the Custom Attributes for the property
            editInfo.Attributes = objProperty.GetCustomAttributes(true);

            // Get Category Field
            editInfo.Category = string.Empty;
            object[] categoryAttributes = objProperty.GetCustomAttributes(typeof(CategoryAttribute), true);
            if (categoryAttributes.Length > 0)
            {
                var category = (CategoryAttribute)categoryAttributes[0];
                editInfo.Category = category.Category;
            }

            // Get EditMode Field
            if (!objProperty.CanWrite)
            {
                editInfo.EditMode = PropertyEditorMode.View;
            }
            else
            {
                object[] readOnlyAttributes = objProperty.GetCustomAttributes(typeof(IsReadOnlyAttribute), true);
                if (readOnlyAttributes.Length > 0)
                {
                    var readOnlyMode = (IsReadOnlyAttribute)readOnlyAttributes[0];
                    if (readOnlyMode.IsReadOnly)
                    {
                        editInfo.EditMode = PropertyEditorMode.View;
                    }
                }
            }

            // Get Editor Field
            editInfo.Editor = "UseSystemType";
            object[] editorAttributes = objProperty.GetCustomAttributes(typeof(EditorAttribute), true);
            if (editorAttributes.Length > 0)
            {
                EditorAttribute editor = null;
                for (int i = 0; i <= editorAttributes.Length - 1; i++)
                {
                    if (((EditorAttribute)editorAttributes[i]).EditorBaseTypeName.IndexOf("DotNetNuke.UI.WebControls.EditControl") >= 0)
                    {
                        editor = (EditorAttribute)editorAttributes[i];
                        break;
                    }
                }

                if (editor != null)
                {
                    editInfo.Editor = editor.EditorTypeName;
                }
            }

            // Get Required Field
            editInfo.Required = false;
            object[] requiredAttributes = objProperty.GetCustomAttributes(typeof(RequiredAttribute), true);
            if (requiredAttributes.Length > 0)
            {
                // The property may contain multiple edit mode types, so make sure we only use DotNetNuke editors.
                var required = (RequiredAttribute)requiredAttributes[0];
                if (required.Required)
                {
                    editInfo.Required = true;
                }
            }

            // Get Css Style
            editInfo.ControlStyle = new Style();
            object[] StyleAttributes = objProperty.GetCustomAttributes(typeof(ControlStyleAttribute), true);
            if (StyleAttributes.Length > 0)
            {
                var attribute = (ControlStyleAttribute)StyleAttributes[0];
                editInfo.ControlStyle.CssClass = attribute.CssClass;
                editInfo.ControlStyle.Height   = attribute.Height;
                editInfo.ControlStyle.Width    = attribute.Width;
            }

            // Get LabelMode Field
            editInfo.LabelMode = LabelMode.Left;
            object[] labelModeAttributes = objProperty.GetCustomAttributes(typeof(LabelModeAttribute), true);
            if (labelModeAttributes.Length > 0)
            {
                var mode = (LabelModeAttribute)labelModeAttributes[0];
                editInfo.LabelMode = mode.Mode;
            }

            // Set ResourceKey Field
            editInfo.ResourceKey = string.Format("{0}_{1}", dataSource.GetType().Name, objProperty.Name);

            // Get Validation Expression Field
            editInfo.ValidationExpression = string.Empty;
            object[] regExAttributes = objProperty.GetCustomAttributes(typeof(RegularExpressionValidatorAttribute), true);
            if (regExAttributes.Length > 0)
            {
                var regExAttribute = (RegularExpressionValidatorAttribute)regExAttributes[0];
                editInfo.ValidationExpression = regExAttribute.Expression;
            }

            // Set Visibility
            editInfo.ProfileVisibility = new ProfileVisibility
            {
                VisibilityMode = UserVisibilityMode.AllUsers,
            };

            return(editInfo);
        }
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// GetEditorInfo builds an EditorInfo object for a propoerty
        /// </summary>
        /// <history>
        /// 	[cnurse]	05/05/2006	Created
        /// </history>
        /// -----------------------------------------------------------------------------
        private EditorInfo GetEditorInfo()
        {
            string CategoryDataField = Convert.ToString(FieldNames["Category"]);
            string EditorDataField = Convert.ToString(FieldNames["Editor"]);
            string NameDataField = Convert.ToString(FieldNames["Name"]);
            string RequiredDataField = Convert.ToString(FieldNames["Required"]);
            string TypeDataField = Convert.ToString(FieldNames["Type"]);
            string ValidationExpressionDataField = Convert.ToString(FieldNames["ValidationExpression"]);
            string ValueDataField = Convert.ToString(FieldNames["Value"]);
            string VisibilityDataField = Convert.ToString(FieldNames["ProfileVisibility"]);
            string MaxLengthDataField = Convert.ToString(FieldNames["Length"]);

            var editInfo = new EditorInfo();
            PropertyInfo property;

            //Get the Name of the property
            editInfo.Name = string.Empty;
            if (!String.IsNullOrEmpty(NameDataField))
            {
                property = DataSource.GetType().GetProperty(NameDataField);
                if (!(property == null || (property.GetValue(DataSource, null) == null)))
                {
                    editInfo.Name = Convert.ToString(property.GetValue(DataSource, null));
                }
            }
			
            //Get the Category of the property
            editInfo.Category = string.Empty;
			
			//Get Category Field
            if (!String.IsNullOrEmpty(CategoryDataField))
            {
                property = DataSource.GetType().GetProperty(CategoryDataField);
                if (!(property == null || (property.GetValue(DataSource, null) == null)))
                {
                    editInfo.Category = Convert.ToString(property.GetValue(DataSource, null));
                }
            }
            
			//Get Value Field
			editInfo.Value = string.Empty;
            if (!String.IsNullOrEmpty(ValueDataField))
            {
                property = DataSource.GetType().GetProperty(ValueDataField);
                if (!(property == null || (property.GetValue(DataSource, null) == null)))
                {
                    editInfo.Value = Convert.ToString(property.GetValue(DataSource, null));
                }
            }
            
			//Get the type of the property
			editInfo.Type = "System.String";
            if (!String.IsNullOrEmpty(TypeDataField))
            {
                property = DataSource.GetType().GetProperty(TypeDataField);
                if (!(property == null || (property.GetValue(DataSource, null) == null)))
                {
                    editInfo.Type = Convert.ToString(property.GetValue(DataSource, null));
                }
            }
            
			//Get Editor Field
			editInfo.Editor = "DotNetNuke.UI.WebControls.TextEditControl, DotNetNuke";
            if (!String.IsNullOrEmpty(EditorDataField))
            {
                property = DataSource.GetType().GetProperty(EditorDataField);
                if (!(property == null || (property.GetValue(DataSource, null) == null)))
                {
                    editInfo.Editor = EditorInfo.GetEditor(Convert.ToInt32(property.GetValue(DataSource, null)));
                }
            }
			
            //Get LabelMode Field
            editInfo.LabelMode = LabelMode.Left;

            //Get Required Field
            editInfo.Required = false;
            if (!String.IsNullOrEmpty(RequiredDataField))
            {
                property = DataSource.GetType().GetProperty(RequiredDataField);
                if (!((property == null) || (property.GetValue(DataSource, null) == null)))
                {
                    editInfo.Required = Convert.ToBoolean(property.GetValue(DataSource, null));
                }
            }
			
            //Set ResourceKey Field
            editInfo.ResourceKey = editInfo.Name;
            editInfo.ResourceKey = string.Format("{0}_{1}", Name, editInfo.Name);

            //Set Style
            editInfo.ControlStyle = new Style();

            //Get Visibility Field
            editInfo.ProfileVisibility = new ProfileVisibility
                                             {
                                                 VisibilityMode = UserVisibilityMode.AllUsers
                                             };
            if (!String.IsNullOrEmpty(VisibilityDataField))
            {
                property = DataSource.GetType().GetProperty(VisibilityDataField);
                if (!(property == null || (property.GetValue(DataSource, null) == null)))
                {
                    editInfo.ProfileVisibility = (ProfileVisibility)property.GetValue(DataSource, null);
                }
            }
			
            //Get Validation Expression Field
            editInfo.ValidationExpression = string.Empty;
            if (!String.IsNullOrEmpty(ValidationExpressionDataField))
            {
                property = DataSource.GetType().GetProperty(ValidationExpressionDataField);
                if (!(property == null || (property.GetValue(DataSource, null) == null)))
                {
                    editInfo.ValidationExpression = Convert.ToString(property.GetValue(DataSource, null));
                }
            }
			
			//Get Length Field
            if (!String.IsNullOrEmpty(MaxLengthDataField))
            {
                property = DataSource.GetType().GetProperty(MaxLengthDataField);
                if (!(property == null || (property.GetValue(DataSource, null) == null)))
                {
                    int length = Convert.ToInt32(property.GetValue(DataSource, null));
                    var attributes = new object[1];
                    attributes[0] = new MaxLengthAttribute(length);
                    editInfo.Attributes = attributes;
                }
            }
			
			//Remove spaces from name
            editInfo.Name = editInfo.Name.Replace(" ", "_");
            return editInfo;
        }