Exemplo n.º 1
0
        /// <summary>
        /// 查询页面数据
        /// </summary>
        /// <returns></returns>
        public static Model.M_Table XmlSelectTableModel(int ItemID)
        {
            Model.M_Table mt      = new Model.M_Table();
            string        xmlPath = System.AppDomain.CurrentDomain.BaseDirectory + "\\DataXML\\Table.xml";
            XmlDocument   xml     = new XmlDocument();

            xml.Load(xmlPath);                                                             //读取文件
            XmlElement    root = xml.DocumentElement;                                      //获取根节点
            StringBuilder sb   = new StringBuilder();
            XmlNode       xn   = root.SelectSingleNode("OPTION[@TableID=" + ItemID + "]"); //获取指定子节点

            if (xn != null)
            {
                PropertyInfo[] propertys = mt.GetType().GetProperties();
                foreach (PropertyInfo property in propertys)
                {
                    var attrName = property.Name;
                    if (xn.Attributes[attrName] != null)
                    {
                        Type   columnType = property.PropertyType;
                        object obj        = Convert.ChangeType(xn.Attributes[attrName].Value, columnType);
                        property.SetValue(mt, obj, null);
                    }
                }
            }
            return(mt);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取全部页面数据
        /// </summary>
        /// <returns></returns>
        public static List <Model.M_Table> XmlSelectAllTableModelList()
        {
            List <Model.M_Table> ListModel = new List <Model.M_Table>();
            string      xmlPath            = System.AppDomain.CurrentDomain.BaseDirectory + "\\DataXML\\Table.xml";
            XmlDocument xml = new XmlDocument();

            xml.Load(xmlPath);                                   //读取文件
            XmlElement    root     = xml.DocumentElement;        //获取根节点
            StringBuilder sb       = new StringBuilder();
            XmlNodeList   rootChil = root.SelectNodes("OPTION"); //获取子节点

            foreach (XmlNode xn in rootChil)
            {
                Model.M_Table  mt        = new Model.M_Table();
                PropertyInfo[] propertys = mt.GetType().GetProperties();
                foreach (PropertyInfo property in propertys)
                {
                    var attrName = property.Name;
                    if (xn.Attributes[attrName] != null)
                    {
                        Type   columnType = property.PropertyType;
                        object obj        = Convert.ChangeType(xn.Attributes[attrName].Value, columnType);
                        property.SetValue(mt, obj, null);
                    }
                }
                ListModel.Add(mt);
            }
            return(ListModel);
        }