public static void CreateOrUpdateTask(decimal auditId, decimal responsiblePersonId, int recordTypeId, DateTime dueDate, string status) { var entities = new PSsqmEntities(); AUDIT audit = SelectAuditById(entities, auditId); AUDIT_TYPE type = SelectAuditTypeById(entities, audit.AUDIT_TYPE_ID); var taskMgr = new TaskStatusMgr(); taskMgr.Initialize(recordTypeId, auditId); taskMgr.LoadTaskList(recordTypeId, auditId); TASK_STATUS task = taskMgr.FindTask("0", "T", responsiblePersonId); if (task == null) { task = taskMgr.CreateTask("0", "T", 0, type.TITLE.ToString(), dueDate, responsiblePersonId); task.STATUS = ((int)TaskMgr.CalculateTaskStatus(task)).ToString(); } else { switch (status) { case "C": task.STATUS = ((int)TaskStatus.Complete).ToString(); taskMgr.SetTaskComplete(task, responsiblePersonId); break; } //task = taskMgr.UpdateTask(task, dueDate, responsiblePersonId, audit.AUDIT_TYPE_ID.ToString()); } taskMgr.UpdateTaskList(auditId); }
public static void CreateOrUpdateTask(decimal incidentId, decimal responsiblePersonId, int recordTypeId, DateTime dueDate) { var entities = new PSsqmEntities(); INCIDENT incident = SelectIncidentById(entities, incidentId); var taskMgr = new TaskStatusMgr(); taskMgr.Initialize(recordTypeId, incidentId); taskMgr.LoadTaskList(recordTypeId, incidentId); TASK_STATUS task = taskMgr.FindTask("0", "T", 0); if (task == null) { task = taskMgr.CreateTask("0", "T", 0, incident.ISSUE_TYPE, dueDate, responsiblePersonId); task.STATUS = ((int)TaskMgr.CalculateTaskStatus(task)).ToString(); } else { task = taskMgr.UpdateTask(task, dueDate, responsiblePersonId, incident.ISSUE_TYPE); } taskMgr.UpdateTaskList(incidentId); }
protected void btnTaskAdd_Click(object sender, EventArgs e) { PSsqmEntities ctx = new PSsqmEntities(); lblErrorMessage.Text = ""; Button btn = (Button)sender; if (btn == null || string.IsNullOrEmpty(btn.CommandArgument)) { return; } string[] cmd = btn.CommandArgument.Split('~'); // recordType, recordID, recordSubID, taskStep, taskType, plantID int recordType = Convert.ToInt32(cmd[0]); decimal recordID = Convert.ToDecimal(cmd[1]); decimal recordSubID = Convert.ToDecimal(cmd[2]); string taskStep = cmd[3]; string taskType = cmd[4]; decimal plantID = 0; decimal.TryParse(cmd[5], out plantID); // make sure that the Assign To Employee has been selected if (ddlAssignPersonAdd.SelectedValue.ToString().Equals("")) { // I don't think we need to bind the list at this point BindTaskAdd(recordType, recordID, recordSubID, taskStep, taskType, lblTaskDetailValueAdd.Text.ToString(), plantID, ""); lblErrorMessage.Text = lblErrRequiredInputs.Text.ToString(); string script = "function f(){OpenUpdateTaskWindow(); Sys.Application.remove_load(f);}Sys.Application.add_load(f);"; ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", script, true); } else { TaskStatusMgr taskMgr = new TaskStatusMgr(); taskMgr.Initialize(recordType, recordID); TASK_STATUS task = new TASK_STATUS(); task.RECORD_TYPE = recordType; task.RECORD_ID = recordID; task.RECORD_SUBID = recordSubID; task.TASK_STEP = taskStep; task.TASK_TYPE = taskType; task.TASK_SEQ = 0; task.DUE_DT = rdpTaskDueDTAdd.SelectedDate; task.RESPONSIBLE_ID = Convert.ToDecimal(ddlAssignPersonAdd.SelectedValue.ToString()); task.DETAIL = lblTaskDetailValueAdd.Text.ToString(); task.DESCRIPTION = tbTaskDescriptionAdd.Text.ToString(); task.STATUS = ((int)TaskStatus.New).ToString(); task.CREATE_DT = SessionManager.UserContext.LocalTime != null ? SessionManager.UserContext.LocalTime : DateTime.UtcNow; task.CREATE_ID = SessionManager.UserContext.Person.PERSON_ID; taskMgr.CreateTask(task); taskMgr.UpdateTaskList(task.RECORD_ID); // send email PERSON assignTo = SQMModelMgr.LookupPerson(ctx, (decimal)task.RESPONSIBLE_ID, "", false); EHSNotificationMgr.NotifyTaskAssigment(task, assignTo.PLANT_ID); // reset the fields for the next add ddlAssignPersonAdd.SelectedValue = ""; tbTaskDescriptionAdd.Text = ""; rdpTaskDueDTAdd.SelectedDate = DateTime.Today; if (OnTaskAdd != null) { OnTaskAdd("added", task.RECORD_ID, (decimal)task.RECORD_SUBID); } if (recordType == (int)TaskRecordType.Audit) // update the Question Status when adding tasks for an audit followup. { EHSAuditQuestion auditQuestion = EHSAuditMgr.SelectAuditQuestion(recordID, recordSubID); if (auditQuestion != null) { auditQuestion.Status = "02"; EHSAuditMgr.UpdateAnswer(auditQuestion); } //SessionManager.ReturnRecordID = task.RECORD_ID; //SessionManager.ReturnObject = "AddTask"; //SessionManager.ReturnStatus = true; } if (Page.Request.Url.ToString().Contains("AssessmentForm")) { // now update the list and stay on the popup BindTaskAdd(recordType, recordID, recordSubID, taskStep, taskType, lblTaskDetailValueAdd.Text.ToString(), plantID, ""); lblErrorMessage.Text = ""; string script = "function f(){OpenUpdateTaskWindow(); Sys.Application.remove_load(f);}Sys.Application.add_load(f);"; ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", script, true); } else { SessionManager.ReturnRecordID = task.RECORD_ID; SessionManager.ReturnObject = "AddTask"; SessionManager.ReturnStatus = true; } } }