Exemplo n.º 1
0
        private void tbGuestName_Leave(object sender, EventArgs e)
        {
            if (tbGuestName.Text != "")
            {
                //Clears the error provider for guest name.
                epGuestName.Clear();

                //New instance of UseDatabase class.
                UseDatabase useDb = new UseDatabase("..\\..\\App_Data\\database.accdb");

                //Connect database.
                useDb.ConnectToDatabase();

                //Execute query to autofill room data from the room number provided.
                string queryString = "SELECT GuestName FROM [Guest] WHERE Guestname = '" + tbGuestName.Text + "'";

                //Execute query to check for matches in the database.
                OleDbDataReader dbReader = useDb.ExecuteQuery(queryString);

                //If there are rows in the result from the ExecuteQuery then the check was successful meaning there was a match.
                if (dbReader != null && dbReader.HasRows)
                {
                    epGuestName.Clear();
                }
                else
                {
                    epGuestName.SetError(tbGuestName, "Guest not found");
                }
            }
        }
Exemplo n.º 2
0
        //Upon leaving focus of the Room number textbox.
        private void txtRoomNo_Leave(object sender, EventArgs e)
        {
            if (txtRoomNo.Text == "")
            {
                //Informs the user to enter a value in the Room Number field.
                epRoomNo.SetError(this.txtRoomNo, "Please enter a room number");
            }
            else
            {
                epRoomNo.Clear();

                //New instance of UseDatabase class.
                UseDatabase useDb = new UseDatabase("..\\..\\App_Data\\database.accdb");

                //Connect database.
                useDb.ConnectToDatabase();

                //Execute query to autofill room data from the room number provided.
                string queryString = "SELECT GuestName, CheckInDate, NoOfDays, NoOfPeople, TotalDue FROM [CheckIn] WHERE RoomNum = '" + txtRoomNo.Text + "'";

                //Execute query to check for matches in the database.
                OleDbDataReader dbReader = useDb.ExecuteQuery(queryString);

                //If there are rows in the result from the ExecuteQuery then the check was successful meaning there was a match.
                if (dbReader != null && dbReader.HasRows)
                {
                    string          queryString2 = "SELECT RoomType, RoomRate FROM [Room] WHERE RoomNumber = '" + txtRoomNo.Text + "'";
                    OleDbDataReader dbReader2    = useDb.ExecuteQuery(queryString2);

                    //Checks for matches to the room no to get the rest of the info like guest name, room type, checkin date and total payment due.
                    if (dbReader.Read())
                    {
                        txtGuestName.Text = dbReader[0].ToString();
                        txtCheckIn.Text   = dbReader[1].ToString();
                        txtNoDays.Text    = dbReader[2].ToString();
                        txtNoPeople.Text  = dbReader[3].ToString();
                        txtSubTotal.Text  = dbReader[4].ToString();
                    }
                    else
                    {
                        epGuest.SetError(this.txtGuestName, "Guest not checked in");
                    }
                    if (dbReader2.Read())
                    {
                        txtRoomType.Text = dbReader2[0].ToString();
                        txtRoomRate.Text = dbReader2[1].ToString();
                    }
                    else
                    {
                        epRoomNo.SetError(this.txtRoomNo, "No room found for guest name provided");
                    }
                }
                else
                {
                    //Informs the user if the room was not found.
                    epRoomNo.SetError(this.txtRoomNo, "Guest not found");
                }
            }
        }
Exemplo n.º 3
0
        private void btnReserve_Click(object sender, EventArgs e)
        {
            //declaring variables used in the reservation form
            string guestName;
            string roomNum;
            string rType;
            string checkInDate;
            string checkOutDate;
            string noDays;
            string noOfPeople;

            DateTime currentDate = DateTime.Now;

            //initialising the variable2s used in the reservation form
            guestName    = tbGuestName.Text;
            roomNum      = tbRoomNum.Text.ToString();
            rType        = tbRoomType.Text;
            checkInDate  = dtpCheckIn.Text;
            checkOutDate = dtpCheckOut.Text;
            noDays       = tbNoDays.Text.ToString();
            noOfPeople   = numAdults.Text.ToString();
            //subTotal = Convert.ToInt32(tbSubTotal.Text);
            subTotal = 0;

            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //Check whether text box fields have values entered.

            if ((epGuestName.GetError(this.tbGuestName).Length > 0) || ((epRoomNum.GetError(this.tbRoomNum).Length > 0)))
            {
                MessageBox.Show("Please attend to any errors", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                //Create a new instance of the UseDatabase case.
                UseDatabase useDb = new UseDatabase("..\\..\\App_Data\\database.accdb");
                useDb.ConnectToDatabase();
                string b = useDb.Reservation(guestName, roomNum, checkInDate, checkOutDate, noOfPeople, noDays, subTotal.ToString());

                if (b == "success")
                {
                    MessageBox.Show("Reservation successfull", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    File.AppendAllText("..\\..\\App_Data\\LogFiles\\Check-In.txt", "Guest : " + guestName + " Has made a reservation ,on : " + currentDate + Environment.NewLine);
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Fail");
                }

                useDb.DisconnectDatabase();
            }
        }
Exemplo n.º 4
0
        private void tbRoomNum_Leave(object sender, EventArgs e)
        {
            if (tbRoomNum.Text != string.Empty)
            {
                //New instance of the UseDatabase class
                UseDatabase useDb = new UseDatabase("..\\..\\App_Data\\database.accdb");

                //Connect to the database
                useDb.ConnectToDatabase();

                //Query to autofill the rooms data from the room number provided
                string queryString = "SELECT Status,RoomType, RoomRate FROM [Room] WHERE RoomNumber = '" + tbRoomNum.Text + "'";

                //Execute Query to check for matches
                OleDbDataReader dbReader = useDb.ExecuteQuery(queryString);

                //If the query executed it means there was a match
                if (dbReader != null && dbReader.HasRows)
                {
                    if (dbReader.Read())
                    {
                        string roomStatus = dbReader[0].ToString();
                        if (roomStatus == "Available")
                        {
                            tbRoomType.Text = dbReader[1].ToString();
                            tbRoomRate.Text = dbReader[2].ToString();
                            roomRate        = Convert.ToInt32(tbRoomRate.Text);
                            tbSubTotal.Text = "R" + tbRoomRate.Text;
                            subTotal        = Convert.ToInt32(tbNoDays.Text) * roomRate;
                            epStatus.Clear();
                            epGuestName.Clear();
                            epRoomNum.Clear();
                        }
                        else
                        {
                            epStatus.SetError(tbRoomNum, "Room not available");
                        }
                    }
                }
                else
                {
                    epRoomNum.Clear();
                    epRoomNum.SetError(tbRoomNum, "Room number not found");
                }
            }
            else
            {
                epRoomNum.SetError(tbRoomNum, "Please enter a room number");
            }
        }
Exemplo n.º 5
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            //Declaring variables for use in the guest form.
            string   sName       = txtName.Text;
            string   sSurname    = txtSurname.Text;
            string   sAddress    = txtAddress.Text;
            string   sNum        = txtNum.Text;
            string   sGender     = cbGender.Text;
            string   sEmail      = txtEmail.Text;
            string   sStatus     = "";
            DateTime currentDate = DateTime.Now;

            //Validates if all the fields are entered and that there are no error messages before saving the data to the database.
            if ((txtName.Text == "") || (txtSurname.Text == "") || (txtAddress.Text == "") || (txtNum.Text == "") || (txtEmail.Text == ""))
            {
                //Message box to inform the user of errors.
                MessageBox.Show("Please ensure all fields have values entered", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                if ((epContact.GetError(this.txtNum).Length > 0) || (epEmail.GetError(this.txtEmail).Length > 0))
                {
                    //Message box to inform the user of errors.
                    MessageBox.Show("Please attend to any error messages", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    //Calls methods form the UseDatabase case to add a new quest.
                    UseDatabase useDb = new UseDatabase("..\\..\\App_Data\\database.accdb");
                    useDb.ConnectToDatabase();
                    string b = useDb.addGuest(sName, sSurname, sAddress, sNum, sGender, sEmail, sStatus);
                    useDb.DisconnectDatabase();

                    //Informs the user if the database was updated
                    if (b == "success")
                    {
                        MessageBox.Show("A guest has been successfully added", "Caption", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        //Appends details to a log file.
                        File.AppendAllText("..\\..\\App_Data\\LogFiles\\Guest.txt", "Guest : " + sName + " Has been added :" + currentDate + Environment.NewLine);
                    }
                    else
                    {
                        MessageBox.Show("There was a problem with inserting into the database", "Caption", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    this.Close();
                }
            }
        }
Exemplo n.º 6
0
        private void txtRoomNumber_Leave(object sender, EventArgs e)
        {
            //Checks if the room no field is empty.
            if (txtRoomNumber.Text != "")
            {
                epRoomNo.Clear();

                //New instance of UseDatabase class.
                UseDatabase useDb = new UseDatabase("..\\..\\App_Data\\database.accdb");

                //Connect database.
                useDb.ConnectToDatabase();

                //Execute query to autofill room data from the room number provided.
                string queryString = "SELECT RoomType, RoomRate FROM [Room] WHERE RoomNumber = '" + txtRoomNumber.Text + "'";

                //Execute query to check for matches in the database.
                OleDbDataReader dbReader = useDb.ExecuteQuery(queryString);

                //If there are rows in the result from the ExecuteQuery then the check was successful meaning there was a match.
                if (dbReader != null && dbReader.HasRows)
                {
                    //Checks for matches to the room no to get the room type and rate from the database.
                    if (dbReader.Read())
                    {
                        txtRoomType.Text = dbReader[0].ToString();
                        txtRoomRate.Text = dbReader[1].ToString();
                        roomRate         = Convert.ToInt32(txtRoomRate.Text);
                        txtSubTotal.Text = "R" + txtRoomRate.Text;
                        subTotal         = Convert.ToInt32(txtNoDays.Text) * roomRate;
                    }
                }
                else
                {
                    //Informs the user if the room was not found.
                    epRoomNo.SetError(this.txtRoomNumber, "Room number not found");
                }
            }
            else
            {
                //Asks the user to enter a room no.
                epRoomNo.SetError(this.txtRoomNumber, "Please enter a room number");
            }
        }
Exemplo n.º 7
0
        private void btnCheckout_Click(object sender, EventArgs e)
        {
            //Checks if all text boxes are filled
            if (txtGuestName.Text == "" || txtRoomNo.Text == "")
            {
                MessageBox.Show("Please enter all required fields", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                //Checks if any error messages are active before proceeding.
                if ((epGuest.GetError(this.txtGuestName).Length > 0) || (epRoomNo.GetError(this.txtRoomNo).Length > 0))
                {
                    MessageBox.Show("Please attend to any errors", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    //Initiates variables
                    string guestName    = txtGuestName.Text;
                    string checkOutDate = txtCheckOut.Text = DateTime.Now.ToString();
                    string roomNo       = txtRoomNo.Text;

                    //Create a new instance of the UseDatabase case.
                    UseDatabase useDb = new UseDatabase("..\\..\\App_Data\\database.accdb");
                    useDb.ConnectToDatabase();
                    string b = useDb.CheckOut(guestName, roomNo, checkOutDate);

                    //Informs user of success or failure of database entry.
                    if (b == "success")
                    {
                        MessageBox.Show("User has been checked out successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        File.AppendAllText("..\\..\\App_Data\\LogFiles\\Check-In.txt", "Guest : " + guestName + " Has been Checked-out ,on : " + checkOutDate + Environment.NewLine);
                    }
                    else
                    {
                        MessageBox.Show("Failed to check out user", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    useDb.DisconnectDatabase();
                }
            }
        }
Exemplo n.º 8
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            //Declaring variables used in the new room form
            string   roomNum;
            string   roomType;
            string   roomRate;
            DateTime currentDate = DateTime.Now;

            //Initialising variables used in new room form
            roomNum  = txtRoomNumber.Text;
            roomType = txtRoomType.Text;
            roomRate = txtRoomRate.Text.ToString();

            if ((txtRoomNumber.Text == "") || (txtRoomType.Text == "") || (txtRoomRate.Text == ""))
            {
                //Message box to inform the user of errors.
                MessageBox.Show("Please ensure all fields have values entered", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                //creates new instance of the Usedatabase case.
                UseDatabase useDb = new UseDatabase("..\\..\\App_Data\\database.accdb");
                useDb.ConnectToDatabase();
                //Runs the method to add a room and returns a string as result.
                string b = useDb.addRoom(roomNum, roomType, roomRate);
                useDb.DisconnectDatabase();

                //Informs the user if the room was added or if there was an error.
                if (b == "success")
                {
                    MessageBox.Show("A Room has been successfully added", "Caption", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    File.AppendAllText("..\\..\\App_Data\\LogFiles\\Room.txt", "Room : " + roomNum + " Has been added :" + currentDate + Environment.NewLine);
                    this.Close();
                }
                else
                {
                    MessageBox.Show("There was a problem with inserting into the database", "Caption", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Exemplo n.º 9
0
        private void btnLogIn_Click(object sender, EventArgs e)
        {
            //Variables.
            string sName     = txtUsername.Text;
            string sPassword = txtPassword.Text;

            //New instance of UseDatabase class.
            UseDatabase useDb = new UseDatabase("..\\..\\App_Data\\database.accdb");

            //Connect database.
            useDb.ConnectToDatabase();

            //Generates a query for the database containing the username and password
            string queryString = "SELECT * FROM [Users] WHERE Username = '******'AND Password = '******';";

            //Execute query to check for matches in the database.
            OleDbDataReader dbReader = useDb.ExecuteQuery(queryString);

            //If there are rows in the result from the ExecuteQuery then the check was successful meaning there was a match.
            if (dbReader != null && dbReader.HasRows)
            {
                //Informs the user that the login was successfull with a warming message.
                this.Hide();
                MessageBox.Show("Welcome " + sName, "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                frmMain fM = new frmMain(txtUsername.Text);
                fM.ShowDialog();
            }
            else
            {
                //Informs the user that either the username or password is incorrect.
                MessageBox.Show("Incorrect username or password!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtUsername.Clear();
                txtPassword.Clear();
            }
        }
Exemplo n.º 10
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            //Checks whether text box fields have values entered.
            if (tbUserName.Text != "" || tbPassword.Text != "" || tbConfirmPassword.Text != "")
            {
                //Checks if there are no error messages before trying to add the user to the database.
                if (epPasswordCheck.GetError(this.tbConfirmPassword).Length > 0)
                {
                    //informs the user there are errors
                    MessageBox.Show("Please attend to any error messages first", "Attention", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else
                {
                    //initialise variables.
                    string userName = tbUserName.Text;
                    string Password = tbPassword.Text;

                    UseDatabase useDb = new UseDatabase("..\\..\\App_Data\\database.accdb");
                    string      b     = useDb.addUser(userName, Password);

                    //Informs the user if user was added successfully to the database or not.
                    if (b == "success")
                    {
                        MessageBox.Show("User has been added successfully", "Caption", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("Failed to add new user", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    this.Close();
                }
            }
            else
            {
                MessageBox.Show("Please ensure all fields are entered", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Exemplo n.º 11
0
        //When the Check-In button is clicked.
        private void btnCheckIn_Click(object sender, EventArgs e)
        {
            //Declaring variables used in the check form.
            string   guestName   = txtGuestName.Text;
            string   roomNum     = txtRoomNumber.Text;
            string   roomType    = txtRoomType.Text;
            string   numPeople   = (numAdults.Value).ToString();
            DateTime currentDate = DateTime.Now;

            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //Checks whether text box fields have values entered.
            if ((epGuestName.GetError(this.txtGuestName).Length > 0) || (epRoomNo.GetError(this.txtRoomNumber).Length > 0) || (epNumPeople.GetError(this.numAdults).Length > 0))
            {
                MessageBox.Show("Please attend to any errors", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                //Create a new instance of the UseDatabase case.
                UseDatabase useDb = new UseDatabase("..\\..\\App_Data\\database.accdb");
                useDb.ConnectToDatabase();
                string b = useDb.CheckIn(guestName, d1.ToString(), roomNum, txtNoDays.Text, numPeople, subTotal);

                //Informs user of success or failure of database entry.
                if (b == "success")
                {
                    MessageBox.Show("User has been checked in", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    File.AppendAllText("..\\..\\App_Data\\LogFiles\\Check-In.txt", "Guest : " + guestName + " Has been Checked-in ,on : " + currentDate + Environment.NewLine);
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Failed to check-in", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                useDb.DisconnectDatabase();
            }
        }
Exemplo n.º 12
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (tbAdminPassword.Text == "")
            {
                epAdminPass.SetError(this.tbAdminPassword, "Please enter an admin password");
            }
            else
            {
                String sPassword = tbAdminPassword.Text;

                //New instance of UseDatabase class.
                UseDatabase useDb = new UseDatabase(Application.StartupPath + "\\App_Data\\database.accdb");

                //Connect database.
                useDb.ConnectToDatabase();

                string queryString = "SELECT * FROM [Users] WHERE Username = '******' AND Password = '******';";

                //Execute query to check for matches.
                OleDbDataReader dbReader = useDb.ExecuteQuery(queryString);

                //If there are rows in the result from the ExecuteQuery then the check was successful.
                if (dbReader != null && dbReader.HasRows)
                {
                    this.Hide();
                    MessageBox.Show("Success!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    frmForgotPassword FP = new frmForgotPassword();
                    FP.ShowDialog();
                }
                else
                {
                    MessageBox.Show("Incorrect password!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }