Your SlideShare is downloading. ×
Email Program By Marcelo
Email Program By Marcelo
Email Program By Marcelo
Email Program By Marcelo
Email Program By Marcelo
Email Program By Marcelo
Email Program By Marcelo
Email Program By Marcelo
Email Program By Marcelo
Email Program By Marcelo
Email Program By Marcelo
Email Program By Marcelo
Email Program By Marcelo
Email Program By Marcelo
Email Program By Marcelo
Email Program By Marcelo
Email Program By Marcelo
Email Program By Marcelo
Email Program By Marcelo
Email Program By Marcelo
Email Program By Marcelo
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Email Program By Marcelo

484

Published on

Allows to send email with patient information to the hospital.

Allows to send email with patient information to the hospital.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
484
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
14
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. (Library Project) by Marcelo Salvador Introduction: The project was created in order to create a library database accessing a SQL Server database and allowing data manipulation. Audience:  Business Executives  Information Workers  IT Managers Project Goals: The goal of this project was to allow data manipulation of a library database by utilizing Windows Forms as a graphic user interface. Afterwards, the project was migrated to ASP.NET. Below I enclose examples of the classes utilizing N-Tier Architecture. using System; using System.Collections.Generic; using System.Text; using Ms.Library.Entities; using Ms.Library.Entities.Properties; using Ms.Library.Entities.ItemsDataSetTableAdapters; using LibraryDataAccess; using LibraryDataAccess.Properties; using System.Data.SqlClient; using System.Data; /********************************************************************* * Description: This class is utilized to gather all the information from * the database;also, deletes, updates,etc. Every single * methods contains a connection to the library database and * returns an error number in case an error takes place. * * Author: Marcelo D. Salvador * Create Date: 11/24/2008 * Modified Date: 11/28/2007
  • 2. * Modification: 12/01/2008 ********************************************************************/ namespace Marcelo_Library { /// <summary> /// This class is utilized to access data in the library database /// </summary> public class LibraryDataAccess { /// <summary> /// default constructor /// </summary> public LibraryDataAccess() { } /// <summary> /// Gets the member based on member ID /// </summary> /// <param name="memberID"></param> /// <returns></returns> public Member getMember(int memberID) { Member mymember = new Member(); int returnValue; try { // create connection using (SqlConnection cnn = new SqlConnection(Settings.Default.libraryConnectionString)) { // create the command object using (SqlCommand cmd = new SqlCommand("GetMember", cnn)) { // assign the connection above to your new command object cmd.Connection = cnn; // name of the proc you are calling // command object will use a stored procedure cmd.CommandType = CommandType.StoredProcedure; //add input paramater for memberID cmd.Parameters.AddWithValue("@MemberID", memberID); //add return value parameter so we can access the return value from the proc SqlParameter returnParm = new SqlParameter(); returnParm.ParameterName = "@return"; returnParm.SqlDbType = SqlDbType.Int; returnParm.Direction = ParameterDirection.ReturnValue; cmd.Parameters.Add(returnParm);
  • 3. // open the connection cnn.Open(); // create a SQLDAtaREader to use with the data coming back from the proc using (SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection)) { // It will fall into the code // block below if the proc // executed successfully // and returned a row. while (reader.Read()) {//Column order on the table /* m.lastname, m.firstname, m.middleinitial, a.street, a.city, a.state, a.zip, a.phone_no, a.expr_date, j.adult_member_no, j.birth_date */ /* Checking if the column number 10 which is * actually 9 because it is zero based.*/ if (!(reader.IsDBNull(9))) { //Juvenile member created... JuvenileMember juvMember = new JuvenileMember(); //using ordinal positions of columns juvMember.LastName = reader[0].ToString(); juvMember.FirstName = reader[1].ToString(); juvMember.MiddleInitial = reader[2].ToString(); juvMember.AdultMemberID = short.Parse(reader[9].ToString()); juvMember.BirthDate = DateTime.Parse(reader[10].ToString()); // juvenile member is built in entity class can return it now return juvMember; } else { //Adult member created
  • 4. AdultMember myAdultMember = new AdultMember(); myAdultMember.LastName = reader[0].ToString(); myAdultMember.FirstName = reader[1].ToString(); myAdultMember.MiddleInitial = reader[2].ToString(); myAdultMember.Street = reader[3].ToString(); myAdultMember.City = reader[4].ToString(); myAdultMember.State = reader[5].ToString(); // zipcode needs to be trimmed string zip = reader[6].ToString(); myAdultMember.ZipCode = zip.Trim(); myAdultMember.PhoneNumber = reader[7].ToString(); myAdultMember.ExpirationDate = DateTime.Parse(reader[8].ToString()); return myAdultMember; } } } // Checking SQL stored procedures return values and through exceptions based on them returnValue = int.Parse(cmd.Parameters["@return"].Value.ToString()); /*return 0 -- 'Return values successful from the query*/ /*Return -1 -- 'MemberID is null'*/ /*Return -2 -- 'MemberID is < 1 OR MemberID > 32767*/ /*Return -3 -- 'No Member found or if length is greater than 5*/ if (returnValue != 0) { switch (returnValue) { case -1: throw new LibraryException("isbn is null", LibraryException.ErrorCode.IsbnIsNull); case -2: throw new LibraryException("copy_no is null", LibraryException.ErrorCode.OutOfRangeMemberValue); case -3: throw new LibraryException("member_no is null", LibraryException.ErrorCode.NoSuchMember); } }
  • 5. } } } catch (InvalidCastException e) { string.Format("Invalid Cast", e.ToString()); } catch (SqlException sql) { throw new LibraryException(sql.Message, LibraryException.ErrorCode.GenericException); } return mymember; } /// <summary> /// /// </summary> /// <param name="memberNumber"></param> /// <returns></returns> public ItemsDataSet GetItems(short memberNumber) { ItemsDataSet itemsDS = new ItemsDataSet(); ItemsTableAdapter itemsTableAdapter = new ItemsTableAdapter(); ItemsDataSet.ItemsDataTable myTable = new ItemsDataSet.ItemsDataTable(); int returnValue = itemsTableAdapter.Fill(itemsDS.Items, memberNumber); returnValue = (int)itemsTableAdapter.GetReturnValue(0); if (returnValue == 0) return itemsDS; else throw new Exception("Book not Found!!!"); } /// <summary> /// Get book information /// </summary> /// <param name="isbnNumber"></param> /// <param name="copyNumber"></param> /// <returns></returns> public Item GetItem(int isbnNumber, short copyNumber) { Item myitem = new Item(); int returnValue; try { // create connection using (SqlConnection cnn = new SqlConnection(Settings.Default.libraryConnectionString)) {
  • 6. // create the command object using (SqlCommand cmd = new SqlCommand("GetMyItem", cnn)) { // assign the connection above to your new command object cmd.Connection = cnn; // name of the proc you are calling // command object will use a stored procedure cmd.CommandType = CommandType.StoredProcedure; //add input paramater for memberID cmd.Parameters.AddWithValue("@isbn", isbnNumber); cmd.Parameters.AddWithValue("@copy_no", copyNumber); //add return value parameter so we can access the return value from the proc SqlParameter returnParm = new SqlParameter(); returnParm.ParameterName = "@return"; returnParm.SqlDbType = SqlDbType.Int; returnParm.Direction = ParameterDirection.ReturnValue; cmd.Parameters.Add(returnParm); // open the connection cnn.Open(); // create a SQLDataReader to use with the data coming back from the proc using (SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection)) { // we will fall into the code block below if the proc executed successfully // and returned a row. while (reader.Read()) { /* * @isbn, * @copy_no, * @title, * @author, * @member_no, * @out_date, * @due_date */ if (!(reader.IsDBNull(0))) { //add stuff to juvenile class Item dItem = new Item(); // Using ordinal positions of columns
  • 7. dItem.ISBN = Convert.ToInt32(reader[0].ToString()); dItem.CopyNo = Convert.ToInt32(reader[1].ToString()); dItem.Title = reader[2].ToString(); dItem.Author = reader[3].ToString(); dItem.MemberNO = Convert.ToInt32(reader[4].ToString()); dItem.OutDate = Convert.ToDateTime(reader[5].ToString()); dItem.DueDate = Convert.ToDateTime(reader[6].ToString()); return dItem; } } } //RETURN Codes: //RETURN 0 -- Sucesss //RETURN -1 -- ISBN is null //RETURN -2 -- Copy number is null //RETURN -3 -- Member does not exist returnValue = int.Parse(cmd.Parameters["@return"].Value.ToString()); if (returnValue != 0) { switch (returnValue) { case -1: throw new LibraryException("isbn is null", LibraryException.ErrorCode.IsbnIsNull); case -2: throw new LibraryException("copy_no is null", LibraryException.ErrorCode.OutOfRangeMemberValue); case -3: throw new LibraryException("member_no is null", LibraryException.ErrorCode.NoSuchMember); } } } } } catch (InvalidCastException e) { string.Format("Invalid Cast", e.ToString()); } catch (SqlException ex) {
  • 8. throw new LibraryException(ex.Message, LibraryException.ErrorCode.GenericException); } return myitem; } /// <summary> /// Add item to loan table /// </summary> /// <param name="memberID"></param> /// <param name="copyNumber"></param> /// <param name="isbnNumber"></param> public void CheckOutItem(int memberID, short copyNumber, int isbnNumber) { try { //Open Library connection //using (SqlConnection cnn = new SqlConnection(connectionString)) using (SqlConnection cnn = new SqlConnection(Settings.Default.libraryConnectionString)) { //create the command within a using block using (SqlCommand cmd = new SqlCommand("checkOutBookItem", cnn)) { Item member = new Item(); // Item member = new Item(isbnNumber, copyNumber, memberID); cmd.CommandType = CommandType.StoredProcedure; // Set up the return value parameter SqlParameter prm = new SqlParameter(); prm.ParameterName = "@Return"; prm.Direction = ParameterDirection.ReturnValue; cmd.Parameters.Add(prm); // Passes in the memberID, copyNumber and isbnNumber passed in // from the checkout screen. cmd.Parameters.AddWithValue("@isbn", isbnNumber); cmd.Parameters.AddWithValue("@copy_no", copyNumber); cmd.Parameters.AddWithValue("@member_no", memberID); // Open connection and execute query cnn.Open(); cmd.ExecuteNonQuery(); /* Error Codes From the CheckOut Book stored procedure...
  • 9. Return -1 -- 'isbn is null' Return -2 -- 'copy_no is null' Return -3 -- 'member_no is null' Return -4 -- 'book does not exist' Return -5 -- 'member does not exist' Return -6 -- 'copy does not exist' Return -7 -- 'book already checked out' Return -8 -- 'member has 4 books already' Return -9 -- 'insert failed' */ int returnValue = (int)cmd.Parameters["@Return"].Value; if (returnValue != 0) { switch (returnValue) { case -1: throw new LibraryException("isbn is null", LibraryException.ErrorCode.IsbnIsNull); case -2: throw new LibraryException("copy_no is null", LibraryException.ErrorCode.CopyNoIsNull); case -3: throw new LibraryException("member_no is null", LibraryException.ErrorCode.MemberNoIsNull); case -4: throw new LibraryException("book does not exist", LibraryException.ErrorCode.BookDoesNotExist); case -5: throw new LibraryException("member does not exist", LibraryException.ErrorCode.NoSuchMember); case -6: throw new LibraryException("copy does not exist", LibraryException.ErrorCode.CopyDoesNotExist); case -7: throw new LibraryException("book already checked out", LibraryException.ErrorCode.BookAlreadyCheckedOut); case -8: throw new LibraryException("member has 4 books already", LibraryException.ErrorCode.MemberHasfourBooksAlready); case -9: throw new LibraryException("insert failed", LibraryException.ErrorCode.InsertFailed); } } } } } catch (SqlException sqlex) { throw new LibraryException(sqlex.Message, LibraryException.ErrorCode.GenericException); } }
  • 10. /// <summary> /// /// </summary> /// <param name="copyNumber"></param> /// <param name="isbnNumber"></param> public void CheckInItem(short copyNumber, int isbnNumber) { try { //Open Library connection //using (SqlConnection cnn = new SqlConnection(connectionString)) using (SqlConnection cnn = new SqlConnection(Settings.Default.libraryConnectionString)) { //create the command within a using block using (SqlCommand cmd = new SqlCommand("CheckInBookItem", cnn)) { cmd.CommandType = CommandType.StoredProcedure; // Set up the return value parameter SqlParameter prm = new SqlParameter(); prm.ParameterName = "@Return"; prm.Direction = ParameterDirection.ReturnValue; cmd.Parameters.Add(prm); // Passes the new member variables to the stored proc cmd.Parameters.AddWithValue("@isbn", isbnNumber); cmd.Parameters.AddWithValue("@copy_no", copyNumber); // Open connection and execute query cnn.Open(); cmd.ExecuteNonQuery(); // Get Error Code int returnValue = (int)cmd.Parameters["@Return"].Value; /* Error codes: Return -1 -- 'isbn is null' Return -2 -- 'copy_no is null' Return -3 -- 'member_no is null' Return -4 -- 'book does not exist' Return -5 -- 'copy does not exist' Return -6 -- 'book is not checked out' Return -7 -- 'delete from loan table failed'
  • 11. Return -8 -- 'Adding row to loan history table failed' Return -9 -- 'Update on copy table failed' */ if (returnValue != 0) { switch (returnValue) { case -1: throw new LibraryException("isbn is null", LibraryException.ErrorCode.IsbnIsNull); case -2: throw new LibraryException("copy_no is null", LibraryException.ErrorCode.CopyNoIsNull); case -3: throw new LibraryException("member_no is null", LibraryException.ErrorCode.MemberNoIsNull); case -4: throw new LibraryException("book does not exist", LibraryException.ErrorCode.BookDoesNotExist); case -5: throw new LibraryException("member does not exist", LibraryException.ErrorCode.DeleteFailed); case -6: throw new LibraryException("copy does not exist", LibraryException.ErrorCode.InsertFailed); case -7: throw new LibraryException("book already checked out", LibraryException.ErrorCode.BookAlreadyCheckedOut); case -8: throw new LibraryException("member has 4 books already", LibraryException.ErrorCode.MemberHasfourBooksAlready); case -9: throw new LibraryException("insert failed", LibraryException.ErrorCode.UpdateFailed); } } } } } catch (SqlException ex) { throw new LibraryException(ex.Message, LibraryException.ErrorCode.GenericException); } } /// <summary> /// /// </summary> /// <param name="member"></param> public void AddMember(AdultMember member) {
  • 12. try { //Open Library connection //using (SqlConnection cnn = new SqlConnection(connectionString)) using (SqlConnection cnn = new SqlConnection(Settings.Default.libraryConnectionString)) { //create the command within a using block using (SqlCommand cmd = new SqlCommand("AddAdult", cnn)) { cmd.CommandType = CommandType.StoredProcedure; // Set up the return value parameter SqlParameter prm = new SqlParameter(); prm.ParameterName = "@Return"; prm.Direction = ParameterDirection.ReturnValue; cmd.Parameters.Add(prm); // Passes the new member variables to the stored proc cmd.Parameters.AddWithValue("@lastName", member.LastName); cmd.Parameters.AddWithValue("@name", member.FirstName); cmd.Parameters.AddWithValue("@middleInitial", member.MiddleInitial); cmd.Parameters.AddWithValue("@street", member.Street); cmd.Parameters.AddWithValue("@city", member.City); cmd.Parameters.AddWithValue("@state", member.State); cmd.Parameters.AddWithValue("@zipCode", member.ZipCode); cmd.Parameters.AddWithValue("@phoneNumber", member.PhoneNumber); // Add the output params prm = new SqlParameter("@InsertMemberID", SqlDbType.SmallInt); prm.Direction = ParameterDirection.Output; cmd.Parameters.Add(prm); prm = new SqlParameter("@ExpirationDate", SqlDbType.DateTime); prm.Direction = ParameterDirection.Output; cmd.Parameters.Add(prm); // Open connection and execute query cnn.Open(); cmd.ExecuteNonQuery(); // --RETURN Codes:
  • 13. //-- RETURN 0 -- Successful //-- RETURN -1 --'Firstname is null' //-- RETURN -2 --'LastName is null' //-- RETURN -3 --'Street is null' //-- RETURN -4 --'City is null' //-- RETURN -5 --'State is null' //-- RETURN -6 --'Zip is null' //-- RETURN -7 --'insert into member failed' //-- RETURN -8 --'insert into adult failed' // Get Error Code int returnValue = (int)cmd.Parameters["@Return"].Value; if (returnValue != 0) switch (returnValue) { case -1: throw new LibraryException("Firstname is null", LibraryException.ErrorCode.FirstnameIsNull); case -2: throw new LibraryException("LastName is null", LibraryException.ErrorCode.LastNameIsNull); case -3: throw new LibraryException("Street is null", LibraryException.ErrorCode.StreetIsNull); case -4: throw new LibraryException("City is null", LibraryException.ErrorCode.CityIsNull); case -5: throw new LibraryException("State is null", LibraryException.ErrorCode.StateIsNull); case -6: throw new LibraryException("Zip is null", LibraryException.ErrorCode.ZipIsNull); case -7: throw new LibraryException("insert into member failed", LibraryException.ErrorCode.InsertFailed); case -8: throw new LibraryException("insert into adult failed", LibraryException.ErrorCode.InsertFailed); } // Get return variables member.ExpirationDate = (DateTime) (cmd.Parameters["@ExpirationDate"].Value);
  • 14. member.MemberID = (short)cmd.Parameters["@InsertMemberID"].Value; } } } catch (SqlException ex) { throw new LibraryException(ex.Message, LibraryException.ErrorCode.GenericException); } } /// <summary> /// Insert juvenile and member rows into Library data base /// </summary> /// <param name="member">JuvenileMember object</param> public void AddMember(JuvenileMember member) { try {//Open Library connection using (SqlConnection cnn = new SqlConnection(Settings.Default.libraryConnectionString)) { //create the command within a using block using (SqlCommand cmd = new SqlCommand("AddJuvenile", cnn)) { cmd.CommandType = CommandType.StoredProcedure; // Set up the return value parameter SqlParameter prm = new SqlParameter(); prm.ParameterName = "@Return"; prm.Direction = ParameterDirection.ReturnValue; cmd.Parameters.Add(prm); // Pass the new member variables to the stored proc cmd.Parameters.AddWithValue("@lastname", member.LastName); cmd.Parameters.AddWithValue("@name", member.FirstName); cmd.Parameters.AddWithValue("@middleInitial", member.MiddleInitial); cmd.Parameters.AddWithValue("@adultMemberID", member.AdultMemberID); cmd.Parameters.AddWithValue("@juvBirthDate", member.BirthDate); // Add the output params SqlParameter memberIDParm = new SqlParameter(); memberIDParm.ParameterName = "@InsertMemberID"; memberIDParm.SqlDbType = SqlDbType.SmallInt; memberIDParm.Direction = ParameterDirection.Output; cmd.Parameters.Add(memberIDParm);
  • 15. // Open connection and execute query cnn.Open(); cmd.ExecuteNonQuery(); // Get Error Code int returnValue = (int)cmd.Parameters["@Return"].Value; // RETURN 0 -- Successful //-- RETURN -1 --'name is null' //-- RETURN -2 --'middleinitial is null' //-- RETURN -3 --'lastname is null' //-- RETURN -4 --'adultmemberid is null' //-- RETURN -5 --'juvbirthdate is null' //-- RETURN -6 --'insert into member failed' //-- RETURN -7 --'insert into juvenile failed' if (returnValue != 0) { switch (returnValue) { case -1: throw new LibraryException("Firstname is null", LibraryException.ErrorCode.FirstnameIsNull); case -2: throw new LibraryException("MiddleInitial is null", LibraryException.ErrorCode.NullValue); case -3: throw new LibraryException("lastname is null", LibraryException.ErrorCode.LastNameIsNull); case -4: throw new LibraryException("adultMemberId is null", LibraryException.ErrorCode.AddAdultFailed); case -5: throw new LibraryException("juvBirthDateis null", LibraryException.ErrorCode.BirthdateNull); case -6: throw new LibraryException("Insert Into Member Failed", LibraryException.ErrorCode.InsertFailed); case -7: throw new LibraryException("insert Int Juvenile failed", LibraryException.ErrorCode.AddJuvenileFailed); }
  • 16. } member.MemberID = (short)cmd.Parameters["@InsertMemberID"].Value; } } } catch (SqlException ex) { throw new LibraryException(ex.Message, LibraryException.ErrorCode.GenericException); } } /// <summary> /// Used to renew membership /// </summary> /// <param name="memberNumber"></param> public void RenewMembership(int memberNumber) { try { //Open Library connection //using (SqlConnection cnn = new SqlConnection(connectionString)) using (SqlConnection cnn = new SqlConnection(Settings.Default.libraryConnectionString)) { //create the command within a using block using (SqlCommand cmd = new SqlCommand("RenewExpirationDate", cnn)) { Item member = new Item(); // Item member = new Item(isbnNumber, copyNumber, memberID); cmd.CommandType = CommandType.StoredProcedure; // Set up the return value parameter SqlParameter prm = new SqlParameter(); prm.ParameterName = "@Return"; prm.Direction = ParameterDirection.ReturnValue; cmd.Parameters.Add(prm); // Passes in the memberID // from the checkout screen. cmd.Parameters.AddWithValue("@member_no", memberNumber); // Add the output params SqlParameter memberExpDate = new SqlParameter(); memberExpDate.ParameterName = "@expr_date"; memberExpDate.SqlDbType = SqlDbType.DateTime; memberExpDate.Direction = ParameterDirection.Output;
  • 17. cmd.Parameters.Add(memberExpDate); // Open connection and execute query cnn.Open(); cmd.ExecuteNonQuery(); /* Error Codes From the CheckOut Book stored procedure... Return -1 -- 'Failed: Member number is null' Return -2 -- 'Failed: Member does not exist' Return -3 -- 'Insert into adult member table failed' */ int returnValue = (int)cmd.Parameters["@Return"].Value; if (returnValue != 0) { switch (returnValue) { case -1: throw new LibraryException("Failed: Member number is null", LibraryException.ErrorCode.MemberNoIsNull); case -2: throw new LibraryException("Failed: Member does not exist", LibraryException.ErrorCode.NoSuchMember); case -3: throw new LibraryException("Insert into adult member table failed", LibraryException.ErrorCode.InsertFailed); } } } } } catch (SqlException sqlex) { throw new LibraryException(sqlex.Message, LibraryException.ErrorCode.GenericException); } } /// <summary> /// Method used to add a new book to the library database /// </summary> /// <param name="title"></param> /// <param name="author"></param> /// <param name="synopsis"></param> /// <param name="isbn"></param> /// <param name="translation"></param> /// <param name="cover"></param> /// <param name="loanable"></param> public void AddNewBook(string title, string author, string synopsis, int isbn, string translation, string cover, char loanable)
  • 18. { try { //Open Library connection //using (SqlConnection cnn = new SqlConnection(connectionString)) using (SqlConnection cnn = new SqlConnection(Settings.Default.libraryConnectionString)) { //create the command within a using block using (SqlCommand cmd = new SqlCommand("EnterNewBook", cnn)) { Item member = new Item(); cmd.CommandType = CommandType.StoredProcedure; // Set up the return value parameter SqlParameter prm = new SqlParameter(); prm.ParameterName = "@Return"; prm.Direction = ParameterDirection.ReturnValue; cmd.Parameters.Add(prm); // Passes in the values // from the checkout screen. cmd.Parameters.AddWithValue("@title", title); cmd.Parameters.AddWithValue("@author", author); cmd.Parameters.AddWithValue("@synopsis", synopsis); cmd.Parameters.AddWithValue("@isbn", isbn); cmd.Parameters.AddWithValue("@translation", translation); cmd.Parameters.AddWithValue("@cover", cover); cmd.Parameters.AddWithValue("@loanable", loanable); // Open connection and execute query cnn.Open(); cmd.ExecuteNonQuery(); /* *********************************************************************** **** * RETURN Codes: RETURN -0 -- Sucesss RETURN -1 -- The title is null RETURN -2 -- The author is null RETURN -3 -- The synopsis is null is null RETURN -4 -- The translation is null RETURN -5 -- The cover is null RETURN -6 -- The loanable is null RETURN -7 -- The isbn is null is null
  • 19. RETURN -8 -- The ISBN exist in the Item table RETURN -9 -- The isbn exist in the copy table RETURN -10 -- INSERT for the title table failed RETURN -11 -- INSERT for the item table failed RETURN -12 -- INSERT for the copy table failed ********************************************** ********************************/ int returnValue = (int)cmd.Parameters["@Return"].Value; if (returnValue != 0) { switch (returnValue) { case -1: throw new LibraryException("The title is null", LibraryException.ErrorCode.titleIsNull); case -2: throw new LibraryException("The author is null", LibraryException.ErrorCode.AuthorIsNull); case -3: throw new LibraryException("The synopsis is null is null", LibraryException.ErrorCode.SynopsisIsNull); case -4: throw new LibraryException("The translation is null", LibraryException.ErrorCode.TranslationIsNull); case -5: throw new LibraryException("The cover is null", LibraryException.ErrorCode.CoverIsNull); case -6: throw new LibraryException("The loanable is null", LibraryException.ErrorCode.LoanableIsNull); case -7: throw new LibraryException("The isbn is null is null", LibraryException.ErrorCode.IsbnIsNull); case -8: throw new LibraryException("The ISBN exist in the Item table", LibraryException.ErrorCode.IsbnExistInItemTable); case -9: throw new LibraryException("The isbn exist in the copy table", LibraryException.ErrorCode.IsbnExistInCopyTable); case -10: throw new LibraryException("INSERT for the title table failed", LibraryException.ErrorCode.TitleInsertFailed); case -11: throw new LibraryException("INSERT for the item table failed", LibraryException.ErrorCode.ItemInsertFailed); case -12:
  • 20. throw new LibraryException("INSERT for the copy table failed", LibraryException.ErrorCode.CopyInsertFailed); } } } } } catch (SqlException sqlex) { throw new LibraryException(sqlex.Message, LibraryException.ErrorCode.GenericException); } } /// <summary> /// Method created to convert a Juvenile member of less than 18 yrs of age to an adult member) /// </summary> /// <param name="memberNumber"></param> public void adolescentToAdult(int memberNumber) { try { //Open Library connection //using (SqlConnection cnn = new SqlConnection(connectionString)) using (SqlConnection cnn = new SqlConnection(Settings.Default.libraryConnectionString)) { //create the command within a using block using (SqlCommand cmd = new SqlCommand("KidToAdult", cnn)) { Item member = new Item(); cmd.CommandType = CommandType.StoredProcedure; // Set up the return value parameter SqlParameter prm = new SqlParameter(); prm.ParameterName = "@Return"; prm.Direction = ParameterDirection.ReturnValue; cmd.Parameters.Add(prm); // Passes in the memberID // from the checkout screen. cmd.Parameters.AddWithValue("@member_no", memberNumber); // Open connection and execute query cnn.Open(); cmd.ExecuteNonQuery();
  • 21. /* Error Codes From the KitToAdult Book stored procedure... Return -1 -- 'Juvenile member number is null' Return -2 -- 'Juvenile member does not exist' Return -3 -- 'Delete from juvenile member table failed' Return -4 -- ''Insert into adult member table failed' */ int returnValue = (int)cmd.Parameters["@Return"].Value; if (returnValue != 0) { switch (returnValue) { case -1: throw new LibraryException("Juvenile member number is null", LibraryException.ErrorCode.MemberNoIsNull); case -2: throw new LibraryException("Juvenile member does not exist", LibraryException.ErrorCode.NoSuchMember); case -3: throw new LibraryException("Delete from juvenile member table failed", LibraryException.ErrorCode.DeleteFailed); case -4: throw new LibraryException("Insert into adult member table failed", LibraryException.ErrorCode.InsertFailed); } } } } } catch (SqlException sqlex) { throw new LibraryException(sqlex.Message, LibraryException.ErrorCode.GenericException); } } } }

×