intTypePromotion=1
zunia.vn Tuyển sinh 2024 dành cho Gen-Z zunia.vn zunia.vn
ADSENSE

Phát triển ứng dụng web nâng cao với ASP.net - Part 4

Chia sẻ: Huongdanhoctot Huongdanhoctot | Ngày: | Loại File: PDF | Số trang:17

64
lượt xem
12
download
 
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

Tài liệu giảng dạy về ASP.net đã được giảng dạy với mục đích cung cấp cho sinh viên những kiến thức cơ bản nhất, có tính hệ thống liên quan tới lập trình. Thông qua cuốn tài liệu này, chúng tôi muốn giới thiệu với các bạn đọc về kỹ năng lập trình cơ bản.Mời các bạn cùng tham khảo

Chủ đề:
Lưu

Nội dung Text: Phát triển ứng dụng web nâng cao với ASP.net - Part 4

  1. 03/11/2010 TRƯ NG Đ I H C KHOA H C T NHIÊN KHOA CÔNG NGH THÔNG TIN B MÔN CÔNG NGH PH N M M --- --- Product Catalog – P2 Môn h c: Phát tri n ng d ng Web nâng cao v i ASP.NET 1 N i dung 2 Gi i thi u relational data, relationship gi a các datatables trong cùng m t database S d ng join table, sub query, tri n khai phân trang t i thành ph n Data tier, các k thu t m r ng trên SQL Xây d ng thành ph n Business tier s d ng store procedures v i input và output parameter Xây d ng thành ph n Presentation tier 1
  2. 03/11/2010 M cl c 3 Xây d ng thành ph n Data Tier Code 1. Relational Database 1. Các bư c ti n x lý 2. ADO.NET v i Parameterized Store Procedures 3. Xây dưng thành ph n Business Tier Code 2. Xây d ng thành ph n Presentation Tier Code 3. Relational Database 4 Relational Data ? M i liên h gi a b ng Product và Category M i liên h gi a b ng Category và Department M i liên h gi a b ng Orders và Customers … Relational Database Management Systems (RDBMS) MySQL, PostgreSQL, SQL Server Oracle,DB2 Table Relationship One– to– Many Many– to–Many 2
  3. 03/11/2010 Unrelated Table 5 Relational Data và Table Relationships 6 Liên quan n các table Product Category Department Các table liên h v i nhau thông qua các m i quan h: One-to-many Many-to-many 3
  4. 03/11/2010 One–to–Many Relationship 7 Là m i liên h th hiên: M t record trong m t b ng có liên h v i nhi u record trong m t b ng related khác Th hi n qua m i liên h Department - Category One–to–Many Relationship 8 4
  5. 03/11/2010 Many-to-many Relationship 9 Là m i liên h th hiên: Nhi u records trong hai b ng có m i liên h v i nhau Th hi n qua m i liên h Product - Category Tuy nhiên vi c th hi n m i liên h này c n dùng thông qua m t b ng th ba g i là ProductCategory (ProductID, CategoryID) – thư ng g i là Linking table ho c Associate table và s d ng hai m i liên h one-to-many relationship liên k t 3 b ng l i. Many-to-many Relationship 10 5
  6. 03/11/2010 Many-to-many Relationship 11 Foreign key contraints 12 Cơ ch m b o relationship gi a các data tables Referecing table vs referenced table 6
  7. 03/11/2010 M cl c 13 Xây d ng thành ph n Data Tier Code 1. Relational Database 1. Các bư c ti n x lý 2. ADO.NET v i Parameterized Store Procedures 3. Xây dưng thành ph n Business Tier Code 2. Xây d ng thành ph n Presentation Tier Code 3. Các bư c ti n x lý 14 Bư c 1: T o categories table, product table Bư c 2: Query data L y thông tin short product description Joining data tables Implementing paging Bư c 3: Các k thu t s d ng Store Procedures 7
  8. 03/11/2010 Category Table - Foregin Key 15 ALTER TABLE Category ADD CONSTRAINT FK_Category_Department FOREIGN KEY(DepartmentID) REFERENCES Department (DepartmentID) Product Table – ProductCategory Table 16 8
  9. 03/11/2010 Relationship diagram 17 Querying the data 18 Các n i dung chính: Ch c năng short product descriptions Ch c năng joining data tables Ch c năng phân trang 9
  10. 03/11/2010 Short product description 19 S d ng: SELECT LEFT(Description, 60) + '...' AS 'Short Description‘ FROM Product Joining data tables 20 Ví d : SELECT p.ProductID, p.Name FROM ProductCategory pc INNER JOIN Product p ON p.ProductID = pc.ProductID WHERE pc.CategoryID = 5 10
  11. 03/11/2010 Show Product Page by Page 21 Hai phương pháp paging Paging t i Data tier level ? Paging t i Presentation tier level ? S d ng Data tier level Better performance Áp d ng m t s k thu t khá hay: S d ng DbDataReader ho c Write custom store procedures => best Show Product Page by Page 22 Ví d : SELECT ROW_NUMBER() OVER (ORDER BY ProductID) AS Row, Name FROM Product Ghi chú: áp dung cho SQL 2005 : ROW_NUMBER() SELECT Row, Name FROM( SELECT ROW_NUMBER() OVER (ORDER BY ProductID) AS Row, Name FROM Product ) AS ProductsWithRowNumbers WHERE Row >= 6 AND Row
  12. 03/11/2010 ROW_NUMBER() 23 Show Product Page by Page 24 K thu t Table Variables -- declare a new TABLE variable DECLARE @Products TABLE (RowNumber INT, ProductID INT, Name VARCHAR(50), Description VARCHAR(5000)) -- populate the table variable with the complete list of products INSERT INTO @Products SELECT ROW_NUMBER() OVER (ORDER BY Product.ProductID) AS Row, ProductID, Name, Description FROM Product 12
  13. 03/11/2010 Store Procedures 25 Syntax CREATE PROCEDURE [( [=] [INPUT|OUTPUT], [=] [INPUT|OUTPUT], ... ... )] AS Store Procedures 26 Ví d : GetDepartmentDetails CREATE PROCEDURE GetDepartmentDetails (@DepartmentID int) AS SELECT Name, Description FROM Department WHERE DepartmentID = @DepartmentID Các store procedures khác: GetCategoryDetails, GetProductDetails, GetCategoriesInDepartment, 13
  14. 03/11/2010 Store Procedure s d ng Output Parameter 27 Ví d : GetProductsOnCatalogPromotion Store Procedure s d ng Output Parameter 28 Các Store Procedure khác: GetProductsInCategory GetProductsOnDepartmentPromotion 14
  15. 03/11/2010 M cl c 29 Xây d ng thành ph n Data Tier Code 1. Relational Database 1. Các bư c ti n x lý 2. ADO.NET v i Parameterized Store Procedures 3. Xây dưng thành ph n Business Tier Code 2. Xây d ng thành ph n Presentation Tier Code 3. ADO.NET v i Parameterized Store Procedures 30 S d ng i tư ng DbCommand (t ng quát c a SqlCommand) 15
  16. 03/11/2010 DbCommand v i Input Parameter 31 DbCommand comn = … DbParameter param = comm.CreateParameter(); param.ParameterName = "@DepartmentID"; param.Value = value; param.DbType = DbType.Int32; comm.Parameters.Add(param); DbCommand v i Output Parameter 32 DbCommand comn = … DbParameter param = comm.CreateParameter(); param.ParameterName = "@HowManyProducts"; param.Value = ParameterDirection.Output; param.DbType = DbType.Int32; comm.Parameters.Add(param); 16
  17. 03/11/2010 Thành ph n Business Tier Code 33 Thêm thông tin trong web.config, BalloonShopConfiguration class, CatalogAccess class Thành ph n Presentation Tier Code 34 Xây d ng các thành ph n CategoriesList.ascx: hi n th danh sách các Category thu c m t Department Catalog.aspx: hi n th thông tin v Department ho c Category ProductList.ascx: hi n th danh sách các s n ph m Product.aspx: hi n th thông tin chi ti t v m t s n ph m 17
ADSENSE

CÓ THỂ BẠN MUỐN DOWNLOAD

 

Đồng bộ tài khoản
2=>2