protected string GetPlantName(decimal auditId) { string content = ""; content = EHSAuditMgr.SelectAuditLocationNameByAuditId(auditId); return(content); }
static void UpdatePastDueAuditStatus() { string status = ""; // get a list of all audits that do not have a close date List <AUDIT> openAudits = EHSAuditMgr.SelectOpenAudits(0, null); foreach (AUDIT audit in openAudits) { AUDIT_TYPE type = EHSAuditMgr.SelectAuditTypeById(entities, audit.AUDIT_TYPE_ID); PLANT plant = SQMModelMgr.LookupPlant((decimal)audit.DETECT_PLANT_ID); DateTime closeDT = Convert.ToDateTime(audit.AUDIT_DT.AddDays(type.DAYS_TO_COMPLETE + 1)); // add one to the date and it will default to the next day at 00:00:00, which means midnight DateTime localTime = WebSiteCommon.LocalTime(DateTime.UtcNow, plant.LOCAL_TIMEZONE); if (closeDT.CompareTo(localTime) < 0) { // close the audit // valid status codes... A = active, C = complete, I = incomplete/in-process, E = Expired. We are closing audits that are past due, so Expired. try { status = audit.CURRENT_STATUS; if (status != "C") { status = "E"; } } catch { status = "E"; } EHSAuditMgr.CloseAudit(audit.AUDIT_ID, status, closeDT.AddDays(-1)); // now take the one day back off so that the close date sets correctly // now mark the Task as expired too! EHSAuditMgr.CreateOrUpdateTask(audit.AUDIT_ID, (decimal)audit.AUDIT_PERSON, 50, closeDT.AddDays(-1), status, 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); }
//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); }
private void UpdateTaskList(string cmd, decimal recordID, decimal recordSubID) { // update the status when a task is added if (cmd == "added") { EHSAuditQuestion auditQuestion = EHSAuditMgr.SelectAuditQuestion(recordID, recordSubID); if (auditQuestion != null) { auditQuestion.Status = "02"; EHSAuditMgr.UpdateAnswer(auditQuestion); } //SearchAudits(); } }
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()); } } }
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); }
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()); } } }
protected void Page_PreRender(object sender, EventArgs e) { bool createAuditAccess = SessionManager.CheckUserPrivilege(SysPriv.config, SysScope.audit); var sourceId = Page.Request[Page.postEventSourceID]; if (IsPostBack) { if (!uclAssessmentForm.IsEditContext) { RadPersistenceManager1.StorageProviderKey = SessionManager.UserContext.Person.PERSON_ID.ToString(); RadPersistenceManager1.SaveState(); } if (SessionManager.ReturnStatus == true) { if (SessionManager.ReturnObject is string) { string type = SessionManager.ReturnObject as string; string auditStatus = ""; switch (type) { case "DisplayAudits": rbNew.Visible = createAuditAccess; UpdateDisplayState(DisplayState.AuditList); break; case "Notification": //UpdateDisplayState(DisplayState.AuditNotificationEdit); //UpdateDisplayState(DisplayState.AuditReportEdit); uclAssessmentForm.EditAuditId = SessionManager.ReturnRecordID; // need to determine if the Audit is past due and force it into display mode (probelm when coming from Calendar) auditStatus = EHSAuditMgr.SelectAuditStatus(SessionManager.ReturnRecordID); rbNew.Visible = false; if (auditStatus == "C") { UpdateDisplayState(DisplayState.AuditNotificationDisplay); } else { UpdateDisplayState(DisplayState.AuditNotificationEdit); } if (isDirected) { uclAssessmentForm.EnableReturnButton(false); } break; case "ReAudit": decimal reauditId = CreateReAudit(SessionManager.ReturnRecordID); if (reauditId > 0) { SessionManager.ReturnRecordID = reauditId; uclAssessmentForm.EditAuditId = reauditId; rbNew.Visible = false; UpdateDisplayState(DisplayState.AuditNotificationEdit); if (isDirected) { uclAssessmentForm.EnableReturnButton(false); } } else { // probably need to show some sort of error message... rbNew.Visible = createAuditAccess; UpdateDisplayState(DisplayState.AuditList); } break; case "Closed": uclAssessmentForm.EditAuditId = SessionManager.ReturnRecordID; UpdateDisplayState(DisplayState.AuditNotificationClosed); rbNew.Visible = false; if (isDirected) { uclAssessmentForm.EnableReturnButton(false); } break; case "DisplayOnly": uclAssessmentForm.EditAuditId = SessionManager.ReturnRecordID; UpdateDisplayState(DisplayState.AuditNotificationDisplay); rbNew.Visible = false; if (isDirected) { uclAssessmentForm.EnableReturnButton(false); } break; case "AddAttachment": case "AddTask": //UpdateDisplayState(DisplayState.AuditNotificationEdit); //UpdateDisplayState(DisplayState.AuditReportEdit); uclAssessmentForm.EditAuditId = SessionManager.ReturnRecordID; // need to determine if the Audit is past due and force it into display mode (probelm when coming from Calendar) auditStatus = EHSAuditMgr.SelectAuditStatus(SessionManager.ReturnRecordID); rbNew.Visible = false; if (auditStatus == "C") { UpdateDisplayState(DisplayState.AuditNotificationDisplay); } else { UpdateDisplayState(DisplayState.AuditNotificationEdit); } if (isDirected) { uclAssessmentForm.EnableReturnButton(false); } break; } } SessionManager.ClearReturns(); } } else { uclAssessmentForm.EditReturnState = "NeedsRefresh"; if (SessionManager.ReturnStatus == true && SessionManager.ReturnObject is string) { try { // from inbox DisplayNonPostback(); SessionManager.ReturnRecordID = Convert.ToDecimal(SessionManager.ReturnObject.ToString()); SessionManager.ReturnObject = "Notification"; SessionManager.ReturnStatus = true; isDirected = true; StringBuilder sbScript = new StringBuilder(); ClientScriptManager cs = Page.ClientScript; sbScript.Append("<script language='JavaScript' type='text/javascript'>\n"); sbScript.Append("<!--\n"); sbScript.Append(cs.GetPostBackEventReference(this, "PBArg") + ";\n"); sbScript.Append("// -->\n"); sbScript.Append("</script>\n"); cs.RegisterStartupScript(this.GetType(), "AutoPostBackScript", sbScript.ToString()); } catch { // not a number, parse as type DisplayNonPostback(); } } else { DisplayNonPostback(); } } // for now, we will only let 'admin' create audits //if (!SessionManager.UserContext.Person.SSO_ID.ToLower().Equals("admin")) // rbNew.Visible = false; rbNew.Visible = createAuditAccess; }
protected void ddlChartTypeChange(object sender, EventArgs e) { divChart.ViewStateMode = System.Web.UI.ViewStateMode.Disabled; //if (ddlChartType.SelectedValue == "" || HSCalcs().ehsCtl.IncidentHst == null || HSCalcs().ehsCtl.IncidentHst.Count == 0) if (ddlChartType.SelectedValue == "") { pnlChartSection.Style.Add("display", "none"); lnkChartClose.Visible = lnkPrint.Visible = false; } else { //PERSPECTIVE_VIEW view = null; //divSummaryCharts.Controls.Clear(); //view = ViewModel.LookupView(entities, "HSIR", "HSIR", 0); //if (view != null) //{ // PERSPECTIVE_VIEW_ITEM vi = view.PERSPECTIVE_VIEW_ITEM.Where(i => i.ITEM_SEQ.ToString() == ddlChartType.SelectedValue).FirstOrDefault(); // if (vi != null) // { // GaugeDefinition ggCfg = new GaugeDefinition().Initialize().ConfigureControl(vi, null, "", false, !string.IsNullOrEmpty(hfwidth.Value) ? Convert.ToInt32(hfwidth.Value) - 62 : 0, 0); // ggCfg.Position = null; // HSCalcs().ehsCtl.SetCalcParams(vi.CALCS_METHOD, vi.CALCS_SCOPE, vi.CALCS_STAT, (int)vi.SERIES_ORDER).IncidentSeries((EHSCalcsCtl.SeriesOrder)vi.SERIES_ORDER, SQMBasePage.GetComboBoxCheckedItems(ddlPlantSelect).Select(i => Convert.ToDecimal(i.Value)).ToArray(), new DateTime(1900, 1, 1), SessionManager.UserContext.LocalTime.AddYears(100), HSCalcs().ehsCtl.GetIncidentTopics()); // uclChart.CreateControl((SQMChartType)vi.CONTROL_TYPE, ggCfg, HSCalcs().ehsCtl.Results, divSummaryCharts); // pnlChartSection.Style.Add("display", "inline"); // lnkChartClose.Visible = lnkPrint.Visible = true; // // return; // } //} divChart.Controls.Clear(); switch (ddlChartType.SelectedValue) { case "charts": decimal protection = 0; decimal protectionTotal = 0; decimal surveillance = 0; decimal surveillanceTotal = 0; decimal manualresponse = 0; decimal manualresponseTotal = 0; decimal humanelement = 0; decimal humanelementTotal = 0; decimal hazards = 0; decimal hazardsTotal = 0; decimal maintenence = 0; decimal maintenenceTotal = 0; int iTopic = 0; decimal answerValue; // get the current year results foreach (EHSAuditData audit in HSCalcs().ehsCtl.AuditHst) { foreach (AUDIT_ANSWER answer in audit.Audit.AUDIT_ANSWER) { try { answerValue = Convert.ToInt16(answer.ANSWER_VALUE); } catch { answerValue = 0; } EHSAuditQuestion question = EHSAuditMgr.SelectAuditQuestion(audit.Audit.AUDIT_ID, answer.AUDIT_QUESTION_ID); iTopic = Convert.ToInt16(question.TopicId); switch (iTopic) { case 3: protection += answerValue; protectionTotal += 3; break; case 4: surveillance += answerValue; surveillanceTotal += 3; break; case 5: manualresponse += answerValue; manualresponseTotal += 3; break; case 6: humanelement += answerValue; humanelementTotal += 3; break; case 7: hazards += answerValue; hazardsTotal += 3; break; case 8: maintenence += answerValue; maintenenceTotal += 3; break; } } } List <GaugeSeries> gaugeSeries = new List <GaugeSeries>(); GaugeSeries g = new GaugeSeries(); g.Name = "Percentage"; if (protectionTotal > 0) { answerValue = Math.Round((protection / protectionTotal), 3) * 100; } else { answerValue = 0; } g.ItemList.Add(new GaugeSeriesItem(0, 0, 0, answerValue, "Protection")); if (surveillanceTotal > 0) { answerValue = Math.Round((surveillance / surveillanceTotal), 3) * 100; } else { answerValue = 0; } g.ItemList.Add(new GaugeSeriesItem(0, 0, 0, answerValue, "Surveillance")); if (manualresponseTotal > 0) { answerValue = Math.Round((manualresponse / manualresponseTotal), 3) * 100; } else { answerValue = 0; } g.ItemList.Add(new GaugeSeriesItem(0, 0, 0, answerValue, "Manual Response")); if (humanelementTotal > 0) { answerValue = Math.Round((humanelement / humanelementTotal), 3) * 100; } else { answerValue = 0; } g.ItemList.Add(new GaugeSeriesItem(0, 0, 0, answerValue, "Human Element")); if (hazardsTotal > 0) { answerValue = Math.Round((hazards / hazardsTotal), 3) * 100; } else { answerValue = 0; } g.ItemList.Add(new GaugeSeriesItem(0, 0, 0, answerValue, "Hazards")); if (maintenenceTotal > 0) { answerValue = Math.Round((maintenence / maintenenceTotal), 3) * 100; } else { answerValue = 0; } g.ItemList.Add(new GaugeSeriesItem(0, 0, 0, answerValue, "Maintenence")); gaugeSeries.Add(g); GaugeDefinition gauge = new GaugeDefinition(); gauge.ColorPallete = "chartSeriesColor"; //gauge.ContainerHeight = 550; //gauge.ContainerWidth = 550; gauge.ControlType = 70; gauge.DisplayLabel = true; gauge.DisplayLegend = true; gauge.DisplayTitle = true; gauge.DisplayTooltip = true; gauge.Grouping = 0; gauge.Height = 550; gauge.Width = 650; gauge.ItemVisual = "CENTER"; gauge.MinorTics = false; gauge.Multiplier = 0; gauge.ScaleMax = 100; gauge.ScaleMin = 0; gauge.Title = "Audit Summary"; gauge.DisplayTitle = false; CalcsResult rslt = new CalcsResult(); rslt.metricSeries = gaugeSeries; rslt.Status = 0; rslt.ValidResult = true; uclChart.CreateControl(SQMChartType.SpiderChart, gauge, rslt, divChart); pnlChartSection.Style.Add("display", "inline"); lnkChartClose.Visible = lnkPrint.Visible = true; divChart.Visible = true; divDataResults.Visible = false; break; case "report": lnkChartClose.Visible = lnkPrint.Visible = true; divChart.Visible = false; divDataResults.Visible = true; break; } } }
private void SetupPage() { if (ddlPlantSelect.Items.Count < 1) { List <BusinessLocation> locationList = SQMModelMgr.SelectBusinessLocationList(SessionManager.UserContext.HRLocation.Company.COMPANY_ID, 0, true); SQMBasePage.SetLocationList(ddlPlantSelect, UserContext.FilterPlantAccessList(locationList), 0); rcbStatusSelect.SelectedValue = "A"; } divAuditList.Visible = true; pnlChartSection.Style.Add("display", "none"); lblChartType.Visible = ddlChartType.Visible = false; dmFromDate.ShowPopupOnFocus = dmToDate.ShowPopupOnFocus = true; // ABW 1/5/16 - use user's default plant local time for search default DateTime localTime = SessionManager.UserContext.LocalTime; dmFromDate.SelectedDate = localTime.AddMonths(-1); dmToDate.SelectedDate = localTime.AddMonths(1); if (Mode == AuditMode.Audit) { lblViewEHSRezTitle.Text = GetLocalResourceObject("lblViewEHSRezTitleResource1.Text").ToString(); lblPageInstructions.Text = GetLocalResourceObject("lblPageInstructionsResource1.Text").ToString(); //lblStatus.Text = "Assessment Status:"; rbNew.Text = GetLocalResourceObject("rbNewResource1.Text").ToString(); lblAuditDate.Visible = true; phAudit.Visible = true; SETTINGS sets = SQMSettings.GetSetting("EHS", "AUDITSEARCHFROM"); if (sets != null) { try { string[] args = sets.VALUE.Split('-'); if (args.Length > 1) { dmFromDate.SelectedDate = new DateTime(Convert.ToInt32(args[0]), Convert.ToInt32(args[1]), Convert.ToInt32(args[2])); } else { dmFromDate.SelectedDate = SessionManager.UserContext.LocalTime.AddMonths(Convert.ToInt32(args[0]) * -1); } } catch { } } if (rcbAuditType.Items.Count < 1) { foreach (AUDIT_TYPE ip in EHSAuditMgr.SelectAuditTypeList(SessionManager.PrimaryCompany().COMPANY_ID, false)) { RadComboBoxItem item = new RadComboBoxItem(ip.TITLE, ip.AUDIT_TYPE_ID.ToString()); item.Checked = true; rcbAuditType.Items.Add(item); } } // lookup charts defined for this module & app context //PERSPECTIVE_VIEW view = ViewModel.LookupView(entities, "HSIR", "HSIR", 0); //if (view != null) //{ // ddlChartType.Items.Clear(); // ddlChartType.Items.Add(new RadComboBoxItem("", "")); // foreach (PERSPECTIVE_VIEW_ITEM vi in view.PERSPECTIVE_VIEW_ITEM.Where(l => l.STATUS != "I").OrderBy(l => l.ITEM_SEQ).ToList()) // { // RadComboBoxItem item = new RadComboBoxItem(); // item.Text = vi.TITLE; // item.Value = vi.ITEM_SEQ.ToString(); // item.ImageUrl = ViewModel.GetViewItemImageURL(vi); // ddlChartType.Items.Add(item); // } //} ddlChartType.Items.Clear(); ddlChartType.Items.Add(new RadComboBoxItem("", "")); ddlChartType.Items.Add(new RadComboBoxItem("Audit Summary", "charts")); ddlChartType.Items.Add(new RadComboBoxItem("Data Results", "report")); } }
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); }