if(System.IO.File.Exists("..//..//User.xml"))
{
XmlDocument doc = new XmlDocument();
XmlElement element = doc.CreateElement("UserAll");
doc.AppendChild(element);
XmlElement user = doc.CreateElement("User");
XmlElement name = doc.CreateElement("Name");
name.InnerText = Base64.Base64EnCdoe(textBox1.Text.Trim());
XmlElement password = doc.CreateElement("PassWord");
password.InnerText = Base64.Base64EnCdoe(textBox2.Text.Trim()); ;
user.AppendChild(name);
user.AppendChild(password);
element.AppendChild(user);
doc.Save("..//..//User.xml");
}
else
{
XmlDocument doc = new XmlDocument();
doc.Load("..//..//User.xml");
XmlNode root = doc.SelectSingleNode("UserAll");//查找
XmlNodeList nodes = root.ChildNodes;
int count = nodes.Count;
int i = 0;
foreach (XmlElement element in nodes)
{
if (element.ChildNodes[0].ChildNodes[0].InnerText ==Base64.Base64EnCdoe (textBox1.Text.Trim()))
{
element.ChildNodes[1].ChildNodes[0].InnerText =Base64.Base64EnCdoe (textBox2.Text.Trim());
i++;
break;
}
}
if (i == 0)
{
XmlElement user = doc.CreateElement("User");
XmlElement name = doc.CreateElement("Name");
name.InnerText =Base64.Base64EnCdoe (textBox1.Text.Trim());
XmlElement password = doc.CreateElement("PassWord");
password.InnerText =Base64 .Base64EnCdoe (textBox2.Text.Trim());
user.AppendChild(name);
user.AppendChild(password);
root.AppendChild(user);
}
doc.Save("..//..//User.xml");
}
{
textBox2.Text = "";
XmlDataDocument doc = new XmlDataDocument();
doc.Load("..//..//User.xml");
XmlNode root = doc.SelectSingleNode("UserAll");//查找
XmlNodeList nodes = root.ChildNodes;
int count = nodes.Count;
int i = 0;
foreach (XmlElement element in nodes)
{
if (element.ChildNodes[0].ChildNodes[0].InnerText == Base64.Base64EnCdoe(textBox1.Text.Trim()))
{
textBox2.Text = Base64.Base64DnCdoe(element.ChildNodes[1].ChildNodes[0].InnerText.ToString());
i++;
break;
}
}
}