private void initializeAllowance() { MiscellaneousControllerInterface miscellaneousController = new MiscellaneousController(); Miscellaneous foodAllowanceBenefits = miscellaneousController.fetchMiscellaneousBenefitByNameAndEmployee(employee, "FoodAllowance"); Miscellaneous transpoAllowanceBenefits = miscellaneousController.fetchMiscellaneousBenefitByNameAndEmployee(employee, "TransportationAllowance"); foodAllowance.Text = foodAllowanceBenefits.amount.ToString("0.##"); transpoAllowance.Text = transpoAllowanceBenefits.amount.ToString("0.##"); }
private void createEmployeeButton_Click(object sender, EventArgs e) { EmployeeControllerInterface employeeController = new EmployeeController(); if (username.Text.Equals("")) { MessageBox.Show("Username cannot be empty."); return; } if (firstname.Text.Equals("")) { MessageBox.Show("Firstname cannot be empty."); return; } if (middlename.Text.Equals("")) { MessageBox.Show("Middlename cannot be empty."); return; } if (lastname.Text.Equals("")) { MessageBox.Show("Lastname cannot be empty."); return; } if (foodAllowance.Text.Equals("")) { MessageBox.Show("Food Allowance cannot be empty."); return; } if (transpoAllowance.Text.Equals("")) { MessageBox.Show("Transpo Allowance cannot be empty."); return; } if (createEmployeeButton.Text == "Create") { if (password.Text != confirmPassword.Text) { MessageBox.Show("Password did not matched"); password.Text = ""; confirmPassword.Text = ""; return; } Employee employee = new Employee(); employee.employeeId = Convert.ToInt64(employeeId.Text); employee.userAccount = new User(); employee.userAccount.username = username.Text; employee.userAccount.password = password.Text; if (checkUsernameIfExist(employee.userAccount)) { MessageBox.Show("Username is not available anymore, please create another username."); return; } Role role = new Role(); employee.userAccount.role = role; employee.userAccount.role.id = 2; employee.userAccount.role.type = "employee"; employee.userAccount.status = AccountStatus.Enable; employee.fullName = lastname.Text + ", " + firstname.Text + " " + middlename.Text; employee.birthDate = birthdayTimePicker.Text; employee.gender = genderComboBox.Text; PositionControllerInterface positionController = new PositionController(); employee.jobPosition = positionController.fetchPositionByName(positionComboBox.Text); employee.civilStatus = civilStatusComboBox.Text; try { employee.dependents = Convert.ToInt32(dependents.Text); } catch (FormatException ex) { MessageBox.Show("Dependents must be a number!"); return; } employee.address = address.Text; employee.contactNumber = contactNumber.Text; employee.tin = tin.Text; employee.sssId = sssId.Text; employee.philHealthId = philHealthId.Text; employee.pagIbigId = pagIbigId.Text; employee.dateEmployed = DateTime.Now.ToString(); decimal foodAllowanceAmount = 0.00M; decimal transpoAllowanceAmount = 0.00M; try { foodAllowanceAmount = Convert.ToDecimal(foodAllowance.Text); transpoAllowanceAmount = Convert.ToDecimal(transpoAllowance.Text); } catch (FormatException ex) { MessageBox.Show("Allowance amount must be a number!"); return; } if (employeeController.saveEmployee(employee).id > 0) { Miscellaneous foodAllowanceBenefits = new Miscellaneous(); foodAllowanceBenefits.name = "FoodAllowance"; foodAllowanceBenefits.description = "Food Allowance"; foodAllowanceBenefits.amount = foodAllowanceAmount; foodAllowanceBenefits.type = MiscType.Benefits; Miscellaneous transpoAllowanceBenefits = new Miscellaneous(); transpoAllowanceBenefits.name = "TransportationAllowance"; transpoAllowanceBenefits.description = "Transportation Allowance"; transpoAllowanceBenefits.amount = transpoAllowanceAmount; transpoAllowanceBenefits.type = MiscType.Benefits; MiscellaneousControllerInterface miscellaneousController = new MiscellaneousController(); foodAllowanceBenefits = miscellaneousController.addMiscByEmployee(foodAllowanceBenefits, employee); transpoAllowanceBenefits = miscellaneousController.addMiscByEmployee(transpoAllowanceBenefits, employee); MessageBox.Show("Successfully added new employee."); FormControllerInterface formController = new FormController(); formController.showAdminDashBoard(adminDashboard, this); } else { MessageBox.Show("Please try again, or contact the administrator."); password.Text = ""; confirmPassword.Text = ""; } } else if (createEmployeeButton.Text == "Update") { employee.fullName = lastname.Text + ", " + firstname.Text + " " + middlename.Text; employee.birthDate = birthdayTimePicker.Text; employee.gender = genderComboBox.Text; PositionControllerInterface positionController = new PositionController(); employee.jobPosition = positionController.fetchPositionByName(positionComboBox.Text); employee.civilStatus = civilStatusComboBox.Text; try { employee.dependents = Convert.ToInt32(dependents.Text); } catch (FormatException ex) { MessageBox.Show("Dependents must be a number!"); return; } if (isAccountStatusInvalid()) { MessageBox.Show("Account status is not valid."); return; } employee.address = address.Text; employee.contactNumber = contactNumber.Text; employee.tin = tin.Text; employee.sssId = sssId.Text; employee.philHealthId = philHealthId.Text; employee.pagIbigId = pagIbigId.Text; employee.userAccount.status = accountStatusComboBox.Text.Equals("Disable") ? AccountStatus.Disable : AccountStatus.Enable; decimal foodAllowanceAmount = 0.00M; decimal transpoAllowanceAmount = 0.00M; try { foodAllowanceAmount = Convert.ToDecimal(foodAllowance.Text); transpoAllowanceAmount = Convert.ToDecimal(transpoAllowance.Text); } catch (FormatException ex) { MessageBox.Show("Allowance amount must be a number!"); return; } if (employeeController.updateEmployee(employee) != null) { UserControllerInterface userController = new UserController(); userController.updateUserAccountStatus(employee.userAccount); MiscellaneousControllerInterface miscellaneousController = new MiscellaneousController(); Miscellaneous foodAllowanceBenefits = miscellaneousController.fetchMiscellaneousBenefitByNameAndEmployee(employee, "FoodAllowance"); foodAllowanceBenefits.amount = foodAllowanceAmount; Miscellaneous transpoAllowanceBenefits = miscellaneousController.fetchMiscellaneousBenefitByNameAndEmployee(employee, "TransportationAllowance"); transpoAllowanceBenefits.amount = transpoAllowanceAmount; foodAllowanceBenefits = miscellaneousController.updateMiscellaneousBenefitAmountById(foodAllowanceBenefits); foodAllowanceBenefits = miscellaneousController.updateMiscellaneousBenefitAmountById(transpoAllowanceBenefits); MessageBox.Show("Successfully updated employee."); FormControllerInterface formController = new FormController(); formController.showAdminDashBoard(adminDashboard, this); } else { MessageBox.Show("Please try again, or contact the administrator."); } } }