One PetShop (Task000) in Sousse-Architecture

Source: Internet
Author: User
Tags configuration settings

Source code: 13033480 group sharing

PetShop4.0 is a sample source code provided by Microsoft to demonstrate its Visual Studio functions. Although the program is small, it contains ASP. NET is very suitable for beginners to learn and study.

Although this PetShop is a pet store, due to its code specifications and classic structure, it can be easily rewritten into other online shopping systems and is very eager to create a NetShop, it is called the PetShop of the mountain slice version.

1. "file" → "New Project", open the "new project" dialog box, select "Visual Studio solution" in "project type ", select "blank solution" in "template"
2. "file" → "add" → "New Website"
3. "file" → "add" → "New Project", open the "new project" dialog box, and create a class library BLL
4. Add the project DALFactory, DBUtility, IDAL, Model, and SQLServerDAL in the same step.


 
5. Modify the "assembly name" and "default namespace" of the six class library attributes"

 


Tutorial: You can change the "assembly name" and "default namespace" in the attributes of the class library project. When you add a class file later, The namespace will be automatically generated.

The Web project does not support this. Is there a similar method to make it easier to set the file namespace in the Web ??


6. Copy SQLHelper. cs from DBUtility
Copy all * Info. cs files in the Model, except AssemblyInfo. cs.
Copy ICategory. cs in IDAL
Copy Category. cs from SQLServerDAL
Copy Category. cs from BLL
Copy DataAccess. cs in DALFactory and modify the following content:

Using System. Reflection;
Using System. Configuration;

Namespace NetShop. DALFactory
{

/// <Summary>
// This class is implemented following the Abstract Factory pattern to create the DAL implementation
/// Specified from the configuration file
/// </Summary>
Public sealed class DataAccess
{

// Look up the DAL implementation we shoshould be using
Private static readonly string path = ConfigurationManager. deleettings ["WebDAL"];
Private static readonly string orderPath = ConfigurationManager. deleettings ["OrdersDAL"];

Private DataAccess (){}

Public static NetShop. IDAL. ICategory CreateCategory ()
{
String className = path + ". Category ";
Return (NetShop. IDAL. ICategory) Assembly. Load (path). CreateInstance (className );
}

}
}
7. Add a reference and replace the PetShop in the file with NetShop.

8. Right-click the Web Project → create folder, and create the folder Controls.
Right-click Controls → add new item, and add the user control NavigationControl. ascx.
The code in NavigationControl. ascx is as follows:
<Body>
<Asp: Repeater ID = "repCategories" runat = "server">
<HeaderTemplate>
<Table cellspacing = "0" border = "0" style = "border-collapse: collapse;">
</HeaderTemplate>
<ItemTemplate>
<Tr>
<Td>
<Asp: HyperLink runat = "server" ID = "lnkCategory"> <% # DataBinder. Eval (Container. DataItem, "Name") %> </asp: HyperLink>
</Td>
</Tr>
</ItemTemplate>
<FooterTemplate>
</Table>
</FooterTemplate>
</Asp: Repeater>
</Body>

The code in NavigationControl. ascx. cs is as follows:
Namespace NetShop. Web
{
Public partial class NavigationControl: System. Web. UI. UserControl
{

Protected void Page_Load (object sender, EventArgs e)
{
BindCategories ();
}

// Bind categories
Private void BindCategories (){
Category category = new Category ();
RepCategories. DataSource = category. GetCategories ();
RepCategories. DataBind ();
}
}
}

9. In Default. aspx, drag the user control NavigationControl. ascx

10. Copy the connection string
[Html]
<ConnectionStrings>
<Add name = "SQLProfileConnString" connectionString = "server = (local) \ sqlexpress; database = MSPetShop4Profile; integrated security = SSPI; min pool size = 4; max pool size = 4; "providerName =" System. data. sqlClient "/>
<Add name = "SQLMembershipConnString" connectionString = "server = (local) \ sqlexpress; database = MSPetShop4Services; integrated security = SSPI; min pool size = 4; max pool size = 4; "providerName =" System. data. sqlClient "/>
<Add name = "SQLConnString1" connectionString = "server = (local) \ sqlexpress; database = MSPetShop4; integrated security = SSPI; min pool size = 4; max pool size = 4; "providerName =" System. data. sqlClient "/>
<Add name = "SQLConnString2" connectionString = "server = (local) \ sqlexpress; database = MSPetShop4; integrated security = SSPI; max pool size = 4; min pool size = 4; "providerName =" System. data. sqlClient "/>
<Add name = "SQLConnString3" connectionString = "server = (local) \ sqlexpress; database = MSPetShop4Orders; integrated security = SSPI; min pool size = 4; max pool size = 4; "providerName =" System. data. sqlClient "/>
</ConnectionStrings>

 
11. Copy
[Html]
<Deleetask>
<! -- Pet Shop DAL configuration settings. Possible values: PetShop. SQLServerDAL for SqlServer, PetShop. OracleServerDALfor Oracle. -->
<Add key = "WebDAL" value = "NetShop. SQLServerDAL"/>
<Add key = "OrdersDAL" value = "NetShop. SQLServerDAL"/>
</AppSettings>

 

12. Right-click "Default. aspx" → "view in Browser"


 
 


From ASP. NET Technology

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.