예제 #1
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     if (this.email != null)
     {
         foreach (HiringRequests hr in HiringRequests.GetAllHiringRequests())
         {
             if (hr.PersonId == personId)
             {
                 hr.DeclineHiringRequest();
             }
         }
         form.UpdateGUI();
     }
     else
     {
         foreach (FiringRequests fr in FiringRequests.GetAllFiringRequests())
         {
             if (fr.PersonId == personId)
             {
                 fr.DeclineFiringRequest();
             }
         }
         form.UpdateGUI();
     }
 }
예제 #2
0
        public void UpdateGUI()
        {
            firingRequests = null;
            controls.Clear();
            flpRequests.Controls.Clear();
            firingRequests    = FiringRequests.GetAllFiringRequests();
            hiringRequests    = HiringRequests.GetAllHiringRequests();
            promotionrequests = PromotionRequests.GetAllPromotionRequests();
            foreach (FiringRequests fr in firingRequests)
            {
                controls.Add(new RequestControl(fr.PersonId, fr.CreatedById, fr.DepartmentId, fr.Description, fr.FirstName, fr.LastName, fr.Username, this));
            }

            foreach (PromotionRequests pr in promotionrequests)
            {
                controls.Add(new RequestControl(pr.PersonId, pr.CreatedById, pr.Username, pr.FirstName, pr.LastName, pr.HourlyWage, pr.DepartmentId, this));
            }

            foreach (HiringRequests hr in hiringRequests)
            {
                controls.Add(new RequestControl(hr.PersonId, hr.CreatedById, hr.Username, hr.FirstName, hr.LastName, hr.HourlyWage, hr.DepartmentId, hr.ContractStartDate, hr.PhoneNumber, hr.Email, this));
            }

            foreach (RequestControl request in controls)
            {
                flpRequests.Controls.Add(request);
            }
        }
예제 #3
0
 private void btnApprove_Click_1(object sender, EventArgs e)
 {
     if (MessageBox.Show("Do you really want to approve this request?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
     {
         if (lblRequest.Text.Contains("Hiring"))
         {
             foreach (HiringRequests hr in HiringRequests.GetAllHiringRequests())
             {
                 if (hr.PersonId == personId)
                 {
                     hr.ApproveHiringRequest();
                 }
             }
             form.UpdateGUI();
         }
         else if (lblRequest.Text.Contains("firing"))
         {
             foreach (FiringRequests fr in FiringRequests.GetAllFiringRequests())
             {
                 if (fr.PersonId == personId)
                 {
                     fr.ApproveFiringRequest();
                 }
             }
             form.UpdateGUI();
         }
         else if (lblRequest.Text.Contains("Promotion"))
         {
             foreach (PromotionRequests pr in PromotionRequests.GetAllPromotionRequests())
             {
                 if (pr.PersonId == personId)
                 {
                     pr.ApprovePromotionRequest();
                 }
             }
             form.UpdateGUI();
         }
     }
 }
예제 #4
0
        private void btnSendRequest_Click(object sender, EventArgs e)
        {
            decimal minHourlyWage = 7;

            if (tbUsername.Text == "Username" || tbFirstName.Text == "First name" || tbLastName.Text == "Last name" || tbCountry.Text == "Country" || tbRegion.Text == "region" || tbPostcode.Text == "postcode" || tbStreet.Text == "street" || tbPhoneNumber.Text == "Phone number" || tbPassword.Text == "Password")
            {
                MessageBox.Show("Please change the initial information in the fields!");
            }
            else if (tbUsername.Text == "" || tbFirstName.Text == "" || tbLastName.Text == "" || tbCountry.Text == "Country" || tbRegion.Text == "" || tbPostcode.Text == "" || tbStreet.Text == "" || tbPhoneNumber.Text == "" || tbPassword.Text == "" || tbEmail.Text == "")
            {
                MessageBox.Show("Please fill in all the fields in the table!");
            }
            else if (!cbMonday.Checked && !cbTuesday.Checked && !cbWednesday.Checked && !cbThursday.Checked && !cbFriday.Checked && !cbSaturday.Checked && !cbSunday.Checked)
            {
                MessageBox.Show("Please select available working days!");
            }
            else if (!cbMorningShift.Checked && !cbAfternoonShift.Checked && !cbEveningShift.Checked)
            {
                MessageBox.Show("Please select a prefered workshift!");
            }
            else if (nHourlyWage.Value < minHourlyWage)
            {
                MessageBox.Show("Employee hourly wage must be above the minimum!");
            }
            else if (cmbDepartment.Text == "Department" || cmbDepartment.Text == "")
            {
                MessageBox.Show("Please select a department from the menu!");
            }
            else if (!IsValidEmail(tbEmail.Text))
            {
                MessageBox.Show("Please enter a valid email address!");
            }
            else
            {
                if (UniqueUsername())
                {
                    MySqlConnection conn = Utils.GetConnection();
                    try
                    {
                        int accountType = 0;
                        if (rbAdmin.Checked)
                        {
                            accountType = (int)ProfileRoles.ADMINISTRATOR;
                        }
                        else if (rbManager.Checked)
                        {
                            accountType = (int)ProfileRoles.MANAGER;
                        }
                        else if (rbEmployee.Checked)
                        {
                            accountType = (int)ProfileRoles.EMPLOYEE;
                        }

                        int contract_id = 0;
                        this.username = tbUsername.Text;
                        string   firstName   = tbFirstName.Text;
                        string   lastName    = tbLastName.Text;
                        DateTime dateOfBirth = dtpBirthdate.Value;
                        string   street      = tbStreet.Text;
                        string   postcode    = tbPostcode.Text;
                        string   region      = tbRegion.Text;
                        string   country     = tbCountry.Text;
                        string   email       = tbEmail.Text;
                        hourlyWage = nHourlyWage.Value;
                        string   password          = tbPassword.Text;
                        long     phoneN            = Convert.ToInt64(tbPhoneNumber.Text);
                        DateTime contractStartDate = dtbContractStartDate.Value;
                        int      departmentId      = ((DepartmentComboBoxItem)cmbDepartment.SelectedItem).Id;
                        pc.CreateWorker(accountType, username, password, firstName, lastName, dateOfBirth, street, postcode, region, country, phoneN, email, hourlyWage, contractStartDate, departmentId);//adds worker to person table

                        string       contractQuery = "INSERT into contract (person_id, contract_start) VALUES (@person_id, @contract_start);";
                        MySqlCommand contractCmd   = new MySqlCommand(contractQuery, conn);
                        contractCmd.Parameters.AddWithValue("@person_id", pc.GetIdByUsername(username));
                        contractCmd.Parameters.AddWithValue("@contract_start", contractStartDate);
                        conn.Open();
                        contractCmd.ExecuteNonQuery();



                        string       employeDetailsQuery = "INSERT into employee_details(person_id, hourly_wage, contract_id, department_id, is_approved) VALUES (@person_id, @hourly_wage, @contract_id, @department_id, @is_approved);";
                        MySqlCommand employeDetailsCmd   = new MySqlCommand(employeDetailsQuery, conn);
                        employeDetailsCmd.Parameters.AddWithValue("@person_id", pc.GetIdByUsername(username));
                        employeDetailsCmd.Parameters.AddWithValue("@hourly_wage", hourlyWage);
                        employeDetailsCmd.Parameters.AddWithValue("@contract_id", pc.GetContractId(pc.GetIdByUsername(username)));
                        employeDetailsCmd.Parameters.AddWithValue("@department_id", departmentId);//department ID department class
                        employeDetailsCmd.Parameters.AddWithValue("@is_approved", 1);
                        employeDetailsCmd.ExecuteNonQuery();

                        if (cbMonday.Checked)
                        {
                            workdays.Add(0);
                        }
                        if (cbTuesday.Checked)
                        {
                            workdays.Add(1);
                        }
                        if (cbWednesday.Checked)
                        {
                            workdays.Add(2);
                        }
                        if (cbThursday.Checked)
                        {
                            workdays.Add(3);
                        }
                        if (cbFriday.Checked)
                        {
                            workdays.Add(4);
                        }
                        if (cbSaturday.Checked)
                        {
                            workdays.Add(5);
                        }
                        if (cbSunday.Checked)
                        {
                            workdays.Add(6);
                        }

                        if (cbMorningShift.Checked)
                        {
                            workshifts.Add(1);
                        }
                        if (cbAfternoonShift.Checked)
                        {
                            workshifts.Add(2);
                        }
                        if (cbEveningShift.Checked)
                        {
                            workshifts.Add(3);
                        }

                        foreach (int shift in workshifts)
                        {
                            foreach (int day in workdays)
                            {
                                string       shiftsQuery    = "INSERT into employee_working_days (employee_id,week_day_id, shift) VALUE(@userId,@week_day_id, @shift)";
                                MySqlCommand shiftsQueryCmd = new MySqlCommand(shiftsQuery, conn);
                                shiftsQueryCmd.Parameters.AddWithValue("@shift", shift);
                                shiftsQueryCmd.Parameters.AddWithValue("@userId", pc.GetIdByUsername(username));
                                shiftsQueryCmd.Parameters.AddWithValue("@week_day_id", day);
                                shiftsQueryCmd.ExecuteNonQuery();
                            }
                        }
                        HiringRequests hr  = new HiringRequests(pc.GetIdByUsername(username), loggedInUser, this.username, firstName, lastName, this.hourlyWage, departmentId, contractStartDate, phoneN, email);
                        HiringRequests hr1 = new HiringRequests(pc.GetIdByUsername(username), loggedInUser);
                        if (!hr1.FrExists)
                        {
                            MessageBox.Show("Hiring request already exists!");
                        }
                        else
                        {
                            MessageBox.Show("Request sent successfully!");
                        }
                        addContact = true;
                        if (addContact)
                        {
                            btnAddOtherContact.Enabled = true;
                            btnOpenContact.Enabled     = true;
                            btnDeleteContact.Enabled   = true;
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                    finally
                    {
                        conn.Close();
                    }
                }
                else
                {
                    MessageBox.Show("User with that username already exists.");
                }
            }
        }