예제 #1
0
        public override void DataBind()
        {
            if (DataSource == null)
            {
                return;
            }

            properties = DataSource.GetProperties(BindingFlags.Public | BindingFlags.Instance);
            foreach (PropertyInfo property in properties)
            {
                ModulePropertyAttribute attribute = (ModulePropertyAttribute)Attribute.GetCustomAttribute(property, typeof(ModulePropertyAttribute));
                if (attribute == null)
                {
                    continue;
                }

                string value = Context.Request.Form[property.Name];
                if (value == null)
                {
                    continue;
                }

                if (PropertyValues.ContainsKey(property.Name))
                {
                    PropertyValues[property.Name] = value;
                }
                else
                {
                    PropertyValues.Add(property.Name, value);
                }
            }
        }
예제 #2
0
        private static Label GetLabelControl(PropertyInfo property, ModulePropertyAttribute attribute)
        {
            Label label = new Label();

            label.Text = attribute.Name ?? property.Name.ToProperCase();
            label.ID   = property.Name + "Label";
            label.AssociatedControlId = property.Name;
            return(label);
        }
        public static string ListProperties(ModuleBase module)
        {
            System.Reflection.PropertyInfo[] pis = module.GetType().GetProperties();

            StringBuilder sb = new StringBuilder();

            sb.Append(module.Name);
            sb.Append("\n");
            string indent = "   ";

            foreach (System.Reflection.PropertyInfo pi in pis)
            {
                object[] os = pi.GetCustomAttributes(typeof(ModulePropertyAttribute), true);
                if (os.Length > 0)
                {
                    ModulePropertyAttribute mpa = (ModulePropertyAttribute)os[0];
                    sb.Append(indent + pi.Name + ": " + pi.GetValue(module, null).ToString());
                    sb.Append('\n');
                }
            }

            return(sb.ToString());
        }
예제 #4
0
        private Control GetEditControl(PropertyInfo property, ModulePropertyAttribute attribute)
        {
            string name = property.Name;

            if (PropertyValues.ContainsKey(name))
            {
                attribute.DefaultValue = PropertyValues[name];
            }

            PortalControl editControl = attribute.GetEditControl(property.PropertyType);

            editControl.ID = name;
            string value = Context.Request.Form[name];

            if (value != null)
            {
                ITextControl textControl = editControl as ITextControl;
                if (textControl != null)
                {
                    textControl.Text = value;
                    return(editControl);
                }

                IListControl listControl = editControl as IListControl;
                if (listControl != null)
                {
                    ListItem item = listControl.Items.FindByValue(value);
                    if (item != null)
                    {
                        item.Selected = true;
                    }
                    return(editControl);
                }
            }

            return(editControl);
        }
예제 #5
0
        protected override void CreateChildControls()
        {
            if (ItemTemplate == null)
            {
                base.CreateChildControls();
                return;
            }

            for (int index = 0; index < properties.Length; index++)
            {
                PropertyInfo            property  = properties[index];
                ModulePropertyAttribute attribute = (ModulePropertyAttribute)Attribute.GetCustomAttribute(property, typeof(ModulePropertyAttribute));
                if (attribute == null)
                {
                    continue;
                }

                Control edit  = GetEditControl(property, attribute);
                Control label = GetLabelControl(property, attribute);

                StringWriter   sw     = new StringWriter();
                HtmlTextWriter writer = new HtmlTextWriter(sw);

                label.RenderControl(writer);
                string labelHtml = sw.ToString();

                sw     = new StringWriter();
                writer = new HtmlTextWriter(sw);

                edit.RenderControl(writer);
                string editHtml = sw.ToString();

                PropertyGridItem item = new PropertyGridItem(labelHtml, editHtml, attribute.Description);

                RenderTemplate(ItemTemplate, item, index);
            }
        }
예제 #6
0
        protected override void Render(HtmlTextWriter writer)
        {
            if (ItemTemplate != null)
            {
                base.Render(writer);
                return;
            }

            if (DataSource == null)
            {
                return;
            }

            if (CssClass != null)
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Class, CssClass);
            }
            writer.RenderBeginTag(HtmlTextWriterTag.Table);

            writer.RenderBeginTag(HtmlTextWriterTag.Thead);
            writer.RenderBeginTag(HtmlTextWriterTag.Tr);

            if (PropertyColumnCssClass != null)
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Class, PropertyColumnCssClass);
            }
            writer.RenderBeginTag(HtmlTextWriterTag.Th);
            writer.Write("Property");
            writer.RenderEndTag();

            if (ValueColumnCssClass != null)
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Class, ValueColumnCssClass);
            }
            writer.RenderBeginTag(HtmlTextWriterTag.Th);
            writer.Write("Value");
            writer.RenderEndTag();

            if (DescriptionColumnCssClass != null)
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Class, DescriptionColumnCssClass);
            }
            writer.RenderBeginTag(HtmlTextWriterTag.Th);
            writer.Write("Description");
            writer.RenderEndTag();

            writer.RenderEndTag();
            writer.RenderEndTag();

            writer.RenderBeginTag(HtmlTextWriterTag.Tbody);
            foreach (PropertyInfo property in properties)
            {
                ModulePropertyAttribute attribute = (ModulePropertyAttribute)Attribute.GetCustomAttribute(property, typeof(ModulePropertyAttribute));
                if (attribute == null)
                {
                    continue;
                }

                Control edit  = GetEditControl(property, attribute);
                Control label = GetLabelControl(property, attribute);

                writer.RenderBeginTag(HtmlTextWriterTag.Tr);

                if (PropertyColumnCssClass != null)
                {
                    writer.AddAttribute(HtmlTextWriterAttribute.Class, PropertyColumnCssClass);
                }
                writer.RenderBeginTag(HtmlTextWriterTag.Td);
                label.RenderControl(writer);
                writer.RenderEndTag();

                if (ValueColumnCssClass != null)
                {
                    writer.AddAttribute(HtmlTextWriterAttribute.Class, ValueColumnCssClass);
                }
                writer.RenderBeginTag(HtmlTextWriterTag.Td);
                edit.RenderControl(writer);
                writer.RenderEndTag();

                if (DescriptionColumnCssClass != null)
                {
                    writer.AddAttribute(HtmlTextWriterAttribute.Class, DescriptionColumnCssClass);
                }
                writer.RenderBeginTag(HtmlTextWriterTag.Td);
                writer.Write(attribute.Description);
                writer.RenderEndTag();

                writer.RenderEndTag();
            }
            writer.RenderEndTag();

            writer.RenderEndTag();
        }