public void InformationManageTest() { XmlOperator <User> xmlOperator = new XmlOperator <User>(); User user = new User(); user.Name = "张锦亮"; user.StudentId = 2016052355; user.Jwxtpassword = "******"; user.Major = "软件工程"; string filename = "User//User" + user.StudentId.ToString() + ".xml"; checkDir check = new checkDir(); check.check("User//"); xmlOperator.saveXML(filename, user); Assert.IsTrue(File.Exists(filename)); User resUser = xmlOperator.readXML(filename); Assert.AreEqual(user.Name, resUser.Name); Assert.AreEqual(user.Jwxtpassword, resUser.Jwxtpassword); Assert.AreEqual(user.Major, resUser.Major); }
private void modifyClick(object sender, EventArgs e) { User user = new User(); try { if (this.stuIDInput.Text.Length != 10) { MessageBox.Show("请输入正确学号"); return; } Regex regex = new Regex("[1-9][1-7][0-9][0-9]"); if (!regex.IsMatch(this.roomInput.Text)) { MessageBox.Show("请输入正确宿舍号"); return; } user.Name = this.nameInput.Text; user.Jwxtpassword = this.jwxtPasswordInput.Text; user.Major = this.majorInput.Text; user.School = this.schoolInput.Text; user.Password = this.passwordInput.Text; user.StudentId = int.Parse(this.stuIDInput.Text); user.RoomId = int.Parse(this.roomInput.Text); user.CardId = int.Parse(this.cardIDInput.Text); } catch (System.FormatException exception) { LogHelper.WriteLog(typeof(InformationManage), exception); MessageBox.Show("数字信息未完善"); return; } checkDir check = new checkDir(); check.check("User//"); xmlOperator.saveXML("User//User" + GlobalData.stuId + ".xml", user); GlobalData.user = user; LogHelper.WriteLog(typeof(InformationManage), "用户修改用户信息 " + user.ToString()); MessageBox.Show("修改成功!"); }