コード例 #1
0
        void drillModel(ReportModel model, string src, string dst, string val, ref string destLabel, ref string srcRestriction, Report newReport, Report rootReport)
        {
            //First remove hidden elements
            model.Elements.RemoveAll(i => i.PivotPosition == PivotPosition.Hidden);

            foreach (var element in model.Elements.Where(i => i.MetaColumnGUID == src).ToList())
            {
                var els = new Dictionary <ReportElement, string>();
                if (val != null)
                {
                    //Drill Down, check src
                    ReportRestriction restriction = ReportRestriction.CreateReportRestriction();
                    model.Restrictions.Add(restriction);
                    restriction.Source         = model.Source;
                    restriction.Report         = newReport;
                    restriction.Model          = model;
                    restriction.MetaColumnGUID = src;
                    restriction.Operator       = Operator.Equal;
                    restriction.SetDefaults();
コード例 #2
0
        void SynchronizeRestrictions()
        {
            if (Report == null || !_useCustomRestrictions)
            {
                return;
            }

            List <ReportRestriction> allRestrictions = Report.AllRestrictions;

            //Check the existing restrictions
            int index = _restrictions.Count;

            while (--index >= 0)
            {
                ReportRestriction restriction = allRestrictions.FirstOrDefault(i => i.GUID == _restrictions[index].GUID);
                if (restriction == null)
                {
                    _restrictions.RemoveAt(index);
                }
                else
                {
                    _restrictions[index].SetSourceReference(restriction.Source);
                    _restrictions[index].Report = Report;
                    _restrictions[index].Model  = restriction.Model;
                }
            }

            //Add new restrictions
            foreach (var restriction in allRestrictions)
            {
                ReportRestriction outputRestriction = _restrictions.FirstOrDefault(i => i.GUID == restriction.GUID);
                if (outputRestriction == null)
                {
                    outputRestriction = ReportRestriction.CreateReportRestriction();
                    Helper.CopyProperties(restriction, outputRestriction);
                    _restrictions.Add(outputRestriction);
                }
                outputRestriction.PivotPosition = restriction.PivotPosition;
            }
        }
コード例 #3
0
ファイル: Report.cs プロジェクト: andrecamilo/Seal-Report
 public string TranslateRestriction(ReportRestriction restriction, string value)
 {
     string result = value;
     if (restriction.IsDateTime && ReportRestriction.HasDateKeyword(value))
     {
         result = TranslateDateKeywords(result);
     }
     return result;
 }
コード例 #4
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.None))
                        {
                            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
            });
        }
コード例 #5
0
        void drillModel(ReportModel model, string src, string dst, string val, ref string destLabel, ref string srcRestriction, Report newReport, Report rootReport)
        {
            //First remove hidden elements
            model.Elements.RemoveAll(i => i.PivotPosition == PivotPosition.Hidden);

            foreach (var element in model.Elements.Where(i => i.MetaColumnGUID == src).ToList())
            {
                var els = new Dictionary <ReportElement, string>();
                if (val != null)
                {
                    //Drill Down, check src
                    ReportRestriction restriction = ReportRestriction.CreateReportRestriction();
                    model.Restrictions.Add(restriction);
                    restriction.Source         = model.Source;
                    restriction.Report         = newReport;
                    restriction.Model          = model;
                    restriction.MetaColumnGUID = src;
                    restriction.Operator       = Operator.Equal;
                    restriction.SetDefaults();
                    restriction.IsForNavigation = true;
                    if (val == "")
                    {
                        restriction.Operator = Operator.IsEmpty;
                    }
                    restriction.SetNavigationValue(val);
                    if (!string.IsNullOrEmpty(model.Restriction))
                    {
                        model.Restriction = string.Format("({0}) {1} ", model.Restriction, model.IsLINQ ? "&&" : "AND");
                    }
                    model.Restriction += ReportRestriction.kStartRestrictionChar + restriction.GUID + ReportRestriction.kStopRestrictionChar;

                    srcRestriction = restriction.GeNavigationDisplayValue();

                    if (rootReport.ExecutionView.GetBoolValue(Parameter.DrillAllParameter))
                    {
                        //Check if children are involved

                        //Elements having a child reaching the src -> they are now the src
                        foreach (var child in model.Elements.Where(i => i.MetaColumn.DrillChildren.Contains(src)))
                        {
                            els.Add(child, src);
                        }

                        //Children elements of the new dst, change dst element to its child
                        var destColumn = model.Source.MetaData.AllColumns.FirstOrDefault(i => i.GUID == dst);
                        if (destColumn != null && destColumn.DrillChildren.Count > 0)
                        {
                            var childColumn = model.Source.MetaData.AllColumns.Where(i => destColumn.DrillChildren.Contains(i.GUID)).OrderBy(i => i.DisplayOrder).FirstOrDefault();
                            if (childColumn != null)
                            {
                                //Set new GUID for chidren
                                foreach (var child in model.Elements.Where(i => i.MetaColumnGUID == dst))
                                {
                                    els.Add(child, childColumn.GUID);
                                }
                            }
                        }
                    }
                }
                else
                {
                    //Drill Up: 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, model.IsLINQ ? "true" : "1=1");
                    }

                    //Check if parents are involved
                    if (rootReport.ExecutionView.GetBoolValue(Parameter.DrillAllParameter))
                    {
                        //Check element having a child to dest
                        //First metacolumn sorted by DisplayOrder
                        var parentColumn = model.Source.MetaData.AllColumns.Where(i => i.DrillChildren.Contains(dst)).OrderBy(i => i.DisplayOrder).FirstOrDefault();
                        if (parentColumn != null)
                        {
                            //Set new GUID for parents
                            foreach (var parent in model.Elements.Where(i => i.MetaColumnGUID == dst))
                            {
                                els.Add(parent, parentColumn.GUID);
                            }
                        }

                        //Check element having a child to src
                        foreach (var child in element.MetaColumn.DrillChildren)
                        {
                            foreach (var parent in model.Elements.Where(i => i.MetaColumnGUID == child))
                            {
                                els.Add(parent, src);
                            }
                        }
                    }
                }
                //Set new GUID
                if (element != null)
                {
                    changeElementGUID(element, dst, newReport.ExecutionView);
                    destLabel = element.DisplayNameElTranslated;
                }

                foreach (var el in els)
                {
                    changeElementGUID(el.Key, el.Value, newReport.ExecutionView);
                }
            }
        }
コード例 #6
0
        public ReportExecution Navigate(string navigation, Report rootReport)
        {
            var    parameters    = HttpUtility.ParseQueryString(navigation);
            string reportPath    = parameters.Get("rpa"); //For subreports
            string executionGuid = parameters.Get("exe"); //For drill
            bool   isSubReport   = !string.IsNullOrEmpty(reportPath);
            bool   isDrill       = !string.IsNullOrEmpty(executionGuid);

            Report newReport = null;

            //Check if the same navigation with the same execution GUID occured
            var previousNav = Navigations.Values.FirstOrDefault(i => i.Execution.NavigationParameter == navigation && i.Execution.RootReport.ExecutionGUID == rootReport.ExecutionGUID);

            if (previousNav != null)
            {
                newReport = previousNav.Execution.Report;
            }

            string destLabel = "", srcRestriction = "", srcGUID = "";

            if (Navigations.Count(i => i.Value.Execution.RootReport.ExecutionGUID == rootReport.ExecutionGUID) == 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.ExecutionGUID == rootReport.ExecutionGUID).Value.Link.Href = !string.IsNullOrEmpty(rootReport.WebUrl) ? ReportExecution.ActionViewHtmlResultFile + "?execution_guid=" + rootReport.ExecutionGUID : rootReport.ResultFilePath;
            }

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

                    int index = 1;
                    while (true)
                    {
                        string res = parameters.Get("res" + index.ToString());
                        string val = parameters.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))
                            {
                                restriction.SetNavigationValue(val);
                                srcRestriction = restriction.GeNavigationDisplayValue();
                            }
                        }
                        index++;
                    }
                    //Get display value
                    string dis = parameters.Get("dis");
                    if (!string.IsNullOrEmpty(dis))
                    {
                        srcRestriction = HttpUtility.HtmlDecode(dis);
                    }
                }
            }
            else if (!string.IsNullOrEmpty(executionGuid))
            {
                //Drill
                var els = new Dictionary <ReportElement, string>();
                if (newReport == null)
                {
                    if (Navigations.ContainsKey(executionGuid))
                    {
                        newReport = Navigations[executionGuid].Execution.Report.Clone();
                    }
                    else
                    {
                        //Drill from dashboard
                        newReport = rootReport.Clone();
                    }
                    newReport.ExecutionGUID = Guid.NewGuid().ToString();
                    string src = parameters.Get("src");
                    string dst = parameters.Get("dst");
                    string val = parameters.Get("val");
                    newReport.DrillParents.Add(src);

                    foreach (var model in newReport.Models)
                    {
                        foreach (var element in model.Elements.Where(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 (val != null)
                                {
                                    //Drill Down: Add restriction
                                    ReportRestriction restriction = ReportRestriction.CreateReportRestriction();
                                    restriction.Source         = model.Source;
                                    restriction.Report         = newReport;
                                    restriction.Model          = model;
                                    restriction.MetaColumnGUID = src;
                                    restriction.SetDefaults();
                                    restriction.Operator = Operator.Equal;
                                    if (val == "")
                                    {
                                        restriction.Operator = Operator.IsEmpty;
                                    }
                                    else if (val == null)
                                    {
                                        restriction.Operator = Operator.IsNull;
                                    }
                                    restriction.SetNavigationValue(val);
                                    model.Restrictions.Add(restriction);
                                    if (!string.IsNullOrEmpty(model.Restriction))
                                    {
                                        model.Restriction = string.Format("({0}) {1} ", model.Restriction, model.IsLINQ ? "&&" : "AND");
                                    }
                                    model.Restriction += ReportRestriction.kStartRestrictionChar + restriction.GUID + ReportRestriction.kStopRestrictionChar;

                                    srcRestriction = restriction.GeNavigationDisplayValue();
                                    srcGUID        = restriction.MetaColumnGUID;

                                    if (rootReport.ExecutionView.GetBoolValue(Parameter.DrillAllParameter))
                                    {
                                        //Check if children are involved

                                        //Elements having a child reaching the src -> they are now the src
                                        foreach (var child in model.Elements.Where(i => i.MetaColumn.DrillChildren.Contains(src)))
                                        {
                                            els.Add(child, src);
                                        }

                                        //Children elements of the new dst, change dst element to its child
                                        var destColumn = model.Source.MetaData.AllColumns.FirstOrDefault(i => i.GUID == dst);
                                        if (destColumn != null && destColumn.DrillChildren.Count > 0)
                                        {
                                            var childColumn = model.Source.MetaData.AllColumns.Where(i => destColumn.DrillChildren.Contains(i.GUID)).OrderBy(i => i.DisplayOrder).FirstOrDefault();
                                            if (childColumn != null)
                                            {
                                                //Set new GUID for chidren
                                                foreach (var child in model.Elements.Where(i => i.MetaColumnGUID == dst))
                                                {
                                                    els.Add(child, childColumn.GUID);
                                                }
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    //Drill Up: 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");
                                    }

                                    //Check if parents are involved
                                    if (rootReport.ExecutionView.GetBoolValue(Parameter.DrillAllParameter))
                                    {
                                        //Check element having a child to dest
                                        //First metacolumn sorted by DisplayOrder
                                        var parentColumn = model.Source.MetaData.AllColumns.Where(i => i.DrillChildren.Contains(dst)).OrderBy(i => i.DisplayOrder).FirstOrDefault();
                                        if (parentColumn != null)
                                        {
                                            //Set new GUID for parents
                                            foreach (var parent in model.Elements.Where(i => i.MetaColumnGUID == dst))
                                            {
                                                els.Add(parent, parentColumn.GUID);
                                            }
                                        }

                                        //Check element having a child to src
                                        foreach (var child in element.MetaColumn.DrillChildren)
                                        {
                                            foreach (var parent in model.Elements.Where(i => i.MetaColumnGUID == child))
                                            {
                                                els.Add(parent, src);
                                            }
                                        }
                                    }
                                }
                                //Set new GUID
                                if (element != null)
                                {
                                    changeElementGUID(element, dst, newReport.ExecutionView);
                                    destLabel = element.DisplayNameElTranslated;
                                }

                                foreach (var el in els)
                                {
                                    changeElementGUID(el.Key, el.Value, newReport.ExecutionView);
                                }
                            }
                        }
                    }
                }
            }

            if (newReport == null)
            {
                throw new Exception("Invalid Navigation");
            }

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

            if (previousNav == null)
            {
                if (!string.IsNullOrEmpty(srcRestriction))
                {
                    newReport.DisplayName = string.Format("{0} > {1}", newReport.ExecutionName, srcRestriction);
                }
                else
                {
                    newReport.DisplayName = newReport.ExecutionName;
                    if (!string.IsNullOrEmpty(destLabel))
                    {
                        newReport.DisplayName += string.Format(" < {0}", destLabel);
                    }
                }
            }
            return(new ReportExecution()
            {
                NavigationParameter = navigation, Report = newReport, RootReport = rootReport
            });
        }
コード例 #7
0
 void setContext(ITypeDescriptorContext context)
 {
     _restriction = context.Instance as ReportRestriction;
 }