繁体中文
设为首页
加入收藏
当前位置:.Net技术首页 >> Asp.Net开发 >> 学习PetShop3.0(2)用户注册(CreateAccount.aspx)

学习PetShop3.0(2)用户注册(CreateAccount.aspx)

2007-09-15 08:00:00  作者:  来源:互联网  浏览次数:0  文字大小:【】【】【
简介:通过点击SignIn.ASPx里的Register Now,转到CreateAccount.ASPx。 1)我的帐户(My Account)的填写,没什么值得介绍的,就是三个textBox加三个equiredFieldValidator。很简单。输入完成了,后台调用WebComponen...

通过点击SignIn.ASPx里的Register Now,转到CreateAccount.ASPx。

1)我的帐户(My Account)的填写,没什么值得介绍的,就是三个textBox加三个equiredFieldValidator。很简单。输入完成了,后台调用WebComponents.CleanString.InputText(string inputString, int maxLength),进行字符传的规则,这点和登陆的时候是一样的。估计是为了程序的简单,或者微软认为CustomerValidator不属于这个例子要说明的东西,输入字符串的规则没有用控件来检验,就是说对于Email的输入都可以是一个字符,只要非空就行。

2)我的地址(My Address)的填入。例子里做了个UserControl。因为有多处需要用到,例如Account的修改,定单的地址等。例子对于Address也建了Model类,有上面提到的AddressUI控件的一个属性的返回值来实例化。该属性有get,set方法。Account修改的时候,从数据库里返回用户信息的可以直接用一个AddressInfo对象来赋值。这一点有点象JSF,将一个datatable控件和后台的一个bean绑定。

3)我的爱好(My Preferences)的填入。和My Address的填入一样,做了一个UserControl,略微不同的是没有对Preferences来建model类,只写了四个属性,用来访问Language,Category,IsShowFavorites,IsShowBanners。然后用这个AddressInfo对象,和上面的四个属性来实例化AccountInfo。

4)写入数据库,利用CreateAccount(AccountInfo newAccountInfo)。成功则把新的用户信息写人Session,并设置通过验证,跳转页面default.ASPx。

Code highlighting produced by Actipro CodeHighlighter (freeware)

http://www.CodeHighlighter.com/

-->public bool CreateAccount(AccountInfo newAccountInfo){

try {

Account account = new Account();

account.Insert(newAccountInfo);

HttpContext.Current.Session[ACCOUNT_KEY] = newAccountInfo;

FormsAuthentication.SetAuthCookie(newAccountInfo.UserId, false);

HttpContext.Current.Response.Redirect(URL_ACCOUNTCREATE, true);

}catch {

return false;

}

return true;

}

5)BLL.account.Insert(newAccountInfo)和登陆是的SignIn函数一样。利用一个DALFactory和反射,对Accout实例化。剩下的就只是简单的数据库访问了。

Code highlighting produced by Actipro CodeHighlighter (freeware)

http://www.CodeHighlighter.com/

-->public void Insert(AccountInfo account) {

if (account.UserId.Trim() == string.Empty)

return;

IAccount dal = PetShop.DALFactory.Account.Create();

dal.Insert(account);

}

6) 对于Accout的ID的重复问题,没有做过多判断,只利用主键来做判断,如果重复BLL.account.Insert(newAccountInfo)返回false。界面输出“Duplicate user ID! Please try again”,微软似乎认为新建帐户错误的原因只有重复用户。

7) 成功登陆转到MyAccount.ASPx页面。MyAccount.ASPx有一个blockquote的HTML标记,是向右缩排标签,问题不是很大。唯一要注意的后台代码中OnLoad事件,根据action后的查询字符串显示不同的成功信息,分新建帐户,更新帐户,登陆帐户。

Code highlighting produced by Actipro CodeHighlighter (freeware)

http://www.CodeHighlighter.com/

-->case "create":

lblMessage.Text = "Your account was successfully created.";

break;

case "update":

lblMessage.Text = "Your account was successfully updated.";

break;

case "signIn":

lblMessage.Text = "Welcome to the .NET Pet Shop Demo.";

break;

责任编辑:admin
相关文章