.NET Code Examples
Upcoming SlideShare
Loading in...5
×
 

.NET Code Examples

on

  • 506 views

 

Statistics

Views

Total Views
506
Views on SlideShare
505
Embed Views
1

Actions

Likes
0
Downloads
0
Comments
0

1 Embed 1

http://www.lmodules.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

.NET Code Examples .NET Code Examples Presentation Transcript

    • .NET Portfolio
    • Gary Brenner
    • [email_address]
    • Phone (281) 300-5830
  • Table of Contents
    • Windows Front-End Application (Library Project phase 1)
    • Replace Data Access and Entity Layers(Library Project phase 2), with SQL Stored Procedures and our own Entities.
    • Create Web-Application to replace Windows Front-End(Library Project phase 3)
  • (Windows Front-End Application)
    • Objective
    • A database has been created to support the principal functions of a lending library’s day-to-day 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. Creating that application will be your task.
    • Requirements
    • Design and develop a front end application that satisfies the four basic functionalities: Add Adult, Add Juvenile, Check In a book, Check Out a book.
    • Develop code that is easily maintainable.
    • Provide validation for all required fields (see details below).
    • Provide adequate error handling.
    • Produce a user interface that is intuitive, requiring minimal training for users while minimizing resource utilization.
  • Windows Front-End Add Adult Member Screen
  • (Code Sample for Add Adult Screen)
    • public NewMemberForm()
    • {
    • InitializeComponent();
    • // set up validation regular expressions
    • // note: PatternAndMessage is a user-defined class
    • this.mTextBoxFirstName.Tag = new PatternAndMessage(@"^[A-Z][a-z]{0,14}$",
    • "First Name must be all letters, first uppercase, all others lowercase, length limited to 15 letters");
    • this.mTextBoxLastName.Tag = new PatternAndMessage(@"^[A-Z][a-z]{0,14}$",
    • "Last Name must be all letters, first uppercase, all others lowercase, length limited to 15 letters");
    • this.mTextBoxMiddleInitial.Tag = new PatternAndMessage(@"^[A-Z]$",
    • "Middle Initial is optional, if entered must be only 1 uppercase letter");
    • this.mTextBoxStreetAddress.Tag = new PatternAndMessage(@"^.{1,15}$",
    • "Street Address must be 1 to 15 characters long");
    • this.mTextBoxCity.Tag = new PatternAndMessage(@"^.{1,15}$",
    • "City must be 1 to 15 characters long");
    • }
  • (Windows Business & Data Access Replacements)
    • Requirements
    • Design the Business and Data Access tiers
    • 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.
  • (Code Sample for SQL stored procedure : CheckInItem)
    • /****** Object: StoredProcedure [dbo].[CheckInItem] Script Date: 08/21/2009 04:31:27 ******/
    • SET ANSI_NULLS ON
    • GO
    • SET QUOTED_IDENTIFIER ON
    • GO
    • --stored proc CheckInItem
    • -- will add the item to the loanhist table and remove it from the load table if successful
    • CREATE Proc [dbo].[CheckInItem]
    • @ISBN int ,
    • @Copy_No smallint
    • --@Title_No int,
    • --@On_Loan nchar(1)
    • As
    • Declare @Temp_Title_No int
    • Declare @Temp_Member_No smallint
    • Declare @Temp_Out_Date datetime
    • Declare @Temp_Due_Date datetime
    • Set @Temp_Title_No = NULL
    • Set @Temp_Member_No = NULL
    • Set NoCount ON
    • Begin Try
    • Begin Transaction
    • select @Temp_Title_No = title_no from copy where ISBN = @ISBN and
    • copy_no = @Copy_No and on_loan = 'Y'
    • if (@Temp_Title_No IS NULL)
    • Begin
    • Raiserror ('X108',13,1) -- item is not on loan
    • End
    • else
    • Begin
    • ******************* Code is continued on next slide *****************************
  • (Code Sample for SQL stored procedure : CheckInItem )
    • ******************* Code is continued on below *****************************
    • update copy set on_loan = 'N' where on_loan = 'Y' and ISBN = @ISBN and copy_no = @Copy_No and title_no = @Temp_Title_No
    • select @Temp_Member_No = member_no,@Temp_Out_Date = out_date,
    • @Temp_Due_Date = due_date from loan where isbn = @ISBN and copy_no = @Copy_No and title_no = @Temp_Title_No
    • if (@Temp_Member_No IS NULL)
    • Begin
    • Raiserror ('X107',13,1) -- item not found
    • End
    • else
    • Begin
    • delete from loan where member_no = @Temp_Member_No and out_date = @Temp_Out_Date
    • and due_date = @Temp_Due_Date and isbn = @ISBN and copy_no = @Copy_No and title_no = @Temp_Title_No
    • insert into loanhist(isbn,copy_no,out_date,title_no,member_no,due_date,
    • in_date,fine_assessed,fine_paid,fine_waived,remarks)
    • values(@isbn,@copy_no,@Temp_Out_Date,@Temp_Title_No,@Temp_Member_No,@Temp_Due_Date,
    • GetDate(),NULL,NULL,NULL,NULL)
    • End
    • End
    • if @@error <> 0
    • Begin
    • Raiserror('X103',13,1) -- check in failed
    • End
    • COMMIT
    • End Try
    • BEGIN CATCH
    • -- there was an error
    • IF @@TRANCOUNT > 0
    • ROLLBACK
    • -- Raise an error with the details of the exception
    • DECLARE @ErrMsg nvarchar(4000), @ErrSeverity int --, @ErrNumber int
    • SELECT @ErrMsg = ERROR_MESSAGE(),
    • @ErrSeverity = ERROR_SEVERITY()
    • RAISERROR( @ErrMsg, @ErrSeverity, 1)
    • END CATCH
    • GO
  • (Web Application to replace Windows Front-End 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 can not 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 updgrade 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.
    • Use of hyperlinks to navigate between pages.
    • Project locations and requirements:
    • Create your web application project as a File System project. Your solution folder must contain all your project folders so that when you submit the solution folder all necessary parts of your application are present. Your solution must include the source for all your projects; i.e. not just the DLLs for your business tier and data access tier projects.
  • (Add Adult Code Sample ASPX)
    • public partial class AddAdult : System.Web.UI.Page
    • {
    • protected void Page_Load(object sender, EventArgs e)
    • {
    • }
    • protected void btnAddAdult_Click(object sender, EventArgs e)
    • {
    • AdultMember newAdultMember = new AdultMember();
    • newAdultMember.FirstName = txtFirstName.Text;
    • newAdultMember.MiddleInitial = txtMiddleInitial.Text;
    • newAdultMember.LastName = txtLastName.Text;
    • newAdultMember.Street = txtStreet.Text;
    • newAdultMember.City = txtCity.Text;
    • newAdultMember.State = statesDropDown.Text;
    • newAdultMember.ZipCode = txtZipCode.Text;
    • newAdultMember.PhoneNumber = txtPhoneNumber.Text;
    • try
    • {
    • BusinessLayer bl = new BusinessLayer();
    • bl.AddAdult(newAdultMember);
    • // MessageBox.Show(&quot;Added &quot;, newAdultMember.MemberID.ToString());
    • LitMemberInfo.Text = (&quot;Added adult &quot; + newAdultMember.MemberID.ToString());
    • }
    • catch (LibException lex)
    • {
    • switch (lex.LibErrorCode)
  • (Add Adult Code Sample ASPX)
    • {
    • case LibErrorCode.GenericException:
    • LitMemberInfo.Text = &quot;Some sort of generic error need to see.&quot;;
    • break;
    • case LibErrorCode.AddAdultFailed:
    • LitMemberInfo.Text = &quot;This adult member was not added.&quot;;
    • break;
    • case LibErrorCode.None:
    • LitMemberInfo.Text = &quot;No error code was provided, sorry.&quot;;
    • break;
    • default:
    • LitMemberInfo.Text = &quot;What happened?&quot;;
    • break;
    • }
    • }
    • }
    • protected void btnCancel_Click(object sender, EventArgs e)
    • {
    • txtFirstName.Text = &quot;&quot;;
    • txtMiddleInitial.Text = &quot;&quot;;
    • txtLastName.Text = &quot;&quot;;
    • txtStreet.Text = &quot;&quot;;
    • txtCity.Text = &quot;&quot;;
    • txtZipCode.Text = &quot;&quot;;
    • txtPhoneNumber.Text = &quot;&quot;;
    • }