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); }
//protected void lnkAddTask_Click(Object sender, EventArgs e) //{ // //if (OnExceptionListItemClick != null) // //{ // //LinkButton lnk = (LinkButton)sender; // //string[] cmd = lnk.CommandArgument.Split(','); // string[] cmd = lnkAddTask.CommandArgument.Split(','); // AddTask(Convert.ToDecimal(cmd[0].ToString()), Convert.ToDecimal(cmd[1].ToString())); // // call sending AuditID, QuestionID // // OnExceptionListItemClick(Convert.ToDecimal(cmd[0].ToString()), Convert.ToDecimal(cmd[1].ToString())); // //} //} 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); uclTaskList.TaskWindow(50, auditQuestion.AuditId, auditQuestion.QuestionId, "350", auditQuestion.QuestionText, (decimal)audit.DETECT_PLANT_ID); //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); }
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); }
AuditData PopulateByAuditId(decimal aid) { AuditData d = new AuditData(); var entities = new PSsqmEntities(); d.audit = EHSAuditMgr.SelectAuditById(entities, aid); if (d.audit != null) { try { string plantName = EHSAuditMgr.SelectPlantNameById((decimal)d.audit.DETECT_PLANT_ID); d.auditLocation = plantName; d.auditNumber = aid.ToString(); AUDIT_TYPE auditType = EHSAuditMgr.SelectAuditTypeById(entities, d.audit.AUDIT_TYPE_ID); d.auditType = auditType.TITLE; // do I need this? decimal auditTypeId = d.audit.AUDIT_TYPE_ID; // if I have all this, why am I redefining it? decimal companyId = d.audit.DETECT_COMPANY_ID; if (d.audit.DEPT_ID != null) { if (d.audit.DEPT_ID == 0) { d.auditDepartment = "Plant Wide"; } else { DEPARTMENT dept = SQMModelMgr.LookupDepartment(entities, (decimal)d.audit.DEPT_ID); d.auditDepartment = dept.DEPT_NAME; } } var questions = EHSAuditMgr.SelectAuditQuestionList(auditTypeId, 0, aid); d.questionList = questions; List <AUDIT_TOPIC> topics = new List <AUDIT_TOPIC>(); AUDIT_TOPIC topic = new AUDIT_TOPIC(); decimal previousTopicId = 0; foreach (EHSAuditQuestion question in questions) { if (question.TopicId != previousTopicId) { topic = new AUDIT_TOPIC(); topic.AUDIT_TOPIC_ID = question.TopicId; topic.TITLE = question.TopicTitle; topics.Add(topic); previousTopicId = question.TopicId; } } d.topicList = topics; // Date/Time d.auditDate = d.audit.AUDIT_DT.ToShortDateString(); DateTime closeDate = d.audit.AUDIT_DT.AddDays(auditType.DAYS_TO_COMPLETE); d.auditCloseDate = closeDate.ToShortDateString(); // Description d.auditDescription = d.audit.DESCRIPTION; d.auditPerson = SQMModelMgr.LookupPerson(entities, (decimal)d.audit.AUDIT_PERSON, "", false); // Audit Exception Actions foreach (TASK_STATUS ac in EHSAuditMgr.GetAuditActionList(aid, 0)) { //if (ac.RESPONSIBLE_ID.HasValue) //{ // ac.COMMENTS = SQMModelMgr.FormatPersonListItem(SQMModelMgr.LookupPerson((decimal)ac.RESPONSIBLE_ID, "")); //} d.actionList.Add(ac); } // not showing the attachments at this point, but not deleting code... just in case //var files = (from a in entities.ATTACHMENT // where // (a.RECORD_ID == aid && a.RECORD_TYPE == 40 && a.DISPLAY_TYPE > 0) && // (a.FILE_NAME.ToLower().Contains(".jpg") || a.FILE_NAME.ToLower().Contains(".jpeg") || // a.FILE_NAME.ToLower().Contains(".gif") || a.FILE_NAME.ToLower().Contains(".png") || // a.FILE_NAME.ToLower().Contains(".bmp")) // orderby a.RECORD_TYPE, a.FILE_NAME // select new // { // Data = (from f in entities.ATTACHMENT_FILE where f.ATTACHMENT_ID == a.ATTACHMENT_ID select f.ATTACHMENT_DATA).FirstOrDefault(), // Description = (string.IsNullOrEmpty(a.FILE_DESC)) ? "" : a.FILE_DESC, // }).ToList(); //if (files.Count > 0) //{ // d.photoData = new List<byte[]>(); // d.photoCaptions = new List<string>(); // foreach (var f in files) // { // d.photoData.Add(f.Data); // d.photoCaptions.Add(f.Description); // } //} } catch { } } return(d); }