Library Project Phase 1
 
Library Project This Library project will use two class objects to work with the menu form. The first class object is the businesslayer bl. This object will do Library functions such as get MemberID, Check in  and out books. The second class object Validation V will perform validation on the required fields in the add new members menu. Each Method and events will be decribed below.  T he following   e xceptions will be handled LibraryException, ArgumentNullException, ArgumentOutOfRangeException,OverflowException and FormatException.
 
Validation Class using System; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; namespace JG.LibraryWinClient { public class Validation { enum Colors { White, Yellow, Red }; /// <summary> // method will check to see if the first charactor is upper class /// </summary> ///  #region- Upper check const string ALL_CAPS_PATTERN = &quot;[a-z]&quot;; static readonly Regex All_Caps_Regex = new Regex(ALL_CAPS_PATTERN);
Validation Class public bool AllUpperCase(string inputChar) { if (All_Caps_Regex.IsMatch(inputChar)) { return false; } return true; } #endregion /// <summary> /// verify that a string is alphabits only  /// </summary> /// <param name=&quot;strToCheck&quot;></param> /// <returns></returns> ///  #region-Alpha check for members public bool IsAlpha(String strToCheck) { Regex objAlphaPattern = new Regex(&quot;[^a-zA-Z]&quot;); return !objAlphaPattern.IsMatch(strToCheck); } #endregion
Validation Class /// <summary> /// verify that string of charaters following the capitalized  /// first letter are in lower case. /// </summary> #region-Firstletter upper rest lower const string ALL_Lower_PATTERN = &quot;[A-Z]&quot;; static readonly Regex All_LowCap_Regex = new Regex(ALL_Lower_PATTERN); public bool AllLowerCase(string inputstring) { if (All_LowCap_Regex.IsMatch(inputstring)) { return false; } return true; } #endregion
Validation Class /// <summary> /// verify the zip pattern is ##### or #####-#### /// </summary> /// <param name=&quot;num&quot;></param> /// <returns></returns> #region-Zip pattern check public bool ZipCheck(string num) { string pattern = @&quot;^(\d{5}-\d{4}|\d{5}|\d{9})$&quot;; Regex match = new Regex(pattern); return match.IsMatch(num); } #endregion
Validation Class /// <summary> /// verify that the phone number is (###)###-#### /// </summary> /// <param name=&quot;num&quot;></param> /// <returns></returns> #region-Phone validation public bool Phone(string num) { string pattern = &quot;\\(\\d\\d\\d\\)\\d\\d\\d\\-\\d\\d\\d\\d&quot;; Regex match = new Regex(pattern); if (match.IsMatch(num)) { return true; } return false; } #endregion
Validation Class /// <summary> /// verify that the birthday is mm/dd/yyyy /// </summary> /// <param name=&quot;day&quot;></param> /// <returns></returns> #region-birthday validation public bool Birthday(string day) { string pattern = &quot;^([1-9]|0[1-9]|1[012])[ /.]([1-9]|0[1-9]|[12][0-9]|3[01])[ /.][0-9]{4}$&quot;; Regex match = new Regex(pattern); return match.IsMatch(day); } #endregion
Validation Class /// <summary> /// The confirmDate is check the juvenile's birthday to make sure  /// it is within 18 years.  /// </summary> /// <param name=&quot;d&quot;></param> /// <returns></returns> #region-check birthday for under 18 public bool ConfirmDate(DateTime d) { int yrs; yrs = DateTime.Compare(DateTime.Now, d.AddYears(18)); if (yrs >= 0) { return false; } else { return true; } }
Validation Class /// <summary> /// The validateCheckout method will  /// check to see if a member is eligiable for  /// checking out books.  /// </summary> /// <param name=&quot;D&quot;></param> /// <param name=&quot;bc&quot;></param> /// <returns></returns> #region- ValidateCheckOut public StringBuilder ValidateCheckOut(DateTime D, Int32 bc) { StringBuilder Sb = new StringBuilder(); int dc = DateTime.Compare(DateTime.Now, D); if (dc >= 0) { Sb.Append(&quot;Member membership has expired &quot;); } if (bc >= 4 && dc >= 0) { Sb.Append(&quot; and member will exceed maximum allowed books for checkout&quot;); } else if (bc >= 4) { Sb.Append(&quot;Member will exceed maximum allowed books for checkout&quot;); } return Sb; }
Validation Class public StringBuilder ValidateCheckOut(Int32 bc) { StringBuilder Sb = new StringBuilder(); if (bc >= 4) { Sb.Append(&quot;Member will exceed maximum allowed books for checkout&quot;); } return Sb; } #endregion
Validation Class #region-EvaluateExpirationDate //This is the method I should use to return //the color change for the expiration textbox //in the Check out book tab.  public Enum ChangeColor(DateTime d) { int expireDate; Colors c = new Colors(); c = Colors.White; expireDate = DateTime.Compare(DateTime.Now.AddDays(7), d); if (expireDate > 0) { c = Colors.Yellow; } expireDate = DateTime.Compare(DateTime.Now, d); if (expireDate >= 0) { c = Colors.Red; } return c; } #endregion } }
Business Layer Class using System; using System.Collections.Generic; using System.Text; using SetFocus.Library.DataAccess; using SetFocus.Library.Entities; using System.Data; namespace JG.LibraryBusiness { public class BusinessLayer { public BusinessLayer() { }
Business Layer Class /// <summary> /// This method will retrive member Id. /// </summary> /// <param name=&quot;memberId&quot;></param> /// <returns></returns> #region - Get Member ID public Member GetInformation(short memberId) { // Create a library data access object LibraryDataAccess lda = new LibraryDataAccess(); // Call the GetMember() method and pass in a member id Member myMember = lda.GetMember(memberId); // return the retrieved member return myMember; } #endregion
Business Layer Class /// <summary> /// The Add New Member method is overloaded to take both adult and juvenile members /// </summary> /// <param name=&quot;J&quot;></param> #region- Add new members public void AddNewMember(JuvenileMember J) { LibraryDataAccess lda = new LibraryDataAccess(); lda.AddMember(J); } public void AddNewMember(AdultMember A) { LibraryDataAccess lda = new LibraryDataAccess(); lda.AddMember(A); } #endregion
Businss Layer Class /// <summary> /// Get Member book Info will return a  /// dataset of all the books that  /// are currently checked out by the member ///  /// </summary> /// <param name=&quot;num&quot;></param> /// <returns>Dataset</returns> #region -Get Member's book information public DataSet GetCheckoutInfo(Int16  num) { LibraryDataAccess lda = new LibraryDataAccess(); DataSet Ds = lda.GetItems(num); return Ds; } #endregion
Business Layer Class /// <summary> /// Get Member book Info will return a  /// dataset of all the books that  /// are currently checked out by the member ///  /// </summary> /// <param name=&quot;num&quot;></param> /// <returns>Dataset</returns> #region -Get Member's book information public DataSet GetCheckoutInfo(Int16  num) { LibraryDataAccess lda = new LibraryDataAccess(); DataSet Ds = lda.GetItems(num); return Ds; } #endregion
Business Layer Class /// <summary> /// CheckIn method will check in books /// </summary> /// <param name=&quot;isbn&quot;></param> /// <param name=&quot;Cnum&quot;></param> #region-CheckIn public void CheckIn(Int32 isbn, Int16 Cnum) { LibraryDataAccess lda = new LibraryDataAccess(); lda.CheckInItem(isbn, Cnum); } #endregion
Business Layer Class /// <summary> /// This will get the items in the Item class and return an object /// </summary> /// <param name=&quot;isbn&quot;></param> /// <param name=&quot;Cnum&quot;></param> /// <returns>Item Object</returns> #region-GetItem public object GetItem(Int32 isbn,Int16 Cnum) { LibraryDataAccess ld = new LibraryDataAccess(); Item It = ld.GetItem(isbn, Cnum); return It; } #endregion
Business Layer Class /// </summary> /// <param name=&quot;mem&quot;></param> /// <param name=&quot;isdn&quot;></param> /// <param name=&quot;copy&quot;></param> #region-Check Out public void CheckOut(Int16 mem, Int32 isdn, Int16 copy) { try { LibraryDataAccess lda = new LibraryDataAccess(); lda.CheckOutItem(mem, isdn, copy); } catch (LibraryException) { } } #endregion } }

Library Project Phase 1

  • 1.
  • 2.
  • 3.
    Library Project ThisLibrary project will use two class objects to work with the menu form. The first class object is the businesslayer bl. This object will do Library functions such as get MemberID, Check in and out books. The second class object Validation V will perform validation on the required fields in the add new members menu. Each Method and events will be decribed below. T he following e xceptions will be handled LibraryException, ArgumentNullException, ArgumentOutOfRangeException,OverflowException and FormatException.
  • 4.
  • 5.
    Validation Class usingSystem; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; namespace JG.LibraryWinClient { public class Validation { enum Colors { White, Yellow, Red }; /// <summary> // method will check to see if the first charactor is upper class /// </summary> /// #region- Upper check const string ALL_CAPS_PATTERN = &quot;[a-z]&quot;; static readonly Regex All_Caps_Regex = new Regex(ALL_CAPS_PATTERN);
  • 6.
    Validation Class publicbool AllUpperCase(string inputChar) { if (All_Caps_Regex.IsMatch(inputChar)) { return false; } return true; } #endregion /// <summary> /// verify that a string is alphabits only /// </summary> /// <param name=&quot;strToCheck&quot;></param> /// <returns></returns> /// #region-Alpha check for members public bool IsAlpha(String strToCheck) { Regex objAlphaPattern = new Regex(&quot;[^a-zA-Z]&quot;); return !objAlphaPattern.IsMatch(strToCheck); } #endregion
  • 7.
    Validation Class ///<summary> /// verify that string of charaters following the capitalized /// first letter are in lower case. /// </summary> #region-Firstletter upper rest lower const string ALL_Lower_PATTERN = &quot;[A-Z]&quot;; static readonly Regex All_LowCap_Regex = new Regex(ALL_Lower_PATTERN); public bool AllLowerCase(string inputstring) { if (All_LowCap_Regex.IsMatch(inputstring)) { return false; } return true; } #endregion
  • 8.
    Validation Class ///<summary> /// verify the zip pattern is ##### or #####-#### /// </summary> /// <param name=&quot;num&quot;></param> /// <returns></returns> #region-Zip pattern check public bool ZipCheck(string num) { string pattern = @&quot;^(\d{5}-\d{4}|\d{5}|\d{9})$&quot;; Regex match = new Regex(pattern); return match.IsMatch(num); } #endregion
  • 9.
    Validation Class ///<summary> /// verify that the phone number is (###)###-#### /// </summary> /// <param name=&quot;num&quot;></param> /// <returns></returns> #region-Phone validation public bool Phone(string num) { string pattern = &quot;\\(\\d\\d\\d\\)\\d\\d\\d\\-\\d\\d\\d\\d&quot;; Regex match = new Regex(pattern); if (match.IsMatch(num)) { return true; } return false; } #endregion
  • 10.
    Validation Class ///<summary> /// verify that the birthday is mm/dd/yyyy /// </summary> /// <param name=&quot;day&quot;></param> /// <returns></returns> #region-birthday validation public bool Birthday(string day) { string pattern = &quot;^([1-9]|0[1-9]|1[012])[ /.]([1-9]|0[1-9]|[12][0-9]|3[01])[ /.][0-9]{4}$&quot;; Regex match = new Regex(pattern); return match.IsMatch(day); } #endregion
  • 11.
    Validation Class ///<summary> /// The confirmDate is check the juvenile's birthday to make sure /// it is within 18 years. /// </summary> /// <param name=&quot;d&quot;></param> /// <returns></returns> #region-check birthday for under 18 public bool ConfirmDate(DateTime d) { int yrs; yrs = DateTime.Compare(DateTime.Now, d.AddYears(18)); if (yrs >= 0) { return false; } else { return true; } }
  • 12.
    Validation Class ///<summary> /// The validateCheckout method will /// check to see if a member is eligiable for /// checking out books. /// </summary> /// <param name=&quot;D&quot;></param> /// <param name=&quot;bc&quot;></param> /// <returns></returns> #region- ValidateCheckOut public StringBuilder ValidateCheckOut(DateTime D, Int32 bc) { StringBuilder Sb = new StringBuilder(); int dc = DateTime.Compare(DateTime.Now, D); if (dc >= 0) { Sb.Append(&quot;Member membership has expired &quot;); } if (bc >= 4 && dc >= 0) { Sb.Append(&quot; and member will exceed maximum allowed books for checkout&quot;); } else if (bc >= 4) { Sb.Append(&quot;Member will exceed maximum allowed books for checkout&quot;); } return Sb; }
  • 13.
    Validation Class publicStringBuilder ValidateCheckOut(Int32 bc) { StringBuilder Sb = new StringBuilder(); if (bc >= 4) { Sb.Append(&quot;Member will exceed maximum allowed books for checkout&quot;); } return Sb; } #endregion
  • 14.
    Validation Class #region-EvaluateExpirationDate//This is the method I should use to return //the color change for the expiration textbox //in the Check out book tab. public Enum ChangeColor(DateTime d) { int expireDate; Colors c = new Colors(); c = Colors.White; expireDate = DateTime.Compare(DateTime.Now.AddDays(7), d); if (expireDate > 0) { c = Colors.Yellow; } expireDate = DateTime.Compare(DateTime.Now, d); if (expireDate >= 0) { c = Colors.Red; } return c; } #endregion } }
  • 15.
    Business Layer Classusing System; using System.Collections.Generic; using System.Text; using SetFocus.Library.DataAccess; using SetFocus.Library.Entities; using System.Data; namespace JG.LibraryBusiness { public class BusinessLayer { public BusinessLayer() { }
  • 16.
    Business Layer Class/// <summary> /// This method will retrive member Id. /// </summary> /// <param name=&quot;memberId&quot;></param> /// <returns></returns> #region - Get Member ID public Member GetInformation(short memberId) { // Create a library data access object LibraryDataAccess lda = new LibraryDataAccess(); // Call the GetMember() method and pass in a member id Member myMember = lda.GetMember(memberId); // return the retrieved member return myMember; } #endregion
  • 17.
    Business Layer Class/// <summary> /// The Add New Member method is overloaded to take both adult and juvenile members /// </summary> /// <param name=&quot;J&quot;></param> #region- Add new members public void AddNewMember(JuvenileMember J) { LibraryDataAccess lda = new LibraryDataAccess(); lda.AddMember(J); } public void AddNewMember(AdultMember A) { LibraryDataAccess lda = new LibraryDataAccess(); lda.AddMember(A); } #endregion
  • 18.
    Businss Layer Class/// <summary> /// Get Member book Info will return a /// dataset of all the books that /// are currently checked out by the member /// /// </summary> /// <param name=&quot;num&quot;></param> /// <returns>Dataset</returns> #region -Get Member's book information public DataSet GetCheckoutInfo(Int16 num) { LibraryDataAccess lda = new LibraryDataAccess(); DataSet Ds = lda.GetItems(num); return Ds; } #endregion
  • 19.
    Business Layer Class/// <summary> /// Get Member book Info will return a /// dataset of all the books that /// are currently checked out by the member /// /// </summary> /// <param name=&quot;num&quot;></param> /// <returns>Dataset</returns> #region -Get Member's book information public DataSet GetCheckoutInfo(Int16 num) { LibraryDataAccess lda = new LibraryDataAccess(); DataSet Ds = lda.GetItems(num); return Ds; } #endregion
  • 20.
    Business Layer Class/// <summary> /// CheckIn method will check in books /// </summary> /// <param name=&quot;isbn&quot;></param> /// <param name=&quot;Cnum&quot;></param> #region-CheckIn public void CheckIn(Int32 isbn, Int16 Cnum) { LibraryDataAccess lda = new LibraryDataAccess(); lda.CheckInItem(isbn, Cnum); } #endregion
  • 21.
    Business Layer Class/// <summary> /// This will get the items in the Item class and return an object /// </summary> /// <param name=&quot;isbn&quot;></param> /// <param name=&quot;Cnum&quot;></param> /// <returns>Item Object</returns> #region-GetItem public object GetItem(Int32 isbn,Int16 Cnum) { LibraryDataAccess ld = new LibraryDataAccess(); Item It = ld.GetItem(isbn, Cnum); return It; } #endregion
  • 22.
    Business Layer Class/// </summary> /// <param name=&quot;mem&quot;></param> /// <param name=&quot;isdn&quot;></param> /// <param name=&quot;copy&quot;></param> #region-Check Out public void CheckOut(Int16 mem, Int32 isdn, Int16 copy) { try { LibraryDataAccess lda = new LibraryDataAccess(); lda.CheckOutItem(mem, isdn, copy); } catch (LibraryException) { } } #endregion } }