Library Website

626 views

Published on

  • Be the first to comment

  • Be the first to like this

Library Website

  1. 1. Library Website
  2. 2. Library Website <ul><li>This website was developed using a three tier design, a data layer, business layer, and presentation layer. This makes updating and new library functions more manageable. </li></ul>
  3. 3. Business Layer <ul><li>namespace JGBusinessLayer </li></ul><ul><li>{ </li></ul><ul><li>/// <summary> </li></ul><ul><li>/// This business layer will be use </li></ul><ul><li>/// throughout the solution as </li></ul><ul><li>/// a portal to return data from </li></ul><ul><li>/// the Library Data Access. </li></ul><ul><li>/// </summary> </li></ul><ul><li>/// </li></ul><ul><li>[DataObject(true)] </li></ul><ul><li>public class BusinessLayer </li></ul><ul><li>{ </li></ul><ul><li>/// <summary> </li></ul><ul><li>/// </li></ul><ul><li>/// </summary> </li></ul><ul><li>public BusinessLayer() </li></ul><ul><li>{ </li></ul><ul><li>} </li></ul><ul><li>/// <summary> </li></ul><ul><li>/// This method returns </li></ul><ul><li>/// Author, CheckoutDate, </li></ul><ul><li>/// CopyNumber, DueDate, </li></ul><ul><li>/// ISBN MemberNumber, and </li></ul><ul><li>/// Title of books that are on </li></ul><ul><li>/// loan. </li></ul><ul><li>/// </summary> </li></ul><ul><li>/// <param name=&quot;isbn_no&quot;></param> </li></ul><ul><li>/// <param name=&quot;copy_no&quot;></param> </li></ul><ul><li>/// <returns></returns> </li></ul><ul><li>#region-GetItem </li></ul><ul><li>public Item GetItem(int isbn_no, short copy_no) </li></ul><ul><li>{ </li></ul><ul><li>Item it = new Item(); </li></ul><ul><li>LibraryDataAccess ida = new LibraryDataAccess(); </li></ul><ul><li>it = ida.GetItem(isbn_no, copy_no); </li></ul><ul><li>return it; </li></ul><ul><li>} </li></ul><ul><li>#endregion </li></ul><ul><li>/// <summary> </li></ul><ul><li>/// This is used to check out </li></ul><ul><li>/// a book </li></ul><ul><li>/// </summary> </li></ul><ul><li>/// <param name=&quot;isbn_no&quot;></param> </li></ul><ul><li>/// <param name=&quot;copy_no&quot;></param> </li></ul><ul><li>/// <param name=&quot;memid&quot;></param> </li></ul><ul><li>#region-CheckoutItem </li></ul><ul><li>public void CheckOut(int isbn_no, short copy_no, short memid ) </li></ul><ul><li>{ </li></ul><ul><li>LibraryDataAccess ida = new LibraryDataAccess(); </li></ul><ul><li>ida.CheckOutItem(isbn_no, copy_no, memid); </li></ul><ul><li>} </li></ul><ul><li>#endregion </li></ul>
  4. 4. Business Layer Cont’ <ul><li>/// <summary> </li></ul><ul><li>/// Add an adult member </li></ul><ul><li>/// and juuvenile member </li></ul><ul><li>/// </summary> </li></ul><ul><li>/// <param name=&quot;a&quot;></param> </li></ul><ul><li>#region- AddMember </li></ul><ul><li>public Member AddNewMember(AdultMember a) </li></ul><ul><li>{ </li></ul><ul><li>LibraryDataAccess ida = new LibraryDataAccess(); <<create Data access object. This objects makes calls to the database. </li></ul><ul><li>Member m = new Member(); </li></ul><ul><li>m = ida.AddMember(a); </li></ul><ul><li>return m; </li></ul><ul><li>} </li></ul><ul><li>/// <summary> </li></ul><ul><li>/// Add juvenile Member </li></ul><ul><li>/// </summary> </li></ul><ul><li>/// <param name=&quot;j&quot;></param> </li></ul><ul><li>public Member AddNewMember(JuvenileMember j) </li></ul><ul><li>{ </li></ul><ul><li>LibraryDataAccess ida = new LibraryDataAccess(); </li></ul><ul><li>Member m = new Member(); </li></ul><ul><li>m = ida.AddMember(j); </li></ul><ul><li>return m; </li></ul><ul><li>} </li></ul><ul><li>#endregion </li></ul>
  5. 5. Data Access Layer <ul><li>namespace JGLibraryDataAccess </li></ul><ul><li>{ </li></ul><ul><li>/// <summary> </li></ul><ul><li>/// This class is used to interact </li></ul><ul><li>/// with the database from callsb </li></ul><ul><li>/// from the business layer. </li></ul><ul><li>/// </summary> </li></ul><ul><li>public class LibraryDataAccess </li></ul><ul><li>{ </li></ul><ul><li>/// <summary> </li></ul><ul><li>/// This will return a set of data items that the customer has </li></ul><ul><li>/// on loan. </li></ul><ul><li>/// </summary> </li></ul><ul><li>/// <param name=&quot;memid&quot;></param> </li></ul><ul><li>/// <returns></returns> </li></ul><ul><li>#region- Get Customer Items </li></ul><ul><li>public CustomerItems GetCustomerItems(short memid) </li></ul><ul><li>{ </li></ul><ul><li>try </li></ul><ul><li>{ </li></ul><ul><li>CustomerItems ds = new CustomerItems(); << creating a type dataset to bring to be used in a gridview to display books that are on loan to a member. </li></ul><ul><li>ItemsTableAdapter da = new ItemsTableAdapter(); </li></ul><ul><li>da.Fill(ds.Items, memid); </li></ul><ul><li>return ds; </li></ul><ul><li>} </li></ul><ul><li>catch (SqlException ex) << catch any SqlExceptions and throwing that exception to a custom library exception. </li></ul><ul><li>{ </li></ul><ul><li>StringBuilder sb = new StringBuilder(); </li></ul><ul><li>sb.Append(&quot;Procedure: &quot;); </li></ul><ul><li>sb.Append(ex.Procedure.ToString()); </li></ul><ul><li>sb.Append(&quot; Line no.: &quot;); </li></ul><ul><li>sb.AppendLine(ex.LineNumber.ToString()); </li></ul><ul><li>sb.Append(ex.Message.ToString()); </li></ul><ul><li>throw new LibraryException(sb.ToString()); << throw a custom Library exception if there was an exception raised in the stored procedure </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>
  6. 6. Data Access Layer Cont’ <ul><li>public Member AddMember(AdultMember a) </li></ul><ul><li>{ </li></ul><ul><li>using (SqlConnection cn = new SqlConnection(Properties.Settings.Default.LibraryConnection)) <<this using statement will dispose of the connection when finished </li></ul><ul><li>{ </li></ul><ul><li>using (SqlCommand cmd = new SqlCommand(&quot;addAdult&quot;, cn)) </li></ul><ul><li>{ </li></ul><ul><li>try </li></ul><ul><li>{ </li></ul><ul><li>cn.Open(); </li></ul><ul><li>cmd.CommandType = CommandType.StoredProcedure; </li></ul><ul><li>cmd.Parameters.AddWithValue(&quot;@street&quot;, a.Street); </li></ul><ul><li>cmd.Parameters.AddWithValue(&quot;@city&quot;, a.City); </li></ul><ul><li>cmd.Parameters.AddWithValue(&quot;@zip&quot;, a.ZipCode); </li></ul><ul><li>cmd.Parameters.AddWithValue(&quot;@state&quot;, a.State); </li></ul><ul><li>cmd.Parameters.AddWithValue(&quot;@phone_no&quot;, a.PhoneNumber); </li></ul><ul><li>cmd.Parameters.AddWithValue(&quot;@expr_date&quot;, DateTime.Today.AddYears(1)); </li></ul><ul><li>cmd.Parameters.AddWithValue(&quot;@last_name&quot;, a.LastName); </li></ul><ul><li>cmd.Parameters.AddWithValue(&quot;@first_name&quot;, a.FirstName); </li></ul><ul><li>cmd.Parameters.AddWithValue(&quot;@middle_initial&quot;, a.MiddleInitial); </li></ul><ul><li>SqlParameter prm = new SqlParameter(&quot;@newMemberno&quot;, SqlDbType.SmallInt); </li></ul><ul><li>prm.Direction = ParameterDirection.Output; </li></ul><ul><li>cmd.Parameters.Add(prm); </li></ul><ul><li>cmd.ExecuteNonQuery(); </li></ul><ul><li>Member m = new Member(); </li></ul><ul><li>m.NewMemberno = (short)cmd.Parameters[&quot;@newMemberno&quot;].Value; </li></ul><ul><li>return m; </li></ul><ul><li>} </li></ul><ul><li>catch (SqlException ex) </li></ul><ul><li>{ </li></ul><ul><li>StringBuilder sb = new StringBuilder(); </li></ul><ul><li>sb.Append(&quot;Procedure: &quot;); </li></ul><ul><li>sb.Append(ex.Procedure.ToString()); </li></ul><ul><li>sb.Append(&quot; Line no.: &quot;); </li></ul><ul><li>sb.AppendLine(ex.LineNumber.ToString()); </li></ul><ul><li>sb.Append(ex.Message.ToString()); </li></ul><ul><li>throw new LibraryException(sb.ToString()); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>
  7. 8. Logon Page <ul><li>The logon page uses the ASP.Net membership security features. This will authenticate user and help the web administrator to manage roles and users for the website. </li></ul>
  8. 9. Membership Security Features <ul><li><allow roles=&quot;Administrators&quot; /> </li></ul><ul><li><allow users=&quot;?&quot; /> </li></ul><ul><li></authorization> </li></ul><ul><li><roleManager enabled=&quot;true&quot; cacheRolesInCookie=&quot;true&quot; cookieName=&quot;.ASPXROLES&quot; cookieTimeout=&quot;30&quot; cookiePath=&quot;/&quot; cookieRequireSSL=&quot;false&quot; cookieSlidingExpiration=&quot;true&quot; cookieProtection=&quot;All&quot; defaultProvider=&quot;AspNetSqlRoleProvider&quot;/> </li></ul><ul><li><membership> </li></ul><ul><li><providers> </li></ul><ul><li><clear/> </li></ul><ul><li><add name=&quot;AspNetSqlMembershipProvider&quot; </li></ul><ul><li>type=&quot;System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a&quot; </li></ul><ul><li>connectionStringName=&quot;LocalSqlServer&quot; </li></ul><ul><li>enablePasswordRetrieval=&quot;false&quot; enablePasswordReset=&quot;true&quot; requiresQuestionAndAnswer=&quot;true&quot; applicationName=&quot;/&quot; requiresUniqueEmail=&quot;false&quot; passwordFormat=&quot;Hashed&quot; maxInvalidPasswordAttempts=&quot;5&quot; minRequiredPasswordLength=&quot;7&quot; minRequiredNonalphanumericCharacters=&quot;0&quot; passwordAttemptWindow=&quot;10&quot; passwordStrengthRegularExpression=&quot;&quot;/> </li></ul><ul><li></providers> </li></ul><ul><li></membership> </li></ul>
  9. 10. Administration management
  10. 11. Add New Adult Member
  11. 12. <ul><li>protected void Button1_Click(object sender, EventArgs e) </li></ul><ul><li>{ </li></ul><ul><li>if (IsValid) </li></ul><ul><li>{ </li></ul><ul><li>panelStatus.Visible = true; </li></ul><ul><li>panelValidation.Visible = false; </li></ul><ul><li>BusinessLayer bl = new BusinessLayer(); <<Create business layer object </li></ul><ul><li>AdultMember Ad = new AdultMember(); << This adult object will contain information about the member being added. </li></ul><ul><li>Ad.FirstName = textBoxFirstName.Text; </li></ul><ul><li>Ad.LastName = textBoxLastName.Text; </li></ul><ul><li>Ad.MiddleInitial = textMiddleIntial.Text; </li></ul><ul><li>Ad.Street = textBoxStreet.Text; </li></ul><ul><li>Ad.City = textBoxCity.Text; </li></ul><ul><li>Ad.State = stateDropDown.Text; </li></ul><ul><li>Ad.ZipCode = textBoxZipCode.Text; </li></ul><ul><li>if (textBoxPhone.Text != string.Empty) </li></ul><ul><li>{ </li></ul><ul><li>Ad.PhoneNumber = textBoxPhone.Text; </li></ul><ul><li>} </li></ul><ul><li>else </li></ul><ul><li>{ </li></ul><ul><li>Ad.PhoneNumber = null; </li></ul><ul><li>} </li></ul><ul><li>Member m = new Member(); << create member object. </li></ul><ul><li>m = bl.AddNewMember(Ad); << this is a call to the business layer to add member to the library. </li></ul><ul><li>labelStatus.Text = textBoxFirstName.Text + &quot; &quot; + textBoxLastName.Text </li></ul><ul><li>+ &quot; has been added as an adult member and the new member number is &quot; + m.NewMemberno.ToString(); </li></ul><ul><li>} </li></ul><ul><li>else </li></ul><ul><li>{ </li></ul><ul><li>panelValidation.Visible = true; </li></ul><ul><li>panelStatus.Visible = false; </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>
  12. 13. Book Check Out
  13. 14. Checkout Code Behind <ul><li>protected void buttonEnter_Click(object sender, EventArgs e) </li></ul><ul><li>{ </li></ul><ul><li>if (textBoxMemberID.Text != string.Empty) </li></ul><ul><li>{ </li></ul><ul><li>try </li></ul><ul><li>{ </li></ul><ul><li>Session[&quot;MemberID&quot;] = short.Parse(textBoxMemberID.Text); </li></ul><ul><li>BusinessLayer bl = new BusinessLayer(); </li></ul><ul><li>Member m = new Member(); </li></ul><ul><li>Cnt = 0; </li></ul><ul><li>JuvenileMember j = new JuvenileMember(); </li></ul><ul><li>//check to see if a member is a juvenile member or an adult member. </li></ul><ul><li>j = bl.CheckJuvenile(short.Parse(textBoxMemberID.Text)); </li></ul><ul><li>if(j.IsJuvenile==&quot;Yes&quot;) </li></ul><ul><li>{ </li></ul><ul><li>m = bl.GetMember(short.Parse(textBoxMemberID.Text)); </li></ul><ul><li>int myBday; </li></ul><ul><li>int myEday; </li></ul><ul><li>myBday = DateTime.Compare(DateTime.Today, (DateTime)m.Birthdate.AddYears(18)); </li></ul><ul><li>myEday = DateTime.Compare(DateTime.Today, (DateTime)m.Expiration_date); </li></ul>
  14. 15. Checkout Code Behind cont’ <ul><li>if ((myBday >= 0) && (myEday < 0)) </li></ul><ul><li>{ </li></ul><ul><li>Msg = m.FirstName + &quot; &quot; + m.LastName </li></ul><ul><li>+ &quot; is now an adult as of today and will be added as an adult member&quot;; </li></ul><ul><li>bl.convertJuvenileToAdult(m); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>m = bl.GetMember(short.Parse(textBoxMemberID.Text)); </li></ul><ul><li>labelFirstName.Text = m.FirstName; </li></ul><ul><li>labelLastName.Text = m.LastName; </li></ul><ul><li>labelExpireDate.Text = m.Expiration_date.ToShortDateString(); </li></ul><ul><li>labelStreet.Text = m.Street; </li></ul><ul><li>labelCity.Text = m.City; </li></ul><ul><li>labelState.Text = m.State; </li></ul><ul><li>labelZipCode.Text = m.ZipCode; </li></ul><ul><li>labelPhoneNumber.Text = m.PhoneNumber; </li></ul>
  15. 16. Checkout Code Behind Cont’ <ul><li>if (DateTime.Compare(DateTime.Today, m.Expiration_date) >= 0) </li></ul><ul><li>{ </li></ul><ul><li>Msg = labelFirstName.Text + &quot; membership has expired If you want to update the &quot; </li></ul><ul><li>+ &quot;membership expiration date by one year then click the Renew Expiration Date button&quot;; </li></ul><ul><li>labelStatus.CssClass = &quot;Late&quot;; </li></ul><ul><li>buttonRenew.Visible = true; </li></ul><ul><li>linkButtonCheckOut.Visible = false; </li></ul><ul><li>} </li></ul><ul><li>else </li></ul><ul><li>{ </li></ul><ul><li>labelStatus.CssClass = &quot;NotLate&quot;; </li></ul><ul><li>linkButtonCheckOut.Visible = true; </li></ul><ul><li>} </li></ul><ul><li>Status(); </li></ul><ul><li>} </li></ul><ul><li>catch (LibraryException ex) </li></ul><ul><li>{ </li></ul><ul><li>labelStatus.Text = ex.Message; </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>else </li></ul><ul><li>{ </li></ul><ul><li>Session[&quot;MemberID&quot;] = 0; </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>
  16. 17. Library Website <ul><li>These slides highlight some of the feature of this website. If there are any questions, I would be happy to answer them. </li></ul>

×