Exemplo n.º 1
0
        /// <summary>
        /// 取得Collecion对应的xml
        /// </summary>
        /// <param name="prop">Collection的propinfo</param>
        /// <param name="collection">Collection的value</param>
        /// <returns>xml</returns>
        private string GetCollectionXml(PropertyInfo prop, IJQProperty c)
        {
            StringBuilder builder = new StringBuilder();
            if (c is JQCollection<JQDefaultColumn>)
            {
                JQCollection<JQDefaultColumn> collection = c as JQCollection<JQDefaultColumn>;
                if (prop != null && collection != null && prop.PropertyType == collection.GetType())
                {
                    if (collection.Count > 0)
                    {
                        builder.AppendLine(string.Format("\t<{0}>", prop.Name));
                        for (int i = 0; i < collection.Count; i++)
                        {
                            PropertyInfo[] infos = null;
                            builder.Append(string.Format("\t\t<{0}:{1} ", "JQTools", collection[i].GetType().Name));
                            infos = collection[i].GetType().GetProperties();

                            for (int j = 0; j < infos.Length; j++)
                            {
                                if (!IsVisibilityHidden(infos[j]))
                                {
                                    if (infos[j].PropertyType == typeof(string) || infos[j].PropertyType == typeof(int) || infos[j].PropertyType == typeof(bool)
                                        || infos[j].PropertyType.BaseType == typeof(Enum))
                                    {
                                        if (!infos[j].Name.Equals("Name"))
                                        {
                                            object value = infos[j].GetValue(collection[i], null);
                                            object defaultvalue = GetDefaultValue(infos[j]);
                                            if (infos[j].CanWrite && value != defaultvalue)
                                            {
                                                builder.Append(string.Format("{0}=\"{1}\" ", infos[j].Name, value));
                                            }
                                        }
                                    }
                                }
                            }
                            builder.AppendLine("/>");
                        }
                        builder.AppendLine(string.Format("\t</{0}>", prop.Name));
                    }
                }
            }
            else if (c is JQCollection<JQValidateColumn>)
            {
                JQCollection<JQValidateColumn> collection = c as JQCollection<JQValidateColumn>;
                if (prop != null && collection != null && prop.PropertyType == collection.GetType())
                {
                    if (collection.Count > 0)
                    {
                        builder.AppendLine(string.Format("\t<{0}>", prop.Name));
                        for (int i = 0; i < collection.Count; i++)
                        {
                            PropertyInfo[] infos = null;
                            builder.Append(string.Format("\t\t<{0}:{1} ", "JQTools", collection[i].GetType().Name));
                            infos = collection[i].GetType().GetProperties();

                            for (int j = 0; j < infos.Length; j++)
                            {
                                if (!IsVisibilityHidden(infos[j]))
                                {
                                    if (infos[j].PropertyType == typeof(string) || infos[j].PropertyType == typeof(int) || infos[j].PropertyType == typeof(bool)
                                        || infos[j].PropertyType.BaseType == typeof(Enum))
                                    {
                                        if (!infos[j].Name.Equals("Name"))
                                        {
                                            object value = infos[j].GetValue(collection[i], null);
                                            object defaultvalue = GetDefaultValue(infos[j]);
                                            if (infos[j].CanWrite && value != defaultvalue)
                                            {
                                                builder.Append(string.Format("{0}=\"{1}\" ", infos[j].Name, value));
                                            }
                                        }
                                    }
                                }
                            }
                            builder.AppendLine("/>");
                        }
                        builder.AppendLine(string.Format("\t</{0}>", prop.Name));
                    }
                }
            }

            return builder.ToString();
        }
Exemplo n.º 2
0
 private void SetCollectionValue(WebDevPage.IHTMLElement controlElement, PropertyInfo prop, IJQProperty collection)
 {
     if (controlElement != null)
     {
         string collectionxml = GetCollectionXml(prop, collection);
         if (collectionxml.Length > 0)
         {
             string html = controlElement.innerHTML;
             int index = IndexOfBeginTag(html, prop.Name);
             int length;
             if (index > 0)
             {
                 int indexend = IndexOfEndTag(html, prop.Name, out length);
                 html = html.Remove(indexend - index - length);
             }
             else
             {
                 index = 0;
             }
             controlElement.innerHTML = html.Insert(index, collectionxml);
         }
     }
 }