Beispiel #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome! Press any key to procced...");
            Console.ReadKey();

            RegisterOwnFunctions();

            // create report instance
            Report report = new Report();
            // add report page
            ReportPage page = new ReportPage();

            report.Pages.Add(page);
            // always give names to objects you create. You can use CreateUniqueName method to do this;
            // call it after the object is added to a report.
            page.CreateUniqueName();

            // create title band
            page.ReportTitle = new ReportTitleBand();
            // native FastReport unit is screen pixel, use conversion
            page.ReportTitle.Height = Units.Centimeters * 1;
            page.ReportTitle.CreateUniqueName();

            // create two title text objects
            TextObject titleText1 = new TextObject();

            titleText1.Parent = page.ReportTitle;
            titleText1.CreateUniqueName();
            titleText1.Bounds    = new RectangleF(0, 0, Units.Centimeters * 8, Units.Centimeters * 1);
            titleText1.Font      = new Font("Arial", 14, FontStyle.Bold);
            titleText1.HorzAlign = HorzAlign.Center;

            // !!! use our function
            titleText1.Text = "[MyUpperCase(\"products\")]";
            // !!!

            // prepare the report
            report.Prepare();

            // save prepared report
            if (!Directory.Exists(outFolder))
            {
                Directory.CreateDirectory(outFolder);
            }
            report.SavePrepared($@"{outFolder}\Prepared Report.fpx");

            // export to image
            ImageExport image = new ImageExport();

            image.ImageFormat = ImageExportFormat.Jpeg;
            report.Export(image, $@"{outFolder}\report.jpg");

            // free resources used by report
            report.Dispose();

            Console.WriteLine("\nPrepared report and report exported as image have been saved into the 'out' folder.");
            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
Beispiel #2
0
        /// <summary>
        /// Add/Overlay Application Data Over Report
        /// </summary>
        public void AddCodeData()
        {
            PageFooterBand pageFooterBand = (PageFooterBand)this.FindObject("PageFooter1");
            // create title text
            TextObject textObjectOverlaySoftwareCertification = new TextObject();

            textObjectOverlaySoftwareCertification.Parent = pageFooterBand;
            textObjectOverlaySoftwareCertification.CreateUniqueName();
            //textObjectOverlaySoftwareCertification.Bounds = new RectangleF(Units.Centimeters, 0, Units.Centimeters * 10, Units.Centimeters * 1);

            //All Finance Documents use Processed, else Payments that use Emmited
            string prefix = (_reportFileName.EndsWith("ReportDocumentFinancePayment.frx"))
                ? Resx.global_report_overlay_software_certification_emitted
                : Resx.global_report_overlay_software_certification_processed
            ;

            //Processed|Emitted with certified Software Nº {0}/AT - Copyright {1} - Licenced to a {2} - Used only if System Country is Portugal
            if (SettingsApp.ConfigurationSystemCountry.Oid == SettingsApp.XpoOidConfigurationCountryPortugal &&
                (
                    _reportFileName.Contains("ReportDocumentFinance.frx") ||
                    _reportFileName.Contains("ReportDocumentFinancePayment.frx") ||
                    _reportFileName.Contains("ReportDocumentFinanceWayBill.frx")
                )
                )
            {
                textObjectOverlaySoftwareCertification.Text = string.Format(
                    Resx.global_report_overlay_software_certification,
                    prefix,
                    SettingsApp.SaftSoftwareCertificateNumber,
                    SettingsApp.SaftProductID,
                    GlobalFramework.LicenceCompany);

                //Add Hash Validation if Defined (In DocumentFinance Only)
                if (_hash4Chars != String.Empty)
                {
                    textObjectOverlaySoftwareCertification.Text = string.Format("{0} - {1}", _hash4Chars, textObjectOverlaySoftwareCertification.Text);
                }
            }
            ;

            //Finnally Add Overlay
            textObjectOverlaySoftwareCertification.ZOrder    = 1;
            textObjectOverlaySoftwareCertification.Left      = 0.0f;
            textObjectOverlaySoftwareCertification.Top       = 5.0f;
            textObjectOverlaySoftwareCertification.Width     = 718.2f;
            textObjectOverlaySoftwareCertification.Height    = 18.9f;
            textObjectOverlaySoftwareCertification.HorzAlign = HorzAlign.Center;
            textObjectOverlaySoftwareCertification.Font      = new Font("Arial", 8, FontStyle.Bold);

            //Assign _addCodeData to true to prevent repeat add CodeData
            _addCodeData = false;
        }
Beispiel #3
0
        private void AddTextObject()
        {
            textObject = new TextObject();
            textObject.CreateUniqueName();
            textObject.Width        = 100;
            textObject.Height       = 100;
            textObject.Text         = "Test";
            textObject.Left         = 0;
            textObject.Top          = 0;
            textObject.Border.Lines = BorderLines.All;

            dataBand.AddChild(textObject);
        }
Beispiel #4
0
        /// <summary>
        /// 生成默认报表
        /// </summary>
        /// <returns></returns>
        public FastReport.Report DefaultReport()
        {
            FastReport.Report report = new FastReport.Report();
            //判断有报表数据,则注册数据
            if (dt != null && dt.Rows.Count > 0)
            {
                report.RegisterData(dt, styleObject);
            }
            else
            {
                return(null);
            }
            //查询报表设置
            DataTable dtReportSet = DBHelper.GetTable("", "tb_report_set", "*", string.Format("set_object='{0}' and set_user='******'", styleObject, GlobalStaticObj.UserID), "", "order by set_num");

            if (dtReportSet == null || dtReportSet.Rows.Count == 0)
            {
                return(null);
            }
            // enable the "Employees" table to use it in the report
            report.GetDataSource(styleObject).Enabled = true;

            // add report page
            ReportPage page = new ReportPage();

            if (paperSize != null)
            {
                page.PaperWidth  = paperSize.Width;
                page.PaperHeight = paperSize.Height;
            }
            report.Pages.Add(page);
            // always give names to objects you create. You can use CreateUniqueName method to do this;
            // call it after the object is added to a report.
            page.CreateUniqueName();

            // create title band
            page.ReportTitle = new ReportTitleBand();
            // native FastReport unit is screen pixel, use conversion
            page.ReportTitle.Height = Units.Centimeters * 1;
            page.ReportTitle.CreateUniqueName();

            // create title text
            TextObject titleText = new TextObject();

            titleText.Parent = page.ReportTitle;
            titleText.CreateUniqueName();
            //titleText.Bounds = new RectangleF(Units.Centimeters * 5, 0, Units.Centimeters * 10, Units.Centimeters * 1);
            titleText.Bounds    = new RectangleF(0, 0, Units.Millimeters * page.PaperWidth, Units.Centimeters * 1);
            titleText.Font      = new Font("Arial", 14, FontStyle.Bold);
            titleText.Text      = styleTitle;
            titleText.HorzAlign = HorzAlign.Center;
            titleText.VertAlign = VertAlign.Center;
            //内容行高
            float rowHeight = Units.Centimeters * 1F;
            //标题行高,如果有合并列,怎行高价高
            float rowHeaderHeight = rowHeight;

            if (dicSpanRows != null && dicSpanRows.Count > 0)
            {
                rowHeaderHeight = Units.Centimeters * 1.5f;
            }
            page.PageHeader        = new PageHeaderBand();
            page.PageHeader.Height = rowHeaderHeight;
            page.PageHeader.CreateUniqueName();
            #region 生成报表内容
            // create data band
            DataBand dataBand = new DataBand();
            page.Bands.Add(dataBand);
            dataBand.CreateUniqueName();
            dataBand.DataSource = report.GetDataSource(styleObject);
            dataBand.Height     = rowHeight;
            float x = 0F;//x坐标

            foreach (DataRow dr in dtReportSet.Rows)
            {
                //判断是否要打印
                if (CommonCtrl.IsNullToString(dr["is_print"]) != "1")
                {
                    continue;
                }
                //列宽
                float columnWidth = Units.Centimeters * 2;
                //标题
                string headerName = string.Empty;
                //获取设置的列宽和标题
                float.TryParse(dr["set_width"].ToString(), out columnWidth);
                //columnWidth = columnWidth * 0.9f;
                headerName = dr["set_name"].ToString();
                //生成标题
                TextObject txtHeader = new TextObject();
                txtHeader.Parent = page.PageHeader;
                txtHeader.CreateUniqueName();
                txtHeader.Text      = headerName;
                txtHeader.HorzAlign = HorzAlign.Center;
                txtHeader.VertAlign = VertAlign.Center;
                //生成标题竖线
                LineObject lineHeaderVer = new LineObject();
                lineHeaderVer.Parent = page.PageHeader;
                //生成标题横线
                LineObject lineHeaderHor = new LineObject();
                lineHeaderHor.Parent = page.PageHeader;
                lineHeaderHor.Bounds = new RectangleF(x, 0, columnWidth, 1f);

                //数据源列名称
                string dataName = dr["set_data_name"].ToString();
                string spanName = IsContainDataColumn(dataName);
                //判断列是否是合并列
                if (spanName.Length > 0)
                {
                    #region 合并列标题
                    txtHeader.Bounds     = new RectangleF(x, rowHeaderHeight / 2, columnWidth, rowHeaderHeight / 2);
                    lineHeaderVer.Bounds = new RectangleF(x, rowHeaderHeight / 2, 1F, rowHeaderHeight / 2);
                    //生成合并列的短竖线
                    LineObject lineHeaderHorSpan = new LineObject();
                    lineHeaderHorSpan.Parent = page.PageHeader;
                    lineHeaderHorSpan.Bounds = new RectangleF(x, rowHeaderHeight / 2, columnWidth, 1F);
                    //判断是否包含合并列头
                    if (dicSpanWidth.ContainsKey(spanName))
                    {
                        //增加合并列头的列宽
                        RectangleF rf = dicSpanWidth[spanName];
                        rf.Width += columnWidth;
                        dicSpanWidth[spanName] = rf;
                    }
                    else
                    {
                        //记录合并列头
                        RectangleF rf = new RectangleF();
                        rf.X      = x;
                        rf.Y      = 0;
                        rf.Width  = columnWidth;
                        rf.Height = rowHeaderHeight / 2;
                        dicSpanWidth.Add(spanName, rf);
                    }
                    #endregion
                }
                else
                {
                    lineHeaderVer.Bounds = new RectangleF(x, 0, 1F, rowHeaderHeight);
                    txtHeader.Bounds     = new RectangleF(x, 0, columnWidth, rowHeaderHeight);
                }
                // create two text objects with employee's name and birth date
                //生成内容
                TextObject empNameText = new TextObject();
                empNameText.Parent = dataBand;
                empNameText.CreateUniqueName();
                empNameText.Bounds = new RectangleF(x, 0, columnWidth, rowHeight);
                DataColumn dc = dt.Columns[dataName];
                empNameText.Text = string.Format("[{0}.{1}]", styleObject, dataName);
                //empNameText.HideZeros = true;
                if (dc != null && dc.DataType != typeof(string))
                {
                    empNameText.HorzAlign = HorzAlign.Right;
                }
                else
                {
                    empNameText.HorzAlign = HorzAlign.Center;
                }
                empNameText.VertAlign = VertAlign.Center;
                //生成内容列的竖线
                LineObject lineVertical = new LineObject();
                lineVertical.Parent = dataBand;
                lineVertical.Bounds = new RectangleF(x, 0, 1F, rowHeight);
                //生成内容列顶部的横线
                LineObject lineHorizontal = new LineObject();
                lineHorizontal.Parent = dataBand;
                lineHorizontal.Bounds = new RectangleF(x, 0, columnWidth, 1f);
                //生成内荣列底部的横线
                LineObject lineHorizontalD = new LineObject();
                lineHorizontalD.Parent = dataBand;
                lineHorizontalD.Bounds = new RectangleF(x, rowHeight, columnWidth, 1f);

                //x坐标增加当前列
                x += columnWidth;
            }

            //生成标题右边的竖线
            LineObject lineHeaderRightVer = new LineObject();
            lineHeaderRightVer.Parent = page.PageHeader;
            lineHeaderRightVer.Bounds = new RectangleF(x, 0, 1f, rowHeight);
            //生成内容右边的竖线
            LineObject lineRightVer = new LineObject();
            lineRightVer.Parent = dataBand;
            lineRightVer.Bounds = new RectangleF(x, 0, 1f, rowHeight);
            //生成合并列头
            foreach (string span in dicSpanWidth.Keys)
            {
                //合并列头
                TextObject txtSpan = new TextObject();
                txtSpan.Parent = page.PageHeader;
                txtSpan.CreateUniqueName();
                txtSpan.Bounds    = dicSpanWidth[span];
                txtSpan.Text      = span;
                txtSpan.HorzAlign = HorzAlign.Center;
                txtSpan.VertAlign = VertAlign.Center;
                //合并列头的竖线
                LineObject lineHeaderVer = new LineObject();
                lineHeaderVer.Parent = page.PageHeader;
                lineHeaderVer.Bounds = new RectangleF(txtSpan.Bounds.X, txtSpan.Bounds.Y, 1f, txtSpan.Bounds.Height);
            }
            #endregion
            return(report);
        }
Beispiel #5
0
        private void Done()
        {
            if (DialogResult == DialogResult.OK)
            {
                float defaultHeight = Units.Millimeters * 10;
                if (ReportWorkspace.Grid.GridUnits == PageUnits.Inches ||
                    ReportWorkspace.Grid.GridUnits == PageUnits.HundrethsOfInch)
                {
                    defaultHeight = Units.Inches * 0.4f;
                }

                GroupHeaderBand initialGroup = null;
                DataBand        data         = null;
                int             childIndex   = -1;
                foreach (BandBase band in FPage.Bands)
                {
                    if (band is GroupHeaderBand)
                    {
                        childIndex   = band.ZOrder;
                        initialGroup = band as GroupHeaderBand;
                        data         = (band as GroupHeaderBand).GroupDataBand;
                        break;
                    }
                    else if (band is DataBand)
                    {
                        childIndex = band.ZOrder;
                        data       = band as DataBand;
                        break;
                    }
                }

                // report has no groups nor databands, create a databand
                if (childIndex == -1)
                {
                    data        = new DataBand();
                    data.Height = defaultHeight;
                    childIndex  = 0;
                }

                // connect groups to each other
                data.Parent = null;
                Base parent = null;
                for (int i = 0; i < lbGroups.Items.Count; i++)
                {
                    GroupHeaderBand group = lbGroups.Items[i] as GroupHeaderBand;
                    group.Parent = parent;
                    group.Data   = i < lbGroups.Items.Count - 1 ? null : data;
                    parent       = group;
                }

                // insert a group to the report page
                if (lbGroups.Items.Count > 0)
                {
                    GroupHeaderBand firstGroup = lbGroups.Items[0] as GroupHeaderBand;
                    FPage.Bands.Insert(childIndex, firstGroup);

                    // create unique names
                    if (String.IsNullOrEmpty(firstGroup.GroupDataBand.Name))
                    {
                        firstGroup.GroupDataBand.CreateUniqueName();
                    }
                    for (int i = 0; i < lbGroups.Items.Count; i++)
                    {
                        GroupHeaderBand group = lbGroups.Items[i] as GroupHeaderBand;
                        if (String.IsNullOrEmpty(group.Name))
                        {
                            group.Height = defaultHeight;
                            group.CreateUniqueName();

                            // create text object with group name
                            TextObject text = new TextObject();
                            text.Parent = group;
                            text.CreateUniqueName();
                            text.Bounds = new RectangleF(new PointF(0, 0), text.GetPreferredSize());
                            text.Text   = "[" + group.Condition + "]";

                            // create group footer
                            group.GroupFooter        = new GroupFooterBand();
                            group.GroupFooter.Height = defaultHeight;
                            group.GroupFooter.CreateUniqueName();
                        }
                    }
                }
                else
                {
                    if (!String.IsNullOrEmpty(data.Name))
                    {
                        FPage.Bands.Insert(childIndex, data);
                    }
                }

                // delete initial group if it was deleted in the expert
                if (initialGroup != null && !lbGroups.Items.Contains(initialGroup))
                {
                    initialGroup.Dispose();
                }
            }
        }
Beispiel #6
0
        private void FastReportForm_Load(object sender, EventArgs e)
        {
            var dataSet = new DataSet(DataTable.TableName);

            dataSet.Tables.Add(DataTable);
            _report = new Report();

            // register all data tables and relations
            _report.RegisterData(dataSet);

            // enable the "result" table to use it in the report
            _report.GetDataSource(DataTable.TableName).Enabled = true;

            // add report page
            ReportPage page = new ReportPage();

            _report.Pages.Add(page);
            // always give names to objects you create. You can use CreateUniqueName method to do this;
            // call it after the object is added to a report.
            page.CreateUniqueName();

            // create title band
            page.ReportTitle = new ReportTitleBand {
                Height = Units.Centimeters * 1
            };

            page.ReportTitle.CreateUniqueName();

            // create title text
            TextObject titleText = new TextObject
            {
                Bounds    = new System.Drawing.RectangleF(Units.Centimeters * 5, 0, Units.Centimeters * 10, Units.Centimeters * 1),
                Font      = new System.Drawing.Font("Arial", 14, System.Drawing.FontStyle.Bold),
                Text      = "Report result",
                HorzAlign = HorzAlign.Center,
                Parent    = page.ReportTitle
            };

            titleText.CreateUniqueName();

            // create data band
            DataBand dataBand = new DataBand();

            page.Bands.Add(dataBand);
            dataBand.CreateUniqueName();
            dataBand.DataSource = _report.GetDataSource(DataTable.TableName);
            dataBand.Height     = Units.Centimeters * 0.5f;
            var width = page.PaperWidth / DataTable.Columns.Count;

            foreach (DataColumn column in DataTable.Columns)
            {
                // create two text objects with employee's name and birth date
                TextObject empNameText = new TextObject
                {
                    Bounds = new System.Drawing.RectangleF(0, 0, width * Units.Millimeters, Units.Centimeters * 0.5f),
                    Text   = "[" + DataTable.TableName + "." + column.ColumnName + "]",
                    Parent = dataBand,
                    Dock   = DockStyle.Left,
                };
                empNameText.CreateUniqueName();
            }
        }
Beispiel #7
0
        /// <summary>
        /// 生成默认报表
        /// </summary>
        /// <returns></returns>
        public FastReport.Report DefaultReport()
        {

            FastReport.Report report = new FastReport.Report();
            //判断有报表数据,则注册数据
            if (dt != null && dt.Rows.Count > 0)
            {
                report.RegisterData(dt, styleObject);
            }
            else
            {
                return null;
            }
            //查询报表设置
            DataTable dtReportSet = DBHelper.GetTable("", "tb_report_set", "*", string.Format("set_object='{0}' and set_user='******'", styleObject, GlobalStaticObj.UserID), "", "order by set_num");
            if (dtReportSet == null || dtReportSet.Rows.Count == 0)
            {
                return null;
            }
            // enable the "Employees" table to use it in the report
            report.GetDataSource(styleObject).Enabled = true;

            // add report page
            ReportPage page = new ReportPage();
            if (paperSize != null)
            {
                page.PaperWidth = paperSize.Width;
                page.PaperHeight = paperSize.Height;
            }
            report.Pages.Add(page);
            // always give names to objects you create. You can use CreateUniqueName method to do this;
            // call it after the object is added to a report.
            page.CreateUniqueName();

            // create title band
            page.ReportTitle = new ReportTitleBand();
            // native FastReport unit is screen pixel, use conversion 
            page.ReportTitle.Height = Units.Centimeters * 1;
            page.ReportTitle.CreateUniqueName();

            // create title text
            TextObject titleText = new TextObject();
            titleText.Parent = page.ReportTitle;
            titleText.CreateUniqueName();
            //titleText.Bounds = new RectangleF(Units.Centimeters * 5, 0, Units.Centimeters * 10, Units.Centimeters * 1);
            titleText.Bounds = new RectangleF(0, 0, Units.Millimeters * page.PaperWidth, Units.Centimeters * 1);
            titleText.Font = new Font("Arial", 14, FontStyle.Bold);
            titleText.Text = styleTitle;
            titleText.HorzAlign = HorzAlign.Center;
            titleText.VertAlign = VertAlign.Center;
            //内容行高
            float rowHeight = Units.Centimeters * 1F;
            //标题行高,如果有合并列,怎行高价高
            float rowHeaderHeight = rowHeight;
            if (dicSpanRows != null && dicSpanRows.Count > 0)
            {
                rowHeaderHeight = Units.Centimeters * 1.5f;
            }
            page.PageHeader = new PageHeaderBand();
            page.PageHeader.Height = rowHeaderHeight;
            page.PageHeader.CreateUniqueName();
            #region 生成报表内容
            // create data band
            DataBand dataBand = new DataBand();
            page.Bands.Add(dataBand);
            dataBand.CreateUniqueName();
            dataBand.DataSource = report.GetDataSource(styleObject);
            dataBand.Height = rowHeight;
            float x = 0F;//x坐标

            foreach (DataRow dr in dtReportSet.Rows)
            {
                //判断是否要打印
                if (CommonCtrl.IsNullToString(dr["is_print"]) != "1")
                {
                    continue;
                }
                //列宽
                float columnWidth = Units.Centimeters * 2;
                //标题
                string headerName = string.Empty;
                //获取设置的列宽和标题
                float.TryParse(dr["set_width"].ToString(), out columnWidth);
                //columnWidth = columnWidth * 0.9f;
                headerName = dr["set_name"].ToString();
                //生成标题
                TextObject txtHeader = new TextObject();
                txtHeader.Parent = page.PageHeader;
                txtHeader.CreateUniqueName();
                txtHeader.Text = headerName;
                txtHeader.HorzAlign = HorzAlign.Center;
                txtHeader.VertAlign = VertAlign.Center;
                //生成标题竖线
                LineObject lineHeaderVer = new LineObject();
                lineHeaderVer.Parent = page.PageHeader;
                //生成标题横线
                LineObject lineHeaderHor = new LineObject();
                lineHeaderHor.Parent = page.PageHeader;
                lineHeaderHor.Bounds = new RectangleF(x, 0, columnWidth, 1f);

                //数据源列名称
                string dataName = dr["set_data_name"].ToString();
                string spanName = IsContainDataColumn(dataName);
                //判断列是否是合并列
                if (spanName.Length > 0)
                {
                    #region 合并列标题
                    txtHeader.Bounds = new RectangleF(x, rowHeaderHeight / 2, columnWidth, rowHeaderHeight / 2);
                    lineHeaderVer.Bounds = new RectangleF(x, rowHeaderHeight / 2, 1F, rowHeaderHeight / 2);
                    //生成合并列的短竖线
                    LineObject lineHeaderHorSpan = new LineObject();
                    lineHeaderHorSpan.Parent = page.PageHeader;
                    lineHeaderHorSpan.Bounds = new RectangleF(x, rowHeaderHeight / 2, columnWidth, 1F);
                    //判断是否包含合并列头
                    if (dicSpanWidth.ContainsKey(spanName))
                    {
                        //增加合并列头的列宽
                        RectangleF rf = dicSpanWidth[spanName];
                        rf.Width += columnWidth;
                        dicSpanWidth[spanName] = rf;
                    }
                    else
                    {
                        //记录合并列头
                        RectangleF rf = new RectangleF();
                        rf.X = x;
                        rf.Y = 0;
                        rf.Width = columnWidth;
                        rf.Height = rowHeaderHeight / 2;
                        dicSpanWidth.Add(spanName, rf);
                    }
                    #endregion
                }
                else
                {
                    lineHeaderVer.Bounds = new RectangleF(x, 0, 1F, rowHeaderHeight);
                    txtHeader.Bounds = new RectangleF(x, 0, columnWidth, rowHeaderHeight);
                }
                // create two text objects with employee's name and birth date
                //生成内容
                TextObject empNameText = new TextObject();
                empNameText.Parent = dataBand;
                empNameText.CreateUniqueName();
                empNameText.Bounds = new RectangleF(x, 0, columnWidth, rowHeight);
                DataColumn dc = dt.Columns[dataName];
                empNameText.Text = string.Format("[{0}.{1}]", styleObject, dataName);
                //empNameText.HideZeros = true;
                if (dc != null && dc.DataType != typeof(string))
                {
                    empNameText.HorzAlign = HorzAlign.Right;
                }
                else
                {
                    empNameText.HorzAlign = HorzAlign.Center;
                }
                empNameText.VertAlign = VertAlign.Center;
                //生成内容列的竖线
                LineObject lineVertical = new LineObject();
                lineVertical.Parent = dataBand;
                lineVertical.Bounds = new RectangleF(x, 0, 1F, rowHeight);
                //生成内容列顶部的横线
                LineObject lineHorizontal = new LineObject();
                lineHorizontal.Parent = dataBand;
                lineHorizontal.Bounds = new RectangleF(x, 0, columnWidth, 1f);
                //生成内荣列底部的横线
                LineObject lineHorizontalD = new LineObject();
                lineHorizontalD.Parent = dataBand;
                lineHorizontalD.Bounds = new RectangleF(x, rowHeight, columnWidth, 1f);

                //x坐标增加当前列
                x += columnWidth;
            }

            //生成标题右边的竖线
            LineObject lineHeaderRightVer = new LineObject();
            lineHeaderRightVer.Parent = page.PageHeader;
            lineHeaderRightVer.Bounds = new RectangleF(x, 0, 1f, rowHeight);
            //生成内容右边的竖线
            LineObject lineRightVer = new LineObject();
            lineRightVer.Parent = dataBand;
            lineRightVer.Bounds = new RectangleF(x, 0, 1f, rowHeight);
            //生成合并列头
            foreach (string span in dicSpanWidth.Keys)
            {
                //合并列头
                TextObject txtSpan = new TextObject();
                txtSpan.Parent = page.PageHeader;
                txtSpan.CreateUniqueName();
                txtSpan.Bounds = dicSpanWidth[span];
                txtSpan.Text = span;
                txtSpan.HorzAlign = HorzAlign.Center;
                txtSpan.VertAlign = VertAlign.Center;
                //合并列头的竖线
                LineObject lineHeaderVer = new LineObject();
                lineHeaderVer.Parent = page.PageHeader;
                lineHeaderVer.Bounds = new RectangleF(txtSpan.Bounds.X, txtSpan.Bounds.Y, 1f, txtSpan.Bounds.Height);
            }
            #endregion
            #region 生成页脚
            page.PageFooter = new PageFooterBand();
            page.PageFooter.Height = rowHeaderHeight;
            page.PageHeader.CreateUniqueName();
            TextObject txtPageN = new TextObject();
            txtPageN.Parent = page.PageFooter;
            txtPageN.CreateUniqueName();
            txtPageN.Text = "[PageNofM]";
            txtPageN.Bounds = new RectangleF(100, 0, 200, rowHeaderHeight);

            //TextObject txtTotalPages = new TextObject();
            //txtTotalPages.Parent = page.PageFooter;
            //txtTotalPages.CreateUniqueName();
            //txtTotalPages.Text = "[TotalPages]";
            //txtTotalPages.Bounds = new RectangleF(350, 0, 200, rowHeaderHeight);
            #endregion
            return report;

        }
Beispiel #8
0
        static Report GetMasterDetailReport()
        {
            Report report = new Report();

            // load nwind database
            DataSet dataSet = new DataSet();

            dataSet.ReadXml(inFolder + "\\nwind.xml");

            // register all data tables and relations
            report.RegisterData(dataSet);

            // enable the "Categories" and "Products" tables to use it in the report
            report.GetDataSource("Categories").Enabled = true;
            report.GetDataSource("Products").Enabled   = true;
            // enable relation between two tables
            report.Dictionary.UpdateRelations();

            // add report page
            ReportPage page = new ReportPage();

            report.Pages.Add(page);
            // always give names to objects you create. You can use CreateUniqueName method to do this;
            // call it after the object is added to a report.
            page.CreateUniqueName();

            // create master data band
            DataBand masterDataBand = new DataBand();

            page.Bands.Add(masterDataBand);
            masterDataBand.CreateUniqueName();
            masterDataBand.DataSource = report.GetDataSource("Categories");
            masterDataBand.Height     = Units.Centimeters * 0.5f;

            // create category name text
            TextObject categoryText = new TextObject();

            categoryText.Parent = masterDataBand;
            categoryText.CreateUniqueName();
            categoryText.Bounds = new RectangleF(0, 0, Units.Centimeters * 5, Units.Centimeters * 0.5f);
            categoryText.Font   = new Font("Arial", 10, FontStyle.Bold);
            categoryText.Text   = "[Categories.CategoryName]";

            // create detail data band
            DataBand detailDataBand = new DataBand();

            masterDataBand.Bands.Add(detailDataBand);
            detailDataBand.CreateUniqueName();
            detailDataBand.DataSource = report.GetDataSource("Products");
            detailDataBand.Height     = Units.Centimeters * 0.5f;
            // set sort by product name
            detailDataBand.Sort.Add(new Sort("[Products.ProductName]"));

            // create product name text
            TextObject productText = new TextObject();

            productText.Parent = detailDataBand;
            productText.CreateUniqueName();
            productText.Bounds = new RectangleF(Units.Centimeters * 1, 0, Units.Centimeters * 10, Units.Centimeters * 0.5f);
            productText.Text   = "[Products.ProductName]";

            return(report);
        }
Beispiel #9
0
        static Report GetSubreportReport()
        {
            Report report = new Report();

            // load nwind database
            DataSet dataSet = new DataSet();

            dataSet.ReadXml(inFolder + "\\nwind.xml");

            // register all data tables and relations
            report.RegisterData(dataSet);

            // enable the "Products" and "Suppliers" tables to use it in the report
            report.GetDataSource("Products").Enabled  = true;
            report.GetDataSource("Suppliers").Enabled = true;

            // add report page
            ReportPage page = new ReportPage();

            report.Pages.Add(page);
            // always give names to objects you create. You can use CreateUniqueName method to do this;
            // call it after the object is added to a report.
            page.CreateUniqueName();

            // create title band
            page.ReportTitle = new ReportTitleBand();
            // native FastReport unit is screen pixel, use conversion
            page.ReportTitle.Height = Units.Centimeters * 1;
            page.ReportTitle.CreateUniqueName();

            // create two title text objects
            TextObject titleText1 = new TextObject();

            titleText1.Parent = page.ReportTitle;
            titleText1.CreateUniqueName();
            titleText1.Bounds    = new RectangleF(0, 0, Units.Centimeters * 8, Units.Centimeters * 1);
            titleText1.Font      = new Font("Arial", 14, FontStyle.Bold);
            titleText1.Text      = "Products";
            titleText1.HorzAlign = HorzAlign.Center;

            TextObject titleText2 = new TextObject();

            titleText2.Parent = page.ReportTitle;
            titleText2.CreateUniqueName();
            titleText2.Bounds    = new RectangleF(Units.Centimeters * 9, 0, Units.Centimeters * 8, Units.Centimeters * 1);
            titleText2.Font      = new Font("Arial", 14, FontStyle.Bold);
            titleText2.Text      = "Suppliers";
            titleText2.HorzAlign = HorzAlign.Center;

            // create report title's child band that will contain subreports
            ChildBand childBand = new ChildBand();

            page.ReportTitle.Child = childBand;
            childBand.CreateUniqueName();
            childBand.Height = Units.Centimeters * 0.5f;

            // create the first subreport
            SubreportObject subreport1 = new SubreportObject();

            subreport1.Parent = childBand;
            subreport1.CreateUniqueName();
            subreport1.Bounds = new RectangleF(0, 0, Units.Centimeters * 8, Units.Centimeters * 0.5f);

            // create subreport's page
            ReportPage subreportPage1 = new ReportPage();

            report.Pages.Add(subreportPage1);
            // connect subreport to page
            subreport1.ReportPage = subreportPage1;

            // create report on the subreport's page
            DataBand dataBand = new DataBand();

            subreportPage1.Bands.Add(dataBand);
            dataBand.CreateUniqueName();
            dataBand.DataSource = report.GetDataSource("Products");
            dataBand.Height     = Units.Centimeters * 0.5f;

            TextObject productText = new TextObject();

            productText.Parent = dataBand;
            productText.CreateUniqueName();
            productText.Bounds = new RectangleF(0, 0, Units.Centimeters * 8, Units.Centimeters * 0.5f);
            productText.Text   = "[Products.ProductName]";


            // create the second subreport
            SubreportObject subreport2 = new SubreportObject();

            subreport2.Parent = childBand;
            subreport2.CreateUniqueName();
            subreport2.Bounds = new RectangleF(Units.Centimeters * 9, 0, Units.Centimeters * 8, Units.Centimeters * 0.5f);

            // create subreport's page
            ReportPage subreportPage2 = new ReportPage();

            report.Pages.Add(subreportPage2);
            // connect subreport to page
            subreport2.ReportPage = subreportPage2;

            // create report on the subreport's page
            DataBand dataBand2 = new DataBand();

            subreportPage2.Bands.Add(dataBand2);
            dataBand2.CreateUniqueName();
            dataBand2.DataSource = report.GetDataSource("Suppliers");
            dataBand2.Height     = Units.Centimeters * 0.5f;

            // create supplier name text
            TextObject supplierText = new TextObject();

            supplierText.Parent = dataBand2;
            supplierText.CreateUniqueName();
            supplierText.Bounds = new RectangleF(0, 0, Units.Centimeters * 8, Units.Centimeters * 0.5f);
            supplierText.Text   = "[Suppliers.CompanyName]";

            return(report);
        }
Beispiel #10
0
        static Report GetSimpleListReport()
        {
            Report report = new Report();

            // load nwind database
            DataSet dataSet = new DataSet();

            dataSet.ReadXml(inFolder + "\\nwind.xml");

            // register all data tables and relations
            report.RegisterData(dataSet);

            // enable the "Employees" table to use it in the report
            report.GetDataSource("Employees").Enabled = true;

            // add report page
            ReportPage page = new ReportPage();

            report.Pages.Add(page);
            // always give names to objects you create. You can use CreateUniqueName method to do this;
            // call it after the object is added to a report.
            page.CreateUniqueName();

            // create title band
            page.ReportTitle = new ReportTitleBand();
            // native FastReport unit is screen pixel, use conversion
            page.ReportTitle.Height = Units.Centimeters * 1;
            page.ReportTitle.CreateUniqueName();

            // create title text
            TextObject titleText = new TextObject();

            titleText.Parent = page.ReportTitle;
            titleText.CreateUniqueName();
            titleText.Bounds    = new RectangleF(Units.Centimeters * 5, 0, Units.Centimeters * 10, Units.Centimeters * 1);
            titleText.Font      = new Font("Arial", 14, FontStyle.Bold);
            titleText.Text      = "Employees";
            titleText.HorzAlign = HorzAlign.Center;

            // create data band
            DataBand dataBand = new DataBand();

            page.Bands.Add(dataBand);
            dataBand.CreateUniqueName();
            dataBand.DataSource = report.GetDataSource("Employees");
            dataBand.Height     = Units.Centimeters * 0.5f;

            // create two text objects with employee's name and birth date
            TextObject empNameText = new TextObject();

            empNameText.Parent = dataBand;
            empNameText.CreateUniqueName();
            empNameText.Bounds = new RectangleF(0, 0, Units.Centimeters * 5, Units.Centimeters * 0.5f);
            empNameText.Text   = "[Employees.FirstName] [Employees.LastName]";

            TextObject empBirthDateText = new TextObject();

            empBirthDateText.Parent = dataBand;
            empBirthDateText.CreateUniqueName();
            empBirthDateText.Bounds = new RectangleF(Units.Centimeters * 5.5f, 0, Units.Centimeters * 3, Units.Centimeters * 0.5f);
            empBirthDateText.Text   = "[Employees.BirthDate]";
            // format value as date
            DateFormat format = new DateFormat();

            format.Format           = "MM/dd/yyyy";
            empBirthDateText.Format = format;

            return(report);
        }
Beispiel #11
0
        static Report GetNestedGroupsReport()
        {
            Report report = new Report();

            // load nwind database
            DataSet dataSet = new DataSet();

            dataSet.ReadXml(inFolder + "\\nwind.xml");

            // register all data tables and relations
            report.RegisterData(dataSet);

            // enable the "Products" table to use it in the report
            report.GetDataSource("Products").Enabled = true;

            // add report page
            ReportPage page = new ReportPage();

            report.Pages.Add(page);
            // always give names to objects you create. You can use CreateUniqueName method to do this;
            // call it after the object is added to a report.
            page.CreateUniqueName();

            // create group header
            GroupHeaderBand groupHeaderBand = new GroupHeaderBand();

            page.Bands.Add(groupHeaderBand);
            groupHeaderBand.Height    = Units.Centimeters * 1;
            groupHeaderBand.Condition = "[Products.ProductName].Substring(0,1)";

            // create group text
            TextObject groupText = new TextObject();

            groupText.Parent = groupHeaderBand;
            groupText.CreateUniqueName();
            groupText.Bounds    = new RectangleF(0, 0, Units.Centimeters * 10, Units.Centimeters * 1);
            groupText.Font      = new Font("Arial", 14, FontStyle.Bold);
            groupText.Text      = "[[Products.ProductName].Substring(0,1)]";
            groupText.VertAlign = VertAlign.Center;
            groupText.Fill      = new LinearGradientFill(Color.OldLace, Color.Moccasin, 90, 0.5f, 1);

            // create nested group header
            GroupHeaderBand nestedGroupBand = new GroupHeaderBand();

            groupHeaderBand.NestedGroup = nestedGroupBand;
            nestedGroupBand.Height      = Units.Centimeters * 0.5f;
            nestedGroupBand.Condition   = "[Products.ProductName].Substring(0,2)";

            // create nested group text
            TextObject nestedText = new TextObject();

            nestedText.Parent = nestedGroupBand;
            nestedText.CreateUniqueName();
            nestedText.Bounds = new RectangleF(0, 0, Units.Centimeters * 10, Units.Centimeters * 0.5f);
            nestedText.Font   = new Font("Arial", 10, FontStyle.Bold);
            nestedText.Text   = "[[Products.ProductName].Substring(0,2)]";

            // create data band
            DataBand dataBand = new DataBand();

            // connect it to inner group
            nestedGroupBand.Data = dataBand;
            dataBand.CreateUniqueName();
            dataBand.DataSource = report.GetDataSource("Products");
            dataBand.Height     = Units.Centimeters * 0.5f;
            // set sort by product name
            dataBand.Sort.Add(new Sort("[Products.ProductName]"));

            // create product name text
            TextObject productText = new TextObject();

            productText.Parent = dataBand;
            productText.CreateUniqueName();
            productText.Bounds = new RectangleF(Units.Centimeters * 0.5f, 0, Units.Centimeters * 9.5f, Units.Centimeters * 0.5f);
            productText.Text   = "[Products.ProductName]";

            // create group footer for outer group
            groupHeaderBand.GroupFooter = new GroupFooterBand();
            groupHeaderBand.GroupFooter.CreateUniqueName();
            groupHeaderBand.GroupFooter.Height = Units.Centimeters * 1;

            // create total
            Total groupTotal = new Total();

            groupTotal.Name      = "TotalRows";
            groupTotal.TotalType = TotalType.Count;
            groupTotal.Evaluator = dataBand;
            groupTotal.PrintOn   = groupHeaderBand.GroupFooter;
            report.Dictionary.Totals.Add(groupTotal);

            // show total in the group footer
            TextObject totalText = new TextObject();

            totalText.Parent = groupHeaderBand.GroupFooter;
            totalText.CreateUniqueName();
            totalText.Bounds       = new RectangleF(0, 0, Units.Centimeters * 10, Units.Centimeters * 0.5f);
            totalText.Text         = "Rows: [TotalRows]";
            totalText.HorzAlign    = HorzAlign.Right;
            totalText.Border.Lines = BorderLines.Top;

            return(report);
        }
Beispiel #12
0
        private void btnGroup_Click(object sender, EventArgs e)
        {
            Report report = new Report();

            // load nwind database
            DataSet dataSet = new DataSet();

            dataSet.ReadXml(GetReportsFolder() + "nwind.xml");

            // register all data tables and relations
            report.RegisterData(dataSet);

            // enable the "Products" table to use it in the report
            report.GetDataSource("Products").Enabled = true;

            // add report page
            ReportPage page = new ReportPage();

            report.Pages.Add(page);
            // always give names to objects you create. You can use CreateUniqueName method to do this;
            // call it after the object is added to a report.
            page.CreateUniqueName();

            // create group header
            GroupHeaderBand groupHeaderBand = new GroupHeaderBand();

            page.Bands.Add(groupHeaderBand);
            groupHeaderBand.Height    = Units.Centimeters * 1;
            groupHeaderBand.Condition = "[Products.ProductName].Substring(0,1)";
            groupHeaderBand.SortOrder = FastReport.SortOrder.Ascending;

            // create group text
            TextObject groupText = new TextObject();

            groupText.Parent = groupHeaderBand;
            groupText.CreateUniqueName();
            groupText.Bounds    = new RectangleF(0, 0, Units.Centimeters * 10, Units.Centimeters * 1);
            groupText.Font      = new Font("Arial", 14, FontStyle.Bold);
            groupText.Text      = "[[Products.ProductName].Substring(0,1)]";
            groupText.VertAlign = VertAlign.Center;
            groupText.Fill      = new LinearGradientFill(Color.OldLace, Color.Moccasin, 90, 0.5f, 1);

            // create data band
            DataBand dataBand = new DataBand();

            groupHeaderBand.Data = dataBand;
            dataBand.CreateUniqueName();
            dataBand.DataSource = report.GetDataSource("Products");
            dataBand.Height     = Units.Centimeters * 0.5f;

            // create product name text
            TextObject productText = new TextObject();

            productText.Parent = dataBand;
            productText.CreateUniqueName();
            productText.Bounds = new RectangleF(0, 0, Units.Centimeters * 10, Units.Centimeters * 0.5f);
            productText.Text   = "[Products.ProductName]";

            // create group footer
            groupHeaderBand.GroupFooter = new GroupFooterBand();
            groupHeaderBand.GroupFooter.CreateUniqueName();
            groupHeaderBand.GroupFooter.Height = Units.Centimeters * 1;

            // create total
            Total groupTotal = new Total();

            groupTotal.Name      = "TotalRows";
            groupTotal.TotalType = TotalType.Count;
            groupTotal.Evaluator = dataBand;
            groupTotal.PrintOn   = groupHeaderBand.GroupFooter;
            report.Dictionary.Totals.Add(groupTotal);

            // show total in the group footer
            TextObject totalText = new TextObject();

            totalText.Parent = groupHeaderBand.GroupFooter;
            totalText.CreateUniqueName();
            totalText.Bounds       = new RectangleF(0, 0, Units.Centimeters * 10, Units.Centimeters * 0.5f);
            totalText.Text         = "Rows: [TotalRows]";
            totalText.HorzAlign    = HorzAlign.Right;
            totalText.Border.Lines = BorderLines.Top;

            // run report designer
            report.Design();
        }
        private void HeaderAllReport(ReportPage Page, string FeaturesName)
        {
            // create title text
            TextObject titleText = new TextObject();

            titleText.Parent = Page.ReportTitle;
            titleText.CreateUniqueName();
            titleText.Bounds    = new RectangleF((Units.Centimeters * 5f), 0f, (Units.Centimeters * 10f), (Units.Centimeters * 1f));
            titleText.Font      = FontDialog_Topic.Font;
            titleText.Text      = "بسمه تعالی";
            titleText.HorzAlign = HorzAlign.Center;
            titleText.VertAlign = VertAlign.Center;

            // create title text
            TextObject InputDateText = new TextObject();

            InputDateText.Parent = Page.ReportTitle;
            InputDateText.CreateUniqueName();
            InputDateText.Bounds    = new RectangleF((Units.Centimeters * 0f), 0f, (Units.Centimeters * 2.4f), (Units.Centimeters * 1f));
            InputDateText.Font      = FontDialog_Topic.Font;
            InputDateText.Text      = dateTimeReport.SelectedDateInStringPersian;
            InputDateText.HorzAlign = HorzAlign.Left;
            InputDateText.VertAlign = VertAlign.Center;

            TextObject DateText = new TextObject();

            DateText.Parent = Page.ReportTitle;
            DateText.CreateUniqueName();
            DateText.Bounds    = new RectangleF((Units.Centimeters * 2.4f), 0f, (Units.Centimeters * 2f), (Units.Centimeters * 1f));
            DateText.Font      = FontDialog_Topic.Font;
            DateText.Text      = ": " + "تاریخ";
            DateText.HorzAlign = HorzAlign.Left;
            DateText.VertAlign = VertAlign.Center;

            PictureObject PictureTitle = new PictureObject();

            PictureTitle.Parent = Page.ReportTitle;
            PictureTitle.CreateUniqueName();
            if (System.IO.File.Exists(Properties.Settings.Default.SettingLogoPath + Properties.Settings.Default.SettingLogoExtension))
            {
                PictureTitle.Image = Image.FromFile(Properties.Settings.Default.SettingLogoPath + Properties.Settings.Default.SettingLogoExtension);
            }

            PictureTitle.Bounds = new RectangleF((Units.Centimeters * 15f), 0f, (Units.Centimeters * 10f), (Units.Centimeters * 1f));
            PictureTitle.Width  = (Units.Centimeters * 2.75f);
            PictureTitle.Height = (Units.Centimeters * 2.25f);

            // create two title text objects
            TextObject titleText1 = new TextObject();

            titleText1.Parent = Page.ReportTitle;
            titleText1.CreateUniqueName();
            titleText1.Bounds    = new RectangleF((Units.Centimeters * 5f), (Units.Centimeters * 1f), (Units.Centimeters * 10f), (Units.Centimeters * 1f));
            titleText1.Font      = FontDialog_Topic.Font;
            titleText1.Text      = "وزارت نیرو";
            titleText1.HorzAlign = HorzAlign.Center;

            // create two title text objects
            TextObject InputNumberText1 = new TextObject();

            InputNumberText1.Parent = Page.ReportTitle;
            InputNumberText1.CreateUniqueName();
            InputNumberText1.Bounds    = new RectangleF(0.0f, (Units.Centimeters * 1f), (Units.Centimeters * 2.4f), (Units.Centimeters * 1f));
            InputNumberText1.Font      = FontDialog_Topic.Font;
            InputNumberText1.Text      = string.IsNullOrWhiteSpace(txtNumber.Text) ? "-" : txtNumber.Text;
            InputNumberText1.HorzAlign = HorzAlign.Left;

            // create two title text objects
            TextObject NumberText1 = new TextObject();

            NumberText1.Parent = Page.ReportTitle;
            NumberText1.CreateUniqueName();
            NumberText1.Bounds    = new RectangleF((Units.Centimeters * 2.4f), (Units.Centimeters * 1f), (Units.Centimeters * 2f), (Units.Centimeters * 1f));
            NumberText1.Font      = FontDialog_Topic.Font;
            NumberText1.Text      = ": " + "شماره";
            NumberText1.HorzAlign = HorzAlign.Left;

            TextObject titleText2 = new TextObject();

            titleText2.Parent = Page.ReportTitle;
            titleText2.CreateUniqueName();
            titleText2.Bounds    = new RectangleF((Units.Centimeters * 5f), (Units.Centimeters * 1.5f), (Units.Centimeters * 10f), (Units.Centimeters * 1f));
            titleText2.Font      = FontDialog_Topic.Font;
            titleText2.Text      = "اداره کل محیط زیست استان هرمزگان";
            titleText2.HorzAlign = HorzAlign.Center;

            TextObject titleText3 = new TextObject();

            titleText3.Parent = Page.ReportTitle;
            titleText3.CreateUniqueName();
            titleText3.Bounds    = new RectangleF((Units.Centimeters * 5f), (Units.Centimeters * 2f), (Units.Centimeters * 10f), (Units.Centimeters * 1f));
            titleText3.Font      = FontDialog_Topic.Font;
            titleText3.Text      = FeaturesName + " گزارش اطلاعات توصیفی عوارض لایه ";
            titleText3.HorzAlign = HorzAlign.Center;
        }
        private bool CreateReport()
        {
            bool functionReturnValue = false;

            // ERROR: Not supported in C#: OnErrorStatement


            functionReturnValue = false;

            // create report instance
            FastReport.Report MainReport  = new FastReport.Report();
            FastReport.Report StyleReport = default(FastReport.Report);

            // register the dataset
            MainReport.RegisterData(this.FDataSet);

            MainReport.GetDataSource("TableData").Enabled = true;
            if (StyleRowsEven == null)
            {
                if (System.IO.File.Exists(Application.StartupPath + "\\Report\\Pattern.frx"))
                {
                    StyleReport = new FastReport.Report();
                    StyleReport.Load(Application.StartupPath + "\\Report\\Pattern.frx");
                    StyleRowsEven = StyleReport.Styles[0];
                    if (StyleRowsEven != null)
                    {
                        MainReport.Styles.Add(StyleRowsEven);
                    }
                }
            }

            ReportPage page = new ReportPage();

            page.Width = 33 * Units.Centimeters;

            MainReport.Pages.Add(page);

            page.CreateUniqueName();

            DataBand dataBand = new DataBand();

            page.Bands.Add(dataBand);
            dataBand.CreateUniqueName();
            dataBand.DataSource = MainReport.GetDataSource("TableData");
            dataBand.Height     = (Units.Centimeters * 0.5f);

            if (StyleRowsEven != null)
            {
                MainReport.Styles.Add(StyleRowsEven);
                if (!ChkWithoutColorTextReport.Checked)
                {
                    dataBand.EvenStyle = StyleRowsEven.Name;
                }
                else
                {
                    dataBand.EvenStyle = "";
                }
            }

            page.ReportTitle        = new ReportTitleBand();
            page.ReportTitle.Height = (Units.Centimeters * 4f);
            page.ReportTitle.CreateUniqueName();

            if (ChkWithoutColorHeader.CheckState == CheckState.Checked)
            {
                colorHeader     = Color.Transparent;
                backgroundColor = Color.Transparent;
            }

            HeaderAllReport(page, cboLayers.SelectedItem.ToString());
            double higthHeader = double.Parse(txtWidthHeader.Text);
            double higthBody   = double.Parse(txtWidthBody.Text);
            double WidthReport = 19;
            double widthColumn = (double)19 / columnNames.Count;

            for (int i = 0; i < columnNames.Count; i++)
            {
                WidthReport -= (widthColumn - 0.005);
                if (WidthReport < 0)
                {
                    break;
                }

                TextObject titleText = new TextObject();
                titleText.Parent = page.ReportTitle;
                titleText.CreateUniqueName();
                titleText.Bounds      = new RectangleF(Convert.ToSingle((Units.Centimeters * WidthReport)), (Units.Centimeters * 3f), (Units.Centimeters * (float)widthColumn), (Units.Centimeters * (float)higthHeader));
                titleText.Font        = FontDialog_Topic.Font;
                titleText.Text        = columnNames[i];
                titleText.VertAlign   = VertAlign.Center;
                titleText.HorzAlign   = HorzAlign.Center;
                titleText.Fill        = new LinearGradientFill(backgroundColor, colorHeader, 90, Convert.ToSingle(higthHeader), 1f);
                titleText.RightToLeft = true;


                TextObject ReportText = new TextObject();
                ReportText.Parent = dataBand;
                ReportText.CreateUniqueName();
                ReportText.Bounds      = new RectangleF(Convert.ToSingle((Units.Centimeters * WidthReport)), 0f, (Units.Centimeters * (float)widthColumn), (Units.Centimeters * (float)higthBody));
                ReportText.Text        = "[TableData." + FDataSet.Tables[0].Columns[i].ColumnName + "]";
                ReportText.Font        = FontDialog_TextReport.Font;
                ReportText.HorzAlign   = HorzAlign.Center;
                ReportText.VertAlign   = VertAlign.Center;
                ReportText.RightToLeft = true;

                // ReportText.Border.Lines = BorderLines.All;
                //ReportText.Border.BottomLine.Color = Color.Black;
                //ReportText.Border.BottomLine.Width = 0.5f;
                //ReportText.Border.TopLine .Color = Color.Black;
                //ReportText.Border.TopLine.Width = 0.5f;
            }

            if (WidthReport < 19)
            {
                TextObject RemaintitleText = new TextObject();
                RemaintitleText.Parent = page.ReportTitle;
                RemaintitleText.CreateUniqueName();
                RemaintitleText.Bounds    = new RectangleF(0.0f, (Units.Centimeters * 3f), Convert.ToSingle((Units.Centimeters * WidthReport)), (Units.Centimeters * (float)higthHeader));
                RemaintitleText.Text      = "";
                RemaintitleText.VertAlign = VertAlign.Center;
                RemaintitleText.HorzAlign = HorzAlign.Center;
                RemaintitleText.Fill      = new LinearGradientFill(backgroundColor, colorHeader, 90, Convert.ToSingle(higthHeader), 1f);
            }

            MainReport.Save(Application.StartupPath + "\\Report\\Report_TableResult.frx");
            MainReport.Dispose();

            functionReturnValue = true;
            return(functionReturnValue);

Err:
            return(functionReturnValue);
        }
Beispiel #15
0
        /// <summary>
        /// Prepare report when finished
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="reportBuilder"></param>
        /// <returns></returns>
        public static Report Prepare <T>(this ReportBuilder <T> reportBuilder)
        {
            var report = new Report();
            var name   = typeof(T).Name;

            report.RegisterData(reportBuilder._data, name);
            report.GetDataSource(name).Enabled = true;

            ReportPage page = new ReportPage();

            report.Pages.Add(page);
            page.CreateUniqueName();

            page.ReportTitle        = new ReportTitleBand();
            page.ReportTitle.Height = Units.Centimeters * 1;
            page.ReportTitle.CreateUniqueName();
            page.ReportTitle.Visible = reportBuilder._reportTitle.Visible;

            TextObject titleText = new TextObject();

            titleText.Parent = page.ReportTitle;
            titleText.CreateUniqueName();
            titleText.Bounds    = new RectangleF(Units.Centimeters * 5, 0, Units.Centimeters * 10, Units.Centimeters * 1);
            titleText.Font      = reportBuilder._reportTitle.Font;
            titleText.Text      = reportBuilder._reportTitle.Text;
            titleText.TextColor = reportBuilder._reportTitle.TextColor;
            titleText.FillColor = reportBuilder._reportTitle.FillColor;
            titleText.HorzAlign = HorzAlign.Center;

            DataBand dataBand = new DataBand();

            dataBand.Parent = page;
            dataBand.CreateUniqueName();
            dataBand.DataSource = report.GetDataSource(name);
            dataBand.Height     = Units.Centimeters * 0.5f;

            if (reportBuilder._groupHeader.Visible)
            {
                GroupHeaderBand groupHeader = new GroupHeaderBand();
                groupHeader.CreateUniqueName();
                groupHeader.Height    = Units.Centimeters * 0.5f;
                groupHeader.Condition = string.IsNullOrEmpty(reportBuilder._groupHeader.Expression)
                    ? $"[{name}.{reportBuilder._groupHeader.Name}]"
                    : string.Format(reportBuilder._groupHeader.Expression, $"[{name}.{reportBuilder._groupHeader.Name}]");
                groupHeader.Data      = dataBand;
                groupHeader.SortOrder = reportBuilder._groupHeader.SortOrder;
                groupHeader.Parent    = page;

                if (reportBuilder._groupHeader.TextVisible)
                {
                    TextObject textGroupHeader = new TextObject();
                    textGroupHeader.CreateUniqueName();
                    textGroupHeader.Bounds = new RectangleF(0, 0, Units.Centimeters * 2, Units.Centimeters * 0.5f);
                    textGroupHeader.Text   = $"[{groupHeader.Condition}]";
                    textGroupHeader.Font   = new Font("Tahoma", 10, FontStyle.Bold);
                    textGroupHeader.Parent = groupHeader;
                }
            }

            var dataHeaderBand = new DataHeaderBand();

            if (reportBuilder._dataHeader.Visible)
            {
                dataHeaderBand.Parent = dataBand;
                dataHeaderBand.CreateUniqueName();
                dataHeaderBand.Height = Units.Centimeters * 0.5f;
            }

            float leftCm       = 0.0f;
            float size         = 0.0f;
            float pageWidth    = page.PaperWidth - (page.LeftMargin + page.RightMargin);
            float cellWidth    = pageWidth / 100;
            var   remainColumn = reportBuilder._columns.Count(a => a.Width == 0);
            float remainSize   = 100 - reportBuilder._columns.Sum(a => a.Width);
            float remainWidth  = remainSize / (remainColumn * 10);

            foreach (var item in reportBuilder._columns)
            {
                size = item.Width == 0 ? remainWidth : (float)item.Width / 10;
                if (reportBuilder._dataHeader.Visible)
                {
                    TextObject headerText = new TextObject();
                    headerText.CreateUniqueName();
                    headerText.Bounds       = new RectangleF(leftCm, 0f * Units.Centimeters, cellWidth * Units.Centimeters * size, 0.1f * Units.Centimeters);
                    headerText.VertAlign    = reportBuilder._reportTitle.VertAlign ?? reportBuilder._report.VertAlign;
                    headerText.HorzAlign    = reportBuilder._reportTitle.HorzAlign ?? reportBuilder._report.HorzAlign;
                    headerText.Font         = reportBuilder._dataHeader.Font;
                    headerText.TextColor    = reportBuilder._dataHeader.TextColor;
                    headerText.FillColor    = reportBuilder._dataHeader.FillColor;
                    headerText.Border.Lines = BorderLines.All;
                    headerText.Text         = item.Title;
                    headerText.GrowToBottom = true;
                    headerText.Parent       = dataHeaderBand;
                }

                TextObject text = new TextObject();
                text.Parent = dataBand;
                text.CreateUniqueName();
                text.Bounds = new RectangleF(leftCm, 0, Units.Centimeters * cellWidth * size, Units.Centimeters * 0.5f);
                text.Text   = string.IsNullOrEmpty(item.Expression)
                    ? $"[{name}.{item.Name}]"
                    : string.Format($"[{item.Expression}]", $"[{name}.{item.Name}]");
                text.Border.Lines = BorderLines.All;
                text.TextColor    = Color.Black;
                text.VertAlign    = item.VertAlign ?? reportBuilder._report.VertAlign;
                text.HorzAlign    = item.HorzAlign ?? reportBuilder._report.HorzAlign;

                if (!string.IsNullOrEmpty(item.Format))
                {
                    CustomFormat format = new CustomFormat();
                    format.Format = item.Format;
                    text.Format   = format;
                }

                leftCm += cellWidth * Units.Centimeters * size;
            }

            report.Prepare();

            return(report);
        }
Beispiel #16
0
        private void CreateReport()
        {
            // disable all datasources, enable selected only
            foreach (Base c in Report.Dictionary.AllObjects)
            {
                if (c is DataSourceBase && c != DataSource)
                {
                    (c as DataSourceBase).Enabled = false;
                }
            }

            // create page layout
            // by default, empty report contains the following bands: ReportTitle, PageHeader, Data, PageFooter
            ReportPage page = Report.Pages[0] as ReportPage;

            page.Landscape = rbLandscape.Checked;
            float pageWidth     = (page.PaperWidth - page.LeftMargin - page.RightMargin) * Units.Millimeters;
            float snapSize      = ReportWorkspace.Grid.SnapSize;
            float defaultHeight = page.IsImperialUnitsUsed ? Units.Inches * 0.2f : Units.Millimeters * 5;

            // styles
            if (lbStyles.SelectedIndex != -1)
            {
                StyleCollection style = FStyleSheet[FStyleSheet.IndexOf((string)lbStyles.SelectedItem)];
                FStyleSheet.Remove(style);
                FSampleStyleReport.Styles = new StyleCollection();
                Report.Styles             = style;
            }

            // title
            TextObject title = new TextObject();

            title.Parent = page.ReportTitle;
            title.CreateUniqueName();
            title.Dock      = DockStyle.Fill;
            title.HorzAlign = HorzAlign.Center;
            title.VertAlign = VertAlign.Center;
            title.Text      = DataSource.Alias;
            title.Style     = "Title";

            // data and header
            List <Column> selectedColumns = SelectedColumns;
            DataBand      dataBand        = page.Bands[0] as DataBand;

            dataBand.DataSource = DataSource;

            if (rbTabular.Checked)
            {
                float[] columnWidths = new float[selectedColumns.Count];
                float   columnWidth  = pageWidth / selectedColumns.Count;

                // try fit to grid
                columnWidth = (int)(columnWidth / snapSize) * snapSize;
                for (int i = 0; i < selectedColumns.Count; i++)
                {
                    columnWidths[i] = columnWidth;
                }

                // compensate column widths to fit pagewidth
                float extraWidth = pageWidth - columnWidth * selectedColumns.Count;
                for (int i = 0; i < selectedColumns.Count; i++)
                {
                    if (extraWidth - snapSize < 0)
                    {
                        break;
                    }
                    columnWidths[i] += snapSize;
                    extraWidth      -= snapSize;
                }

                // create data and header
                float offsetX = 0;
                for (int i = 0; i < selectedColumns.Count; i++)
                {
                    TextObject dataColumn = new TextObject();
                    dataColumn.Parent = dataBand;
                    dataColumn.CreateUniqueName();
                    dataColumn.Bounds = new RectangleF(offsetX, 0, columnWidths[i], defaultHeight);
                    dataColumn.Text   = "[" + DataSource.Alias + "." + selectedColumns[i].Alias + "]";
                    dataColumn.Style  = "Data";

                    TextObject headerColumn = new TextObject();
                    headerColumn.Parent = page.PageHeader;
                    headerColumn.CreateUniqueName();
                    headerColumn.Bounds = new RectangleF(offsetX, 0, columnWidths[i], defaultHeight);
                    headerColumn.Text   = selectedColumns[i].Alias;
                    headerColumn.Style  = "Header";

                    offsetX += columnWidths[i];
                }

                dataBand.Height        = defaultHeight;
                dataBand.EvenStyle     = "EvenRows";
                page.PageHeader.Height = defaultHeight + snapSize;
            }
            else
            {
                page.PageHeader = null;

                // calculate max header width
                float headerWidth = 0;
                using (TextObject tempHeader = new TextObject())
                {
                    tempHeader.Parent = dataBand;
                    tempHeader.Style  = "Header";

                    for (int i = 0; i < selectedColumns.Count; i++)
                    {
                        tempHeader.Text = selectedColumns[i].Alias;
                        float width = (int)(tempHeader.CalcWidth() / snapSize + 1) * snapSize;
                        if (width > headerWidth)
                        {
                            headerWidth = width;
                        }
                    }
                }

                // create data and header
                float dataWidth = (int)((pageWidth - headerWidth) / snapSize) * snapSize;
                float offsetY   = 0;
                for (int i = 0; i < selectedColumns.Count; i++)
                {
                    TextObject headerColumn = new TextObject();
                    headerColumn.Parent = dataBand;
                    headerColumn.CreateUniqueName();
                    headerColumn.Bounds = new RectangleF(0, offsetY, headerWidth, defaultHeight);
                    headerColumn.Text   = selectedColumns[i].Alias;
                    headerColumn.Style  = "Header";

                    TextObject dataColumn = new TextObject();
                    dataColumn.Parent = dataBand;
                    dataColumn.CreateUniqueName();
                    dataColumn.Bounds = new RectangleF(headerWidth, offsetY, dataWidth, defaultHeight);
                    dataColumn.Text   = "[" + DataSource.Alias + "." + selectedColumns[i].Alias + "]";
                    dataColumn.Style  = "Data";

                    offsetY += defaultHeight;
                }

                dataBand.Height = offsetY + snapSize;
            }

            // groups
            if (Groups.Count > 0)
            {
                // create group headers
                Base parent = page;
                foreach (Column column in Groups)
                {
                    GroupHeaderBand groupHeader = new GroupHeaderBand();
                    groupHeader.Parent = parent;
                    groupHeader.CreateUniqueName();
                    groupHeader.Height    = defaultHeight;
                    groupHeader.Condition = "[" + DataSource.Alias + "." + column.Alias + "]";

                    groupHeader.GroupFooter = new GroupFooterBand();
                    groupHeader.GroupFooter.CreateUniqueName();
                    groupHeader.GroupFooter.Height = defaultHeight;

                    TextObject groupText = new TextObject();
                    groupText.Parent = groupHeader;
                    groupText.CreateUniqueName();
                    groupText.Dock  = DockStyle.Fill;
                    groupText.Text  = groupHeader.Condition;
                    groupText.Style = "Group";

                    parent = groupHeader;
                }

                // connect last header to the data
                (parent as GroupHeaderBand).Data = dataBand;
            }

            // page footer
            TextObject pageN = new TextObject();

            pageN.Parent = page.PageFooter;
            pageN.CreateUniqueName();
            pageN.Dock             = DockStyle.Fill;
            pageN.HorzAlign        = HorzAlign.Right;
            pageN.Text             = "Page [Page]";
            pageN.Style            = "Footer";
            page.PageFooter.Height = defaultHeight;

            // tell the designer to reflect changes
            Report.Designer.SetModified(null, "ChangeReport");
        }