Exemplo n.º 1
0
        ///<summary>Adds a ReportObject with the given font, to the top-center of the Report Header Section.  Should only be done once, and done before any subTitles.</summary>
        public void AddTitle(string name, string title, Font font)
        {
            ReportComplexEvent.Fire(ODEventType.ReportComplex, Lan.g("ReportComplex", "Adding Title To Report") + "...");
            SizeF sizeF = _grfx.MeasureString(title, font);
            Size  size  = new Size((int)(sizeF.Width / _grfx.DpiX * 100 + 2), (int)(sizeF.Height / _grfx.DpiY * 100));
            int   xPos;

            if (_isLandscape)
            {
                xPos  = 1100 / 2;
                xPos -= 50;
            }
            else
            {
                xPos  = 850 / 2;
                xPos -= 30;
            }
            xPos -= size.Width / 2;
            if (_sections[AreaSectionType.ReportHeader] == null)
            {
                _sections.Add(new Section(AreaSectionType.ReportHeader, 0));
            }
            _reportObjects.Add(new ReportObject(name, AreaSectionType.ReportHeader, new Point(xPos, 0), size, title, font, ContentAlignment.MiddleCenter));
            //this is the only place a white buffer is added to a header.
            _sections[AreaSectionType.ReportHeader].Height = size.Height + 10;
        }
Exemplo n.º 2
0
        ///<summary>Adds a ReportObject with the given font, at the bottom-center of the Report Header Section.
        ///Should only be done after AddTitle.  You can add as many subtitles as you want.  Padding is added to the height only of the subtitle.</summary>
        public void AddSubTitle(string name, string subTitle, Font font, int padding)
        {
            ReportComplexEvent.Fire(ODEventType.ReportComplex, Lan.g("ReportComplex", "Adding SubTitle To Report") + "...");
            SizeF sizeF = _grfx.MeasureString(subTitle, font);
            Size  size  = new Size((int)(sizeF.Width / _grfx.DpiX * 100 + 2), (int)(sizeF.Height / _grfx.DpiY * 100));
            int   xPos;

            if (_isLandscape)
            {
                xPos  = 1100 / 2;
                xPos -= 50;
            }
            else
            {
                xPos  = 850 / 2;
                xPos -= 30;
            }
            xPos -= size.Width / 2;
            if (_sections[AreaSectionType.ReportHeader] == null)
            {
                _sections.Add(new Section(AreaSectionType.ReportHeader, 0));
            }
            //find the yPos+Height of the last reportObject in the Report Header section
            int yPos = _reportObjects.OfType <ReportObject>()
                       .Where(x => x.SectionType == AreaSectionType.ReportHeader)
                       .Select(x => x.Location.Y + x.Size.Height).Where(x => x > 0).DefaultIfEmpty(0).Max();

            _reportObjects.Add(new ReportObject(name, AreaSectionType.ReportHeader, new Point(xPos, yPos + padding), size, subTitle, font, ContentAlignment.MiddleCenter));
            _sections[AreaSectionType.ReportHeader].Height += size.Height + padding;
        }
Exemplo n.º 3
0
        ///<summary>Adds a ReportObject with the given font, at the bottom-center of the Report Header Section.
        ///Should only be done after AddTitle.  You can add as many subtitles as you want.  Padding is added to the height only of the subtitle.</summary>
        public void AddSubTitle(string name, string subTitle, Font font, int padding)
        {
            ReportComplexEvent.Fire(new ODEventArgs("ReportComplexEvent", Lan.g("ReportComplex", "Adding SubTitle To Report") + "..."));
            Size size = new Size((int)(_grfx.MeasureString(subTitle, font).Width / _grfx.DpiX * 100 + 2)
                                 , (int)(_grfx.MeasureString(subTitle, font).Height / _grfx.DpiY * 100 + 2));
            int xPos;

            if (_isLandscape)
            {
                xPos  = 1100 / 2;
                xPos -= 50;
            }
            else
            {
                xPos  = 850 / 2;
                xPos -= 30;
            }
            xPos -= (int)(size.Width / 2);
            if (_sections[AreaSectionType.ReportHeader] == null)
            {
                _sections.Add(new Section(AreaSectionType.ReportHeader, 0));
            }
            //find the yPos+Height of the last reportObject in the Report Header section
            int yPos = 0;

            foreach (ReportObject reportObject in _reportObjects)
            {
                if (reportObject.SectionType != AreaSectionType.ReportHeader)
                {
                    continue;
                }
                if (reportObject.Location.Y + reportObject.Size.Height > yPos)
                {
                    yPos = reportObject.Location.Y + reportObject.Size.Height;
                }
            }
            _reportObjects.Add(new ReportObject(name, AreaSectionType.ReportHeader, new Point(xPos, yPos + padding), size, subTitle, font, ContentAlignment.MiddleCenter));
            _sections[AreaSectionType.ReportHeader].Height += (int)size.Height + padding;
        }
Exemplo n.º 4
0
        ///<summary>Submits the queries to the database and makes query objects for each query with the results.  Returns false if one of the queries failed.</summary>
        public bool SubmitQueries(bool isShowMessage = false)
        {
            bool     hasRows         = false;
            bool     hasReportServer = !string.IsNullOrEmpty(PrefC.ReportingServer.DisplayStr);
            Graphics grfx            = Graphics.FromImage(new Bitmap(1, 1));
            string   displayText;
            ReportObjectCollection newReportObjects = new ReportObjectCollection();

            _sections.Add(new Section(AreaSectionType.Query, 0));
            for (int i = 0; i < _reportObjects.Count; i++)
            {
                if (_reportObjects[i].ObjectType == ReportObjectType.QueryObject)
                {
                    QueryObject query = (QueryObject)_reportObjects[i];
                    if (!query.SubmitQuery())
                    {
                        _actionCloseReportProgress?.Invoke();
                        MsgBox.Show(this, "There was an error generating this report."
                                    + (hasReportServer ? "\r\nVerify or remove the report server connection settings and try again." : ""));
                        return(false);
                    }
                    if (query.ReportTable.Rows.Count == 0)
                    {
                        continue;
                    }
                    hasRows    = true;
                    TotalRows += query.ReportTable.Rows.Count;
                    //Check if the query needs to be split up into sub queries.  E.g. one payment report query split up via payment type.
                    if (!String.IsNullOrWhiteSpace(query.ColumnNameToSplitOn))
                    {
                        ReportComplexEvent.Fire(ODEventType.ReportComplex, Lan.g("ReportComplex", "Creating Splits Based On") + " " + query.ColumnNameToSplitOn + "...");
                        //The query needs to be split up into sub queries every time the ColumnNameToSplitOn cell changes.
                        //Therefore, we need to create a separate QueryObject for every time the cell value changes.
                        string lastCellValue = "";
                        query.IsLastSplit = false;
                        QueryObject newQuery = null;
                        for (int j = 0; j < query.ReportTable.Rows.Count; j++)
                        {
                            if (query.ReportTable.Rows[j][query.ColumnNameToSplitOn].ToString() == lastCellValue)
                            {
                                if (newQuery == null)
                                {
                                    newQuery = query.DeepCopyQueryObject();
                                    newQuery.AddInitialHeader(newQuery.GetGroupTitle().StaticText, newQuery.GetGroupTitle().Font);
                                }
                                newQuery.ReportTable.ImportRow(query.ReportTable.Rows[j]);
                            }
                            else
                            {
                                //Must happen the first time through
                                if (newQuery != null)
                                {
                                    switch (newQuery.SplitByKind)
                                    {
                                    case SplitByKind.None:
                                        return(false);

                                    case SplitByKind.Enum:
                                        if (newQuery.ListEnumNames == null)
                                        {
                                            return(false);
                                        }
                                        displayText = newQuery.ListEnumNames[PIn.Int(newQuery.ReportTable.Rows[0][query.ColumnNameToSplitOn].ToString())];
                                        newQuery.GetGroupTitle().Size       = new Size((int)(grfx.MeasureString(displayText, newQuery.GetGroupTitle().Font).Width / grfx.DpiX * 100 + 2), (int)(grfx.MeasureString(displayText, newQuery.GetGroupTitle().Font).Height / grfx.DpiY * 100 + 2));
                                        newQuery.GetGroupTitle().StaticText = displayText;
                                        break;

                                    case SplitByKind.Definition:
                                        if (newQuery.DictDefNames == null)
                                        {
                                            return(false);
                                        }
                                        if (newQuery.DictDefNames.ContainsKey(PIn.Long(newQuery.ReportTable.Rows[0][query.ColumnNameToSplitOn].ToString())))
                                        {
                                            displayText = newQuery.DictDefNames[PIn.Long(newQuery.ReportTable.Rows[0][query.ColumnNameToSplitOn].ToString())];
                                            newQuery.GetGroupTitle().Size       = new Size((int)(grfx.MeasureString(displayText, newQuery.GetGroupTitle().Font).Width / grfx.DpiX * 100 + 2), (int)(grfx.MeasureString(displayText, newQuery.GetGroupTitle().Font).Height / grfx.DpiY * 100 + 2));
                                            newQuery.GetGroupTitle().StaticText = displayText;
                                        }
                                        else
                                        {
                                            newQuery.GetGroupTitle().StaticText = "Undefined";
                                        }
                                        break;

                                    case SplitByKind.Date:
                                        displayText = PIn.Date(newQuery.ReportTable.Rows[0][query.ColumnNameToSplitOn].ToString()).ToShortDateString();
                                        newQuery.GetGroupTitle().StaticText = displayText;
                                        newQuery.GetGroupTitle().Size       = new Size((int)(grfx.MeasureString(displayText, newQuery.GetGroupTitle().Font).Width / grfx.DpiX * 100 + 2), (int)(grfx.MeasureString(displayText, newQuery.GetGroupTitle().Font).Height / grfx.DpiY * 100 + 2));
                                        break;

                                    case SplitByKind.Value:
                                        displayText = newQuery.ReportTable.Rows[0][query.ColumnNameToSplitOn].ToString();
                                        newQuery.GetGroupTitle().StaticText = displayText;
                                        newQuery.GetGroupTitle().Size       = new Size((int)(grfx.MeasureString(displayText, newQuery.GetGroupTitle().Font).Width / grfx.DpiX * 100 + 2), (int)(grfx.MeasureString(displayText, newQuery.GetGroupTitle().Font).Height / grfx.DpiY * 100 + 2));
                                        break;
                                    }
                                    newQuery.SubmitQuery();
                                    newReportObjects.Add(newQuery);
                                }
                                if (newQuery == null && query.GetGroupTitle().StaticText != "")
                                {
                                    newQuery = query.DeepCopyQueryObject();
                                    newQuery.ReportTable.ImportRow(query.ReportTable.Rows[j]);
                                    newQuery.AddInitialHeader(newQuery.GetGroupTitle().StaticText, newQuery.GetGroupTitle().Font);
                                }
                                else
                                {
                                    newQuery = query.DeepCopyQueryObject();
                                    newQuery.ReportTable.ImportRow(query.ReportTable.Rows[j]);
                                }
                            }
                            lastCellValue = query.ReportTable.Rows[j][query.ColumnNameToSplitOn].ToString();
                        }
                        switch (newQuery.SplitByKind)
                        {
                        case SplitByKind.None:
                            return(false);

                        case SplitByKind.Enum:
                            if (newQuery.ListEnumNames == null)
                            {
                                return(false);
                            }
                            displayText = newQuery.ListEnumNames[PIn.Int(newQuery.ReportTable.Rows[0][query.ColumnNameToSplitOn].ToString())];
                            newQuery.GetGroupTitle().Size       = new Size((int)(grfx.MeasureString(displayText, newQuery.GetGroupTitle().Font).Width / grfx.DpiX * 100 + 2), (int)(grfx.MeasureString(displayText, newQuery.GetGroupTitle().Font).Height / grfx.DpiY * 100 + 2));
                            newQuery.GetGroupTitle().StaticText = displayText;
                            break;

                        case SplitByKind.Definition:
                            if (newQuery.DictDefNames == null)
                            {
                                return(false);
                            }
                            if (newQuery.DictDefNames.ContainsKey(PIn.Long(newQuery.ReportTable.Rows[0][query.ColumnNameToSplitOn].ToString())))
                            {
                                displayText = newQuery.DictDefNames[PIn.Long(newQuery.ReportTable.Rows[0][query.ColumnNameToSplitOn].ToString())];
                                newQuery.GetGroupTitle().Size       = new Size((int)(grfx.MeasureString(displayText, newQuery.GetGroupTitle().Font).Width / grfx.DpiX * 100 + 2), (int)(grfx.MeasureString(displayText, newQuery.GetGroupTitle().Font).Height / grfx.DpiY * 100 + 2));
                                newQuery.GetGroupTitle().StaticText = displayText;
                            }
                            else
                            {
                                newQuery.GetGroupTitle().StaticText = Lans.g(this, "Undefined");
                            }
                            break;

                        case SplitByKind.Date:
                            newQuery.GetGroupTitle().StaticText = PIn.Date(newQuery.ReportTable.Rows[0][query.ColumnNameToSplitOn].ToString()).ToShortDateString();
                            break;

                        case SplitByKind.Value:
                            newQuery.GetGroupTitle().StaticText = newQuery.ReportTable.Rows[0][query.ColumnNameToSplitOn].ToString();
                            break;
                        }
                        newQuery.SubmitQuery();
                        newQuery.IsLastSplit = true;
                        newReportObjects.Add(newQuery);
                    }
                    else
                    {
                        newReportObjects.Add(_reportObjects[i]);
                    }
                }
                else
                {
                    newReportObjects.Add(_reportObjects[i]);
                }
            }
            if (!hasRows && isShowMessage)
            {
                _actionCloseReportProgress?.Invoke();
                MsgBox.Show(this, "The report has no results to show.");
                return(false);
            }
            _reportObjects = newReportObjects;
            return(true);
        }