protected Image GenerateCN22(string trackingNo, DespatchItem[] items, bool barcode=true, bool tracked=true)
        {
            Bitmap output = new Bitmap(Resources.CN22);
            Graphics img = Graphics.FromImage(output);
            img.InterpolationMode = InterpolationMode.HighQualityBicubic;
            var font = new Font("Bradley Hand ITC", 16, FontStyle.Bold);
            img.DrawString("X", font, Brushes.Black, 45, 144);
            img.DrawString(DateTime.Now.ToString("yyyy-MM-dd"), font, Brushes.Black, 272, 645);

            var labelrow = 36;
            var weightrowx = 444;
            var valuerowx = 577;

            var rowstart = 255;
            var rowoffset = 44;

            Dictionary<string, int> counts = new Dictionary<string, int>();
            Dictionary<string, decimal> weights = new Dictionary<string, decimal>();
            Dictionary<string, decimal> values = new Dictionary<string, decimal>();

            if (items != null) {
                foreach (var item in items) {
                    //var price = item.SalePrice;
                    var price = "10.00";
                    if (!counts.ContainsKey(item.ItemGroupName))
                    {
                        var quantity = int.Parse(item.QuantityOrdered);
                        counts[item.ItemGroupName] = quantity;
                        weights[item.ItemGroupName] = decimal.Parse(item.Weight) * quantity;
                        values[item.ItemGroupName] = decimal.Parse(price) * quantity;
                    }
                    else
                    {
                        var quantity = int.Parse(item.QuantityOrdered);
                        counts[item.ItemGroupName] += quantity;
                        weights[item.ItemGroupName] += decimal.Parse(item.Weight) * quantity;
                        values[item.ItemGroupName] += decimal.Parse(price) * quantity;
                    }
                }
            }

            if (counts.Count > 4)
            {
                throw new ArgumentOutOfRangeException("More than 4 item groups!");
            }

            int i = 0;
            foreach (var entry in counts)
            {
                img.DrawString(string.Format("{0} x {1}", entry.Value, entry.Key), font, Brushes.Black, labelrow, rowstart + (i * rowoffset));
                img.DrawString(string.Format("{0} KG", weights[entry.Key]), font, Brushes.Black, weightrowx, rowstart + (i * rowoffset));
                img.DrawString(string.Format("{0} GBP", values[entry.Key]), font, Brushes.Black, valuerowx, rowstart + (i * rowoffset));
                i++;
            }

            img.DrawString(string.Format("{0} KG", weights.Sum(x => x.Value)), font, Brushes.Black, weightrowx, 520);
            img.DrawString(string.Format("{0} GBP", values.Sum(x => x.Value)), font, Brushes.Black, valuerowx, 520);
            img.DrawImage(Resources.SIGNATURE, new Rectangle(470, 610, 200, 80));
            img.Save();

            Bitmap printable = new Bitmap(720, 960);
            var label = Graphics.FromImage(printable);
            label.DrawImageUnscaled(output, 0, 0);

            if (tracked)
            {
                label.DrawString("TRACKED MAIL", new Font("Bradley Hand ITC", 23, FontStyle.Bold), Brushes.Black, 225, 720);
            }
            if (barcode)
            {
                Image code = Barcode.DoEncode(TYPE.CODE39, trackingNo, true, 600, 150);
                label.DrawImage(code, (720 - 600) / 2, 770);
            }

            label.Save();

            //printable.Save("C:\\Temp\\cn22.png");
            return printable;
        }
Beispiel #2
0
		public void Calculate() {
			Lessees = new Dictionary<Lessee, ResultInfo>();
			Vacancy = new ResultInfo();
			Landlord = new ResultInfo();
			if ( Project == Project.Empty ) return;

			foreach ( var fac in Project.Assignments ) {
				foreach ( var fa in fac ) {
					if ( !Lessees.ContainsKey(fa.Lessee) ) Lessees[fa.Lessee] = new ResultInfo();
					Lessees[fa.Lessee].Lessee = fa.Lessee;
					if ( fa.Start < Lessees[fa.Lessee].StartDate ) Lessees[fa.Lessee].StartDate = fa.Start;
					if ( fa.End > Lessees[fa.Lessee].EndDate ) Lessees[fa.Lessee].EndDate = fa.End;
					Lessees[fa.Lessee].Durations.Add(new Interval(fa.StartIntervalIndex, fa.EndIntervalIndex));
					Lessees[fa.Lessee].Members = fa.Lessee.Members;
					Lessees[fa.Lessee].FlatSize += fac.Flat.Size * fa.Duration;
				}
				Vacancy.Members += fac.VacantDuration;
				Vacancy.FlatSize += fac.Flat.Size * fac.VacantDuration;
			}

			foreach ( var result in Lessees.Values ) {
				result.AdvancePayment = TimeInterval.Within(result.StartDate, result.EndDate).Sum(
					i => result.Lessee.Payments.Get(i.Start) / 2.0);
                result.Members *= result.Duration;
			}

			foreach ( var cost in Project.Costs ) {
				if ( !Landlord.Costs.ContainsKey(cost) ) Landlord.Costs[cost] = 0;
				var devisor = CalculateDevisor(cost, Lessees, Vacancy);
				foreach ( var lessee in Lessees.Keys ) {
					var option = cost.Options.FirstOrDefault(o => o.Lessee == lessee); 
					if ( option == null || (!option.Affected && !option.Exempt) ) continue;
					if ( option.Exempt ) Landlord.Costs[cost] += CalculateAmount(cost, Lessees[lessee], devisor);
					else Lessees[lessee].Costs[cost] = CalculateAmount(cost, Lessees[lessee], devisor);
				}
				if ( cost.AffectsVacancy ) Vacancy.Costs[cost] = CalculateAmount(cost, Vacancy, devisor);
			}

			Error = new ResultInfo();
			foreach ( var cost in Project.Costs ) {
				Error.Costs[cost] = Math.Abs(Lessees.Sum(i => i.Value.Costs.ContainsKey(cost) ? i.Value.Costs[cost] : 0)
					+ (Vacancy.Costs.ContainsKey(cost) ? Vacancy.Costs[cost] : 0)
					+ (Landlord.Costs.ContainsKey(cost) ? Landlord.Costs[cost] : 0 )
					- cost.Amount);
			}
			
			NotifyPropertyChanged("Result");
		}
        public Action BestAction(BitArray state)
        {
            List<Rule> fitting = new List<Rule>();
            foreach (Rule r in RuleSet)
            {
                if (IsActive(r, state))
                {
                    fitting.Add(r);
                }
            }
            Dictionary<Action, Counter> pred = new Dictionary<Action, Counter>();
            foreach (Action a in possibleActions)
                pred.Add(a, new Counter());
            foreach (Rule r in fitting)
            {
                pred[r.RuleAction].Add(r.Prediction);
            }
            float randomPred = Random.value * pred.Sum(val=> val.Value.Value());

            Action best = Action.GoHome;
            float maxValue = 0F;
            foreach(KeyValuePair<Action, Counter> k in pred)
            {
                //if (k.Value.Value() > maxValue)
                //{
                //    maxValue = k.Value.Value();
                //    best = k.Key;
                //}
                best = k.Key;
                randomPred -= k.Value.Value();
                if (randomPred <= 0)
                    break;
            }
            LastVoters.Add (fitting.Where((e)=>e.RuleAction == best).ToList());
            if (LastVoters.Count > maxDelay)
                LastVoters.RemoveAt(0);
            // return highest answer
            return best;
        }
Beispiel #4
0
 private static void UpdatePatchAfterQuestion(Dictionary<string, long> dict, long lS, string lN)
 {
     var listNameOfPatches = dict.Keys.ToList();
     listNameOfPatches.Sort((x, y) => UpdatingLib.GetDate(x).CompareTo(UpdatingLib.GetDate(y)));
     string lastPatch = listNameOfPatches.Last();
     long sizePatches = dict.Sum(l => l.Value);
     if ((UpdatingLib.GetDate(lN) > UpdatingLib.GetDate(lastPatch)) ||
         (UpdatingLib.GetDate(lN) == UpdatingLib.GetDate(lastPatch) && lS <= sizePatches))
     {
         var f = new UpdatingLib("L");
         f.Updating();
     }
     else
     {
         var f = new UpdatingLib("P");
         f.Updating();
     }
 }
        public StringBuilder FillSectionData(string contents, string json)
        {
            var sectionMatches = SectionRegex.Matches(contents);
            var sections = new Dictionary<string, SectionData>();

            foreach (Match match in sectionMatches)
            {
                // extract the matched sections into variables 
                var sectionData = match.Value.Split(':');
                var operation = sectionData[1];
                var name = sectionData[2].TrimEnd('#', '-', '>');

                if (!sections.ContainsKey(name))
                    sections.Add(name, new SectionData() { NameLength = name.Length });

                switch (operation)
                {
                    case "start":
                        sections[name].Start = match.Index + match.Length;
                        break;
                    case "stop":
                        sections[name].Stop = match.Index;
                        sections[name].Contents = contents.Substring(sections[name].Start, sections[name].Stop - sections[name].Start).Trim(' ', '\n', '\t', '\r');
                        break;
                }
            }

            // find the master for this template
            // ###master            
            // todo:
            // return an HTML error describing the missing
            var masterMatch = MasterRegex.Match(contents, 0);
            if (!masterMatch.Success)
                return new StringBuilder(contents, contents.Length * 2);

            var removal = sections.Values.OrderByDescending(_ => _.Stop);
            foreach (SectionData sd in removal)
            {
                // <!--####section:start:####-->
                // <!--####section:stop:####-->
                int start = sd.Start - sd.NameLength - 29;
                int stop = sd.Stop + sd.NameLength + 28;
                contents = contents.Remove(start, stop - start);
            }


            // remove the master tag from the render pipeline
            contents = contents.Remove(masterMatch.Index, masterMatch.Length);

            // this logic is only needed if there is a master template with sections
            // any content not in a section will be automatically assumed as the 
            // "content" section and appended to it (if it was already created)
            if (!sections.ContainsKey("contents"))
            {
                sections.Add("contents", new SectionData { });
                sections["contents"].Contents = contents.Trim(' ', '\n', '\t', '\r');
            }

            var masterPath = masterMatch.Value.Split(':')[1].TrimEnd('#');
            string master = _template.Render(masterPath, json);

            // recycle variable for efficiency
            sectionMatches = SectionRegex.Matches(master);

            // foreach section in the master, 
            // replace the section with the contents from the template
            // if the sections don't exist then leave them because there
            // might be default content

            var masterSections = new Dictionary<string, SectionData>();
            foreach (Match match in sectionMatches)
            {
                // extract the matched sections into variables
                var sectionData = match.Value.Split(':');
                var operation = sectionData[1];
                var name = sectionData[2].TrimEnd('#', '-', '>');

                if (!masterSections.ContainsKey(name))
                    masterSections.Add(name, new SectionData() { NameLength = name.Length });

                switch (operation)
                {
                    case "start":
                        masterSections[name].Start = match.Index + match.Length;
                        break;
                    case "stop":
                        masterSections[name].Stop = match.Index;
                        break;
                }
            }

            // use a pesamistic estimate for the length of the string builder (considering we might get donuts later
            var sb = new StringBuilder(master, (master.Length + sections.Sum(_ => _.Value.Contents.Length)) * 2);

            var replacement = masterSections.OrderByDescending(_ => _.Value.Stop);
            foreach (KeyValuePair<string, SectionData> kvp in replacement)
            {
                if (sections.ContainsKey(kvp.Key))
                {
                    sb.Remove(masterSections[kvp.Key].Start, masterSections[kvp.Key].Stop - masterSections[kvp.Key].Start);
                    sb.Insert(masterSections[kvp.Key].Start, "\n" + sections[kvp.Key].Contents + "\n");
                }
            }

            return sb;
        }
Beispiel #6
0
        /// <summary>
        /// This method automatically evaluates the optimal width of each column based on its contents
        /// </summary>
        /// <param name="currentReport">Current Telerik.Reporting.Report object</param>
        /// <param name="itemList">List of *Info objects belonging to the process which is related to this report</param>
        /// <param name="graphics">System.Drawing.Graphics object is needed to retrieve text's width in pixels</param>
        //TODO: Method is too complex. Refactor!
        private void RearrangeColumns(Report currentReport, IEnumerable<IInfoClass> itemList, Graphics graphics)
        {
            //Initializing variables
            var colNum = 0;     //counter for columns
            double maxRows = 0;     //max number of rows from all headers
            double extraSpace = 0;      //space left after the first rearrangement
            var headerWidthDict = new Dictionary<int, double>();    //key - column index, value - width of column's header in pixels
            var columnToExpand = new Dictionary<int, double>();     //columns which were limited in there desired width
            var unitType = currentReport.Width.Type;    //may be inches or centimetres or smth else
            double headerHeight = 0;    //the height of one row of header's text in pixels
            var emptyColumns = new List<int>();
            var columnInitialSizeDict = new Dictionary<int, double>();
            var widthOfAllPreviousColumns =
                (100 / Unit.FromPixels(100, unitType).Value) * _indentOffset;    //all the space occupied to the left of current processing column
            _dataHeights = new Dictionary<string, List<int>>();

            foreach (var col in _colDict)   //first rearrangement
            {
                colNum++;

                var propName = col.Value[0];    //field's system name
                var propDisplayName = col.Value[1];     //field's display name

                //full width of column's header in pixels
                double headerLength = 0;
                var pageHeaderItem = currentReport.Items["pageHeader"].Items.ElementAt(col.Key) as TextBox;
                if (pageHeaderItem != null)
                {
                    var headerSize = MeasureDisplayStringSize(propDisplayName, ToSystemFont(pageHeaderItem.Style.Font), graphics);
                    headerLength = headerSize.Width;
                    headerHeight = headerSize.Height;
                    headerWidthDict.Add(col.Key, headerLength);
                }

                //is based on the ItemList and stores the contents of the specified column
                var contentList = new List<ReportData>();

                if (itemList != null && itemList.Any())
                {
                    var prop = itemList.First().GetPropertyByFullName(propName);
                    if (prop != null)
                    {
                        contentList.AddRange(itemList.Select(x =>
                        {
                            var ancestor = x.GetAncestor(prop);
                            if (ancestor == null)
                                return ReportData.GetDefault(prop.PropertyType);

                            var fieldProperty = _fieldAttrDict.Keys.FirstOrDefault(p => p.Name == propName);
                            return new ReportData(prop, ancestor, fieldProperty == null ? null : _fieldAttrDict[fieldProperty], currentReport);
                        }));
                    }
                }

                if (contentList.Count > 0)
                {
                    _dataHeights.Add(propName, contentList.Select(x => x.Height).ToList());
                }

                double lessThanColName = 0;     //strings from the contents of the column that contain less symbols than the column's header    
                double moreThanColName = 0;     //strings from the contents of the column that contain more symbols than the column's header
                double contentMaxLength = 0;    //the longest string from the contents of the column

                if (contentList.Count > 0)
                {
                    lessThanColName = contentList.Count(x => x.Width < propDisplayName.Length);
                    moreThanColName = contentList.Count(x => x.Width >= propDisplayName.Length);
                    var contentMax = contentList.OrderByDescending(x => x.Width).First();
                    if (contentMax.Width > 0)
                    {
                        contentMaxLength = contentMax.GetPixels(currentReport, graphics);
                    }
                    else
                        contentMaxLength = 0;
                }

                double contentResultLength = 0;     //the desired width of the column in pixels
                double headerPartMaxLength = 0;     //width in pixels of the biggest part of column's name if it contains ' ' (spaces) or '_' (underscores)
                if (contentMaxLength < headerLength && Regex.IsMatch(propDisplayName, @"[\s_]"))
                {
                    string[] parts;
                    if (propDisplayName.Contains(" "))
                    {
                        parts = propDisplayName.Split(' ');
                        headerPartMaxLength = parts.Max(
                            x => MeasureDisplayStringSize(x, ToSystemFont(currentReport.Items["pageHeader"].Style.Font), graphics).Width);
                    }
                    else
                    {
                        parts = propDisplayName.Split('_');
                        headerPartMaxLength = parts.Max(
                            x => MeasureDisplayStringSize(x, ToSystemFont(currentReport.Items["pageHeader"].Style.Font), graphics).Width);
                    }

                    //if column's header contains spaces or underscores and the longest string from the column's contents
                    //is shorter than the full-length header name then the optimal column width can be found as maximum
                    //between thw longest string from the contents and the longest part of the column name
                    contentResultLength = Math.Max(contentMaxLength, headerPartMaxLength);
                }
                else if (contentMaxLength < headerLength)
                {
                    //if the header cannot be logically splitted into parts and the longest string from the column's contents
                    //is shorter than column name then the header's width is the optimal
                    contentResultLength = headerLength;
                }
                else
                {
                    //if the longest string from the column's contents is longer than header then the desired width may be represented by:
                    // 1. the longest string from the column's contents in case when the portion of strings which contain more symbols than the column's name is bigger than 20% of all strings
                    // 2. the header in other case
                    contentResultLength = (moreThanColName / lessThanColName) > 0.25 ? contentMaxLength : headerLength;
                }

                //how many units is the average width of the column (all the space is divided by the number of columns)
                //and then how many pixels is this average width, calculated in units
                var defaultLenght = (100 / Unit.FromPixels(100, unitType).Value) * ((currentReport.Width.Value - Unit.FromPixels(widthOfAllPreviousColumns, unitType).Value) / (_colDict.Count - (colNum - 1)));

                var newWidth = Math.Min(contentResultLength + 3, defaultLenght);    //the final width of column in pixels
                var resultWidth = widthOfAllPreviousColumns + newWidth;     //offset for next columns in pixels
                widthOfAllPreviousColumns = resultWidth;

                columnInitialSizeDict.Add(col.Key, newWidth);

                if (colNum < _colDict.Count)    //if this is not the last column
                {
                    ((TextBox)currentReport.Items["pageHeader"].Items[col.Key + 1]).Location = new PointU(Unit.FromPixels(resultWidth, unitType), new Unit(0.4, unitType));
                    ((ReportItem)currentReport.Items["detail"].Items["rowPanel"].Items[colNum]).Location = new PointU(Unit.FromPixels(resultWidth, unitType), new Unit(0, unitType));
                }

                ((TextBox)currentReport.Items["pageHeader"].Items[col.Key]).Size = new SizeU(Unit.FromPixels(newWidth, unitType), new Unit(0.2, unitType));
                ((ReportItem)currentReport.Items["detail"].Items["rowPanel"].Items[colNum - 1]).Size = new SizeU(Unit.FromPixels(newWidth, unitType), new Unit(0.2, unitType));

                if (colNum == _colDict.Count)   //if this is the last column the free space to the right could remain
                    extraSpace = (currentReport.Width.Value) - Unit.FromPixels(widthOfAllPreviousColumns, unitType).Value;

                if (headerLength > 0)
                    maxRows = Math.Max(maxRows, (headerLength / (newWidth - (headerLength / propDisplayName.Length))));

                if ((contentResultLength + 3) > defaultLenght && contentMaxLength > 0)
                    columnToExpand.Add(col.Key, Unit.FromPixels(contentResultLength - defaultLenght, unitType).Value);

                if (contentMaxLength == 0)
                    emptyColumns.Add(col.Key);
            }

            if (extraSpace > 0)     //if there is free space to the right of the last column after first rearrangement
            {
                if (columnToExpand.Count == 0)  //if there are no columns which were cut to the average column width
                {
                    var sum = columnInitialSizeDict.Where(x => !emptyColumns.Contains(x.Key)).Sum(x => x.Value);
                    //var spacePerColumn = extraSpace * ((_colDict.Count - emptyColumns.Count) / sum);   //additional space (in units) to add to non-empty columns 
                    double addedSpace = 0;
                    maxRows = 0;
                    colNum = 0;

                    SizeU oldCellSize;      //size in units which the column has after first rearrangement
                    PointU oldCellLocation;     //location point of the column after first rearrangement

                    foreach (var col in _colDict)   //second rearrangement (simple: all extra space is divided equally between the columns )
                    {
                        var auxSpace = emptyColumns.Contains(col.Key) ? 0 : extraSpace * (columnInitialSizeDict[col.Key] / sum);

                        colNum++;

                        if (colNum < _colDict.Count)    //relocation of columns next to the current taking added space into account
                        {
                            oldCellLocation = ((TextBox)currentReport.Items["pageHeader"].Items[col.Key + 1]).Location;
                            ((TextBox)currentReport.Items["pageHeader"].Items[col.Key + 1]).Location = new PointU(new Unit(oldCellLocation.X.Value + auxSpace + addedSpace, unitType), new Unit(0.4, unitType));
                            oldCellLocation = ((ReportItem)currentReport.Items["detail"].Items["rowPanel"].Items[colNum]).Location;
                            ((ReportItem)currentReport.Items["detail"].Items["rowPanel"].Items[colNum]).Location = new PointU(new Unit(oldCellLocation.X.Value + auxSpace + addedSpace, unitType), new Unit(0, unitType));
                        }

                        //resizing the columns
                        oldCellSize = ((TextBox)currentReport.Items["pageHeader"].Items[col.Key]).Size;
                        ((TextBox)currentReport.Items["pageHeader"].Items[col.Key]).Size =
                            ((ReportItem)currentReport.Items["detail"].Items["rowPanel"].Items[colNum - 1]).Size =
                                new SizeU(new Unit(oldCellSize.Width.Value + auxSpace, unitType), new Unit(0.2, unitType));

                        if (headerWidthDict.ContainsKey(col.Key))   //getting number of rows for which the column name was wrapped
                            maxRows = Math.Max(maxRows, Unit.FromPixels(headerWidthDict[col.Key], unitType).Value / (oldCellSize.Width.Value + auxSpace - Unit.FromPixels(headerWidthDict[col.Key] / col.Value[1].Length, unitType).Value));

                        addedSpace += auxSpace;
                    }
                }
                else     //if there are columns which were cut to the average column width
                {
                    double spacePerColumn = 0;
                    maxRows = 0;
                    colNum = 0;

                    SizeU oldCellSize;
                    PointU oldCellLocation;

                    var sum = columnToExpand.Sum(x => x.Value);  //summarized space in units which forcibly shortened columns wanted to occupy over the average width value
                    double addedSpace = 0;  //units already got by the shortened columns from the extra space

                    //columns which weren't shortened forcibly
                    var headers = currentReport.Items["pageHeader"].Items.Cast<TextBox>().ToList();
                    headers = headers.Where(x => headers.IndexOf(x) > 0 && !columnToExpand.ContainsKey(headers.IndexOf(x)) && !emptyColumns.Contains(headers.IndexOf(x))).ToList();

                    double fullWidthHeadersSum = headers.Sum(x => x.Size.Width.Value);  //summarized width of non-shortened columns in units
                    double maxHeaderWidth = headers.Max(x => x.Size.Width.Value);   //the widest header from all non-shortened headers in units
                    double averageHeaderWidth = headers.Average(x => x.Size.Width.Value);     //average width of non-shortened headers in units               
                    averageHeaderWidth += (maxHeaderWidth - averageHeaderWidth) * 0.3;  //average value is taken 30% closer to maximum value to ensure that more columns could get additional space
                    double avgUp = headers.Where(x => x.Size.Width.Value > averageHeaderWidth).Count();     //number of headers that are wider than average

                    double extraSizeBoost = 0;  //units used to enlarge headers that are narrower than average

                    //second rearrangement (complex: if the extra space is smaller than the sum of units that shortened columns wanted to occupy over the average width,
                    //than this extra space is devided between shortened columns according to the portion of each column in that sum;
                    //otherwise each shortened column gets its desired additional space and the remaining is redistributed between the non-shortened columns
                    //based on the principle of less space to shorter columns, more space to wider ones)
                    foreach (var col in _colDict)
                    {
                        colNum++;

                        if (!emptyColumns.Contains(col.Key))
                        {
                            if (columnToExpand.ContainsKey(col.Key))    //if column was forcibly shortened
                            {
                                if (extraSpace > sum)
                                    spacePerColumn = columnToExpand[col.Key];
                                else
                                    spacePerColumn = extraSpace * (columnToExpand[col.Key] / sum);
                            }
                            else
                            {
                                if (extraSpace > sum)
                                {
                                    var currentSize = ((TextBox)currentReport.Items["pageHeader"].Items[col.Key]).Size.Width.Value;
                                    if (currentSize < averageHeaderWidth)
                                    {
                                        if (_colDict.Count != colNum)
                                        {
                                            var overSize = currentSize * 0.5f; //more space to columns which are narrower than the average
                                            currentSize += overSize;
                                            extraSizeBoost += overSize;
                                        }
                                    }
                                    else
                                    {
                                        currentSize -= (float)(extraSizeBoost / avgUp);
                                    }
                                    spacePerColumn = (extraSpace - sum) * (currentSize / fullWidthHeadersSum);
                                }
                                else
                                    spacePerColumn = 0;
                            }
                        }
                        else
                            spacePerColumn = 0;

                        if (colNum < _colDict.Count)
                        {
                            oldCellLocation = ((TextBox)currentReport.Items["pageHeader"].Items[col.Key + 1]).Location;
                            ((TextBox)currentReport.Items["pageHeader"].Items[col.Key + 1]).Location = new PointU(new Unit(oldCellLocation.X.Value + spacePerColumn + addedSpace, unitType), new Unit(0.4, unitType));
                            oldCellLocation = ((ReportItem)currentReport.Items["detail"].Items["rowPanel"].Items[colNum]).Location;
                            ((ReportItem)currentReport.Items["detail"].Items["rowPanel"].Items[colNum]).Location = new PointU(new Unit(oldCellLocation.X.Value + spacePerColumn + addedSpace, unitType), new Unit(0, unitType));
                        }

                        oldCellSize = ((TextBox)currentReport.Items["pageHeader"].Items[col.Key]).Size;
                        ((TextBox)currentReport.Items["pageHeader"].Items[col.Key]).Size =
                            ((ReportItem)currentReport.Items["detail"].Items["rowPanel"].Items[colNum - 1]).Size =
                                new SizeU(new Unit(oldCellSize.Width.Value + spacePerColumn, unitType), new Unit(0.2, unitType));

                        addedSpace += spacePerColumn;

                        oldCellSize = ((TextBox)currentReport.Items["pageHeader"].Items[col.Key]).Size;
                        if (headerWidthDict.ContainsKey(col.Key))
                            maxRows = Math.Max(maxRows, Unit.FromPixels(headerWidthDict[col.Key], unitType).Value / (oldCellSize.Width.Value + spacePerColumn - Unit.FromPixels(headerWidthDict[col.Key] / col.Value[1].Length, unitType).Value));
                    }
                }
            }

            //allocation of group aggregates
            foreach (var groupName in _groups)
            {
                var group = currentReport.Groups.FirstOrDefault(x => x.Name == groupName);

                if (group != null)
                {
                    var footerPanel = (Panel)group.GroupFooter.Items[0];
                    var groupIndex = _groups.IndexOf(groupName);
                    var groupOffset = new Unit(groupIndex * 0.15, currentReport.Width.Type);

                    if (footerPanel != null)
                    {
                        var aggregateItems = CreateAggregateItems(currentReport, true);

                        foreach (var item in aggregateItems)
                        {
                            item.Location = new PointU(item.Location.X - groupOffset, item.Location.Y);
                            item.Value = item.Value.Replace(":scope:", groupName);

                            footerPanel.Items.Add(item);
                        }
                    }
                }
            }

            //page aggregates
            var pageAggregatePanel = currentReport.Items["pageFooter"].Items["pageAggregatePanel"];

            if (pageAggregatePanel != null)
            {
                var pageFooter = currentReport.Items["pageFooter"] as PageFooterSection;

                var aggregateItems = CreateAggregateItems(currentReport, false);
                var maxFuncCount = _aggregateDict.Count > 0 ? _aggregateDict.Max(x => x.Value.Count) : 0;

                pageFooter.Height += Unit.FromPixels(16, unitType) * maxFuncCount;

                foreach (var item in aggregateItems)
                {
                    item.Style.Font.Size = new Unit(10);
                    pageAggregatePanel.Items.Add(item);
                }
            }

            if (maxRows < 1)    //height of Page Header Section is reduced by one row   
            {
                ((PageHeaderSection)currentReport.Items["pageHeader"]).Height -= Unit.Inch(0.1);
                //_originalPageHeaderHeight -= Unit.Inch(0.1);
            }
            else if (maxRows > 2)   //height of Page Header Section is increases by number of rows (if there are more than two)
            {
                ((PageHeaderSection)currentReport.Items["pageHeader"]).Height += Unit.Inch(Math.Min(Math.Ceiling(maxRows - 2) * (headerHeight > 0 ? Unit.FromPixels(headerHeight, unitType).Value : 0.25), 1.5));
                //_originalPageHeaderHeight += Unit.Inch(Math.Min(Math.Ceiling(maxRows - 2) * (headerHeight > 0 ? Unit.FromPixels(headerHeight, unitType).Value : 0.25), 1.5));
            }
        }