private int Update_Grant() { DataTable temp = (DataTable)Priv_dataGridView.DataSource; foreach (DataRow dr in temp.Rows) { if ((dr["COLUMN_NAME"].ToString().ToUpper() == "LUONG" || dr["COLUMN_NAME"].ToString().ToUpper() == "PHUCAP") && this.Table_name == "LUONG") { MessageBox.Show("CỘT " + dr["COLUMN_NAME"].ToString().ToUpper() + "ĐÃ ĐƯỢC MÃ HÓA, KHÔNG ĐƯỢC PHÉP ADD QUYỀN SELECT QUA APP!!", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Error); return(0); } } MainForm.Login_Form.conn.Open(); Oracle.revoke_priv(MainForm.Login_Form.conn, Table_name, MainForm.username, "UPDATE"); foreach (DataRow dr in temp.Rows) { if (Convert.ToBoolean(dr["ENABLED"])) { if (Convert.ToBoolean(dr["WITH GRANT OPTION"]) && MainForm.is_user) { Oracle.Grant_Update(MainForm.Login_Form.conn, dr["COLUMN_NAME"].ToString(), Table_name, MainForm.username, true); } else { Oracle.Grant_Update(MainForm.Login_Form.conn, dr["COLUMN_NAME"].ToString(), Table_name, MainForm.username, false); } } } MainForm.Login_Form.conn.Close(); return(1); }
private void Select_Grant() { MainForm.Login_Form.conn.Open(); DataTable temp = (DataTable)Priv_dataGridView.DataSource; string Grant_select_No_GrantOption_str = ""; string Grant_select_WithGrantOption_str = ""; // KHỞI TẠO RA STRING GỒM CÁC CỘT ĐỂ ĐƯỢC GRANT foreach (DataRow dr in temp.Rows) { Grant_select_No_GrantOption_str += dr["COLUMN_NAME"].ToString() + ','; if (Convert.ToBoolean(dr["WITH GRANT OPTION"])) { Grant_select_WithGrantOption_str += dr["COLUMN_NAME"].ToString() + ','; } } // BỎ KÍ TỰ ',' DƯ Grant_select_No_GrantOption_str = Grant_select_No_GrantOption_str.Remove(Grant_select_No_GrantOption_str.Length - 1, 1); // THỰC HIỆN GRANT Oracle.Create_View_Select(MainForm.Login_Form.conn, Table_name, Grant_select_No_GrantOption_str, MainForm.username, false); if (Grant_select_WithGrantOption_str != "") { // BỎ KÍ TỰ ',' DƯ Grant_select_WithGrantOption_str = Grant_select_WithGrantOption_str.Remove(Grant_select_WithGrantOption_str.Length - 1, 1); Oracle.Create_View_Select(MainForm.Login_Form.conn, Table_name, Grant_select_WithGrantOption_str, MainForm.username, true); } MessageBox.Show(Grant_select_No_GrantOption_str); MessageBox.Show(Grant_select_WithGrantOption_str); MainForm.Login_Form.conn.Close(); }
private void Delete_Grant() { DataTable temp = (DataTable)Priv_dataGridView.DataSource; foreach (DataRow dr in temp.Rows) { string table_name = dr["OWNER"].ToString() + "." + dr["TABLE_NAME"].ToString(); Oracle.revoke_priv(MainForm.Login_Form.conn, table_name, MainForm.username, "DELETE"); } foreach (DataRow dr in temp.Rows) { if (Convert.ToBoolean(dr["ENABLED"])) { string table_name = dr["OWNER"].ToString() + "." + dr["TABLE_NAME"].ToString();; if (Convert.ToBoolean(dr["WITH GRANT OPTION"])) { Oracle.Grant_Delete(MainForm.Login_Form.conn, table_name, MainForm.username, true); } else { Oracle.Grant_Delete(MainForm.Login_Form.conn, table_name, MainForm.username, false); } } } }
public Choose_Table(ChucNang_form form, string Priv_Type) { this.Priv_Type = Priv_Type; MainForm = form; InitializeComponent(); label1.Text = "CHON BANG DE GRANT QUYEN " + Priv_Type + ": "; All_Table_dataGridView.DataSource = Oracle.Get_All_Table(MainForm.Login_Form.conn); All_Table_dataGridView.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; All_Table_dataGridView.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; All_Table_dataGridView.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; }
private void Add_Role_button_Click(object sender, EventArgs e) { try { Oracle.CreateRole(MainForm.Login_Form.conn, Role_name_textBox.Text, Role_password_textbox.Text); MessageBox.Show("ĐA TAO ROLE " + Role_name_textBox.Text + " THANH CONG!!", "Succeed", MessageBoxButtons.OK, MessageBoxIcon.Information); MainForm.GetRoles(); this.Close(); } catch (Exception ex) { MessageBox.Show("ERROR:" + ex.Message, "Fail", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void Add_User_button_Click(object sender, EventArgs e) { try { Oracle.CreateUser(MainForm.Login_Form.conn, UserName_textBox.Text, Password_textBox.Text); MessageBox.Show("ĐA TAO USER " + UserName_textBox.Text + " THANH CONG!!", "Succeed", MessageBoxButtons.OK, MessageBoxIcon.Information); MainForm.GetUsers(); this.Close(); } catch (Exception ex) { MessageBox.Show("ERROR:" + ex.Message, "Fail", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private int Select_Grant() { DataTable temp = (DataTable)Priv_dataGridView.DataSource; string Grant_select_No_GrantOption_str = ""; string Grant_select_WithGrantOption_str = ""; // NẾU CHỌN VÀO NHỮNG CỘT BỊ MÃ HÓA THÌ THỰC HIỆN NGƯNG QUI TRÌNH VÀ HIỆN LỖI foreach (DataRow dr in temp.Rows) { if ((dr["COLUMN_NAME"].ToString().ToUpper() == "LUONG" || dr["COLUMN_NAME"].ToString().ToUpper() == "PHUCAP") && this.Table_name == "LUONG") { MessageBox.Show("CỘT " + dr["COLUMN_NAME"].ToString().ToUpper() + "ĐÃ ĐƯỢC MÃ HÓA, KHÔNG ĐƯỢC PHÉP ADD QUYỀN SELECT QUA APP!!", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Error); return(0); } } MainForm.Login_Form.conn.Open(); // THỰC HIỆN DROP HẾT QUYỀN SELECT CỦA USER CÓ THỂ CÓ TRÊN OBJECT TUONG ỨNG Oracle.Drop_View(MainForm.Login_Form.conn, Table_name, MainForm.username); // KHỞI TẠO RA STRING GỒM CÁC CỘT ĐỂ ĐƯỢC GRANT foreach (DataRow dr in temp.Rows) { if (Convert.ToBoolean(dr["ENABLED"])) { Grant_select_No_GrantOption_str += dr["COLUMN_NAME"].ToString() + ','; if (Convert.ToBoolean(dr["WITH GRANT OPTION"]) && MainForm.is_user) { Grant_select_WithGrantOption_str += dr["COLUMN_NAME"].ToString() + ','; } } } if (Grant_select_No_GrantOption_str != "") { // BỎ KÍ TỰ ',' DƯ Grant_select_No_GrantOption_str = Grant_select_No_GrantOption_str.Remove(Grant_select_No_GrantOption_str.Length - 1, 1); // THỰC HIỆN GRANT Oracle.Create_View_Select(MainForm.Login_Form.conn, Table_name, Grant_select_No_GrantOption_str, MainForm.username, false); } if (Grant_select_WithGrantOption_str != "") { // BỎ KÍ TỰ ',' DƯ Grant_select_WithGrantOption_str = Grant_select_WithGrantOption_str.Remove(Grant_select_WithGrantOption_str.Length - 1, 1); Oracle.Create_View_Select(MainForm.Login_Form.conn, Table_name, Grant_select_WithGrantOption_str, MainForm.username, true); } //MessageBox.Show(Grant_select_No_GrantOption_str); //MessageBox.Show(Grant_select_WithGrantOption_str); MainForm.Login_Form.conn.Close(); return(1); }
private void ChonRole_button_Click(object sender, EventArgs e) { tabControl2.TabPages.Remove(RoleTab); string role = role_comboBox.Text; is_user = false; this.username = role_comboBox.Text; NAME_label.Text = "ROLE " + role; // Select DataTable ret = Oracle.GetAllPriv(Login_Form.conn, role); Priv_Preprocessing(ret); Select_User_dataGridView1.DataSource = ret; }
private void button1_Click(object sender, EventArgs e) { try { string username = f_DangNhap_Username_textbox.Text; string password = f_DangNhap_Password_textbox.Text; //Oracle db = new Oracle(); //MainForm = new ChucNang_form(); conn = Oracle.CreateDBConnection(username, password); LogedIn_Username = username; //MainForm.username = f_DangNhap_Username_textbox.Text; MessageBox.Show("Da dang nhap voi username:"******"Error: " + er); } }
private void ChonUser_button_Click(object sender, EventArgs e) { if (tabControl2.TabCount < 2) { tabControl2.TabPages.Add(RoleTab); } this.username = user_comboBox.Text; string username = user_comboBox.Text; is_user = true; NAME_label.Text = "USER " + username; // Select DataTable ret = Oracle.GetAllPriv(Login_Form.conn, username); //DataTable ret2 = Oracle.GetRemain_One_User(Login_Form.conn, username, "SELECT"); Priv_Preprocessing(ret); Select_User_dataGridView1.DataSource = ret; // ROLE ret = Oracle.GetRoleGrantedToUser(Login_Form.conn, username); RoleGrantedToUser_dataGridView.DataSource = ret; }
private int Delete_Grant() { DataTable temp = (DataTable)Priv_dataGridView.DataSource; // CHECK XEM CÓ BẢNG NÀO THUỘC DẠNG EXCEPTION KHÔNG, NẾU CÓ BÁO ERROR (DO CHƯA CÓ CÁCH XỬ LÍ) foreach (DataRow dr in temp.Rows) { if (Convert.ToBoolean(dr["ENABLED"]) && dr["TABLE_NAME"].ToString() == "LUONG") { MessageBox.Show("BANG " + dr["TABLE_NAME"].ToString().ToUpper() + "ĐÃ ĐƯỢC MÃ HÓA, KHÔNG ĐƯỢC PHÉP ADD QUYỀN SELECT QUA APP!!", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Error); return(0); } } MainForm.Login_Form.conn.Open(); foreach (DataRow dr in temp.Rows) { string table_name = dr["OWNER"].ToString() + "." + dr["TABLE_NAME"].ToString(); Oracle.revoke_priv(MainForm.Login_Form.conn, table_name, MainForm.username, "DELETE"); } foreach (DataRow dr in temp.Rows) { if (Convert.ToBoolean(dr["ENABLED"]) && MainForm.is_user) { string table_name = dr["OWNER"].ToString() + "." + dr["TABLE_NAME"].ToString();; if (Convert.ToBoolean(dr["WITH GRANT OPTION"])) { Oracle.Grant_Delete(MainForm.Login_Form.conn, table_name, MainForm.username, true); } else { Oracle.Grant_Delete(MainForm.Login_Form.conn, table_name, MainForm.username, false); } } } MainForm.Login_Form.conn.Close(); return(1); }
private void Update_Grant() { MainForm.Login_Form.conn.Open(); DataTable temp = (DataTable)Priv_dataGridView.DataSource; Oracle.revoke_priv(MainForm.Login_Form.conn, Table_name, MainForm.username, "UPDATE"); foreach (DataRow dr in temp.Rows) { if (Convert.ToBoolean(dr["ENABLED"])) { if (Convert.ToBoolean(dr["WITH GRANT OPTION"])) { Oracle.Grant_Update(MainForm.Login_Form.conn, dr["COLUMN_NAME"].ToString(), Table_name, MainForm.username, true); } else { Oracle.Grant_Update(MainForm.Login_Form.conn, dr["COLUMN_NAME"].ToString(), Table_name, MainForm.username, false); } } } }
public Choose_Priv(ChucNang_form form, string Priv_Type, string table_name = "") { MainForm = form; this.Priv_type = Priv_Type; this.Table_name = table_name; InitializeComponent(); label1.Text = "CHON PRIVILEGES " + Priv_Type + " DE GRANT CHO USER TRONG BANG " + table_name + ": "; if (Priv_Type == "SELECT" || Priv_Type == "UPDATE") //SELECT, UPDATE { name_without_owner = table_name.Split('.')[1]; //name_without_owner = table_name.Split('.')[1]; DataTable Col = Oracle.Get_All_Col(MainForm.Login_Form.conn, name_without_owner); Col.Columns.Add("ENABLED", Type.GetType("System.Boolean")); Col.Columns.Add("WITH GRANT OPTION", Type.GetType("System.Boolean")); foreach (DataRow dr1 in Col.Rows) { dr1["WITH GRANT OPTION"] = false; dr1["ENABLED"] = false; } DataTable Priv_user = Oracle.GetPriv_One_User_2(MainForm.Login_Form.conn, MainForm.username, Priv_Type, name_without_owner); if (Priv_Type == "SELECT") { Select_Priv_Preprocessing(Priv_user); } foreach (DataRow dr in Priv_user.Rows) { foreach (DataRow dr1 in Col.Rows) { if (dr["COLUMN_NAME"].ToString() == dr1["COLUMN_NAME"].ToString()) { if (dr["GRANTABLE"].ToString() == "NO") { dr1["WITH GRANT OPTION"] = false; } else { dr1["WITH GRANT OPTION"] = true; } dr1["ENABLED"] = true; break; } } } Priv_dataGridView.DataSource = Col; } else // INSERT, DELETE { //string name = MainForm.username; DataTable All_tables = Oracle.Get_All_Table(MainForm.Login_Form.conn); All_tables.Columns.Add("ENABLED", Type.GetType("System.Boolean")); All_tables.Columns.Add("WITH GRANT OPTION", Type.GetType("System.Boolean")); foreach (DataRow dr1 in All_tables.Rows) { dr1["WITH GRANT OPTION"] = false; dr1["ENABLED"] = false; } DataTable Priv_user = Oracle.GetPriv_One_User_2(MainForm.Login_Form.conn, MainForm.username, Priv_Type, table_name); foreach (DataRow dr in Priv_user.Rows) { foreach (DataRow dr1 in All_tables.Rows) { if (dr["OBJECT_NAME"].ToString() == dr1["TABLE_NAME"].ToString() && dr["OWNER"].ToString() == dr1["OWNER"].ToString()) { if (dr["GRANTABLE"].ToString() == "NO") { dr1["WITH GRANT OPTION"] = false; } else { dr1["WITH GRANT OPTION"] = true; } dr1["ENABLED"] = true; break; } } } Priv_dataGridView.DataSource = All_tables; //DataTable User_Priv = Oracle.GetPriv_One_User_2(MainForm.Login_Form.conn, name, ); } }
private void GetRoles() { role_comboBox.DataSource = Oracle.GetAllRoles(Login_Form.conn); }
private void Chon_Type_button_Click(object sender, EventArgs e) { Object_dataGridView.DataSource = Oracle.Get_Object(Login_Form.conn, Object_Type_comboBox.Text); }
private void button1_Click(object sender, EventArgs e) { try { string username = f_DangNhap_Username_textbox.Text; username = username.ToLower(); string password = f_DangNhap_Password_textbox.Text; //Oracle db = new Oracle(); //MainForm = new ChucNang_form(); LogedIn_Username = username; //MainForm.username = f_DangNhap_Username_textbox.Text; //MessageBox.Show("Da dang nhap voi username:"******"sy") == true || username.StartsWith("dba") == true) { conn = Oracle.CreateDBConnection(username, password); ChucNang_form MainFrom = new ChucNang_form(this); MainFrom.Show(); } if (username.StartsWith("tt") == true) { conn = TiepTan.CreateDBConnection(username, password); try { // conn.Open(); FormTiepTan tieptan = new FormTiepTan(this); tieptan.Show(); } catch { MessageBox.Show("Đăng nhập thất bại!"); } } if (username.StartsWith("kt") == true) { conn = Oracle.CreateDBConnection(username, password); conn.Open(); FormKeToan ketoan = new FormKeToan(this); ketoan.Show(); } if (username.StartsWith("bs") == true) { conn = BacSi.CreateDBConnection(username, password); try { conn.Open(); FormBacSi bacsi = new FormBacSi(this); bacsi.Show(); } catch { MessageBox.Show("Đăng nhập thất bại!"); } } if (username.StartsWith("bt") == true) { conn = BacSi.CreateDBConnection(username, password); try { FormBanThuoc bt = new FormBanThuoc(this); bt.Show(); } catch { MessageBox.Show("Đăng nhập thất bại!"); } } if (username.StartsWith("tv") == true) { conn = TaiVu.CreateDBConnection(username, password); try { conn.Open(); FormTaiVu f_tv = new FormTaiVu(this); f_tv.Show(); //this.Hide(); } catch (Exception ex) { MessageBox.Show("Đăng nhập thất bại!"); } } if (username.StartsWith("ql002") == true) { conn = TaiVu.CreateDBConnection(username, password); try { conn.Open(); FormQuanLiTaiVu f_qltv = new FormQuanLiTaiVu(this); f_qltv.Show(); //this.Hide(); } catch (Exception ex) { MessageBox.Show("Đăng nhập thất bại!"); } } if (username.StartsWith("ql001") == true) { conn = QuanLy.CreateDBConnection(username, password); try { conn.Open(); QLTNNS f_qltnns = new QLTNNS(this); f_qltnns.Show(); //this.Hide(); } catch (Exception ex) { MessageBox.Show("Đăng nhập thất bại!"); } } if (username.StartsWith("ql003") == true) { conn = QuanLy.CreateDBConnection(username, password); try { conn.Open(); QLCM f_qlcm = new QLCM(this); f_qlcm.Show(); //this.Hide(); } catch (Exception ex) { MessageBox.Show("Đăng nhập thất bại!"); } } } catch (Exception er) { MessageBox.Show("Error: " + er); } }
private void GetUsers() { user_comboBox.DataSource = Oracle.GetAllUsers(Login_Form.conn); }
private void GetObjectType() { Object_Type_comboBox.DataSource = Oracle.Get_object_type(Login_Form.conn); }