Esempio n. 1
0
        private void btnSearch_Click(object sender, RoutedEventArgs e)
        {
            //grab the room json file to gather the quantity and price of the room
            try
            {
                string strRoomPath = @"..\..\..\Data Files\Rooms.json";
                string strJsonData = File.ReadAllText(strRoomPath);
                lstRoom = JsonConvert.DeserializeObject <List <RoomType> >(strJsonData);
            }
            catch
            {
                MessageBox.Show("An error occured with fetching the room information. Please try again later.");
                return;
            }


            int intSelectedIndex = cmbRoomType.SelectedIndex;

            if (cmbRoomType.SelectedIndex != 0)
            {
                //get the combo-box item content into a string
                string strRoomLookup = cmbRoomType.Items[intSelectedIndex].ToString();
                int    intRoomLookup = strRoomLookup.IndexOf(':');
                strRoomLookup   = strRoomLookup.Substring(intRoomLookup + 1).Trim();
                rmtSelectedRoom = lstRoom.Find(r => r.Type == strRoomLookup);
            }
            else
            {
            }

            //get the room from the list that matches strRoomLookup

            double dblPrice    = rmtSelectedRoom.Price;
            int    intQuantity = rmtSelectedRoom.Quantity;


            int intNumOfRoom;

            if (!Int32.TryParse(txbNumOfRoom.Text, out intNumOfRoom))
            {
                MessageBox.Show("Please enter a whole number as the number of rooms.");
                return;
            }
            if (intNumOfRoom <= 0 && intNumOfRoom < intQuantity)
            {
                MessageBox.Show("The room cannot be negative or zero.");
                return;
            }
            if (dtpCheckIn.SelectedDate == null)
            {
                MessageBox.Show("Must select a check-in date.");
                return;
            }
            if (dtpCheckIn.SelectedDate < DateTime.Now)
            {
                MessageBox.Show("Check-in date must not in the past.");
                return;
            }

            if (dtpCheckOut.SelectedDate == null)
            {
                MessageBox.Show("Must select a check-out date.");
                return;
            }
            if (dtpCheckIn.SelectedDate > dtpCheckOut.SelectedDate)
            {
                MessageBox.Show("The check-out date must be later than the check-in date.");
                return;
            }
            if (dtpCheckOut.SelectedDate < DateTime.Now)
            {
                MessageBox.Show("Check-out date must not in the past.");
                return;
            }

            btnContinue.Visibility = Visibility.Visible;
            btnNRBack.Visibility   = Visibility.Visible;
            txbQuote.Visibility    = Visibility.Visible;
            lblQuote.Visibility    = Visibility.Visible;

            intNumOfRoom = Convert.ToInt32(txbNumOfRoom.Text);
            string strroomRate = cmbRoomType.Text;
            double dblsubtotal, dbltax;

            dblsubtotal = 0;
            dbltax      = dblsubtotal * 0.07;


            //switch (roomrate)
            //{
            //    case "one king":
            //        roomrate = "$179";
            //        break;
            //    case "one king deluxe":
            //        roomrate = "$189";
            //        break;
            //    case "two queens":
            //        roomrate = "$189";
            //        break;
            //    case "two queen deluxe":
            //        roomrate = "$214";
            //        break;
            //}



            TimeSpan tspDiff = (Convert.ToDateTime(dtpCheckOut.SelectedDate) - Convert.ToDateTime(dtpCheckIn.SelectedDate));



            int intConveniceFee = intNumberOfDays * 10;

            txbQuote.Text = "Number of Nights:".PadRight(10) + intNumOfDay + Environment.NewLine +
                            "Rate Per Night:".PadRight(10) + strroomRate + Environment.NewLine +
                            "Subtotal:" + dblsubtotal.ToString() + Environment.NewLine +
                            "Tax:" + dbltax.ToString() + Environment.NewLine +
                            "Convenience Fee:" + intConvenienceFee.ToString() + Environment.NewLine +
                            "Total:";
        }
        //public RoomManagement(int myNum)
        //{
        //    InitializeComponent();

        //    MyNumber = myNum;

        //    //Take Get room data from json file to use later in the document
        //    try
        //    {
        //        strJsonData = File.ReadAllText(strFilePath);
        //        lstRoom = JsonConvert.DeserializeObject<List<RoomType>>(strJsonData);

        //    }
        //    catch (Exception ex)
        //    {
        //        MessageBox.Show("Unable to find file. Please try again later.");
        //    }
        //}

        //public void DoSomething()
        //{
        //    //fdsdsfs
        //}

        private void btnRMSave_Click(object sender, RoutedEventArgs e)
        {
            #region Validation
            //make sure that a room is selected
            if (cbxRoomType.SelectedIndex == 0)
            {
                MessageBox.Show("Please Select a Room, before saving changes.");

                return;
            }
            //make sure that the room inputs are not null and valid
            else if (!Int32.TryParse(txtQuantityInput.Text, out intQuantity))
            {
                MessageBox.Show("Please input a Number for Quantity.");
                return;
            }
            else if (!Double.TryParse(txtPriceInput.Text, out dblPrice))
            {
                MessageBox.Show("Please input a Number for Price.");
                return;
            }
            else if (dblPrice < 0 || intQuantity < 0)
            {
                MessageBox.Show("Please input Positive Numbers for Price and Quantity.");
                return;
            }
            #endregion
            //create variables
            int      intSelectedIndex = cbxRoomType.SelectedIndex;
            RoomType rmtSavedRoom     = new RoomType(rmtSelectedRoom.Type, intQuantity, dblPrice);


            //MessageBox to Confirm that changes are wanted
            MessageBoxResult mbrSaveConfirm = MessageBox.Show("Are You Sure You Would Like to Make the Following Changes?" + Environment.NewLine + Environment.NewLine + rmtSavedRoom.ToString(), "", MessageBoxButton.YesNo);

            if (mbrSaveConfirm == MessageBoxResult.No)
            {
                return;
            }
            else
            //load information into json document for external save
            {
                //get the combo-box item content into a string
                string strRoomLookup = cbxRoomType.Items[intSelectedIndex].ToString();
                int    intRoomLookup = strRoomLookup.IndexOf(':');
                strRoomLookup = strRoomLookup.Substring(intRoomLookup + 1).Trim();

                //Get the roomindex of the masterdata room that was changed, delete it, and add new room info

                int intRoomIndex = lstRoom.IndexOf(rmtSelectedRoom);
                lstRoom.RemoveAt(intRoomIndex);
                lstRoom.Add(rmtSavedRoom);

                //Overwrite  the json file with the new list
                try
                {
                    string strJsonData = JsonConvert.SerializeObject(lstRoom);
                    File.WriteAllText(strFilePath, strJsonData);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Unable to Save Changes. Please Try Again Later.");
                }
            }

            //Move to Confirmation Page and close this window
            RMConfirmation RMConfirmWindow = new RMConfirmation();
            RMConfirmWindow.Show();
            this.Close();
        }
Esempio n. 3
0
        private void cbxRoomType_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //Clear out the outputs
            try
            {
                //lblPriceLabel.Visibility = 0;

                //lblRoomType.Content = "";
                //txtPriceInput.Text = "";
                //txtQuantityInput.Text = "";
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error occured");
            }

            #region Change Labels with Room Selection

            //Make so that when user dropdowns,the labels change to match the dropdown

            int intSelectedIndex;
            bolSelectedIndex = true;

            intSelectedIndex = cbxRoomType.SelectedIndex;

            //Use switch statement to determine which RoomType is selected in the combobox
            switch (intSelectedIndex)
            {
            case 1:
            { rmtSelectedRoom = rmtKing;

              break; }

            case 2:
            { rmtSelectedRoom = rmtKingDeluxe;
              break; }

            case 3:
            { rmtSelectedRoom = rmtQueen;
              break; }

            case 4:
            { rmtSelectedRoom = rmtQueenDeluxe;
              break; }

            case 5:
            { rmtSelectedRoom = rmtKingSuite;
              break; }

            case 6:
            { rmtSelectedRoom = rmtPresidential;
              break; }

            default:
            { bolSelectedIndex = false;
              break; }
            }

            #endregion


            //Display the Room Information based on the selected room if room is selected; hide if no room selected
            if (bolSelectedIndex)
            {
                lblRoomType.Content = rmtSelectedRoom.Type;

                txtQuantityInput.Text = rmtSelectedRoom.Quantity.ToString();

                txtPriceInput.Text = rmtSelectedRoom.Price.ToString();
            }
        }
        private void cbxRoomType_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            #region Change Labels with Room Selection

            //Make so that when user dropdowns,the labels change to match the dropdown

            int intSelectedIndex;
            bolSelectedIndex = true;

            intSelectedIndex = cbxRoomType.SelectedIndex;



            if (cbxRoomType.SelectedIndex != 0)
            {
                //get the combo-box item content into a string
                string strRoomLookup = cbxRoomType.Items[intSelectedIndex].ToString();
                int    intRoomLookup = strRoomLookup.IndexOf(':');
                strRoomLookup = strRoomLookup.Substring(intRoomLookup + 1).Trim();

                //get the room from the list that matches strRoomLookup
                rmtSelectedRoom = lstRoom.Find(r => r.Type == strRoomLookup);
            }
            else
            {
                bolSelectedIndex = false;
            }



            #endregion



            //Display the Room Information based on the selected room if room is selected; hide if no room selected
            //Hide and show save button based on selected index


            if (bolSelectedIndex)
            {
                lblRoomType.Content = rmtSelectedRoom.Type;

                txtQuantityInput.Text = rmtSelectedRoom.Quantity.ToString();

                txtPriceInput.Text = rmtSelectedRoom.Price.ToString();

                btnRMSave.Visibility = Visibility.Visible;
            }
            else
            {
                try
                {
                    lblRoomType.Content   = " ";
                    txtQuantityInput.Text = " ";
                    txtPriceInput.Text    = " ";
                    btnRMSave.Visibility  = Visibility.Hidden;
                }
                //When first entering window have a catch for the null exception
                catch
                { }
            }
        }