private void LoadDepartments() { List <Notification_Dep_user> lstDepartments = AMP_DepartmentDAL.getDepartments(); if (lstDepartments.Count > 0) { ((ListBox)checkedListBox1).DataSource = lstDepartments; ((ListBox)checkedListBox1).DisplayMember = "DepartmentDesc"; ((ListBox)checkedListBox1).ValueMember = "DepartmentCode"; } }
/// <summary> /// checkamendment for all departments, all events, all functions and orders, all notes, all documents. /// </summary> public static void checkAmendmentbyDepartment_AllofEvent() { //get the program running time, all department, all rules need to use this time as start time // this is trying to avoid if some department running for a long time, and total program need to run > 30 minutes DateTime dtNow = DateTime.Now; //loop 0, check if the current snapshot is finished. int nTryTimes = 0; bool isSnapshotFinish = false; isSnapshotFinish = AMP_Common.isSnapshotFinished(dtNow); while (!isSnapshotFinish) { //delay for 30 seconds then get the status again. System.Threading.Thread.Sleep(1000 * 30); isSnapshotFinish = AMP_Common.isSnapshotFinished(dtNow); nTryTimes += 1; //if tried for 40 times (20 minutes) still fail, then fail. if (nTryTimes >= 40) { break; } } if (isSnapshotFinish) { //loop 1, list all the departments need to run amendments. List <Notification_Dep_user> lstUser = AMP_DepartmentDAL.getDepartments(); foreach (Notification_Dep_user dep in lstUser) { AMP_EventDAL.dep = dep; int nSnapshotCurrent, nSnapshotPrevious; DateTime dtSnapshotCurrent, dtSnapshotPrevious; //loop 2, list all rules for this department. rule is defined to run hourly/daily/... with different event filters. this is trying to shrink the message numbers send to user. List <AMP_Rules> lstrules = AMP_RulesDAL.getEventRules(dep.DepartmentCode, dtNow); foreach (AMP_Rules rule in lstrules) { if (rule.RuleId != null) { AMP_EventDAL.rule = rule; AMP_RulesDAL.rule = rule; AMP_FunctionDAL.rule = rule; AMP_OrderDAL.rule = rule; if (rule.Last_Run != null && rule.Last_Run != DateTime.MinValue) { nSnapshotCurrent = AMP_Common.getRecentSnapshotID(dtNow); nSnapshotPrevious = AMP_Common.getRecentSnapshotID(rule.Last_Run); dtSnapshotCurrent = AMP_Common.getRecentSnapshotDateTime(dtNow); dtSnapshotPrevious = AMP_Common.getRecentSnapshotDateTime(rule.Last_Run); } else { nSnapshotCurrent = AMP_Common.getRecentSnapshotID(dtNow); nSnapshotPrevious = AMP_Common.getRecentSnapshotID(dtNow.AddMinutes(-rule.TriggerMinutes)); dtSnapshotCurrent = AMP_Common.getRecentSnapshotDateTime(dtNow); dtSnapshotPrevious = AMP_Common.getRecentSnapshotDateTime(dtNow.AddMinutes(-rule.TriggerMinutes)); } AMP_EventDAL.nSnapshotCurrentID = nSnapshotCurrent; AMP_EventDAL.nSnapshotPreviousID = nSnapshotPrevious; AMP_EventDAL.dtSnapshotCurrent = dtSnapshotCurrent; AMP_EventDAL.dtSnapshotPrevious = dtSnapshotPrevious; AMP_RulesDAL.nSnapshotCurrentID = nSnapshotCurrent; AMP_RulesDAL.nSnapshotPreviousID = nSnapshotPrevious; AMP_RulesDAL.dtSnapshotCurrent = dtSnapshotCurrent; AMP_RulesDAL.dtSnapshotPrevious = dtSnapshotPrevious; //get all event in the current department rule for 'EVENT', including cancelled, turnover List <EventInfo> lstEvent = AMP_EventDAL.getAllEventsFromRule(); CheckEvent_Amendment(lstEvent, dep, nSnapshotCurrent, nSnapshotPrevious); } AMP_RulesDAL.UpdateNextRun(); } }//end foreach rule if (dtNow.Year == 2018 && dtNow.Month <= 5) { AMP_Notification.sendEmail("*****@*****.**", "*****@*****.**", "status of running for " + (DateTime.Now.Subtract(dtNow).TotalSeconds.ToString("G")) + " seconds.", "Start at:" + dtNow.ToString("dd/MM/yyyy HH:mm") + " finish at " + DateTime.Now.ToString("dd/MM/yyyy HH:mm")); } } else { AMP_Notification.sendEmail("*****@*****.**", "*****@*****.**", "Snapshot is hanging the process. Start from:" + dtNow.ToString("dd/MM/yyyy HH:mm") + " finish at " + DateTime.Now.ToString("dd/MM/yyyy HH:mm"), "Tried very hard for 4 times of checking, still not finish the snapshot process, I gave up. You can you do it, no can no bibi."); } }