private bool validateall()
 {
     RequiredFieldValidator1.Validate();
     RequiredFieldValidator2.Validate();
     RequiredFieldValidator3.Validate();
     RequiredFieldValidator4.Validate();
     RequiredFieldValidator5.Validate();
     RequiredFieldValidator6.Validate();
     RequiredFieldValidator7.Validate();
     RequiredFieldValidator8.Validate();
     RequiredFieldValidator9.Validate();
     RegularExpressionValidator1.Validate();
     RegularExpressionValidator2.Validate();
     RegularExpressionValidator3.Validate();
     RegularExpressionValidator4.Validate();
     RegularExpressionValidator5.Validate();
     RegularExpressionValidator6.Validate();
     RegularExpressionValidator7.Validate();
     CompareValidator1.Validate();
     CompareValidator2.Validate();
     CompareValidator3.Validate();
     if (!RequiredFieldValidator1.IsValid || !RequiredFieldValidator2.IsValid || !RequiredFieldValidator3.IsValid || !RequiredFieldValidator4.IsValid || !RequiredFieldValidator5.IsValid || !RequiredFieldValidator6.IsValid || !RequiredFieldValidator7.IsValid || !RequiredFieldValidator8.IsValid || !RequiredFieldValidator9.IsValid ||
         !RegularExpressionValidator1.IsValid || !RegularExpressionValidator2.IsValid || !RegularExpressionValidator3.IsValid || !RegularExpressionValidator4.IsValid || !RegularExpressionValidator5.IsValid || !RegularExpressionValidator6.IsValid || !RegularExpressionValidator7.IsValid || !CompareValidator1.IsValid || !CompareValidator2.IsValid || !CompareValidator3.IsValid)
     {
         return(false);
     }
     return(true);
 }
    protected void BtReg_Click(object sender, EventArgs e)
    {
        RequiredFieldValidator1.Validate();
        RequiredFieldValidator2.Validate();
        RequiredFieldValidator3.Validate();
        RequiredFieldValidator4.Validate();
        RequiredFieldValidator5.Validate();
        RequiredFieldValidator6.Validate();
        RequiredFieldValidator7.Validate();
        CompareValidator1.Validate();
        RegularExpressionValidator1.Validate();
        RegularExpressionValidator2.Validate();
        RegularExpressionValidator3.Validate();
        RequiredFieldValidator8.Validate();
        RequiredFieldValidator9.Validate();
        if (!RequiredFieldValidator8.IsValid || !RequiredFieldValidator9.IsValid || !RequiredFieldValidator1.IsValid || !RequiredFieldValidator2.IsValid || !RequiredFieldValidator3.IsValid || !RequiredFieldValidator4.IsValid || !RequiredFieldValidator5.IsValid || !RequiredFieldValidator6.IsValid || !RequiredFieldValidator7.IsValid || !CompareValidator1.IsValid || !RegularExpressionValidator1.IsValid || !RegularExpressionValidator2.IsValid || !RegularExpressionValidator3.IsValid)
        {
            eMessage.Message("请仔细检查输入!", UpdatePanel1, this);
            return;
        }
        if (!this.SerialNumber1.CheckSN(txtCheck.Text) || txtCheck.Text == null || txtCheck.Text == "")
        {
            eMessage.Message("请输入正确的验证码", UpdatePanel1, this);
            this.SerialNumber1.Create();
            return;
        }

        if (!Regex.IsMatch(txtIdReg.Text, "^\\d{10}$"))
        {
            eMessage.Message("不正确的ID", UpdatePanel1, this);
            SerialNumber1.Create();
            return;
        }
        if (!Regex.IsMatch(txtNameReg.Text, "^[\u4E00-\u9FA5]{0,}$"))
        {
            eMessage.Message("请输入正确的姓名", UpdatePanel1, this);
            SerialNumber1.Create();
            return;
        }
        if (txtPawReg.Text != txtPawRegCnf.Text)
        {
            eMessage.Message("您两次输入的密码不同", UpdatePanel1, this);
            SerialNumber1.Create();
            return;
        }


        var cn = new SqlConnection();

        cn.ConnectionString = DealData.constring;
        SqlCommand cmd = new SqlCommand("usp_VaUserName", cn);

        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Add(new SqlParameter("@username", SqlDbType.NVarChar, 50)).Value = txtUsrReg.Text;
        try
        {
            cn.Open();
            if ((string)cmd.ExecuteScalar() != null)
            {
                eMessage.Message("该用户名已被注册!", UpdatePanel1, this);
                SerialNumber1.Create();
                return;
            }
        }
        catch (Exception e1)
        {
            eMessage.Message("系统发生问题,请稍后重试或联系管理员", UpdatePanel1, this);
            SerialNumber1.Create();
            eMessage.Message(e1);
        }
        finally
        {
            cn.Close();
        }

        int state = 0;
        var cn2   = new SqlConnection();

        cn2.ConnectionString = DealData.constring;
        SqlCommand cmd2 = new SqlCommand("usp_CreateUser", cn2);

        cmd2.CommandType = CommandType.StoredProcedure;
        cmd2.Parameters.Add(new SqlParameter("@username", SqlDbType.NVarChar, 50)).Value  = txtUsrReg.Text;
        cmd2.Parameters.Add(new SqlParameter("@studentid", SqlDbType.NVarChar, 50)).Value = txtIdReg.Text;
        cmd2.Parameters.Add(new SqlParameter("@password", SqlDbType.NVarChar, 50)).Value  = txtPawReg.Text;
        cmd2.Parameters.Add(new SqlParameter("@email", SqlDbType.NVarChar, 50)).Value     = txtEmailReg.Text;
        cmd2.Parameters.Add(new SqlParameter("@question", SqlDbType.NVarChar, 50)).Value  = txtQueReg.Text;
        cmd2.Parameters.Add(new SqlParameter("@key", SqlDbType.NVarChar, 50)).Value       = txtAnsReg.Text;
        cmd2.Parameters.Add(new SqlParameter("@RealName", SqlDbType.NVarChar, 50)).Value  = txtNameReg.Text;
        try
        {
            cn2.Open();
            if (cmd2.ExecuteNonQuery() > 0)
            {
                eMessage.Message("注册成功,请等待老师的审核!", UpdatePanel1, this);
                SerialNumber1.Create();
                state = 1;
            }
            else
            {
                eMessage.Message("注册失败,请稍后再试", UpdatePanel1, this);
                SerialNumber1.Create();
                state = -1;
            }
        }
        catch (Exception e2)
        {
            eMessage.Message("系统发生错误请稍后再试", UpdatePanel1, this);
            SerialNumber1.Create();
            eMessage.Message(e2);
        }
        finally
        {
            cn2.Close();
            if (state == 1)
            {
                Response.Redirect("~/Default.aspx");
            }
        }
    }
    protected void recover_button_click(object sender, EventArgs e)
    {
        RegularExpressionValidator3.Validate();
        RequiredFieldValidator3.Validate();

        if (RegularExpressionValidator3.IsValid == false ||
            RequiredFieldValidator3.IsValid == false)
        {
            login_users.Visible         = false;
            current_users_panel.Visible = false;
            new_users_panel.Visible     = false;
            user_account_panel.Visible  = false;
            recover_password.Visible    = true;

            return;
        }

        String messageString = "";

        List <User> allUsersList = Application["AllUsersList"] as List <User>;
        String      email_id     = email_T2.Text;

        int tempAccessCode = 0;

        if ((Application["AllUsersList"] != null) && (check_Existing_User(allUsersList, email_id)))
        {
            for (int i = 0; i < allUsersList.Count; i++)
            {
                if (allUsersList[i].EmailAddress.Equals(email_id))
                {
                    // get accessCode from the database
                    String        connStr = ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString;
                    SqlConnection conn    = new SqlConnection(connStr);

                    String select = "select accessCode from ParabA2_WADsp16_users" +
                                    " where emailAddress = '" +
                                    allUsersList[i].EmailAddress + "'";
                    SqlCommand command = new SqlCommand(select, conn);


                    try
                    {
                        conn.Open();
                        SqlDataReader sqlReader = command.ExecuteReader();
                        while (sqlReader.Read())
                        {
                            tempAccessCode = (int)sqlReader["accessCode"];
                        }
                        String header  = "Recover Password";
                        String subject = "We have recovered your Access Code!";
                        String body    = "Valued Customer,<br/>Thank you for contacting us. Your access code is " + tempAccessCode.ToString() + ".<br/>Thank You.<br/><br/>T & P Delivery Service – Security Team";
                        if (send_mail_to_user(allUsersList[i].EmailAddress, header, subject, body))
                        {
                            messageString = "alert('Your Access code has been sent to the email address in file');";
                        }
                    }
                    finally
                    {
                        conn.Close();
                    }
                    break;
                }
            }

            //send email logic
            login_users.Visible         = true;
            current_users_panel.Visible = true;
            new_users_panel.Visible     = false;
            user_account_panel.Visible  = false;
            recover_password.Visible    = false;
        }
        else
        {
            messageString               = "alert('Sorry Your Email Account cannot be verified');";
            login_users.Visible         = false;
            current_users_panel.Visible = false;
            new_users_panel.Visible     = false;
            user_account_panel.Visible  = false;
            recover_password.Visible    = true;
        }

        ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "", messageString, true);
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        bool IsPwSame = false;

        // 현재 비밀번호
        CompareValidator1.Validate();
        CompareValidator2.Validate();
        RegularExpressionValidator2.Validate();
        RegularExpressionValidator3.Validate();
        RegularExpressionValidator4.Validate();
        if (CompareValidator1.IsValid && CompareValidator2.IsValid && RegularExpressionValidator2.IsValid &&
            RegularExpressionValidator3.IsValid && RegularExpressionValidator4.IsValid)
        {
            string        connectionString = @"server=(local)\SQLExpress;Integrated Security=true;database=db_user";//서버 연결
            SqlConnection Con = new SqlConnection(connectionString);

            // SQL COMMAND OBJECT를 만들고  SQL COMMAND 넣기
            SqlCommand Cmd = new SqlCommand();
            Cmd.Connection = Con;

            try
            {
                // SQL COMMAND 수행하기
                Con.Open();
                // 현재 비밀번호가 맞는지 체크
                Cmd.CommandText = "SELECT pw FROM db_user WHERE id = \'" + Application["id"].ToString().TrimEnd() + "\'";
                SqlDataReader reader = Cmd.ExecuteReader();
                if (reader.Read())
                {
                    string pw = reader["pw"].ToString().TrimEnd();
                    if (pw == TextBox1.Text)
                    {
                        IsPwSame = true;
                    }
                }
                reader.Close();
                if (IsPwSame) // 현재 비밀번호가 맞으면
                {
                    //새 비밀번호를 DB에 업데이트
                    Cmd.CommandText = "UPDATE db_user SET pw = \'" + TextBox2.Text + "\' WHERE id = \'" + Application["id"].ToString().TrimEnd() + "\'";

                    // ExecuteNonQuery()문은 CREATE, ALTER, DROP, INSERT, UPDATE, DELETE 문을 수행할때 사용
                    int rowsAffected = Cmd.ExecuteNonQuery();   //편집구문에따라 영향받는 줄은 몇줄인가?

                    if (rowsAffected == 1)                      //영향받는 줄은 1줄
                    {
                        Response.Redirect(".\\pwchanged.aspx"); //비밀번호 변경후로 이동
                    }
                }
                else // 현재 비밀번호가 아니라면 다시 입력
                {
                    Label1.Text = "비밀번호가 다릅니다!";
                }
                Con.Close();
            }
            catch
            { // 예외 처리
                Label1.Text = "안되는대?";
            }
        }
    }