Exemple #1
0
        //Method deletes a Customer Given the reference number
        private void btn_removeCostumer_Click(object sender, RoutedEventArgs e)
        {
            int refNumber;

            if (!Int32.TryParse(txt_costumerReferenceNumber.Text, out refNumber))
            {
                MessageBox.Show("Please input a valid reference number");
            }
            else
            {
                Costumer aCostumer = facade.GetCostumer(refNumber);
                if (aCostumer != null)
                {
                    facade.RemoveCostumer(refNumber);
                    facade.SaveToCSV();
                    MessageBox.Show("Costumer Successfully removed");
                }
                else
                {
                    MessageBox.Show("Costumer with the reference number entered does not exist.");
                }
            }
            txt_costumerReferenceNumber.Text = "";
            DisableCostumerMenuOptions();
        }
 //Method validates user input for custumer name and address fields in order to create new customers
 private void btn_addNewCostumerDone_Click(object sender, RoutedEventArgs e)
 {
     //Check if name field is not empty
     if (txt_addNewCostumerName.Text == "")
     {
         MessageBox.Show("Please enter a valid customer name!");
     }
     //Check if address field is not empty
     else if (txt_addNewCostumerAddress.Text == "")
     {
         MessageBox.Show("Please enter a valid customer address!");
     }
     else
     {
         //Create new customer object
         Costumer aCostumer = new Costumer();
         // try to assign values to the new customer object
         try
         {
             aCostumer.Name    = txt_addNewCostumerName.Text;      // (Try to) assign costumer name from user input
             aCostumer.Address = txt_addNewCostumerAddress.Text;   // (Try to) assign costumer address from user input
             facade.AddCostumer(aCostumer);                        //use the facade class to add new customer to customer list
             facade.SaveToCSV();                                   //saves it to CSV file
             facade.SetCurrentCostumer(aCostumer.ReferenceNumber); //Sets the current custumer in the facade class to the customer just created
             MessageBox.Show("New Costumer has been added. Costumer reference number: " + aCostumer.ReferenceNumber);
             this.Close();
         }
         // If assignement of name or address fails, catch and show exception message
         catch (Exception excep)
         {
             MessageBox.Show(excep.Message);
         }
     }
 }
Exemple #3
0
        // Finds a Costumer by getting a valid reference number input from the user (Does some validation of user input)
        private void btn_findCostumer_Click(object sender, RoutedEventArgs e)
        {
            int refNumber;

            if (!Int32.TryParse(txt_costumerReferenceNumber.Text, out refNumber)) //if refnumber input is not an int
            {
                MessageBox.Show("Please input a valid reference number");
                txt_costumerReferenceNumber.Text = "";
            }
            else // if reference number is a valid int
            {
                Costumer aCostumer = facade.GetCostumer(refNumber);
                if (aCostumer != null) //if costumer was found
                {
                    cmbBox_Bookings.Items.Clear();
                    cmbBox_Bookings.IsEnabled = false;
                    facade.SetCurrentCostumer(refNumber);
                    EnableCostumerMenuOptions();
                    lbl_costumerNameOutput.Content    = aCostumer.Name;
                    lbl_costumerAddressOutput.Content = aCostumer.Address;

                    // Add all the booking reference numbers to the booking menu comboBox
                    foreach (Booking booking in aCostumer.CostumerBookings)
                    {
                        cmbBox_Bookings.Items.Add(booking.ReferenceNumber);
                        cmbBox_Bookings.IsEnabled = true;
                    }
                }
                else
                {
                    MessageBox.Show("Costumer with the reference number entered does not exist.");
                    DisableCostumerMenuOptions();
                }
            }
        }
Exemple #4
0
 //Add a new guest to an existing booking
 private void btn_addGuest_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         Costumer aCostumer = facade.CurrentCostumer;
         Booking  aBooking  = facade.CurrentBooking;
         Guest    aGuest    = new Guest();
         aGuest.Name           = txt_guestName.Text;
         aGuest.PassportNumber = txt_guestPassportNumber.Text;
         int guestAge;
         if (Int32.TryParse(txt_guestAge.Text, out guestAge))
         {
             aGuest.Age = Int32.Parse(txt_guestAge.Text);
             aBooking.Guests.Add(aGuest);
             cmb_bookingGuests.Items.Add(aGuest.Name.ToString());
             MessageBox.Show("New guest was successfully added!");
             txt_guestName.Text           = "";
             txt_guestPassportNumber.Text = "";
             txt_guestAge.Text            = "";
         }
         else
         {
             MessageBox.Show("Please insert a valid Guest age!");
         }
     }
     catch (Exception excep)
     {
         MessageBox.Show(excep.Message);
     }
 }
Exemple #5
0
        // Loads details of the selected guest in the combo box
        private void cmb_bookingGuests_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Costumer aCostumer = facade.CurrentCostumer;
            Guest    aGuest    = null;

            if (cmb_bookingGuests.SelectedItem != null)
            {
                Booking aBooking = facade.CurrentBooking;
                if (cmb_bookingGuests.SelectedIndex < aBooking.Guests.Count())
                {
                    aGuest = facade.GetGuest(cmb_bookingGuests.SelectedIndex);
                }
            }

            if (aGuest != null)
            {
                txt_guestName.Text           = aGuest.Name;
                txt_guestPassportNumber.Text = aGuest.PassportNumber;
                txt_guestAge.Text            = aGuest.Age.ToString();
                btn_deleteGuest.IsEnabled    = true;
                btn_amendGuest.IsEnabled     = true;
            }
            else
            {
                btn_deleteGuest.IsEnabled = false;
                btn_amendGuest.IsEnabled  = false;
            }
        }
Exemple #6
0
        //Method writes (appends) a costumer to the costumer.csv file
        public void WriteCostumer(Costumer aCostumer)
        {
            string line = aCostumer.ReferenceNumber.ToString() + ","
                          + aCostumer.Name.ToString() + ","
                          + aCostumer.Address.ToString();
            string        filepath = csvCostumerPath;
            StringBuilder sb       = new StringBuilder();

            sb.AppendLine(line);
            System.IO.File.AppendAllText(filepath, sb.ToString());
        }
Exemple #7
0
        // Loads the booking selected in the combobox and loads its details to main window
        private void btn_searchBooking_Click(object sender, RoutedEventArgs e)
        {
            Costumer aCostumer = facade.CurrentCostumer;
            Booking  aBooking  = null;

            if (cmbBox_Bookings.SelectedItem != null)
            {
                aBooking = facade.GetBooking(Int32.Parse(cmbBox_Bookings.SelectedItem.ToString()));
            }

            if (aBooking == null)
            {
                MessageBox.Show("Booking does not exist");
            }
            else
            {
                facade.SetCurrentBooking(aBooking.ReferenceNumber);
                ClearBookingMenu();
                txt_bookingReferenceNumber.Text     = aBooking.ReferenceNumber.ToString();
                txt_bookingArrivalDate.Text         = aBooking.ArrivalDate.ToString(aBooking.DatePattern);
                txt_bookingDepartureDate.Text       = aBooking.DepartureDate.ToString(aBooking.DatePattern);
                txt_bookingDietaryRequirements.Text = aBooking.DietaryRequirements.ToString();
                btn_removeBooking.IsEnabled         = true;
                btn_addGuest.IsEnabled    = true;
                btn_addExtra.IsEnabled    = true;
                btn_saveChanges.IsEnabled = true;
                btn_invoice.IsEnabled     = true;
                foreach (Guest aGuest in aBooking.Guests)
                {
                    cmb_bookingGuests.Items.Add(aGuest.Name);
                }
                cmb_bookingGuests.IsEnabled = true;

                if (aBooking.Extras.Count > 0)
                {
                    cmb_bookingExtras.IsEnabled = true;
                    foreach (Extra anExtra in aBooking.Extras)
                    {
                        if (anExtra.GetType().ToString() == "HollydayBooking.Breakfast")
                        {
                            cmb_bookingExtras.Items.Add("Breakfast");
                        }
                        else if (anExtra.GetType().ToString() == "HollydayBooking.EveningMeal")
                        {
                            cmb_bookingExtras.Items.Add("Evening meal");
                        }
                        else if (anExtra.GetType().ToString() == "HollydayBooking.CarHire")
                        {
                            cmb_bookingExtras.Items.Add("Car hire");
                        }
                    }
                }
            }
        }
Exemple #8
0
        // Reads from booking.csv file to populate the booking list (of each customer) with all its bookings
        public void GetBookings(Costumer aCostumer)
        {
            StreamReader reader = new StreamReader(File.OpenRead(csvBookingPath));

            while (!reader.EndOfStream)
            {
                var line   = reader.ReadLine();
                var values = line.Split(',');
                if (Int32.Parse(values[0]) == aCostumer.ReferenceNumber)                                                                     //if the booking belongs to the custumer (aCostumer)
                {
                    Booking aBooking = new Booking(Int32.Parse(values[1]), DateTime.Parse(values[2]), DateTime.Parse(values[3]), values[4]); //Create a new booking object an set its values from the CSV record
                    aCostumer.AddBooking(aBooking);                                                                                          //Add new booking to the Custumer listofbookings
                }
            }
            reader.Dispose();
        }
Exemple #9
0
        // Loads all the customers from the CSV into a list of customers (ListOfCostumer Singleton Class)
        public void GetCostumers()
        {
            // Create a streamReader object to access the file
            StreamReader    reader       = new StreamReader(File.OpenRead(csvCostumerPath));
            ListOfCostumers costumerList = ListOfCostumers.Instance();//Get an instance of the ListOfCustomer (Singleton) class

            // Create a streamReader object to access the file
            while (!reader.EndOfStream)
            {
                var      line      = reader.ReadLine();
                var      values    = line.Split(',');
                Costumer aCostumer = new Costumer(Int32.Parse(values[0]), values[1], values[2]); //Create a new customer and sets its properties to the values on the csv
                costumerList.AddCostumer(aCostumer);                                             //adds the customer to the custumer list (in the ListOfCustumers in the singleton class)
            }
            reader.Dispose();
        }
Exemple #10
0
        // Opens a new window and prints a detailed invoice for the selected booking
        private void btn_invoice_Click(object sender, RoutedEventArgs e)
        {
            Invoice  inv       = new Invoice();
            Costumer aCostumer = facade.CurrentCostumer;
            Booking  aBooking  = facade.CurrentBooking;

            inv.lbl_invoiceDateOutput.Content           = DateTime.Now.ToString("yyyy-MM-dd");
            inv.lbl_invoiceBookingIDOutput.Content      = aBooking.ReferenceNumber;
            inv.lbl_invoiceNumberOfGuestsOutput.Content = aBooking.Guests.Count();
            inv.lbl_customerIDOutput.Content            = aCostumer.ReferenceNumber;
            inv.lbl_customerNameOutput.Content          = aCostumer.Name;
            inv.lbl_customerAddressOutput.Content       = aCostumer.Address;
            foreach (Guest aGuest in aBooking.Guests)
            {
                if (aGuest.Age <= 18)
                {
                    inv.lbl_bookingDescription.Content += "Guest" + (aBooking.Guests.IndexOf(aGuest) + 1) + ": £30.00 (child rate) x " + (aBooking.DepartureDate - aBooking.ArrivalDate).TotalDays + " nights\n";
                    inv.lbl_bookingAmount.Content      += 30.00 * ((aBooking.DepartureDate - aBooking.ArrivalDate).TotalDays) + "£\n";
                }
                else
                {
                    inv.lbl_bookingDescription.Content += "Guest" + (aBooking.Guests.IndexOf(aGuest) + 1) + ": £50.00 (adult rate) x " + (aBooking.DepartureDate - aBooking.ArrivalDate).TotalDays + " nights\n";
                    inv.lbl_bookingAmount.Content      += 50.00 * ((aBooking.DepartureDate - aBooking.ArrivalDate).TotalDays) + "£\n";
                }
            }
            foreach (Extra anExtra in aBooking.Extras)
            {
                if (anExtra.GetType().ToString() == "HollydayBooking.Breakfast")
                {
                    inv.lbl_bookingDescription.Content += "Breakfast: " + "£5.00 x " + aBooking.Guests.Count() + " guests x " + (aBooking.DepartureDate - aBooking.ArrivalDate).TotalDays + " nights\n";
                    inv.lbl_bookingAmount.Content      += anExtra.Price * aBooking.Guests.Count() * ((aBooking.DepartureDate - aBooking.ArrivalDate).TotalDays) + "£\n";
                }
                else if (anExtra.GetType().ToString() == "HollydayBooking.EveningMeal")
                {
                    inv.lbl_bookingDescription.Content += "Evening Meal: " + "£15.00 x " + aBooking.Guests.Count() + " guests x " + (aBooking.DepartureDate - aBooking.ArrivalDate).TotalDays + " nights\n";
                    inv.lbl_bookingAmount.Content      += anExtra.Price * aBooking.Guests.Count() * ((aBooking.DepartureDate - aBooking.ArrivalDate).TotalDays) + "£\n";
                }
                else if (anExtra.GetType().ToString() == "HollydayBooking.CarHire")
                {
                    CarHire aCarHire = (CarHire)anExtra;
                    inv.lbl_bookingDescription.Content += "Car Hire: " + "£50.00 x " + (aCarHire.ReturnDate - aCarHire.StartDate).TotalDays + " days\n";
                    inv.lbl_bookingAmount.Content      += aCarHire.Price * ((aCarHire.ReturnDate - aCarHire.StartDate).TotalDays) + "£\n";
                }
            }
            inv.lbl_invoiceTotalAmountOutput.Content = aBooking.GetCost() + "£";
            inv.ShowDialog();
        }
        // Updates the details of an existing costumer
        private void btn_amendCostumerUpdate_Click(object sender, RoutedEventArgs e)
        {
            Costumer aCostumer = facade.CurrentCostumer; //Get Current costumer from the facade

            // Try to re-assing the values of the customer details from the user input
            try
            {
                aCostumer.Name    = txt_amendCostumerName.Text;                 // (Try to) re-assign costumer name from user input
                aCostumer.Address = txt_amendCostumerAddress.Text;              // (Try to) re-assign costumer address from user input
                facade.SaveToCSV();                                             // Save Customer Details (amended) to CSV file
                MessageBox.Show("Costumer details were successfully updated!"); //Insforms the user the customer detaisl were successfully updated
                MainWindow mainWin = Owner as MainWindow;                       // Get a reference of main window to access its properties
                mainWin.txt_costumerReferenceNumber.Text  = "";                 //clear textbox in main window
                mainWin.lbl_costumerNameOutput.Content    = "";                 // clear textbox in main window
                mainWin.lbl_costumerAddressOutput.Content = "";                 //clear textbox in main window
                this.Close();                                                   //close this window
            }
            // If re-assignement of name or address fails, catch and show exception message
            catch (Exception excep)
            {
                MessageBox.Show(excep.Message);
            }
        }
Exemple #12
0
 //Adds a new custumer to the custumer list given a costumer object
 public void AddCostumer(Costumer aCostumer)
 {
     costumerList.AddCostumer(aCostumer);
 }
Exemple #13
0
 // Set the current custumer given its reference number (when selected by the user)
 public void SetCurrentCostumer(int refNumber)
 {
     currentCostumer = costumerList.FindCostumer(refNumber);
 }
 // Remove a costumer from a list of costumer given the costumer object
 public void RemoveCostumer(Costumer costumer)
 {
     costumerList.Remove(costumer);
 }
 //Method adds a costumer object to the list of costumers
 public void AddCostumer(Costumer costumer)
 {
     this.costumerList.Add(costumer);
 }
Exemple #16
0
        private void btn_addExtra_Click(object sender, RoutedEventArgs e)
        {
            MainWindow mainWin   = Owner as MainWindow;    //Create a reference to the main window (in order to have access to its properties)
            Costumer   aCostumer = facade.CurrentCostumer; //Get the currentCostumer object
            Booking    aBooking  = facade.CurrentBooking;  //Get the currentBooking object

            //If Brekfast extra is selected...
            if (cmb_extraTypes.SelectedItem.ToString() == "Breakfast")
            {
                Breakfast aBreakfast = new Breakfast();                                      //Create new Breakfast object
                aBooking.Extras.Add(aBreakfast);                                             //Add Breakfast Object to the booking list of extras
                aBooking.DietaryRequirements = txt_dietaryRequirements.Text;                 //Set the booking dietary requirements from user input
                mainWin.txt_bookingDietaryRequirements.Text = aBooking.DietaryRequirements;  //update the dietary requirement of booking on main window textbox
                txt_dietaryRequirements.Text        = "";                                    //clear the textbox
                mainWin.cmb_bookingExtras.IsEnabled = true;                                  //enable comboBox with the extras on main window
                mainWin.cmb_bookingExtras.Items.Add(cmb_extraTypes.SelectedItem.ToString()); //Add extra Type (Breakfast) to the extra comboBox in main window
                MessageBox.Show("Breakfast has been successfully added");                    //Prompt user that Breakfast extra has been created
                this.Close();
            }
            //If Evening Meal extra is selected...
            else if (cmb_extraTypes.SelectedItem.ToString() == "Evening meal")
            {
                EveningMeal anEveningMeal = new EveningMeal();                               //Create new Evening Meal object
                aBooking.Extras.Add(anEveningMeal);                                          //Add Evening Meal Object to the booking list of extras
                aBooking.DietaryRequirements = txt_dietaryRequirements.Text;                 //Set the booking dietary requirements from user input
                mainWin.txt_bookingDietaryRequirements.Text = aBooking.DietaryRequirements;  //update the dietary requirement of booking on main window textbox
                txt_dietaryRequirements.Text        = "";                                    //clear the textbox
                mainWin.cmb_bookingExtras.IsEnabled = true;                                  //enable comboBox with the extras on main window
                mainWin.cmb_bookingExtras.Items.Add(cmb_extraTypes.SelectedItem.ToString()); //Add extra Type (Evening Meal) to the extra comboBox in main window
                MessageBox.Show("Evening Meal has been successfully added");                 //Prompt user that Evening Meal extra has been created
                this.Close();
            }
            //If Car Hire extra is selected...
            else if (cmb_extraTypes.SelectedItem.ToString() == "Car hire")
            {
                DateTime arrivalDate;                                           //local variable to hold a DateTime value (Car Hire pick-up date)
                DateTime departureDate;                                         //local variable to hold a DateTime value (Car Hire return Date)
                if (DateTime.TryParse(txt_startDate.Text, out arrivalDate))     //Check if pick-up date input is a valid DateTime value
                {
                    if (DateTime.TryParse(txt_endDate.Text, out departureDate)) //Check if return date input is a valid DateTime value
                    {
                        // Try to assign input values to CarHire object
                        try
                        {
                            CarHire aCarHire = new CarHire();                                            //Create new Car Hire object
                            aCarHire.DriverName = txt_driverName.Text;                                   // (try to) Set driver name from user input
                            aCarHire.StartDate  = arrivalDate;                                           // (try to) Set pick-up date from user input
                            aCarHire.ReturnDate = departureDate;                                         // (try to) Set return date from user input
                            aBooking.Extras.Add(aCarHire);                                               //Add Car Hire Object to the booking list of extras
                            txt_driverName.Text = "";                                                    //clear the textbox
                            txt_startDate.Text  = "";                                                    //clear the textbox
                            txt_endDate.Text    = "";                                                    //clear the textbox
                            mainWin.cmb_bookingExtras.IsEnabled = true;                                  //enable comboBox with the extras on main window
                            mainWin.cmb_bookingExtras.Items.Add(cmb_extraTypes.SelectedItem.ToString()); //Add extra Type (Car Hire) to the extra comboBox in main window
                            MessageBox.Show("Car hire has been successfully added");                     //Prompt user that Car Hire extra has been created
                            this.Close();
                        }
                        // Catch exception messages if the assignemt of CarHire properties fail
                        catch (Exception excep)
                        {
                            MessageBox.Show(excep.Message);//Print message in Message Box
                        }
                    }
                    else
                    {
                        MessageBox.Show("Please enter a valid return date date. (YYYY-MM-DD)"); //Promp user to input a valid DateTime showing the correct format
                        txt_endDate.Text = "";                                                  //clear the textbox
                    }
                }
                else
                {
                    MessageBox.Show("Please enter a valid pick-up date. (YYYY-MM-DD)"); //Promp user to input a valid DateTime showing the correct format
                    txt_startDate.Text = "";                                            //clear the textbox
                }
            }
        }