private void BtnWorkerCompleteWorkCancel_Click(object sender, EventArgs e) { if (SelectedWorkerProject().State == ProjectState.Canceled || SelectedWorkerProject().State == ProjectState.Completed) { MessageBox.Show("Изменение отмененого или завершенного проекта не возможно", "Сообщение об ошибке", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } int idWorkInProject = SelectedWorkerWorkInProject().Id; var selectedCells = dgvWorkerModel.SelectedCells; List <WorkLog> completeWorkLogs = new List <WorkLog>(); try { foreach (DataGridViewCell cell in selectedCells) { int idElement = (int)cell.Tag; if (ElementHasWork(idElement, idWorkInProject)) { var workByElement = GetWorkByElement(idElement, idWorkInProject); WorkLog workLog = workByElement.GetCompleteLog2Delete(actualUser.Id, driver); if (workLog.Id != -1) { completeWorkLogs.Add(workLog); } } } if (completeWorkLogs.Count == 0) { MessageBox.Show($"Нет элементов для отмены выполнения", "Отмена выполнения", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } WorkByElement.DeleteWorkLogsComplete(completeWorkLogs, driver); ShowWorkerProjects(); ShowUserData(); workerModel.ShowModel(SelectedWorkerSectionOfBuilding()); workerModel.ShowWorkInModel(SelectedWorkerWorkInProject()); ShowWorkerWorksInProject(); MessageBox.Show($"Отмена выполнения работы для {completeWorkLogs.Count} элементов", "Отмена выполнения", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, "Сообщение об ошибке", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public WorkLog GetAcceptLog2Delete(int idActualUser, IDriverDB driver) { if (State != WorkState.Accepted) { return(new WorkLog()); } WorkLog acceptLog2Delete = driver.GetAcceptLog(id); if (idActualUser == acceptLog2Delete.IdUser) { return(acceptLog2Delete); } return(new WorkLog()); }
public WorkLog GetRejectLog2Delete(int idActualUser, IDriverDB driver) { if (State != WorkState.Rejected) { return(new WorkLog()); } WorkLog rejectLog2Delete = driver.GetLastRejectLog(id); if (idActualUser == rejectLog2Delete.IdUser) { return(rejectLog2Delete); } return(new WorkLog()); }
public WorkLog GetCompleteLog2Delete(int idActualUser, IDriverDB driver) { if (State != WorkState.Completed) { return(new WorkLog()); } WorkLog lastCompleteLog = driver.GetLastCompleteLog(id); if (idActualUser == lastCompleteLog.IdUser) { return(lastCompleteLog); } return(new WorkLog()); }
private void BtnSectionOfBuildingAcceptWorkCancel_Click(object sender, EventArgs e) { if (actualProject.State != ProjectState.Actual) { MessageBox.Show("Учет работ возможен только для текущего проекта", "Сообщение об ошибке", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } int idWorkInProject = SelectedWorkInProjectInSectionOfBuilding().Id; var selectedCells = dgvManagerModel.SelectedCells; List <WorkLog> acceptWorkLogs = new List <WorkLog>(); try { foreach (DataGridViewCell cell in selectedCells) { int idElement = (int)cell.Tag; if (ElementHasWork(idElement, idWorkInProject)) { var workByElement = GetWorkByElement(idElement, idWorkInProject); WorkLog workLog = workByElement.GetAcceptLog2Delete(actualUser.Id, driver); if (workLog.Id != -1) { acceptWorkLogs.Add(workLog); } } } if (acceptWorkLogs.Count == 0) { MessageBox.Show($"Нет элементов для отмены приемки", "Отмена приемки", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } WorkByElement.DeleteWorkLogsAccept(acceptWorkLogs, driver); managerModel.ShowWorkInModel(SelectedWorkInProjectInSectionOfBuilding()); ShowActualProject(); ShowProjects(); ShowWorksInProjectInSectionOfBuilding(); MessageBox.Show($"Отменa приемки работы для {acceptWorkLogs.Count} элементов", "Отмена приемки", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, "Сообщение об ошибке", MessageBoxButtons.OK, MessageBoxIcon.Error); } }