private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e) { try { //GRANT MỊN TRÊN CỘT, FLAG == 3 LÀ USER, FLAG == 4 LÀ ROLE if (flag == 3 || flag == 4) { // grant update(malichtruc) on lichtruc to ACCMASTER; // dataGridView2[4, e.RowIndex].Value.ToString() if (e.ColumnIndex == 0) //SELECT { List <string> kq = get_CurrentViewStatus(); if (kq.Contains(dataGridView2[4, e.RowIndex].Value.ToString())) { DialogResult res = MessageBox.Show("DA TON TAI VIEW VOI QUYEN NAY. REVOKE?", "REVOKE?", MessageBoxButtons.YesNo); if (res == DialogResult.Yes) { kq.Remove(dataGridView2[4, e.RowIndex].Value.ToString()); string query_revoke = "CREATE OR REPLACE VIEW " + (flag == 3 ? Cur_user : Cur_role) + "_" + tableName + " as " + "select "; for (int i = 1; i < kq.Count - 1; i++) { query_revoke += kq[i] + ", "; } query_revoke += kq[kq.Count - 1]; query_revoke += " from " + tableName; DBUtils dbu = new DBUtils(); if (kq.Count == 1) { query_revoke = "DROP VIEW " + (flag == 3 ? Cur_user : Cur_role) + "_" + tableName; } MessageBox.Show(query_revoke); if (dbu.ExecuteNonQuery(query_revoke)) { MessageBox.Show("REVOKE THANH CONG"); privcs.loadDT(); if (flag == 1 || flag == 3) { privcs.LoadUserObjPriv_gridView(); } if (flag == 2 || flag == 4) { privcs.LoadRoleObjPriv_gridView(); } return; } MessageBox.Show("REVOKE THAT BAI"); } return; } kq.Add(dataGridView2[4, e.RowIndex].Value.ToString()); string query = " VIEW " + (flag == 3 ? Cur_user : Cur_role) + "_" + tableName + " as " + "select "; for (int i = 1; i < kq.Count - 1; i++) { query += kq[i] + ", "; } query += kq[kq.Count - 1]; query += " from " + tableName; grant_revoke_objectPriv grant_Revoke_ObjectPriv = new grant_revoke_objectPriv(this, privcs, query, Cur_user, Cur_role, (flag == 4 ? 6 : 5), tableName); grant_Revoke_ObjectPriv.ShowDialog(); } if (e.ColumnIndex == 1 || e.ColumnIndex == 2) { MessageBox.Show("KHONG HO TRO INSERT VA DELETE MIN TREN COT"); return; } if (e.ColumnIndex == 3) //UPDATE { string query = " UPDATE(" + dataGridView2[4, e.RowIndex].Value.ToString() + ") on " + tableName; grant_revoke_objectPriv grant_Revoke_ObjectPriv = new grant_revoke_objectPriv(this, privcs, query, Cur_user, Cur_role, flag); grant_Revoke_ObjectPriv.ShowDialog(); } } else { if (e.ColumnIndex == 0) //SELECT { string query = " SELECT ON " + dataGridView2[5, e.RowIndex].Value.ToString() + "." + dataGridView2[4, e.RowIndex].Value.ToString(); grant_revoke_objectPriv grant_Revoke_ObjectPriv = new grant_revoke_objectPriv(this, privcs, query, Cur_user, Cur_role, (flag == 2 ? 4 : 3)); grant_Revoke_ObjectPriv.ShowDialog(); } if (e.ColumnIndex == 1) //INSERT { string query = " INSERT ON " + dataGridView2[5, e.RowIndex].Value.ToString() + "." + dataGridView2[4, e.RowIndex].Value.ToString(); grant_revoke_objectPriv grant_Revoke_ObjectPriv = new grant_revoke_objectPriv(this, privcs, query, Cur_user, Cur_role, (flag == 2 ? 4 : 3)); grant_Revoke_ObjectPriv.ShowDialog(); } if (e.ColumnIndex == 2) //DELETE { string query = " DELETE ON " + dataGridView2[5, e.RowIndex].Value.ToString() + "." + dataGridView2[4, e.RowIndex].Value.ToString(); grant_revoke_objectPriv grant_Revoke_ObjectPriv = new grant_revoke_objectPriv(this, privcs, query, Cur_user, Cur_role, (flag == 2 ? 4 : 3)); grant_Revoke_ObjectPriv.ShowDialog(); } if (e.ColumnIndex == 3) //UPDATE { string query = " UPDATE ON " + dataGridView2[5, e.RowIndex].Value.ToString() + "." + dataGridView2[4, e.RowIndex].Value.ToString(); grant_revoke_objectPriv grant_Revoke_ObjectPriv = new grant_revoke_objectPriv(this, privcs, query, Cur_user, Cur_role, (flag == 2 ? 4 : 3)); grant_Revoke_ObjectPriv.ShowDialog(); } } } catch (Exception ex) { return; } }
private void button1_Click(object sender, EventArgs e) { if (flag != 5 && flag != 6) { q = qq; q = "GRANT" + q + " TO " + ((flag == 3) ? cUser : cRole); DialogResult res = MessageBox.Show("WITH GRANT OPTION?", "Grant option", MessageBoxButtons.YesNo); if (res == DialogResult.Yes) { q = q + " with grant option"; } MessageBox.Show(q); DBUtils dbu = new DBUtils(); if (dbu.ExecuteNonQuery(q)) { MessageBox.Show("GRANT THANH CONG"); papaformpriv.loadDT(); if (flag == 1 || flag == 3) { papaformpriv.LoadUserObjPriv_gridView(); } else { papaformpriv.LoadRoleObjPriv_gridView(); } this.Close(); return; } MessageBox.Show("GRANT THAT BAI"); } else { q = qq; q = "CREATE OR REPLACE " + q; string qGrant = "GRANT SELECT ON " + ((flag == 5) ? cUser : cRole) + "_" + tabName + " TO " + ((flag == 5) ? cUser : cRole); DialogResult res = MessageBox.Show("WITH GRANT OPTION?", "Grant option", MessageBoxButtons.YesNo); if (res == DialogResult.Yes) { qGrant = qGrant + " with grant option"; } MessageBox.Show(q); MessageBox.Show(qGrant); DBUtils dbu = new DBUtils(); if (dbu.ExecuteNonQuery(q)) { DBUtils dbu1 = new DBUtils(); if (dbu1.ExecuteNonQuery(qGrant)) { MessageBox.Show("GRANT THANH CONG"); } papaformpriv.loadDT(); if (flag == 5) { papaformpriv.LoadUserObjPriv_gridView(); } if (flag == 6) { papaformpriv.LoadRoleObjPriv_gridView(); } this.Close(); return; } MessageBox.Show("GRANT THAT BAI"); } }