private void btnEditRoleUser_Click(object sender, EventArgs e) { OracleDataController.ConnectDB(FormLogin.connectionStr); string query = null; if (comboEditUserInfor.SelectedIndex != -1) { if (comboOldRole.Items.Count > 0) { query = "revoke " + comboOldRole.Text + " from " + comboEditUserInfor.SelectedItem.ToString(); bool checkIsRevoke = OracleDataController.Revoke(query); if (checkIsRevoke) { MessageBox.Show("Revoke role successfully!"); } } query = "grant " + comboEditNewRole.SelectedItem.ToString() + " to " + comboEditUserInfor.SelectedItem.ToString(); bool checkIsGrant = OracleDataController.Grant(query); if (checkIsGrant) { MessageBox.Show("Grant role successfully!"); } } }
private void btnEditPriInCol_Click(object sender, EventArgs e) { string grantTo = ""; if (checkBoxPriUserInCol.Checked) { grantTo = comboEditPriInColRole.SelectedItem.ToString(); comboEditPriInColUser.Enabled = false; } else if (checkBoxPriRoleInCol.Checked) { grantTo = comboEditPriInColUser.SelectedItem.ToString(); comboEditPriInColRole.Enabled = false; } string queryGrantInColumn = String.Format("GRANT {0}({1}) ON {2} TO {3}" , comboEditPriInColPri.SelectedItem.ToString(), comboEditPriInColCol.SelectedItem.ToString(), comboEditPrivInColTable.SelectedItem.ToString(), grantTo); OracleDataController.ConnectDB(FormLogin.connectionStr); bool checkIfGrant = OracleDataController.Grant(queryGrantInColumn); if (checkIfGrant) { MessageBox.Show("Grant in column successfully!"); } else { MessageBox.Show("Grant in column failed!"); return; } }
// Revoke privileges from user/role private void button1_Click(object sender, EventArgs e) { string revokeTo = ""; comboWithGrantOption.Enabled = false; if (checkBoxUserPri.Checked) { revokeTo = comboEditPriviRole.SelectedItem.ToString(); comboEditPrivUser.Enabled = false; if (comboEditPriviRole.SelectedIndex == -1) { MessageBox.Show("You didn't choose the role yet!"); return; } } else if (checkBoxRolePri.Checked) { revokeTo = comboEditPrivUser.SelectedItem.ToString(); comboEditPriviRole.Enabled = false; if (comboEditPrivUser.SelectedIndex == -1) { MessageBox.Show("You didn't choose the user yet!"); return; } } if (comboPrivi.SelectedIndex == -1) { MessageBox.Show("You didn't choose the privilege yet!"); return; } if (comboTargetObj.SelectedIndex == -1) { MessageBox.Show("You didn't choose the target object yet!"); return; } string pri = comboPrivi.SelectedItem.ToString(); string targetObj = comboTargetObj.SelectedItem.ToString(); string queryGrantPri = "revoke " + pri + " on " + targetObj + " from " + revokeTo; OracleDataController.ConnectDB(FormLogin.connectionStr); bool checkIsGrant = OracleDataController.Grant(queryGrantPri); if (checkIsGrant) { MessageBox.Show("Revoke privilege successfully!"); } }
private void btnEditPrivi_Click(object sender, EventArgs e) { string grantOption = ""; string grantTo = ""; if (checkBoxUserPri.Checked) { grantTo = comboEditPriviRole.SelectedItem.ToString(); comboEditPrivUser.Enabled = false; grantOption = "NO"; if (comboEditPriviRole.SelectedIndex == -1) { MessageBox.Show("You didn't choose the role yet!"); return; } } else if (checkBoxRolePri.Checked) { grantTo = comboEditPrivUser.SelectedItem.ToString(); comboEditPriviRole.Enabled = false; if (comboEditPrivUser.SelectedIndex == -1) { MessageBox.Show("You didn't choose the user yet!"); return; } } if (comboPrivi.SelectedIndex == -1) { MessageBox.Show("You didn't choose the privilege yet!"); return; } if (comboTargetObj.SelectedIndex == -1) { MessageBox.Show("You didn't choose the target object yet!"); return; } if (comboWithGrantOption.SelectedIndex == -1) { MessageBox.Show("You didn't choose the with grant option field yet!"); return; } else { if (comboWithGrantOption.SelectedItem.ToString().Equals("NO")) { grantOption = ""; } else { grantOption = " WITH GRANT OPTION"; } } string pri = comboPrivi.SelectedItem.ToString(); string targetObj = comboTargetObj.SelectedItem.ToString(); string queryGrantPri = "grant " + pri + " on " + targetObj + " to " + grantTo + grantOption;; OracleDataController.ConnectDB(FormLogin.connectionStr); bool checkIsGrant = OracleDataController.Grant(queryGrantPri); if (checkIsGrant) { MessageBox.Show("Grant privilege successfully!"); } }