/// <summary> /// Miguel Santana /// Created: 2015/02/16 /// Edit an Existing Hotel Guest /// </summary> /// <param name="hotelGuest"></param> /// <param name="readOnly">Make the form ReadOnly.</param> /// <exception cref="WanderingTurtleException">Occurs making components readonly.</exception> public AddEditHotelGuest(HotelGuest hotelGuest, bool readOnly = false) { InitializeComponent(); CurrentHotelGuest = hotelGuest; Title = String.Format("Editing Guest: {0}", CurrentHotelGuest.GetFullName); InitializeEverything(); if (readOnly) { (Content as Panel).MakeReadOnly(BtnCancel); } }
/// <summary> /// Miguel Santana /// Created: 2015/02/12 /// Creates a new Hotel Guest in the database /// </summary> /// <remarks> /// Rose Steffensmeier /// Updated: 2015/03/10 /// /// Rose Steffensmeier /// Updated: 2015/03/12 /// Updated try/catch blocks /// /// Tony Noel /// Updated 2015/04/13 by /// Updated to comply with the ResultsEdit class of error codes. /// </remarks> /// <param name="newHotelGuest">Object containing new hotel guest information</param> /// <returns>Number of rows effected</returns> public ResultsEdit AddHotelGuest(HotelGuest newHotelGuest) { try { bool worked = HotelGuestAccessor.HotelGuestAdd(newHotelGuest) > 0; if (worked == true) { return ResultsEdit.Success; } } catch (SqlException) { throw; } catch (Exception) { throw; } return ResultsEdit.DatabaseError; }
/// <summary> /// Miguel Santana /// Created: 2015/02/12 /// Creates a new Hotel Guest in the database /// </summary> /// <remarks> /// Pat Banks /// Updated: 2015/02/27 /// Stored Procedure updated to create an invoice record automatically when adding a hotel guest /// /// Rose Steffensmeier /// Updated: 2015/03/12 /// Added try-catch blocks /// /// Pat Banks /// Updated: 2015/04/03 /// Added GuestPIN field /// </remarks> /// <param name="newHotelGuest">Object containing new hotel guest information</param> /// <returns>Number of rows effected</returns> public static int HotelGuestAdd(HotelGuest newHotelGuest) { var conn = DatabaseConnection.GetDatabaseConnection(); var cmdText = "spInsertHotelGuestInsertInvoice"; var cmd = new SqlCommand(cmdText, conn); var numRows = 0; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@firstName", newHotelGuest.FirstName); cmd.Parameters.AddWithValue("@lastName", newHotelGuest.LastName); cmd.Parameters.AddWithValue("@zip", newHotelGuest.CityState.Zip); cmd.Parameters.AddWithValue("@address1", newHotelGuest.Address1); cmd.Parameters.AddWithValue("@address2", newHotelGuest.Address2); cmd.Parameters.AddWithValue("@phoneNumber", newHotelGuest.PhoneNumber); cmd.Parameters.AddWithValue("@email", newHotelGuest.EmailAddress); cmd.Parameters.AddWithValue("@room", newHotelGuest.Room); cmd.Parameters.AddWithValue("@guestPIN", newHotelGuest.GuestPIN); try { conn.Open(); numRows = cmd.ExecuteNonQuery(); } catch (SqlException) { throw; } catch (Exception) { throw; } finally { conn.Close(); } return numRows; }
public void initialize() { //Contructs the HotelGuest object to be used for all tests. TestGuest = new HotelGuest("Fake", "Person", "1111 Fake St.", "", new CityState("52641", "Mt. Pleasant", "IA"), "5556667777", "*****@*****.**", "234234", "3453", true); }
public void HotelManagerUpdate() { ResultsEdit changed = access.AddHotelGuest(TestGuest); //locates the fake record ID int guestID = TestCleanupAccessor.GetHotelGuest(); //pulls from real manager HotelGuest guest = access.GetHotelGuest(guestID); //assigns a new value in guest2 HotelGuest guest2 = new HotelGuest(guest.FirstName, "Individual", guest.Address1, guest.Address2, guest.CityState, guest.PhoneNumber, guest.EmailAddress, guest.Room, guest.GuestPIN, guest.Active); //calls to manager to complete update ResultsEdit edited = access.UpdateHotelGuest(guest, guest2); Assert.AreEqual(ResultsEdit.Success, edited); }
public void initialize() { TestGuest = new HotelGuest("Fake", "Person", "1111 Fake St.", "", new CityState("52641", "Mt. Pleasant", "IA"), "5556667777", "*****@*****.**", "234234", "3453", true); hgm.AddHotelGuest(TestGuest); }
/// <summary> /// Miguel Santana /// Created: 2015/02/12 /// /// Updates a hotel guest with new information /// </summary> /// <remarks> /// Rose Steffensmeier /// Updated: 2015/03/12 /// Updated try/catch blocks /// /// Tony Noel /// Updated 2015/04/13 /// Updated to comply with the ResultsEdit class of error codes. /// </remarks> /// <param name="oldHotelGuest">Object containing original information about a hotel guest</param> /// <param name="newHotelGuest">Object containing new hotel guest information</param> /// <returns>Number of rows effected</returns> public ResultsEdit UpdateHotelGuest(HotelGuest oldHotelGuest, HotelGuest newHotelGuest) { try { bool worked = HotelGuestAccessor.HotelGuestUpdate(oldHotelGuest, newHotelGuest) > 0; if (worked == true) { return ResultsEdit.Success; } } catch (ApplicationException) { throw; } catch (SqlException) { throw; } catch (Exception) { throw; } return ResultsEdit.DatabaseError; }
/// <summary> /// Miguel Santana /// Created: 2015/02/12 /// Updates a hotel guest with new information /// </summary> /// <remarks> /// Rose Steffensmeier /// Updated: 02/23/2015 /// added room number field /// </remarks> /// <param name="oldHotelGuest">Object containing original information about a hotel guest</param> /// <param name="newHotelGuest">Object containing new hotel guest information</param> /// <returns>Number of rows effected</returns> public static int HotelGuestUpdate(HotelGuest oldHotelGuest, HotelGuest newHotelGuest) { var conn = DatabaseConnection.GetDatabaseConnection(); var cmdText = "spUpdateHotelGuest"; var cmd = new SqlCommand(cmdText, conn); var numRows = 0; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@firstName", newHotelGuest.FirstName); cmd.Parameters.AddWithValue("@lastName", newHotelGuest.LastName); cmd.Parameters.AddWithValue("@zip", newHotelGuest.CityState.Zip); cmd.Parameters.AddWithValue("@address1", newHotelGuest.Address1); cmd.Parameters.AddWithValue("@address2", newHotelGuest.Address2); cmd.Parameters.AddWithValue("@phoneNumber", newHotelGuest.PhoneNumber); cmd.Parameters.AddWithValue("@email", newHotelGuest.EmailAddress); cmd.Parameters.AddWithValue("@room", newHotelGuest.Room); cmd.Parameters.AddWithValue("@active", newHotelGuest.Active); cmd.Parameters.AddWithValue("@guestpin", newHotelGuest.GuestPIN); cmd.Parameters.AddWithValue("@original_hotelGuestID", oldHotelGuest.HotelGuestID); cmd.Parameters.AddWithValue("@original_firstName", oldHotelGuest.FirstName); cmd.Parameters.AddWithValue("@original_lastName", oldHotelGuest.LastName); cmd.Parameters.AddWithValue("@original_zip", oldHotelGuest.CityState.Zip); cmd.Parameters.AddWithValue("@original_address1", oldHotelGuest.Address1); cmd.Parameters.AddWithValue("@original_address2", oldHotelGuest.Address2); cmd.Parameters.AddWithValue("@original_phoneNumber", oldHotelGuest.PhoneNumber); cmd.Parameters.AddWithValue("@original_email", oldHotelGuest.EmailAddress); cmd.Parameters.AddWithValue("@original_room", oldHotelGuest.Room); cmd.Parameters.AddWithValue("@original_active", oldHotelGuest.Active); cmd.Parameters.AddWithValue("@original_guestpin", oldHotelGuest.GuestPIN); try { conn.Open(); numRows = cmd.ExecuteNonQuery(); if (numRows == 0) { throw new ApplicationException("Concurrency Violation"); } } catch (SqlException) { throw; } catch (Exception) { throw; } finally { conn.Close(); } return numRows; }
/// <summary> /// Arik Chadima /// Created: 2015/4/30 /// Refactored->Extracted method for reuse. /// </summary> private void ResetVariables() { foundGuest = null; ticketQty = 0; guestName = ""; eventName = ""; date = DateTime.Now; discount = 0; totalPrice = 0; extendedPrice = 0m; selectedItemListing = null; //create new session variables Session["foundGuest"] = foundGuest; Session["ticketQty"] = ticketQty; Session["selectedItemListing"] = selectedItemListing; Session["extendedPrice"] = extendedPrice; Session["totalPrice"] = totalPrice; Session["discount"] = discount; }
/// <summary> /// Pat Banks /// Created: 2015/04/11 /// Loads web pages for hotel guest and udpates session variables /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_Load(object sender, EventArgs e) { if (Session.IsNewSession) { ResetVariables(); } else { //update variables with Session variables try { foundGuest = (HotelGuest)Session["foundGuest"]; ticketQty = (int)Session["ticketQty"]; selectedItemListing = (ItemListingDetails)Session["selectedItemListing"]; extendedPrice = (decimal)Session["extendedPrice"]; totalPrice = (decimal)Session["totalPrice"]; discount = (decimal)Session["discount"]; } catch { //Running on the assumption that if there's an exception it's due to the (int) case on ticketQty failing due to a null session object. ResetVariables(); } } }
/// <summary> /// Pat Banks /// Created 2015/04/11 /// Handles submit functionality of a hotel guest adding an event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSubmit_Click(object sender, EventArgs e) { lblOtherMessage.Text = ""; string errors = ""; //if something isn't selected - throw error if (gvListings.SelectedValue == null) { errors += "<li>Please select an event</li>"; } //gets quantity from the quantity field if (!txtGuestTickets.Text.ValidateInt(1)) { errors += "<li>You must enter a valid number of tickets.</li>"; txtGuestTickets.Text = ""; } else { if (Int32.Parse(txtGuestTickets.Text) > getSelectedItem().QuantityOffered) { errors += "<li>You cannot request more tickets than available</li>"; txtGuestTickets.Text = ""; } } if (!txtGuestPin.Text.ValidateAlphaNumeric()) { errors += "<li>You must enter a valid pin.</li>"; txtGuestTickets.Text = ""; } if (errors.Length > 0) { showError("Please fix the following errors: <ul>" + errors + "</ul>"); return; } try { string inPin = txtGuestPin.Text; //see if pin was found = if not there will be an exception foundGuest = myManager.CheckValidPIN(inPin); } catch (Exception) { showError("You must enter a valid pin."); } gatherFormInformation(); }
/// <summary> /// Pat Banks /// Created: 2015/04/14 /// Verifies the hotel guest pin to sign up for an item listing and create a booking /// </summary> /// <param name="inPIN">The pin to cross reference against HotelGuests</param> /// <returns>Hotel guest that has that pin</returns> public static HotelGuest VerifyHotelGuestPin(string inPIN) { SqlConnection conn = DatabaseConnection.GetDatabaseConnection(); var cmdText = "spSelectHotelGuestByPin"; SqlCommand cmd = new SqlCommand(cmdText, conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@guestPIN", inPIN); HotelGuest foundGuest = null; try { conn.Open(); SqlDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { foundGuest = new HotelGuest( reader.GetInt32(0), //HotelGuestID reader.GetString(1), //FirstName reader.GetString(2), //LastName reader.GetString(3), //Address1 !reader.IsDBNull(4) ? reader.GetString(4) : null, //Address2 new CityState( reader.GetString(5), //Zip reader.GetString(6), //City reader.GetString(7) //State ), !reader.IsDBNull(8) ? reader.GetString(8) : null, //PhoneNumber !reader.IsDBNull(9) ? reader.GetString(9) : null, //EmailAdddress !reader.IsDBNull(10) ? reader.GetString(10) : null, //Room !reader.IsDBNull(11) ? reader.GetString(11) : null, // PIN reader.GetBoolean(12) //Active ); } // end while } else { var ax = new ApplicationException("PIN not found"); throw ax; } } catch (SqlException) { var ax = new ApplicationException("PIN not found"); throw ax; } catch (Exception) { throw; } finally { conn.Close(); } return foundGuest; }