Ejemplo n.º 1
0
        /// <summary>
        /// Adds the specified task history.
        /// </summary>
        /// <param name="taskHistory">The task history.</param>
        /// <returns></returns>
        public tbl_TaskHistory Add(tbl_TaskHistory taskHistory)
        {
            taskHistory.ID        = Guid.NewGuid();
            taskHistory.CreatedAt = DateTime.Now;
            _dataContext.tbl_TaskHistory.AddObject(taskHistory);
            _dataContext.SaveChanges();

            return(taskHistory);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Handles the OnClick event of the lbtnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void lbtnSave_OnClick(object sender, EventArgs e)
        {
            if (!Page.IsValid)
            {
                return;
            }

            var task       = DataManager.Task.SelectById(SiteId, _taskId) ?? new tbl_Task();
            var isWorkflow = WorkflowProcessing.IsWorkflow(_taskId);

            var needAddHistory         = false;
            var needAddCreatorReminder = false;

            if (task.ID == Guid.Empty)
            {
                needAddHistory = true;
            }
            else if (task.StartDate != rdpStartDate.SelectedDate || task.EndDate != rdpEndDate.SelectedDate || task.DateOfControl != rdpDateOfControl.SelectedDate ||
                     task.IsImportantTask != chxIsImportantTask.Checked || task.PlanDurationHours != rntxtPlanDurationHours.Value || task.PlanDurationMinutes != rntxtPlanDurationMinutes.Value ||
                     task.ResponsibleID != ucResponsible.SelectedValue || task.TaskStatusID != (int)CurrentTaskStatus || task.TaskResultID != (dcbTaskResult.SelectedId == Guid.Empty ? null : (Guid?)dcbTaskResult.SelectedId) ||
                     task.DetailedResult != txtDetailedResult.Text)
            {
                needAddHistory = true;
            }

            if (task.ID != Guid.Empty && task.TaskStatusID != (int)CurrentTaskStatus && task.CreatorID != task.ResponsibleID && (CurrentTaskStatus == TaskStatus.Completed || CurrentTaskStatus == TaskStatus.Canceled || CurrentTaskStatus == TaskStatus.Rejected))
            {
                needAddCreatorReminder = true;
            }

            task.Title = txtTitle.Text;
            if (dcbTaskType.SelectedId != Guid.Empty)
            {
                task.TaskTypeID = dcbTaskType.SelectedId;
            }

            if (rdpStartDate.SelectedDate.HasValue)
            {
                task.StartDate = (DateTime)rdpStartDate.SelectedDate;
            }

            // && (!WorkflowProcessing.IsWorkflow(_taskId) || _taskId == Guid.Empty)
            if (rdpDateOfControl.SelectedDate.HasValue && ((Guid)CurrentUser.Instance.ContactID == task.CreatorID || _taskId == Guid.Empty))
            {
                task.DateOfControl = (DateTime)rdpDateOfControl.SelectedDate;
            }

            task.IsImportantTask = chxIsImportantTask.Checked;

            var taskType = DataManager.TaskType.SelectById(SiteId, task.TaskTypeID);

            if (CheckUpdatePlanDurationRights(taskType))
            {
                if (rntxtPlanDurationHours.Value.HasValue)
                {
                    task.PlanDurationHours = (int)rntxtPlanDurationHours.Value;
                }

                if (rntxtPlanDurationMinutes.Value.HasValue)
                {
                    task.PlanDurationMinutes = (int)rntxtPlanDurationMinutes.Value;
                }

                if (rdpEndDate.SelectedDate.HasValue)
                {
                    task.EndDate = (DateTime)rdpEndDate.SelectedDate;
                }
            }
            else
            {
                task.PlanDurationHours   = taskType.StandardDurationHours;
                task.PlanDurationMinutes = taskType.StandardDurationMinutes;
                task.EndDate             = rdpStartDate.SelectedDate.Value.AddHours(taskType.StandardDurationHours).AddMinutes(taskType.StandardDurationMinutes);
            }

            task.ResponsibleID           = (Guid)ucResponsible.SelectedValue;
            task.ResponsibleReminderDate = rdpResponsibleReminderDate.SelectedDate;
            task.CreatorReminderDate     = rdpCreatorReminderDate.SelectedDate;
            task.IsUrgentTask            = chxIsUrgentTask.Checked;
            task.TaskStatusID            = (int)CurrentTaskStatus;

            if (dcbTaskResult.SelectedId != Guid.Empty)
            {
                task.TaskResultID = dcbTaskResult.SelectedId;
            }
            else
            {
                task.TaskResultID = null;
            }

            task.DetailedResult = txtDetailedResult.Text;

            if (((TaskTypeCategory)taskType.TaskTypeCategoryID) == TaskTypeCategory.LongTermTask)
            {
                task.ActualDurationHours   = ucTaskDurations.TaskDurationsList.Sum(td => td.ActualDurationHours);
                task.ActualDurationMinutes = ucTaskDurations.TaskDurationsList.Sum(td => td.ActualDurationMinutes);
                task.CompletePercentage    = CalculateCompletePercent();
            }
            else
            {
                if (CurrentTaskStatus == TaskStatus.Completed)
                {
                    var date = task.EndDate - task.StartDate;
                    task.ActualDurationHours   = date.Hours;
                    task.ActualDurationMinutes = date.Minutes;
                    task.CompletePercentage    = 100;
                }
            }

            if (dcbProducts.SelectedId != Guid.Empty)
            {
                task.ProductID = dcbProducts.SelectedId;
            }
            else
            {
                task.ProductID = null;
            }

            if (dcbOrders.SelectedId != Guid.Empty)
            {
                task.OrderID = dcbOrders.SelectedId;
            }
            else
            {
                task.OrderID = null;
            }

            if (task.ID == Guid.Empty)
            {
                task.SiteID    = SiteId;
                task.CreatorID = (Guid)CurrentUser.Instance.ContactID;
                DataManager.Task.Add(task);
            }
            else
            {
                DataManager.Task.Update(task);
            }

            var redirect = ucTaskMembers.Save(task.ID);

            if (((TaskTypeCategory)taskType.TaskTypeCategoryID) == TaskTypeCategory.LongTermTask)
            {
                ucTaskDurations.Save(task.ID);
            }

            if (taskType.TaskMembersCountID == (int)TaskMembersCount.MainPlusList || taskType.TaskMembersCountID == (int)TaskMembersCount.One)
            {
                ucMainTaskMember.Save(task.ID);
            }

            if (needAddHistory)
            {
                var taskHistory = new tbl_TaskHistory
                {
                    TaskID              = task.ID,
                    DateStart           = task.StartDate,
                    DateEnd             = task.EndDate,
                    DateOfControl       = task.DateOfControl,
                    IsImportantTask     = task.IsImportantTask,
                    PlanDurationHours   = task.PlanDurationHours,
                    PlanDurationMinutes = task.PlanDurationMinutes,
                    ResponsibleID       = task.ResponsibleID,
                    TaskStatusID        = task.TaskStatusID,
                    TaskResultID        = task.TaskResultID,
                    DetailedResult      = task.DetailedResult
                };
                DataManager.TaskHistory.Add(taskHistory);
            }

            var module = DataManager.Module.SelectByName("Tasks");

            if (rdpCreatorReminderDate.SelectedDate.HasValue)
            {
                UpdateReminder(task.CreatorID, rdpCreatorReminderDate.SelectedDate.Value, module.ID, task.ID);
            }

            if (rdpResponsibleReminderDate.SelectedDate.HasValue)
            {
                UpdateReminder(task.ResponsibleID, rdpResponsibleReminderDate.SelectedDate.Value, module.ID, task.ID);
            }

            if (needAddCreatorReminder)
            {
                UpdateReminder(task.CreatorID, DateTime.Now, module.ID, task.ID);
            }

            // Workflow
            if (isWorkflow)
            {
                switch (CurrentTaskStatus)
                {
                case TaskStatus.Completed:
                    WorkflowProcessing.Processing(WorkflowProcessing.WorkflowElementByValue(task.ID), ddlWorkflowResult.SelectedValue);
                    break;

                case TaskStatus.Canceled:
                    WorkflowProcessing.Processing(WorkflowProcessing.WorkflowElementByValue(task.ID), WorkflowProcessing.WorkflowElementResult(task.ID, "Задача отменена").ID.ToString());
                    break;
                }
            }

            if (redirect)
            {
                Response.Redirect(UrlsData.AP_Tasks());
            }
            else
            {
                ucNotificationMessage.Text = "Ошибка обновления участников в задаче. Возможно текущие данные уже обновлены.";
            }
        }