private void bnDeleteAllSchedules_Click(object sender, EventArgs e) { if (MessageBox.Show( "Are you sure you want to delete all expired schedules?", "Delete schedules", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { int lCounter = 0; foreach (DataRow row in lReportSchedulesDAO.GetAllAppointments().Rows) { object rawAppointmentData = row["_APPOINTMENTDATA"]; if (rawAppointmentData is byte[] == false) { continue; } Appointment appointment = Appointment.FromBytes(rawAppointmentData as byte[]); if (appointment.Recurrence.RangeEndDate < DateTime.Now.AddSeconds(-62)) { lReportSchedulesDAO.DeleteAppt(Convert.ToInt32(row["_REPORTSCHEDULEID"])); lCounter++; } } string message = String.Format("Deleted {0} expired report schedules.", lCounter); if (lCounter == 0) { message = "There were no expired report schedules to delete."; } DesktopAlert.ShowDesktopAlert(message); //MessageBox.Show( // message, // "Delete report schedules", // MessageBoxButtons.OK, // MessageBoxIcon.Information); PopulateGrid(); } }
private void HandleCalendarEvent() { LogFile ourLog = new LogFile(); try { SettingsDAO lSettingsDAO = new SettingsDAO(); ReportSchedulesDAO lReportSchedulesDAO = new ReportSchedulesDAO(); Appointment appointment; object rawAppointmentData; ultraCalendarInfo.Appointments.Clear(); foreach (DataRow row in lReportSchedulesDAO.GetAllAppointments().Rows) { rawAppointmentData = row["_APPOINTMENTDATA"]; if (rawAppointmentData is byte[] == false) { continue; } appointment = Appointment.FromBytes(rawAppointmentData as byte[]); ultraCalendarInfo.Appointments.Add(appointment); } string strLastReportRunTime = lSettingsDAO.GetSetting("LastReportRun", false); DateTime lLastReportRunDateTime = (strLastReportRunTime == "") ? DateTime.MinValue : Convert.ToDateTime(strLastReportRunTime); DateTime lReportRunTime = DateTime.Now; AppointmentsSubsetCollection expiredAppointments = ultraCalendarInfo.GetAppointmentsInRange(lLastReportRunDateTime, lReportRunTime); lSettingsDAO.SetSetting("LastReportRun", lReportRunTime.ToString(), false); foreach (Appointment expiredAppointment in expiredAppointments) { // need to re-check that this appointment is between the LastTaskReportRun date and DateTime.Now // there is a hole in the ultraCalendarInfo.GetAppointmentsInRange logic above if ((lLastReportRunDateTime < expiredAppointment.StartDateTime) && (lReportRunTime > expiredAppointment.StartDateTime)) { string[] lSubject = expiredAppointment.Subject.Split('|'); string lReportCategory = ""; string lReportName = ""; if (lSubject.Length == 2) { lReportCategory = lSubject[0]; lReportName = lSubject[1]; } else if (lSubject.Length == 3) { lReportCategory = lSubject[0]; lReportName = lSubject[1] + " | " + lSubject[2]; } if (lReportCategory.StartsWith("Custom Report")) { int lReportId = Convert.ToInt32(expiredAppointment.Description); emailController.SendCustomReportByEmail(expiredAppointment.Subject, lReportId, expiredAppointment.Location); } else if (lReportCategory.StartsWith("Compliance Report")) { int lReportId = Convert.ToInt32(expiredAppointment.Description); emailController.SendComplianceReportByEmail(expiredAppointment.Subject, lReportId, expiredAppointment.Location); } else if (lReportCategory.StartsWith("User-Defined SQL Report")) { int lReportId = Convert.ToInt32(expiredAppointment.Description); emailController.SendSQLReportByEmail(expiredAppointment.Subject, lReportId, expiredAppointment.Location); } else { emailController.SendReportByEmail(expiredAppointment.Subject, expiredAppointment.Location); } } } } catch (Exception ex) { ourLog.Write(ex.Message, true); } }