Ejemplo n.º 1
0
        private void btnDeleteEmployee_Click(object sender, EventArgs e)
        {
            // Validate if the employee number is not a integer
            if (int.TryParse(txtEmployeeNumber.Text, out employeeNumber) == false)
            {
                MessageBox.Show("Please enter a valid employee number.");
            }
            else
            {
                if (employeeNumber == 19)
                {
                    MessageBox.Show("Cannot delete cleaner.");
                }
                else
                {
                    // Make sure there is an employee with that number
                    // Setting up a variable for the datatable from the database
                    RestaurantDataSet.EmployeesDataTable emp = new RestaurantDataSet.EmployeesDataTable();
                    // Setting up a employee adaptor and it's to fill in the datatable
                    RestaurantDataSetTableAdapters.EmployeesTableAdapter EmpTableAdap = new RestaurantDataSetTableAdapters.EmployeesTableAdapter();
                    // Getting the employee data from the database
                    EmpTableAdap.GetData();
                    // Filling the data to the datatable
                    EmpTableAdap.Fill(emp);
                    // Going and looking in the datatable for a given employee number and returning the row.
                    RestaurantDataSet.EmployeesRow empRow = emp.FindByemployeeNumber(employeeNumber);

                    // Check if the employee row was found (If null, employee number does not exist in database)
                    if (empRow == null)
                    {
                        MessageBox.Show("Could not find employee number, please try again.");
                        employeeNumber = 0;
                    }
                    else
                    {
                        // Get current record data
                        name             = empRow.name;
                        employeePasscode = empRow.employeePasscode;
                        jobTitle         = empRow.jobTitle;
                        restId           = empRow.Restaurant_restaurantId;

                        // Delete the user from the database
                        EmpTableAdap.Delete(employeeNumber, employeePasscode, restId);

                        // Close the Delete Employee form and notify the user
                        this.Close();
                        MessageBox.Show("Employee has been successfully deleted.");
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void BtnLogIn_Click(object sender, EventArgs e)
        {
            // Check to see if the employee number exists

            // If the employee number is not a integer
            if (int.TryParse(txtUserName.Text, out employeeNumber) == false)
            {
                MessageBox.Show("Please enter a valid employee number.");
            }
            else if (int.TryParse(txtPassword.Text, out int password) == false)
            {
                MessageBox.Show("Please enter a valid password");
            }
            else
            {
                // Table Adapter is the link between the database and your
                // Application. It allows for insert, update, delete and displaying
                // of data from the database.

                // Setting up a variable for the datatable from the database
                RestaurantDataSet.EmployeesDataTable emp = new RestaurantDataSet.EmployeesDataTable();
                // Setting up a employee adaptor and it's to fill in the datatable
                RestaurantDataSetTableAdapters.EmployeesTableAdapter EmpTableAdap = new RestaurantDataSetTableAdapters.EmployeesTableAdapter();
                // Getting the employee data from the database
                EmpTableAdap.GetData();
                // Filling the data to the datatable
                EmpTableAdap.Fill(emp);
                // Going and looking in the datatable for a given employee number and returning the row.
                RestaurantDataSet.EmployeesRow empRow = emp.FindByemployeeNumber(employeeNumber);

                // Check if the employee row was found (If null, employee number does not exist in database)
                if (empRow == null)
                {
                    MessageBox.Show("Could not find employee number, please try again.");
                }

                // Checks to see if password text box equals the password in the database for the employee
                else if (empRow.employeePasscode == password)
                {
                    // Collect user name
                    userName = empRow.name;

                    // Hide the login screen
                    this.Hide();

                    if (empRow.jobTitle == "Manager")
                    {
                        // Login - to manager screen
                        ManagerForm Form1 = new ManagerForm();
                        Form1.ShowDialog();
                    }
                    else if (empRow.jobTitle == "Chef")
                    {
                        // Login - to chef screen
                        ChefForm Form1 = new ChefForm();
                        Form1.ShowDialog();
                    }
                    else if (empRow.jobTitle == "Waitstaff")
                    {
                        // Login - to waitstaff screen
                        WaitstaffForm form1 = new WaitstaffForm();

                        form1.ShowDialog();
                    }
                }
                else
                {
                    MessageBox.Show("Your password was incorrect, please try again.");
                }
            }
        }
Ejemplo n.º 3
0
        private void btnUpdateEmployee_Click(object sender, EventArgs e)
        {
            // Validate first name
            if (txtFirstName.Text == "")
            {
                MessageBox.Show("Please enter a valid first name");
                validItemEntry = 0;
            }
            else
            {
                newFName = txtFirstName.Text;
            }

            // Validate last name
            if (txtLastName.Text == "")
            {
                MessageBox.Show("Please enter a valid last name");
                validItemEntry = 0;
            }
            else
            {
                newLName = txtLastName.Text;
            }

            // Make sure password is an int
            if (int.TryParse(txtPassword.Text, out newPassword) == false)
            {
                MessageBox.Show("Please enter a valid password");
                validItemEntry = 0;
            }

            // Job title selection
            if (rbChef.Checked == true)
            {
                newJobTitle = "Chef";
            }
            else if (rbManager.Checked == true)
            {
                newJobTitle = "Manager";
            }
            else if (rbWaitstaff.Checked == true)
            {
                newJobTitle = "Waitstaff";
            }
            else
            {
                MessageBox.Show("Please Select a Job Title");
                validItemEntry = 0;
            }

            // If all inputs are valid, check employee number and update the record
            if (validItemEntry == 1)
            {
                // Validate the employee number is an integer
                if (int.TryParse(txtEmployeeNumber.Text, out employeeNumber) == false)
                {
                    MessageBox.Show("Please enter a valid employee number.");
                }
                else
                {
                    // Make sure there is an employee with that number
                    // Setting up a variable for the datatable from the database
                    RestaurantDataSet.EmployeesDataTable emp = new RestaurantDataSet.EmployeesDataTable();
                    // Setting up a employee adaptor and it's to fill in the datatable
                    RestaurantDataSetTableAdapters.EmployeesTableAdapter EmpTableAdap = new RestaurantDataSetTableAdapters.EmployeesTableAdapter();
                    // Getting the employee data from the database
                    EmpTableAdap.GetData();
                    // Filling the data to the datatable
                    EmpTableAdap.Fill(emp);
                    // Going and looking in the datatable for a given employee number and returning the row.
                    RestaurantDataSet.EmployeesRow empRow = emp.FindByemployeeNumber(employeeNumber);

                    // Check if the employee row was found (If null, employee number does not exist in database)
                    if (empRow == null)
                    {
                        MessageBox.Show("Could not find employee number, please try again.");
                        employeeNumber = 0;
                    }
                    else
                    {
                        string fullname = newFName + " " + newLName;

                        // Get current record data
                        oldFName    = empRow.name;
                        oldPassword = empRow.employeePasscode;
                        oldJobTitle = empRow.jobTitle;
                        restId      = empRow.Restaurant_restaurantId;

                        // Update the record in the database
                        EmpTableAdap.Update(fullname, newPassword, newJobTitle, restId, employeeNumber, oldPassword, restId);

                        // Close the Update Employee form and notify the user
                        this.Close();
                        MessageBox.Show("Employee has been successfully updated.");
                    }
                }
            }
            // Reset validation checker
            validItemEntry = 1;
        }
Ejemplo n.º 4
0
        private void btnAddEmployee_Click(object sender, EventArgs e)
        {
            // Validate first name
            if (txtFirstName.Text == "")
            {
                MessageBox.Show("Please enter a valid first name");
                validItemEntry = 0;
            }
            else
            {
                fName = txtFirstName.Text;
            }

            // Validate last name
            if (txtLastName.Text == "")
            {
                MessageBox.Show("Please enter a valid last name");
                validItemEntry = 0;
            }
            else
            {
                lName = txtLastName.Text;
            }

            // Make sure password is an int
            if (int.TryParse(txtPassword.Text, out password) == false)
            {
                MessageBox.Show("Please enter a valid password");
                validItemEntry = 0;
            }

            // Job title selection
            if (rbChef.Checked == true)
            {
                jobTitle = "Chef";
            }
            else if (rbManager.Checked == true)
            {
                jobTitle = "Manager";
            }
            else if (rbWaitstaff.Checked == true)
            {
                jobTitle = "Waitstaff";
            }
            else
            {
                MessageBox.Show("Please Select a Job Title");
                validItemEntry = 0;
            }

            // If all inputs are valid, add the record
            if (validItemEntry == 1)
            {
                string fullname = fName + " " + lName;

                // Setting up a variable for the datatable from the database
                RestaurantDataSet.EmployeesDataTable emp = new RestaurantDataSet.EmployeesDataTable();
                // Setting up a employee adaptor and it's to fill in the datatable
                RestaurantDataSetTableAdapters.EmployeesTableAdapter EmpTableAdap = new RestaurantDataSetTableAdapters.EmployeesTableAdapter();
                // Getting the employee data from the database
                EmpTableAdap.GetData();
                // Filling the data to the datatable
                EmpTableAdap.Fill(emp);

                // Adding the new record
                EmpTableAdap.Insert(fullname, password, jobTitle, 1);

                // Close the Add Employee form and notify the user
                this.Close();
                MessageBox.Show("Employee has been successfully added.");
            }

            // Reset validation checker
            validItemEntry = 1;
        }