// This method is called on SAVE button click. It saves and update the binary files with customer's details. private void btnSaveCust_Click(object sender, RoutedEventArgs e) { try { if (data.CustDict.StoreCustomers.ContainsKey(_custID)) { data.CustDict.StoreCustomers[_custID].Name = txbCustName.Text; data.CustDict.StoreCustomers[_custID].Address = txbCustAddress.Text; } else { Business.Customer newCust = new Business.Customer(_custID, txbCustName.Text, txbCustAddress.Text); data.CustDict.addCustomer(newCust); } } catch (Exception excep) { MessageBox.Show(excep.Message); } data.updateFile(); }
// This method is called on SAVE button click. It saves all the information about the booking, any extras, and guest list and updates the binary file. Appropriate // checks are done to see if data need to be edited or it is a new booking. private void btnSaveBooking_Click(object sender, RoutedEventArgs e) { try { ExtraSelector extraType = new NoExtra(); ExtraSelector breakfast = new Breakfast(); ExtraSelector eveningMeal = new EveningMeal(); ExtraSelector carHire = new CarHire(); if (data.CustDict.StoreCustomers[_custID].DictBookings.ContainsKey(_bookingID)) { if (clrArrival.SelectedDate == null || clrDeparture.SelectedDate == null) { throw new ArgumentException("Please select an Arrival Date and a Departure Date"); } data.CustDict.StoreCustomers[_custID].DictBookings[_bookingID].ArrivalDate = Convert.ToDateTime(clrArrival.SelectedDate); data.CustDict.StoreCustomers[_custID].DictBookings[_bookingID].DepartureDate = Convert.ToDateTime(clrDeparture.SelectedDate); if (data.CustDict.StoreCustomers[_custID].DictBookings[_bookingID].ChaletID == Int32.Parse(tbxChaletID.Text)) { data.CustDict.StoreCustomers[_custID].DictBookings[_bookingID].ChaletID = Int32.Parse(tbxChaletID.Text); } if (!data.CustDict.ChaletsBooked.Contains(Int32.Parse(tbxChaletID.Text))) { data.CustDict.ChaletsBooked.Remove(data.CustDict.StoreCustomers[_custID].DictBookings[_bookingID].ChaletID); data.CustDict.StoreCustomers[_custID].DictBookings[_bookingID].ChaletID = Int32.Parse(tbxChaletID.Text); data.CustDict.ChaletsBooked.Add(Int32.Parse(tbxChaletID.Text)); } else if (data.CustDict.StoreCustomers[_custID].DictBookings[_bookingID].ChaletID != Int32.Parse(tbxChaletID.Text) && data.CustDict.ChaletsBooked.Contains(Int32.Parse(tbxChaletID.Text))) { throw new ArgumentException("Chalet already booked, please choose another chalet."); } if (ckbBreakfast.IsChecked == false && data.CustDict.StoreCustomers[_custID].DictBookings[_bookingID].ExtraDict.ContainsKey("Breakfast")) { data.CustDict.StoreCustomers[_custID].DictBookings[_bookingID].ExtraDict.Remove("Breakfast"); } else if (ckbBreakfast.IsChecked == true && !data.CustDict.StoreCustomers[_custID].DictBookings[_bookingID].ExtraDict.ContainsKey("Breakfast")) { Extra extra = new Extra("Breakfast"); extraType.SetExtra(breakfast); breakfast.ProcessExtra(extra); data.CustDict.StoreCustomers[_custID].DictBookings[_bookingID].addExtra(extra); } if (ckbDinner.IsChecked == false && data.CustDict.StoreCustomers[_custID].DictBookings[_bookingID].ExtraDict.ContainsKey("Evening Meal")) { data.CustDict.StoreCustomers[_custID].DictBookings[_bookingID].ExtraDict.Remove("Evening Meal"); } else if (ckbDinner.IsChecked == true && !data.CustDict.StoreCustomers[_custID].DictBookings[_bookingID].ExtraDict.ContainsKey("Evening Meal")) { Extra extra = new Extra("Evening Meal"); extraType.SetExtra(eveningMeal); eveningMeal.ProcessExtra(extra); data.CustDict.StoreCustomers[_custID].DictBookings[_bookingID].addExtra(extra); } if (ckbCarHire.IsChecked == false && data.CustDict.StoreCustomers[_custID].DictBookings[_bookingID].ExtraDict.ContainsKey("Car Hire")) { data.CustDict.StoreCustomers[_custID].DictBookings[_bookingID].ExtraDict.Remove("Car Hire"); tbxDriver.Text = null; clrStartHire.SelectedDate = null; clrEndHire.SelectedDate = null; } else if (ckbCarHire.IsChecked == true && !data.CustDict.StoreCustomers[_custID].DictBookings[_bookingID].ExtraDict.ContainsKey("Car Hire")) { if (clrStartHire.SelectedDate == null || clrEndHire.SelectedDate == null || tbxDriver.Text == null) { throw new ArgumentException("Please select a start hire date, an end hire date, and a driver name."); } if (clrStartHire.SelectedDate < clrArrival.SelectedDate || clrEndHire.SelectedDate > clrDeparture.SelectedDate) { throw new ArgumentException("Invalid hiring dates. Please, insert dates within your booking period of staying."); } Extra extra = new Extra("Car Hire"); extraType.SetExtra(carHire); carHire.ProcessExtra(extra); extra.DriverName = tbxDriver.Text; extra.StartHire = Convert.ToDateTime(clrStartHire.SelectedDate); extra.EndHire = Convert.ToDateTime(clrEndHire.SelectedDate); data.CustDict.StoreCustomers[_custID].DictBookings[_bookingID].addExtra(extra); } else if (ckbCarHire.IsChecked == true && data.CustDict.StoreCustomers[_custID].DictBookings[_bookingID].ExtraDict.ContainsKey("Car Hire")) { if (clrStartHire.SelectedDate < clrArrival.SelectedDate || clrEndHire.SelectedDate > clrDeparture.SelectedDate) { throw new ArgumentException("Invalid hiring dates. Please, insert dates within your booking period of staying."); } data.CustDict.StoreCustomers[_custID].DictBookings[_bookingID].ExtraDict["Car Hire"].DriverName = tbxDriver.Text; data.CustDict.StoreCustomers[_custID].DictBookings[_bookingID].ExtraDict["Car Hire"].EndHire = Convert.ToDateTime(clrEndHire.SelectedDate); data.CustDict.StoreCustomers[_custID].DictBookings[_bookingID].ExtraDict["Car Hire"].StartHire = Convert.ToDateTime(clrStartHire.SelectedDate); } } else { if (clrArrival.SelectedDate == null || clrDeparture.SelectedDate == null) { throw new ArgumentException("Please selecet an Arrival Date and a Departure Date"); } _newBooking = new Business.Booking(_bookingID, Convert.ToDateTime(clrArrival.SelectedDate), Convert.ToDateTime(clrDeparture.SelectedDate)); foreach (KeyValuePair <string, Guest> guest in _tempGuestDict) { _newBooking.addGuest(guest.Value); } if (ckbBreakfast.IsChecked == true) { Extra extra = new Extra("Breakfast"); extraType.SetExtra(breakfast); breakfast.ProcessExtra(extra); _newBooking.addExtra(extra); } if (ckbDinner.IsChecked == true) { Extra extra = new Extra("Evening Meal"); extraType.SetExtra(eveningMeal); eveningMeal.ProcessExtra(extra); _newBooking.addExtra(extra); } if (ckbCarHire.IsChecked == true) { if (clrStartHire.SelectedDate == null || clrEndHire.SelectedDate == null || tbxDriver.Text == null) { throw new ArgumentException("Please select a start hire date, an end hire date, and a driver name."); } Extra extra = new Extra("Car Hire"); extraType.SetExtra(carHire); carHire.ProcessExtra(extra); extra.DriverName = tbxDriver.Text; extra.StartHire = Convert.ToDateTime(clrStartHire.SelectedDate); extra.EndHire = Convert.ToDateTime(clrEndHire.SelectedDate); _newBooking.addExtra(extra); } data.CustDict.StoreCustomers[_custID].addBooking(_newBooking); if (!data.CustDict.ChaletsBooked.Contains(Int32.Parse(tbxChaletID.Text))) { _newBooking.ChaletID = Int32.Parse(tbxChaletID.Text); data.CustDict.ChaletsBooked.Add(_newBooking.ChaletID); } else { throw new ArgumentException("Chalet already booked, please choose another chalet."); } } data.updateFile(); } catch (Exception excep) { MessageBox.Show(excep.Message); } }