Exemplo n.º 1
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult dialogResult = MessageBox.Show("Are you sure you want to delete: " + Environment.NewLine +
                                                            $"Room number: {txtRoomNumber.Text}?", "Delete Record", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);

                if (dialogResult == DialogResult.Yes)
                {
                    if (Convert.ToInt16(GetSendData.GetScalarValue($"SELECT COUNT(*) FROM Booking WHERE RoomId = {dtRoom.Rows[currentRecord]["RoomID"]}")) > 0)
                    {
                        MessageBox.Show("Cannot delete room that has records in booking.", "Delete Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }

                    if (GetSendData.SendData($"DELETE FROM Room WHERE RoomId = {dtRoom.Rows[currentRecord]["RoomID"]}") > 0)
                    {
                        MessageBox.Show("Record Deleted");

                        currentRecord = 0;

                        LoadRoom();
                        PopulateField();
                    }
                    else
                    {
                        MessageBox.Show("An error occured while saving the data.");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().ToString());
            }
        }
Exemplo n.º 2
0
 // Business Rule: If a guest has had 4 or more bookings with any hotel, they should automatically be given preferred status.
 private void UpdatePreferredStatus()
 {
     try
     {
         if (Convert.ToInt32(GetSendData.GetScalarValue($"SELECT COUNT(*) FROM Booking WHERE GuestID = '{cboGuestId.Text}';")) == 4)
         {
             GetSendData.SendData($"UPDATE guest SET Preferred = 1 WHERE GuestID = '{cboGuestId.Text}';");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, ex.GetType().ToString());
     }
 }
Exemplo n.º 3
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult dialogResult = MessageBox.Show("Are you sure you want to delete: " + Environment.NewLine +
                                                            $"{txtLastName.Text}, {txtFirstName.Text} " + Environment.NewLine +
                                                            $"GuestID: {dtGuest.Rows[currentRecord]["GuestID"]}?", "Delete Record", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);

                if (dialogResult == DialogResult.Yes)
                {
                    if (Convert.ToInt16(GetSendData.GetScalarValue($"SELECT COUNT(*) FROM Booking WHERE Guestid = '{dtGuest.Rows[currentRecord]["GuestID"]}'")) > 0)
                    {
                        MessageBox.Show("Cannot delete guest who has bookings.", "Delete Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }

                    if (GetSendData.SendData($"DELETE FROM Guest WHERE GuestId = '{dtGuest.Rows[currentRecord]["GuestID"]}'") > 0)
                    {
                        MessageBox.Show("Record Deleted");

                        currentRecord = 0;

                        LoadGuest();
                        PopulateField();
                    }
                    else
                    {
                        MessageBox.Show("An error occured while saving the data.");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().ToString());
            }
        }
Exemplo n.º 4
0
        private void ControlValidation(object sender, CancelEventArgs e)
        {
            //Loop through all the controls
            //Check TextBox is not null or whitespace
            //Check ComboBox has a valid option selected.
            foreach (Control gp in this.Controls)
            {
                //The controls are in a groupbox so a nested loop is required
                if (gp is GroupBox)
                {
                    foreach (Control ctrl in gp.Controls)
                    {
                        if (ctrl is TextBox)
                        {
                            if (string.IsNullOrWhiteSpace(ctrl.Text))
                            {
                                e.Cancel = true;
                                errorProvider1.SetError(ctrl, "This field is required");
                            }
                            else
                            {
                                errorProvider1.SetError(ctrl, "");
                            }
                        }
                    }
                }
            }

            if (dtpEndDate.Value <= dtpStartDate.Value)
            {
                e.Cancel = true;
                errorProvider1.SetError(dtpEndDate, "End date can not be before the start date.");
            }
            else
            {
                errorProvider1.SetError(dtpEndDate, "");
            }

            if (cboRoomType.Text.ToLower() == "no room")
            {
                e.Cancel = true;
                errorProvider1.SetError(cboRoomType, "This field is required");
            }
            else
            {
                errorProvider1.SetError(cboRoomType, "");
            }

            if (cboRoomNumber.Text.ToLower() == "no room")
            {
                e.Cancel = true;
                errorProvider1.SetError(cboRoomNumber, "This field is required");
            }
            else
            {
                errorProvider1.SetError(cboRoomNumber, "");
            }

            if (cboGuestId.Text.ToLower() == "no guest")
            {
                e.Cancel = true;
                errorProvider1.SetError(cboGuestId, "This field is required");
            }
            else
            {
                errorProvider1.SetError(cboGuestId, "");
            }

            //Business Rule:
            //A booking cannot be created for the penthouse suite for a guest that has not booked with the
            //hotel at least 2 times in the past.
            if (cboRoomNumber.Text.ToLower() != "no room" && cboRoomType.Text.ToLower() == "penthouse suite" && cboHotel.SelectedIndex > 0 && cboGuestId.Text.ToLower() != "no guest")
            {
                if (Convert.ToInt16(GetSendData.GetScalarValue($"SELECT COUNT(*) FROM Booking INNER JOIN Room ON Booking.RoomID = Room.RoomID WHERE GuestID = '{cboGuestId.Text}' AND Hotel = {cboHotel.SelectedValue};")) < 2)
                {
                    e.Cancel = true;
                    errorProvider1.SetError(cboRoomType, "Guest must have booked with us twice in the past to get Penthouse option");
                }
            }
        }