. NET PetShop 4.0 (1),. netpetshop4.0
First, go to the Default. aspx page.
Process: Enter keywords, click Search, jump to the Search page, and display the results
Open Default. aspx and you can see that the btnSearch click event is btnSearch_Click. Open Default. aspx. cs and find the response method.
We can see that the SearchRedirect static method of the WebUntity static class is used:
Private const string REDIRECT_URL = "~ /Search. aspx? Keywords = {0 }";
HttpContext. Current. Response. Redirect (string. Format (REDIRECT_URL, InputText (key, 255 )));
Open Search. aspx
<% @ Register Src = "Controls/SearchControl. ascx" TagName = "SearchControl" TagPrefix = "uc1" %>
Although I do not know what it means, but it can be seen that it calls SearchControl. ascx, then open SearchControl. ascx
<% =Request. QueryString["Keywords"] %> combined with the page display, we can see that the request string is obtained.
<% # Eval ("Name") %> This will be known soon. ^_^
Next, there are two methods to open SearchControl. ascx. cs. Let's take a look at the Load method (that is, loading) and find out... Cough and cough. Check out PageChanged.
String keywordKey = Request. QueryString ["keywords"]; 1. Get the keyword
Product product = new Product ();
SearchList. DataSource = product.GetProductsBySearch(KeywordKey); 2. Use the GetProductsBySearch method of the Product object to obtain data.
SearchList. DataBind (); 3. Bind data
Find the GetProductsBySearch method of the Product class.
Private static readonly IProduct dal = PetShop. DALFactory. DataAccess. CreateProduct ();
Dal. GetProductsBySearch (keywords );
So,Find the CreateProduct Method
private static readonly string path = ConfigurationManager.AppSetting["WebDAL"];string className = path + ".Product";return (PetShop.IDAL.IProduct)Assembly.Load(path).CreateInstance(className);
<appSettings> <add key="WebDAL" value="PetShop.SQLServerDAL"/></appSettings>
Export className = "PetShop. SQLServerDAL. Product"
The one after repeated return is to dynamically load the Assembly and create the instance of the given type.
Pipeline returns a Product object.
Go to PetShop. SQLServerDAL. Product and find GetProductsBySearch.
You do not need to take a closer look.
1 using (SqlDataReader rdr = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqlProductsBySearch, parms)) {2 while (rdr.Read()) {3 ProductInfo product = new ProductInfo(rdr.GetString(0), rdr.GetString(1), rdr.GetString(2), rdr.GetString(3), rdr.GetString(4));4 productsBySearch.Add(product);5 }6 }7 return productsBySearch;
It can be seen that it calls the SQLHelper ExecuteReader (ConnectionString, CommandType, sqlStr, params [] SqlParameter [] commandParameters) Auxiliary Method
Then, it's over
The general level is as follows:
Default. aspx-> Search. aspx-> SearchControl. ascxPetShop. BLL. ProductPetShop. SQLServerDAL. Product-> PetShop. DBUntity. SQLHelperPetShop. Model. ProductInfo
Does Microsoft's NET petshop40 use databases?
Here is
Specific petshop 4.0 source code and instructions
Download.csdn.net/source/670968
Reference: download.csdn.net/source/670968
Ask a NET PetShop question
There are two situations,
1. If the two classes are in the same project project1 but the namespaces are different, you can use your method. For example:
File1.cs
Public namespaces myspace1
{
Public class class1
{
....
}
}
File2.cs
Using myspace1
Public namespaces myspace2
{
Public class class2
{
....
}
}
2. If the classes applied to each other are not in the same project, two steps are required:
1) first apply the class to be called (by adding a reference to project2 or the dll it generates)
2) use using namespace2