private void editEmployeeBtn_Click(object sender, EventArgs e) { string name = nameTextBox.Text; string surname = surnameTextBox.Text; string lastName = lastNameTextBox.Text; string egn = egnTextBox.Text; string position = positionComboBox.Text; DateTime hireDate = hireDateTimePicker.Value; if (IsValidName(name, "Name") && IsValidName(surname, "Surname") && IsValidName(lastName, "Last Name") && IsValidEgn(egn) && IsValidPosition(position) && IsValidHireDate(hireDate, (DateTime)employee.EmployeeHiredate)) { employee.EmployeeName = name; employee.EmployeeSurname = surname; employee.EmployeeLastname = lastName; employee.EmployeeEgn = egn; employee.EmployeePosition = position; employee.EmployeeHiredate = hireDate; EditEventArgs args = new EditEventArgs(); args.RowIndex = rowIndex; args.Employee = employee; EditEventHandler?.Invoke(this, args); this.Close(); } }
private void editTaskBtn_Click(object sender, EventArgs e) { int taskHours = 0; string task = taskTextBox.Text; decimal employeeMaxWorkingHoursOnProject = project.ProjectMaxhours != null ? (decimal)project.ProjectMaxhours : (decimal)int.MaxValue; decimal employeeCurrentWorkingHoursOnProject = this.employee.ProjectHours.Where(ph => ph.ProjectId == project.ProjectId).Sum(ph => ph.ProjectHours1) - this.task.ProjectHours1; if (IsValidTask(task) && IsValidHours(ref taskHours, employeeCurrentWorkingHoursOnProject, employeeMaxWorkingHoursOnProject)) { this.task.ProjectTask = task; this.task.ProjectHours1 = taskHours; var args = new EditEventArgs() { RowIndex = this.rowIndex, Task = this.task }; EditEventHandler?.Invoke(this, args); this.Close(); } }
private void TaskEditForm_EditEventHandler(object sender, TaskEditForm.EditEventArgs args) { try { if ((bool)EditEventHandler?.Invoke(this)) { dataGridView1.Rows.Remove(dataGridView1.Rows[args.RowIndex]); dataGridView1.Rows.Insert(args.RowIndex, args.Task.ToDataView(this.projectName)); MessageBox.Show( $"Task was successfully edited!", "Successful Task Update", MessageBoxButtons.OK, MessageBoxIcon.Information ); } } catch { MessageBox.Show("An error occurred while recording the changes! Please, try again!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }