Beispiel #1
0
        public bool SetScheduledReportIsActive(int scheduledReportId, bool isActive)
        {
            bool isSuccessful = false;

            try
            {
                LoginUser        loginUser        = TSAuthentication.GetLoginUser();
                ScheduledReports scheduledReports = new ScheduledReports(loginUser);
                scheduledReports.LoadById(scheduledReportId);

                if (scheduledReports != null && scheduledReports.Any())
                {
                    scheduledReports[0].IsActive = isActive;

                    if (!isActive)
                    {
                        scheduledReports[0].NextRun = null;
                    }
                    else
                    {
                        scheduledReports[0].SetNextRun();
                    }

                    scheduledReports[0].ModifierId = loginUser.UserID;
                    scheduledReports.Save();
                    isSuccessful = true;
                }
            }
            catch (Exception ex)
            {
                isSuccessful = false;
                ExceptionLogs.LogException(TSAuthentication.GetLoginUser(), ex, "ReportService.SetScheduledReportIsActive");
            }

            return(isSuccessful);
        }
Beispiel #2
0
        public int SaveScheduledReport(int scheduledReportId,
                                       int reportId,
                                       string emailSubject,
                                       string emailBody,
                                       string emailAddresses,
                                       Object startOn,
                                       ScheduledReportFrequency frequency,
                                       int every,
                                       int weekday,
                                       int dayOfMonth,
                                       bool isActive)
        {
            try
            {
                LoginUser        loginUser        = TSAuthentication.GetLoginUser();
                ScheduledReports scheduledReports = new ScheduledReports(loginUser);

                if (scheduledReportId == 0)
                {
                    ScheduledReport scheduledReport = scheduledReports.AddNewScheduledReport();
                    scheduledReport.ReportId        = reportId;
                    scheduledReport.EmailSubject    = emailSubject;
                    scheduledReport.EmailBody       = emailBody;
                    scheduledReport.EmailRecipients = emailAddresses;
                    scheduledReport.OrganizationId  = TSAuthentication.OrganizationID;
                    scheduledReport.IsActive        = true;
                    scheduledReport.StartDate       = (DateTime)startOn;
                    scheduledReport.RecurrencyId    = (byte)frequency;
                    scheduledReport.Every           = (byte)every;
                    scheduledReport.Weekday         = (byte)weekday;
                    scheduledReport.Monthday        = (byte)dayOfMonth;
                    scheduledReport.IsActive        = isActive;
                    scheduledReport.FilePathID      = 3;

                    //This needs to be set before SetNextRun because that one needs it to get the timezone to use.
                    scheduledReport.CreatorId = loginUser.UserID;

                    if (isActive)
                    {
                        scheduledReport.SetNextRun();
                    }
                    else
                    {
                        scheduledReport.NextRun = null;
                    }

                    scheduledReport.Collection.Save();

                    scheduledReportId = scheduledReport.Id;
                }
                else
                {
                    scheduledReports.LoadById(scheduledReportId);

                    if (scheduledReports != null && scheduledReports.Any())
                    {
                        scheduledReports[0].EmailSubject    = emailSubject;
                        scheduledReports[0].EmailBody       = emailBody;
                        scheduledReports[0].EmailRecipients = emailAddresses;
                        scheduledReports[0].IsActive        = true;
                        try
                        { scheduledReports[0].StartDate = (DateTime)startOn; }
                        catch (Exception ex) { }
                        scheduledReports[0].RecurrencyId = (byte)frequency;
                        scheduledReports[0].Every        = (byte)every;
                        scheduledReports[0].Weekday      = (byte)weekday;
                        scheduledReports[0].Monthday     = (byte)dayOfMonth;
                        scheduledReports[0].IsActive     = isActive;

                        if (isActive)
                        {
                            scheduledReports[0].SetNextRun();
                        }
                        else
                        {
                            scheduledReports[0].NextRun = null;
                        }

                        scheduledReports[0].ModifierId = loginUser.UserID;
                        scheduledReports.Save();
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionLogs.LogException(TSAuthentication.GetLoginUser(), ex, "ReportService.SaveScheduledReport");
            }

            return(scheduledReportId);
        }