NET Library Application

  • Upload
    phil-wu

  • View
    220

  • Download
    1

Embed Size (px)

Citation preview

.NET Library Application

Phil Wu

Introduction

This brief portfolio highlights a .NET Library project I did during my time with SetFocus.

Project Overview

A library application was developed that allows the user (i.e. librarian) to perform the following functions:Obtain and display member information

Add a new adult member

Add a new juvenile member

Check in book

Check out books

Add new books or additional copies of existing books

Renew expired members

Convert juvenile members to adult members

N-tier Design - 4 tiers in this case

Presentation Layer (Front-end) TierWindows Forms (Phase 1), Web-based (Phase 3)

Entities Layer

Business objects shared across the first three layers

Business Layer Tier Business Rules...

Data Access Layer TierAccessing data

Database Layer Tier | Data and stored procedures

Multiple Phases

The project was broken down into multiple phases.

Phase 1 Presentation Layer (front-end user interface) using Windows FormsRequirements

This initial phase involves creating the Presentation Layer (front-end user interface). The Database, Data Access Layer, and Library Entities assemblies were provided by a third party. The requirements were:

Design and develop the Presentation Layer (basic front-end user interface) that calls into the Business Access Layer. The basic user interface should be intuitive and satisfies four of the above basic functions: adding a new adult member; adding a new juvenile member; check in a book; checking out a book. Interface requires minimal training for users while minimizing resource utilization.

Develop the Business Layer that calls into the Data Access Layer.

Develop easily maintainable code.

Provide validation for all required fields.

Provide adequate error handling.

Technologies used

Visual Studio 2008, .Net Framework 3.5, C#, Windows Forms, Regular Expressions

Presentation Layout Overview

Overall Layout

Read-only info boxes

Presentation Samples of User Interaction

Get Member Information

Sample success scenario

C) Successful status message

D) An option to highlight an item in the data grid and check it in is available

A) The Get Member Information Button was clicked

B) A data grid shows items that are checked out by the member

Sample scenario with error handling

A) User enters an invalid. B) In this particular case, the application notices that the ID is out of range. An error provider next to the field lets the user know of this error.

Checking out a book

Sample success scenario

C) User clicks on Get Item Info Book button...this takes the user back to the Get Member Info tab

A) User clicks on Check Out Tab

D) User clicks on Check Out Book button which brings user back to the Get Member Info tab, NOTE: button does not appear until after user clicks Get Item Info

Book info appears here after user clicks Get Item Info so the Librarian knows what is being checked out exactly. If the book is already on loan, the checkoutdate and duedate fields are populated.

B) User fills out fields

D) A messagebox allows the user to confirm, cancel, or simply start over the operation

F) Successful status message

E) DataGrid is updated with the newly checked out item

B) The application includes a final input validation mechanism to make sure all user input is valid.

A) User clicks on Add Adult button to add an adult member to the library.

Error providers tell the user exactly what the input should be and ensure that proper input is entered.

B) User clicks on Add Adult button to add an adult member to the library.

A) Fields are properly filled out by User

C) A new member number is generated and the new member information is displayed

Code Samples for Phase 1

Event handling code

(form level code)

B) Reset the status message

A) Final form validation for user inputs to ensure all fields are filled out properly

C) 1) Read in the member ID field2) Create a Business Layer object and call it's GetMember() method using the memberID as an input parameter3) Point a new member object to the member object that is returned from step 24) Display the member info and populate the data grid

Event handler code for the Get member Info Button

Input Validation via Regular Expressions

(business layer code)

Regular Expression

(form layer code that calls into business layer)

Populating the Data Grid Views

(form layer code)

Databound datagridview method

Unbound datagridview method

Checking in a book by highlighting in the Get Member Info tab

(form layer code)

Input validation to make sure User clicked Get Member info button first

Call check in books method from the Business Layer

Make sure User an item is highlighted in the datagridview.

Phase 2 Business and Data Access LayerRequirements

In phase 1 of the ongoing project, an Data Access Layer assembly that encapsulates all the data access logic was provided by a third party. It did not use any stored procedures which could have made operations more efficient. The requirements were:Design and implement a new Data Access Layer to replace the Data Access assembly from Phase 1 using ADO.NET.

Write new stored procedures that will be called by the new Data Access Layer. The Data Access Layer should not contain any SQL statements.

Re-use the Business Layer developed in Phase 1

Design and implement your own Business Entities class containing all the business objects to replace the Business Entities assembly provided in Phase 1.

Use database-programming techniques that provide maximum programming flexibility and control while minimizing resource utilization.

Use SQL Server .NET Data Provider

Technologies used

Visual Studio 2008, .Net Framework 3.5, C#, ADO.NET, SQL Server 2008, Transact-SQL (stored procedures)

Code Samples for Phase 2

Get Member Information

(Data Access Layer code)ETC...

C) Pass inputs to the SQL stored procedure on the SQL Server

D) Add output parameters to the SQL stored procedure...this is the data that the stored proc will return

B) The SqlCommand type supports IDisposable so we have this inside a using statement. A command object is created which takes in the proper name of the stored procedure that will be called through the database connection.

A) Use a Sql connection object and set it to the appropriate connection string (this string is returned by the GetConnection() method)

(Continued from last page...)

NOTE: Steps A D all happen on the application level as part of a disconnected model. This way, we minimize the number of database connections needed and save resources. Basically, we do as much work upfront before talking to the database.

ETC...

G) Populate the member object properties with the data returned from the database

F) Call the ExecuteNonQuery() method from the command object to invoke the stored procedure on the SQL Server

E) Finally, we open up the database connection. Because of the using block, we don't have to worry about explicitly closing the connection later.

H) Return the member object with all the data

SQL Stored Procedure - Get Member Information

Stored procedure name

Input / Output variables (the output variables store the data the will be returned to the method that called this stored procedure, the input variables hold data that is passed into this procedure)

(CONTINUED from last page...)

Transaction block ensures successful completion of operations. Failure of any transaction results in a rollback (changes are undone and not committed and an error is passed to the application.

Each stored procedure returns error codes that are specific to the error. Here we check for null input which is invalid. An error code of -1 is returned to the application which properly handles it using a custom exception handler.

Phase 3 Web-based version of Phase 1 and 2

Requirements

In this phase, a web-based version of Phases 1 and 2 is created. The requirements were:

Create a web application was created that supports all of the functionality required for Phase 1 and 2 of the Library project. The Presentation Layer using Windows Forms was essentially replaced with ASP.NET Web forms.

Provide forms authentication and security using ASP.NET Membership and Role Management

Technologies used

Visual Studio 2008, .Net C#, ASP.NET, Regular Expressions\

Presentation Layer Samples

Adding a new adult member

Sample success scenario

Status message lets user know of success, failure, or error message

A) User fills in new member data.

C) New member ID is generated

B) User presses Add Adult button

Checking out a library item

A) User enters in item data and member who will be checking out the item.

B) User clicks Get Item Info button

D) Check out button will now be displayed. This button stays hidden until the user clicks on the get item info button.

C) Item info is displayed

Code samples for Phase 3

Code-behind for the Add Adult Member function

ETC...similar to event handling code from the above phases...

Page loader

The applications references an XML file containing all the state abbreviations and then loads up dropdown list web control with them.

Markup code for the Check Out Item Page

ASP.net web form validation controls

ASP.net web button control that calls the code behind method.

ASP.net label controls with customizable HTML attributes

Phase 4 Web ServicesRequirements

This phase essentially adds Web Services to the Library Application using WCF. The requirements were:

Create and add WCF Web Services that calls into the Business Layer in the Library Application to allow interoperability with other systems through the WCF message passing mechanism.

Update the Presentation Layer (front-end user interface) to call the Web Service while supporting all previous functionality from the previous phases.

Secure the application using WSE 3.0 and signed certificates, encryption, and secured sessions.

Host the application on the Windows Visual Studio Development Server.

Create a client application to test the Library Application.

Technologies used

Visual Studio 2008, .Net C#, WCF, Web Services

Code Samples for Phase 4

Service Contract Code

ETC....

Service Contract attribute

Fault and operation contracts for each method (also known as an operation from a WCF standpoint)

Implementation of the Interface

ETC....

Team Project LINQ to XML, Version Control

Requirements

This project was designed to simulate a real-world team-based environment where more than one person is working on the same project through the use of source control. This phase essentially involved modifying a third party's existing web application to interface with an XML data source rather than the SQL Server Database. An XML data source file was provided. The requirements were:

Re-write the Data Access Layer using LINQ to XML to interface with the XML data source.

Leverage source control software (Sub Version, Beyond Compare, AhnkSvn) to avoid coding conflicts and enhance productivity.

Establish a good work breakdown scheme to allocate tasks efficiently.

Figure out who would be a good team lead.

Establish good rapport with one another, avoid personality conflicts, and help each other out.

Write a test harness to thoroughly test the modified web application.

The modified web application must continue to support the following functionality:

Technologies used

Visual Studio 2008, .Net C#, LINQ to XML

Code Samples for Team Project

(Data Access Layer code)

LINQ to XML assembly

XML file path

Perform a query for the session with the given attributes. Use a strongly-typed IEnumerable object to hold the results.

Load the XML data into memory via an XDocument object

(CONTINUED from last page...)

ETC...

Iterate through the XML results data and populate the session fields.