Beispiel #1
0
        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

            //Move to Confirmation Page and close this window
            RMConfirmation RMConfirmWindow = new RMConfirmation();
            RMConfirmWindow.Show();
            this.Close();
        }
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.winRMConfirmation = ((Hotel_Reservations.RMConfirmation)(target));
                return;

            case 2:
                this.recBackground = ((System.Windows.Shapes.Rectangle)(target));
                return;

            case 3:
                this.btnRMConfirm = ((System.Windows.Controls.Button)(target));

            #line 25 "..\..\RMConfirmation.xaml"
                this.btnRMConfirm.Click += new System.Windows.RoutedEventHandler(this.btnRMConfirm_Click);

            #line default
            #line hidden
                return;

            case 4:
                this.btnRMEdit = ((System.Windows.Controls.Button)(target));

            #line 26 "..\..\RMConfirmation.xaml"
                this.btnRMEdit.Click += new System.Windows.RoutedEventHandler(this.btnRMEdit_Click);

            #line default
            #line hidden
                return;

            case 5:
                this.lblConfirmationLabel = ((System.Windows.Controls.Label)(target));
                return;

            case 6:
                this.lblRoom = ((System.Windows.Controls.Label)(target));
                return;

            case 7:
                this.lblRoomQuantityLabel = ((System.Windows.Controls.Label)(target));
                return;

            case 8:
                this.lblRoomPriceLabel = ((System.Windows.Controls.Label)(target));
                return;

            case 9:
                this.lblRoomPrice = ((System.Windows.Controls.Label)(target));
                return;

            case 10:
                this.lblRoomQuantity = ((System.Windows.Controls.Label)(target));
                return;
            }
            this._contentLoaded = true;
        }
        //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();
        }