private void createNewRoomButton_Click(object sender, EventArgs e)
        {
            hms    = new HotelManagementSystem();
            hotels = new Dictionary <int, Hotel>();
            Room room;

            string employeeItem = managementHotelListBox.SelectedItem.ToString();
            int    employeeId   = Convert.ToInt32(employeeItem.Substring(0, employeeItem.IndexOf(' ')));
            int    HotelId      = employeeId;
            string type         = this.roomTypeTextbox.Text;
            string RoomPrice    = roomPriceTextbox.Text;
            float  price        = (float)Convert.ToDouble(RoomPrice);


            room = new Room(1, HotelId, type, price, null, false);
            this.hms.AddRoom(room);
            Dictionary <int, Room> rooms = hms.getRoomsByHotelId(HotelId);

            managementRoomListBox.Items.Clear();
            roomListBox.Items.Clear();
            // Clear the current list of items

            foreach (var pair in rooms)
            {
                managementRoomListBox.Items.Add($"{pair.Value.getId()} - {pair.Value.getType()} - ${pair.Value.getPrice()}");
            }
            managementRoomListBox.Update();
            roomListBox.Update();

            ExceptionInterface excep = new ExceptionInterface("Successfully created new room");

            excep.Show();
        }
        private void deleteRoomButton_Click(object sender, EventArgs e)
        {
            Room room;
            int  roomId;

            string employeeItem = managementRoomListBox.SelectedItem.ToString();
            int    employeeId   = Convert.ToInt32(employeeItem.Substring(0, employeeItem.IndexOf(' ')));

            roomId = employeeId;
            room   = new Room(roomId, 0, null, 0, null, false);
            this.hms.DeleteRoom(room);
            string employeeItems         = managementHotelListBox.SelectedItem.ToString();
            int    employeeIds           = Convert.ToInt32(employeeItems.Substring(0, employeeItems.IndexOf(' ')));
            int    HotelId               = employeeIds;
            Dictionary <int, Room> rooms = hms.getRoomsByHotelId(HotelId);

            managementRoomListBox.Items.Clear();
            roomListBox.Items.Clear();
            // Clear the current list of items

            foreach (var pair in rooms)
            {
                managementRoomListBox.Items.Add($"{pair.Value.getId()} - {pair.Value.getType()} - ${pair.Value.getPrice()}");
                roomListBox.Items.Add($"{pair.Value.getId()} - {pair.Value.getType()} - ${pair.Value.getPrice()}");
            }
            managementRoomListBox.Update();
            roomListBox.Update();


            ExceptionInterface excep = new ExceptionInterface("Successfully deleted room");

            excep.Show();
        }
        private void generateReportButton_Click(object sender, EventArgs e)
        {
            string startingDateString = this.reportBeginDateTextBox.Text; // Get starting date string from UI
            string endingDateString   = this.reportEndDateTextBox.Text;   // Get ending date string from UI

            DateTime startingDate, endingDate;                            // DateTimes for comparison within the generator

            if (!DateTime.TryParseExact(startingDateString, "MM-dd-yy", null, System.Globalization.DateTimeStyles.None, out startingDate))
            {
                // If the parse fails, throw an exception and exit
                ExceptionInterface excep = new ExceptionInterface("Starting date must be in MM-dd-yy format");
                excep.Show();
                return;
            }

            if (!DateTime.TryParseExact(endingDateString, "MM-dd-yy", null, System.Globalization.DateTimeStyles.None, out endingDate))
            {
                // If the parse fails, throw an exception and exit
                ExceptionInterface excep = new ExceptionInterface("Ending date must be in MM-dd-yy format");
                excep.Show();
                return;
            }

            if (DateTime.Compare(startingDate, endingDate) > 0)
            {
                // If the parse fails, throw an exception and exit
                ExceptionInterface excep = new ExceptionInterface("This range of dates is invalid");
                excep.Show();
                return;
            }


            this.summaryReportTextBox.Text = this.hms.generateSummaryReport(startingDate, endingDate).Replace("\n", Environment.NewLine);  // Use the hms to generate report and assign it to UI
        }
Beispiel #4
0
        // Click the login button
        private void loginButton_Click(object sender, EventArgs e)
        {
            string username = this.loginUsernameTextBox.Text;   // Get the values in the text boxes
            string password = this.loginPasswordTextBox.Text;

            Dictionary <int, Employee> employees = this.hms.getEmployeeData();   // Get the data on all employees
            Dictionary <int, Customer> customers = this.hms.getCustomerData();   // Get the data on all customers

            // Loop through all employees
            foreach (var pair in employees)
            {
                if (pair.Value.getUsername().Equals(username))                 // If the username matches, continue
                {
                    if (pair.Value.getPassword().Equals(password))             // If the password matches, show the employee interface
                    {
                        employeeInterface = new EmployeeInterface(pair.Value); // Pass the employee information into the interface
                        employeeInterface.Show();
                        //this.Hide();
                        return;
                    }

                    ExceptionInterface excep = new ExceptionInterface("Password is invalid");   // Give Exception
                    excep.Show();
                    return;
                }
            }

            // Loop through all customers
            foreach (var pair in customers)
            {
                if (pair.Value.getUsername().Equals(username))                 // If the username matches, continue
                {
                    if (pair.Value.getPassword().Equals(password))             // If the passowrd matches, show the customer interface
                    {
                        customerInterface = new CustomerInterface(pair.Value); // Pass the customer information into the interface
                        customerInterface.Show();
                        //this.Hide();
                        return;
                    }

                    ExceptionInterface excep = new ExceptionInterface("Password is invalid");
                    excep.Show();
                    return;
                }
            }

            ExceptionInterface final_excep = new ExceptionInterface("Username is not found");

            return;

            //this.Hide();
        }
        // Click create new transaction
        private void button4_Click(object sender, EventArgs e)
        {
            // If there hasn't been a room selected, throw an exception and exit
            if (this.roomListBox.SelectedIndex == -1)
            {
                ExceptionInterface excep = new ExceptionInterface("Please select a room and try again");
                excep.Show();
                return;
            }

            // If there hasn't been a date range selected, throw an exception and exit
            if (roomReservationCalendar.SelectionStart == null || roomReservationCalendar.SelectionEnd == null)
            {
                ExceptionInterface excep = new ExceptionInterface("Please select a date range and try again");
                excep.Show();
                return;
            }

            // Parse room id from selected item
            string item   = roomListBox.SelectedItem.ToString();
            int    roomId = Convert.ToInt32(item.Substring(0, item.IndexOf(' ')));

            // Get start and end dates from calendar
            DateTime startDate = roomReservationCalendar.SelectionStart;
            DateTime endDate   = roomReservationCalendar.SelectionEnd;

            Dictionary <int, Reservation> reservations = this.hms.getReservationsByRoom(roomId); // Fetch all existing reservations for the room

            // Check selected range against all reservations. If there's an overlap, throw an exception and exit
            foreach (var pair in reservations)
            {
                if (!(DateTime.Compare(endDate, pair.Value.getStartDate()) <= 0 || DateTime.Compare(startDate, pair.Value.getEndDate()) >= 0))
                {
                    // If the dates overlap, throw an exception and exit
                    ExceptionInterface excep = new ExceptionInterface("Selected reservation overlaps with another. Please try again");
                    excep.Show();
                    return;
                }
            }

            // Spawn the transaction interface and give it everything it needs to continue the use case
            TransactionInterface transactionInterface = new TransactionInterface(this.customer, this.hms.getRoomData()[roomId], startDate, endDate);

            transactionInterface.Show();    // Show a transaction interface

            this.customer = hms.getCustomerData()[this.customer.getId()];
        }
        private void removeLocationButton_Click(object sender, EventArgs e)
        {
            Hotel hotel;
            int   hotelId;

            string employeeItem = managementHotelListBox.SelectedItem.ToString();
            int    employeeId   = Convert.ToInt32(employeeItem.Substring(0, employeeItem.IndexOf(' ')));

            hotelId = employeeId;
            hotel   = new Hotel(hotelId, null, null, null, null);
            this.hms.DeleteHotel(hotel);


            ExceptionInterface excep = new ExceptionInterface("Successfully deleted hotel");

            excep.Show();
        }
        private void createNewLocationButton_Click_1(object sender, EventArgs e)
        {
            hms    = new HotelManagementSystem();
            hotels = new Dictionary <int, Hotel>();

            string name    = this.managementLocationNameTextBox.Text;
            string address = this.manageHotelAddressTextBox.Text;
            string city    = this.manageHotelCity.Text;
            string state   = this.manageHotelState.Text;

            Hotel hotel = new Hotel(1, address, city, state, name);

            this.hms.AddHotel(hotel);

            ExceptionInterface excep = new ExceptionInterface("Successfully created new hotel");

            excep.Show();
        }
        // Click button for cancel reservation
        private void cancelReservationButton_Click(object sender, EventArgs e)
        {
            // If a reservation hasn't been selected, throw an exception and exit
            if (this.reservationListBox.SelectedIndex == -1)
            {
                ExceptionInterface excep = new ExceptionInterface("Please select a reservation and try again");
                excep.Show();
                return;
            }

            // Parse the reservation id from the list item
            string item          = reservationListBox.SelectedItem.ToString();
            int    reservationId = Convert.ToInt32(item.Substring(0, item.IndexOf(' ')));

            // Set to cancelled in the database and remove it from the list
            this.hms.cancelReservation(reservationId);
            this.reservationListBox.Items.RemoveAt(this.reservationListBox.SelectedIndex);
        }
        // Update the user's information.
        private void updateInformationButton_Click(object sender, EventArgs e)
        {
            if (this.customer.getUsername().Equals(this.usernameTextBox.Text))
            {
                this.hms.updateCustomerInformation(this.customer.getId(), this.firstTextBox.Text, this.usernameTextBox.Text, this.passwordTextBox.Text);
                return;
            }

            Dictionary <int, Customer> customers = this.hms.getCustomerData();

            // Check to see if an inputted username already exists
            foreach (var pair in customers)
            {
                if (pair.Value.getUsername().Equals(this.usernameTextBox.Text))
                {
                    ExceptionInterface excep = new ExceptionInterface("This username already exists. Please select another");
                    excep.Show();
                    return;
                }
            }

            this.hms.updateCustomerInformation(this.customer.getId(), this.firstTextBox.Text, this.usernameTextBox.Text, this.passwordTextBox.Text);
        }
        // Method to load the external file for reservations
        private void loadReservationFileButton_Click(object sender, EventArgs e)
        {
            string path = loadReservationFileTextBox.Text;

            // Check if file exists in the first place
            if (!File.Exists(path))
            {
                ExceptionInterface excep = new ExceptionInterface("This file does not exist");
                excep.Show();
                return;
            }

            string[] lines = System.IO.File.ReadAllLines(path); // Read file into an array of lines

            if (lines.Length == 0)                              // If the file is empty, throw an exception
            {
                ExceptionInterface excep = new ExceptionInterface("This file is empty");
                excep.Show();
                return;
            }

            DateTime creationDate = parseFileDateString(lines[0].Split(' ')[1]);  // Parse out the creation date

            // Loop through each entry in the file
            for (int i = 1; i < lines.Length; i++)
            {
                String[] tokens = lines[i].Split(' ');

                int reservationId = Convert.ToInt32(tokens[1]);
                int customerId    = Convert.ToInt32(tokens[3]);
                int hotelId       = Convert.ToInt32(tokens[5]);
                int roomId        = Convert.ToInt32(tokens[7]);

                DateTime startDate = parseFileDateString(tokens[11]);
                DateTime endDate   = parseFileDateString(tokens[13]);

                Dictionary <int, Reservation> reservations = this.hms.getReservationsByRoom(roomId);

                foreach (var pair in reservations)
                {
                    if (!(DateTime.Compare(endDate, pair.Value.getStartDate()) <= 0 || DateTime.Compare(startDate, pair.Value.getEndDate()) >= 0))
                    {
                        // If the dates overlap, throw an exception and exit
                        ExceptionInterface excep = new ExceptionInterface("One inputted reservation overlaps with existing");
                        excep.Show();
                        return;
                    }
                }

                Customer customer = this.hms.getCustomerData()[customerId];
                Room     room     = this.hms.getRoomData()[roomId];

                int duration = (int)(endDate - startDate).TotalDays;

                // Calculate cost
                float cost = duration * room.getPrice() /* - amount earned from rewards*/;
                int   rewardPointsEarned = duration * 25;
                int   rewardPointsSpent  = 0;

                Reservation reservation = new Reservation(0, customer.getId(), room.getId(), startDate, endDate, creationDate, cost, rewardPointsEarned, rewardPointsSpent, false, false, 0);

                this.hms.insertReservation(reservation);
                this.hms.updateCustomerRewardPoints(customer.getId(), customer.getRewardPoints() - rewardPointsSpent + rewardPointsEarned);
            }
        }
Beispiel #11
0
        private void accountButton_Click(object sender, EventArgs e)
        {
            string name     = this.accountFirstTextBox.Text;
            string username = this.accountUsernameTextBox.Text;
            string password = this.accountPasswordTextBox.Text;
            string dobText  = this.accountDOBTextBox.Text;

            DateTime dob;

            if (!DateTime.TryParseExact(dobText, "MM-dd-yy", null, System.Globalization.DateTimeStyles.None, out dob))
            {
                // If the parse fails, throw an exception and exit
                ExceptionInterface excep = new ExceptionInterface("Date of Birth must be in MM-dd-yy format");
                excep.Show();
                return;
            }

            Dictionary <int, Employee> employees = this.hms.getEmployeeData();   // Get the data on all employees
            Dictionary <int, Customer> customers = this.hms.getCustomerData();   // Get the data on all customers

            // Check if the username already exists in the customers
            foreach (var pair in customers)
            {
                if (pair.Value.getUsername().Equals(username))
                {
                    ExceptionInterface excep = new ExceptionInterface("This username already exists");
                    excep.Show();
                    return;
                }
            }

            // Check if the username already exists in the employees
            foreach (var pair in employees)
            {
                if (pair.Value.getUsername().Equals(username))
                {
                    ExceptionInterface excep = new ExceptionInterface("This username already exists");
                    excep.Show();
                    return;
                }
            }

            // Make the account depending on which radio button is checked
            if (customerRadioButton.Checked)
            {
                Customer customer = new Customer(0, name, username, password, dob, 0);
                this.hms.createNewCustomer(customer);

                ExceptionInterface excep = new ExceptionInterface("Successfully create account");
                excep.Show();
            }
            else if (employeeRadioButton.Checked)
            {
                Employee employee = new Employee(0, name, username, password, dob);
                this.hms.createNewEmployee(employee);

                ExceptionInterface excep = new ExceptionInterface("Successfully create account");
                excep.Show();
            }
            else
            {
                // Throw an exception if neither is checked
                ExceptionInterface excep = new ExceptionInterface("Please select either customer or employee");
                excep.Show();
            }
        }