private void OnCreate(object sender, EventArgs e) { if (String.IsNullOrWhiteSpace(tbLogin.Text)) { MessageBox.Show("You must specify a login name.", "Create Login Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (String.IsNullOrWhiteSpace(tbPassword.Text)) { MessageBox.Show("You must specify a password.", "Create Login Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (tbPassword.Text != tbConfirm.Text) { MessageBox.Show("The password don't match.", "Create Login Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { LoginQueries.CreateLogin(LoginInformation.Server, LoginInformation.User, LoginInformation.Password, tbLogin.Text, tbPassword.Text); LoginName = tbLogin.Text; this.DialogResult = System.Windows.Forms.DialogResult.OK; this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Create Login Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public CreateUser(string currentDB) { InitializeComponent(); var logins = LoginQueries.GetLogins(LoginInformation.Server, LoginInformation.User, LoginInformation.Password); cbLogins.Items.AddRange(logins.ToArray()); CurrentDatabase = currentDB; if (CurrentDatabase == "master") { clbRoles.Items.Add("loginmanager"); clbRoles.Items.Add("dbmanager"); } else { clbRoles.Items.Add("db_owner"); clbRoles.Items.Add("db_securityadmin"); clbRoles.Items.Add("db_accessadmin"); clbRoles.Items.Add("db_backupoperator"); clbRoles.Items.Add("db_ddladmin"); clbRoles.Items.Add("db_datawriter"); clbRoles.Items.Add("db_datareader"); clbRoles.Items.Add("db_denydatawriter"); clbRoles.Items.Add("db_denydatareader"); } }
private void OnRename(object sender, EventArgs e) { if (listView1.SelectedItems.Count > 0) { try { LoginQueries.CreateLogin(LoginInformation.Server, LoginInformation.User, LoginInformation.Password, "megatest", "newmgt"); } catch (Exception ex) { MessageBox.Show(ex.Message, "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void OnDelete(object sender, EventArgs e) { if (listView1.SelectedItems.Count > 0) { if (MessageBox.Show("Are you sure you want to drop this login?", "Drop Login", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { try { LoginQueries.DeleteLogin(LoginInformation.Server, LoginInformation.User, LoginInformation.Password, listView1.SelectedItems[0].Text); listView1.Items.Remove(listView1.SelectedItems[0]); } catch (Exception ex) { MessageBox.Show(ex.Message, "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
public void RefreshView() { listView1.Items.Clear(); try { var logins = LoginQueries.GetLogins(LoginInformation.Server, LoginInformation.User, LoginInformation.Password); foreach (var item in logins) { listView1.Items.Add(item.Name, 0); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Class for all the methods that control the login proccess, injects the database /// </summary> public LoginController(IDBConnect _connection) { loginQueries = new LoginQueries(_connection); }