private void GenerateReport()
        {
            ReportHeaderBand headerBand = new ReportHeaderBand();
            DetailBand       detailBand = new DetailBand();
            XRLabel          title      = new XRLabel();
            string           dataPath   = dataSet.Tables[0].TableName;

            report            = new XtraReport();
            report.DataMember = dataPath;

            headerBand.Height   = 50;
            detailBand.Height   = 25;
            title.Size          = new Size(report.PageWidth - report.Margins.Left - report.Margins.Right - 1, 50);
            title.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
            title.Font          = new Font(title.Font.FontFamily, 20);
            title.Text          = "Hierarchical Data Report";

            headerBand.Controls.Add(title);
            report.Bands.Add(headerBand);
            report.Bands.Add(detailBand);

            AddDataFieldsToBand(dataSet.Tables[0], detailBand, dataPath, false);

            XtraReportBase nextReport = report;

            for (int i = 0; i < dataSet.Relations.Count; i++)
            {
                DataRelation dataRelation = dataSet.Relations[i];

                dataPath  += "." + dataRelation.RelationName;
                nextReport = CreateReportForTable(nextReport, dataRelation.ChildTable, dataPath);
            }

            report.DataSource = dataSet;
        }
Exemple #2
0
        private void ReadDetailReportBand(XtraReportBase xtraReport, DetailReportBand band, StiPage page)
        {
            detailLevel++;
            StiPage tempPage = new StiPage(report);

            string storeDataSourceName = currentDataSourceName;

            currentDataSourceName = band.DataMember;

            ProcessBands(band, band.Controls, tempPage);

            //StiDataBand masterBand = page.Components[page.Components.Count - 1] as StiDataBand;
            //if (masterBand != null)
            //{
            //    foreach (StiComponent comp in tempPage.Components)
            //    {
            //        StiDataBand dataBand = comp as StiDataBand;
            //        if (dataBand != null)
            //        {
            //            dataBand.MasterComponent = masterBand;
            //        }
            //    }
            //}

            //page.Components.AddRange(tempPage.Components);
            SortBands(tempPage);
            page.Components.Add(tempPage);

            currentDataSourceName = storeDataSourceName;

            detailLevel--;
        }
Exemple #3
0
        private void ReadGroupFooterBand(XtraReportBase xtraReport, GroupFooterBand xtraBand, StiPage page)
        {
            StiGroupFooterBand band = new StiGroupFooterBand();

            page.Components.Add(band);

            ReadBand(xtraBand, band);
        }
        public static ReportDataContext GetReportDataContext(this XtraReportBase report)
        {
            VerifyListBrowserAndDataSourceAreCreated(report);

            var field = typeof(XtraReportBase).GetField("fDataContext", BindingFlags.NonPublic | BindingFlags.Instance);

            return((ReportDataContext)field.GetValue(report));
        }
        public static ListBrowser GetListBrowser(this XtraReportBase report)
        {
            VerifyListBrowserAndDataSourceAreCreated(report);

            var field = typeof(XtraReportBase).GetField("dataBrowser", BindingFlags.NonPublic | BindingFlags.Instance);

            return((ListBrowser)field.GetValue(report));
        }
Exemple #6
0
        private void ReadPageFooterBand(XtraReportBase xtraReport, PageFooterBand xtraBand, StiPage page)
        {
            StiFooterBand band = new StiFooterBand();

            band.PrintOnAllPages = true;
            page.Components.Add(band);

            ReadBand(xtraBand, band);
        }
        public static void InitializeDataMember(this XtraReportBase report, string dataMember)
        {
            if (string.IsNullOrWhiteSpace(dataMember))
            {
                throw new ArgumentNullException(nameof(dataMember));
            }

            report.DataMember = dataMember;
        }
Exemple #8
0
        private void ReadBottomMarginBand(XtraReportBase xtraReport, BottomMarginBand xtraBand, StiPage page)
        {
            StiPageFooterBand band = new StiPageFooterBand();

            page.Components.Add(band);

            ReadBand(xtraBand, band);

            page.Margins.Bottom = page.Margins.Bottom - report.Unit.ConvertToHInches(band.Height);
        }
Exemple #9
0
        private void ReadTopMarginBand(XtraReportBase xtraReport, TopMarginBand xtraBand, StiPage page)
        {
            StiPageHeaderBand band = new StiPageHeaderBand();

            page.Components.Add(band);

            ReadBand(xtraBand, band);

            page.Margins.Top = page.Margins.Top - report.Unit.ConvertToHInches(band.Height);
        }
        public static string ParseFormula(XtraReportBase Rpt, string strFormula)
        {
            while (true)
            {
                int Index = strFormula.IndexOf("GetCurrentColumnValue");
                if (Index < 0)
                {
                    return(strFormula);
                }

                int StartParam = strFormula.IndexOf("(", Index);
                if (Index < 0)
                {
                    return(strFormula);
                }

                int EndParam = strFormula.IndexOf(")", StartParam);
                if (Index < 0)
                {
                    return(strFormula);
                }

                object TmpValue = Rpt.GetCurrentColumnValue(strFormula.Substring(StartParam + 2, EndParam - StartParam - 3));

                if (TmpValue == null)
                {
                    throw new ApplicationException(string.Concat("Field ",
                                                                 strFormula.Substring(StartParam + 1, EndParam - StartParam - 1), " tidak ditemukan"));
                }

                string OldValue = strFormula.Substring(Index, EndParam - Index + 1);

                Type tp = TmpValue.GetType();
                if (tp == typeof(string))
                {
                    strFormula = strFormula.Replace(OldValue,
                                                    string.Concat("\"", ((string)TmpValue).Replace("\"", "\\\""), "\""));
                }
                else if (tp == typeof(decimal))
                {
                    strFormula = strFormula.Replace(OldValue,
                                                    ((decimal)TmpValue).ToString(BaseUtility.DefaultCultureInfo));
                }
                else if (tp == typeof(bool))
                {
                    strFormula = strFormula.Replace(OldValue,
                                                    ((bool)TmpValue).ToString(BaseUtility.DefaultCultureInfo));
                }
                else if (tp == typeof(DateTime))
                {
                    strFormula = strFormula.Replace(OldValue, string.Concat("#",
                                                                            ((DateTime)TmpValue).ToString(BaseUtility.DefaultCultureInfo), "#"));
                }
            }
        }
        protected BaseGroupHeaderHelper(XtraReport report, XtraReportBase detailReport,
                                        GroupField[] fields)
            : base(report, detailReport)
        {
            if (fields == null || fields.Length == 0)
            {
                throw new ArgumentNullException(nameof(fields));
            }

            this.ContainerBand = this.CreateContainerBand(fields);
        }
Exemple #12
0
 private double ReadValueFrom(XtraReportBase xtraReport, double value)
 {
     if (reportUnit == ReportUnit.TenthsOfAMillimeter)
     {
         return(value / 10);
     }
     else
     {
         return(value);
     }
 }
        public static ObjectDataSource InitializeDataSource(this XtraReportBase report,
                                                            string dataMember = null)
        {
            var result = new ObjectDataSource();

            if (!string.IsNullOrWhiteSpace(dataMember))
            {
                result.DataMember = dataMember;
            }
            report.DataSource = result;
            return(result);
        }
        private XtraReportBase CreateReportForTable(XtraReportBase parentReport, DataTable dataTable, string dataPath)
        {
            DetailReportBand detailReport = new DetailReportBand();
            DetailBand       detailBand   = new DetailBand();

            detailBand.Height = 25;
            detailReport.Bands.Add(detailBand);
            parentReport.Bands.Add(detailReport);
            AddDataFieldsToBand(dataTable, detailBand, dataPath, false);
            detailReport.DataMember = dataPath;

            return(detailReport);
        }
        public static XtraReportBase GetLastDetailReport(this XtraReportBase report)
        {
            var repBand = report.GetBandByType <DetailReportBand>();

            if (repBand != null)
            {
                return(ReportExtensions.GetLastDetailReport(repBand));
            }
            else
            {
                return(report);
            }
        }
        public static ReportFooterBand AddReportFooterBand(this XtraReportBase report)
        {
            var result = report.GetBandByType <ReportFooterBand>();

            if (result == null)
            {
                result = new ReportFooterBand()
                {
                    HeightF = 0F,
                };
                report.Bands.Add(result);
            }
            return(result);
        }
        public static GroupFooterBand AddGroupFooterBand(this XtraReportBase report)
        {
            var result = new GroupFooterBand
            {
                KeepTogether    = true,
                HeightF         = 0F,
                GroupUnion      = GroupFooterUnion.WithLastDetail,
                RepeatEveryPage = false,
                Level           = report.Bands.OfType <GroupFooterBand>().Count(),
            };

            report.Bands.Add(result);
            return(result);
        }
 public static string JoinWithDataMember(this XtraReportBase report, string dataMember)
 {
     if (string.IsNullOrWhiteSpace(dataMember))
     {
         return(report.DataMember);
     }
     else if (string.IsNullOrWhiteSpace(report.DataMember))
     {
         return(dataMember);
     }
     else
     {
         return($"{report.DataMember}.{dataMember}");
     }
 }
Exemple #19
0
        private void ReadDetailBand(XtraReportBase xtraReport, DetailBand xtraBand, StiPage page)
        {
            StiDataBand band = new StiDataBand();

            page.Components.Add(band);

            ReadBand(xtraBand, band);

            band.EvenStyle = xtraBand.EvenStyleName;
            band.OddStyle  = xtraBand.OddStyleName;

            string dsName = ParseDatasourceName(xtraReport.DataMember, true);

            band.DataSourceName   = dsName;
            band.DataRelationName = ParseRelationName(xtraReport.DataMember);
        }
        public static GroupHeaderBand AddGroupHeaderBand(this XtraReportBase report,
                                                         string fieldName,
                                                         XRColumnSortOrder sortOrder = XRColumnSortOrder.Ascending)
        {
            var result = new GroupHeaderBand
            {
                KeepTogether    = true,
                HeightF         = 0F,
                GroupUnion      = GroupUnion.WithFirstDetail,
                RepeatEveryPage = true,
                Level           = report.Bands.OfType <GroupHeaderBand>().Count(),
            };

            result.GroupFields.Add(new GroupField(fieldName, sortOrder));
            report.Bands.Add(result);
            return(result);
        }
Exemple #21
0
        private void ReadReportFooterBand(XtraReportBase xtraReport, ReportFooterBand xtraBand, StiPage page)
        {
            StiBand band = null;

            if (detailLevel == 0)
            {
                band = new StiReportSummaryBand();
            }
            else
            {
                band = new StiFooterBand();
                (band as StiFooterBand).PrintOnAllPages = false;
            }
            page.Components.Add(band);

            ReadBand(xtraBand, band);
        }
Exemple #22
0
 private void ProcessBands(XtraReportBase xtraReport, XRControlCollection controls, StiPage page)
 {
     foreach (XRControl band in controls)
     {
         if (band is GroupHeaderBand)
         {
             ReadGroupHeaderBand(xtraReport, band as GroupHeaderBand, page);
         }
         else if (band is GroupFooterBand)
         {
             ReadGroupFooterBand(xtraReport, band as GroupFooterBand, page);
         }
         else if (band is DetailBand)
         {
             ReadDetailBand(xtraReport, band as DetailBand, page);
         }
         else if (band is ReportHeaderBand)
         {
             ReadReportHeaderBand(xtraReport, band as ReportHeaderBand, page);
         }
         else if (band is ReportFooterBand)
         {
             ReadReportFooterBand(xtraReport, band as ReportFooterBand, page);
         }
         else if (band is PageHeaderBand)
         {
             ReadPageHeaderBand(xtraReport, band as PageHeaderBand, page);
         }
         else if (band is PageFooterBand)
         {
             ReadPageFooterBand(xtraReport, band as PageFooterBand, page);
         }
         else if (band is TopMarginBand)
         {
             ReadTopMarginBand(xtraReport, band as TopMarginBand, page);
         }
         else if (band is BottomMarginBand)
         {
             ReadBottomMarginBand(xtraReport, band as BottomMarginBand, page);
         }
         else if (band is DetailReportBand)
         {
             ReadDetailReportBand(xtraReport, band as DetailReportBand, page);
         }
     }
 }
        public static GroupHeaderBand AddGroupHeaderBand(this XtraReportBase report, params GroupField[] fields)
        {
            var result = new GroupHeaderBand
            {
                KeepTogether    = true,
                HeightF         = 0F,
                GroupUnion      = GroupUnion.WithFirstDetail,
                RepeatEveryPage = true,
                Level           = report.Bands.OfType <GroupHeaderBand>().Count(),
            };

            if (fields != null && fields.Length > 0)
            {
                result.GroupFields.AddRange(fields);
            }
            report.Bands.Add(result);
            return(result);
        }
Exemple #24
0
 public GroupHeadersHelper(XtraReport report, XtraReportBase detailReport,
                           params string[] fieldNames)
     : base(report, detailReport)
 {
     this.headerHelpers = new List <GroupHeaderHelper>(fieldNames.Length);
     if (fieldNames != null && fieldNames.Length > 0)
     {
         for (int i = fieldNames.Length - 1; i >= 0; i--)
         {
             this.headerHelpers.Add(this.Report.AddGroupHeader(fieldNames[i]));
         }
         this.headerHelpers[0].AdjustBorderStyle();
         for (int i = 0; i < this.headerHelpers.Count - 1; i++)
         {
             this.headerHelpers[i].AdjustBookmarks(this.headerHelpers[i + 1].ContainerControl);
         }
         this.headerHelpers[this.headerHelpers.Count - 1].AdjustBookmarks();
     }
 }
        public static void InitStyles(XtraReportBase rep)
        {
            // Create different odd and even styles
            XRControlStyle oddStyle  = new XRControlStyle();
            XRControlStyle evenStyle = new XRControlStyle();

            // Specify the odd style appearance
            oddStyle.BackColor = Color.LightBlue;
            oddStyle.StyleUsing.UseBackColor = true;
            oddStyle.StyleUsing.UseBorders   = false;
            oddStyle.Name = "OddStyle";

            // Specify the even style appearance
            evenStyle.BackColor = Color.LightPink;
            evenStyle.StyleUsing.UseBackColor = true;
            evenStyle.StyleUsing.UseBorders   = false;
            evenStyle.Name = "EvenStyle";

            // Add styles to report's style sheet
            rep.RootReport.StyleSheet.AddRange(new DevExpress.XtraReports.UI.XRControlStyle[] { oddStyle, evenStyle });
        }
        private void CreateReportHeader(XtraReportBase report, string caption, Color labelColor, int fontSize)
        {
            //Creating a Report header
            ReportHeaderBand header = new ReportHeaderBand();

            report.Bands.Add(header);
            header.HeightF = 0;

            XRLabel label = new XRLabel();

            header.Controls.Add(label);

            label.BackColor     = labelColor;
            label.Font          = new Font("Tahoma", fontSize, FontStyle.Bold);
            label.Text          = caption;
            label.TextAlignment = DevExpress.XtraPrinting.TextAlignment.TopCenter;
            label.LocationF     = new PointF(0, 0);

            XtraReport rep = report.RootReport;

            label.WidthF = rep.PageWidth - rep.Margins.Right - rep.Margins.Left;
        }
        // Another method of passing Subreport it's parent datasource
        // This method did not work for me.
        //private static void ChangeSubreportParentForDataContext(this XRSubreport subreport)
        //{
        //    var report = subreport.ReportSource;

        //    //var dataContextContainer = subreport.Report;
        //    var dataContextContainer = subreport.RootReport;

        //    //container.Bands[BandKind.Detail].Controls.Add(report);

        //    var field = typeof(XtraReportBase).GetField("fParent", BindingFlags.NonPublic | BindingFlags.Instance);
        //    field.SetValue(report, dataContextContainer);
        //}

        #endregion

        #region Set DataSource

        public static void SetReportDataSource(this XtraReportBase report, object datasource)
        {
            if (report == null)
            {
                return;
            }

            if (datasource == null)
            {
                report.DataSource = null;
            }

            // Set Datasource, Must be a Collection
            else if (datasource is IEnumerable)
            {
                report.DataSource = datasource;
            }
            else
            {
                report.DataSource = new List <object> {
                    datasource
                }
            };
        }
 public static GroupFooterHelper AddGroupFooter(this XtraReportBase report)
 {
     return(new GroupFooterHelper(report.AddGroupFooterBand()));
 }
 public static T GetBandByType <T>(this XtraReportBase report) where T : Band
 {
     return(report.Bands.GetBandByType(typeof(T)) as T);
 }
Exemple #30
0
 public static ReportHeaderHelper AddReportHeader(this XtraReportBase report)
 {
     return(new ReportHeaderHelper(report.AddReportHeaderBand()));
 }
 private static void VerifyListBrowserAndDataSourceAreCreated(XtraReportBase report)
 {
     // Force ListBrowser to be created, along with DataContext
     // Very important.
     report.GetCurrentRow();
 }