예제 #1
0
        public void AddList(ListItem list)
        {
            XmlDocument doc = GetXmlDocumentByFileName(DbListItemFile);
            XmlNodeList nodeList = doc.GetElementsByTagName("Lists");
            if (nodeList.Count > 0)
            {
                XmlNode root = nodeList[0];

                XmlElement listNode = doc.CreateElement("List");
                XmlElement nodeId = doc.CreateElement("Id");
                nodeId.InnerText = list.Id;
                listNode.AppendChild(nodeId);
                XmlElement nodeName = doc.CreateElement("Name");
                nodeName.InnerText = list.Name;
                listNode.AppendChild(nodeName);
                XmlElement nodeCode = doc.CreateElement("Code");
                nodeCode.InnerText = list.Code;
                listNode.AppendChild(nodeCode);
                XmlElement nodeFile = doc.CreateElement("SubFile");
                nodeFile.InnerText = list.SubDbFileName;
                listNode.AppendChild(nodeFile);
                XmlElement nodeCount = doc.CreateElement("ChildrenCount");
                nodeCount.InnerText = "0";
                listNode.AppendChild(nodeCount);

                root.AppendChild(listNode);
                SaveXmlDocument(doc, DbListItemFile);

                string dirPath = GetXmlFileName(string.Format(@"Contents\{0}", list.SubDbFileName));
                if (!Directory.Exists(dirPath))
                {
                    Directory.CreateDirectory(dirPath);
                }
            }
            else
            {
                throw new ArgumentOutOfRangeException("数据库结构错误 - 列表");
            }
        }
예제 #2
0
 public static ListItem LoadByXmlNode(XmlNode xmlNode)
 {
     ListItem item = new ListItem();
     foreach (XmlNode child in xmlNode.ChildNodes)
     {
         switch (child.Name.ToUpper())
         {
             case "ID":
                 item.Id = child.InnerText;
                 break;
             case "NAME":
                 item.Name = child.InnerText;
                 break;
             case "CODE":
                 item.Code = child.InnerText;
                 break;
             case "SUBFILE":
                 item.SubDbFileName = child.InnerText;
                 break;
             case "CHILDRENCOUNT":
                 item.ChildrenCount = int.Parse(child.InnerText);
                 break;
         }
     }
     return item;
 }