Пример #1
0
        /// <summary>
        /// This is the constructor for the Schedule Stats generator.
        ///
        /// This class determines if today is the last working day of the week, month,
        /// or first working day of the year and send out a report via email automatically.
        /// </summary>
        /// <param name="MainForm"></param>
        /// <param name="detailFrom"></param>
        public ScheduleStatsGen(LogCreator MainForm, DetailForm detailFrom)
        {
            //Check if today is either the end of the week, end of the month, or end of the year.
            //End of the week == Monday(of next week)
            //End of the month == Last business day of the month
            //End of the year == One week into the new year. (Send out on the second Monday of the year)

            today = DateTime.Today;

            //If today is the end of the week we generate end of week statistics
            if (isEndOfWeek())
            {
                //Get the start date
                DateTime startDate = this.getFirstDayOfWeek();
                DateTime endDate   = today;

                while (endDate.DayOfWeek != DayOfWeek.Friday)
                {
                    endDate = endDate.AddDays(-1);
                }
                //generate the stats
                detailFrom.updateDetail("Generating weekly statistics.");
                statGenerator = new StatsGen(MainForm, startDate, endDate, "Weekly");
                //Get the file path
                string filePath = MainForm.STATS_LOCATION + statGenerator.getfileName();
                //Send the email
                detailFrom.updateDetail("Sending Email.");
                EmailSender ES = new EmailSender(filePath, "Weekly CSCO PT Stats");
            }

            //If we are at the end of the month we auto generate statistics
            if (isEndOfMonth())
            {
                //Get the start date
                DateTime starteDate = this.getFirstDayOfMonth();
                //generate the stats
                detailFrom.updateDetail("Generating monthly statistics.");
                statGenerator = new StatsGen(MainForm, starteDate, today, "Monthly");
                //Get the file path
                string filePath = MainForm.STATS_LOCATION + statGenerator.getfileName();
                //Send the email
                detailFrom.updateDetail("Sending Email.");
                EmailSender ES = new EmailSender(filePath, "Monthly CSCO PT Stats for " + today.Month);
            }

            //If we are at the end of the year we end
            if (isEndOfYear())
            {
                //Get the start date
                DateTime starteDate = this.getFirstDayOfYear();
                //generate the stats
                detailFrom.updateDetail("Generating yearly statistics.");
                statGenerator = new StatsGen(MainForm, starteDate, today, "Yearly");
                //Get the file path
                string filePath = MainForm.STATS_LOCATION + statGenerator.getfileName();
                //Send the email
                detailFrom.updateDetail("Sending Email.");
                EmailSender ES = new EmailSender(filePath, "Yearly CSCO PT stats for " + (today.Year - 1));
            }
        }
Пример #2
0
        /// <summary>
        /// Do the work
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Bw_DoWork(object sender, DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;

            try
            {
                StatsGen statGenerator = new StatsGen(this.mainForm, this.startDate, this.endDate, "Manual");
                statsFileToOpen = statGenerator.getfileName();
                statGenerator   = null;
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            catch (Exception)
            {
                return;
            }
            return;
        }