Beispiel #1
0
        private object [] GetControls(IContainer container)
        {
            ComponentCollection allComponents = container.Components;
            ArrayList           array         = new ArrayList();

            // for each control in the container
            foreach (IComponent comp in (IEnumerable)allComponents)
            {
                if (comp is Control)
                {
                    Control control = (Control)comp;

                    // Must have an ID
                    if (control.ID == null || control.ID.Length == 0)
                    {
                        continue;
                    }

                    // Must have a validation property
                    ValidationPropertyAttribute valProp = (ValidationPropertyAttribute)TypeDescriptor.GetAttributes(control)[typeof(ValidationPropertyAttribute)];
                    if (valProp != null && valProp.Name != null)
                    {
                        array.Add(string.Copy(control.ID));
                    }
                }
            }
            array.Sort(Comparer.Default);
            return(array.ToArray());
        }
        public static void SaveFormItems(Hashtable _results, Control _container)
        {
            foreach (Control ctrl in _container.Controls)
            {
                if (ctrl is ListControl)
                {
                    _results.Add(ctrl.ID, ((ListControl)ctrl).Items);
                }

                else if (ctrl is TextBox)
                {
                    _results.Add(ctrl.ID, ((TextBox)ctrl).Text);
                }

                else if (ctrl is CheckBox)
                {
                    _results.Add(ctrl.ID, ((CheckBox)ctrl).Checked);
                }

                else
                {
                    ValidationPropertyAttribute attr = (ValidationPropertyAttribute)Attribute.GetCustomAttribute(ctrl.GetType(), typeof(ValidationPropertyAttribute));

                    if (attr != null)
                    {
                        System.Reflection.PropertyInfo info = ctrl.GetType().GetProperty(attr.Name);
                        _results.Add(ctrl.ID, info.GetValue(ctrl, null));
                    }
                }
            }
        }
        private object[] GetControls(IContainer container)
        {
            ComponentCollection componentCollection = container.Components;
            ArrayList           ctrlList            = new ArrayList();

            foreach (IComponent comp in componentCollection)
            {
                Control ctrl = (Control)comp;

                if (ctrl is CardTypesListBox)
                {
                    if (ctrl.ID != null && ctrl.ID.Length != 0)
                    {
                        ValidationPropertyAttribute vpa =
                            (ValidationPropertyAttribute)TypeDescriptor.GetAttributes(ctrl)[typeof(ValidationPropertyAttribute)];
                        if (vpa != null && vpa.Name != null)
                        {
                            ctrlList.Add(String.Copy(ctrl.ID));
                        }
                    }
                }
            }

            ctrlList.Sort();

            return(ctrlList.ToArray());
        }
        /// <devdoc>
        ///    <para>Helper function to get the validation
        ///       property of a control if it exists.</para>
        /// </devdoc>
        public static PropertyDescriptor GetValidationProperty(object component)
        {
            ValidationPropertyAttribute valProp = (ValidationPropertyAttribute)TypeDescriptor.GetAttributes(component)[typeof(ValidationPropertyAttribute)];

            if (valProp != null && valProp.Name != null)
            {
                return(TypeDescriptor.GetProperties(component, null)[valProp.Name]);
            }
            return(null);
        }
        public static PropertyDescriptor GetValidationProperty(object component)
        {
            ValidationPropertyAttribute attribute = (ValidationPropertyAttribute)TypeDescriptor.GetAttributes(component)[typeof(ValidationPropertyAttribute)];

            if ((attribute != null) && (attribute.Name != null))
            {
                return(TypeDescriptor.GetProperties(component, (Attribute[])null)[attribute.Name]);
            }
            return(null);
        }
        private bool CanBeValidated(Control control)
        {
            // Control must have an ID
            if (control.ID == null || control.ID.Length == 0)
            {
                return(false);
            }

            // Control must have a ValidationProperty attribute
            ValidationPropertyAttribute valProp =
                (ValidationPropertyAttribute)
                TypeDescriptor.GetAttributes(control)[typeof(ValidationPropertyAttribute)];

            if (null != valProp && null != valProp.Name)
            {
                return(true);
            }

            return(false);
        }
Beispiel #7
0
        public static PropertyDescriptor GetValidationProperty(object o)
        {
            PropertyDescriptorCollection props;

            System.ComponentModel.AttributeCollection col;

            props = TypeDescriptor.GetProperties(o);
            col   = TypeDescriptor.GetAttributes(o);

            foreach (Attribute at in col)
            {
                ValidationPropertyAttribute vpa = at as ValidationPropertyAttribute;
                if (vpa != null && vpa.Name != null)
                {
                    return(props[vpa.Name]);
                }
            }

            return(null);
        }
 private static void SetValidProp(Control ctrl, string inValue, ValidationPropertyAttribute attr)
 {
     {
         System.Reflection.PropertyInfo info = ctrl.GetType().GetProperty(attr.Name);
         try
         {
             info.SetValue(ctrl,
                           Convert.ChangeType(inValue, info.PropertyType), null);
         }
         catch
         {
             try
             {
                 // try to set a mythical property named value if we failed
                 info = ctrl.GetType().GetProperty("Value");
                 info.SetValue(ctrl,
                               Convert.ChangeType(inValue, info.PropertyType), null);
             }
             catch { }
         }
     }
 }
		public void Deny_Unrestricted ()
		{
			ValidationPropertyAttribute vpa = new ValidationPropertyAttribute (null);
			Assert.IsNull (vpa.Name, "Name");
		}
Beispiel #10
0
        private void addControlNew(Property p, TabPage tp, string Caption)
        {
            IDataType dt = p.PropertyType.DataTypeDefinition.DataType;

            dt.DataEditor.Editor.ID = string.Format("prop_{0}", p.PropertyType.Alias);
            dt.Data.PropertyId      = p.Id;

            // check for buttons
            IDataFieldWithButtons df1 = dt.DataEditor.Editor as IDataFieldWithButtons;

            if (df1 != null)
            {
                // df1.Alias = p.PropertyType.Alias;

                /*
                 *              // df1.Version = _content.Version;
                 *              editDataType.Data.PropertyId = p.Id;
                 */
                ((Control)df1).ID = p.PropertyType.Alias;


                if (df1.MenuIcons.Length > 0)
                {
                    tp.Menu.InsertSplitter();
                }


                // Add buttons
                int  c          = 0;
                bool atEditHtml = false;
                bool atSplitter = false;
                foreach (object o in df1.MenuIcons)
                {
                    try
                    {
                        MenuIconI m  = (MenuIconI)o;
                        MenuIconI mi = tp.Menu.NewIcon();
                        mi.ImageURL       = m.ImageURL;
                        mi.OnClickCommand = m.OnClickCommand;
                        mi.AltText        = m.AltText;
                        mi.ID             = tp.ID + "_" + m.ID;

                        if (m.ID == "html")
                        {
                            atEditHtml = true;
                        }
                        else
                        {
                            atEditHtml = false;
                        }

                        atSplitter = false;
                    }
                    catch
                    {
                        tp.Menu.InsertSplitter();
                        atSplitter = true;
                    }

                    // Testing custom styles in editor
                    if (atSplitter && atEditHtml && dt.DataEditor.TreatAsRichTextEditor)
                    {
                        DropDownList ddl = tp.Menu.NewDropDownList();

                        ddl.Style.Add("margin-bottom", "5px");
                        ddl.Items.Add(ui.Text("buttons", "styleChoose", null));
                        ddl.ID = tp.ID + "_editorStyle";
                        if (StyleSheet.GetAll().Length > 0)
                        {
                            foreach (StyleSheet s in StyleSheet.GetAll())
                            {
                                foreach (StylesheetProperty sp in s.Properties)
                                {
                                    ddl.Items.Add(new ListItem(sp.Text, sp.Alias));
                                }
                            }
                        }
                        ddl.Attributes.Add("onChange", "addStyle(this, '" + p.PropertyType.Alias + "');");
                        atEditHtml = false;
                    }
                    c++;
                }
            }

            // check for element additions
            IMenuElement menuElement = dt.DataEditor.Editor as IMenuElement;

            if (menuElement != null)
            {
                // add separator
                tp.Menu.InsertSplitter();

                // add the element
                tp.Menu.NewElement(menuElement.ElementName, menuElement.ElementIdPreFix + p.Id.ToString(),
                                   menuElement.ElementClass, menuElement.ExtraMenuWidth);
            }


            // fieldData.Alias = p.PropertyType.Alias;
            // ((Control) fieldData).ID = p.PropertyType.Alias;
            // fieldData.Text = p.Value.ToString();

            _dataFields.Add(dt.DataEditor.Editor);


            Pane    pp     = new Pane();
            Control holder = new Control();

            holder.Controls.Add(dt.DataEditor.Editor);
            if (p.PropertyType.DataTypeDefinition.DataType.DataEditor.ShowLabel)
            {
                string caption = p.PropertyType.Name;
                if (p.PropertyType.Description != null && p.PropertyType.Description != String.Empty)
                {
                    switch (UmbracoSettings.PropertyContextHelpOption)
                    {
                    case "icon":
                        caption += " <img src=\"" + this.ResolveUrl(SystemDirectories.Umbraco) + "/images/help.png\" class=\"umbPropertyContextHelp\" alt=\"" + p.PropertyType.Description + "\" title=\"" + p.PropertyType.Description + "\" />";
                        break;

                    case "text":
                        caption += "<br /><small>" + umbraco.library.ReplaceLineBreaks(p.PropertyType.Description) + "</small>";
                        break;
                    }
                }
                pp.addProperty(caption, holder);
            }
            else
            {
                pp.addProperty(holder);
            }

            // Validation
            if (p.PropertyType.Mandatory)
            {
                try
                {
                    RequiredFieldValidator rq = new RequiredFieldValidator();
                    rq.ControlToValidate = dt.DataEditor.Editor.ID;
                    Control component = dt.DataEditor.Editor; // holder.FindControl(rq.ControlToValidate);
                    ValidationPropertyAttribute attribute =
                        (ValidationPropertyAttribute)
                        TypeDescriptor.GetAttributes(component)[typeof(ValidationPropertyAttribute)];
                    PropertyDescriptor pd = null;
                    if (attribute != null)
                    {
                        pd = TypeDescriptor.GetProperties(component, (Attribute[])null)[attribute.Name];
                    }
                    if (pd != null)
                    {
                        rq.EnableClientScript = false;
                        rq.Display            = ValidatorDisplay.Dynamic;
                        string[] errorVars = { p.PropertyType.Name, Caption };
                        rq.ErrorMessage = ui.Text("errorHandling", "errorMandatory", errorVars, null) + "<br/>";
                        holder.Controls.AddAt(0, rq);
                    }
                }
                catch (Exception valE)
                {
                    HttpContext.Current.Trace.Warn("contentControl",
                                                   "EditorControl (" + dt.DataTypeName + ") does not support validation",
                                                   valE);
                }
            }

            // RegExp Validation
            if (!string.IsNullOrWhiteSpace(p.PropertyType.ValidationRegExp))
            {
                try
                {
                    RegularExpressionValidator rv = new RegularExpressionValidator();
                    rv.ControlToValidate = dt.DataEditor.Editor.ID;

                    Control component = dt.DataEditor.Editor; // holder.FindControl(rq.ControlToValidate);
                    ValidationPropertyAttribute attribute =
                        (ValidationPropertyAttribute)
                        TypeDescriptor.GetAttributes(component)[typeof(ValidationPropertyAttribute)];
                    PropertyDescriptor pd = null;
                    if (attribute != null)
                    {
                        pd = TypeDescriptor.GetProperties(component, (Attribute[])null)[attribute.Name];
                    }
                    if (pd != null)
                    {
                        rv.ValidationExpression = p.PropertyType.ValidationRegExp;
                        rv.EnableClientScript   = false;
                        rv.Display = ValidatorDisplay.Dynamic;
                        string[] errorVars = { p.PropertyType.Name, Caption };
                        rv.ErrorMessage = ui.Text("errorHandling", "errorRegExp", errorVars, null) + "<br/>";
                        holder.Controls.AddAt(0, rv);
                    }
                }
                catch (Exception valE)
                {
                    HttpContext.Current.Trace.Warn("contentControl",
                                                   "EditorControl (" + dt.DataTypeName + ") does not support validation",
                                                   valE);
                }
            }

            // This is once again a nasty nasty hack to fix gui when rendering wysiwygeditor
            if (dt.DataEditor.TreatAsRichTextEditor)
            {
                tp.Controls.Add(dt.DataEditor.Editor);
            }
            else
            {
                Panel ph = new Panel();
                ph.Attributes.Add("style", "padding: 0; position: relative;"); // NH 4.7.1, latest styles added to support CP item: 30363
                ph.Controls.Add(pp);

                tp.Controls.Add(ph);
            }
        }
        public static void LoadFormItems(Hashtable _input, Control _container)
        {
            foreach (DictionaryEntry de in _input)
            {
                Control ctrl = _container.FindControl(de.Key.ToString());

                if (ctrl == null)
                {
                    continue;
                }

                if (ctrl is ListControl)
                {
                    if (de.Value is ListItemCollection)
                    {
                        ListControl _lstCtrl = (ListControl)ctrl;
                        foreach (ListItem li in ((ListItemCollection)de.Value))
                        {
                            ListItem _curr = _lstCtrl.Items.FindByValue(li.Value);
                            if (_curr != null && _curr.Selected != li.Selected)
                            {
                                if (_lstCtrl is ListBox &&
                                    (((ListBox)_lstCtrl).SelectionMode == ListSelectionMode.Multiple))
                                {
                                    _curr.Selected = li.Selected;
                                }
                                else
                                {
                                    _lstCtrl.SelectedIndex = _lstCtrl.Items.IndexOf(_curr);
                                }
                            }
                        }
                    }
                    else
                    {
                        ListControl _lstCtrl = (ListControl)ctrl;
                        ListItem    _curr    = _lstCtrl.Items.FindByValue(de.Value.ToString());
                        if (_curr != null)
                        {
                            _lstCtrl.SelectedIndex = _lstCtrl.Items.IndexOf(_curr);
                        }
                    }
                }

                else if (ctrl is TextBox)
                {
                    ((TextBox)ctrl).Text = de.Value.ToString();
                }

                else if (ctrl is CheckBox)
                {
                    ((CheckBox)ctrl).Checked = (bool)de.Value;
                }

                else
                {
                    ValidationPropertyAttribute attr = (ValidationPropertyAttribute)
                                                       Attribute.GetCustomAttribute(ctrl.GetType(),
                                                                                    typeof(ValidationPropertyAttribute));

                    if (attr != null)
                    {
                        System.Reflection.PropertyInfo info = ctrl.GetType().GetProperty(attr.Name);
                        try
                        {
                            info.SetValue(ctrl, de.Value, null);
                        }
                        catch
                        {
                            try
                            {
                                // try to set a mythical property named value if we failed
                                info = ctrl.GetType().GetProperty("Value");
                                info.SetValue(ctrl, de.Value, null);
                            }
                            catch { }
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Saves the form items: textbox, lists, checkbox, radio button, and validation properties recursively.
        /// </summary>
        /// <param name="_input"></param>
        /// <param name="_container"></param>
        /// <param name="ignoreSerializeAttr">If true it will load all items regardless of attribute</param>
        public static void LoadFormItems(System.Collections.Specialized.StringDictionary _input,
                                         Control _container, bool ignoreSerializeAttr)
        {
            foreach (Control ctrl in _container.Controls)
            {
                // check for the serialize attribute on the webcontrol
                if (ctrl is WebControl)
                {
                    string serialize = ((WebControl)ctrl).Attributes[Dictionary_Serialize];
                    if (serialize != null && serialize.ToLower() == "false" && !(ignoreSerializeAttr))
                    {
                        continue;
                    }
                }

                if (!_input.ContainsKey(ctrl.UniqueID))
                {
                    continue;
                }

                string prevAnswer = _input[ctrl.UniqueID];

                if (ctrl is TextBox)
                {
                    ((TextBox)ctrl).Text = prevAnswer;
                }

                else if (ctrl is CheckBox)
                {
                    ((CheckBox)ctrl).Checked = bool.Parse(prevAnswer);
                }

                else if (ctrl is ListControl)
                {
                    ListControl _tmpCtrl = (ListControl)ctrl;
                    foreach (string ans in prevAnswer.Split("|".ToCharArray()))
                    {
                        ListItem li = _tmpCtrl.Items.FindByValue(ans);
                        if (li != null)
                        {
                            if ((_tmpCtrl is ListBox) &&
                                ((ListBox)_tmpCtrl).SelectionMode == ListSelectionMode.Multiple)
                            {
                                li.Selected = true;
                            }
                            else
                            {
                                _tmpCtrl.SelectedIndex = _tmpCtrl.Items.IndexOf(li);
                            }
                        }
                    }
                }

                else
                {
                    ValidationPropertyAttribute attr = (ValidationPropertyAttribute)
                                                       Attribute.GetCustomAttribute(ctrl.GetType(),
                                                                                    typeof(ValidationPropertyAttribute));

                    if (attr != null && _input.ContainsKey(ctrl.UniqueID))
                    {
                        SetValidProp(ctrl, _input[ctrl.UniqueID], attr);
                    }
                    else
                    {
                        LoadFormItems(_input, ctrl, ignoreSerializeAttr);
                    }

                    continue;
                }
            }
        }
        /// <summary>
        /// Saves the form items: textbox, lists, checkbox, radio button, and validation properties recursively.
        /// </summary>
        /// <param name="_results">Dictionary collection to serialize for future use</param>
        /// <param name="_container"></param>
        public static void SaveFormItems(System.Collections.Specialized.StringDictionary _results,
                                         Control _container)
        {
            foreach (Control ctrl in _container.Controls)
            {
                if (ctrl is ListControl)
                {
                    string selected = string.Empty;
                    foreach (ListItem li in ((ListControl)ctrl).Items)
                    {
                        if (li.Selected)
                        {
                            selected += li.Value + "|";
                        }
                    }

                    if (selected.Length > 1)
                    {
                        selected = selected.Remove(selected.Length - 1, 1);
                    }
                    SaveDictionaryItem(_results, ctrl.UniqueID, selected);
                }

                else if (ctrl is TextBox)
                {
                    SaveDictionaryItem(_results, ctrl.UniqueID, ((TextBox)ctrl).Text);
                }

                else if (ctrl is CheckBox)
                {
                    SaveDictionaryItem(_results, ctrl.UniqueID,
                                       ((CheckBox)ctrl).Checked.ToString());
                }

                else if (ctrl is RadioButton)
                {
                    SaveDictionaryItem(_results, ctrl.UniqueID,
                                       ((RadioButton)ctrl).Checked.ToString());
                }

                // pick up a validation property otherwise
                else
                {
                    ValidationPropertyAttribute attr = (ValidationPropertyAttribute)Attribute.GetCustomAttribute(ctrl.GetType(), typeof(ValidationPropertyAttribute));

                    if (attr != null)
                    {
                        System.Reflection.PropertyInfo info = ctrl.GetType().GetProperty(attr.Name);
                        object currValue = info.GetValue(ctrl, null);

                        if (currValue != null)
                        {
                            SaveDictionaryItem(_results, ctrl.UniqueID, currValue.ToString());
                        }
                    }
                    // continue processing naming container sub items if there is no validation property
                    else if (ctrl is INamingContainer || ctrl is Panel || ctrl is PlaceHolder)
                    {
                        SaveFormItems(_results, ctrl);
                    }
                }
            }
        }
Beispiel #14
0
        protected override bool FilterControl(Control control)
        {
            ValidationPropertyAttribute attribute = (ValidationPropertyAttribute)TypeDescriptor.GetAttributes(control)[typeof(ValidationPropertyAttribute)];

            return((attribute != null) && (attribute.Name != null));
        }
Beispiel #15
0
        /// <devdoc>
        ///    <para>Determines whether a given control should have its id added to the StandardValuesCollection.</para>
        /// </devdoc>
        protected override bool FilterControl(Control control)
        {
            ValidationPropertyAttribute valProp = (ValidationPropertyAttribute)TypeDescriptor.GetAttributes(control)[typeof(ValidationPropertyAttribute)];

            return(valProp != null && valProp.Name != null);
        }