private void TaskEditForm_Load(object sender, EventArgs e) { if (project.ProjectStatus == "C") { MessageBox.Show($"The project is finished!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); return; } if (project.ProjectMonths.Any(pm => pm.ProjectMonth == this.task.ProjectTaskdate.Month && pm.ProjectYear == this.task.ProjectTaskdate.Year)) { ProjectMonths projectMonth = project.ProjectMonths .First(pm => pm.ProjectMonth == this.task.ProjectTaskdate.Month && pm.ProjectYear == this.task.ProjectTaskdate.Year); if (projectMonth.ProjectMonthStatus == "C") { MessageBox.Show("This month is finished for the project!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); return; } } projectTextBox.Text = this.projectName; taskTextBox.Text = this.task.ProjectTask; hoursTextBox.Text = this.task.ProjectHours1.ToString(); taskDateTimePicker.Value = this.task.ProjectTaskdate; }
private void finishMonthBtn_Click(object sender, EventArgs e) { int year = int.Parse(yearComboBox.SelectedItem.ToString()); Months month = (Months)Enum.Parse(typeof(Months), monthComboBox.Text); ProjectMonths projectMonth = this.db.ProjectMonths .FirstOrDefault( pm => pm.ProjectId == this.project.ProjectId && pm.ProjectYear == year && pm.ProjectMonth == (int)month ); if (projectMonth == null) { projectMonth = new ProjectMonths() { ProjectId = this.project.ProjectId, ProjectMonth = (int)month, ProjectYear = year, ProjectMonthStatus = "C" }; this.db.ProjectMonths.Add(projectMonth); } else { projectMonth.ProjectMonthStatus = "C"; } this.db.SaveChanges(); finishMonthBtn.Visible = false; finishedMonthLabel.Visible = true; }
private void monthComboBox_SelectedIndexChanged(object sender, EventArgs e) { int year = int.Parse(yearComboBox.SelectedItem.ToString()); Months month = (Months)Enum.Parse(typeof(Months), monthComboBox.Text); decimal hoursWorked = this.project.ProjectHours .Where(ph => ph.ProjectTaskdate.Month == (int)month && ph.ProjectTaskdate.Year == year).Sum(ph => ph.ProjectHours1); workedHoursLabel.Text = $"Hours Worked: {hoursWorked}"; ProjectMonths projectMonth = this.db.ProjectMonths .FirstOrDefault( pm => pm.ProjectId == this.project.ProjectId && pm.ProjectYear == year && pm.ProjectMonth == (int)month ); if (projectMonth != null && projectMonth.ProjectMonthStatus == "C") { finishMonthBtn.Visible = false; finishedMonthLabel.Visible = true; } else { finishMonthBtn.Visible = true; finishedMonthLabel.Visible = false; } }
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { var senderGrid = (DataGridView)sender; if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex >= 0 && e.RowIndex < this.tasks.Count) { if (e.ColumnIndex == 4) { ProjectHours task = this.tasks[e.RowIndex]; TaskEditForm taskEditForm = new TaskEditForm(e.RowIndex, task, this.projectName, this.employee); taskEditForm.EditEventHandler += TaskEditForm_EditEventHandler; taskEditForm.Show(); } else if (e.ColumnIndex == 5) { Project project = this.db.Projects.Include(p => p.ProjectMonths).First(p => p.ProjectName == this.projectName); if (project.ProjectStatus == "C") { MessageBox.Show($"The project is finished!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } ProjectHours task = this.tasks[e.RowIndex]; if (project.ProjectMonths.Any(pm => pm.ProjectMonth == task.ProjectTaskdate.Month && pm.ProjectYear == task.ProjectTaskdate.Year)) { ProjectMonths projectMonth = project.ProjectMonths .First(pm => pm.ProjectMonth == task.ProjectTaskdate.Month && pm.ProjectYear == task.ProjectTaskdate.Year); if (projectMonth.ProjectMonthStatus == "C") { MessageBox.Show("This month is finished for the project!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } DialogResult result = MessageBox.Show("Are you sure you want to delete this task ?", "Delete Task", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { var args = new DeleteEventArgs() { Task = task }; DeleteEventHandler?.Invoke(this, args); dataGridView1.Rows.RemoveAt(e.RowIndex); MessageBox.Show( $"Task was successfully deleted from {this.projectName}!", "Successful Task Deletion", MessageBoxButtons.OK, MessageBoxIcon.Information ); } } } }
private bool IsValidDate(DateTime taskDate, Project project, Employee employee) { if (taskDate.CompareTo(DateTime.Now) > 0) { MessageBox.Show("Tasks for future dates cannot be added!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (taskDate.CompareTo(this.employee.EmployeeHiredate) < 0) { MessageBox.Show("The Task Date is before the hiring of the employee!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (this.employee.ProjectHours.Any(ph => ph.ProjectId == project.ProjectId && ph.ProjectTaskdate.Year == taskDate.Year && ph.ProjectTaskdate.Month == taskDate.Month && ph.ProjectTaskdate.Day == taskDate.Day)) { MessageBox.Show("The employee has already performed a task on this day!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (taskDate.CompareTo(project.ProjectBegin) < 0) { MessageBox.Show("The Task Date is before the begining of the project!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (taskDate.CompareTo(project.ProjectEnd) > 0) { MessageBox.Show("The Task Date is after the end of the project!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (project.ProjectMonths.Any(pm => pm.ProjectMonth == taskDate.Month && pm.ProjectYear == taskDate.Year)) { ProjectMonths projectMonth = project.ProjectMonths.First(pm => pm.ProjectMonth == taskDate.Month && pm.ProjectYear == taskDate.Year); if (projectMonth.ProjectMonthStatus == "C") { MessageBox.Show("This month is finished for this project!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } } return(true); }
private void TaskRegisterForm_RegisterEventHandler(object sender, TaskRegisterForm.RegisterEventArgs args) { try { DateTime taskDate = args.ProjectTask.ProjectTaskdate; decimal projectId = this.db.Projects.First(p => p.ProjectName == args.ProjectName).ProjectId; ProjectMonths projectMonth = this.db.ProjectMonths.Where(pm => pm.ProjectId == projectId && pm.ProjectMonth == taskDate.Month && pm.ProjectYear == taskDate.Year).FirstOrDefault(); if (projectMonth == null) { projectMonth = new ProjectMonths() { ProjectId = projectId, ProjectMonth = taskDate.Month, ProjectYear = taskDate.Year }; } args.ProjectTask.EmployeeId = this.employee.EmployeeId; args.ProjectTask.ProjectId = projectId; args.ProjectTask.ProjectMonth = projectMonth; db.ProjectHours.Add(args.ProjectTask); db.SaveChanges(); this.employeeTasksCount += 1; tasksCountLabel.Text = $"Number of Tasks: {this.employeeTasksCount}"; FillDataGridView(); monthComboBox_SelectedIndexChanged(null, null); MessageBox.Show( $"Task was successfully added to {args.ProjectName}!", "Successful Task Registration", MessageBoxButtons.OK, MessageBoxIcon.Information ); } catch { MessageBox.Show("An error occurred while recording the data! Please, try again!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }