/// <summary>
        /// Tony Noel
        /// Created: 2015/02/13
        /// UI for adding a booking
        /// Access from the View Invoice screen
        /// </summary>
        /// <param name="inInvoice">brings the invoice data from the prior list view</param>
        public AddBooking(InvoiceDetails inInvoice)
        {
            CurrentInvoice = inInvoice;

            InitializeComponent();
            RefreshListItems();
            Title = "Add a new Booking";
            UdDiscount.Maximum = .20;

            _eId = (int)Globals.UserToken.EmployeeID;
        }
        /// <summary>
        /// Ryan Blake
        /// Created: 2015/03/06
        /// Allows user to edit a booking
        /// </summary>
        /// <param name="invoiceToEdit">Invoice info from the view invoice UI</param>
        /// <param name="inBookingDetails">Booking info from the view invoice UI</param>
        /// <param name="readOnly">Make the form ReadOnly.</param>
        /// <exception cref="WanderingTurtleException">Occurs making components readonly.</exception>
        public EditBooking(InvoiceDetails invoiceToEdit, BookingDetails inBookingDetails, bool readOnly = false)
        {
            CurrentInvoice = invoiceToEdit;
            CurrentBookingDetails = inBookingDetails;
            InitializeComponent();
            Title = "Editing Booking: " + CurrentBookingDetails.EventItemName;

            PopulateTextFields();
            _eId = (int)Globals.UserToken.EmployeeID;

            if (readOnly) { (Content as Panel).MakeReadOnly(BtnCancel); }
        }
        /// <summary>
        /// Pat Banks
        /// Created: 2015/02/2015
        /// Displays information for the selected guest's invoice
        /// </summary>
        /// <param name="selectedGuest">Selected guest to retrieve</param>
        /// <exception cref="ArgumentNullException"><see cref="DataGridContextMenuResult"/> is null. </exception>
        /// <exception cref="ArgumentException"><see cref="DataGridContextMenuResult"/> is not an <see cref="T:System.Enum" />. </exception>
        /// <exception cref="InvalidOperationException">The item to add already has a different logical parent. </exception>
        /// <exception cref="InvalidOperationException">The collection is in ItemsSource mode.</exception>
        /// <exception cref="WanderingTurtleException" />
        public ViewInvoice(InvoiceDetails selectedGuest)
        {
            InitializeComponent();

            //fills the guest data
            RefreshGuestInformation(selectedGuest.HotelGuestID);

            //fills the list view
            RefreshBookingList();

            Title = "Viewing Guest: " + CurrentInvoice.GetFullName;
            LvGuestBookings.SetContextMenu();
        }
        /// <summary>
        /// Pat Banks
        /// Created: 2015/03/03
        /// Creates a connection with database and
        /// calls the stored procedure spSelectAllInvoices
        /// that querys the database for a list of all active invoices
        /// </summary>
        /// <remarks>
        /// Pat Banks
        /// Updated: 2015/03/19
        /// Made a generic accessor by moving if active test to InvoiceManager
        /// </remarks>
        /// <returns>List of InvoiceDetails</returns>
        public static List<InvoiceDetails> GetAllInvoicesList()
        {
            //create list of InvoiceDetail Objects to store the invoice information
            var guestList = new List<InvoiceDetails>();
            var conn = DatabaseConnection.GetDatabaseConnection();
            string query = "spSelectAllInvoices";

            SqlCommand command = new SqlCommand(query, conn);
            command.CommandType = CommandType.StoredProcedure;

            //connect to db and retrieve information
            try
            {
                conn.Open();
                SqlDataReader reader = command.ExecuteReader();

                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        var details = new InvoiceDetails();

                        details.InvoiceID = reader.GetInt32(0);
                        details.HotelGuestID = reader.GetInt32(1);
                        details.DateOpened = reader.GetDateTime(2);
                        if (!reader.IsDBNull(3)) details.DateClosed = reader.GetDateTime(3);
                        if (!reader.IsDBNull(4)) details.TotalPaid = reader.GetDecimal(4);
                        details.Active = reader.GetBoolean(5);
                        details.GuestLastName = reader.GetValue(6).ToString();
                        details.GuestFirstName = reader.GetValue(7).ToString();
                        details.GuestRoomNum = reader.GetValue(8).ToString();

                        guestList.Add(details);
                    }
                }
                else
                {
                    throw new ApplicationException("No invoices found.");
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                conn.Close();
            }
            return guestList;
        }
        /// <summary>
        /// Pat Banks
        /// Created: 2015/02/25
        /// Creates a connection with database and
        /// calls the stored procedure spSelectInvoiceByGuest
        /// that querys the database for a guest's invoice information
        /// </summary>
        /// <param name="guestID">Hotel Guest ID</param>
        /// <returns>Invoice information for the guest</returns>
        public static InvoiceDetails GetInvoiceByGuest(int guestID)
        {
            //create invoice object to store the invoice information
            InvoiceDetails guestInvoice = new InvoiceDetails();

            var conn = DatabaseConnection.GetDatabaseConnection();
            string query = "spSelectInvoiceByGuest";

            SqlCommand command = new SqlCommand(query, conn);
            command.CommandType = CommandType.StoredProcedure;

            command.Parameters.AddWithValue("@guestID", guestID);

            //connect to db and retrieve information
            try
            {
                conn.Open();
                SqlDataReader reader = command.ExecuteReader();

                if (reader.HasRows)
                {
                    reader.Read();
                    guestInvoice.InvoiceID = reader.GetInt32(0);
                    guestInvoice.HotelGuestID = reader.GetInt32(1);
                    guestInvoice.DateOpened = reader.GetDateTime(2);
                    guestInvoice.Active = reader.GetBoolean(3);
                    if (!reader.IsDBNull(4)) guestInvoice.DateClosed = reader.GetDateTime(4);
                    if (!reader.IsDBNull(5)) guestInvoice.TotalPaid = reader.GetDecimal(5);
                    guestInvoice.GuestLastName = reader.GetValue(6).ToString();
                    guestInvoice.GuestFirstName = reader.GetValue(7).ToString();
                    guestInvoice.GuestRoomNum = reader.GetValue(8).ToString();
                }
                else
                {
                    throw new ApplicationException("Customer does not have an open invoice.");
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                conn.Close();
            }
            return guestInvoice;
        }
        /// <summary>
        /// Pat Banks
        /// Created: 2015/03/03
        /// Calls the InvoiceManager method that retrieves the guest's invoice information
        /// and stores the information in invoiceToView
        /// </summary>
        /// <param name="selectedHotelGuestId">selected guest's id</param>
        private void RefreshGuestInformation(int selectedHotelGuestId)
        {
            try
            {
                //object to store guest's information
                CurrentInvoice = _invoiceManager.RetrieveInvoiceByGuest(selectedHotelGuestId);

                LblGuestNameLookup.Content = CurrentInvoice.GetFullName;
                LblCheckInDate.Content = CurrentInvoice.DateOpened.ToString(CultureInfo.InvariantCulture);
                LblRoomNum.Content = CurrentInvoice.GuestRoomNum;
            }
            catch (Exception ex)
            {
                throw new WanderingTurtleException(this, ex, "Unable to retrieve guest information from the database.");
            }
        }
 /// Pat Banks
 /// Created: 2015/03/09
 /// Checks if a booking is in the future and has tickets booked
 /// If fails, then guest cannot checkout
 /// <remarks>
 /// Pat Banks
 /// Updated: 2015/03/19
 /// Moved logic to Business Logic Layer
 /// </remarks>
 public ResultsArchive CheckToArchiveInvoice(InvoiceDetails invoiceToArchive, List<BookingDetails> bookingsToArchive)
 {
     return bookingsToArchive.Any(b => b.StartDate > DateTime.Now.AddHours(6) && b.Quantity > 0) ? ResultsArchive.CannotArchive : ResultsArchive.OkToArchive;
 }
 /// <summary>
 /// Miguel Santana
 /// Created:  2015/02/01
 /// Opens UI for hotel guest operations
 /// </summary>
 /// <param name="selectedItem"></param>
 private void OpenHotelGuest(InvoiceDetails selectedItem = null)
 {
     try
     {
         if (selectedItem == null)
         {
             if (new AddEditHotelGuest().ShowDialog() == false) return;
             RefreshGuestList();
         }
         else
         {
             if (new ViewInvoice(selectedItem).ShowDialog() == false) return;
             RefreshGuestList();
         }
     }
     catch (Exception ex)
     {
         throw new WanderingTurtleException(this, ex);
     }
 }