Example #1
0
        // Button 'Delete' in the room section
        // Remove isactive flag on selected record
        private void buttonDeleteBookingRoom_Click(object sender, EventArgs e)
        {
            Boolean checkedin = false;

            if (dataGridViewRoom.SelectedRows.Count > 0 && dataGridViewRoom.CurrentRow != null)
            {
                int reservationid = Convert.ToInt32(dataGridViewRoom.CurrentRow.Cells[0].Value);
                int roomid        = Convert.ToInt32(dataGridViewRoom.CurrentRow.Cells[3].Value);

                // Confirm delete
                DialogResult confirmDelete = MessageBox.Show("Deleting room reservation for room " + roomid +
                                                             "\nAre you sure you want to continue?", "Warning!", MessageBoxButtons.YesNo);

                if (confirmDelete == DialogResult.Yes)
                {
                    if (DBGetData.GetRoomCheckedin(reservationid) > 0)
                    {
                        checkedin = true;
                    }
                    if (checkedin)
                    {
                        new StatusMessage("Room reservation has already checked in and cant be deleted.");
                    }
                    else
                    {
                        // Save entry to database
                        DBSetData.RoomreservationDelete(reservationid);
                        DisplayDefaultRoom();
                        this.Refresh();
                        new StatusMessage("Room reservation removed from active list.");
                    }
                }
            }
        }
        // Button 'Save'
        private void buttonNewGuestConfirm_Click(object sender, EventArgs e)
        {
            Boolean roomexists = false;
            Boolean roomvalid  = false;
            int     roomid;
            int     roomtypeid = Convert.ToInt32(comboBoxRoomType.SelectedValue);

            // Check if the point entered is numeric
            if (Int32.TryParse(textBoxRoomid.Text, out roomid))
            {
                roomvalid = true;

                if (DBGetData.GetFloorplanRoomExists(roomid) > 0)
                {
                    roomexists = true;
                    MessageBox.Show("Room number already exists, select a different number.");
                }
            }
            else
            {
                MessageBox.Show("Only numbers (0-9) are allowed in the room number.");
            }

            // Execute save
            if (!roomexists && roomvalid)
            {
                DBSetData.FloorplanRoomAdd(roomid, roomtypeid);
                // Close form
                this.Close();
                floorplanForm.LoadDataRoom();
                floorplanForm.Refresh();
                new StatusMessage("Room with number " + roomid + " is added to the database.");
            }
        }
Example #3
0
        // Button 'Save'
        // Validate input and insert into database
        private void buttonNewUserConfirm_Click(object sender, EventArgs e)
        {
            Boolean existingid = false;
            string  adminid    = textBoxUsername.Text;
            string  firstname  = textBoxFirstname.Text;
            string  lastname   = textBoxLastname.Text;
            string  password   = textBoxPassword.Text;
            int     superuser  = 0;

            if (checkBoxSuperuser.Checked)
            {
                superuser = 1;
            }

            // Check for null or empty input
            if (string.IsNullOrWhiteSpace(adminid))
            {
                MessageBox.Show("Username field is not filled in");
            }
            if (string.IsNullOrWhiteSpace(firstname))
            {
                MessageBox.Show("Firstname field is not filled in");
            }
            if (string.IsNullOrWhiteSpace(lastname))
            {
                MessageBox.Show("Lastname field is not filled in");
            }
            if (string.IsNullOrWhiteSpace(password))
            {
                MessageBox.Show("Password field is not filled in");
            }

            // Check if username is already taken
            if (DBGetData.GetLoginUsername(adminid) > 0)
            {
                existingid = true;
            }
            if (existingid)
            {
                MessageBox.Show("Username already exists, please choose a different one.");
            }

            // Execute save
            if (!existingid && !string.IsNullOrWhiteSpace(adminid) && !string.IsNullOrWhiteSpace(firstname) && !string.IsNullOrWhiteSpace(lastname) && !string.IsNullOrWhiteSpace(password))
            {
                // Generate new salt and hash password
                PasswordHasher pwHasher       = new PasswordHasher();
                HashResult     hashedPassword = pwHasher.HashNewSalt(password, 20, SHA512.Create());
                string         salt           = hashedPassword.Salt;
                string         passwordHash   = hashedPassword.Digest;

                DBSetData.UserAdd(adminid, firstname, lastname, passwordHash, salt, superuser);

                // Close form
                this.Close();
                userForm.LoadDataUser();
                userForm.Refresh();
                new StatusMessage("User with login " + adminid + " is added to the database.");
            }
        }
Example #4
0
        // Button 'Save'
        // Validate input and insert into database
        private void buttonNewFolioConfirm_Click(object sender, EventArgs e)
        {
            Boolean folioexists = false;

            // Validate that guest is selcted and folio has items
            if (listBoxGuest.SelectedIndex > -1 && listBoxFolioItem.Items.Count > 0)
            {
                // Reference variables
                int    guestid = Convert.ToInt32(listBoxGuest.SelectedValue);
                string adminid = UserInfo.AdminID;

                // Check -> Folio does not exist
                if (DBGetData.GetFolioExists(guestid) > 0)
                {
                    folioexists = true;
                }
                if (folioexists)
                {
                    MessageBox.Show("Guest already has an active folio, add any changes to existing.");
                }

                if (!folioexists)
                {
                    // Create new folio
                    DBSetData.FolioAdd(guestid, adminid);
                    // Fetch newly created folioid
                    MySqlDataReader getFolioid = DBGetData.GetFolioid(guestid);
                    if (getFolioid.Read())
                    {
                        // Add folio items to folio
                        int folioid = getFolioid.GetInt32(0);

                        foreach (DataRowView drv in listBoxFolioItem.Items)
                        {
                            int billingitemid = int.Parse(drv.Row[listBoxFolioItem.ValueMember].ToString());
                            DBSetData.FolioItemAdd(folioid, billingitemid, adminid);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Could not fetch newly created folioid, try again or contact administrator.");
                    }
                    getFolioid.Dispose();

                    // Refresh datagridview, close form and display new StatusMessage
                    folioForm.LoadDataFolio();
                    folioForm.Refresh();
                    this.Close();
                    new StatusMessage("Folio with " + listBoxFolioItem.Items.Count + " items added.");
                }
            }
        }
Example #5
0
 // Button 'Save'
 private void buttonNewRoomConfirm_Click(object sender, EventArgs e)
 {
     if (comboBoxRoomType.SelectedIndex > -1)
     {
         // Execute save
         int roomtypeid = Convert.ToInt32(comboBoxRoomType.SelectedValue);
         DBSetData.FloorplanRoomEdit(roomid, roomtypeid);
         // Close form
         this.Close();
         floorplanForm.LoadDataRoom();
         floorplanForm.Refresh();
         new StatusMessage("Room with number " + roomid + " is updated in the database.");
     }
 }
Example #6
0
        // Button 'Save'
        // Validate input and insert into database
        private void buttonEditFolioConfirm_Click(object sender, EventArgs e)
        {
            // Validate that guest is selcted and folio has items
            if (listBoxGuest.SelectedIndex > -1 && listBoxFolioItem.Items.Count > 0)
            {
                // Reference variables
                Boolean guestchanged = false;
                Boolean guestconfirm = true;
                int     guestid      = Convert.ToInt32(listBoxGuest.SelectedValue);
                string  adminid      = UserInfo.AdminID;

                // Check if guestid has changed
                MySqlDataReader getFolioGuest = DBGetData.GetFolioGuest(folioid, guestid);
                if (getFolioGuest.Read())
                {
                    guestchanged = true;
                }
                getFolioGuest.Dispose();

                // Give warning if guest has changed and ask for confirmation
                if (!guestchanged)
                {
                    DialogResult guestDifferent = MessageBox.Show("You have changed the guest for this folio" +
                                                                  "\nAre you sure you want to continue?", "Warning!", MessageBoxButtons.YesNo);
                    if (guestDifferent == DialogResult.No)
                    {
                        // Cancel edit and reload data
                        guestconfirm = false;
                        LoadDataFolio();
                    }
                }

                if (guestconfirm)
                {
                    // Add new folio items to folio
                    foreach (DataRowView drv in listBoxFolioItem.Items)
                    {
                        int billingitemid = int.Parse(drv.Row[listBoxFolioItem.ValueMember].ToString());
                        DBSetData.FolioItemAdd(folioid, billingitemid, adminid);
                    }

                    // Refresh datagridview, close form and display new StatusMessage
                    folioForm.LoadDataFolio();
                    folioForm.Refresh();
                    this.Close();
                    new StatusMessage("Folio populated with " + listBoxFolioItem.Items.Count + " additional items.");
                }
            }
        }
Example #7
0
        // Button 'Save'
        // Update database record
        private void buttonNewGuestConfirm_Click(object sender, EventArgs e)
        {
            string firstname = textBoxFirstname.Text;
            string lastname  = textBoxLastname.Text;
            string address   = textBoxAddress.Text;
            string city      = textBoxCity.Text;
            string postcode  = textBoxPostcode.Text;
            string telephone = textBoxTelephone.Text;

            // Check for null or empty input
            if (string.IsNullOrWhiteSpace(firstname))
            {
                MessageBox.Show("Firstname field is not filled in");
            }
            if (string.IsNullOrWhiteSpace(lastname))
            {
                MessageBox.Show("Lastname field is not filled in");
            }
            if (string.IsNullOrWhiteSpace(address))
            {
                MessageBox.Show("Address field is not filled in");
            }
            if (string.IsNullOrWhiteSpace(city))
            {
                MessageBox.Show("City field is not filled in");
            }
            if (string.IsNullOrWhiteSpace(postcode))
            {
                MessageBox.Show("Postcode field is not filled in");
            }

            if (!string.IsNullOrWhiteSpace(firstname) && !string.IsNullOrWhiteSpace(lastname) && !string.IsNullOrWhiteSpace(address) &&
                !string.IsNullOrWhiteSpace(city) && !string.IsNullOrWhiteSpace(postcode))
            {
                if (string.IsNullOrWhiteSpace(telephone))
                {
                    telephone = null;
                }
                // Execute save
                DBSetData.GuestEdit(guestid, firstname, lastname, address, city, postcode, telephone);

                // Close form and refresh data
                guestForm.LoadDataGuest();
                guestForm.Refresh();
                this.Close();
                new StatusMessage("Guest with name " + firstname + " " + lastname + " is updated in the database.");
            }
        }
Example #8
0
        // Button 'Lagre'
        // Validate input and insert into database
        private void buttonNewBookingConfirm_Click(object sender, EventArgs e)
        {
            // Display error messages if value is not selected
            if (listBoxGuest.SelectedIndex == -1)
            {
                MessageBox.Show("Select a guest before saving entry");
            }
            if (!roomchecked || roomid == null)
            {
                MessageBox.Show("Select a room before saving entry");
            }

            // Make sure guest and room is selected
            if (listBoxGuest.SelectedIndex > -1 && roomchecked && roomid != null)
            {
                //Reference variables
                string datefrom = datePickerArrival.Value.ToString("yyyy-MM-dd");
                string dateto   = datePickerDeparture.Value.ToString("yyyy-MM-dd");
                int    guestid  = Convert.ToInt32(listBoxGuest.SelectedValue);
                string remark;
                if (string.IsNullOrWhiteSpace(textBoxRemark.Text))
                {
                    remark = null;
                }
                else
                {
                    remark = textBoxRemark.Text;
                }

                ValidateInput();
                // Check all relevant fields for input
                if (validinput)
                {
                    DBSetData.RoomreservationAdd(guestid, roomid, datefrom, dateto, remark);
                    // Refresh datagridview, close form and display new StatusMessage
                    bookingForm.DisplayDefaultRoom();
                    bookingForm.Refresh();
                    this.Close();
                    new StatusMessage("Reservation for roomnumber " + roomid + " saved in database.");
                }
            }
        }
Example #9
0
        // Button 'Reset'
        private void buttonEditPasswordConfirm_Click(object sender, EventArgs e)
        {
            Boolean passwordMatch   = false;
            string  password        = textBoxPassword.Text;
            string  passwordConfirm = textBoxPasswordConfirm.Text;

            // Check for null or empty input
            if (string.IsNullOrWhiteSpace(password))
            {
                MessageBox.Show("Password field is not filled in");
            }
            if (string.IsNullOrWhiteSpace(passwordConfirm))
            {
                MessageBox.Show("Password confirmation field is not filled in");
            }

            // Check that confirmation field is equal to password field
            if (password.Equals(passwordConfirm))
            {
                passwordMatch = true;
            }

            // Execute save
            if (passwordMatch && !string.IsNullOrWhiteSpace(adminid) && !string.IsNullOrWhiteSpace(password) && !string.IsNullOrWhiteSpace(passwordConfirm))
            {
                // Generate new salt and hash password
                PasswordHasher pwHasher       = new PasswordHasher();
                HashResult     hashedPassword = pwHasher.HashNewSalt(password, 20, SHA512.Create());
                string         salt           = hashedPassword.Salt;
                string         passwordHash   = hashedPassword.Digest;

                DBSetData.UserPasswordChange(adminid, passwordHash, salt);

                // Close form
                this.Close();
                userForm.LoadDataUser();
                new StatusMessage("Password for user with login " + adminid + " is updated in the database.");
            }
        }
Example #10
0
        // Button 'Save'
        private void buttonEditUserConfirm_Click(object sender, EventArgs e)
        {
            string firstname = textBoxFirstname.Text;
            string lastname  = textBoxLastname.Text;
            string password  = textBoxPassword.Text;
            int    superuser = 0;
            int    active    = 0;

            if (checkBoxSuperuser.Checked)
            {
                superuser = 1;
            }
            if (checkBoxActive.Checked)
            {
                active = 1;
            }

            // Check for null or empty input
            if (string.IsNullOrWhiteSpace(firstname))
            {
                MessageBox.Show("Firstname field is not filled in");
            }
            if (string.IsNullOrWhiteSpace(lastname))
            {
                MessageBox.Show("Lastname field is not filled in");
            }

            if (!string.IsNullOrWhiteSpace(adminid) && !string.IsNullOrWhiteSpace(firstname) && !string.IsNullOrWhiteSpace(lastname))
            {
                // Execute save
                DBSetData.UserEdit(adminid, firstname, lastname, superuser, active);

                // Close form and refresh data
                userForm.LoadDataUser();
                userForm.Refresh();
                this.Close();
                new StatusMessage("User with login " + adminid + " is updated in the database.");
            }
        }
        // Button 'Save'
        private void buttonEditHallConfirm_Click(object sender, EventArgs e)
        {
            string hallname = textBoxHallname.Text;

            // Check for null or empty input
            if (string.IsNullOrWhiteSpace(hallname))
            {
                MessageBox.Show("Hallname field is not filled in");
            }

            if (!string.IsNullOrWhiteSpace(hallname) && comboBoxHallType.SelectedIndex > -1)
            {
                // Execute save
                int halltypeid = Convert.ToInt32(comboBoxHallType.SelectedValue);
                DBSetData.FloorplanHallEdit(hallid, hallname, halltypeid);
                // Close form
                this.Close();
                floorplanForm.LoadDataHall();
                floorplanForm.Refresh();
                new StatusMessage("Hall with name " + hallname + " is updated in the database.");
            }
        }
        // Button 'Save'
        private void buttonNewHallConfirm_Click(object sender, EventArgs e)
        {
            Boolean hallexists = false;
            string  hallname   = textBoxHallname.Text;

            if (DBGetData.GetFloorplanHallExists(hallname) > 0)
            {
                hallexists = true;
                MessageBox.Show("Hall name already exists, select a different name.");
            }

            // Execute save
            if (!hallexists && !string.IsNullOrWhiteSpace(hallname) && comboBoxHallType.SelectedIndex > -1)
            {
                int halltypeid = Convert.ToInt32(comboBoxHallType.SelectedValue);
                DBSetData.FloorplanHallAdd(hallname, halltypeid);
                // Close form
                this.Close();
                floorplanForm.LoadDataHall();
                floorplanForm.Refresh();
                new StatusMessage("Hall with name " + hallname + " is added to the database.");
            }
        }
Example #13
0
        // Button 'Check out' in the room section
        // Validation: Room is marked as checked in > Date for checkout is today -> Guest has active messages
        // Checkout procedure: Potential reimbursement -> Payment process ->
        // Mark folio with paid or due date -> Mark room for housekeeping -> Mark room reservation as checked out and inactive
        private void buttonCheckoutRoom_Click(object sender, EventArgs e)
        {
            // Make sure datagridview has selection
            if (dataGridViewRoom.SelectedRows.Count > 0 && dataGridViewRoom.CurrentRow != null)
            {
                // Validation variables
                Boolean checkedout   = false;
                Boolean checkoutdate = true;
                Boolean message      = false;
                // Reference variables
                int roomid        = Convert.ToInt32(dataGridViewRoom.CurrentRow.Cells[3].Value);
                int reservationid = Convert.ToInt32(dataGridViewRoom.CurrentRow.Cells[0].Value);

                // Confirm checkout
                DialogResult confirmCheckout = MessageBox.Show("Checking out roomnumber " + roomid +
                                                               "\nAre you sure you want to continue?", "Check out", MessageBoxButtons.YesNo);
                if (confirmCheckout == DialogResult.Yes)
                {
                    // Check that reservation checkout date is today
                    MySqlDataReader getRoomCheckoutDate = DBGetData.GetRoomCheckoutDate(reservationid);
                    if (getRoomCheckoutDate.Read())
                    {
                        DateTime date = Convert.ToDateTime(getRoomCheckoutDate[0]);
                        if (date != DateTime.Today)
                        {
                            checkoutdate = false;
                        }
                        if (!checkoutdate)
                        {
                            new StatusMessage("Room reservation not marked for checkout today.");
                        }
                    }
                    getRoomCheckoutDate.Dispose();

                    // Yes/no continue dialogue if checkout is early
                    if (!checkoutdate)
                    {
                        DialogResult continueCheckout = MessageBox.Show(
                            "Room is not flagged for checkout today" +
                            "\nAre you sure you want to continue?", "Warning!", MessageBoxButtons.YesNo);
                        if (continueCheckout == DialogResult.Yes)
                        {
                            checkoutdate = true;
                        }
                    }

                    // Check that reservation is checked in
                    if (DBGetData.GetRoomCheckedin(reservationid) < 1)
                    {
                        checkedout = true;
                    }
                    if (checkedout)
                    {
                        new StatusMessage("Room reservation has not checked in or already checked out.");
                    }

                    if (!checkedout && checkoutdate)
                    {
                        // Check if guest has undelivered messages
                        MySqlDataReader getRoomMessages = DBGetData.GetRoomMessages(reservationid);
                        while (getRoomMessages.Read())
                        {
                            message = true;
                            MessageBox.Show("Date recieved: " + getRoomMessages.GetDateTime(0) +
                                            "\nFrom: " + getRoomMessages.GetString(1) +
                                            "\n\n" + getRoomMessages.GetString(2),
                                            "Message to guest");
                        }

                        getRoomMessages.Dispose();

                        // Mark messages as inactive if any
                        if (message)
                        {
                            DBSetData.RoomreservationUpdateMessages(reservationid);
                        }

                        // Check if guest has more than one room reservation checked in
                        int roomcount = DBGetData.GetRoomCount(reservationid);

                        // Do checkout process
                        DBSetData.RoomreservationCheckout(reservationid);
                        DisplayDefaultRoom();
                        this.Refresh();
                        new StatusMessage("Room reservation for room " + roomid + " has been flagged for housekeeping and checked out.");

                        // Print customer folio total for the last room checkout
                        if (roomcount == 1)
                        {
                            MySqlDataReader getFolioTotal = DBGetData.GetRoomCheckoutTotal(reservationid);
                            if (getFolioTotal.Read())
                            {
                                Decimal foliototal = getFolioTotal.GetDecimal(0);

                                // Payment options
                                // Yes -> Cash/card, No -> Invoice bill
                                DialogResult paymentCheckout = MessageBox.Show("Payment total: " + foliototal +
                                                                               "\n\n'Yes' for immidiate payment with cash or creditcard," +
                                                                               "\n'No' for invoice with due date 3 weeks from today.",
                                                                               "Payment options", MessageBoxButtons.YesNo);

                                // Mark folio as paid
                                if (paymentCheckout == DialogResult.Yes)
                                {
                                    DBSetData.RoomreservationFolioPaid(reservationid);
                                }
                                // Mark folio with duedate
                                else if (paymentCheckout == DialogResult.No)
                                {
                                    DBSetData.RoomreservationFolioDue(reservationid);
                                }
                            }

                            getFolioTotal.Dispose();
                        }
                    }
                }
            }
        }
Example #14
0
        // Button 'Check in' in the room section
        // Validation: Room is not marked as checked in already -> Date for checkin is today -> Room is clean
        // Checkin procedure: Create new folio or append existing -> Add folio items for room charge -> Mark room as checked in
        private void buttonCheckinRoom_Click(object sender, EventArgs e)
        {
            // Make sure datagridview has selection
            if (dataGridViewRoom.SelectedRows.Count > 0 && dataGridViewRoom.CurrentRow != null)
            {
                // Validation variables
                Boolean checkedin   = false;
                Boolean checkindate = true;
                Boolean roomcleared = true;
                // Roomstatus values: 0 = deny checkin, 1 = warning, 2 = no flag
                int roomstatus = 2;
                // Reference variables
                string adminid       = UserInfo.AdminID;
                int    reservationid = Convert.ToInt32(dataGridViewRoom.CurrentRow.Cells[0].Value);
                int    roomid        = Convert.ToInt32(dataGridViewRoom.CurrentRow.Cells[3].Value);

                // Confirm checkin
                DialogResult confirmCheckin = MessageBox.Show("Checking in roomnumber " + roomid +
                                                              "\nAre you sure you want to continue?", "Check in", MessageBoxButtons.YesNo);
                if (confirmCheckin == DialogResult.Yes)
                {
                    // Check that reservation checkin date is today
                    MySqlDataReader getRoomCheckinDate = DBGetData.GetRoomCheckinDate(reservationid);
                    if (getRoomCheckinDate.Read())
                    {
                        DateTime date = Convert.ToDateTime(getRoomCheckinDate[0]);
                        if (date != DateTime.Today)
                        {
                            checkindate = false;
                        }
                        if (!checkindate)
                        {
                            new StatusMessage("Room reservation not marked for checkin today.");
                        }
                    }
                    getRoomCheckinDate.Dispose();

                    // Check that reservation is not already checked in
                    if (DBGetData.GetRoomCheckedin(reservationid) > 0)
                    {
                        checkedin = true;
                    }
                    if (checkedin)
                    {
                        new StatusMessage("Room reservation has already checked in.");
                    }

                    // Check if room is clean
                    MySqlDataReader getHousekeepingCode = DBGetData.GetRoomHousekeeping(roomid);
                    if (getHousekeepingCode.Read())
                    {
                        int code = Convert.ToInt32(getHousekeepingCode[0]);
                        switch (code)
                        {
                        case 0:
                            roomstatus = 0;
                            new StatusMessage("Room unavailable due to maintainance, " +
                                              "please change reservation or upgrade guest.");
                            break;

                        case 1:
                            roomstatus = 1;
                            new StatusMessage("Room needs inspection, " +
                                              "please change reservation or send staff immediately.");
                            break;

                        case 2:
                            roomstatus = 1;
                            new StatusMessage("Room needs cleaning, " +
                                              "please change reservation or send staff immediately.");
                            break;
                        }
                    }
                    getHousekeepingCode.Dispose();

                    // Check if room is cleared for checkin
                    switch (roomstatus)
                    {
                    // Deny checkin of a room that is flagged as inactive
                    case 0:
                        roomcleared = false;
                        break;

                    // Option to continue if room has a warning code and other arrangements cant be made
                    case 1:
                        DialogResult continueCheckin = MessageBox.Show(
                            "Room is flagged for cleaning or inspection" +
                            "\nAre you sure you want to continue?", "Warning!", MessageBoxButtons.YesNo);
                        if (continueCheckin == DialogResult.Yes)
                        {
                            roomcleared = true;
                        }
                        else if (continueCheckin == DialogResult.No)
                        {
                            roomcleared = false;
                        }

                        break;

                    // No code on room
                    case 2:
                        roomcleared = true;
                        break;
                    }

                    // Proceed with checkin
                    if (!checkedin && checkindate && roomcleared)
                    {
                        DBSetData.RoomreservationCheckin(reservationid, adminid);
                        DisplayDefaultRoom();
                        this.Refresh();
                        new StatusMessage("Room reservation for room " + roomid + " has been flagged as checked in and folio was added.");
                    }
                }
            }
        }
Example #15
0
        private void buttonSetPaid_Click(object sender, EventArgs e)
        {
            Boolean paiddate        = false;
            Boolean roomreservation = false;
            Boolean hallreservation = false;

            if (dataGridViewFolio.SelectedRows.Count > 0 && dataGridViewFolio.CurrentRow != null)
            {
                int     folioid    = Convert.ToInt32(dataGridViewFolio.CurrentRow.Cells[0].Value);
                string  firstname  = Convert.ToString(dataGridViewFolio.CurrentRow.Cells[1].Value);
                string  lastname   = Convert.ToString(dataGridViewFolio.CurrentRow.Cells[2].Value);
                Decimal foliototal = Convert.ToDecimal(dataGridViewFolio.CurrentRow.Cells[3].Value);

                // Confirm setting due date
                DialogResult confirmPaiddate = MessageBox.Show("Setting paid date today on folio that belongs to " + firstname + " " + lastname +
                                                               " with a total cost of kr " + foliototal +
                                                               "\nAre you sure you want to continue?", "Warning!", MessageBoxButtons.YesNo);

                if (confirmPaiddate == DialogResult.Yes)
                {
                    // Checks -> Folio already has paid date, Folio has room reservation active, Folio has hall reservation active
                    MySqlDataReader getFolioPaidStatus = DBGetData.GetFolioPaidDate(folioid);
                    if (getFolioPaidStatus.Read())
                    {
                        paiddate = true;
                    }
                    getFolioPaidStatus.Dispose();
                    if (paiddate)
                    {
                        new StatusMessage("Folio has already been paid.");
                    }

                    if (DBGetData.GetFolioRoomreservation(folioid) > 0)
                    {
                        roomreservation = true;
                    }
                    if (roomreservation)
                    {
                        new StatusMessage("Folio owner has an active room reservation, cannot mark with paid date until after checkout.");
                    }

                    if (DBGetData.GetFolioHallreservation(folioid) > 0)
                    {
                        hallreservation = true;
                    }
                    if (hallreservation)
                    {
                        new StatusMessage("Folio owner has an active hall reservation, cannot mark with paid date until after checkout.");
                    }

                    if (!paiddate && !roomreservation && !hallreservation)
                    {
                        // Save entry to database
                        DBSetData.FolioPaidDate(folioid);
                        LoadDataFolio();
                        dataGridViewFolio.Refresh();
                        new StatusMessage("Folio marked as paid today.");
                    }
                }
            }
        }
Example #16
0
        // Button 'Lagre'
        // Validate input and update database record
        private void buttonEditBookingConfirm_Click(object sender, EventArgs e)
        {
            // Validation variables
            Boolean checkedin    = false;
            Boolean guestchanged = false;
            Boolean guestconfirm = true;

            // Display error messages if value is not selected
            if (listBoxGuest.SelectedIndex == -1)
            {
                MessageBox.Show("Select a guest before saving entry");
            }
            if (!roomchecked || roomid == null)
            {
                MessageBox.Show("Select a room before saving entry");
            }

            // Make sure guest and room is selected and reservationid set
            if (listBoxGuest.SelectedIndex > -1 && roomchecked && roomid != null && reservationid > 0)
            {
                //Reference variables
                string datefrom = datePickerArrival.Value.ToString("yyyy-MM-dd");
                string dateto   = datePickerDeparture.Value.ToString("yyyy-MM-dd");
                int    guestid  = Convert.ToInt32(listBoxGuest.SelectedValue);
                string remark;
                if (string.IsNullOrWhiteSpace(textBoxRemark.Text))
                {
                    remark = null;
                }
                else
                {
                    remark = textBoxRemark.Text;
                }

                ValidateInput();
                // Check all relevant fields for input
                if (validinput)
                {
                    // Check if reservation is checked in
                    if (DBGetData.GetRoomCheckedin(reservationid) > 0)
                    {
                        checkedin = true;
                    }
                    if (checkedin)
                    {
                        new StatusMessage("Room reservation has already checked in.");
                    }

                    // Check if guestid has changed
                    MySqlDataReader getReservationGuest = DBGetData.GetRoomreservationGuest(reservationid, guestid);
                    if (getReservationGuest.Read())
                    {
                        guestchanged = true;
                    }
                    getReservationGuest.Dispose();

                    // Give warning if guest has changed and ask for confirmation
                    if (!guestchanged)
                    {
                        DialogResult guestDifferent = MessageBox.Show("You have changed the guest for this reservation" +
                                                                      "\nAre you sure you want to continue?", "Warning!", MessageBoxButtons.YesNo);
                        if (guestDifferent == DialogResult.No)
                        {
                            // Cancel edit and reload data
                            guestconfirm = false;
                            LoadDataBooking();
                            // Clear flowlayoutpanel and set parameter to enable drag and drop
                            flowLayoutPanel1.Controls.Clear();
                            roomchecked = false;
                        }
                    }

                    if (!checkedin && guestconfirm)
                    {
                        DBSetData.RoomreservationEdit(reservationid, guestid, roomid, datefrom, dateto, remark);
                        // Refresh datagridview, close form and display new StatusMessage
                        bookingForm.DisplayDefaultRoom();
                        bookingForm.Refresh();
                        this.Close();
                        new StatusMessage("Reservation for roomnumber " + roomid + " saved in database and previous roomnumber released.");
                    }
                }
            }
        }