private void DeleteUser() { if (!File.Exists("users.xml")) { File.Create("users.xml"); } var usersInXml = File.ReadAllText("users.xml"); List <User> usersFromXML = new XMLProvider().XMLToUsers(usersInXml); int selectedRow; try { selectedRow = dataGridView1.SelectedRows[0].Index; } catch (Exception) { return; } if (selectedRow >= usersFromXML.Count || selectedRow < 0) { return; } var userToRemove = usersFromXML.First(i => i.ID == (int)dataGridView1.Rows[selectedRow].Cells[3].Value); usersFromXML.Remove(userToRemove); var newXML = new XMLProvider().UsersToXML(usersFromXML); File.WriteAllText("users.xml", newXML); Reload(); }
private void buttonEdit_Click(object sender, EventArgs e) { int selectedRow; try { selectedRow = dataGridView1.SelectedRows[0].Index; } catch (Exception) { return; } if (!File.Exists("users.xml")) { File.Create("users.xml"); } var usersInXml = File.ReadAllText("users.xml"); List <User> usersFromXML = new XMLProvider().XMLToUsers(usersInXml); User selected = usersFromXML[selectedRow]; var AddUserForm = new AddUserForm(selected); AddUserForm.Show(); DeleteUser(); Reload(); }
private void buttonAddUser_Click(object sender, EventArgs e) { // create user var user = new User { Name = textBoxName.Text, Surname = textBoxSurname.Text, Street = textBoxStreet.Text }; // load users if (!File.Exists("users.xml")) { File.Create("users.xml"); } var usersInXml = File.ReadAllText("users.xml"); var usersFromXML = new XMLProvider().XMLToUsers(usersInXml) ?? new List <User>(); user.ID = usersFromXML.Count == 0 ? 1 : usersFromXML.Max(f => f.ID) + 1; usersFromXML.Add(user); // add user // new file (include all users) var newXML = new XMLProvider().UsersToXML(usersFromXML); File.WriteAllText("users.xml", newXML); Close(); }
private void buttonLogin_Click(object sender, EventArgs e) { //Fake Users Creator King (F**K) v1.0 //var newAdmin = new UsersLogin(); //newAdmin.Login = "******"; //newAdmin.Password = "******"; //newAdmin.Role = "admin"; //new XMLProvider().AddLoginToXML(newAdmin); //for (int i = 0; i < 10; i++) //{ // newAdmin = new UsersLogin(); // newAdmin.Login = "******" + i; // newAdmin.Password = "******" + i; // newAdmin.Role = "postman"; // new XMLProvider().AddLoginToXML(newAdmin); //} // =================================== var login = textBoxLogin.Text; var password = textBoxPassword.Text; var role = new XMLProvider().Login(login, password); IMessageProvider messages = new MessageBoxProvider(); switch (role.Role) { case "admin": messages.SendMessage("Logged in as admin " + login); new UserManageForm().Show(); break; case "postman": messages.SendMessage("Logged in as postman " + login); new MainForm().Show(); break; case "user": messages.SendMessage("Logged in as user " + login); new ClientView(role.ID); break; default: // "register" :D var newUser = new UsersLogin(); newUser.Login = login; newUser.Password = password; newUser.Role = "user"; new XMLProvider().AddLoginToXML(newUser); messages.SendMessage("New user has been created. You can login as this user."); break; } }
private void Reload() { if (!File.Exists("users.xml")) { File.Create("users.xml"); } var usersInXml = File.ReadAllText("users.xml"); List <User> usersFromXML = new XMLProvider().XMLToUsers(usersInXml); dataGridView1.Rows.Clear(); if (usersFromXML != null) { foreach (var user in usersFromXML) { dataGridView1.Rows.Add(user.Name, user.Surname, user.Street, user.ID); } } }
private void buttonSearch_Click(object sender, EventArgs e) { var searchOption = textBoxSearch.Text; if (!File.Exists("users.xml")) { File.Create("users.xml"); } var usersInXml = File.ReadAllText("users.xml"); List <User> usersFromXML = new XMLProvider().XMLToUsers(usersInXml); usersFromXML = usersFromXML.Where(f => f.Name.Contains(searchOption) || f.Surname.Contains(searchOption)).ToList(); dataGridView1.Rows.Clear(); if (usersFromXML != null) { foreach (var user in usersFromXML) { dataGridView1.Rows.Add(user.Name, user.Surname, user.Street, user.ID); } } }