private static string GetItemString(Dictionary<string, string> dic)
        {
            var rev = dic.Reverse();

            var sb = new StringBuilder();
            foreach (var item in rev)
            {
                sb.Append(item.Key + "=" + item.Value + ",");
            }
            sb.Length--;
            return sb.ToString();
        }
        public virtual IEnumerable<RequireSettings> GetRequiredResources(string type)
        {
            List<RequireSettings> result = new List<RequireSettings>();// = _required.Where(r => r.Key.Item1 == type).Select(r => r.Value);
            try
            {
                IDictionary<int, List<RequireSettings>> group = new Dictionary<int, List<RequireSettings>>();
                foreach (var item in _required)
                {
                    if (item.Key.Item1 == type)
                    {
                        if (!group.ContainsKey(item.Value.Group))
                            group[item.Value.Group] = new List<RequireSettings>();
                        group[item.Value.Group].Add(item.Value);
                    }
                }

                foreach (var g in group.Reverse())
                {
                    result.AddRange(g.Value);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.Write(ex.Message);
                result = _required.Where(r => r.Key.Item1 == type).Select(r => r.Value).ToList();
            }

            return result;
        }
Exemple #3
0
        /// <summary>
        /// Creates the aggregate items.
        /// </summary>
        /// <param name="currentReport">The current report.</param>
        /// <param name="forGroups">if set to <c>true</c> [for groups].</param>
        /// <returns>List{TextBox}.</returns>
        private List<TextBox> CreateAggregateItems(Report currentReport, bool forGroups)
        {
            var height = new Unit(16);
            var aggregateItems = new Dictionary<string, List<TextBox>>();
            var additionalInfoForLastAggregateItem = new Dictionary<Unit, float>();

            //calculate server-side aggregates
            var aggregateDefinitions = _aggregateDict.ToList()
                .SelectMany(i => i.Value)
                .Where(d => !AggregateHelper.IsPageAggregateType(d.SummaryType))
                .ToList();

            var queryCriteria = new AggregateDataSourceQueryCriteria
            {
                ProcessName = _processName,
                FilterDefinition = GetFilterDefinition(currentReport)
            };
            var serverAggregateResults = AggregateProcessor.CalculateAggregates(aggregateDefinitions, queryCriteria);

            foreach (var aggregateInfo in _aggregateDict)
            {
                var col = _colDict.FirstOrDefault(x => x.Value[0] == aggregateInfo.Key);

                if (!col.Equals(default(KeyValuePair<int, string[]>)))
                {
                    var fieldValueMap = ((TextBox)currentReport.Items["detail"].Items["rowPanel"].Items[col.Key - 1]).Value.TrimStart('=');

                    var locationX = ((TextBox)currentReport.Items["detail"].Items["rowPanel"].Items[col.Key - 1]).Location.X;

                    var width = GetWidth(currentReport, aggregateInfo);

                    var locationY = new Unit(0, locationX.Type);

                    var list = new List<TextBox>();

                    foreach (var criteria in aggregateInfo.Value)
                    {
                        var textbox = new TextBox();
                        textbox.Style.Padding.Left = new Unit(1);
                        textbox.Style.Padding.Right = new Unit(1);
                        textbox.Style.Font.Size = new Unit(9);
                        textbox.Style.Font.Name = "Arial Unicode MS";
                        textbox.Style.VerticalAlign = VerticalAlign.Middle;
                        textbox.Size = new SizeU(Unit.Inch(width), height);
                        textbox.CanGrow = true;
                        textbox.TextWrap = true;
                        textbox.Location = new PointU(locationX, locationY);

                        if (_aggregateDict.Last().Equals(aggregateInfo))
                        {
                            EventHandler textboxItemDataBoundHandler = (s, e) =>
                                {
                                    var ft = new FormattedText((string)((Telerik.Reporting.Processing.TextBox)s).Value, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface(new System.Windows.Media.FontFamily(((Telerik.Reporting.Processing.VisualElement)s).Style.Font.Name), new System.Windows.FontStyle(), new FontWeight(), new FontStretch()), ((Telerik.Reporting.Processing.VisualElement)s).Style.Font.Size.Value, System.Windows.Media.Brushes.Black);

                                    if (ft.Width > ((Telerik.Reporting.Processing.TextBox)s).Size.Width.Value)
                                    {
                                        foreach (var f in additionalInfoForLastAggregateItem)
                                        {
                                            ((Telerik.Reporting.Processing.ReportItem)s).Location = new PointU(f.Key, ((Telerik.Reporting.Processing.ReportItem)s).Location.Y);
                                            ((Telerik.Reporting.Processing.ReportItem)s).Size = new SizeU(Unit.Inch(f.Value + ((Telerik.Reporting.Processing.ReportItem)s).Size.Width.Value), height);
                                            if (((Telerik.Reporting.Processing.ReportItem)s).Size.Width.Value >= ft.Width)
                                            {
                                                break;
                                            }
                                        }
                                    }
                                };
                            textbox.ItemDataBound += textboxItemDataBoundHandler;

                            EventHandler textboxDisposedHandler = null;
                            textboxDisposedHandler = (sender, args) =>
                            {
                                textbox.ItemDataBound -= textboxItemDataBoundHandler;
                                textbox.Disposed -= textboxDisposedHandler;
                            };
                            textbox.Disposed += textboxDisposedHandler;
                        }

                        if (AggregateHelper.IsPageAggregateType(criteria.SummaryType))
                        {
                            var aggregateFunction = forGroups ? "Exec" : "PageExec";
                            var aggregateFunctionParameter = forGroups ? ":scope:" : aggregateInfo.Key + "TextBox";

                            textbox.Value = string.Format(
                                    @"='{0}: ' + AfterCalculateAggregates({7}('{8}', {2}(BeforeCalculateAggregates(Fields.[{1}], ""{2}"", ""{3}"", ""{4}"", ""{5}"", ""{6}""))), ""{2}"", ""{3}"", ""{4}"", ""{5}"", ""{6}"")",
                                    AggregateHelper.GetAttribute(criteria.SummaryType).ShortName,
                                    aggregateInfo.Key,
                                    criteria.SummaryType,
                                    criteria.CustomConverter,
                                    criteria.TargetType,
                                    criteria.TypeName,
                                    criteria.ConverterParameter,
                                    aggregateFunction,
                                    aggregateFunctionParameter);
                        }
                        else
                        {
                            var result = serverAggregateResults.FirstOrDefault(r => r.ColumnName == criteria.ColumnName && r.SummaryType == criteria.SummaryType);
                            textbox.Value = string.Format("{0}: {1}", AggregateHelper.GetAttribute(criteria.SummaryType).ShortName, result);
                        }

                        list.Add(textbox);

                        locationY += height;
                    }
                    aggregateItems.Add(aggregateInfo.Key, list);
                }
            }

            if (aggregateItems.Count > 1)
            {
                var lastItem = aggregateItems.Last();
                aggregateItems.Remove(lastItem.Key);

                var penultimateItem = aggregateItems.Last();

                var indexOfPenultimateItem = _colDict.First(x => x.Value[0] == penultimateItem.Key).Key;
                var indexOfLastItem = _colDict.First(x => x.Value[0] == lastItem.Key).Key;
                if (indexOfLastItem - indexOfPenultimateItem > 1) // if exists at least one column between last and penultimate aggregate columns
                {
                    // fill additional info for last aggrigate item
                    var i = Convert.ToInt32((indexOfLastItem - indexOfPenultimateItem - 1) / 2);
                    foreach (var column in _colDict)
                    {
                        if (column.Key >= i + indexOfPenultimateItem + 1 && column.Value[0] != lastItem.Key)
                        {
                            var item = ((ReportItem)currentReport.Items["detail"].Items["rowPanel"].Items.FirstOrDefault(x => x.Name == string.Format("{0}TextBox", column.Value[0])));
                            if (item != null)
                            {
                                additionalInfoForLastAggregateItem.Add(item.Location.X, item.Size.Width.Value);
                            }
                        }
                    }

                    var descending = additionalInfoForLastAggregateItem.Reverse();
                    additionalInfoForLastAggregateItem = descending.ToDictionary(x => x.Key, x => x.Value);

                    // new size of penultimate item
                    foreach (var textbox in penultimateItem.Value)
                    {
                        textbox.Size = new SizeU(Unit.Inch(textbox.Size.Width.Value / 2), height);
                    }
                }
                aggregateItems.Add(lastItem.Key, lastItem.Value);
            }

            var returnList = new List<TextBox>();
            foreach (var aggregateItem in aggregateItems)
            {
                returnList.AddRange(aggregateItem.Value);
            }

            return returnList;
        }