260 likes | 406 Views
Visual Studio.NET 2005 Using RAD Tools for N-Tier Development. Andy Beaulieu MCT, MCSD.NET. Drag/Drop Apps?. Demo Using Server Explorer Drag/Drop Table onto Page Use Smart Tag for Formatting No code is generated; instead, everything is “declarative”. Drag/Drop Apps?.
E N D
Visual Studio.NET 2005Using RAD Tools for N-Tier Development Andy Beaulieu MCT, MCSD.NET
Drag/Drop Apps? • Demo • Using Server Explorer • Drag/Drop Table onto Page • Use Smart Tag for Formatting • No code is generated; instead, everything is “declarative”
Drag/Drop Apps? Looking at the source view…
Pros and Cons • Pros • Very fast • Little coding knowledge required • Cons • Easy to break (no validation) • 2Tier Architecture • No reusability • Limited functionality (at some point, you have to code).
N-Tier Architecture • With a bit more work, we can still use RAD tools but get an N-Tier Architecture. • N-Tier provides reusability, scalability, maintainability.
Data Access Layer • Provides “Programmer Friendly” components for retrieving and updating data • Developer is freed from writing mundane and error-prone ADO.NET code • Instead can concentrate on Business Logic
Data Access Layer • TableAdapter is a new class ideal for creating DAL components • Exists within context of a Typed DataSet • Contains DB Connection logic, Select, Insert, Update, Delete commands.
Data Access Layer DEMO: Using VS.NET 2005 Designers to create a DAL component (Typed DataSet + TableAdapter)
Data Access Layer Note on WindowsForms Clients: • WindowsForms clients can take advantage of DataSet events for validation! • Provides strongly typed row argument • Not usable from ASP.NET client using ObjectDataSource
Business Logic Layer • provides validation and workflow • We will extend the Data Access Layer to provide BLL layer • New ObjectDataSource component allows data binding between UI and BLL components
Business Logic Layer • If we want to use ObjectDataSource component for data binding, we must follow some rules…
Business Logic LayerRules for ObjectDataSource • “select” methods must return a DataSet, Typed DataSet, IEnumerable implementation, Collection, or Array. Public Function GetCustomers() As DataSet Public Function GetCustomers() As CustomerDataSet Public Function GetCustomers() As CustomerCollection
Business Logic LayerRules for ObjectDataSource • Insert, update, delete methods must take each field as individual parameters, or a single object containing fields as properties Public Sub Update(ByVal CustomerId As String, _ ByVal CompanyName As String, _ByVal Address As String, ByVal City As String) Public Sub Update(ByVal oCustomersBLL As CustomersBLL)
Business Logic Layer • Good News:The TableAdapter conforms to the requirements of the ObjectDataSource control! • This means we can extend the TableAdapter control to add our own customizations such as validation
Business Logic Layer DEMO: Creating the Business Logic Layer Component
Presentation LayerWeb UI • User interface • Input and validation • ObjectDataSource can be used to bind UI Elements to Business Logic Layer components
Presentation LayerWeb UI DEMO: Creating an input page using the GridView, ObjectDataSource, and BLL Component
Adding ValidationWeb UI • GridView class exposes a RowUpdated event which is fired whenever a row is updated Protected Sub GridView1_RowUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdatedEventArgs) Handles GridView1.RowUpdated
Adding ValidationWeb UI • RowUpdated Event e.Exception argument will contain any errors raised from the update Protected Sub GridView1_RowUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdatedEventArgs) Handles GridView1.RowUpdated If Not e.Exception Is Nothing Then
Adding ValidationWeb UI • We can create a Custom Exception Class to raise Validation errors through the ObjectDataSource component’s Update Event. • CExceptionDetail will hold single error • CValidationException inherits from ApplicationException and holds List of CExceptionDetail.
Adding ValidationWeb UI DEMO: Adding Validation to the Web UI
Presentation LayerWinForms UI • We can reuse Business Logic Layer in WinForms Client • Why WinForms? • “Smart Client” • WinForms are “statefull” • Better DataBinding support • Easy Distribution • Web Browsers Suck!!!
Presentation LayerWinForms UI DEMO: Creating the Windows UI
Adding ValidationWinForms UI DEMO: Adding Validation to WinForms
A Quick word about Transactions For Web UI’s, look at Transaction Attribute on Page For WinForms UI’s, look at new System.Transactions.TransactionScope Ideally, should Introduce Business Façade Layer for Winforms