/// <summary> /// Event that rusn when the button delete to team is clicked /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnDeleteToTeam_Click(object sender, EventArgs e) { model.pojo.Employee _oSelectedEmployee = null; Boolean _blAllCorrect = true; if (this.dgvEmployeesOnTeam.SelectedRows.Count >= 1)//If the row selected { DataGridViewSelectedRowCollection _selected = this.dgvEmployeesOnTeam.SelectedRows; foreach (DataGridViewRow _row in _selected) { int _iIndexSelected = _row.Index; // Recover the index of selected row Object _cell = this.dgvEmployeesOnTeam.Rows[_iIndexSelected].Cells[0].Value; //Gets the NIF if (_cell != null) { String _strSelectedRowCode = _cell.ToString(); // Recover the code _oSelectedEmployee = Controller.EmployeeService.readEmployee(_strSelectedRowCode); // We look for the employee nif Boolean _blDelete = this.deleteFromTeam(_oSelectedEmployee, AuxTeam); if (!_blDelete) { _blAllCorrect = false; } } } } if (!_blAllCorrect) { clMessageBox.showMessage(Literal.DELETE_ALL_EMPLOYEE_TO_TEAM_ERROR, false, this); } this.fillDataGrid(); }
/// <summary> /// Add selected employee to team /// </summary> private void addToTeam() { model.pojo.Employee _oSelectedEmployee = null; model.pojo.Team _oTeam = null; Boolean _blAdd = false; if (this.dgvEmployees.SelectedRows.Count == 1) //If the row selected { int _iIndexSelected = this.dgvEmployees.SelectedRows[0].Index; // Recover the index of selected row Object _cell = this.dgvEmployees.Rows[_iIndexSelected].Cells[0].Value; if (_cell != null) { String _strSelectedRowCode = _cell.ToString(); // Recover the code _oSelectedEmployee = Controller.EmployeeService.readEmployee(_strSelectedRowCode); // We look for the employee nif String _SelectedTeam = this.cmbTeamsToAdd.SelectedValue.ToString(); _oTeam = this.Controller.TeamService.readTeam(_SelectedTeam); model.pojo.TeamHistory _oCurrentTeam = this.Controller.TeamHistoryService.getCurrentTeamHistoryByEmployee(_oSelectedEmployee.nif, _oTeam.code); //We look if the employee already in team if (_oCurrentTeam == null) { if (_oSelectedEmployee != null && _oTeam != null) { _blAdd = this.Controller.TeamService.addToTeam(_oSelectedEmployee.nif, _oTeam.code); } clMessageBox.showMessage(Literal.ADD_EMPLOYEE_TO_TEAM_SUCCESFULL, true, this); } else { clMessageBox.showMessage(Literal.INFO_ON_TEAM, false, this); } } } }
/// <summary> /// Event that runs when the row state change /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dgvEmployees_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e) { if (dgvEmployees.SelectedRows.Count == 1) { btnAddToTeam.Enabled = true; cmbTeamsToAdd.Enabled = true; int _iIndexSelected = dgvEmployees.SelectedRows[0].Index; // Recover the index of selected row Object _cell = dgvEmployees.Rows[_iIndexSelected].Cells[0].Value; if (_cell != null) { String _strSelectedRowCode = _cell.ToString(); // Recover the code model.pojo.Employee _oSelectedEmployee = Controller.EmployeeService.readEmployee(_strSelectedRowCode); // We look for the employee nif //cmbTeamsToAdd.SelectedItem = Controller.TeamService.getTeamOfEmployee(_oSelectedEmployee.nif); } } else { btnAddToTeam.Enabled = false; cmbTeamsToAdd.Enabled = false; } Util.changeButtonText(this.dgvEmployees, this.btnManagementEmployee); }
/// <summary> /// Deleted selected employee to team /// </summary> private bool deleteFromTeam(model.pojo.Employee pEmployee, model.pojo.Team pTeam) { model.pojo.TeamHistory _oTeamHistoryControl = null; Boolean _blUpdateHistory = false; if (pEmployee != null && pTeam != null) { _oTeamHistoryControl = this.Controller.TeamHistoryService.readTeamHistory(pEmployee.nif, pTeam.code); if (_oTeamHistoryControl != null) { _blUpdateHistory = this.Controller.TeamHistoryService.updateTeamHistory(pEmployee.nif, pTeam.code, DateTime.Now); } } return(_blUpdateHistory); }
/// <summary> /// Event that runs when the button is clicked to manage employees /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnManagementEmployee_Click(object sender, EventArgs e) { model.pojo.Employee _oSelectedEmployee = null; if (dgvEmployees.SelectedRows.Count == 1) //If the row selected { int _iIndexSelected = dgvEmployees.SelectedRows[0].Index; // Recover the index of selected row Object _cell = dgvEmployees.Rows[_iIndexSelected].Cells[0].Value; if (_cell != null) { String _strSelectedRowCode = _cell.ToString(); // Recover the code _oSelectedEmployee = Controller.EmployeeService.readEmployee(_strSelectedRowCode); // We look for the employee nif this.Controller.EmployeeMgtView.AuxEmployee = _oSelectedEmployee; // We assign the employee to form employee management } } this.Controller.EmployeeMgtView.ShowDialog(); }
/// <summary> /// Method that adds selected employees on team /// </summary> private void addToTeam() { model.pojo.Employee _oSelectedEmployee = null; model.pojo.Team _oTeam = null; if (this.dgvEmployees.SelectedRows.Count >= 1) { Boolean _blAllCorrect = true; DataGridViewSelectedRowCollection _selected = dgvEmployees.SelectedRows; foreach (DataGridViewRow _row in _selected) { int _iIndexSelected = _row.Index; // Recover the index of selected row Object _cell = this.dgvEmployees.Rows[_iIndexSelected].Cells[0].Value; if (_cell != null) { String _strSelectedRowCode = _cell.ToString(); // Recover the code _oSelectedEmployee = Controller.EmployeeService.readEmployee(_strSelectedRowCode); // We look for the employee nif _oTeam = AuxTeam; model.pojo.TeamHistory _oCurrentTeam = this.Controller.TeamHistoryService.getCurrentTeamHistoryByEmployee(_oSelectedEmployee.nif, _oTeam.code); //We look if the employee already in team if (_oCurrentTeam == null) { if (_oSelectedEmployee != null && _oTeam != null) { Boolean _blAdd = this.Controller.TeamService.addToTeam(_oSelectedEmployee.nif, _oTeam.code); } } else { _blAllCorrect = false; } } } if (!_blAllCorrect) { clMessageBox.showMessage(Literal.ADD_ALL_EMPLOYEE_TO_TEAM_ERROR, false, this); } this.Close(); } }
/// <summary> /// Event that runs when the button is clicked to delete a employee /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnDeleteEmployee_Click(object sender, EventArgs e) { model.pojo.Employee _oDeleteEmployee = null; if (clMessageBox.confirmationDialog(Literal.CONFIRMATION_DELETE_EMPLOYEE, this.Text)) { _oDeleteEmployee = this.Controller.EmployeeService.deleteEmployee(AuxEmployee); if (_oDeleteEmployee != null) { clMessageBox.showMessage(Literal.DELETE_EMPLOYEE_CORRETLY, true, this); this.btnClear_Click(sender, e); this.Close(); } else { clMessageBox.showMessage(Literal.DELETE_EMPLOYEE_FAILED, false, this); } } }