private static void UpdateListResources(int objectId, DataTable items, bool checkAccess) { if (checkAccess) { VerifyCanUpdate(objectId); } int todoCompletionTypeId; bool todoManagerConfirmed; bool todoIsCompleted; int todoReasonId; int todoIncidentId = -1; int todoDocumentId = -1; int todoTaskId = -1; int todoPercentCompleted = 0; bool CompleteIncident = false; bool todoCompleteTask = false; bool todoCompleteDocument = false; string todoTitle = ""; using (IDataReader reader = DBToDo.GetToDo(objectId, Security.CurrentUser.TimeZoneId, Security.CurrentUser.LanguageId)) { reader.Read(); todoCompletionTypeId = (int)reader["CompletionTypeId"]; todoManagerConfirmed = (bool)reader["MustBeConfirmed"]; todoIsCompleted = (bool)reader["IsCompleted"]; todoReasonId = (int)reader["ReasonId"]; if (reader["IncidentId"] != DBNull.Value) { todoIncidentId = (int)reader["IncidentId"]; } if (reader["DocumentId"] != DBNull.Value) { todoDocumentId = (int)reader["DocumentId"]; } if (reader["TaskId"] != DBNull.Value) { todoTaskId = (int)reader["TaskId"]; } if (reader["CompleteIncident"] != DBNull.Value) { CompleteIncident = (bool)reader["CompleteIncident"]; } if (reader["CompleteTask"] != DBNull.Value) { todoCompleteTask = (bool)reader["CompleteTask"]; } if (reader["CompleteDocument"] != DBNull.Value) { todoCompleteDocument = (bool)reader["CompleteDocument"]; } todoPercentCompleted = (int)reader["PercentCompleted"]; todoTitle = reader["Title"].ToString(); } ArrayList oldItems = new ArrayList(); using (IDataReader reader = DBToDo.GetListResources(objectId, Security.CurrentUser.TimeZoneId)) { Common.LoadItems(reader, "UserId", oldItems); } ArrayList add = new ArrayList(); ArrayList del = new ArrayList(); foreach (DataRow row in items.Rows) { int id = (int)row["UserId"]; if (oldItems.Contains(id)) { oldItems.Remove(id); } else { add.Add(id); } } del.AddRange(oldItems); int cuid = Security.CurrentUser.UserID; using (DbTransaction tran = DbTransaction.Begin()) { foreach (int id in del) { DBCommon.DeleteGate((int)OBJECT_TYPE, objectId, id); // O.R. [2009-02-12] DBCalendar.DeleteStickedObject((int)OBJECT_TYPE, objectId, id); DBToDo.DeleteResource(objectId, id); // OZ: User Role Addon //if(todoIncidentId!=-1) //{ // UserRoleHelper.DeleteIssueTodoResourceRole(todoIncidentId, id); //} //else if (todoDocumentId != -1) { UserRoleHelper.DeleteDocumentTodoResourceRole(todoDocumentId, id); } else if (todoTaskId != -1) { UserRoleHelper.DeleteTaskTodoResourceRole(todoTaskId, id); } else { UserRoleHelper.DeleteTodoResourceRole(objectId, id); } // SystemEvents.AddSystemEvents(SystemEventTypes.Todo_Updated_ResourceList_AssignmentDeleted, objectId, id); } foreach (DataRow row in items.Rows) { int id = (int)row["UserId"]; bool mustBeConfirmed = (bool)row["MustBeConfirmed"]; bool updated = true; if (add.Contains(id)) { DbTodo2.AddResource(objectId, id, mustBeConfirmed); if (User.IsExternal(id)) { DBCommon.AddGate((int)OBJECT_TYPE, objectId, id); } // OZ: User Role Addon //if(todoIncidentId!=-1) //{ // UserRoleHelper.AddIssueTodoResourceRole(todoIncidentId, id); //} //else if (todoDocumentId != -1) { UserRoleHelper.AddDocumentTodoResourceRole(todoDocumentId, id); } else if (todoTaskId != -1) { UserRoleHelper.AddTaskTodoResourceRole(todoTaskId, id); } else { UserRoleHelper.AddTodoResourceRole(objectId, id); } // } else { updated = (0 < DbTodo2.UpdateResource(objectId, id, mustBeConfirmed)); } if (updated) { if (mustBeConfirmed) { SystemEvents.AddSystemEvents(SystemEventTypes.Todo_Updated_ResourceList_RequestAdded, objectId, id); } else { SystemEvents.AddSystemEvents(SystemEventTypes.Todo_Updated_ResourceList_AssignmentAdded, objectId, id); } } } if (todoCompletionTypeId == (int)CompletionType.All) { int overallPercent = ToDo.RecalculateOverallPercent(objectId); if (todoPercentCompleted != overallPercent) { DBToDo.UpdatePercent(objectId, overallPercent); SystemEvents.AddSystemEvents(SystemEventTypes.Todo_Updated_Percent, objectId); } // Если поручение было незавершённым, то при удалении людей, процент завершения может // увеличиться и достигнуть 100%. Если при этом не требуется подтверждения менеджера, // то произойдёт завершение todo if (!todoIsCompleted && !todoManagerConfirmed && overallPercent == 100) { DBToDo.UpdateCompletion(objectId, true, (int)CompletionReason.CompletedAutomatically); if (todoTaskId > 0 && todoCompleteTask) { ToDo.UpdateTaskCompletion(todoTaskId); } if (todoDocumentId > 0 && todoCompleteDocument) { ToDo.UpdateDocumentCompletion(todoDocumentId); } if (todoIncidentId > 0 && CompleteIncident) { ToDo.CompleteIncidentIfNeed(todoIncidentId); } ToDo.RecalculateState(objectId); } } tran.Commit(); } }
public static void DeclineResource(int todoId) { UserLight cu = Security.CurrentUser; int UserId = cu.UserID; DateTime utc_now = DateTime.UtcNow; int CompletionTypeId; bool IsManagerConfirmed; bool IsCompleted; int ReasonId; int IncidentId = -1; int DocumentId = -1; int TaskId = -1; bool CompleteIncident = false; bool CompleteTask = false; bool CompleteDocument = false; int oldPercentCompleted = 0; string title = ""; using (IDataReader reader = DBToDo.GetToDo(todoId, cu.TimeZoneId, cu.LanguageId)) { reader.Read(); CompletionTypeId = (int)reader["CompletionTypeId"]; IsManagerConfirmed = (bool)reader["MustBeConfirmed"]; IsCompleted = (bool)reader["IsCompleted"]; ReasonId = (int)reader["ReasonId"]; if (reader["IncidentId"] != DBNull.Value) { IncidentId = (int)reader["IncidentId"]; } if (reader["DocumentId"] != DBNull.Value) { DocumentId = (int)reader["DocumentId"]; } if (reader["TaskId"] != DBNull.Value) { TaskId = (int)reader["TaskId"]; } if (reader["CompleteIncident"] != DBNull.Value) { CompleteIncident = (bool)reader["CompleteIncident"]; } if (reader["CompleteTask"] != DBNull.Value) { CompleteTask = (bool)reader["CompleteTask"]; } if (reader["CompleteDocument"] != DBNull.Value) { CompleteDocument = (bool)reader["CompleteDocument"]; } oldPercentCompleted = (int)reader["PercentCompleted"]; title = reader["Title"].ToString(); } using (DbTransaction tran = DbTransaction.Begin()) { DbTodo2.ResourceReply(todoId, UserId, false); // O.R. [2009-02-12] DBCalendar.DeleteStickedObject((int)OBJECT_TYPE, todoId, UserId); SystemEvents.AddSystemEvents(SystemEventTypes.Todo_Updated_ResourceList_RequestDenied, todoId, UserId); if (CompletionTypeId == (int)CompletionType.All) { int OverallPercent = ToDo.RecalculateOverallPercent(todoId); if (oldPercentCompleted != OverallPercent) { DBToDo.UpdatePercent(todoId, OverallPercent); SystemEvents.AddSystemEvents(SystemEventTypes.Todo_Updated_Percent, todoId); } if (!IsCompleted && !IsManagerConfirmed && OverallPercent == 100) { DBToDo.UpdateCompletion(todoId, true, (int)CompletionReason.CompletedAutomatically); if (TaskId > 0 && CompleteTask) { ToDo.UpdateTaskCompletion(TaskId); } if (DocumentId > 0 && CompleteDocument) { ToDo.UpdateDocumentCompletion(DocumentId); } if (IncidentId > 0 && CompleteIncident) { ToDo.CompleteIncidentIfNeed(IncidentId); } ToDo.RecalculateState(todoId); } } tran.Commit(); } }
private static void UpdateListResources(int objectId, DataTable items, bool checkAccess) { if (checkAccess) { VerifyCanModifyResources(objectId); } int taskCompletionTypeId; bool taskMustBeConfirmed; bool taskIsCompleted; int taskReasonId; int taskProjectId; int taskPercentCompleted; using (IDataReader reader = DBTask.GetTask(objectId, Security.CurrentUser.TimeZoneId, Security.CurrentUser.LanguageId)) { reader.Read(); taskCompletionTypeId = (int)reader["CompletionTypeId"]; taskMustBeConfirmed = (bool)reader["MustBeConfirmed"]; taskIsCompleted = (bool)reader["IsCompleted"]; taskReasonId = (int)reader["ReasonId"]; taskProjectId = (int)reader["ProjectId"]; taskPercentCompleted = (int)reader["PercentCompleted"]; } int managerId = DBProject.GetProjectManager(taskProjectId); ArrayList oldItems = new ArrayList(); using (IDataReader reader = DBTask.GetListResources(objectId, Security.CurrentUser.TimeZoneId)) { Common.LoadItems(reader, "UserId", oldItems); } ArrayList add = new ArrayList(); ArrayList del = new ArrayList(); foreach (DataRow row in items.Rows) { int id = (int)row["UserId"]; if (oldItems.Contains(id)) { oldItems.Remove(id); } else { add.Add(id); } } del.AddRange(oldItems); int cuid = Security.CurrentUser.UserID; using (DbTransaction tran = DbTransaction.Begin()) { foreach (int id in del) { DBCommon.DeleteGate((int)OBJECT_TYPE, objectId, id); // O.R. [2009-02-12] DBCalendar.DeleteStickedObject((int)OBJECT_TYPE, objectId, id); DBTask.DeleteResource(objectId, id); // OZ: User Role Addon UserRoleHelper.DeleteTaskResourceRole(objectId, id); if (id != managerId) { UserRoleHelper.DeleteTaskManagerRole(objectId, id); } // SystemEvents.AddSystemEvents(SystemEventTypes.Task_Updated_ResourceList_AssignmentDeleted, objectId, id); } foreach (DataRow row in items.Rows) { int id = (int)row["UserId"]; bool mustBeConfirmed = (bool)row["MustBeConfirmed"]; bool canManage = (bool)row["CanManage"]; if (id == managerId) { canManage = true; } bool updated = true; if (add.Contains(id)) { DbTask2.AddResource(objectId, id, mustBeConfirmed, canManage); if (User.IsExternal(id)) { DBCommon.AddGate((int)OBJECT_TYPE, objectId, id); } } else { updated = (0 < DbTask2.UpdateResource(objectId, id, mustBeConfirmed, canManage)); } // OZ: User Role Addon if (id != managerId) { UserRoleHelper.DeleteTaskManagerRole(objectId, id); } UserRoleHelper.DeleteTaskResourceRole(objectId, id); if (canManage) { if (id != managerId) { UserRoleHelper.AddTaskManagerRole(objectId, id); } } else { UserRoleHelper.AddTaskResourceRole(objectId, id); } // if (updated) { if (mustBeConfirmed) { SystemEvents.AddSystemEvents(SystemEventTypes.Task_Updated_ResourceList_RequestAdded, objectId, id); } else { SystemEvents.AddSystemEvents(SystemEventTypes.Task_Updated_ResourceList_AssignmentAdded, objectId, id); } } } if (taskCompletionTypeId == (int)CompletionType.All) { int overallPercent = Task.RecalculateOverallPercent(objectId); if (taskPercentCompleted != overallPercent) { DBTask.UpdatePercent(objectId, overallPercent); SystemEvents.AddSystemEvents(SystemEventTypes.Task_Updated_Percent, objectId); } // Если задача была незавершённой, то при удалении людей, процент завершения может // увеличиться и достигнуть 100%. Если при этом не требуется подтверждения менеджера, // то произойдёт завершение задачи if (!taskIsCompleted && !taskMustBeConfirmed && overallPercent == 100) { DBTask.UpdateCompletion(objectId, true, (int)CompletionReason.CompletedAutomatically); Task.CompleteToDo(objectId); Task.RecalculateAllStates(taskProjectId); } DBTask.RecalculateSummaryPercent(objectId); } tran.Commit(); } }