Example #1
0
        protected void btnSignUp_Click(object sender, EventArgs e)
        {
            MyiTestDataDataContext db = new MyiTestDataDataContext();
            iUser ius = new iUser();

            if (txtUsername.Text.Length > 0 && txtUsername.Text.Length < 12 && txtPass.Text.Length > 0 && txtPass.Text.Length < 20
                && txtReEnterPass.Text.Length > 0 && txtEmail.Text.Length > 0)
            {
                int user = db.st_CheckAvailableUser(txtUsername.Text.Trim());
                int email = db.st_CheckAvailableEmail(txtEmail.Text.Trim());

                if (user == 0)
                {
                    labUser.Text = "";
                    labRePass.Text = "";
                    labEmail.Text = "";

                    labUser.Text = "This name is exist ! Please enter other name";
                    txtUsername.Text = string.Empty;
                    //btnSignUp.Enabled = false;
                }
                else if (email == 0)
                {
                    labUser.Text = "";
                    labRePass.Text = "";
                    labEmail.Text = "";

                    labEmail.Text = "This email is exist ! Please enter other email address";
                    txtEmail.Text = string.Empty;
                    //btnSignUp.Enabled = false;
                }
                else if (txtReEnterPass.Text.Trim() != txtPass.Text.Trim())
                {
                    labUser.Text = "";
                    labRePass.Text = "";
                    labEmail.Text = "";

                    labRePass.Text = "Incorrect Password ! Please enter again";
                    txtReEnterPass.Text = string.Empty;
                }
                else
                {

                    ius.iUserName = txtUsername.Text.ToString();
                    ius.iPass = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPass.Text.Trim(), "MD5");
                    ius.iEmailUser = txtEmail.Text.ToString();

                    db.iUsers.InsertOnSubmit(ius);
                    db.SubmitChanges();

                    string strScript = "<script>";
                    strScript += "alert('Created New Account');";
                    strScript += "window.location='Login.aspx';";
                    strScript += "</script>";
                    Page.RegisterClientScriptBlock("strScript", strScript);

                    //Response.Redirect("RedirectHomePage.aspx");

                }
            }
            else
            {
                Response.Write("<script>alert('Please enter all infomation')</script>");

            }
        }
Example #2
0
        protected void btnSignUp_Click(object sender, EventArgs e)
        {
            MyiTestDataDataContext db = new MyiTestDataDataContext();
            iUser ius = new iUser();

            if (chk_DongY.Checked == true)
            {
                if (txtUsername.Text.Length > 0 && txtUsername.Text.Length <= 12
                    && txtPass.Text.Length > 0 && txtPass.Text.Length <= 20
                    && txtReEnterPass.Text.Length > 0 && txtEmail.Text.Length > 0 && txtAnswer.Text.Length > 0
                    && dropCauHoiBiMat.SelectedValue != "-1")
                {
                    int user = db.st_CheckAvailableUser(txtUsername.Text.Trim());
                    int email = db.st_CheckAvailableEmail(txtEmail.Text.Trim());

                    if (user == 0)
                    {
                        labUser.Text = "";
                        labRePass.Text = "";
                        labEmail.Text = "";

                        labUser.Text = "Tên đăng nhập đã tồn tại!";
                        txtUsername.Text = string.Empty;

                    }
                    else if (email == 0)
                    {
                        labUser.Text = "";
                        labRePass.Text = "";
                        labEmail.Text = "";

                        labEmail.Text = "Email đã được sử dụng!";
                        txtEmail.Text = string.Empty;
                        //btnSignUp.Enabled = false;
                    }
                    else if (txtReEnterPass.Text.Trim() != txtPass.Text.Trim())
                    {
                        labUser.Text = "";
                        labRePass.Text = "";
                        labEmail.Text = "";

                        labRePass.Text = "Xác nhận mật khẩu không chính xác!";
                        txtReEnterPass.Text = string.Empty;
                    }
                    else
                    {

                        ius.iUserName = txtUsername.Text.ToString();
                        ius.iPass = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPass.Text.Trim(), "MD5");
                        ius.iEmailUser = txtEmail.Text.ToString();
                        ius.iBirthday =Convert.ToDateTime(ddlNgay.SelectedValue + "-" + ddlThang.SelectedValue + "-" + ddlNam.SelectedValue);
                        ius.iSID = Convert.ToInt32(dropCauHoiBiMat.SelectedItem.Value);
                        ius.iSAns = txtAnswer.Text;
                        ius.iCreatedDate = DateTime.Now;

                        db.iUsers.InsertOnSubmit(ius);
                        db.SubmitChanges();

                        string strScript = "<script>";
                        strScript += "alert('Chào mừng bạn đến với iTest');";
                        strScript += "window.location='Default.aspx';";
                        strScript += "</script>";
                        Page.RegisterClientScriptBlock("strScript", strScript);
                    }
                }
                else
                {
                    Response.Write("<script>alert('Vui lòng điền đầy đủ thông tin ! ')</script>");
                }
            }
            else
            {
                Response.Write("<script>alert('Bạn phải đánh dấu vào ô chấp nhận các điều khoản của iTest.')</script>");
            }
        }