Exemplo n.º 1
0
 protected void btn_insertLec_Click(object sender, EventArgs e)
 {
     if (tb_usernameLec.Text.TrimStart().TrimEnd() == "" || tb_passLec.Text == "" || tb_fullname.Text.TrimStart().TrimEnd() == "")
     {
         lb_msg.Text = "You are required to fill all fields";
     }
     else
     {
         con.Open();
         cmd.CommandText = "SELECT * FROM Lectures WHERE username=@username AND pass=@pass";
         cmd.Parameters.AddWithValue("@username", tb_usernameLec.Text);
         cmd.Parameters.AddWithValue("@pass", tb_passLec.Text);
         reader = cmd.ExecuteReader();
         if (reader.Read())
         {
             reader.Close();
             lb_msg.Text = "Sorry bro this username and password already exists!";
         }
         else
         {
             reader.Close();
             cmd.CommandText = "INSERT INTO Lectures (username,pass,fullname,notes,active) VALUES (@username2,@pass2,@fullname,@notes, 'false')";
             cmd.Parameters.AddWithValue("@username2", tb_usernameLec.Text);
             cmd.Parameters.AddWithValue("@pass2", tb_passLec.Text);
             cmd.Parameters.AddWithValue("@fullname", tb_fullname.Text);
             cmd.Parameters.AddWithValue("@notes", tb_notes.Text);
             cmd.ExecuteNonQuery();
             lb_msg.Text = "Successfully added to database";
             GridView_Lectures.DataBind();
         }
         con.Close();
     }
 }
Exemplo n.º 2
0
 protected void btn_signupLec_Click(object sender, EventArgs e)
 {
     if (tb_usernameLec.Text.TrimStart().TrimEnd() == "" || tb_passLec.Text == "" || tb_fullname.Text.TrimStart().TrimEnd() == "")
     {
         lb_msg.Text = "Please enter your information. Fields cannot be blank!";
     }
     else
     {
         con.Open();
         cmd.CommandText = "SELECT id FROM Lectures WHERE username=@username AND pass=@pass";
         cmd.Parameters.AddWithValue("@username", tb_usernameLec.Text);
         cmd.Parameters.AddWithValue("@pass", tb_passLec.Text);
         reader = cmd.ExecuteReader();
         if (reader.Read())
         {
             reader.Close();
             lb_msg.Text = " The username and password you have selected bave been to another user, " +
                           "please choose a different username and password.\nThank you!";
         }
         else
         {
             reader.Close();
             cmd.CommandText = "INSERT INTO Lectures (username,pass,fullname,notes,active) VALUES (@username2,@pass2,@fullname,@notes,'false')";
             cmd.Parameters.AddWithValue("@username2", tb_usernameLec.Text);
             cmd.Parameters.AddWithValue("@pass2", tb_passLec.Text);
             cmd.Parameters.AddWithValue("@fullname", tb_fullname.Text);
             cmd.Parameters.AddWithValue("@notes", tb_notes.Text);
             cmd.ExecuteNonQuery();
             lb_msg.Text = "Information entered Successfully";
             GridView_Lectures.DataBind();
         }
         con.Close();
     }
 }