private decimal GetTaskLocation(TASK_STATUS task)
        {
            decimal plantID = SessionManager.UserContext.HRLocation.Plant.PLANT_ID;

            switch ((TaskRecordType)task.RECORD_TYPE)
            {
            case TaskRecordType.HealthSafetyIncident:
            case TaskRecordType.PreventativeAction:
                INCIDENT incident = EHSIncidentMgr.SelectIncidentById(new PSsqmEntities(), task.RECORD_ID);
                if (incident != null && incident.DETECT_PLANT_ID.HasValue)
                {
                    plantID = (decimal)incident.DETECT_PLANT_ID;
                }
                break;

            case TaskRecordType.Audit:
                AUDIT audit = EHSAuditMgr.SelectAuditById(new PSsqmEntities(), task.RECORD_ID);
                if (audit != null && audit.DETECT_PLANT_ID.HasValue)
                {
                    plantID = (decimal)audit.DETECT_PLANT_ID;
                }
                break;
            }

            return(plantID);
        }
        protected void AddAttach(decimal auditId, decimal questionId)
        {
            EHSAuditQuestion auditQuestion = EHSAuditMgr.SelectAuditQuestion(auditId, questionId);
            AUDIT            audit         = EHSAuditMgr.SelectAuditById(new PSsqmEntities(), auditId);
            int recordType = (int)TaskRecordType.Audit;

            // before we call the radWindow, we need to update the page?
            uclAttachWin.OpenManageAttachmentsWindow(recordType, audit.AUDIT_ID, auditQuestion.QuestionId.ToString(), Resources.LocalizedText.AttachmentsUpload.ToString(), Resources.LocalizedText.AttachmentsForAssessment.ToString());
        }
Ejemplo n.º 3
0
        protected decimal CreateReAudit(decimal auditId)
        {
            decimal       reauditId = 0;
            PSsqmEntities entities  = new PSsqmEntities();

            AUDIT oldAudit = EHSAuditMgr.SelectAuditById(entities, auditId);

            if (oldAudit != null)
            {
                // create the copy
                PLANT    auditPlant = SQMModelMgr.LookupPlant((decimal)oldAudit.DETECT_PLANT_ID);
                DateTime localTime  = WebSiteCommon.LocalTime(DateTime.UtcNow, auditPlant.LOCAL_TIMEZONE);
                AUDIT    reAudit    = new AUDIT()
                {
                    DETECT_COMPANY_ID = Convert.ToDecimal(oldAudit.DETECT_COMPANY_ID),
                    DETECT_BUS_ORG_ID = oldAudit.DETECT_BUS_ORG_ID,
                    DETECT_PLANT_ID   = oldAudit.DETECT_PLANT_ID,
                    DEPT_ID           = oldAudit.DEPT_ID,
                    AUDIT_TYPE        = oldAudit.AUDIT_TYPE,
                    CREATE_DT         = localTime,
                    CREATE_BY         = SessionManager.UserContext.Person.FIRST_NAME + " " + SessionManager.UserContext.Person.LAST_NAME,
                    DESCRIPTION       = oldAudit.DESCRIPTION,
                    CREATE_PERSON     = SessionManager.UserContext.Person.PERSON_ID,                 // do we want to set this to admin?
                    AUDIT_DT          = localTime,
                    AUDIT_TYPE_ID     = oldAudit.AUDIT_TYPE_ID,
                    AUDIT_PERSON      = SessionManager.UserContext.Person.PERSON_ID,
                    CURRENT_STATUS    = "A",
                    PERCENT_COMPLETE  = 0,
                    TOTAL_SCORE       = 0,
                    AUDITING_ID       = auditId
                };

                entities.AddToAUDIT(reAudit);
                entities.SaveChanges();
                reauditId = reAudit.AUDIT_ID;

                AUDIT_ANSWER            answer    = null;
                List <EHSAuditQuestion> questions = EHSAuditMgr.SelectAuditQuestionList(reAudit.AUDIT_TYPE_ID, 0, auditId);
                foreach (var q in questions)
                {
                    answer = new AUDIT_ANSWER()
                    {
                        AUDIT_ID               = reauditId,
                        AUDIT_QUESTION_ID      = q.QuestionId,
                        ANSWER_VALUE           = "",
                        ORIGINAL_QUESTION_TEXT = q.QuestionText,
                        //COMMENT = q.AnswerComment
                    };
                    entities.AddToAUDIT_ANSWER(answer);
                }
                entities.SaveChanges();
            }

            return(reauditId);
        }
Ejemplo n.º 4
0
        public static string SelectAuditAnswer(AUDIT audit, decimal questionId)
        {
            string answerText = null;
            var    entities   = new PSsqmEntities();

            answerText = (from a in entities.AUDIT_ANSWER
                          where a.AUDIT_ID == audit.AUDIT_ID &&
                          a.AUDIT_QUESTION_ID == questionId
                          select a.ANSWER_VALUE).FirstOrDefault();
            return(answerText);
        }
        private void AddTask(decimal auditID, decimal questionID)
        {
            int              recordType    = (int)TaskRecordType.Audit;
            AUDIT            audit         = EHSAuditMgr.SelectAuditById(new PSsqmEntities(), auditID);
            EHSAuditQuestion auditQuestion = EHSAuditMgr.SelectAuditQuestion(auditID, questionID);

            //List<TASK_STATUS> tasks = TaskMgr.AuditTaskListByRecord(recordType, auditID, questionID);
            uclTask.BindTaskAdd(recordType, auditQuestion.AuditId, auditQuestion.QuestionId, "350", "T", auditQuestion.QuestionText, (decimal)audit.DETECT_PLANT_ID, "");
            string script = "function f(){OpenUpdateTaskWindow(); Sys.Application.remove_load(f);}Sys.Application.add_load(f);";

            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", script, true);
        }
        public void BindAuditListHeader(AUDIT audit, TaskItem taskItem)
        {
            pnlIncidentTaskHdr.Visible = true;
            lblCaseDescription.Visible = lblIncidentDescription.Visible = lblActionDescription.Visible = false;

            lblIncidentDescription.Visible = true;

            if (taskItem.Plant != null)
            {
                lblCasePlant_out.Text = taskItem.Plant.PLANT_NAME;
            }
            lblResponsible_out.Text = SQMModelMgr.FormatPersonListItem(taskItem.Person);
            lblCase2ID_out.Text     = WebSiteCommon.FormatID(audit.AUDIT_ID, 6);
            lblCase2Desc_out.Text   = taskItem.Task.DESCRIPTION;
        }
Ejemplo n.º 7
0
 public AuditData()
 {
     auditNumber               = "N/A";
     auditDate                 = "N/A";
     auditLocation             = "N/A";
     auditDepartment           = "N/A";
     auditType                 = "N/A";
     auditDescription          = "N/A";
     auditCloseDate            = "N/A";
     auditPercentComplete      = "0%";
     auditTotalScore           = "0";
     auditTotalPossibleScore   = "0";
     auditTotalPercentAchieved = "0%";
     auditPerson               = null;
     audit        = null;
     topicList    = new List <AUDIT_TOPIC>();
     questionList = new List <EHSAuditQuestion>();
     actionList   = new List <TASK_STATUS>();
 }
        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);
        }
Ejemplo n.º 9
0
        public static void NotifyOnAuditCreate(decimal auditId, decimal personId)
        {
            var entities = new PSsqmEntities();

            decimal companyId = SessionManager.UserContext.HRLocation.Company.COMPANY_ID;
            decimal busOrgId  = SessionManager.UserContext.HRLocation.BusinessOrg.BUS_ORG_ID;
            var     emailIds  = new HashSet <decimal>();

            AUDIT  audit     = EHSAuditMgr.SelectAuditById(entities, auditId);
            string auditType = EHSAuditMgr.SelectAuditTypeByAuditId(auditId);

            emailIds.Add((decimal)audit.AUDIT_PERSON);

            if (emailIds.Count > 0)
            {
                string appUrl = SQMSettings.SelectSettingByCode(entities, "MAIL", "TASK", "MailURL").VALUE;
                if (string.IsNullOrEmpty(appUrl))
                {
                    appUrl = "the website";
                }

                string emailSubject = "Audit Created: " + auditType;
                string emailBody    = "A new audit has been created:<br/>" +
                                      "<br/>" +
                                      auditType + "<br/>" +
                                      "<br/>" +
                                      "Please log in to " + appUrl + auditPath + " to view the audit.";

                foreach (decimal eid in emailIds)
                {
                    string emailAddress = (from p in entities.PERSON where p.PERSON_ID == eid select p.EMAIL).FirstOrDefault();

                    Thread thread = new Thread(() => WebSiteCommon.SendEmail(emailAddress, emailSubject, emailBody, "", "web"));
                    thread.IsBackground = true;
                    thread.Start();

                    //WebSiteCommon.SendEmail(emailAddress, emailSubject, emailBody, "");
                }
            }
        }
Ejemplo n.º 10
0
        static void ScheduleAllAudits()
        {
            List <SETTINGS> sets              = SQMSettings.SelectSettingsGroup("AUTOMATE", ""); // ABW 20140805
            int             startRangeHours   = 04;
            int             startRangeMinutes = 45;
            int             endRangeHours     = 05;
            int             endRangeMinutes   = 15;

            try
            {
                startRange        = sets.Find(x => x.SETTING_CD == "AuditScheduleStart").VALUE.ToString();
                startRangeHours   = Convert.ToInt16(startRange.Substring(0, 2));
                startRangeMinutes = Convert.ToInt16(startRange.Substring(3, 2));
            }
            catch { }
            try
            {
                endRange        = sets.Find(x => x.SETTING_CD == "AuditScheduleEnd").VALUE.ToString();
                endRangeHours   = Convert.ToInt16(endRange.Substring(0, 2));
                endRangeMinutes = Convert.ToInt16(endRange.Substring(3, 2));
            }
            catch { }

            List <AUDIT_SCHEDULER> scheduler = EHSAuditMgr.SelectActiveAuditSchedulers(0, null);            // currently, we will select all schedules for all plants
            AUDIT audit = null;
            List <EHSAuditQuestion> questions = null;
            AUDIT_ANSWER            answer    = null;
            decimal  auditId = 0;
            TimeSpan start   = new TimeSpan(startRangeHours, startRangeMinutes, 0);
            TimeSpan end     = new TimeSpan(endRangeHours, endRangeMinutes, 0);

            WriteLine("Audits will be created for locations with a local time of " + startRangeHours + ":" + startRangeMinutes + " through " + endRangeHours + ":" + endRangeMinutes);
            foreach (AUDIT_SCHEDULER schedule in scheduler)
            {
                AUDIT_TYPE audittype = EHSAuditMgr.SelectAuditTypeById(entities, (decimal)schedule.AUDIT_TYPE_ID);
                // check that the audit is still active
                if (audittype != null)
                {
                    if (!audittype.INACTIVE)
                    {
                        // ABW 1/5/16 - changing the scheduler from scheduling one week of audits to creating audits that are to be scheduled that day.
                        //     All audits will be scheduled at 5am local plant time for the day.
                        //WriteLine("");
                        //WriteLine("The following " + type.TITLE + " assessments were created for Assessment Scheduler " + schedule.AUDIT_SCHEDULER_ID + ": ");
                        //// determine the date to schedule, by finding the next occurance of the selected day of the week after the current day
                        //DateTime auditDate = DateTime.Today;
                        //while ((int)auditDate.DayOfWeek != schedule.DAY_OF_WEEK)
                        //{
                        //	auditDate = auditDate.AddDays(1);
                        //}

                        // get the plant
                        PLANT auditPlant = SQMModelMgr.LookupPlant((decimal)schedule.PLANT_ID);
                        // check the local plant time to see if it is almost 5am.  If so, schedule the audit. If not, do nothing.
                        DateTime localTime = WebSiteCommon.LocalTime(DateTime.UtcNow, auditPlant.LOCAL_TIMEZONE);
                        if ((int)localTime.DayOfWeek == schedule.DAY_OF_WEEK && ((localTime.TimeOfDay > start) && (localTime.TimeOfDay < end)))
                        {
                            WriteLine("");
                            WriteLine("The following " + audittype.TITLE + " assessments were created for Assessment Scheduler " + schedule.AUDIT_SCHEDULER_ID + ": ");
                            // for the location, select all people that should get the audit
                            List <PERSON> auditors = SQMModelMgr.SelectPlantPrivgroupPersonList(auditPlant.PLANT_ID, new string[1] {
                                schedule.JOBCODE_CD
                            }, true);
                            foreach (PERSON person in auditors)
                            {
                                // check to see if there is already an audit for this plant/type/date/person
                                audit = EHSAuditMgr.SelectAuditForSchedule(auditPlant.PLANT_ID, audittype.AUDIT_TYPE_ID, person.PERSON_ID, localTime);
                                if (audit == null)
                                {
                                    // create audit header
                                    auditId = 0;
                                    audit   = new AUDIT()
                                    {
                                        DETECT_COMPANY_ID = Convert.ToDecimal(auditPlant.COMPANY_ID),
                                        DETECT_BUS_ORG_ID = auditPlant.BUS_ORG_ID,
                                        DETECT_PLANT_ID   = auditPlant.PLANT_ID,
                                        AUDIT_TYPE        = "EHS",
                                        CREATE_DT         = localTime,
                                        CREATE_BY         = "Automated Scheduler",
                                        DESCRIPTION       = audittype.TITLE,
                                        // CREATE_PERSON = SessionManager.UserContext.Person.PERSON_ID, // do we want to set this to admin?
                                        AUDIT_DT         = localTime,
                                        AUDIT_TYPE_ID    = audittype.AUDIT_TYPE_ID,
                                        AUDIT_PERSON     = person.PERSON_ID,
                                        CURRENT_STATUS   = "A",
                                        PERCENT_COMPLETE = 0,
                                        TOTAL_SCORE      = 0
                                    };

                                    entities.AddToAUDIT(audit);
                                    entities.SaveChanges();
                                    auditId = audit.AUDIT_ID;

                                    // create audit answer records
                                    questions = EHSAuditMgr.SelectAuditQuestionListByType(audittype.AUDIT_TYPE_ID);
                                    foreach (var q in questions)
                                    {
                                        answer = new AUDIT_ANSWER()
                                        {
                                            AUDIT_ID               = auditId,
                                            AUDIT_QUESTION_ID      = q.QuestionId,
                                            ANSWER_VALUE           = "",
                                            ORIGINAL_QUESTION_TEXT = q.QuestionText,
                                            //COMMENT = q.AnswerComment
                                        };
                                        entities.AddToAUDIT_ANSWER(answer);
                                    }
                                    entities.SaveChanges();
                                    // create task record for their calendar
                                    EHSAuditMgr.CreateOrUpdateTask(auditId, person.PERSON_ID, 50, localTime.AddDays(audittype.DAYS_TO_COMPLETE), "A", 0);

                                    // send an email
                                    EHSNotificationMgr.NotifyOnAuditCreate(auditId, person.PERSON_ID);
                                    System.Threading.Thread.Sleep(timer);                                     //will wait for 2 seconds to allow Google Mail to process email requests

                                    WriteLine(person.LAST_NAME + ", " + person.FIRST_NAME + " - assessment added");
                                }
                                else
                                {
                                    // ABW 1/5/16 - Since this will be running once every hour now, we don't want to see this message
                                    //WriteLine(person.LAST_NAME + ", " + person.FIRST_NAME + " - assessment already exists for this date");
                                }
                            }
                        }
                        else
                        {
                            // ABW 1/5/16 - Do we need to write any message out to explaing why the audit wasn't created?  I don't think so
                            //WriteLine("Assessment Type " + schedule.AUDIT_TYPE_ID + " - assessment already exists for this date OR is not scheduled to be created");
                        }
                    }
                    else
                    {
                        WriteLine("Assessment Type " + schedule.AUDIT_TYPE_ID + " inactive. Assessments not created for Scheduler Record " + schedule.AUDIT_SCHEDULER_ID.ToString());
                    }
                }
                else
                {
                    WriteLine("Assessment Type " + schedule.AUDIT_TYPE_ID + " not found. Assessments not created for Scheduler Record " + schedule.AUDIT_SCHEDULER_ID.ToString());
                }
            }
        }
Ejemplo n.º 11
0
        static string OverdueTaskNotifications(DateTime currentTime)
        {
            string   nextStep     = "";
            DateTime openFromDate = new DateTime(2000, 1, 1);
            DateTime localTime;
            int      execAtHour = 10;           // set exec time default to 5 am EST

            WriteLine("OVERDUE TASK NOTIFICATIONS Started: " + DateTime.UtcNow.ToString("hh:mm MM/dd/yyyy"));

            SETTINGS        setting = null;
            List <SETTINGS> sets    = SQMSettings.SelectSettingsGroup("AUTOMATE", "");

            try
            {
                // execute at specified hour of day (e.g. TASKNOTIFY_TIME == 01:00)
                if ((setting = sets.Where(x => x.SETTING_CD == "TASKNOTIFY_TIME").FirstOrDefault()) != null)
                {
                    // throwing an error here if the setting format was incorrect will be helpful for debugging
                    execAtHour = int.Parse(WebSiteCommon.SplitString(setting.VALUE, ':').First());
                }

                entities = new PSsqmEntities();

                List <PLANT> plantList = SQMModelMgr.SelectPlantList(entities, 1, 0);
                PLANT        plant     = null;

                List <TaskItem> openTaskList = TaskMgr.SelectOpenTasks(currentTime, openFromDate);
                if (openTaskList.Count > 0)
                {
                    WriteLine("Open Tasks ...");
                    foreach (TaskItem taskItem in openTaskList)
                    {
                        try
                        {
                            if (taskItem.Task.RECORD_TYPE == (int)TaskRecordType.HealthSafetyIncident)
                            {
                                INCIDENT incident = EHSIncidentMgr.SelectIncidentById(entities, taskItem.Task.RECORD_ID);
                                if (incident != null && (plant = plantList.Where(l => l.PLANT_ID == incident.DETECT_PLANT_ID).FirstOrDefault()) != null)
                                {
                                    if (execAtHour == WebSiteCommon.LocalTime(currentTime, plant.LOCAL_TIMEZONE).Hour)
                                    {
                                        WriteLine("Task: " + taskItem.Task.TASK_ID.ToString() + " RecordType:  " + taskItem.Task.RECORD_TYPE.ToString() + "  " + "RecordID:" + taskItem.Task.RECORD_ID.ToString() + "  Status = " + taskItem.Task.STATUS);
                                        // notify assigned person and escalation person if over-over due
                                        EHSNotificationMgr.NotifyIncidentTaskStatus(incident, taskItem, ((int)SysPriv.action).ToString());
                                        System.Threading.Thread.Sleep(timer);                                         //will wait for 2 seconds to allow Google Mail to process email requests

                                        if (taskItem.Taskstatus >= SQM.Website.TaskStatus.Overdue)
                                        {
                                            // send to notification list for plant, BU, ...
                                            //EHSNotificationMgr.NotifyIncidentStatus(incident, taskItem.Task.TASK_STEP, ((int)SysPriv.notify).ToString(), "");
                                            //System.Threading.Thread.Sleep(timer); //will wait for 2 seconds to allow Google Mail to process email requests
                                        }
                                    }
                                }
                                else
                                {
                                    WriteLine("Task: " + taskItem.Task.TASK_ID.ToString() + " RecordType:  " + taskItem.Task.RECORD_TYPE.ToString() + "  " + "RecordID:" + taskItem.Task.RECORD_ID.ToString() + "  Status = " + taskItem.Task.STATUS + "  This task does not have a corresponding incident or plant record");
                                }
                            }
                            else if (taskItem.Task.RECORD_TYPE == (int)TaskRecordType.PreventativeAction)
                            {
                                INCIDENT incident = EHSIncidentMgr.SelectIncidentById(entities, taskItem.Task.RECORD_ID);
                                if (incident != null && (plant = plantList.Where(l => l.PLANT_ID == incident.DETECT_PLANT_ID).FirstOrDefault()) != null)
                                {
                                    if (execAtHour == WebSiteCommon.LocalTime(currentTime, plant.LOCAL_TIMEZONE).Hour)
                                    {
                                        WriteLine("Task: " + taskItem.Task.TASK_ID.ToString() + " RecordType:  " + taskItem.Task.RECORD_TYPE.ToString() + "  " + "RecordID:" + taskItem.Task.RECORD_ID.ToString() + "  Status = " + taskItem.Task.STATUS);
                                        // notify assigned person and escalation person if over-over due
                                        EHSNotificationMgr.NotifyPrevActionTaskStatus(incident, taskItem, ((int)SysPriv.action).ToString());
                                        System.Threading.Thread.Sleep(timer);                                         //will wait for 2 seconds to allow Google Mail to process email requests
                                    }
                                }
                                else
                                {
                                    WriteLine("Task: " + taskItem.Task.TASK_ID.ToString() + " RecordType:  " + taskItem.Task.RECORD_TYPE.ToString() + "  " + "RecordID:" + taskItem.Task.RECORD_ID.ToString() + "  Status = " + taskItem.Task.STATUS + "  This task does not have a corresponding preventative action or plant record");
                                }
                            }
                            else if (taskItem.Task.RECORD_TYPE == (int)TaskRecordType.Audit)
                            {
                                AUDIT audit = EHSAuditMgr.SelectAuditById(entities, taskItem.Task.RECORD_ID);
                                if (audit != null && (plant = plantList.Where(l => l.PLANT_ID == audit.DETECT_PLANT_ID).FirstOrDefault()) != null)
                                {
                                    if (execAtHour == WebSiteCommon.LocalTime(currentTime, plant.LOCAL_TIMEZONE).Hour)
                                    {
                                        WriteLine("Task: " + taskItem.Task.TASK_ID.ToString() + " RecordType:  " + taskItem.Task.RECORD_TYPE.ToString() + "  " + "RecordID:" + taskItem.Task.RECORD_ID.ToString() + "  Status = " + taskItem.Task.STATUS);
                                        if (taskItem.Task.TASK_STEP == "0")
                                        {
                                            EHSNotificationMgr.NotifyAuditStatus(audit, taskItem);
                                            System.Threading.Thread.Sleep(timer);                                             //will wait for 2 seconds to allow Google Mail to process email requests
                                        }
                                        else
                                        {
                                            EHSNotificationMgr.NotifyAuditTaskStatus(audit, taskItem, ((int)SysPriv.action).ToString());
                                            System.Threading.Thread.Sleep(timer);                                             //will wait for 2 seconds to allow Google Mail to process email requests
                                        }
                                    }
                                }
                                else
                                {
                                    WriteLine("Task: " + taskItem.Task.TASK_ID.ToString() + " RecordType:  " + taskItem.Task.RECORD_TYPE.ToString() + "  " + "RecordID:" + taskItem.Task.RECORD_ID.ToString() + "  Status = " + taskItem.Task.STATUS + "  This task does not have a corresponding audit or plant record");
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            WriteLine("Error: " + ex.ToString());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                WriteLine("OVERDUE TASK NOTIFICATIONS Error - " + ex.ToString());
            }

            WriteLine("OVERDUE TASK NOTIFICATIONS Completed: " + DateTime.UtcNow.ToString("hh:mm MM/dd/yyyy"));

            return(nextStep);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            string pageMode = "";

            if (!string.IsNullOrEmpty(Request.QueryString["m"]))               // .../...aspx?p=xxxxx
            {
                pageMode = Request.QueryString["m"].ToLower();                 // page mode (web == running manually from the menu)
            }

            if (IsPostBack)
            {
                if (pageMode != "web")
                {
                    System.Web.UI.ScriptManager.RegisterStartupScript(this, GetType(), "closePage", "window.onunload = CloseWindow();", true);
                }
                return;
            }

            output = new StringBuilder();
            bool     validIP         = true;
            DateTime thisPeriod      = DateTime.UtcNow;
            decimal  updateIndicator = thisPeriod.Ticks;
            decimal  locationID      = 0;

            WriteLine("Started: " + DateTime.UtcNow.ToString("hh:mm MM/dd/yyyy"));

            try
            {
                string          currentIP = GetIPAddress();
                List <SETTINGS> sets      = SQMSettings.SelectSettingsGroup("AUTOMATE", "");           // ABW 20140805

                string strValidIP = sets.Find(x => x.SETTING_CD == "ValidIP").VALUE.ToString();

                /*
                 * if (strValidIP.Equals(currentIP))
                 * {
                 *      WriteLine("Main Incident RollUp being accessed from a valid IP address " + currentIP);
                 *      validIP = true;
                 *
                 *      if (Request.QueryString["validation"] != null)
                 *      {
                 *              if (Request.QueryString["validation"].ToString().Equals("Vb12M11a4"))
                 *                      validIP = true;
                 *      }
                 *      else
                 *      {
                 *              WriteLine("Main Incident RollUp requested from incorrect source.");
                 *              validIP = false;
                 *      }
                 * }
                 * else
                 * {
                 *      WriteLine("Main Incident RollUp being accessed from invalid IP address " + currentIP);
                 *      validIP = false;
                 * }
                 */
            }
            catch (Exception ex)
            {
                validIP = false;
                WriteLine("Main Email Notification Error validating IP Address: " + ex.ToString());
            }

            // make sure this code is NOT moved to production
            validIP = true;

            if (!validIP)
            {
                WriteLine("Main Incident RollUp Invalid IP Address");
                ltrStatus.Text = output.ToString().Replace("\n", "<br/>");
                WriteLogFile();

                System.Web.UI.ScriptManager.RegisterStartupScript(this, GetType(), "closePage", "window.onunload = CloseWindow();", true);
                return;
            }

            try
            {
                PSsqmEntities entities = new PSsqmEntities();

                List <TaskItem> openAuditList = TaskMgr.SelectOpenAudits(DateTime.UtcNow, DateTime.UtcNow);
                if (openAuditList.Count > 0)
                {
                    WriteLine("Open Audits ...");
                    foreach (TaskItem taskItem in openAuditList)
                    {
                        WriteLine("Audit: " + taskItem.Task.RECORD_ID.ToString() + "  Status = " + taskItem.Task.STATUS);
                        AUDIT audit = EHSAuditMgr.SelectAuditById(entities, taskItem.Task.RECORD_ID);
                        if (audit != null)
                        {
                            EHSNotificationMgr.NotifyAuditStatus(audit, taskItem);
                        }
                    }
                }

                List <TaskItem> openTaskList = TaskMgr.SelectOpenTasks(DateTime.UtcNow, DateTime.UtcNow);
                if (openTaskList.Count > 0)
                {
                    WriteLine("Open Tasks ...");
                    foreach (TaskItem taskItem in openTaskList)
                    {
                        WriteLine("Task: " + taskItem.Task.TASK_ID.ToString() + " RecordType:  " + taskItem.Task.RECORD_TYPE.ToString() + "  " + "RecordID:" + taskItem.Task.RECORD_ID.ToString() + "  Status = " + taskItem.Task.STATUS);
                        if (taskItem.Task.RECORD_TYPE == (int)TaskRecordType.HealthSafetyIncident)
                        {
                            INCIDENT incident = EHSIncidentMgr.SelectIncidentById(entities, taskItem.Task.RECORD_ID);
                            if (incident != null)
                            {
                                // notify assigned person and escalation person if over-over due
                                EHSNotificationMgr.NotifyIncidentTaskStatus(incident, taskItem, ((int)SysPriv.action).ToString());
                                if (taskItem.Taskstatus >= TaskStatus.Overdue)
                                {
                                    // send to notification list for plant, BU, ...
                                    EHSNotificationMgr.NotifyIncidentStatus(incident, taskItem.Task.TASK_STEP, ((int)SysPriv.notify).ToString(), "");
                                }
                            }
                        }
                        else if (taskItem.Task.RECORD_TYPE == (int)TaskRecordType.PreventativeAction)
                        {
                            INCIDENT incident = EHSIncidentMgr.SelectIncidentById(entities, taskItem.Task.RECORD_ID);
                            if (incident != null)
                            {
                                // notify assigned person and escalation person if over-over due
                                EHSNotificationMgr.NotifyPrevActionTaskStatus(incident, taskItem, ((int)SysPriv.action).ToString());
                            }
                        }
                        else if (taskItem.Task.RECORD_TYPE == (int)TaskRecordType.Audit)
                        {
                            AUDIT audit = EHSAuditMgr.SelectAuditById(entities, taskItem.Task.RECORD_ID);
                            if (audit != null)
                            {
                                EHSNotificationMgr.NotifyAuditTaskStatus(audit, taskItem, ((int)SysPriv.action).ToString());
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                WriteLine("Main Email Notificaion Error - " + ex.ToString());
            }

            WriteLine("");
            WriteLine("Completed: " + DateTime.UtcNow.ToString("hh:mm MM/dd/yyyy"));
            ltrStatus.Text = output.ToString().Replace("\n", "<br/>");
            WriteLogFile();

            System.Web.UI.ScriptManager.RegisterStartupScript(this, GetType(), "closePage", "window.onunload = CloseWindow();", true);
        }
Ejemplo n.º 13
0
        static void ScheduleAllAudits()
        {
            List <AUDIT_SCHEDULER> scheduler = EHSAuditMgr.SelectActiveAuditSchedulers(0, null);            // currently, we will select all schedules for all plants
            AUDIT audit = null;
            List <EHSAuditQuestion> questions = null;
            AUDIT_ANSWER            answer    = null;
            decimal auditId = 0;

            foreach (AUDIT_SCHEDULER schedule in scheduler)
            {
                AUDIT_TYPE type = EHSAuditMgr.SelectAuditTypeById(entities, (decimal)schedule.AUDIT_TYPE_ID);
                // check that the audit is still active
                if (type != null)
                {
                    if (!type.INACTIVE)
                    {
                        WriteLine("");
                        WriteLine("The following " + type.TITLE + " audits were created for Audit Scheduler " + schedule.AUDIT_SCHEDULER_ID + ": ");
                        // determine the date to schedule, by finding the next occurance of the selected day of the week after the current day
                        DateTime auditDate = DateTime.Today;
                        while ((int)auditDate.DayOfWeek != schedule.DAY_OF_WEEK)
                        {
                            auditDate = auditDate.AddDays(1);
                        }
                        // get the plant
                        PLANT auditPlant = SQMModelMgr.LookupPlant((decimal)schedule.PLANT_ID);
                        // for the location, select all people that should get the audit
                        List <PERSON> auditors = SQMModelMgr.SelectPlantPrivgroupPersonList(auditPlant.PLANT_ID, new string[1] {
                            schedule.JOBCODE_CD
                        });
                        foreach (PERSON person in auditors)
                        {
                            // check to see if there is already an audit for this plant/type/date/person
                            audit = EHSAuditMgr.SelectAuditForSchedule(auditPlant.PLANT_ID, type.AUDIT_TYPE_ID, person.PERSON_ID, auditDate);
                            if (audit == null)
                            {
                                // create audit header
                                auditId = 0;
                                audit   = new AUDIT()
                                {
                                    DETECT_COMPANY_ID = Convert.ToDecimal(auditPlant.COMPANY_ID),
                                    DETECT_BUS_ORG_ID = auditPlant.BUS_ORG_ID,
                                    DETECT_PLANT_ID   = auditPlant.PLANT_ID,
                                    AUDIT_TYPE        = "EHS",
                                    CREATE_DT         = DateTime.Now,
                                    CREATE_BY         = "Automated Scheduler",
                                    DESCRIPTION       = type.TITLE,
                                    // CREATE_PERSON = SessionManager.UserContext.Person.PERSON_ID, // do we want to set this to admin?
                                    AUDIT_DT         = auditDate,
                                    AUDIT_TYPE_ID    = type.AUDIT_TYPE_ID,
                                    AUDIT_PERSON     = person.PERSON_ID,
                                    CURRENT_STATUS   = "A",
                                    PERCENT_COMPLETE = 0,
                                    TOTAL_SCORE      = 0
                                };

                                entities.AddToAUDIT(audit);
                                entities.SaveChanges();
                                auditId = audit.AUDIT_ID;

                                // create audit answer records
                                questions = EHSAuditMgr.SelectAuditQuestionList(type.AUDIT_TYPE_ID, 0, 0);                                 // do not specify the audit ID
                                foreach (var q in questions)
                                {
                                    answer = new AUDIT_ANSWER()
                                    {
                                        AUDIT_ID               = auditId,
                                        AUDIT_QUESTION_ID      = q.QuestionId,
                                        ANSWER_VALUE           = q.AnswerText,
                                        ORIGINAL_QUESTION_TEXT = q.QuestionText,
                                        COMMENT = q.AnswerComment
                                    };
                                    entities.AddToAUDIT_ANSWER(answer);
                                }
                                entities.SaveChanges();
                                // create task record for their calendar
                                EHSAuditMgr.CreateOrUpdateTask(auditId, person.PERSON_ID, 50, auditDate.AddDays(type.DAYS_TO_COMPLETE), "A");

                                // send an email
                                EHSNotificationMgr.NotifyOnAuditCreate(auditId, person.PERSON_ID);

                                WriteLine(person.LAST_NAME + ", " + person.FIRST_NAME + " - audit added");
                            }
                            else
                            {
                                WriteLine(person.LAST_NAME + ", " + person.FIRST_NAME + " - audit already exists for this date");
                            }
                        }
                    }
                    else
                    {
                        WriteLine("Adit Type " + schedule.AUDIT_TYPE_ID + " inactive. Audits not created for Scheduler Record " + schedule.AUDIT_SCHEDULER_ID.ToString());
                    }
                }
                else
                {
                    WriteLine("Adit Type " + schedule.AUDIT_TYPE_ID + " not found. Audits not created for Scheduler Record " + schedule.AUDIT_SCHEDULER_ID.ToString());
                }
            }
        }