17
As Implemented By: Alan P. Weir [email protected] 860-649-7603 ® Library Project

Linked In Presentation

Embed Size (px)

DESCRIPTION

Setfocus Library Project

Citation preview

Page 1: Linked In Presentation

As Implemented By: Alan P. [email protected] 860-649-7603

® Library Project

Page 2: Linked In Presentation

The library project is an intensive, hands-on, project where knowledge and experience is gained in the key components necessary to roll out Windows, ASP.Net, and WCF applications.

It encompasses:

• Developing solutions for diverse programming scenarios in C#

• Developing queries using MS SQL Server 2008 Transact-SQL (T-SQL)

• Using C#, LINQ and ADO.NET to define and implement secure middle-tier components

• Creating and deploying XML Web Services using ASP.NET and Windows Communication Foundation (WCF)

• Consuming Web Services from Windows forms and ASP.NET web applications

• Creating Deployment projects for .NET applications using Microsoft’s MSI packages

® uses a progressive Library Project consisting of four distinct phases throughout the curriculum.

Page 3: Linked In Presentation

A database has been created to support the principal functions of a lending library’s day-today operations: adding new members (adult and juvenile) and checking books in and out. An assembly has been created that contains classes and interfaces that provide access to the database for these functions. What is needed is a Windows Forms-based front-end application that will provide a librarian with a visual interface through which he or she may perform the desired functions.

Phase I— Create a Windows front end User

Page 4: Linked In Presentation

public partial class frmStart : Form{#region Add Juvenile /// <summary> /// Tool Strip Menu - Add Juvenile Member /// Button Click Add Juvenile /// </summary> /// <param name=”sender”></param> /// <param name=”e”></param>private void addJuvenileToolStripMenuItem_Click(object sender, EventArgs e){ UtilityMethods ja = new UtilityMethods(); ja.frmJuvenileAddShow();}private void btnAddJuvenile_Click(object sender, EventArgs e){ UtilityMethods ja = new UtilityMethods(); ja.frmJuvenileAddShow();}#endregion //Juvenile add/// <summary>Utility Methods</summary>public class UtilityMethods{#region Show Forms/// <summary>Show Juvenile Add</summary> public void frmJuvenileAddShow() { frmAddJuvenile frm = new frmAddJuvenile(); frm.Show(); }}

Code Showing the Add Juvenile Form

Page 5: Linked In Presentation

Add Juvenile Member—Preprocessing

Page 6: Linked In Presentation

Juvenile Member Added

Page 7: Linked In Presentation

#region Add Juvenile member Add Button Click/// <summary>Add Juvenile Member Add ButtonClick</summary>/// <param name=”sender”></param>/// <param name=”e”></param>private void btnAddJuvenile_Click(object sender,EventArgs e){ try { //Create a new Instance of Jevenile member //and populate some of the fields with theinformation provided in the text boxes

var myJevMember = new Member();

myJevMember.firstname = txtFirstName.Text; if (txtMiddleInitial.Text == null) { txtMiddleInitial.Text = “ “; }myJevMember.middleinitial = tMiddleInitial.Text[0];myJevMember.lastname = txtLastName.Text;myJevMember.adult_member_no = mId;myJevMember.birth_date = dateTimePicker1.MinDate;

BusinessLayer bl = new BusinessLayer();bl.AddJuvenileMember(myJevMember);

DialogResult response =MessageBox.Show(string.Format(“{0} ‘s new member number is {1}”, myJevMember.firstname, myJevMember.member_no.ToString()), “Juvenile Added”, MessageBoxButtons.OKCancel);

if (response == DialogResult.OK) { txtAdultID.Text = string.Empty; txtFirstName.Text = string.Empty; txtMiddleInitial.Text = string.Empty; txtLastName.Text = string.Empty; txtAdultFirstName.Text = string.Empty; txtAdultLastName.Text = string.Empty; txtState.Text = string.Empty; txtStreet.Text = string.Empty; txtCity.Text = string.Empty; txtZipCode.Text = string.Empty; txtPhone.Text = string.Empty;}else { this.Close(); } }catch (LibraryException ex) { switch (ex.LibraryErrorCode) { case ErrorCode.MissingAdultMember: tssMessage.Text =”Missing AdultMember Failure”; break; case ErrorCode.NoSuchMember: tssMessage.Text = “Adult Member Not Found”; break; case ErrorCode.None: tssMessage.Text = ex.Message; break; default: tssMessage.Text = ex.Message; break; } } catch (Exception ex) { tssMessage.Text = ex.Message; } }#endregion Add Juvenile member Add Button Click

Add Juvenile Member Code

Page 8: Linked In Presentation

Requirements:

• Develop code that is easily maintainable.

• Provide adequate error handling.

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

• Work with your instructor who will act as the project DBA for any required SQL help.

Phase II— Design and Create the Business and Data

Page 9: Linked In Presentation

In Phase 1 of this ongoing project, you were provided with an assembly that encapsulated all the data access logic for your application. The assembly in Phase 1 employed ADO.NET to provide access to the library database. It did not, however, use any stored procedures, which could have made database operations more efficient. In Phase 2, you are to design and implement your own business and data access tiers. Use stored procedures which must be commented thoroughly and your code should not contain any SQL statements.

You were also provided an assembly that contained business entity classes needed for the project (e.g., Item, ItemsDataSet, Member, etc.). You must not use either of the assemblies that were provided to you in your Phase 2 project. You must implement the business entity classes yourself. You are not obligated to use the same interface that the data access object in the assembly provided in Phase 1 employed. If you wish to redesign this interface, you may do so, provided that all required functionality is supported.

In Phase 1 of this ongoing project, verification that an item presented for checkout is loanable was not a requirement. In this phase, you must perform that verification and prevent an item that is not loanable from being checked out.

Focus your efforts on the following:

• Add Adult: Rows are added to both the member table and the adult table.

• Add Juvenile: Verification that the sponsoring adult member’s record exists (and is unexpired) must be performed.

• The juvenile’s age should be verified that it is an acceptable age of a juvenile. Rows are added to both the member table and the juvenile table.

• Checkout item: Verification that item exists and is not already on loan must be performed.

• Verification that item is loanable must be performed. Row is added to loan table. Update copy table’s on_loan field to ‘Y’.

• Checkin item: Verify that the item exists and is on loan. Delete row from loan table. Add row to loanhist table. Update copy table’s on_loan field to ‘N’.

The data access tier has to be stateless. Stateless means that the data access class must not maintain variable state between method calls. Variable state should be kept to local variables.

Remember to treat operations that involve multiple tables as transactions, and validate against null inputs in each relevant procedure.

Required Functionality:

Page 10: Linked In Presentation

Add Juvenile Stored Procedure

USE [library]GO

SET ANSI_NULLS ONGO

SET QUOTED_IDENTIFIER ONGO

IF OBJECT_ID(‘[dbo].[uspJuvenileMemberInsert]’) IS NOT NULLDROP PROCEDURE[dbo].[uspJuvenileMemberInsert]GO

CREATE PROCEDURE[dbo].[uspJuvenileMemberInsert] @member_no smallint OUTPUT ,@lastname varchar (15) ,@firstname varchar (15) ,@middleinitial char (1) = NULL ,@adultmemberno smallint ,@birthdate datetimeAS

BEGINIF @lastname IS NULL OR @firstname IS NULL OR @adultmemberno IS NULL OR @birthdate IS NULLBEGIN RAISERROR(‘You Must provide Member Info’,11,1) RETURNEND

IF NOT EXISTS (SELECT * FROM dbo.adult WHERE member_no = @adultmemberno)

BEGIN RAISERROR(‘AdultMember Not Found’, 11, 2) RETURN

SET NOCOUNT ON;

BEGIN TRANSACTION INSERT dbo.MEMBER ( Lastname ,Firstname ,Middleinitial ) VALUES ( @lastname ,@firstname ,@middleinitial ) IF @@error <> 0BEGIN ROLLBACK TRAN RETURNEND

SET @member_no = Scope_Identity() INSERT dbo.juvenile( member_no ,adult_member_no ,birth_date ) VALUES ( @member_no ,@adultmemberno ,@birthdate ) IF @@error <> 0 BEGIN ROLLBACK TRAN RETURN ENDCOMMIT TRANSACTIONEND

Page 11: Linked In Presentation

Business Layer Code/// <summary>Get Books on loan by members</summary>/// <param name=”myMember”></param>/// <returns></returns>public AW.LibraryEntitiesLINQ.ItemsDSLINQ getItems(short myMember){//Create a Library data access objectDataAccessLINQcode dalc = new DataAccessLINQcode();return dalc.getItems(myMember);}

Data Access Layer/// <summary>Data Access Class </summary>#region Data Access Classpublic class DataAccessLINQcode{/// <summary>Get The Items Data Set Info</summary>/// <param name=”member_no”></param>/// <returns>Books on Loan for this Member</returns>public ItemsDSLINQ getItems(short member_no){ try { var itemsDSL = new ItemsDSLINQ(); using (ItemsTALINQ ita = new ItemsTALINQ()) { ita.Fill(itemsDSL.ItemsLINQ, member_no); } return itemsDSL; } catch (SqlException ex) { if (ex.State == 1) { throw new LbraryException(ex.ToString(), ErrorCode.MissingAdultMember, ex); } else } throw new LibraryException(ex.ToString(), ErrorCode.GenericException, ex); } }}

Retrieve Books on Loan By Member— Load a LINQ Dataset

Page 12: Linked In Presentation

Phase III— Web Application (ADO.NET, ASP.NET, LINQ, AJAX Controls)

Additional requirements:

• When displaying an adult’s information, the application should detect if the card is expired and give the librarian a chance to renew the card. Librarian must be able to choose whether or not to renew the card. The renewal date is today plus one year. Members cannot check out books if the card is expired.

• When dealing with juveniles, the application should detect if the juvenile is 18 years old or older and convert the member to an adult (row deleted in the juvenile table, row added to the adult table). This operation is not at the discretion of the librarian; i.e. the upgrade must take place automatically and the librarian must be notified that the upgrade has taken place.

• Overdue books, shown in any display, must be highlighted.

• The librarian must be able to enter a new book into the database. If the ISBN already exists in the database, all that is needed is to add a record for a new copy number. If the ISBN does not yet exist in the database,

you must add all necessary records for the new ISBN and a new copy number 1 for that ISBN.

• On the Member Information page the design must be altered to use two AJAX controls, the Update Panel control and the Update progress control. The Update Panel control will need to be placed on the form and the grid view that displays checked out items will then be placed within the Update Panel control. The check in functionality will reside within the panel and when an item is checked in a postback for the entire page should not be triggered. Only the information within the Update Panel should be updated. Additionally, the Update Progress control should display the progress of the check in action. (If your project does not currently have a page that displays the member’s information, with a grid that displays the items that are checked out, one will need to be added. The librarian should be able to select a row and click a check in button to check the item back into the library).

• Use hyperlinks to navigate between pages.

Requirements:Create a web application that supports all the functionality required for Phase I and II of the Library project.

Page 13: Linked In Presentation

Add Member—both Adult and Juvenile— using LINQ–Data Access Code

///<summary>Data Access Class </summary>#region Data Access Classpublic class DataAccessLINQcode#region Add Member - Adult and Juvenile/// <summary>Add Member</summary>public AW.LibraryEntitiesLINQ.Member addMember(Member myMember){var ldc = new AW_LibraryObjectModelDataContext();short? tempID = myMember.member_noldc.AdultInsert(ref tempID ,myMember.lastname ,myMember.firstname ,myMember.middleinitial ,myMember.street ,myMember.city ,myMember.state ,myMember.zip ,myMember.phone_no);if (tempID.HasValue){ myMember.member_no = (short)tempID;}else{throw new LibraryException (ErrorCode.MemberNumberCameBackNull, “Member No Came Back Null”);}return myMember;} //method add Adult

/// <summary>Add Juv’y Member</summary>public AW.LibraryEntitiesLINQ.Member addMemberJev(Member myJuvenileMember){var ldc = new AW_LibraryObjectModelDataContext();short? tempID = myJuvenileMember.member_no; ldc.JuvenileInsert(ref tempID ,myJuvenileMember.firstname ,myJuvenileMember.lastname ,myJuvenileMember.middleinitial

#regionDataAccessClasspublicclassDataAccessLINQcode ,myJuvenileMember.adult_member_no ,myJuvenileMember.birth_date);

if (tempID.HasValue){myJuvenileMember.member_no = (short)tempID}else{throw newLibraryException(ErrorCode.MemberNumberCameBackNull, “Member No Came Back Null”);}return myJuvenileMember;}// end Method Add uvenile#endregion //Add Member - Adult and Juvenile

Page 14: Linked In Presentation

Retrieve Member Information— Highlighted Over Due Book(s)

protected voidbooksGridView_RowDataBound(object sender,GridViewRowEventArgs e){if (e.Row.RowType !=DataControlRowType.DataRow) return;try{DataRowView row = e.Row.DataItem as DataRowView;BusinessLayer bl = new BusinessLayer();If (bl.IsOverDue((DateTime)row[“due_date”])){e.Row.ForeColor = System.Drawing.Color.Red;tssMessage.ForeColor = system.Drawing.Color.Red;tssMessageExpired.Visible = true;tssMessageExpired.Text = “Book is Over Due”;}}

// update the CheckIn argumentsInt32 isbn = (Int32)row[“isbn”];Int16 copyNo = (Int16)row[“copy_no”];LinkButton cmdCheckIn =(LinkButton)e.Row.FindControl(“cmdCheckIn”);cmdCheckIn.CommandArgument = String.Format(“{0}|{1}”, row[“isbn”], row[“copy_no”]); // 1|3}catch{tssMessage.ForeColor = Color.Red;tssMessage.Text = (“An unexpected error occured”);}}

Page 15: Linked In Presentation

Our library system rollout has been very successful. As the potential to acquire libraries and creating partnerships with others increases, we see the need to take the library system to the next level—allow interoperability with other systems. With the success on the library system thus far, we are tasking you to provide a proof of concept implementation that utilizes Web services. Use Windows Communication Foundation (WCF) to implement the service. To provide the proof of concept system, you must implement a system that uses Web services to offer access to the business layer. Due to the possibility of utilizing the service between our own systems and those of our partners, security must be employed. Use your existing presentation front-end for the client layer.

Requirements: • Create a WCF service that calls into the business layer. Do not re-write

the business layer. Simply have the service call into the layer.

• Update the presentation (UI) layer to call the WCF service. This will require changing some namespaces and references to accommodate the service.

• The WCF Service must be implemented with or support the following: – WCF Service Library project – WCF Service Website – Uses the WCF Service Library project – Uses WsHttpBinding – Authentication using ASP.NET membership—must be a member

of the LibraryPartner role – Authorization using ASP.NET roles—LibraryPartner role – Use PrinciplePermission to secure service operations – Use DataContracts for entities – Support previous project functionality

Phase IV— WCF Service

Page 16: Linked In Presentation

WEB Service— Interface and Contracts

namespace AWPhase4ServiceLibrary{/// <summary>WEB Service</summary>[ServiceContract(Namespace =“http://AlanWeir.com/”)]public interface IAWPhase4Service{/// <summary>Contract</summary>/// <param name=”ISBN”></param>/// <param name=”Copy_no”></param>[OperationContract][FaultContract(typeof(LibraryFaultErrors))]void CheckBookIn(int ISBN, short Copy_no);

/// <summary>Retrieve Member Info</summary>/// <param name=”memberID”></param>// <param name=”rv”></param>/// <returns></returns>[OperationContract][FaultContract(typeof(LibraryFaultErrors))]Member getMember(short memberID, ref int rv);

/// <summary>Add Adult Member</summary>/// <param name=”myMember”></param>[OperationContract][FaultContract(typeof(LibraryFaultErrors))]Member addMember(Member myMember);

/// <summary>Add Juvenile Member </summary>/// <param name=”myJuvMember”></param>[OperationContract][FaultContract(typeof(LibraryFaultErrors))]Juvenile addJuvenileMember(Juvenile myJuvMember);

/// <summary>Get Copy No for BookAdd</summary>/// <param name=”ISBN”></param>/// <returns>Copy Number</returns>[OperationContract][FaultContract(typeof(LibraryFaultErrors))]CopyNumber getCopyNumber(int ISBN);

/// <summary>Retrieve book Info</summary>/// <param name=”ISBN”></param> <paramname=”Copy_no”></param>/// <returns>Book Info</returns>[OperationContract][FaultContract(typeof(LibraryFaultErrors))]Item GetItemInformation(int ISBN, short Copy_no);

/// <summary>Add Book</summary>/// <param name=”myTCIView”></param>/// <returns></returns>[OperationContract][FaultContract(typeof(LibraryFaultErrors))]AW.LibraryEntitiesLINQ.TCIViews addBook(TCIViews myTCIView);

/// <summary>Check book out</summary>/// <param name=”memberID”></param>/// <param name=”itemISBN”></param>/// <param name=”itemCopy”></param>[FaultContract(typeof(LibraryFaultErrors))][OperationContract]void CheckOutItem(short memberID, int itemISBN, short itemCopy);}}

Page 17: Linked In Presentation

namespace AWPhase4ServiceLibrary{/// <summary>Web ServiceAWPhase4</summary>public class AWPhase4Service : IAWPhase4Service{/// <summary>Check Book In</summary>[PrincipalPermission(SecurityAction.Demand, Role = “LibraryPartner”)]public void CheckBookIn(int ISBN, short Copy_no){try {BusinessLayer bl = new BusinessLayer();bl.CheckInItem(ISBN, Copy_no);}catch (LibraryException ex) {var lfe = new LibraryFaultErrors();lfe.Message = ex.Message;lfe.LibraryErrorCode = ex.LibraryErrorCode;throw new FaultException<LibraryFaultErrors>(lfe, lfe.Message);}}/// <summary>Check Book Out</summary>[PrincipalPermission(SecurityAction.Demand,Role = “LibraryPartner”)]public void CheckOutItem(short memberID, int ISBN, short copy_no){try {var bl = new BusinessLayer();bl.CheckOutItem(memberID, ISBN, copy_no);}catch (LibraryException ex){var lfe = new LibraryFaultErrors();lfe.Message = ex.Message;lfe.LibraryErrorCode = ex.LibraryErrorCode;

throw new FaultException<LibraryFaultErrors>(lfe, lfe.Message);}}

Web Service (typical)— Phase IV Visual Studio Solution