Exemplo n.º 1
0
        private IEnumerable <ISeriesView> BuildSeries(ReportUnit reportUnit, int itemIndex, int totalCount)
        {
            var result = new List <ISeriesView>();

            // series for pie chart
            if (settings.IsPieChartSelected)
            {
                // values count should be equivalent to details depth (levels count)
                var valuesCount = settings.PieChartDetailsDepth + 1;
                // add series for current report unit
                var series = BuildSeries <MCPieSeries>(reportUnit, 0, valuesCount);
                result.Add(series);
                // add all detailing report units as new series with next details depth (level)
                result.AddRange(BuildDetailsPieSeries(reportUnit, series, 1, valuesCount));
            }

            // series for bar chart with columns
            if (settings.IsBarChartColumnsSelected)
            {
                result.AddRange(BuildBarChartSeries <MCStackedColumnSeries>(reportUnit, itemIndex, totalCount));
            }

            // series for bar chart with rows
            if (settings.IsBarChartRowsSelected)
            {
                result.AddRange(BuildBarChartSeries <MCStackedRowSeries>(reportUnit, itemIndex, totalCount));
            }

            return(result);
        }
Exemplo n.º 2
0
        private IEnumerable <ISeriesView> BuildDetailsPieSeries(ReportUnit parentReportUnit, ISeriesView parentSeries,
                                                                int valueIndex, int valuesCount)
        {
            var result = new List <ISeriesView>();

            foreach (var reportUnit in parentReportUnit.Detailing)
            {
                ISeriesView series = null;
                // if detailing report unit category is different create new series else continue parent series
                if (reportUnit.CategoryId != parentReportUnit.CategoryId)
                {
                    series = BuildSeries <MCPieSeries>(reportUnit, valueIndex, valuesCount);
                    result.Add(series);
                }
                else
                {
                    series = parentSeries;
                    series.Values[valueIndex] = reportUnit;
                }

                // build series for every detailed report unit as new level (next value index)
                if (reportUnit.Detailing.Count > 0)
                {
                    result.AddRange(BuildDetailsPieSeries(reportUnit, series, valueIndex + 1, valuesCount));
                }
            }

            return(result);
        }
Exemplo n.º 3
0
        public async Task GenerateReport(Squad scoutedSquad, Squad scoutSquad)
        {
            Report report = new Report
            {
                ArmyId = scoutSquad.ArmyId,
                City   = scoutSquad.City,
                Turn   = scoutSquad.Army.Player.Game.Turn
            };

            _dbContext.Reports.Add(report);

            foreach (SquadUnit squadUnit in scoutedSquad.SquadUnits)
            {
                ReportUnit newReportUnit = new ReportUnit
                {
                    ReportId      = report.Id,
                    UnitId        = squadUnit.UnitId,
                    NumberOfUnits = squadUnit.NumberOfUnits
                };

                _dbContext.ReportUnits.Add(newReportUnit);
            }

            await _dbContext.SaveChangesAsync();
        }
Exemplo n.º 4
0
        private void report_FillEmptySpace(object sender, BandEventArgs e)
        {
            if (!(bool)DrawZBelowTheTableParameter.Value)
            {
                FillEmptySpace -= report_FillEmptySpace;
                return;
            }
            int bandHeight = GraphicsUnitConverter.Convert(e.Band.Height, ReportUnit.ToDpi(), ReportUnit.HundredthsOfAnInch.ToDpi());

            if (bandHeight <= 30)
            {
                return;
            }
            Size     size         = new Size(612, bandHeight - 30);
            Size     sizeInPixels = XRConvert.Convert(size, GraphicsDpi.HundredthsOfAnInch, GraphicsDpi.Pixel);
            Bitmap   zBitmap      = new Bitmap(sizeInPixels.Width, sizeInPixels.Height);
            Graphics gr           = Graphics.FromImage(zBitmap);

            using (Pen pen = new Pen(Color.FromArgb(205, 205, 205), 4)) {
                Point[] points = new Point[] {
                    new Point(0, 4),
                    new Point(sizeInPixels.Width, 4),
                    new Point(0, sizeInPixels.Height - 4),
                    new Point(sizeInPixels.Width, sizeInPixels.Height - 4)
                };
                gr.DrawLines(pen, points);
            }
            XRPictureBox pictureBox = new XRPictureBox();

            pictureBox.BackColor = Color.Transparent;
            pictureBox.Size      = size;
            pictureBox.Location  = new Point(19, 15);
            pictureBox.Image     = zBitmap;
            e.Band.Controls.Add(pictureBox);
        }
Exemplo n.º 5
0
        public async Task <LatestUploadReport> GetLatestUploadsReport(int value, ReportUnit unit)
        {
            if (value == 0)
            {
                throw new ArgumentException("value must be greater than zero.");
            }

            LatestUploadReport report = new LatestUploadReport();

            Task <IEnumerable <DocumentInfo> > uploadsTask = null;

            switch (unit)
            {
            case ReportUnit.Units:
                uploadsTask = _repository.GetLastNItemsAsync(value);
                break;

            case ReportUnit.Hours:
                uploadsTask = _repository.GetItemsInLastNHoursAsync(value);
                break;
            }

            Task <IEnumerable <LatestUploadReportEntry> > reportTask = _repository.GenerateStorageReport();

            await Task.WhenAll(uploadsTask, reportTask);

            report.Uploads           = uploadsTask.Result;
            report.StorageByCategory = reportTask.Result;

            return(report);
        }
Exemplo n.º 6
0
        private List <ReportUnit> BuildReportUnits(IEnumerable <ITransaction> transactions, int categoryLevel, int detailsDepth,
                                                   Sorting sorting)
        {
            var result = new List <ReportUnit>();

            foreach (var t in GetCategorizedTransactions(transactions, categoryLevel))
            {
                // create report unit
                var reportUnit = new ReportUnit
                {
                    CategoryId = t.CategoryId,
                    Caption    = _data.Categories.FirstOrDefault(_ => _.Id == t.CategoryId)?.Name,
                    Amount     = Math.Abs(t.Transactions.Sum(_ => ToMainCurrency(_.TransactionAmount, _.TransactionCurrencyId)))
                };

                // build details
                if (detailsDepth > 0)
                {
                    reportUnit.Detailing = BuildReportUnits(t.Transactions, categoryLevel + 1, detailsDepth - 1, sorting);
                }

                // add report unit to result list
                result.Add(reportUnit);
            }

            var sortedResult = ApplySorting(result, sorting).ToList();

            // fix caption for empty category after sorting (empty category should be first/last if alphabetical sorting)
            sortedResult.Where(x => x.CategoryId == null).ToList().ForEach(x => x.Caption = NoneCategoryName);

            return(sortedResult);
        }
Exemplo n.º 7
0
        private ISeriesView BuildSeries <TSeries>(ReportUnit reportUnit, int itemIndex = 0, int itemsCount = 1)
            where TSeries : Series, new()
        {
            var series = new TSeries()
            {
                Title      = reportUnit.Caption,
                Values     = new ChartValues <ReportUnit>(),
                DataLabels = settings.ShowValue
            };

            // all previous and next values should be equal to 0 but not current
            for (int i = 0; i < itemsCount; i++)
            {
                series.Values.Add(i != itemIndex ? new ReportUnit() : reportUnit);
            }

            return(series);
        }
Exemplo n.º 8
0
        private List <ISeriesView> BuildBarChartSeries <TSeries>(ReportUnit reportUnit, int itemIndex, int totalCount)
            where TSeries : Series, new()
        {
            var result = new List <ISeriesView>();

            if (reportUnit.Detailing.Count > 0)
            {
                foreach (var reportUnitDetail in reportUnit.Detailing)
                {
                    result.Add(BuildSeries <TSeries>(reportUnitDetail, itemIndex, totalCount));
                }
            }
            else
            {
                result.Add(BuildSeries <TSeries>(reportUnit, itemIndex, totalCount));
            }

            return(result);
        }
Exemplo n.º 9
0
        /// <summary>
        /// The measure text width pixels.
        /// </summary>
        /// <param name="unit">
        /// The unit.
        /// </param>
        /// <param name="text">
        /// The text.
        /// </param>
        /// <param name="font">
        /// The font.
        /// </param>
        /// <returns>
        /// The <see cref="float"/>.
        /// </returns>
        private float MeasureTextWidthPixels(ReportUnit unit, string text, Font font)
        {
            var gr = Graphics.FromHwnd(IntPtr.Zero);

            int factor;

            if (unit == ReportUnit.HundredthsOfAnInch)
            {
                gr.PageUnit = GraphicsUnit.Inch;
                factor      = 100;
            }
            else
            {
                gr.PageUnit = GraphicsUnit.Millimeter;
                factor      = 10;
            }

            var size = gr.MeasureString(text, font);

            gr.Dispose();

            return(size.Width * factor);
        }
Exemplo n.º 10
0
        private List <ReportUnit> BuildReportUnits(IEnumerable <ITransaction> transactions, PeriodType periodType, DateTime dateFrom, DateTime dateUntil)
        {
            var result  = new List <ReportUnit>();
            var periods = PeriodUtils.SplitDateRange(periodType, dateFrom, dateUntil);

            foreach (var period in periods)
            {
                // get transactions for the correspond date range
                var periodTransactions = transactions
                                         .Where(x => x.TransactionDate >= period.DateFrom && x.TransactionDate <= period.DateUntil);

                // create report unit
                var reportUnit = new ReportUnit
                {
                    Caption = PeriodUtils.GetPeriodRangeDetails(periodType, period.DateFrom, period.DateUntil),
                    Amount  = Math.Abs(periodTransactions.Sum(_ => ToMainCurrency(_.TransactionAmount, _.TransactionCurrencyId)))
                };
                // add report unit to result list
                result.Add(reportUnit);
            }

            return(result);
        }
Exemplo n.º 11
0
 private Brush GetBrush(ReportUnit reportUnit)
 {
     return(Brushes.Blue);
 }
Exemplo n.º 12
0
 /// <summary>
 /// Gets the troop amounts
 /// </summary>
 /// <param name="groupAmount">The RegEx group with home troops</param>
 /// <param name="groupLost">The RegEx group with lost troops</param>
 /// <param name="groupOut">The RegEx group with the out troops</param>
 private static Dictionary<UnitTypes, ReportUnit> GetTroops(Group groupAmount, Group groupLost, Group groupOut)
 {
     var troops = new Dictionary<UnitTypes, ReportUnit>();
     for (int i = 0; i < groupAmount.Captures.Count; i++)
     {
         if (WorldUnits.Default[i] != null)
         {
             var unit = new ReportUnit(WorldUnits.Default[i]);
             int val;
             if (GetTroopCount(groupAmount.Captures[i].Value, out val))
             {
                 unit.AmountStart = val;
                 if (GetTroopCount(groupLost.Captures[i].Value, out val))
                 {
                     unit.AmountLost = val;
                 }
                 if (groupOut != null && groupOut.Captures.Count > 0 && GetTroopCount(groupOut.Captures[i].Value, out val))
                 {
                     unit.AmountOut = val;
                 }
                 troops.Add(unit.Unit.Type, unit);
             }
         }
     }
     return troops;
 }
Exemplo n.º 13
0
        public StiReport Convert(string fileXtraReports)
        {
            CultureInfo currentCulture = Application.CurrentCulture;

            try
            {
                Application.CurrentCulture = new CultureInfo("en-US", false);

                report = new StiReport();
                report.Pages.Clear();

                XtraReport xtraReport = new XtraReport();
                xtraReport.LoadLayout(fileXtraReports);

                detailLevel           = 0;
                currentDataSourceName = xtraReport.DataMember;
                reportUnit            = xtraReport.ReportUnit;

                if (reportUnit == ReportUnit.TenthsOfAMillimeter)
                {
                    report.ReportUnit = StiReportUnitType.Millimeters;
                }
                else
                {
                    report.ReportUnit = StiReportUnitType.HundredthsOfInch;
                }

                ReadPage(xtraReport, report);

                foreach (StiPage page in report.Pages)
                {
                    StiComponentsCollection comps = page.GetComponents();
                    foreach (StiComponent comp in comps)
                    {
                        comp.Page = page;
                    }

                    page.LargeHeightFactor = 2;
                    page.LargeHeight       = true;
                }


                //create datasources and relations, variables
                foreach (DictionaryEntry de in fields)
                {
                    string[] parts = ((string)de.Key).Split(new char[] { '.' });
                    if (parts.Length >= 2)
                    {
                        StiDataSource ds = report.Dictionary.DataSources[parts[0]];
                        if (ds == null)
                        {
                            ds       = new StiDataTableSource();
                            ds.Name  = parts[0];
                            ds.Alias = parts[0];
                            (ds as StiDataTableSource).NameInSource = datasetName;
                            ds.Columns.Add(new StiDataColumn("id"));
                            report.Dictionary.DataSources.Add(ds);
                        }

                        int pos = 1;
                        while (pos < parts.Length - 1)
                        {
                            string dsName = parts[pos];
                            if (dsName.StartsWith(ds.Name))
                            {
                                dsName = dsName.Substring(ds.Name.Length);
                            }

                            StiDataSource childSource = report.Dictionary.DataSources[dsName];
                            if (childSource == null)
                            {
                                childSource       = new StiDataTableSource();
                                childSource.Name  = dsName;
                                childSource.Alias = dsName;
                                (childSource as StiDataTableSource).NameInSource = datasetName;
                                childSource.Columns.Add(new StiDataColumn("id"));
                                report.Dictionary.DataSources.Add(childSource);
                            }
                            StiDataRelation relation = ds.GetChildRelations()[parts[pos]];
                            if (relation == null)
                            {
                                relation = new StiDataRelation(parts[pos], ds, childSource, new string[1] {
                                    "id"
                                }, new string[1] {
                                    "id"
                                });
                                report.Dictionary.Relations.Add(relation);
                            }
                            ds = childSource;
                            pos++;
                        }

                        if (ds.Columns[parts[pos]] == null)
                        {
                            StiDataColumn column = new StiDataColumn();
                            column.Name = parts[pos];
                            ds.Columns.Add(column);
                        }
                    }
                    else if (parts.Length == 1)
                    {
                        StiVariable varr = report.Dictionary.Variables[parts[0]];
                        if (varr == null)
                        {
                            varr       = new StiVariable();
                            varr.Name  = parts[0];
                            varr.Alias = parts[0];
                            report.Dictionary.Variables.Add(varr);
                        }
                    }
                }

                return(report);
            }
            finally
            {
                Application.CurrentCulture = currentCulture;
            }
        }