Learn PETSHOP3.0 (2) User Registration (CreateAccount.aspx)

xiaoxiao2021-04-04  275

Go to CreateAccount.aspx by clicking on Register Now in Signin.aspx.

1) My account (My Account), nothing is worth mentioning, three Textbox plus three EquiredFieldValidator. Very simple. The input is completed, the background calls WebComponents.cleanstring.inputText (String InputString, Int Maxlength), the rules of the character are transmitted, this is the same as if the login is. It is estimated to be simple, or Microsoft believes that CustomerValidator does not belong to something to be explained. The rule of the input string does not use controls, that is, the input of Email can be a character, as long as it is not empty.

2) My address (My Address) is filled. The example made a UserControl. Because there is a need to use, such as the modification of Account, the address of the order, etc. Examples have also built a Model class for Address, which has the return value of an attribute of the AddressUI control above. This attribute has a GET, SET method. When Account is modified, returning to user information from the database can be assigned directly with an AddressInfo object. This is a bit like JSF, bind a DataTable control and a bean in the background.

3) Fill in my preferences. Like My Address, make a UserControl, slightly different is to build a Model class for Preferences, with only four properties, use to access Language, Category, IsshowFavorites, Isshowbanners. Then use this AddressInfo object, and four attributes above. Accountinfo.

4) Write into the database and utilize CreateAccount (AccountInfo NewAccountInfo). Successfully writes the new user information session and sets the verification, jump page default.aspx.

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)

Like the Signin function on the login. Instant ACCOUT is instantiated using a DalFactory and reflection. The rest is just a simple database access.

public

Void

INSERT (AccountInfo Account) {

IF

(Account.Userid.trim ()

==

String

Empty)

Return

Iaccount Dal

=

PETSHOP.DALFACTORY.ACCOUNT.CREATE (); Dal.Insert (account);

6

) For the repetition of Accout's ID, there is no excessive judgment, only use the primary key to make judgments, if repeated

BLL.

Account.insert (NewaccountInfo)

Return False. The interface output "Duplicate User ID! Please try", Microsoft seems to think that the new account is wrong only if it is repeated.

7) Successfully logged into the MyAccount.aspx page. MyAccount.aspx has a block quote's HTML tag, which is to roll right, and the problem is not very big. The only ONLOAD event in the background code you have to pay attention to, displays different successful information according to the query string after Action, and subtract accounts, update the account, and log in.

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

;

转载请注明原文地址:https://www.9cbs.com/read-131826.html

New Post(0)