setfocus portfolio
DESCRIPTION
TRANSCRIPT
SetFocus Portfolio
Frank Stepanski
215-820-2353
http://www.linkedin.com/in/fstepanskipanet
SetFocus Project #1 - .Net Framework
Objective Build a C# language only business- tier framework, consisting of two assemblies; Foundation and AppTypes.
SummaryThis project demonstrates fundamental .NET skills and interaction between a n-tiered application.
A list of C#/.NET sills used in project:
Delegates, events
Abstract classes Enumerations Generic Collections Methods and properties
Custom exception/attribute classes Collection classes Custom Enumerators Implementation of
ISerializable, IComparer, IComparable, & IList<T> interfaces
Foundation AssemblyThis assembly contains the foundation interfaces and base classes used throughout the project.
SetFocus Project #1 - .Net Framework
AppTypes Assembly
This assembly contains various entity, collections, and exception classes used by the library.
SetFocus Project #2 – Windows Forms Application
Objective
Create a Windows Forms-based front-end application that will provide a user with a visual interface through which various functions are performed. Required functionality included adding new member (adult and juvenile) and checking books in and out.
Summary
This project demonstrates the use of .NET Windows Form development techniques. Some of the techniques used include:
User input validation and feedback using error providers Data binding to a grid view control Incorporates n-tier architecture for scalability Create error and exception handling Use of regular expressions for input validation
Description
The code behind the user interface (FS.LibraryPhase1) handled all validations, screen changes and logic to perform each operation.
The Business layer (FS.LibraryBusiness) provided the connection between the UI and the data access functions. In this project, all data (book, member, loan, etc.) was stored in a SQL Server 2008 database.
The UI does not reference the data access layer, and uses only methods provided by the business layer classes provided true scalability for future modifications or updates.
The UI frontend contains an instance and a reference to the Business layer.
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using FS.LibraryBusiness;
private BusinessLogic businessLogic = new BusinessLogic();
SetFocus Project #2 – Windows Forms Application
Functionality Overview
Add Adult – Adds row to database with fields of Name, Address, City, State, City, Zip, and Phone.
Add Juvenile – Adds row to database with fields ( First, Last Name, and Birthdate).
Search Member – Returns all member data (name, address, books on loan, etc) from member id search.
Checkout - Loans a book for a member by first checking availability and then adding to loaned book queue.
Checkin – Returns book from member and removing loaned status from book.
Business Rules:
First and Last Name must only be 15 characters long and start with a capital letter. Street and City must only be 15 characters long. State is selected from a drop down populated by an XML file. Zip must be in format of either ##### or #####-####. Phone must be in the format of (###) ###- ####. Birthdate must be in the range of 18 years or younger (from today’s date). Juvenile must have a sponsoring adult member before adding to database. Each member can only checkout 4 books at a time. If book to be checked out is already on loan, must be checked in first. Functions for checkin and checkout must be confirmed first by user (Confirm or Cancel).
SetFocus Project #2 – Windows Forms Application
Screenshots:
SetFocus Project #3 – Data Access Layer (Class library)
Objective
This project created the Data Access layer and SQL Server Stored Procedures for the library application to replace the pre-built DLLs that were supplied in the previous project. Additional exception, entity and error code classes were also created as part of this project.
Summary
This project demonstrates the use of ADO.NET and Transact-SQL to access a SQL Server 2008 database. Some of the techniques used include:
Data validation in SQL Stored procedures in Transact-SQL (T-SQL) on SQL Server 2008 Implementing error handing in SQL Accessing stored procedures through System.Data.SqlClient Retrieve and process result sets returned from stored procedures Process errors raised by T-SQL in ADO.NET using error numbers and states
Description
LibraryEntities contained the various classes and enumerations referenced by the entire project. It contains the AdultMember, JuvenileMember, Member, Item and LibraryException classes as well as the ErrorCode enumeration.
The LibraryDataAccess project provides the layer between the Business Layer and the database. The UI (user interface) layer makes requests to the LibraryBusiness layer, which in turn makes requests of the Data Access layer.
The Data Access layer executes the appropriate SQL Server database stored procedures via ADO.NET.
The Business layer contains an instance and has a reference to the Data Access layer:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Data;using FS.LibraryDataAccess;
private DataAccess DataAccess = new DataAccess();
SetFocus Project #3 – Data Access Layer (Class library)
Database diagram of tables and relationships
Data Access method to connect to database:
private SqlConnection GetConnection(){ return new SqlConnection(Properties.Settings.Default.LibraryConnection);
}
<connectionStrings> <add name="FS.LibraryDataAccess.Properties.Settings.LibraryConnection" connectionString="Data Source=.;Initial Catalog=library;Integrated Security=True" providerName="System.Data.SqlClient" /></connectionStrings>
SetFocus Project #3 – Data Access Layer (Class library)
Stored Procedures
Several stored procedures were created to interact with the various related tables in the database. Each stored procedure contains input and output parameters as well as error handing and transactions for any data updates (INSERT, UPDATE or DELETE).
FS_AddultMember – Inserts row into the dbo.member and dbo.adult tables
CREATE PROCEDURE [dbo].[FS_AddAdultMember]-- parameters
@firstname VARCHAR(15), @middleinitial CHAR(1) = null, @lastname VARCHAR(15), @street VARCHAR(15), @city VARCHAR(15), @state CHAR(2), @zip CHAR(10), @phone CHAR(13) = null, @memberID smallint OUTPUT
ASBEGIN
SET NOCOUNT ON; BEGIN TRYBEGIN TRAN
IF @firstname IS NULL OR @lastname IS NULL OR @street IS NULL OR @city IS NULL OR @state IS NULL OR @zip IS NULL
BEGIN
RAISERROR('Library: Missing inputs are required',11,1)RETURN
END
-- temporary variableDECLARE @expirationDate datetime
-- set expiration (1 year from today)SET @expirationDate = DATEADD(year,1,getdate()) -- insert into member table to generate memberidINSERT INTO dbo.member(firstname,middleinitial,lastname)VALUES(@firstname,@middleinitial,@lastname)
-- Get the new ProductIDSET @memberID=SCOPE_IDENTITY()
-- insert into adult table for member contact infoINSERT INTO dbo.adult(member_no,street,city,state,zip,phone_no,expr_date)
VALUES(@MemberID,@street,@city,@state,@zip,@phone,@expirationDate)
COMMIT TRANEND TRY
SetFocus Project #3 – Data Access Layer (Class library)
FS_AddItem - Inserts row into dbo.copy table or dbo.title and dbo.item table if item exists or not.
BEGIN TRY BEGIN TRAN
-- Check to see if item exists first-- If it does, just add new copy number (1+highest)IF EXISTS (SELECT isbn FROM dbo.item WHERE isbn = @isbn)
BEGIN
-- Grab highest copy_noDECLARE @highest_copy_no int, @new_copy_no int
SELECT TOP 1 @highest_copy_no = copy_no FROM dbo.copy WHERE isbn = @isbn ORDER BY copy_no DESC
SET @new_copy_no = @highest_copy_no + 1
-- Grab title_noDECLARE @title_no int
SELECT @title_no = title_no FROM dbo.copy WHERE isbn = @isbn
INSERT INTO dbo.copy(isbn,copy_no,title_no, on_loan) VALUES (@isbn, @new_copy_no, @title_no, @loanable)
SET @copy_no_output = @new_copy_noEND
ELSE
BEGIN
-- ADD NEW ITEM
-- step 1: add to title (title_no is identity spec)DECLARE @new_title_no int
INSERT INTO dbo.title (title,author,synopsis) VALUES (@title, @author, @synopsis)
--Get the new title noSET @new_title_no=SCOPE_IDENTITY()
-- step 2: add to item
INSERT INTO dbo.item (isbn,title_no,cover,loanable) VALUES (@isbn, @new_title_no, @cover, @loanable)
-- step 3: add to copy (not on loan by deafult)
INSERT INTO dbo.copy (isbn,copy_no,title_no,on_loan) VALUES (@isbn, @new_title_no, @cover, 'N')
SetFocus Project #3 – Data Access Layer (Class library)
FS_Checkin - Updates record from dbo.copy table and inserts row into dbo.loan and dbo.loanhist table
BEGIN TRY
BEGIN TRAN
-- temporary variablesDECLARE @out_date datetime, @title_no int, @member_no smallint, @on_loan CHAR(1)
-- Make sure item is first in databaseIF NOT EXISTS (SELECT isbn, copy_no FROM dbo.copy WHERE isbn = @isbn)
BEGINRAISERROR('Library: Item not found in Database',11,2)RETURN
END
-- Make sure item is on loan so it can be checked inSELECT @on_loan = on_loan FROM dbo.copy WHERE isbn = @isbn AND copy_no = @copy_no
IF (@on_loan = 'N')
BEGIN RAISERROR('Library: Item not on loan',11,3) RETURN
END
BEGIN
-- Grab title_noSELECT @title_no = title_no FROM dbo.copy WHERE isbn = @isbn
AND copy_no = @copy_no
--Grab member_no, out_dateSELECT @member_no = member_no, @out_date = out_dateFROM dbo.loan WHERE isbn = @isbn AND copy_no = @copy_no AND @title_no = title_no
--Update copy UPDATE dbo.copy SET on_loan = 'N' WHERE isbn = @isbn AND copy_no = @copy_no
--Remove record from loan DELETE dbo.loan WHERE isbn = @isbn AND copy_no = @copy_no
--Insert into loanhistINSERT INTO dbo.loanhist(isbn, copy_no, out_date, title_no, member_no, due_date, in_date)VALUES(@isbn, @copy_no, @out_date, @title_no, @member_no,
DATEADD(day,14,@out_date), GETDATE())
END
COMMIT TRAN
END TRY
SetFocus Project #3 – Data Access Layer (Class library)
Data Access layer methods:
Methods created in the Data Access layer interact with the SQL Server 2008 database and execute and return values from Stored Procedures.
Sample Code:
public void AddMember(AdultMember adult){
try{ using (SqlConnection cn = GetConnection())
using (SqlCommand cmd = new SqlCommand("FS_AddAdultMember", cn)) {
cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@firstName", SqlDbType.VarChar, 15).Value = adult.fName; cmd.Parameters.Add("@middleInitial", SqlDbType.Char, 1).Value = adult.mInitial;
cmd.Parameters.Add("@lastName", SqlDbType.VarChar, 15).Value = adult.LastName;cmd.Parameters.Add("@street", SqlDbType.VarChar, 15).Value = adult.Street; cmd.Parameters.Add("@city", SqlDbType.VarChar, 15).Value = adult.City;
cmd.Parameters.Add("@state", SqlDbType.Char, 2).Value = adult.State; cmd.Parameters.Add("@zip", SqlDbType.Char, 10).Value = adult.ZipCode; cmd.Parameters.Add("@phone", SqlDbType.Char, 13).Value = adult.PhoneNumber;
cmd.Parameters.Add("@memberID", SqlDbType.SmallInt).Direction = ParameterDirection.Output;
cn.Open(); cmd.ExecuteNonQuery();
adult.MemberID = (short)cmd.Parameters["@memberID"].Value; }
}catch (SqlException ex){
switch (ex.State) {
case 1: throw new LibraryException(ErrorCode.MissingRequiredItems, ex.Message, ex);
default: throw new LibraryException(ErrorCode.AddAdultFailed, ex.Message, ex);
}}
}
SetFocus Project #3 – Data Access Layer (Class library)
Sample Code:
public short AddItem(int isbn, string title, string author, string cover){
try{
using (SqlConnection cn = GetConnection())
using (SqlCommand cmd = new SqlCommand("FS_AddItem", cn)) {
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@isbn", SqlDbType.VarChar, 15).Value = isbn; cmd.Parameters.Add("@title", SqlDbType.VarChar, 15).Value = title; cmd.Parameters.Add("@author", SqlDbType.VarChar, 15).Value = author; cmd.Parameters.Add("@cover", SqlDbType.Char, 8).Value = cover;
cmd.Parameters.Add("@copy_no_output", SqlDbType.SmallInt).Direction = ParameterDirection.Output;
cn.Open(); cmd.ExecuteNonQuery();
short newCopyNumber = (short)cmd.Parameters["@copy_no_output"].Value;
return newCopyNumber;
}
}
catch (SqlException ex){
switch (ex.State) {
case 1: throw new LibraryException(ErrorCode.MissingRequiredItems, ex.Message, ex); default: throw new LibraryException(ErrorCode.GetItemFailed, ex.Message, ex);
}} }
SetFocus Project #3 – Data Access Layer (Class library)
Sample Code:
public void CheckInItem(int isbn, short copyNum){
try{
using (SqlConnection cn = GetConnection())
using (SqlCommand cmd = new SqlCommand("FS_CheckIn", cn)) {
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@isbn", SqlDbType.Int).Value = isbn; cmd.Parameters.Add("@copy_no", SqlDbType.SmallInt).Value = copyNum;
cn.Open(); cmd.ExecuteNonQuery();
} } catch (SqlException ex){
switch (ex.State){
case 1:
throw new LibraryException(ErrorCode.MissingRequiredItems, ex.Message, ex);
case 2:
throw new LibraryException(ErrorCode.ItemNotFound, ex.Message, ex); case 3:
throw new LibraryException(ErrorCode.ItemNotOnLoan, ex.Message, ex);
default: throw new LibraryException(ErrorCode.CheckInFailed, ex.Message, ex);
}}
}
SetFocus Project #4 – ASP.NET Web Application
Summary
This project demonstrates the use of ASP.NET 3.5. in creating a web application. Some of the techniques used include:
Use of Membership Roles to restrict access to pages. Created MasterPage to provide consistent look and feel for website. Conversion of a HTML/CSS layout implemented with a MasterPage and content pages. Use of Skins and CSS to modify design layout characteristics. Utilizing ViewState objects to save data between postbacks. Use of validation controls (required, range and expression) to validate input before postback. Use of various AJAX controls such as UpdatePanel, UpdateProgress as well as Ajax Toolkit controls to provide
partial updates and improved user interactions. Navigation was accomplished via a sitemap and menu control. Additional 3rd party controls were used for additional functionality such as GoogleMaps. Use of JavaScript library jQuery was implemented for effects and animations.
Description
The visual interface was created by converting a HTML/CSS layout into a MasterPage and each corresponding content page used various ASP.NET web controls.
Each web page had their own validation controls and used an instance of the Business Layer class to initiate methods that executed from the Data Access layer.
Communication of the resulting data from the Data Access layer was accomplished by either using ObjectDataSource controls or ADO.NET objects such as Connection, Command, and DataSet.
The UI frontend has an instance and reference to the Business layer class:
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using FS.LibraryBusiness;
private BusinessLogic businessLogic = new BusinessLogic();
SetFocus Project #4 – ASP.NET Web Application
Sample Code:
protected void btnAddAdult_Click(object sender, EventArgs e){
try {
AdultMember adultMember = new AdultMember(); Member member = new Member();
adultMember.FirstName = txtFirstName.Text.Trim(); adultMember.MiddleInitial = txtMiddleName.Text.Trim(); adultMember.LastName = txtLastName.Text.Trim(); adultMember.Street = txtAddress.Text.Trim(); adultMember.City = txtCity.Text.Trim(); adultMember.State = ddlState.SelectedValue.ToString(); adultMember.ZipCode = txtZip.Text.Trim(); adultMember.PhoneNumber = txtPhone.Text.Trim();
businessLogic.AddMember(adultMember);
member = businessLogic.GetMember(adultMember.MemberID); lblStatus.Text = newMember.MemberID.ToString() + " was added";
}catch (LibraryException lex){
switch (lex.LibraryErrorCode){
case ErrorCode.GenericException:
lblStatus.Text = "Error: Database Error please contact IT"; break;
case ErrorCode.AddAdultFailed:
lblStatus.Text = "Error: Adding Adult Member failed"; break;
default:
lblStatus.Text = "Error: " + lex.Message;break;
}}
catch (Exception ex){ lblStatus.Text = "Error: " + ex.Message;}
SetFocus Project #4 – ASP.NET Web Application
Sample Code:
protected void btnAddItem_Click(object sender, EventArgs e){
try {
Item item = new Item();
item.ISBN = int.Parse(txtISBN.Text); item.Author = txtAuthor.Text; item.Title = txtTitle.Text; item.Cover = radioListCover.SelectedItem.Value; short copy_no = businessLogic.AddItem(item.ISBN, item.Title, item.Author);
if (copy_no != 0) {
lblStatus.Text = "Item added with Copy Number of " + copy_no; }
resetControls(); } catch (LibraryException lex) {
switch (lex.LibraryErrorCode) {
case ErrorCode.GenericException:
lblStatus.Text = "Error: Database Error please contact IT"; break;
case ErrorCode.MissingRequiredItems:
lblStatus.Text = "Error: Missing Required Items"; break;
default: lblStatus.Text = "Error: " + lex.Message; break; } }
catch (Exception ex) { lblStatus.Text = "Error: " + ex.Message; }
}
}
SetFocus Project #4 – ASP.NET Web Application
Sample Code:
protected void btnCheckinConfirm_Click(object sender, EventArgs e){try{
short isbn = short.Parse(GridView1.SelectedRow.Cells[1].Text);short copyNumber = short.Parse(GridView1.SelectedRow.Cells[2].Text);
businessLogic.CheckInItem(isbn, copyNumber);
GridView1.DataBind();setStatus("ISBN: " + isbn + " CopyNumber: " + copyNumber + " has been checked in");
}
catch (LibraryException lex)
{ switch (lex.LibraryErrorCode)
{ case ErrorCode.GenericException:
setStatus("Error: Database Error please contact IT");break;
case ErrorCode.CheckInFailed:
setStatus("Error: Checkin Failed");break;
default:
setStatus("Error: " + lex.Message);break;
}
}
catch (Exception ex){
setStatus("Error: " + ex.Message);
}
SetFocus Project #4 – ASP.NET Web Application
MasterPage:
<%@ Master Language="C#" CodeFile="Site.master.cs" Inherits="Site" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head id="Head1" runat="server"> <link href="master.css" rel="stylesheet" type="text/css" /> <link href="page.css" rel="stylesheet" type="text/css" /> <script src="../scripts/jquery-1.4.2.min.js" type="text/javascript"></script> </head><body>
<form id="form1" runat="server"> <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" /> <div id="wrap">
<div id="header">
<h1><asp:Label ID="lblSiteHeading" runat="server" ></asp:Label></h1>
</div> <div id="nav">
<asp:Menu ID="Menu1" Width="300px" runat="server" Orientation="Horizontal" StaticEnableDefaultPopOutImage="False" DataSourceID="SiteMapDataSource1" CssClass="menu"> </asp:Menu>
<asp:LoginStatus ID="LoginStatus1" runat="server" CssClass="login_status" LogoutPageUrl="~/Login.aspx" LogoutAction="Redirect" /> </div>
<div id="main">
<asp:ContentPlaceHolder ID="ContentPlaceHolderMain" runat="server"> </asp:ContentPlaceHolder>
</div> <div id="sidebar">
<asp:ContentPlaceHolder ID="ContentPlaceHolderSidebar" runat="server"> </asp:ContentPlaceHolder>
</div>
<div id="footer">Copyright © 2010 LibraryCheckout.com</div>
</div>
SetFocus Project #4 – ASP.NET Web Application
Screenshots: