/// <summary> /// 修改普通用户密码 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button12_Click(object sender, EventArgs e) { if (this.lbNormal.SelectedIndex != -1) { string id = this.lbNormal.SelectedItem.ToString(); FormPassword fp = new FormPassword("管理员用户", id); fp.ShowDialog(); if (GlobalInfo.IsSetPSWFin == true) { string psw = fp.psw1; string path = "LoginPSW.xml"; XmlDocument xd = new XmlDocument(); xd.Load(path); XmlNode root = xd.DocumentElement; XmlNode normal = root.SelectSingleNode("normal");//选中normal节点 XmlNodeList normalxnl = normal.ChildNodes; foreach (XmlNode userxn in normalxnl) { if (userxn.Attributes["id"].Value == id) { userxn.Attributes["psw"].Value = psw; break; } } GlobalInfo.IsSetPSWFin = false; xd.Save(path); MessageBox.Show("更新成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("请选择对象!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
/// <summary> /// 添加普通用户 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button11_Click(object sender, EventArgs e) { FormPassword fp = new FormPassword("普通用户"); fp.ShowDialog(); if (GlobalInfo.IsSetPSWFin == true) { string id = fp.id; string psw = fp.psw1; if (false == CheckUserName(id)) { //添加至xml string path = "LoginPSW.xml"; XmlDocument xd = new XmlDocument(); xd.Load(path); XmlNode root = xd.DocumentElement; XmlNode normal = root.SelectSingleNode("normal"); //选中normal节点 XmlElement newxn = xd.CreateElement("user"); //新建节点 XmlAttribute xa = xd.CreateAttribute("id"); //用户名属性 xa.Value = id; XmlAttribute xa1 = xd.CreateAttribute("psw"); //密码属性 xa1.Value = psw; newxn.Attributes.Append(xa); //添加属性 newxn.Attributes.Append(xa1); normal.AppendChild(newxn);//向super中添加新的节点 xd.Save(path); LoadUser();//刷新列表 MessageBox.Show("更改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); GlobalInfo.IsSetPSWFin = false; } else { MessageBox.Show("用户已经存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }