/// <summary> /// Pat Banks /// Created: 2015/03/19 /// Populates text fields with object data /// </summary> private void PopulateTextFields() { //get latest data on the eventItemListing _eventListingToView = _bookingManager.RetrieveItemListingDetailsList(CurrentBookingDetails.ItemListID); _eventListingToView.QuantityOffered = _bookingManager.AvailableQuantity(_eventListingToView.MaxNumGuests, _eventListingToView.CurrentNumGuests); //populate form fields with object data LblEditBookingGuestName.Content = CurrentInvoice.GetFullName; LblEventName.Content = CurrentBookingDetails.EventItemName; LblStartDate.Content = CurrentBookingDetails.StartDate; LblTicketPrice.Content = CurrentBookingDetails.TicketPrice.ToString("c"); LblTotalDue.Content = CurrentBookingDetails.TotalCharge.ToString("c"); UdAddBookingQuantity.Value = CurrentBookingDetails.Quantity; UdDiscount.Value = (double?)CurrentBookingDetails.Discount; LblAvailSeats.Content = _eventListingToView.QuantityOffered; //calculates the maximum quantity for the u/d UdAddBookingQuantity.Maximum = CurrentBookingDetails.Quantity + _eventListingToView.QuantityOffered; }
/// <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/03/11 /// Updates the total cost with discount /// </summary> /// <param name="myItemObject"></param> private void RefreshCostsToDisplay(ItemListingDetails myItemObject) { //total cost calculations if (myItemObject == null) return; decimal extendedPrice = _bookingManager.CalcExtendedPrice(myItemObject.Price, (int)(UdAddBookingQuantity.Value)); LblTotalWithDiscount.Content = _bookingManager.CalcTotalCharge((decimal)(UdDiscount.Value), extendedPrice); }
/// <summary> /// Pat Banks /// Created 2015/04/11 /// gets selected item from the data grid /// </summary> /// <returns></returns> private ItemListingDetails getSelectedItem() { int itemID = (int)gvListings.SelectedDataKey.Value; selectedItemListing = myManager.RetrieveItemListingDetailsList(itemID); return selectedItemListing; }
/// <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/03/11 /// /// Retrieves Event Listing information for the one selected item listing /// Information is human readable with data from joined tables /// </summary> /// <param name="itemListID">ItemList ID matching an ItemListingDetails record</param> /// <returns>an ItemListingDetails containing the item listing information</returns> public ItemListingDetails RetrieveItemListingDetailsList(int itemListID) { var now = DateTime.Now; double cacheExpirationTime = 5; try { if (DataCache._currentItemListingDetailsList == null) { return BookingAccessor.GetItemListingDetails(itemListID); } //check time. If less than 5 min, return event from cache if (now > DataCache._ItemListingDetailsListTime.AddMinutes(cacheExpirationTime)) { //get event from DB var requestedEvent = BookingAccessor.GetItemListingDetails(itemListID); return requestedEvent; } else { //get event from cached list var list = DataCache._currentItemListingDetailsList; ItemListingDetails requestedEvent = new ItemListingDetails(); requestedEvent = list.Where(e => e.ItemListID == itemListID).FirstOrDefault(); if (requestedEvent != null) { return requestedEvent; } throw new ApplicationException("Event not found."); } } catch (Exception ex) { throw ex; } }
/// <summary> /// Tony Noel /// Created: 2015/02/13 /// Creates a list of Event listings with an ItemListID, Quantity, and readable event info /// to populate the lists of Event Listings /// List consists of active listings that have start time after DateTime.Now /// </summary> /// <returns>a list of ItemListingDetails objects (is created from two tables, ItemListing and Event Item)</returns> public static List<ItemListingDetails> GetItemListingDetailsList() { var activeListingDetailsList = new List<ItemListingDetails>(); //Set up database call var conn = DatabaseConnection.GetDatabaseConnection(); string query = "spSelectItemListingDetailsList"; var cmd = new SqlCommand(query, conn); cmd.CommandType = CommandType.StoredProcedure; try { conn.Open(); var reader = cmd.ExecuteReader(); if (reader.HasRows == true) { while (reader.Read()) { var currentItemListingDetails = new ItemListingDetails(); //Below are found on the ItemListing table (ItemListID is a foreign key on booking) currentItemListingDetails.ItemListID = reader.GetInt32(0); currentItemListingDetails.MaxNumGuests = reader.GetInt32(1); currentItemListingDetails.CurrentNumGuests = reader.GetInt32(2); currentItemListingDetails.StartDate = reader.GetDateTime(3); currentItemListingDetails.EndDate = reader.GetDateTime(4); //Below are found on the EventItem table currentItemListingDetails.EventID = reader.GetInt32(5); currentItemListingDetails.EventName = reader.GetString(6); currentItemListingDetails.EventDescription = reader.GetString(7); //this is from itemlisting table currentItemListingDetails.Price = reader.GetDecimal(8); activeListingDetailsList.Add(currentItemListingDetails); } } else { var ax = new ApplicationException("Booking data not found!"); throw ax; } } catch (Exception) { throw; } finally { conn.Close(); } return activeListingDetailsList; }
/// <summary> /// Pat Banks /// Created: 2015/03/11 /// Retrieves the event listing information to enable /// user to see current number of spots available for a selected listing /// </summary> /// <param name="itemListID">Id for the itemListing</param> /// <returns>An ItemListingDetails object whose ID matches the passed ID</returns> public static ItemListingDetails GetItemListingDetails(int itemListID) { var eventItemListing = new ItemListingDetails(); //Set up database call var conn = DatabaseConnection.GetDatabaseConnection(); string query = "spSelectItemListingDetailsByID"; var cmd = new SqlCommand(query, conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@itemListID", itemListID); try { conn.Open(); var reader = cmd.ExecuteReader(); if (reader.HasRows == true) { while (reader.Read()) { //Below are found on the ItemListing table (ItemListID is a foreign key on booking) eventItemListing.ItemListID = reader.GetInt32(0); eventItemListing.MaxNumGuests = reader.GetInt32(1); eventItemListing.CurrentNumGuests = reader.GetInt32(2); eventItemListing.StartDate = reader.GetDateTime(3); eventItemListing.EndDate = reader.GetDateTime(4); //Below are found on the EventItem table eventItemListing.EventID = reader.GetInt32(5); eventItemListing.EventName = reader.GetString(6); eventItemListing.EventDescription = reader.GetString(7); //this is from itemlisting table eventItemListing.Price = reader.GetDecimal(8); } } else { var ax = new ApplicationException("Event data not found!"); throw ax; } } catch (Exception) { throw; } finally { conn.Close(); } return eventItemListing; }