private void SaveButton_Click(object sender, RoutedEventArgs e) { CheckData(); if (oldPassOK && newPassOK && newPassConfirmOK) { DB.GetCurrentSession().changePassword(NewPassTextBox.Password); LoginDatabase loginDB = new LoginDatabase(); XmlSerializer xmlSerializer = new XmlSerializer(typeof(LoginDatabase)); using (StreamReader reader = new StreamReader("loginDetails.xml")) { loginDB = (LoginDatabase)xmlSerializer.Deserialize(reader); } foreach (Session user in loginDB.getExistingUsers()) { if (DB.GetCurrentSession().getUserID() == user.getUserID()) { user.changePassword(NewPassTextBox.Password); } } using (TextWriter writer = new StreamWriter("loginDetails.xml")) { xmlSerializer.Serialize(writer, loginDB); } DialogResult = true; this.Close(); } }
public void UpdateLoginDatabase(Staff newStaff) { LoginDatabase loginDB = new LoginDatabase(); XmlSerializer xmlSerializer = new XmlSerializer(typeof(LoginDatabase)); using (StreamReader reader = new StreamReader("loginDetails.xml")) { loginDB = (LoginDatabase)xmlSerializer.Deserialize(reader); } LoginDatabase newLoginDB = new LoginDatabase(); if (loginDB.getExistingUsers().Count != 0 && loginDB.getExistingUsers()[0].getUsername() == "admin") { newLoginDB.AddUser(loginDB.getExistingUsers()[0]); } else { newLoginDB.createAdminAccount(); } foreach (Staff staff in DB.GetListOfStaffMembers()) { bool staffAdded = false; foreach (Session user in loginDB.getExistingUsers()) { if (staff.getPersonID() == user.getUserID() && !staffAdded) { string username = staff.getFirstName() + "." + staff.getSurname() + staff.getPersonID().ToString(); if (username != user.getUsername()) { user.setUsername(username); user.changePassword("password"); } newLoginDB.AddUser(user); staffAdded = true; } } } Session newUser = new Session(newStaff); newLoginDB.AddUser(newUser); using (TextWriter writer = new StreamWriter("loginDetails.xml")) { xmlSerializer.Serialize(writer, newLoginDB); } }
private void WipeDataButton_Click(object sender, RoutedEventArgs e) { DB = new Database(); XmlSerializer xmlSerializer = new XmlSerializer(typeof(Database)); using (TextWriter writer = new StreamWriter("outputTest.xml")) { xmlSerializer.Serialize(writer, DB); } LoginDatabase loginDB = new LoginDatabase(); loginDB.createAdminAccount(); xmlSerializer = new XmlSerializer(typeof(LoginDatabase)); using (TextWriter writer = new StreamWriter("loginDetails.xml")) { xmlSerializer.Serialize(writer, loginDB); } }
public Login(Database data) { DB = data; loginDB = new LoginDatabase(); if (File.Exists("loginDetails.xml")) { XmlSerializer xmlSerializer = new XmlSerializer(typeof(LoginDatabase)); using (StreamReader reader = new StreamReader("loginDetails.xml")) { loginDB = (LoginDatabase)xmlSerializer.Deserialize(reader); } loginDB.createAdminAccount(); } else { loginDB.createAdminAccount(); } InitializeComponent(); }