Inheritance: ReportExecutionLog
Exemplo n.º 1
1
 void setCurrentExecution()
 {
     string executionGUID = webBrowser.Document.All[ReportExecution.HtmlId_execution_guid].GetAttribute("value");
     if (_navigation.Navigations.ContainsKey(executionGUID))
     {
         _execution = _navigation.Navigations[executionGUID].Execution;
         _report = _execution.Report;
     }
 }
Exemplo n.º 2
0
 public override string Process(Report report)
 {
     ReportOutput output = report.OutputToExecute;
     if (string.IsNullOrEmpty(output.FolderPath)) throw new Exception("The output folder path is not specified in the report output.");
     if (string.IsNullOrEmpty(output.FileName)) throw new Exception("The file name is not specified in the report output.");
     output.Information = report.Translate("Report result generated in '{0}'", report.DisplayResultFilePath);
     return string.Format("Report result generated in '{0}'", report.DisplayResultFilePath);
 }
Exemplo n.º 3
0
 public string GetNavigationLinksHTML(Report rootReport)
 {
     string links = "";
     foreach (var navigation in Navigations.Values.Where(i => i.Execution.RootReport == rootReport))
     {
         links += string.Format("<li><a href='{0}'>{1}</a></li>", HttpUtility.HtmlEncode(navigation.Link.Href), HttpUtility.HtmlEncode(navigation.Link.Text));
     }
     return links;
 }
Exemplo n.º 4
0
        public SmartCopyForm(string title, object source, Report report)
        {
            InitializeComponent();

            Text = title;

            _source = source;
            _report = report;

            ShowIcon = true;
            Icon = Repository.ProductIcon;
        }
Exemplo n.º 5
0
 void deleteFromDestinationList(Report report)
 {
     string destinationName = getDestinationName();
     List<PropertyItem> destinations = new List<PropertyItem>();
     if (destinationName.StartsWith(ReportsKeyword))
     {
         _destinationItems.RemoveAll(i => i.Object == report);
     }
     else if (destinationName.StartsWith(ModelsKeyword))
     {
         _destinationItems.RemoveAll(i => i.Object != null && ((ReportModel)i.Object).Report == report);
     }
     else if (destinationName.StartsWith(ElementsKeyword))
     {
         _destinationItems.RemoveAll(i => i.Object != null && ((ReportElement)i.Object).Model.Report == report);
     }
     else if (destinationName.StartsWith(RestrictionsKeyword))
     {
         _destinationItems.RemoveAll(i => i.Object != null && ((ReportRestriction)i.Object).Model.Report == report);
     }
     else if (destinationName.StartsWith(ViewsKeyword))
     {
         _destinationItems.RemoveAll(i => i.Object != null && ((ReportView)i.Object).Report == report);
     }
     else if (destinationName.StartsWith(TasksKeyword))
     {
         _destinationItems.RemoveAll(i => i.Object != null && ((ReportTask)i.Object).Report == report);
     }
     else if (destinationName.StartsWith(TasksFolderKeyword))
     {
         _destinationItems.RemoveAll(i => i.Object == report);
     }
     else if (destinationName.StartsWith(OutputsKeyword))
     {
         _destinationItems.RemoveAll(i => i.Object != null && ((ReportOutput)i.Object).Report == report);
     }
     applyFilter();
 }
Exemplo n.º 6
0
 void addToDestinationList(Report report)
 {
     string destinationName = getDestinationName();
     string fileName = convertFileName(report.FilePath);
     if (destinationName.StartsWith(ReportsKeyword))
     {
         if (_destinationItems.FirstOrDefault(i => i.Name == fileName) == null)
         {
             _destinationItems.Add(new PropertyItem() { Name = fileName, Object = report });
         }
     }
     else if (destinationName.StartsWith(ModelsKeyword))
     {
         foreach (var item in report.Models.Where(i => i != _source))
         {
             string name = string.Format("[{0}] {1}", fileName, item.Name);
             if (_destinationItems.FirstOrDefault(i => i.Name == name) == null)
             {
                 _destinationItems.Add(new PropertyItem() { Name = name, Object = item });
             }
         }
     }
     else if (destinationName.StartsWith(ElementsKeyword))
     {
         foreach (var model in report.Models)
         {
             foreach (var item in model.Elements.Where(i => i != _source))
             {
                 string name = string.Format("[{0}/{1}] {2} ", fileName, model.Name, item.DisplayNameEl);
                 if (_destinationItems.FirstOrDefault(i => i.Object == item) == null)
                 {
                     _destinationItems.Add(new PropertyItem() { Name = name, Object = item });
                 }
             }
         }
     }
     else if (destinationName.StartsWith(RestrictionsKeyword))
     {
         bool isAggregate = !((ReportRestriction)_source).Model.Restrictions.Contains(_source);
         foreach (var model in report.Models)
         {
             var restrictions = (isAggregate ? model.AggregateRestrictions : model.Restrictions);
             foreach (var item in restrictions.Where(i => i != _source))
             {
                 string name = string.Format("[{0}/{1}] {2} ", fileName, model.Name, item.DisplayNameEl);
                 if (_destinationItems.FirstOrDefault(i => i.Object == item) == null)
                 {
                     _destinationItems.Add(new PropertyItem() { Name = name, Object = item });
                 }
             }
         }
     }
     else if (destinationName.StartsWith(ViewsKeyword))
     {
         //add a dummy view for report itself
         string reportName = string.Format("[{0}] ", fileName);
         if (addRadioButton.Checked && ((ReportView)_source).TemplateName == "Report")
         {
             _destinationItems.Add(new PropertyItem() { Name = reportName, Object = new ReportView() { Report = report } });
         }
         foreach (var view in report.Views)
         {
             addViewsToDestinations(view, reportName);
         }
     }
     else if (destinationName.StartsWith(TasksKeyword))
     {
         foreach (var item in report.Tasks.Where(i => i != _source))
         {
             string name = string.Format("[{0}] {1} ", fileName, item.Name);
             if (_destinationItems.FirstOrDefault(i => i.Object == item) == null)
             {
                 _destinationItems.Add(new PropertyItem() { Name = name, Object = item });
             }
         }
     }
     else if (destinationName.StartsWith(OutputsKeyword))
     {
         foreach (var item in report.Outputs.Where(i => i != _source))
         {
             string name = string.Format("[{0}] {1} ", fileName, item.Name);
             if (_destinationItems.FirstOrDefault(i => i.Object == item) == null)
             {
                 _destinationItems.Add(new PropertyItem() { Name = name, Object = item });
             }
         }
     }
     else if (destinationName.StartsWith(TasksFolderKeyword))
     {
         if (report != _report)
         {
             string name = string.Format("[{0}] Tasks Script ", fileName);
             _destinationItems.Add(new PropertyItem() { Name = name, Object = report });
         }
     }
 }
Exemplo n.º 7
0
 static void sendEmail(Report report, string to, string from, string subject, string body)
 {
     OutputEmailDevice device = report.Repository.Devices.OfType<OutputEmailDevice>().FirstOrDefault(i => i.UsedForNotification);
     if (device == null) device = report.Repository.Devices.OfType<OutputEmailDevice>().FirstOrDefault();
     if (device == null)
     {
         Helper.WriteLogEntryScheduler(EventLogEntryType.Error, "No email device is defined in the repository to send the error. Please use the server manager to define at least an email device.");
     }
     else
     {
         try
         {
             MailMessage message = new MailMessage();
             message.From = new MailAddress(Helper.IfNullOrEmpty(from, device.SenderEmail));
             device.AddEmailAddresses(message.To, to);
             message.Subject = subject;
             message.Body = body;
             SmtpClient client = device.SmtpClient;
             client.Send(message);
         }
         catch (Exception emailEx)
         {
             Helper.WriteLogEntryScheduler(EventLogEntryType.Error, "Error got trying sending notification email.\r\n{0}", emailEx.Message);
         }
     }
 }
Exemplo n.º 8
0
 string publishReportResult(Report report)
 {
     if (!string.IsNullOrEmpty(report.ResultFilePath))
     {
         string publishPath = FileHelper.GetUniqueFileName(Path.Combine(Path.GetDirectoryName(report.HTMLDisplayFilePath), Path.GetFileName(report.ResultFilePath)));
         System.IO.File.Copy(report.ResultFilePath, publishPath);
         if (!report.ForPDFConversion && !report.HasExternalViewer)
         {
             foreach (ReportModel model in report.Models)
             {
                 if (model.HasSerie)
                 {
                     foreach (ResultPage page in model.Pages.Where(i => i.ChartPath != null))
                     {
                         System.IO.File.Copy(page.ChartPath, Path.Combine(Path.GetDirectoryName(report.HTMLDisplayFilePath), Path.GetFileName(page.ChartPath)), true);
                     }
                 }
             }
         }
         return report.WebTempUrl + Path.GetFileName(publishPath);
     }
     return "";
 }
Exemplo n.º 9
0
        public static Report Create(Repository repository)
        {
            Report result = new Report() { GUID = Guid.NewGuid().ToString() };
            result.FilePath = "NewReport." + Repository.SealReportFileExtension;
            result.Repository = repository;
            foreach (MetaSource source in repository.Sources)
            {
                ReportSource reportSource = result.AddSource(source);
            }
            if (result.Sources.Count == 0) result.AddSource(null);
            foreach (ReportSource source in result.Sources)
            {
                source.LoadRepositoryMetaSources(repository);
                //Remove the connection added
                if (source.Connections.Count > 1) source.Connections.RemoveAll(i => i.IsEditable);
                //And master table added for NoSQL
                if (source.IsNoSQL && source.MetaData.Tables.Count > 1) source.MetaData.Tables.RemoveAll(i => i.IsEditable);
            }

            //and a first model
            if (result.Models.Count == 0) result.AddModel();
            //Add default views
            ReportView defaultView = result.AddModelHTMLView();
            if (defaultView == null) throw new Exception(string.Format("Unable to find any view in your repository. Check that your repository folder '{0}' contains all the default sub-folders and files...", repository.RepositoryPath));
            result.ViewGUID = defaultView.GUID;
            result.AddModelCSVView();

            return result;
        }
Exemplo n.º 10
0
        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                if (!checkModified()) return;
                if (_reportViewer != null && _reportViewer.Visible) _reportViewer.Close();

                if (_repository == null || _repository.MustReload()) _repository = Repository.Create();
                _report = Report.Create(_repository);
                IsModified = true;
                mainTreeView.SelectedNode = null;
                init();
                selectAfterLoad();

                toolsHelper.Report = _report;
                _report.SchedulesWithCurrentUser = Properties.Settings.Default.SchedulesWithCurrentUser;
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
Exemplo n.º 11
0
        private void reloadToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (_report != null)
            {
                if (!checkModified()) return;
                if (_reportViewer != null && _reportViewer.Visible) _reportViewer.Close();

                string path = _report.FilePath;
                _report = null;
                IsModified = false;
                closeToolStripMenuItem_Click(sender, e);
                if (File.Exists(path)) openReport(path);
            }
        }
Exemplo n.º 12
0
        private bool processAction(string action)
        {
            bool cancelNavigation = false;
            try
            {
                switch (action)
                {
                    case ReportExecution.ActionExecuteReport:
                        setCurrentExecution();
                        cancelNavigation = true;
                        _reportDone = false;
                        if (webBrowser.Document != null)
                        {
                            _report.InputRestrictions.Clear();
                            if (HeaderForm != null)
                            {
                                foreach (HtmlElement element in HeaderForm.All)
                                {
                                    if (element.Id != null)
                                    {
                                        _report.InputRestrictions.Add(element.Id, element.TagName.ToLower() == "option" ? element.GetAttribute("selected") : element.GetAttribute("value"));
                                        Debug.WriteLine("{0} {1} {2} {3}", element.Id, element.Name, element.GetAttribute("value"), element.GetAttribute("selected"));
                                    }
                                }
                            }
                        }
                        _report.IsNavigating = false;
                        Execute();
                        break;

                    case ReportExecution.ActionRefreshReport:
                        if (_report.IsExecuting)
                        {
                            cancelNavigation = true;
                            HtmlElement message = webBrowser.Document.All[ReportExecution.HtmlId_processing_message];
                            if (message != null) message.SetAttribute("innerHTML", _report.ExecutionHeader);
                            HtmlElement messages = webBrowser.Document.All[ReportExecution.HtmlId_execution_messages];
                            if (messages != null) messages.SetAttribute("innerHTML", Helper.ToHtml(_report.ExecutionMessages));
                        }
                        else if (!_reportDone)
                        {
                            _navigation.SetNavigation(_execution);
                            cancelNavigation = true;
                            _reportDone = true;
                            _report.IsNavigating = false;
                            _url = "file:///" + _report.HTMLDisplayFilePath;
                            webBrowser.Navigate(_url);
                        }
                        break;

                    case ReportExecution.ActionCancelReport:
                        _execution.Report.LogMessage(_report.Translate("Cancelling report..."));
                        cancelNavigation = true;
                        _report.Cancel = true;
                        break;

                    case ReportExecution.ActionUpdateViewParameter:
                        cancelNavigation = true;
                        _report.UpdateViewParameter(GetFormValue(ReportExecution.HtmlId_parameter_view_id), GetFormValue(ReportExecution.HtmlId_parameter_view_name), GetFormValue(ReportExecution.HtmlId_parameter_view_value));
                        break;

                    case ReportExecution.ActionViewHtmlResult:
                        setCurrentExecution();
                        string resultPath = _execution.GenerateHTMLResult();
                        if (File.Exists(resultPath)) Process.Start(resultPath);
                        cancelNavigation = true;
                        break;

                    case ReportExecution.ActionViewPrintResult:
                        setCurrentExecution();
                        resultPath = _execution.GeneratePrintResult();
                        if (File.Exists(resultPath)) Process.Start(resultPath);
                        cancelNavigation = true;
                        break;

                    case ReportExecution.ActionViewPDFResult:
                        setCurrentExecution();
                        resultPath = _execution.GeneratePDFResult();
                        if (File.Exists(resultPath)) Process.Start(resultPath);
                        cancelNavigation = true;
                        break;

                    case ReportExecution.ActionViewExcelResult:
                        setCurrentExecution();
                        resultPath = _execution.GenerateExcelResult();
                        if (File.Exists(resultPath)) Process.Start(resultPath);
                        cancelNavigation = true;
                        break;

                    case ReportExecution.ActionNavigate:
                        string nav = webBrowser.Document.All[ReportExecution.HtmlId_navigation_id].GetAttribute("value");
                        _execution = _navigation.Navigate(nav, _execution.RootReport);
                        _report = _execution.Report;

                        _canRender = false;
                        cancelNavigation = true;
                        _reportDone = false;
                        Execute();
                        break;

                    case ReportExecution.ActionGetNavigationLinks:
                        cancelNavigation = true;
                        HtmlElement navMenu = webBrowser.Document.All[ReportExecution.HtmlId_navigation_menu];
                        if (navMenu != null) navMenu.SetAttribute("innerHTML", _navigation.GetNavigationLinksHTML(_execution.RootReport));
                        break;
                }
            }
            catch (Exception ex)
            {
                cancelNavigation = true;
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return cancelNavigation;
        }
Exemplo n.º 13
0
        public static Report Create(Repository repository)
        {
            Report result = new Report() { GUID = Guid.NewGuid().ToString() };
            result.FilePath = "NewReport." + Repository.SealReportFileExtension;
            result.Repository = repository;
            foreach (MetaSource source in repository.Sources)
            {
                ReportSource reportSource = result.AddSource(source);
            }
            if (result.Sources.Count == 0) result.AddSource(null);
            foreach (ReportSource source in result.Sources)
            {
                source.LoadRepositoryMetaSources(repository);
                //Remove the connection added
                if (source.Connections.Count > 1) source.Connections.RemoveAll(i => i.IsEditable);
                //And master table added for NoSQL
                if (source.IsNoSQL && source.MetaData.Tables.Count > 1) source.MetaData.Tables.RemoveAll(i => i.IsEditable);
            }

            //and a first model
            if (result.Models.Count == 0) result.AddModel();
            //Add default views
            ReportView defaultView = result.AddModelHTMLView();
            result.ViewGUID = defaultView.GUID;
            result.AddModelCSVView();

            return result;
        }
Exemplo n.º 14
0
        public override string Process(Report report)
        {
            ReportOutput output = report.OutputToExecute;

            if (string.IsNullOrEmpty(output.EmailTo)) throw new Exception("No email address has been specified in the report output.");

            MailMessage message = new MailMessage();
            message.From = new MailAddress(Helper.IfNullOrEmpty(output.EmailFrom, SenderEmail));
            AddEmailAddresses(message.To, output.EmailTo);
            AddEmailAddresses(message.CC, output.EmailCC);
            AddEmailAddresses(message.Bcc, output.EmailBCC);
            AddEmailAddresses(message.ReplyToList, Helper.IfNullOrEmpty(output.EmailReplyTo,ReplyTo));
            message.Subject = Helper.IfNullOrEmpty(output.EmailSubject, report.ExecutionName);
            if (output.EmailHtmlBody)
            {
                message.Body = File.ReadAllText(report.ResultFilePath);
                message.IsBodyHtml = true;
            }
            else if (output.EmailMessagesInBody)
            {
                message.Body = string.Format("Execution messages for report '{0}':\r\n\r\n{1}", report.FilePath, report.ExecutionMessages);
            }
            else
            {
                if (output.EmailMessagesInBody) message.Body = string.Format("Execution messages for report '{0}':\r\n\r\n{1}", report.FilePath, report.ExecutionMessages);
                else message.Body = Helper.IfNullOrEmpty(output.EmailBody, report.Translate("Please find the report '{0}' in attachment.", report.ExecutionView.Name));

                message.Attachments.Add(new Attachment(report.ResultFilePath));
            }

            //Attach image files
            foreach (string path in report.ExecutionAttachedFiles)
            {
                message.Attachments.Add(new Attachment(path));
            }

            foreach (ReportModel model in report.Models)
            {
                foreach (ResultPage page in model.Pages)
                {
                    if (model.HasSerie && File.Exists(page.ChartPath)) message.Attachments.Add(new Attachment(page.ChartPath));
                }
            }

            //Attachments options
            if (output.EmailSkipAttachments)
            {
                message.Attachments.Clear();
            }
            else if (output.EmailZipAttachments)
            {
                using (ZipFile zip = new ZipFile())
                {
                    if (!string.IsNullOrEmpty(output.EmailZipPassword)) zip.Password = output.EmailZipPassword;
                    foreach (var attachement in message.Attachments) zip.AddFile(Path.Combine(Path.GetDirectoryName(report.ResultFilePath), attachement.Name), ".");
                    string zipName = Path.Combine(Path.GetDirectoryName(report.ResultFilePath), Path.GetFileNameWithoutExtension(report.ResultFilePath) + ".zip");
                    zip.Save(zipName);
                    message.Attachments.Clear();
                    message.Attachments.Add(new Attachment(zipName));
                    message.Attachments[0].Name = report.ExecutionName + ".zip";
                }
            }
            SmtpClient client = SmtpClient;
            client.Send(message);
            output.Information = report.Translate("Email sent to '{0}'", output.EmailTo);
            return string.Format("Email sent to '{0}'", output.EmailTo);
        }
        private bool processAction(string action)
        {
            bool cancelNavigation = false;
            try
            {
                switch (action)
                {
                    case ReportExecution.ActionExecuteReport:
                        cancelNavigation = true;
                        _reportDone = false;
                        if (webBrowser.Document != null)
                        {
                            _report.InputRestrictions.Clear();
                            if (HeaderForm != null)
                            {
                                foreach (HtmlElement element in HeaderForm.All)
                                {
                                    if (element.Id != null)
                                    {
                                        _report.InputRestrictions.Add(element.Id, element.TagName.ToLower() == "option" ? element.GetAttribute("selected") : element.GetAttribute("value"));
                                        Debug.WriteLine("{0} {1} {2} {3}", element.Id, element.Name, element.GetAttribute("value"), element.GetAttribute("selected"));
                                    }
                                }
                            }
                        }
                        _report.IsNavigating = false;
                        Execute();
                        break;

                    case ReportExecution.ActionRefreshReport:
                        if (_report.IsExecuting)
                        {
                            cancelNavigation = true;
                            HtmlElement message = webBrowser.Document.All[ReportExecution.HtmlId_processing_message];
                            if (message != null) message.SetAttribute("innerHTML", _report.ExecutionHeader);
                            HtmlElement messages = webBrowser.Document.All[ReportExecution.HtmlId_execution_messages];
                            if (messages != null) messages.SetAttribute("innerHTML", Helper.ToHtml(_report.ExecutionMessages));
                        }
                        else if (!_reportDone)
                        {
                            //Set last drill path if any
                            if (_report.NavigationLinks.Count > 0) _report.NavigationLinks.Last().Href = _report.ResultFilePath;

                            cancelNavigation = true;
                            _reportDone = true;
                            _report.IsNavigating = false;
                            _url = "file:///" + _report.HTMLDisplayFilePath;
                            webBrowser.Navigate(_url);
                        }
                        break;

                    case ReportExecution.ActionCancelReport:
                        _execution.Report.LogMessage(_report.Translate("Cancelling report..."));
                        cancelNavigation = true;
                        _report.Cancel = true;
                        break;

                    case ReportExecution.ActionUpdateViewParameter:
                        cancelNavigation = true;
                        _report.UpdateViewParameter(GetFormValue(ReportExecution.HtmlId_parameter_view_id), GetFormValue(ReportExecution.HtmlId_parameter_view_name), GetFormValue(ReportExecution.HtmlId_parameter_view_value));
                        break;

                    case ReportExecution.ActionViewHtmlResult:
                        string resultPath = _execution.GenerateHTMLResult();
                        if (File.Exists(resultPath)) Process.Start(resultPath);
                        cancelNavigation = true;
                        break;

                    case ReportExecution.ActionViewPrintResult:
                        resultPath = _execution.GeneratePrintResult();
                        if (File.Exists(resultPath)) Process.Start(resultPath);
                        cancelNavigation = true;
                        break;

                    case ReportExecution.ActionViewPDFResult:
                        resultPath = _execution.GeneratePDFResult();
                        if (File.Exists(resultPath)) Process.Start(resultPath);
                        cancelNavigation = true;
                        break;

                    case ReportExecution.ActionViewExcelResult:
                        resultPath = _execution.GenerateExcelResult();
                        if (File.Exists(resultPath)) Process.Start(resultPath);
                        cancelNavigation = true;
                        break;

                    case ReportExecution.ActionNavigate:
                        string nav = HeaderForm.GetAttribute(ReportExecution.HtmlId_navigation_attribute_name);
                        string sre = HttpUtility.ParseQueryString(nav).Get("sre");
                        bool navigationDone = false;
                        Report lastReport = _report;
                        ReportExecution lastExecution = _execution;
                        string destLabel = "", srcRestriction = "";

                        if (!string.IsNullOrEmpty(sre))
                        {
                            //Sub-Report
                            string path = sre.Replace(Repository.SealRepositoryKeyword, _report.Repository.RepositoryPath);
                            _report = Report.LoadFromFile(path, _report.Repository);
                            _report.NavigationLinks.AddRange(lastReport.NavigationLinks);

                            /*        if (!File.Exists(path))
                                    {
                                        cancelNavigation = true;
                                        break;
                                    }
                                    */
                            int index = 1;
                            while (true)
                            {
                                string res = HttpUtility.ParseQueryString(nav).Get("res" + index.ToString());
                                string val = HttpUtility.ParseQueryString(nav).Get("val" + index.ToString());
                                if (string.IsNullOrEmpty(res) || string.IsNullOrEmpty(val)) break;
                                foreach (var model in _report.Models)
                                {
                                    foreach (var restriction in model.Restrictions.Where(i => i.MetaColumnGUID == res && i.Prompt == PromptType.Prompt))
                                    {
                                        if (restriction.IsEnum)
                                        {
                                            restriction.EnumValues.Clear();
                                            restriction.EnumValues.Add(val);
                                        }
                                        else restriction.Value1 = val;
                                    }
                                }
                                index++;
                            }
                            _canRender = false;
                            _execution = new ReportExecution() { Report = _report };
                            _report.InitForExecution();
                            navigationDone = true;
                        }
                        else
                        {
                            //Drill
                            string src = HttpUtility.ParseQueryString(nav).Get("src");
                            string dst = HttpUtility.ParseQueryString(nav).Get("dst");
                            string val = HttpUtility.ParseQueryString(nav).Get("val");

                            foreach (var model in _report.Models)
                            {
                                ReportElement element = model.Elements.FirstOrDefault(i => i.MetaColumnGUID == src);
                                if (element != null)
                                {
                                    navigationDone = true;
                                    //If the dest element is already in the model, we can remove it
                                    if (model.Elements.Exists(i => i.MetaColumnGUID == dst && i.PivotPosition == element.PivotPosition)) model.Elements.Remove(element);
                                    else element.ChangeColumnGUID(dst);
                                    destLabel = element.DisplayNameElTranslated;
                                    if (val != null)
                                    {
                                        destLabel = "> " + destLabel;
                                        //Add restriction
                                        ReportRestriction restriction = ReportRestriction.CreateReportRestriction();
                                        restriction.Source = model.Source;
                                        restriction.Model = model;
                                        restriction.MetaColumnGUID = src;
                                        restriction.SetDefaults();
                                        restriction.Operator = Operator.Equal;
                                        if (restriction.IsEnum) restriction.EnumValues.Add(val);
                                        else restriction.Value1 = val;
                                        model.Restrictions.Add(restriction);
                                        if (!string.IsNullOrEmpty(model.Restriction)) model.Restriction = string.Format("({0}) AND ", model.Restriction);
                                        model.Restriction += ReportRestriction.kStartRestrictionChar + restriction.GUID + ReportRestriction.kStopRestrictionChar;

                                        srcRestriction = restriction.DisplayText;
                                    }
                                    else
                                    {
                                        destLabel = "< " + destLabel;
                                        var restrictions = model.Restrictions.Where(i => i.MetaColumnGUID == dst).ToList();
                                        foreach (var restr in restrictions)
                                        {
                                            model.Restrictions.Remove(restr);
                                            model.Restriction = model.Restriction.Replace(ReportRestriction.kStartRestrictionChar + restr.GUID + ReportRestriction.kStopRestrictionChar, "1=1");
                                        }
                                    }
                                }
                            }
                        }

                        if (navigationDone)
                        {
                            NavigationLink lastLink = null;
                            if (_report.NavigationLinks.Count == 0)
                            {
                                lastLink = new NavigationLink();
                                _report.NavigationLinks.Add(lastLink);
                            }
                            else lastLink = _report.NavigationLinks.Last();

                            //create HTML result for navigation -> NavigationLinks must have one link to activate the button
                            _report.IsNavigating = true;
                            _canRender = false;

                            if (lastReport != _report)
                            {
                                lastReport.IsNavigating = true;
                                if (lastReport.NavigationLinks.Count == 0) lastReport.NavigationLinks.Add(lastLink);
                            }

                            lastLink.Href = lastExecution.GenerateHTMLResult();
                            if (string.IsNullOrEmpty(lastLink.Text)) lastLink.Text = lastReport.ExecutionName;

                            string linkText = string.Format("{0} {1}", _report.ExecutionName, destLabel);
                            if (!string.IsNullOrEmpty(srcRestriction)) linkText += string.Format(" [{0}]", srcRestriction);
                            _report.NavigationLinks.Add(new NavigationLink() { Href = "#", Text = linkText });
                        }

                        cancelNavigation = true;
                        _reportDone = false;
                        Execute();

                        break;

                    case ReportExecution.ActionGetNavigationLinks:
                        cancelNavigation = true;
                        HtmlElement navMenu = webBrowser.Document.All[ReportExecution.HtmlId_navigation_menu];
                        if (navMenu != null)
                        {
                            string links = "";
                            foreach (var link in _report.NavigationLinks)
                            {
                                links += string.Format("<li><a href='{0}'>{1}</a></li>", link.Href, HttpUtility.HtmlEncode(link.Text));
                            }
                            navMenu.SetAttribute("innerHTML", links);
                        }
                        break;
                }
            }
            catch (Exception ex)
            {
                cancelNavigation = true;
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return cancelNavigation;
        }
Exemplo n.º 16
0
        private void reloadToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (_report != null)
            {
                if (IsModified)
                {
                    DialogResult dlgResult = MessageBox.Show("The current report has been modified, are you sure you to reload it ?", "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                    if (dlgResult == DialogResult.Cancel) return;
                }
                if (_reportViewer != null && _reportViewer.Visible) _reportViewer.Close();

                string path = _report.FilePath;
                _report = null;
                IsModified = false;
                closeToolStripMenuItem_Click(sender, e);
                if (File.Exists(path)) openReport(path);
            }
        }
Exemplo n.º 17
0
        public void ViewReport(Report report, Repository repository, bool render, string viewGUID, string outputGUID, string originalFilePath)
        {
            Show();
            Text = Path.GetFileNameWithoutExtension(originalFilePath) + " - " + Repository.SealRootProductName + " Report Viewer";
            BringToFront();

            Report previousReport = _report;

            _report = report;
            _report.ExecutionContext = ReportExecutionContext.DesignerReport;
            if (string.IsNullOrEmpty(_report.DisplayName)) _report.DisplayName = Path.GetFileNameWithoutExtension(originalFilePath);
            _report.CurrentViewGUID = _report.ViewGUID;

            //execute to output
            if (!string.IsNullOrEmpty(outputGUID))
            {
                _report.OutputToExecute = _report.Outputs.FirstOrDefault(i => i.GUID == outputGUID);
                _report.ExecutionContext = ReportExecutionContext.DesignerOutput;
                if (_report.OutputToExecute != null) _report.CurrentViewGUID = _report.OutputToExecute.ViewGUID;
            }

            //execute with custom view
            if (!string.IsNullOrEmpty(viewGUID)) _report.CurrentViewGUID = viewGUID;

            if (previousReport != null && render)
            {
                //force execution
                var parameter = _report.ExecutionView.Parameters.FirstOrDefault(i => i.Name == "force_execution");
                if (parameter != null) parameter.BoolValue = true;

                //set previous data tables and restrictions
                foreach (var model in _report.Models)
                {
                    ReportModel previousModel = previousReport.Models.FirstOrDefault(i => i.GUID == model.GUID);
                    if (previousModel != null)
                    {
                        model.ResultTable = previousModel.ResultTable;
                        model.Restrictions = previousModel.Restrictions;
                        model.RestrictionText = previousModel.RestrictionText;
                        model.Sql = previousModel.Sql;
                    }
                }
                _report.RenderOnly = true;
            }

            _execution = new ReportExecution() { Report = _report };
            _report.InitForExecution();
            _execution.RenderHTMLDisplayForViewer();
            _url = "file:///" + _report.HTMLDisplayFilePath;
            webBrowser.Navigate(_url);
        }
Exemplo n.º 18
0
        public ReportExecution Navigate(string navigation, Report rootReport)
        {
            string reportPath = HttpUtility.ParseQueryString(navigation).Get("rpa");
            string destLabel = "", srcRestriction = "", srcGUID = "";
            Report newReport = null;

            if (Navigations.Count(i => i.Value.Execution.RootReport == rootReport) == 1)
            {
                //For the first navigation, we update the JS file in the result to show up the button
                string html = File.ReadAllText(rootReport.ResultFilePath);
                html = html.Replace("var hasNavigation = false;/*SRKW do not modify*/", "var hasNavigation = true;");
                rootReport.ResultFilePath = Helpers.FileHelper.GetUniqueFileName(rootReport.ResultFilePath);
                File.WriteAllText(rootReport.ResultFilePath, html, System.Text.Encoding.UTF8);
                rootReport.IsNavigating = true;
                rootReport.HasNavigation = true;

                Navigations.First(i => i.Value.Execution.RootReport == rootReport).Value.Link.Href = !string.IsNullOrEmpty(rootReport.WebUrl) ? rootReport.WebTempUrl + Path.GetFileName(rootReport.ResultFilePath) : rootReport.ResultFilePath;

            }

            if (!string.IsNullOrEmpty(reportPath))
            {
                //Sub-Report
                string path = reportPath.Replace(Repository.SealRepositoryKeyword, rootReport.Repository.RepositoryPath);
                newReport = Report.LoadFromFile(path, rootReport.Repository);

                int index = 1;
                while (true)
                {
                    string res = HttpUtility.ParseQueryString(navigation).Get("res" + index.ToString());
                    string val = HttpUtility.ParseQueryString(navigation).Get("val" + index.ToString());
                    if (string.IsNullOrEmpty(res) || string.IsNullOrEmpty(val)) break;
                    foreach (var model in newReport.Models)
                    {
                        foreach (var restriction in model.Restrictions.Where(i => i.MetaColumnGUID == res && i.Prompt == PromptType.Prompt))
                        {
                            restriction.SetNavigationValue(val);
                            srcRestriction = restriction.GeNavigationDisplayValue();
                        }
                    }
                    index++;
                }
                //Get display value
                string dis = HttpUtility.ParseQueryString(navigation).Get("dis");
                if (!string.IsNullOrEmpty(dis)) srcRestriction = HttpUtility.ParseQueryString(navigation).Get("dis");
            }
            else
            {
                //Drill
                string executionGuid = HttpUtility.ParseQueryString(navigation).Get("exe");
                if (!Navigations.ContainsKey(executionGuid)) throw new Exception("Missing execution GUID");
                newReport = Navigations[executionGuid].Execution.Report.Clone();
                newReport.ExecutionGUID = Guid.NewGuid().ToString();
                string src = HttpUtility.ParseQueryString(navigation).Get("src");
                string dst = HttpUtility.ParseQueryString(navigation).Get("dst");
                string val = HttpUtility.ParseQueryString(navigation).Get("val");
                newReport.DrillParents.Add(src);

                foreach (var model in newReport.Models)
                {
                    ReportElement element = model.Elements.FirstOrDefault(i => i.MetaColumnGUID == src);
                    //Has already restriction ? if down check src, if up check dest
                    bool hasAlreadyRestriction = model.Restrictions.Exists(i => i.MetaColumnGUID == (val != null ? src : dst));
                    if (element != null || hasAlreadyRestriction)
                    {
                        if (element != null)
                        {
                            string initialLabel = element.DisplayNameEl;
                            element.ChangeColumnGUID(dst);
                            destLabel = element.DisplayNameElTranslated;
                            newReport.ExecutionView.ReplaceInParameterValues("chart_nvd3_title", "%" + initialLabel + "%", "%" + element.DisplayNameEl + "%");
                        }

                        if (val != null)
                        {
                            //Drill Down: Add restriction 
                            ReportRestriction restriction = ReportRestriction.CreateReportRestriction();
                            restriction.Source = model.Source;
                            restriction.Model = model;
                            restriction.MetaColumnGUID = src;
                            restriction.SetDefaults();
                            restriction.Operator = Operator.Equal;
                            restriction.SetNavigationValue(val);
                            model.Restrictions.Add(restriction);
                            if (!string.IsNullOrEmpty(model.Restriction)) model.Restriction = string.Format("({0}) AND ", model.Restriction);
                            model.Restriction += ReportRestriction.kStartRestrictionChar + restriction.GUID + ReportRestriction.kStopRestrictionChar;

                            srcRestriction = restriction.GeNavigationDisplayValue();
                            srcGUID = restriction.MetaColumnGUID;
                        }
                        else
                        {
                            //Drill Down: Remove restrictions 
                            var restrictions = model.Restrictions.Where(i => i.MetaColumnGUID == dst).ToList();
                            foreach (var restr in restrictions)
                            {
                                model.Restrictions.Remove(restr);
                                model.Restriction = model.Restriction.Replace(ReportRestriction.kStartRestrictionChar + restr.GUID + ReportRestriction.kStopRestrictionChar, "1=1");
                            }
                        }
                    }
                }
            }

            newReport.WebUrl = rootReport.WebUrl;
            newReport.IsNavigating = true;
            newReport.HasNavigation = true;

            if (!string.IsNullOrEmpty(srcRestriction)) newReport.DisplayName = string.Format("{0} > {1}", newReport.ExecutionName, srcRestriction);
            else newReport.DisplayName = string.Format("{0} < {1}", newReport.ExecutionName, destLabel);

            return new ReportExecution() { Report = newReport, RootReport = rootReport };
        }
Exemplo n.º 19
0
        private void openReport(string path)
        {
            //refresh repository
            _repository = Repository.Create();
            _report = Report.LoadFromFile(path, _repository);
            if (_report != null)
            {
                addMRU(path);
                IsModified = false;
                init();
                selectAfterLoad();

                if (!string.IsNullOrEmpty(_report.LoadErrors))
                {
                    MessageBox.Show(string.Format("Error loading the report:\r\n{0}", _report.LoadErrors), "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                if (!string.IsNullOrEmpty(_report.UpgradeWarnings))
                {
                    MessageBox.Show(_report.UpgradeWarnings, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            if (_reportViewer != null && _reportViewer.Visible) _reportViewer.Close();
            toolsHelper.Report = _report;
            _report.SchedulesWithCurrentUser = Properties.Settings.Default.SchedulesWithCurrentUser;
        }
Exemplo n.º 20
0
 public static ReportSchedule GetReportSchedule(TaskFolder taskFolder, Report report, string scheduleGUID)
 {
     ReportSchedule schedule = report.Schedules.FirstOrDefault(i => i.GUID == scheduleGUID);
     if (schedule == null)
     {
         //Remove the schedule
         foreach (Task oldTask in taskFolder.GetTasks().Where(i => i.Definition.RegistrationInfo.Source.EndsWith(scheduleGUID)))
         {
             taskFolder.DeleteTask(oldTask.Name);
         }
     }
     return schedule;
 }
Exemplo n.º 21
0
 private void closeToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (!checkModified()) return;
     if (_reportViewer != null && _reportViewer.Visible) _reportViewer.Close();
     _report = null;
     toolStripHelper.SetHelperButtons(null);
     IsModified = false;
     init();
     toolsHelper.Report = _report;
 }
Exemplo n.º 22
0
        static void InitReportSchedule(string scheduleGUID, out Task task, out Report report, out ReportSchedule schedule)
        {
            if (string.IsNullOrEmpty(scheduleGUID)) throw new Exception("No schedule GUID specified !\r\n");

            Repository repository = Repository.Create();
            TaskService taskService = new TaskService();
            TaskFolder taskFolder = taskService.RootFolder.SubFolders.FirstOrDefault(i => i.Name == repository.Configuration.TaskFolderName);
            if (taskFolder == null) throw new Exception(string.Format("Unable to find schedule task folder '{0}'\r\nCheck your configuration...", repository.Configuration.TaskFolderName));

            task = taskFolder.GetTasks().FirstOrDefault(i => i.Definition.RegistrationInfo.Source.EndsWith(scheduleGUID));
            if (task == null) throw new Exception(string.Format("Unable to find schedule '{0}'\r\n", scheduleGUID));

            string reportPath = ReportSchedule.GetTaskSourceDetail(task.Definition.RegistrationInfo.Source, 0);
            string reportGUID = ReportSchedule.GetTaskSourceDetail(task.Definition.RegistrationInfo.Source, 1);
            report = GetScheduledReport(taskFolder, reportPath, reportGUID, scheduleGUID, repository);
            if (report == null) throw new Exception(string.Format("Unable to find report '{0}' for schedule '{1}'\r\nReport schedules have been deleted...", reportGUID, scheduleGUID));

            schedule = GetReportSchedule(taskFolder, report, scheduleGUID);
            if (schedule == null) throw new Exception(string.Format("Unable to find schedule '{0}' in report '{1}'.\r\nSchedule has been deleted", scheduleGUID, report.FilePath));
        }
Exemplo n.º 23
0
 public abstract string Process(Report report);
Exemplo n.º 24
0
        void initInputRestrictions(Report report)
        {
            report.InputRestrictions.Clear();
            if (report.PreInputRestrictions.Count > 0)
            {
                int i = 0;
                while (true)
                {
                    string prefix = string.Format("r{0}", i);
                    string key = prefix + "_name";
                    if (report.PreInputRestrictions.ContainsKey(key))
                    {
                        var displayName = report.PreInputRestrictions[key].ToLower();
                        foreach (ReportRestriction restriction in report.ExecutionCommonRestrictions.Where(j => j.DisplayNameEl.ToLower() == displayName))
                        {
                            //Convert values to normal input using the html id...
                            key = prefix + "_operator";
                            if (report.PreInputRestrictions.ContainsKey(key))
                            {
                                //operator
                                report.InputRestrictions.Add(restriction.OperatorHtmlId, report.PreInputRestrictions[key]);
                                if (restriction.IsEnumRE)
                                {
                                    //options
                                    key = prefix + "_enum_values";
                                    if (report.PreInputRestrictions.ContainsKey(key))
                                    {
                                        var optionValues = report.PreInputRestrictions[key];
                                        //Convert values into index of the enum...
                                        var preOptionvalues = optionValues.Split(',');
                                        for (int k = 0; k < restriction.EnumRE.Values.Count; k++)
                                        {
                                            var enumDef = restriction.EnumRE.Values[k];
                                            if (preOptionvalues.Contains(enumDef.Id))
                                            {
                                                report.InputRestrictions.Add(restriction.OptionHtmlId + k.ToString(), "true");
                                            }
                                        }
                                    }
                                }
                                else if (restriction.IsDateTime)
                                {
                                    //convert to user input format
                                    DateTime dt;
                                    key = prefix + "_value_1";
                                    if (report.PreInputRestrictions.ContainsKey(key))
                                    {
                                        if (DateTime.TryParseExact(report.PreInputRestrictions[key], "yyyyMMdd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt))
                                        {
                                            report.InputRestrictions.Add(restriction.ValueHtmlId + "_1", ((IFormattable)dt).ToString(report.ExecutionView.CultureInfo.DateTimeFormat.ShortDatePattern, report.ExecutionView.CultureInfo));
                                        }
                                    }
                                    key = prefix + "_value_2";
                                    if (report.PreInputRestrictions.ContainsKey(key))
                                    {
                                        if (DateTime.TryParseExact(report.PreInputRestrictions[key], "yyyyMMdd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt))
                                        {
                                            report.InputRestrictions.Add(restriction.ValueHtmlId + "_2", ((IFormattable)dt).ToString(report.ExecutionView.CultureInfo.DateTimeFormat.ShortDatePattern, report.ExecutionView.CultureInfo));
                                        }
                                    }
                                    key = prefix + "_value_3";
                                    if (report.PreInputRestrictions.ContainsKey(key))
                                    {
                                        if (DateTime.TryParseExact(report.PreInputRestrictions[key], "yyyyMMdd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt))
                                        {
                                            report.InputRestrictions.Add(restriction.ValueHtmlId + "_3", ((IFormattable)dt).ToString(report.ExecutionView.CultureInfo.DateTimeFormat.ShortDatePattern, report.ExecutionView.CultureInfo));
                                        }
                                    }
                                    key = prefix + "_value_4";
                                    if (report.PreInputRestrictions.ContainsKey(key))
                                    {
                                        if (DateTime.TryParseExact(report.PreInputRestrictions[key], "yyyyMMdd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt))
                                        {
                                            report.InputRestrictions.Add(restriction.ValueHtmlId + "_4", ((IFormattable)dt).ToString(report.ExecutionView.CultureInfo.DateTimeFormat.ShortDatePattern, report.ExecutionView.CultureInfo));
                                        }
                                    }

                                }
                                else
                                {
                                    //standard values
                                    key = prefix + "_value_1";
                                    if (report.PreInputRestrictions.ContainsKey(key)) report.InputRestrictions.Add(restriction.ValueHtmlId + "_1", report.PreInputRestrictions[key]);
                                    key = prefix + "_value_2";
                                    if (report.PreInputRestrictions.ContainsKey(key)) report.InputRestrictions.Add(restriction.ValueHtmlId + "_2", report.PreInputRestrictions[key]);
                                    key = prefix + "_value_3";
                                    if (report.PreInputRestrictions.ContainsKey(key)) report.InputRestrictions.Add(restriction.ValueHtmlId + "_3", report.PreInputRestrictions[key]);
                                    key = prefix + "_value_4";
                                    if (report.PreInputRestrictions.ContainsKey(key)) report.InputRestrictions.Add(restriction.ValueHtmlId + "_4", report.PreInputRestrictions[key]);
                                }
                            }
                        }
                        i++;
                    }
                    else
                    {
                        break;
                    }
                }
            }
            else {
                //get restriction values from the form request (if any)
                foreach (string key in Request.Form.Keys)
                {
                    string value = Request.Form[key];
                    if (value != null)
                    {
                        if (key.EndsWith("_Option_Value"))
                        {
                            foreach (string optionValue in value.Split(','))
                            {
                                report.InputRestrictions.Add(optionValue, "true");
                            }
                        }
                        else
                        {
                            report.InputRestrictions.Add(key, value);
                        }
                    }
                }
            }
            report.PreInputRestrictions.Clear();
        }