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 lnkDeleteTask_OnClick(object sender, EventArgs e)
        {
            // we are only marking the status as deleteded, not physically deleting the task.
            lblErrorMessage.Text = "";
            LinkButton btn = (LinkButton)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));

            taskMgr.UpdateTaskStatus(task, TaskStatus.Delete);
            taskMgr.UpdateTask(task);
            taskMgr.UpdateTaskList(task.RECORD_ID);
            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;
            }
        }
        private void UpdateSelectedTask(decimal taskID)
        {
            TaskStatusMgr taskMgr = new TaskStatusMgr().CreateNew(0, 0);
            TASK_STATUS   task    = taskMgr.SelectTask(taskID);

            uclTask.BindTaskUpdate(task, "");
        }
        private void UpdateSelectedTask(decimal taskID)
        {
            TaskStatusMgr taskMgr = new TaskStatusMgr().CreateNew(0, 0);
            TASK_STATUS   task    = taskMgr.SelectTask(taskID);

            SessionManager.ReturnObject = task;
            SessionManager.ReturnStatus = true;
            SessionManager.ReturnPath   = (Request.Path.ToString() + "?v=T");            // return to action/task view
            Response.Redirect("/Home/TaskAction.aspx");
        }
        protected void lblDueDate_OnClick(object sender, EventArgs e)
        {
            lblErrorMessage.Text = "";
            LinkButton btn = (LinkButton)sender;

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

            PSsqmEntities ctx = new PSsqmEntities();
            int           recordType;
            TaskStatusMgr taskMgr = new TaskStatusMgr().CreateNew(0, 0);
            TASK_STATUS   task    = new TASK_STATUS();

            AUDIT audit = new AUDIT();

            try
            {
                decimal recordID = Convert.ToDecimal(btn.CommandArgument.ToString());
                if (TaskXLATList == null || TaskXLATList.Count == 0)
                {
                    TaskXLATList = SQMBasePage.SelectXLATList(new string[5] {
                        "TASK_STATUS", "RECORD_TYPE", "INCIDENT_STATUS", "NOTIFY_SCOPE_TASK", "ACTION_CATEGORY"
                    });
                }
                task = taskMgr.SelectTask(recordID);
                BindTaskUpdate(task, "");
            }
            catch (Exception ex)
            {
                lblErrorMessage.Text = ex.Message.ToString();
            }
            pnlAddTask.Visible    = false;
            pnlUpdateTask.Visible = true;

            string script = "function f(){OpenUpdateTaskWindow(); Sys.Application.remove_load(f);}Sys.Application.add_load(f);";

            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", script, true);
        }
        protected void btnTaskComplete_Click(object sender, EventArgs e)
        {
            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.COMMENTS = tbTaskComments.Text;
            task.STATUS   = ((int)TaskStatus.Complete).ToString();
            task          = taskMgr.SetTaskComplete(task, SessionManager.UserContext.Person.PERSON_ID);
            taskMgr.UpdateTask(task);

            if (OnTaskUpdate != null)
            {
                OnTaskUpdate("update");
            }
        }
        protected void btnTaskAssign_Click(object sender, EventArgs e)
        {
            PSsqmEntities ctx = new PSsqmEntities();
            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));

            btnAssignSave.CommandArgument = task.TASK_ID.ToString();

            decimal          plantID  = GetTaskLocation(task);
            BusinessLocation location = new BusinessLocation().Initialize(plantID);
            // AW 20161229 - if they get this far, they can assign the task to anyone in a plant that they have access...
            //SysPriv maxPriv = UserContext.GetMaxScopePrivilege(SysScope.busloc);
            //if (maxPriv <= SysPriv.config)  // is a plant admin or greater ?
            //{
            List <BusinessLocation> locationList = SessionManager.PlantList;

            locationList = UserContext.FilterPlantAccessList(locationList);

            if (locationList.Select(l => l.Plant.BUS_ORG_ID).Distinct().Count() > 1 && SessionManager.IsUserAgentType("ipad,iphone") == false)
            {
                ddlScheduleScope.Visible = false;
                mnuScheduleScope.Visible = true;
                SQMBasePage.SetLocationList(mnuScheduleScope, locationList, location.Plant.PLANT_ID, location.Plant.PLANT_NAME, "TOP", true);
                //RadMenuItem mi = new RadMenuItem();
                //mi.Text = (SessionManager.UserContext.Person.FIRST_NAME + " " + SessionManager.UserContext.Person.LAST_NAME);
                //mi.Value = "0";
                //mi.ImageUrl = "~/images/defaulticon/16x16/user-alt-2.png";
                //mnuScheduleScope.Items[0].Items.Insert(0, mi);
            }
            else
            {
                ddlScheduleScope.Visible = true;
                mnuScheduleScope.Visible = false;
                SQMBasePage.SetLocationList(ddlScheduleScope, locationList, location.Plant.PLANT_ID, true);
            }
            //}
            //else
            //{
            //	ddlScheduleScope.Visible = true;
            //	mnuScheduleScope.Visible = false;
            //	//ddlScheduleScope.Items.Insert(0, new RadComboBoxItem((SessionManager.UserContext.Person.FIRST_NAME + " " + SessionManager.UserContext.Person.LAST_NAME), "0"));
            //	//ddlScheduleScope.Items[0].ImageUrl = "~/images/defaulticon/16x16/user-alt-2.png";
            //}


            List <PERSON> personList = SQMModelMgr.SelectPlantPersonList(1, plantID).Where(l => !string.IsNullOrEmpty(l.EMAIL)).OrderBy(l => l.LAST_NAME).ToList();

            SQMBasePage.SetPersonList(ddlAssignPerson, personList, "", 0, false, "LF");
            tbAssignComment.Text = task.COMMENTS;

            string script = "function f(){OpenAssignTaskWindow(); Sys.Application.remove_load(f);}Sys.Application.add_load(f);";

            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", script, true);
        }
        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");
                }
            }
        }