Example #1
0
        private void btn_register_Click(object sender, EventArgs e)
        {
            try
            {
                con.Open();
                cmd.Connection  = con;
                cmd.CommandText = "select * from Profile where UserName='******'";
                dr = cmd.ExecuteReader();
                if (dr.HasRows)
                {
                    MessageBox.Show("This username exists,choose another one!");
                }
                else
                {   //we have to close the DataReader so we can execute the insert query
                    dr.Close();
                    //we will add a new user by inserting his UserName,his Password and his E-mail
                    SqlCommand cmd1 = new SqlCommand("insert into Profile(UserName,Password,Email,ProfilePic) values(@UserName,@Password,@Email,@ProfilePic)", con);
                    //Je dois confgurer les paramétres
                    cmd1.CommandType = CommandType.Text;//Cette instruction donne le type de la commande , la valeur par defaut est text et elle n'est pas obligatoire
                    cmd1.Parameters.AddWithValue("@UserName", txt_username.Text);
                    cmd1.Parameters.AddWithValue("@Password", txt_password.Text);
                    cmd1.Parameters.AddWithValue("@Email", txt_Email.Text);
                    var image = new ImageConverter().ConvertTo(pictureBox1.Image, typeof(Byte[]));
                    cmd1.Parameters.AddWithValue("@ProfilePic", image);
                    //get the FK
                    FK = txt_username.Text;

                    //newuser confirmed
                    NewUser = true;
                    Note    = true;
                    //Execut the query
                    cmd1.ExecuteNonQuery();
                    //MessageBox.Show("success");
                    sc.Show();
                    //this.Hide();
                    fb.Close();
                    tw.Close();
                    gp.Close();


                    /*PersonalInformation p = new PersonalInformation();
                     * p.Show();
                     * this.Hide();*/
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                if (con.State == ConnectionState.Open)
                {
                    con.Close();
                }
            }
        }
Example #2
0
 private void btnSignIn_Click(object sender, EventArgs e)
 {
     try
     {
         con.Open();
         cmd.Connection  = con;
         cmd.CommandText = "select * from Profile where UserName='******'";
         dr = cmd.ExecuteReader();
         if (dr.HasRows)
         {   //get the FK
             FK = txt_username.Text;
             Boolean ok = false;
             while (dr.Read() && ok == false)
             {
                 if (!txt_password.Text.Equals(dr["Password"]))
                 {
                     PasswordCheck pw = new PasswordCheck();
                     pw.Show();
                     // MessageBox.Show("You need to check your password!");
                     ok = true;
                 }
                 else if (!txt_Email.Text.Equals(dr["Email"]))
                 { //MessageBox.Show("You need to check your E-mail!");
                     EmailCheck ec = new EmailCheck();
                     ec.Show();
                     ok = true;
                 }
             }
             if (ok == false)
             {
                 dsh.Show();
                 this.Hide();
                 fb.Close();
                 tw.Close();
                 gp.Close();
             }
         }
         else
         {
             if (txt_password.Text.Equals("") && txt_Email.Text.Equals("") && txt_username.Text.Equals(""))
             {
                 // MessageBox.Show("The fields are empty");
                 EmptyFields ep = new EmptyFields();
                 ep.Show();
             }
             else
             {
             }
             // MessageBox.Show("You need to register!");
             CheckRegistration crg1 = new CheckRegistration();
             crg1.Show();
             dr.Close();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
     finally
     {
         if (con.State == ConnectionState.Open)
         {
             con.Close();
         }
     }
 }