Experiences of e-bookstore instances

Source: Internet
Author: User
1. Regard dataset as XML. Because it is XML internally, they can be fully exchanged in many cases;
For example, set a data source for a DataGrid:

Dataset DS =   New Dataset ();
......
DataGrid. datasource = DS;
......
DS. readxml ( " XML. xml " );
DataGrid. datasource = DS;

2. Make sure to develop the habit of defining attributes. Internal variables must be encapsulated.
In particular, common classes that need to be defined.

3. A small amount of data can be stored in an array.
For a data group that needs to be frequently queried or queried based on a key, use a value/key pair, such as hashtable.
These classes all need to implement an interface: icollection. Therefore, you can define the value of the type returned by this interface. For example:

Public Icollection bookorders
{
Get
{
ReturnBookorders. values;
}
}

This is an attribute that returns the internal hashtable: bookorders. Values value group and implements the icollection interface.

4. When using foreach to access each element in icollection, use the following methods:

Foreach (Dictionaryentry entry In Bookorders)
{
.
}

5. attributes can also implement complex computing. Do not always think that the processing is only performed in the method.
For example, you can perform a large amount of processing in get and then output it.

6. The use of cache is very simple and can implement many complex functions, such as automatic task processing by time, such as updating.
For example, we can cache the data dataset of a book to the cache and update it once every 3 minutes.

Context. cache. insert ( " Books " , DS, Null , Datetime. Now. addminutes ( 3 ), Cache. noslidingexpiration, cacheitempriority. Default, New Cacheitemremovedcallback (refreshdataset ));

Static   Void Refreshdataset ( String Key, Object Item, cacheitemremovedreason reason)
{
......
}

7. We can dynamically load controls and custom controls.
However, we must pay attention to a very important issue: because the control is dynamicCodeIs not part of the form initialization. Therefore, when the page is PostBack (such as clicking any button), the page will be reloaded and the corresponding processing code must be written.

Usercontrol goodbookctrl = (Usercontrol) loadcontrol ( " Goodbook. ascx " );
This . Panel1.controls. Add (goodbookctrl );

8. the button event in the DataGrid is the DataGrid. itemcommand event processing, we often judge E. commandname can be used to process the data of the same row (record). For example, the data of one row is E. item. cells [0]. text.

9. The object implemented by DataGrid. datasource, which contains a set of values used to provide data for this control.
The data source must be system. collections. ienumerable interface (such as system. data. dataview, system. collections. arraylist and system. collections. can be bound to a control derived from the basedatalist class.
Similarly, in this example, the shopping cart DataGrid is bound to the object returned by icollection, which is a collection of class elements, in the DataGrid, we set the attribute names bound to the corresponding columns in the class, which will be automatically recognized and very intelligent. because the attribute is a subordinate of the class (that is, the so-called ". "Relationship, applicable ).

This example is very simple. It is also far from the actual system, because it uses dynamic controls, cache, and session Status technologies, and the real data is mainly used in databases, some cache layers may be inserted in the middle.
here is only an example of technical application. The speed is extremely fast and the memory usage is extremely high.
download: http://files.cnblogs.com/wddavid/ElectronicBookShop.rar
SQL database: http://files.cnblogs.com/wddavid/ElectronicBookShopDatabase.rar

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.