/// <summary> /// Retrun the list of navigation links in the View context /// </summary> public List <NavigationLink> GetNavigationLinks(ReportView view) { var result = new List <NavigationLink>(); foreach (var link in Links) { if (link.Type == NavigationType.Drill && !view.IsDrillEnabled) { continue; } if (link.Type == NavigationType.SubReport && !view.IsSubReportsEnabled) { continue; } var newLink = new NavigationLink() { Cell = link.Cell, Href = link.Href, Parameters = link.Parameters, Report = link.Report, Tag = link.Tag, Text = link.Text, Type = link.Type }; Helper.CopyProperties(link, newLink); if (newLink.Type == NavigationType.Drill) { //Add the navigation if exists var modelView = view.ModelView; var navigationView = modelView.GetValue(Parameter.NavigationView); if (!string.IsNullOrEmpty(navigationView)) { newLink.Href += string.Format("&view={0}", modelView.GetValue(Parameter.NavigationView)); } } result.Add(newLink); } return(result); }
/// <summary> /// Add a navigation link from this cell to download a file. The file will be loaded in the Navigation Script of the model. /// </summary> public void AddNavigationFileDownload(string text, string linkTag = "") { var guid = Guid.NewGuid().ToString(); var link = new NavigationLink() { Type = NavigationType.FileDownload, Href = guid, Text = text, Cell = this, Report = Element != null ? Element.Report : null, Tag = linkTag }; Links.Add(link); ContextModel.Report.NavigationLinks.Add(guid, link); }
/// <summary> /// Add a navigation link from this cell to download a file. The file will be loaded in the Navigation Script of the model. /// </summary> public void AddNavigationFileDownload(string text) { var guid = Guid.NewGuid().ToString(); var link = new NavigationLink() { Type = NavigationType.FileDownload, Href = guid, Text = text, Cell = this }; Links.Add(link); ContextModel.Report.NavigationLinks.Add(guid, link); }
/// <summary> /// Add a navigation link from this cell to execute another report within the current navigation context /// </summary> public void AddNavigationReportNavigation(string path, string menuText, string titleText = "") { var link = new NavigationLink() { Type = NavigationType.SubReport, Href = string.Format("rpa={0}", HttpUtility.UrlEncode(path)), Text = menuText }; if (!string.IsNullOrEmpty(titleText)) { link.Href += string.Format("&dis={0}", HttpUtility.UrlEncode(titleText)); } Links.Add(link); }
void initNavigationLinks() { //exe : execution guid of the source report //src : guid element source for drill //dst : guid element destination for drill //val : value of the restriction //res : guid element for a restriction //rpa : report path for sub-report //dis : display value for sub-report if (_links == null) { _links = new List <NavigationLink>(); if (!IsTitle && !IsTotal && !IsTotalTotal && Element != null) { var report = Element.Source.Report; if (Element.PivotPosition != PivotPosition.Data) { //Get Drill child links var metaData = Element.Source.MetaData; foreach (string childGUID in Element.MetaColumn.DrillChildren) { //Check that the element is not already in the model if (Element.Model.Elements.Exists(i => i.MetaColumnGUID == childGUID && i.PivotPosition == Element.PivotPosition)) { continue; } var child = metaData.GetColumnFromGUID(childGUID); if (child != null) { NavigationLink link = new NavigationLink(); link.Type = NavigationType.Drill; link.Href = string.Format("exe={0}&src={1}&dst={2}&val={3}", report.ExecutionGUID, Element.MetaColumnGUID, childGUID, HttpUtility.UrlEncode(NavigationValue)); link.Text = HttpUtility.HtmlEncode(report.Translate("Drill >") + " " + report.Repository.RepositoryTranslate("Element", child.Category + '.' + child.DisplayName, child.DisplayName)); _links.Add(link); } } //Get drill parent link foreach (MetaTable table in Element.Source.MetaData.AllTables) { foreach (MetaColumn parentColumn in table.Columns.Where(i => i.DrillChildren.Contains(Element.MetaColumnGUID))) { //Check that the element is not already in the model if (Element.Model.Elements.Exists(i => i.MetaColumnGUID == parentColumn.GUID && i.PivotPosition == Element.PivotPosition)) { continue; } if (Element.MetaColumn.DrillUpOnlyIfDD) { //check that the drill down occured if (!report.DrillParents.Contains(parentColumn.GUID)) { continue; } } NavigationLink link = new NavigationLink(); link.Type = NavigationType.Drill; link.Href = string.Format("exe={0}&src={1}&dst={2}", report.ExecutionGUID, Element.MetaColumnGUID, parentColumn.GUID); link.Text = HttpUtility.HtmlEncode(report.Translate("Drill <") + " " + report.Repository.RepositoryTranslate("Element", parentColumn.Category + '.' + parentColumn.DisplayName, parentColumn.DisplayName)); _links.Add(link); } } } //Get sub reports links if (Element.PivotPosition != PivotPosition.Data) { foreach (var subreport in Element.MetaColumn.SubReports.Where(i => i.Restrictions.Count > 0)) { string subReportRestrictions = ""; int index = 1; foreach (var guid in subreport.Restrictions) { var cellValue = SubReportValues.FirstOrDefault(i => i.Element.MetaColumnGUID == guid); if (cellValue != null && !string.IsNullOrEmpty(cellValue.NavigationValue)) { subReportRestrictions += string.Format("&res{0}={1}&val{0}={2}", index, guid, HttpUtility.UrlEncode(cellValue.NavigationValue)); index++; } } if (!string.IsNullOrEmpty(subReportRestrictions)) { NavigationLink link = new NavigationLink(); link.Type = NavigationType.SubReport; link.Href = string.Format("rpa={0}", HttpUtility.UrlEncode(subreport.Path)); if (subreport.Restrictions.Count > 1 || !subreport.Restrictions.Contains(Element.MetaColumn.GUID)) { //Add the display value if necessary link.Href += string.Format("&dis={0}", HttpUtility.UrlEncode(DisplayValue)); } link.Href += subReportRestrictions; link.Text = report.Repository.RepositoryTranslate("SubReport", Element.MetaColumn.Category + '.' + Element.MetaColumn.DisplayName, subreport.Name); _links.Add(link); } } } } } }
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.IsDrilling = 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.IsDrilling = 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.ActionDrillReport: string nav = HeaderForm.GetAttribute(ReportExecution.HtmlId_navigation_attribute_name); string src = HttpUtility.ParseQueryString(nav).Get("src"); string dst = HttpUtility.ParseQueryString(nav).Get("dst"); string val = HttpUtility.ParseQueryString(nav).Get("val"); string destLabel = "", srcRestriction = ""; bool drillDone = false; foreach (var model in _report.Models) { ReportElement element = model.Elements.FirstOrDefault(i => i.MetaColumnGUID == src); if (element != null) { drillDone = true; 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 (drillDone) { 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.IsDrilling = true; string htmlPath = _execution.GenerateHTMLResult(); lastLink.Href = htmlPath; if (string.IsNullOrEmpty(lastLink.Text)) lastLink.Text = _report.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; }