ASP. NET startkit commerce is simple and easy to understand.
I think it's the first time to learn. net.CodeThe first choice, not afraid of jokes, I have read the project code three times.
So what knowledge can we learn through reading? Please refer to my summary below:
1. Implementation of Multi-Layer Structure
In my opinion, it is a two-layer structure: PL layer and BLL layer (no obvious Dal layer, Dal and BLL form a BLL layer together ). However, we can learn how to call the DB process.
2. Simple use of Web Services
3. Use of Web User Controls
4. Data Binding knowledge
Let's take a look at a piece of code in this project:
<Asp: hyperlink cssclass = "menuselected" id = "hyperlink2" text = '<% # databinder. eval (container. dataitem, "categoryname") %> 'navigateurl = '<% # "productslist. aspx? Categoryid = "+ databinder. eval (container. dataitem," categoryid ") +" & Selection = "+
Container. itemindex %> 'runat = "server"/>
Note:
(1) single quotation marks are used for data binding. Double quotation marks are used for single quotation marks.
(2) Pay special attention to attributes: container. itemindex, which generates the ID of each item and starts from scratch. The function is similar to the identity () of ms SQL ). in my previous project, to display the index of each row, I often used a temporary table in the database to generate a row index and then bound the data.
5. Form-based verification
In the Web. config file, we can see the following two pieces of code:
<Authentication mode = "forms">
<Forms name = "performanceauth" loginurl = "login. aspx" Protection = "all" Path = "/"/>
</Authentication>
<Location Path = "orderdetails. aspx">
<System. Web>
<Authorization>
<Deny users = "? "/>
</Authorization>
</System. Web>
</Location>
Note: in this way, you are prohibited from accessing the page orderdetails. aspx without logon verification. The Unlogged user is automatically directed to the login. ASPX page for login verification.
6. Implement the shopping cart
Shopping cart is a typical function of e-commerce sites. In this project, we can see the typical operations for adding, deleting, and modifying shopping cart functions. You can also learn some classic usage methods of controls.
.
Let's look at the code first:
<Asp: DataGrid id = mylist runat = "server" bordercolor = "black" gridlines = "vertical" cellpadding = "4" cellspacing = "0"
Datakeyfield = "quantity" autogeneratecolumns = "false">
......
</ASP: DataGrid>
Use the datakeyfield attribute to bind the field quantity of the data source, that is, the purchase quantity of each item in this token.
The datakeyfield attribute of the system. Web. UI. webcontrols. basedatalist class obtains or sets the key fields in the data source specified by the datasource attribute.
Both the DataGrid and datalist are subclasses of basedatalist.
Let's look at the following code: This code is the modification method of the shopping cart.
Void Updateshoppingcartdatabase () {
ASPnet. starterkit. Commerce. shoppingcartdb cart = New ASPnet. starterkit. Commerce. shoppingcartdb ();
// Obtain current user's shopping cart ID
String cartid = Cart. getshoppingcartid ();
// Iterate through all rows within shopping cart list
For ( Int I = 0 ; I < Mylist. Items. Count; I ++ ) {
// Obtain references to row's controls
Textbox quantitytxt = (Textbox) mylist. items [I]. findcontrol ( " Quantity " );
Checkbox remove = (Checkbox) mylist. items [I]. findcontrol ( " Remove " );
// Wrap in try/Catch Block to catch errors in the event that someone types in
// An invalid value for quantity
Int Quantity;
Try {
Quantity = Int32.parse (quantitytxt. Text );
// If the quantity field is changed or delete is checked
If (Quantity ! = ( Int ) Mylist. datakeys [I] | Remove. Checked = True ) {
Label lblproductid = (Label) mylist. items [I]. findcontrol ( " Productid " );
If (Quantity = 0 | Remove. Checked = True ) {
Cart. removeitem (cartid, int32.parse (lblproductid. Text ));
}
Else {
Cart. updateitem (cartid, int32.parse (lblproductid. Text), quantity );
}
}
}
Catch {
Myerror. Text= "There has been a problem with one or more of your inputs.";
}
}
}
Note:
(1) We use (INT) mylist. datakeys [I] to retrieve the purchased quantity value of the product bound to each row.
(2) Use findcontrol () to search for the specified server control in the current named container.
7. Implementation of scheduled tasks in MS SQL
The job function of ms SQL is used to automatically run shoppingcartremoveabandoned at a specific time to delete unnecessary data in the shopping cart (cmrc_shoppingcart.
8. Global Knowledge
See the code in global. asax. CS:
Protected Void Application_beginrequest (Object sender, eventargs E)
{
Try
{
If (Request. userages ! = Null )
Thread. currentthread. currentculture =
Cultureinfo. createspecificculture (request. userpolicages [ 0 ]);
Else
// Default to English if there are no user ages
Thread. currentthread. currentculture = New Cultureinfo ( " En-US " );
Thread. currentthread. currentuiculture = Thread. currentthread. currentculture;
}
Catch (Exception ex)
{
Thread. currentthread. currentculture= NewCultureinfo ("En-US");
}
}
Note: globalization supports localized user interfaces and local data applications for users of multiple cultures.ProgramDesign and development process. In the. NET architecture, the cultureinfo class represents a feature
Cultural information. This information includes the writing system, calendar used, date and time format style, digital and currency style, and classification principles. Localization is for every application supported
The process of converting application resources into localized versions. The current culture is modified based on browser settings every time a user requests a page from an application.
9. Other knowledge points:
(1) Cache Usage
(2) Set and read custom nodes in the web. config file
And so on.
I am writing a reading summary for the first time. I hope you can point it out more because the level is valid. Thank you.
Next, we will summarize ASP. NET startkit timetracker's reading experience.