private void button1_Click(object sender, EventArgs e) { try { if (Dfirstname.Text != "" && Dsurname.Text != "") { using (SqlConnection sqlCon = new SqlConnection(con)) { sqlCon.Open(); DestytAdmin des = new DestytAdmin(); des.FirstnameDes = Dfirstname.Text.Trim(); des.SurnameDes = Dsurname.Text.Trim(); des.UsernameDes = des.FirstnameDes; des.PasswordDes = des.SurnameDes; des.RoleDes = "D"; DestytAdmin register = repos.InsertDBdes(des); Clear(); } void Clear() { Dfirstname.Text = Dsurname.Text = ""; } } else { MessageBox.Show("All fields must be written"); } } catch (Exception exc) { MessageBox.Show(exc.Message); } }
//admin ir destytoooju login public DestytAdmin Logindes(string username, string password) { DestytAdmin logindesad = new DestytAdmin(); try { SqlConnection sqlcon = new SqlConnection(con); SqlCommand cmd = new SqlCommand("SELECT * FROM [Destytojas] WHERE Username=@Username AND Password=@Password", sqlcon); cmd.Parameters.AddWithValue("@Username", username); cmd.Parameters.AddWithValue("@Password", password); sqlcon.Open(); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { string Firstname = dr["Firstname"].ToString(); string Surname = dr["Surname"].ToString(); string Username = dr["Username"].ToString(); string Password = dr["Password"].ToString(); string Role = dr["Role"].ToString(); logindesad.FirstnameDes = Firstname; logindesad.SurnameDes = Surname; logindesad.UsernameDes = Username; logindesad.PasswordDes = Password; logindesad.RoleDes = Role; } sqlcon.Close(); } catch (Exception ex) { Console.WriteLine(ex); return(null); } return(logindesad); }
public DestytMain(DestytAdmin desad) { InitializeComponent(); this.desad = desad; showstudijuojamasdalykas(); //Console.WriteLine(desad.UsernameDes); }
//pridada destytytoja public DestytAdmin InsertDBdes(DestytAdmin dest) { SqlConnection sqlCon = new SqlConnection(con); sqlCon.Open(); SqlCommand cmd = new SqlCommand("SELECT * FROM [destytojas] WHERE Username=@Username", sqlCon); cmd.Parameters.AddWithValue("@Username", dest.UsernameDes); SqlDataReader dr = cmd.ExecuteReader(); if (dr.Read() == true) { MessageBox.Show("Toks usernamas jau yra"); return(null); } dr.Close(); SqlCommand sql = new SqlCommand("INSERT INTO [destytojas] (Firstname,Surname,Username,Password,role)" + " VALUES (@Firstname,@Surname,@Username,@Password,@Role)", sqlCon); sql.Parameters.AddWithValue("@Firstname", dest.FirstnameDes); sql.Parameters.AddWithValue("@Surname", dest.SurnameDes); sql.Parameters.AddWithValue("@Username", dest.UsernameDes); sql.Parameters.AddWithValue("@Password", dest.PasswordDes); sql.Parameters.AddWithValue("@Role", dest.RoleDes); sql.ExecuteNonQuery(); sqlCon.Close(); return(dest); }
private void button1_Click(object sender, EventArgs e) { try { DestytAdmin desad = repos.Logindes(ALU.Text, ALP.Text); if (desad.RoleDes == "D") { DestytMain f = new DestytMain(desad); f.ShowDialog(); } else if (desad.RoleDes == "A") { AdminMain f = new AdminMain(desad); f.ShowDialog(); } else { // MessageBox.Show("neveikia"); } } catch (Exception exc) { MessageBox.Show(exc.Message); } }