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(); }
//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(); }