Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using Oracle.DataAccess.Client;
- namespace quiz
- {
- public partial class Admin : Form
- {
- public Admin()
- {
- InitializeComponent();
- }
- private void felhasznDel()
- {
- try
- {
- string ConString = "Data Source=IDE KELL AZ ADATBÁZIS NEVE;User Id=IDE KELL AZ ADATBÁZIS FELHASZNÁLÓNÉV;Password=IDE KELL AZ ADATBÁZIS JELSZÓ;";
- using (OracleConnection con = new OracleConnection(ConString))
- {
- con.Open();
- OracleCommand felhTorol = new OracleCommand("create or replace "+
- "trigger update_nev "+
- "before delete "+
- "on "+
- "felhasznalo "+
- "for each row "+
- "declare "+
- "begin "+
- "delete szemelyes "+
- "where username = :old.username; "+
- "delete eredmeny "+
- "where username = :old.username; "+
- "delete uzenofal "+
- "where username = :old.username; "+
- "delete toplista "+
- "where username = :old.username; " +
- "end;", con);
- OracleCommand cmd1 = new OracleCommand("update_nev", con);
- OracleDataAdapter triggerDel = new OracleDataAdapter(felhTorol);
- cmd1.CommandType = CommandType.Text;
- DataSet ds = new DataSet();
- triggerDel.Fill(ds);
- con.Close();
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.ToString());
- }
- }
- private void torolProc()
- {
- felhasznDel();
- try
- {
- string ConString = "Data Source=XE;User Id=dorab;Password=dorab;";
- using (OracleConnection con = new OracleConnection(ConString))
- {
- con.Open();
- OracleCommand proc1 = new OracleCommand("create or replace "+
- "procedure update_nev( "+
- "nev varchar2 default '-' "+
- ") "+
- "as "+
- "begin "+
- "update uzenofal "+
- "set username = 'TOROLT_USER' "+
- "where username = nev; "+
- "update eredmeny "+
- "set username = 'TOROLT_USER' "+
- "where username = nev; "+
- "update toplista "+
- "set username = 'TOROLT_USER' "+
- "where username = nev; " +
- "end;", con);
- OracleCommand cmd1 = new OracleCommand("update_nev", con);
- OracleDataAdapter proca = new OracleDataAdapter(proc1);
- DataSet ds = new DataSet();
- proca.Fill(ds);
- cmd1.CommandType = CommandType.StoredProcedure; //proc.-nak átadjuk a paramétereket
- cmd1.Parameters.Add("nev", OracleDbType.Varchar2).Value = delBox.Text;
- cmd1.ExecuteNonQuery();
- con.Close();
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.ToString());
- }
- }
- private void delProc()
- {
- try
- {
- string ConString = "Data Source=XE;User Id=dorab;Password=dorab;";
- using (OracleConnection con = new OracleConnection(ConString))
- {
- OracleCommand delUser = new OracleCommand();
- delUser.CommandText = "delete from felhasznalo where username = '" + delBox.Text + "'";
- delUser.Connection = con;
- delUser.CommandType = CommandType.Text;
- delUser.Connection.Open();
- delUser.ExecuteNonQuery();
- OracleDataReader dr = delUser.ExecuteReader();
- if (dr.HasRows)
- {
- MessageBox.Show("Sikeres törlés!!!");
- }
- else
- {
- MessageBox.Show("Nincs ilyen felhasználó az adatbázisban!!!");
- }
- delUser.Connection.Close();
- }
- }
- catch (OracleException ex)
- {
- MessageBox.Show(ex.ToString());
- }
- }
- private void logout_Click(object sender, EventArgs e)
- {
- this.Hide();
- onscreen visszalep = new onscreen();
- visszalep.ShowDialog();
- }
- private void delButton_Click(object sender, EventArgs e)
- {
- delProc();
- torolProc();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement