Example: ASP. NET Crystal Report tutorial (1)

Source: Internet
Author: User

A report is an indispensable part of an application. A good report can help people intuitively grasp the data and play an important role in decision-making. So what if we can implement reports more quickly and efficiently? This article uses a three-tier ASP. NET Program as an example to describe how to use crystalreport to create a report. It introduces a lot of ASP. NET Crystal Report techniques.

In this example, the application we imagine is to prepare a report for a sales department. The manager can view the sales situation within a certain period of time, shows the sales trend in the form of a list or line chart. We will use SQLServer 2000 as the database, use VB. NET to write the middle layer logic layer, and the front-end presentation layer uses C #.

Before introducing the ASP. NET Crystal Report tutorial, let's take a look at the database structure.

Among them, the tbitem table stores the goods ordered in each order, tbsales stores each order, and tblsalesperson is the salesperson table, which stores each salesman of the publishing house.

Next, use SQLServer 2000 to create these tables. The table structure is as follows:

 
 
  1. CREATETABLE[dbo].[tblItem](  
  2. [ItemId][int]NOTNULL,  
  3. [Description][varchar](50)NOTNULL  
  4. )ON[PRIMARY]  
  5. CREATETABLE[dbo].[tblSalesPerson](  
  6. [SalesPersonId][int]NOTNULL,  
  7. [UserName][varchar](50)NOTNULL,  
  8. [Password][varchar](30)NOTNULL  
  9. )ON[PRIMARY]  
  10. CREATETABLE[dbo].[tblSales](  
  11. [SaleId][int]IDENTITY(1,1)NOTNULL,  
  12. [SalesPersonId][int]NOTNULL,  
  13. [ItemId][int]NOTNULL,  
  14. [SaleDate][datetime]NOTNULL,  
  15. [Amount][int]NOTNULL  
  16. )ON[PRIMARY] 

Use the following code to create constraints between tables.

 
 
  1. ALTERTABLEtblItem  
  2. ADDCONSTRAINTPK_ItemId  
  3. PRIMARYKEY(ItemId)  
  4. GO  
  5. ALTERTABLEtblSalesPerson  
  6. ADDCONSTRAINTPK_SalesPersonId  
  7. PRIMARYKEY(SalesPersonId)  
  8. GO  
  9. ALTERTABLEtblSales  
  10. ADDCONSTRAINTFK_ItemId  
  11. FOREIGNKEY(ItemId)REFERENCEStblItem(ItemId)  
  12. GO  
  13. ALTERTABLEtblSales  
  14. ADDCONSTRAINTFK_SalesPersonId  
  15. FOREIGNKEY(SalesPersonId)REFERENCEStblSalesPerson(SalesPersonId)  
  16. GO 

Creating an intermediate logic layer in ASP. NET Crystal Report tutorial

In the intermediate logic layer component, we create two classes for each table. For example, for tblItems tables, create item and items classes. The Item Class records the details of each sold Item, while the items table records all sold items and there is a way to add them. In this way, the following six classes exist:

Item and Items
SalesPerson and SalesPersons
Sale and Sales

Next, let's take a look at the attributes in each class:

Item class

Includes the following attributes:
ItemId: item id number)
Description of the product)
Items

There is a way to return an item object based on the item number

PublicFunctionGetAllItems () AsCollections. ArrayList

SalesPerson

This class has the following three attributes:
SalesPersonId salesperson ID)
Name)
Password)

SalesPersons

There is a way to verify whether the salesperson's login is correct in the database based on the username and password entered by the salesperson during login. If yes, zero is returned.

PublicFunctionValidateUser (strUserNameasString, strPasswordasString) AsInteger

Sale

The following five attributes are available:
SaleId
SalesPersonId
ItemId
SaleDate
Amount

Sales

There are two methods. getsales returns the set of sales Objects Based on the input parameters.

PublicFunctionGetSales (OptionalnSaleIdAsInteger = 0, OptionalnSalesPersonIdAsInteger = 0, OptionalnItemIdAsInteger = 0) AsCollections. ArrayList

There is also an addsales Method for adding an order

PublicFunctionAddSale (objSaleAsSale)


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.