コード例 #1
0
 protected void btnRegister_Click(object sender, EventArgs e)
 {
     UserRegistration2.Entity.User temp = new UserRegistration2.Entity.User();
     try
     {
         if (txtPassword.Text == txtRePassword.Text)
         {
             temp.Age          = int.Parse(ddlAge.SelectedItem.Value);
             temp.Email        = txtEmail.Text;
             temp.FirstName    = txtName.Text;
             temp.LastName     = txtSurname.Text;
             temp.Phone        = "(" + ddlPhoneArea.SelectedItem.Value + ")" + txtPhone.Text;
             temp.UserName     = txtUserName.Text;
             temp.UserPassword = txtPassword.Text;
             if (rbtnFemale.Checked)
             {
                 temp.Gender = true;
             }
             else
             {
                 temp.Gender = false;
             }
             UserRegistration2.DataLayer.DataUser.Registration(temp);
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #2
0
        public static Entity.User Login(Entity.User LoginRequest)
        {
            Entity.User LoginResult = null;

            SqlConnection con = UserRegistration2.DataLayer.DataConnection.GetConnection();

            SqlCommand com = new SqlCommand();

            string query = "SELECT UserDetails.FirstName, UserDetails.LastName, UserDetails.UserAge, UserDetails.UserGender, UserDetails.UserEmail, UserDetails.UserPhone, UserDetails.UserId, Users.UserName, Users.UserPassword "
                           + "FROM UserDetails INNER JOIN Users ON UserDetails.UserId = Users.UserId "
                           + "where Users.UserName=@un and Users.UserPassword=@up;";

            com.Connection  = con;
            com.CommandText = query;

            com.Parameters.AddWithValue("@un", LoginRequest.UserName);
            com.Parameters.AddWithValue("@up", LoginRequest.UserPassword);
            con.Open();
            SqlDataReader rdr = com.ExecuteReader();

            if (rdr.Read())
            {
                LoginResult              = new UserRegistration2.Entity.User();
                LoginResult.Gender       = bool.Parse(rdr["UserGender"].ToString());
                LoginResult.Age          = int.Parse(rdr["UserAge"].ToString());
                LoginResult.Email        = rdr["UserEmail"].ToString();
                LoginResult.FirstName    = rdr["FirstName"].ToString();
                LoginResult.LastName     = rdr["LastName"].ToString();
                LoginResult.Phone        = rdr["UserPhone"].ToString();
                LoginResult.UserId       = int.Parse(rdr["UserId"].ToString());
                LoginResult.UserName     = rdr["UserName"].ToString();
                LoginResult.UserPassword = rdr["UserPassword"].ToString();
            }
            return(LoginResult);
        }
コード例 #3
0
 protected void btnLogin_Click(object sender, EventArgs e)
 {
     UserRegistration2.Entity.User myUser = new UserRegistration2.Entity.User();
     myUser.UserName     = txtUserName.Text;
     myUser.UserPassword = txtPassword.Text;
     myUser = UserRegistration2.DataLayer.DataUser.Login(myUser);
     if (myUser != null)
     {
         Response.Write("Successfull");
     }
     else
     {
         Response.Write("No such a username and password");
     }
 }