protected void btnTaskAssignUpdate_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;

            if (btn == null || string.IsNullOrEmpty(btn.CommandArgument))
            {
                return;
            }

            if (ddlAssignPerson.SelectedItem != null)
            {
                TaskStatusMgr taskMgr = new TaskStatusMgr().CreateNew(0, 0);
                TASK_STATUS   task    = taskMgr.SelectTask(Convert.ToDecimal(btn.CommandArgument));
                task.COMMENTS       = tbAssignComment.Text;
                task.STATUS         = ((int)TaskStatus.New).ToString();
                task.RESPONSIBLE_ID = Convert.ToDecimal(ddlAssignPerson.SelectedValue);
                taskMgr.UpdateTask(task);
                // send email
                EHSNotificationMgr.NotifyTaskAssigment(task, 0);
            }

            if (OnTaskUpdate != null)
            {
                OnTaskUpdate("update");
            }
        }
        protected void btnTaskUpdate_Click(object sender, EventArgs e)
        {
            PSsqmEntities ctx = new PSsqmEntities();

            lblErrorMessage.Text = "";
            Button btn = (Button)sender;

            if (btn == null || string.IsNullOrEmpty(btn.CommandArgument))
            {
                return;
            }

            TaskStatusMgr taskMgr = new TaskStatusMgr().CreateNew(0, 0);
            TASK_STATUS   task    = taskMgr.SelectTask(Convert.ToDecimal(btn.CommandArgument));

            //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 = rdpTaskDueDT.SelectedDate;
            //task.RESPONSIBLE_ID = Convert.ToDecimal(ddlAssignPerson.SelectedValue.ToString());
            //task.DETAIL = lblTaskDetailValue.Text.ToString(); // this is the original detail, so we don't change it.
            //task.DESCRIPTION = tbTaskDescription.Text.ToString();
            task.COMMENTS = tbTaskComments.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.UpdateTask(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 (task.RECORD_TYPE == (int)TaskRecordType.Audit)             // update the Question Status when adding tasks for an audit followup.
            {
                EHSAuditQuestion auditQuestion = EHSAuditMgr.SelectAuditQuestion(task.RECORD_ID, (decimal)task.RECORD_SUBID);

                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 if adding through assessment form
                BindTaskAdd(task.RECORD_TYPE, task.RECORD_ID, (decimal)task.RECORD_SUBID, task.TASK_STEP, task.TASK_TYPE, lblTaskDetailValue.Text.ToString(), assignTo.PLANT_ID, "");
                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   = "UpdateTask";
                SessionManager.ReturnStatus   = true;

                if (OnTaskUpdate != null)
                {
                    OnTaskUpdate("update");
                }
            }
        }
        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;
                }
            }
        }