共谱一曲
希望更多的朋友一起交流 一起学习 共同进步 在程序这块净土上寻找真正的梦想 QQ:825696924

<?xml version="1.0" encoding="utf-8" ?>
// xml 文件  存储用户注册信息  暂时代替用户表
<UserInfo>
    <User>

        <name>admin</name>
        <pwd>888888</pwd>
        <age>22</age>
        <sex>男</sex>
    </User>


</UserInfo>

 

 

 

 

   //写入xml
       public void InsertXML(User model)
       {
           XmlDocument xmlDoc = new XmlDocument();
           xmlDoc.Load(xmlPath);

       //获取根节点
           XmlNode root = xmlDoc.SelectSingleNode("UserInfo");
           XmlElement xment = xmlDoc.CreateElement("User");

    //创建节点
           XmlElement xmlname = xmlDoc.CreateElement("name");
           xmlname.InnerText = model.UserName;
           xment.AppendChild(xmlname);


           XmlElement xmlpwd = xmlDoc.CreateElement("pwd");
           xmlpwd.InnerText = model.Pwd;
           xment.AppendChild(xmlpwd);

           XmlElement xmlage = xmlDoc.CreateElement("age");
           xmlage.InnerText = model.Age;
           xment.AppendChild(xmlage);

           XmlElement xmlsex = xmlDoc.CreateElement("sex");
           xmlsex.InnerText = model.Sex;
           xment.AppendChild(xmlsex);

           root.AppendChild(xment);
           string strEx = xmlPath.Substring(6,xmlPath.Length-6);
           xmlDoc.Save(strEx);
          
       }

       //登录
       public bool IsLogin(User model)
       {
           List<string> list  = new List<string>();
           XmlDocument xmlDoc = new XmlDocument();
           xmlDoc.Load(xmlPath);

           XmlNode xmlNode = xmlDoc.SelectSingleNode("UserInfo");
           bool ft = false;
           foreach (XmlNode node in xmlNode)
           {

      //验证是否登录通过
               if (model.UserName.ToLower() == node.ChildNodes[0].InnerText.ToLower() && model.Pwd.ToLower()==node.ChildNodes[1].InnerText.ToLower())
               {
                   ft = true;
                   break;
               }
           }

           return ft;
       }



       //读取图像

       public List<string> LoadImg()
       {
           List<string> list = new List<string>();
           XmlDocument xmlDoc = new XmlDocument();
           xmlDoc.Load(xmlImgPath);
           XmlElement xmlEle = xmlDoc.DocumentElement;
         

           XmlNodeList xmlList = xmlEle.SelectNodes("Image/Items/Item");
           foreach (XmlNode node in xmlList)
           {
               list.Add(node.Attributes["src"].InnerXml.ToString());
           }
           return list;
       }

posted on 2011-01-30 17:29  共谱一曲  阅读(999)  评论(0编辑  收藏  举报