第四步 WEB 展示层(显示层) UserReg.aspx.cs 页 实例

 

2008-01-16 16:59

using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.Data.SqlClient;

using Ajaxuser;

using Buygo.SQLDAL;

using Buygo.Model;

public partial class UserReg : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

        Ajax.Utility.RegisterTypeForAjax(typeof(Ajaxuser.pages.AjaxMethod));

        if (!IsPostBack)

        {

            Response.Cookies.Add(new HttpCookie("CheckCode", ""));

            if (this.Request["MsgID"] != null && this.txtState.Value.Trim() == "")

            {

                this.lberror.Text = MessageMap.GetMsg(int.Parse(this.Request["MsgID"]));

                this.txtState.Value = "_";

            }

        }

        //if (this.Request["id"] != null)

        //{

        //    Session["id"] = this.Request["id"].ToString();

        //}

    }

    protected void imsubmit_Click(object sender, ImageClickEventArgs e)

    {

        //if (Session["page"] != null)

        //{

        //    this.Response.Redirect(Session["page"].ToString());

        //}

        //else

        //{

            string nick = this.tbMemberName.Text.Split(new char[] { '@' })[0].ToString();

            //if (String.Compare(Request.Cookies["CheckCode"].Value, TextBox1.Text.ToString().Trim(), true) != 0)

            //{

            //    Label1.Text = "验证码错误,请输入正确的验证码。";

            //    Label1.Visible = true;

            //    return;

            //}

            //else

            //{

            //    Label1.Text = "验证码OK。";

            //    Label1.Visible = true;

            this.TDMessage.InnerHtml = "";

            string userID = this.tbMemberName.Text.ToString().Trim();

            string pwd = this.tbPassword.Text.ToString();

            string question = this.dlQuestion.SelectedItem.Value.ToString();

            string answer = this.tbAnswer.Text.ToString();

            pwd = FormsAuthentication.HashPasswordForStoringInConfigFile(pwd, "MD5");

            BuygoMember buygoMember = new BuygoMember();

            Member member = buygoMember.InsertMember(userID, pwd, question, answer, nick);

            if (member.MsgID == -1)       //注册成功

            {

                string password = FormsAuthentication.HashPasswordForStoringInConfigFile(this.tbPassword.Text.Trim(), "MD5");

                Member mem = buygoMember.Login(this.tbMemberName.Text.Trim(), password);

                this.Session["Member"] = mem;

                this.Response.Redirect("./personalIndex.aspx?Reg=1");

            }

            else

            {

                this.TDMessage.InnerHtml = "" + MessageMap.GetMsg(member.MsgID) + "";

            }

            Response.Redirect(Session["page"].ToString());

        //}

    }

    protected void submit_Click(object sender, EventArgs e)

    {

        if (this.tbxLoginName.Text.Trim() == "")

        {

            this.lberror.Text = "用户名不能为空!";

        }

        else if (this.tbxLoginPwd.Text.Trim() == "")

        {

            this.lberror.Text = "密码不能为空!";

        }

        else

        {

            Buygo.SQLDAL.BuygoMember buygoMember = new Buygo.SQLDAL.BuygoMember();

            string password = FormsAuthentication.HashPasswordForStoringInConfigFile(this.tbxLoginPwd.Text.Trim(), "MD5");

            Member member = buygoMember.Login(this.tbxLoginName.Text.Trim(), password);

            Session["Member"] = member;

            if (member.MsgID.ToString() == "-1")

            {

                this.Response.Redirect("./personalIndex.aspx");

            }

            else

            {

                this.lberror.Text = MessageMap.GetMsg(member.MsgID);

            }

        }

    }

}

你可能感兴趣的:(web,string,session,object,textbox,null)