コード例 #1
0
ファイル: Task.aspx.cs プロジェクト: VijayMVC/LeadForce
        /// <summary>
        /// Handles the Load event of the Page 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 Page_Load(object sender, EventArgs e)
        {
            Title = "Задача - LeadForce";

            if (!CurrentUser.Instance.ContactID.HasValue)
            {
                radWindowManager.RadAlert("Текущий пользователь не имеет контактной информации. Пожалуйста обновите данные.", 420, 100, "Предупреждение", "RedirectToTasksList");
                return;
            }

            RadAjaxManager.GetCurrent(Page).AjaxSettings.AddAjaxSetting(dcbTaskType, ucTaskDurations);
            RadAjaxManager.GetCurrent(Page).AjaxSettings.AddAjaxSetting(dcbTaskType, ucTaskMembers);
            RadAjaxManager.GetCurrent(Page).AjaxSettings.AddAjaxSetting(dcbTaskType, rtsTabs);
            RadAjaxManager.GetCurrent(Page).AjaxSettings.AddAjaxSetting(dcbTaskType, ucMainTaskMember);
            RadAjaxManager.GetCurrent(Page).AjaxSettings.AddAjaxSetting(ucSaveTaskDuration, ucTaskDurations);
            RadAjaxManager.GetCurrent(Page).AjaxSettings.AddAjaxSetting(ucTaskDurations, plDuration);
            RadAjaxManager.GetCurrent(Page).AjaxSettings.AddAjaxSetting(ucSaveTaskDuration, plDuration);
            RadAjaxManager.GetCurrent(Page).AjaxSettings.AddAjaxSetting(ucResponsible, ucTaskMembers);
            RadAjaxManager.GetCurrent(Page).AjaxSettings.AddAjaxSetting(lbtnCharg, plStatuses);
            RadAjaxManager.GetCurrent(Page).AjaxSettings.AddAjaxSetting(lbtnCharg, ucResponsible);
            RadAjaxManager.GetCurrent(Page).AjaxSettings.AddAjaxSetting(ucResponsible, upCharg);
            RadAjaxManager.GetCurrent(Page).AjaxSettings.AddAjaxSetting(rbtnRun, plResult);
            RadAjaxManager.GetCurrent(Page).AjaxSettings.AddAjaxSetting(rbtnRun, plWorkflowResult);
            RadAjaxManager.GetCurrent(Page).AjaxSettings.AddAjaxSetting(dcbProducts, ucTaskMembers);

            if (!string.IsNullOrEmpty(Request.QueryString["ctid"]))
            {
                ucTaskMembers.ContactId = Guid.Parse(Request.QueryString["ctid"]);
            }

            if (!string.IsNullOrEmpty(Request.QueryString["cyid"]))
            {
                ucTaskMembers.CompanyId = Guid.Parse(Request.QueryString["cyid"]);
            }

            ucTaskMembers.SiteId      = SiteId;
            ucTaskDurations.SiteId    = SiteId;
            ucSaveTaskDuration.SiteId = SiteId;

            ucSaveTaskDuration.SaveClicked       += ucSaveTaskDuration_SaveClicked;
            ucTaskDurations.TaskDurationsChanged += ucTaskDurations_TaskDurationsChanged;
            ucResponsible.SelectedIndexChanged   += ucResponsible_SelectedIndexChanged;
            rdpStartDate.SelectedDateChanged     += rdpStartDate_SelectedDateChanged;
            rdpEndDate.SelectedDateChanged       += rdpEndDate_SelectedDateChanged;
            dcbTaskType.SelectedIndexChanged     += dcbTaskType_SelectedIndexChanged;

            if (Page.RouteData.Values["id"] != null)
            {
                _taskId = Guid.Parse(Page.RouteData.Values["id"] as string);
            }

            ucTaskHistories.TaskId = _taskId;

            hlCancel.NavigateUrl = UrlsData.AP_Tasks();

            if (!Page.IsPostBack)
            {
                BindData();
            }
        }
コード例 #2
0
ファイル: Task.aspx.cs プロジェクト: VijayMVC/LeadForce
        /// <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 = "Ошибка обновления участников в задаче. Возможно текущие данные уже обновлены.";
            }
        }