private void btnRegisterNewUser_Click(object sender, EventArgs e) { QDAddUser addUser = new QDAddUser() { DBData = dbData }; if (addUser.ShowDialog() == DialogResult.OK) { try { mysql.ExecuteNonQueryACon("INSERT INTO qd_users (ID, Name, Username, Password) VALUES (?,?,?,?)", Guid.NewGuid(), addUser.DisplayName, addUser.Username, QDLib.HashPassword(addUser.Password) ); } catch { MessageBox.Show("Could not add new user. Please try again later.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } UpdateUsersSettings(); } }
private void EditSelectedUser() { if (lbxUserList.SelectedIndex != -1) { QDAddUser editUser = new QDAddUser { EditID = lbxUserList.SelectedValue.ToString(), DBData = dbData }; if (editUser.ShowDialog() == DialogResult.OK) { try { if (string.IsNullOrEmpty(editUser.Password)) { mysql.ExecuteNonQueryACon("UPDATE qd_users SET Name = ?, Username = ? WHERE ID = ?", editUser.DisplayName, editUser.Username, editUser.EditID ); } else { mysql.ExecuteNonQueryACon("UPDATE qd_users SET Name = ?, Username = ?, Password = ? WHERE ID = ?", editUser.DisplayName, editUser.Username, QDLib.HashPassword(editUser.Password), editUser.EditID ); } } catch { MessageBox.Show("Could not update user data. Please try again later.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } UpdateUsersSettings(); } } }