Пример #1
0
        /// <summary>
        /// 根据XML加载范围查找项
        /// </summary>
        /// <param name="xml">XML</param>
        /// <param name="lstScope">范围集合</param>
        internal static void LoadScopeItems(Stream stm, ScopeList lstScope)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(stm);

            XmlNodeList nodeList = doc.GetElementsByTagName("item");

            foreach (XmlNode node in nodeList)
            {
                string       propertyName    = null;
                ScopeType    stype           = ScopeType.Between;
                ConnectType  ctype           = ConnectType.And;
                object       value1          = null;
                object       value2          = null;
                XmlAttribute attPropertyName = node.Attributes["propertyname"];
                if (attPropertyName != null)
                {
                    propertyName = attPropertyName.InnerText;
                }

                XmlAttribute attScopeType = node.Attributes["scopetype"];
                if (attScopeType != null)
                {
                    stype = (ScopeType)Convert.ToInt32(attScopeType.InnerText);
                }

                XmlAttribute attConnectType = node.Attributes["connecttype"];
                if (attConnectType != null)
                {
                    ctype = (ConnectType)Convert.ToInt32(attConnectType.InnerText);
                }
                foreach (XmlNode itemNode in node.ChildNodes)
                {
                    object       value   = null;
                    Type         objType = null;
                    XmlAttribute attType = itemNode.Attributes["datatype"];
                    if (attType != null)
                    {
                        objType = Type.GetType(attType.InnerText);
                    }
                    else
                    {
                        objType = typeof(string);
                    }
                    value = ListXMLExtends.StringToValue(itemNode.InnerText, objType);
                    if (itemNode.Name == "value1")
                    {
                        value1 = value;
                    }
                    else if (itemNode.Name == "value2")
                    {
                        value2 = value;
                    }
                }
                Scope objScope = new Scope(propertyName, value1, value2, stype, ctype);
                lstScope.Add(objScope);
            }
        }
Пример #2
0
        /// <summary>
        /// 添加一个值
        /// </summary>
        /// <param name="doc">XML文档</param>
        /// <param name="ele">源元素</param>
        /// <param name="valueName">值的标签</param>
        /// <param name="value">值</param>
        /// <param name="objScope">范围对象</param>
        private static void AppendValue(XmlDocument doc, XmlElement ele, string valueName, object value, Scope objScope)
        {
            XmlElement   eleValue = doc.CreateElement(valueName);
            XmlAttribute attType  = doc.CreateAttribute("datatype");

            attType.InnerText = objScope.Value1.GetType().ToString();
            eleValue.Attributes.Append(attType);
            eleValue.InnerText = ListXMLExtends.ValueToString(value);
            ele.AppendChild(eleValue);
        }