Beispiel #1
0
        private void btnEndContract_Click(object sender, EventArgs e)
        {
            EmployeeEmploymentInformation emplInfo = empl.employmentInfo;

            if (String.IsNullOrWhiteSpace(tbEndReason.Text))
            {
                MessageBox.Show("Please fill in end reason.");
                return;
            }
            try
            {
                emplInfo.GetActiveContract().EndDate   = dateTimePickerEndDate.Value;
                emplInfo.GetActiveContract().EndReason = tbEndReason.Text;
                emplInfo.GetActiveContract().IsActive  = false;
                MessageBox.Show($"{empl.FirstName}'s contract was ended with date: {dateTimePickerEndDate.Value}");
                this.Close();
            }
            catch (InvalidEndDateEx ex)
            {
                MessageBox.Show(ex.Message);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #2
0
        public List <Employee> ReadEmployeeFromDepartmentFromDB(EmployeeDepartment department)
        {
            List <Employee>         employees = new List <Employee>();
            List <EmployeeContract> contracts = new List <EmployeeContract>();

            try
            {
                string       sql = $"SELECT FirstName, LastName, employee.EmployeeNumber, Department,  DateOfBirth, City, Street, HouseNumber, HouseNumberAddition, PostCode, Email, Phone, BSN, ICEName, ICEPhone, Password FROM employee INNER JOIN employeeemploymentinfo ON employee.EmployeeNumber = employeeemploymentinfo.EmployeeNumber INNER JOIN empoyeepersonalinfo ON employee.EmployeeNumber = empoyeepersonalinfo.EmployeeNumber WHERE Department='{department}';";
                MySqlCommand cmd = new MySqlCommand(sql, conn);

                string       contract    = "SELECT EmployeeNumber, FTE, Salary, StartDate, EndDate, EndReason, IsActive, ContractNumber FROM contract;";
                MySqlCommand cmdcontract = new MySqlCommand(contract, conn);

                conn.Open();

                MySqlDataReader dr = cmd.ExecuteReader();

                while (dr.Read())
                {
                    Address adress = new Address(dr[6].ToString(), Convert.ToInt32(dr[7]), dr[8].ToString(), dr[9].ToString(), dr[5].ToString());
                    EmployeePersonalInfo          persInfo = new EmployeePersonalInfo(Convert.ToDateTime(dr[4]), dr[11].ToString(), adress, dr[10].ToString(), dr[12].ToString(), dr[13].ToString(), dr[14].ToString(), dr[15].ToString());
                    EmployeeEmploymentInformation emplInfo = new EmployeeEmploymentInformation((EmployeeDepartment)Enum.Parse(typeof(EmployeeDepartment), dr[3].ToString()));
                    Employee e = new Employee(dr[0].ToString(), dr[1].ToString(), emplInfo, persInfo, Convert.ToInt32(dr[2]));
                    employees.Add(e);
                }
                dr.Close();

                MySqlDataReader drcontr = cmdcontract.ExecuteReader();
                while (drcontr.Read())
                {
                    if (Convert.ToBoolean(drcontr[6]))
                    {
                        EmployeeContract eca = new EmployeeContract(Convert.ToDouble(drcontr[1]), Convert.ToDouble(drcontr[2]), Convert.ToDateTime(drcontr[3]), Convert.ToInt32(drcontr[0]), drcontr[7].ToString());
                        contracts.Add(eca);
                    }
                    else
                    {
                        EmployeeContract ec = new EmployeeContract(Convert.ToDouble(drcontr[1]), Convert.ToDouble(drcontr[2]), Convert.ToDateTime(drcontr[3]), Convert.ToDateTime(drcontr[4]), drcontr[5].ToString(), Convert.ToBoolean(drcontr[6]), Convert.ToInt32(drcontr[0]), drcontr[7].ToString());
                        contracts.Add(ec);
                    }
                }
                dr.Close();


                foreach (EmployeeContract c in contracts)
                {
                    foreach (Employee e in employees)
                    {
                        if (e.EmployeeNumber == c.EmplNum)
                        {
                            e.employmentInfo.InitializeContractHistory(c);
                        }
                    }
                }
            }
            catch (MySqlException ex)
            {
                throw ex;
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }
            return(employees);
        }
Beispiel #3
0
        private void btnSaveEmployee_Click(object sender, EventArgs e)
        {
            try
            {
                string             fn         = tbxFirstName.Text;
                string             ln         = tbxLastName.Text;
                EmployeeDepartment ed         = (EmployeeDepartment)comboBoxDepartment.SelectedIndex;
                double             fte        = Convert.ToDouble(numericUpDownHoursPerWeek.Value);
                double             salary     = Convert.ToDouble(numericUpDownSalary.Value);
                DateTime           sd         = dtpStartDate.Value;
                DateTime           bd         = dtpDateOfBirth.Value;
                string             phone      = tbxPhoneNumber.Text;
                string             city       = tbCity.Text;
                string             streetname = tbxStreetName.Text;
                int    streetnum    = Convert.ToInt32(tbxStreetNumber.Text);
                string streetnumadd = tbxStreetNrAddition.Text;
                string postcode     = tbxPostalCode.Text;
                string email        = tbxEmail.Text;
                string bsn          = tbxBSN.Text;
                string icename      = tbxEmergencyName.Text;
                string icephone     = tbxEmergencyPhone.Text;



                if (lbEmplNum.Text == "It will be generated automatically.")
                {
                    EmployeeEmploymentInformation emploInfo = new EmployeeEmploymentInformation(ed, new EmployeeContract(fte, salary, sd, newEmplNum, $"{newEmplNum}.{1}"));
                    EmployeePersonalInfo          persInfo  = new EmployeePersonalInfo(bd, phone, new Address(streetname, streetnum, streetnumadd, postcode, city), email, bsn, icename, icephone);
                    Employee employee = new Employee(fn, ln, emploInfo, persInfo, newEmplNum);
                    if (em.AddEmployee(employee))
                    {
                        MessageBox.Show("New employee was added successfully.");
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("Something went wrong.");
                    }
                }
                else
                {
                    empl.employmentInfo.EditActiveContract(new EmployeeContract(fte, salary, sd, empl.EmployeeNumber, empl.employmentInfo.GetActiveContract().ContractNum));
                    EmployeeEmploymentInformation emploInfo = new EmployeeEmploymentInformation(ed, empl.employmentInfo.GetContractHistory().ToList());
                    EmployeePersonalInfo          persInfo  = new EmployeePersonalInfo(bd, phone, new Address(streetname, streetnum, streetnumadd, postcode, city), email, bsn, icename, icephone);
                    Employee employee = new Employee(fn, ln, emploInfo, persInfo, empl.EmployeeNumber);
                    if (em.EditEmployee(this.empl, employee))
                    {
                        MessageBox.Show("Employee was edited successfully.");
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("Something went wrong.");
                    }
                }
            }
            //catch (CustomeExeptions.InvalidPhoneNumEx ex)
            //{
            //    MessageBox.Show(ex.Message);
            //}
            //catch (CustomeExeptions.InvalidEmailEx ex)
            //{
            //    MessageBox.Show(ex.Message);
            //}
            //catch (CustomeExeptions.InvalidPostcodeEx ex)
            //{
            //    MessageBox.Show(ex.Message);
            //}
            //catch (CustomExceptions.InvalidBSNEx ex)
            //{
            //    MessageBox.Show(ex.Message);
            //}
            //catch (MySqlException ex)
            //{
            //    MessageBox.Show(ex.Message);
            //}
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }