示例#1
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);
        }