Exemplo n.º 1
0
        private void CheckTasks()
        {
            UltraCalendarInfo ultraCalendarInfo = new UltraCalendarInfo();

            ultraCalendarInfo.AllowRecurringAppointments = true;
            TaskSchedulesDAO lTaskSchedulesDAO = new TaskSchedulesDAO();
            SettingsDAO      lSettingsDAO      = new SettingsDAO();
            Appointment      appointment;
            object           rawAppointmentData;

            try
            {
                foreach (DataRow row in lTaskSchedulesDAO.GetAllAppointments().Rows)
                {
                    rawAppointmentData = row["_APPOINTMENTDATA"];

                    if (rawAppointmentData is byte[] == false)
                    {
                        continue;
                    }

                    appointment         = Appointment.FromBytes(rawAppointmentData as byte[]);
                    appointment.DataKey = row[0];
                    ultraCalendarInfo.Appointments.Add(appointment);
                }

                string strLastReportRunTime = lSettingsDAO.GetSetting("LastTaskReportRun", false);

                DateTime lLastReportRunDateTime = (strLastReportRunTime == "") ? DateTime.MinValue : Convert.ToDateTime(strLastReportRunTime);
                DateTime lReportRunTime         = DateTime.Now;

                AppointmentsSubsetCollection expiredAppointments = ultraCalendarInfo.GetAppointmentsInRange(lLastReportRunDateTime, lReportRunTime);
                lSettingsDAO.SetSetting("LastTaskReportRun", DateTime.Now.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 = String.Format("The following task is due at {0}." + Environment.NewLine + Environment.NewLine +
                                                        expiredAppointment.Subject, expiredAppointment.StartDateTime.ToString());

                        DesktopAlert.ShowDesktopAlertForTasks(lSubject, (int)expiredAppointment.DataKey);

                        NewsFeed.AddNewsItem(NewsFeed.Priority.Information, "Task due: " + expiredAppointment.Subject);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
            }
        }
Exemplo n.º 2
0
        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);
            }
        }