コード例 #1
0
        private static string GetPageHeader(ReportBuilder reportBuilder)
        {
            string strHeader = "";

            if (reportBuilder.Page == null || reportBuilder.Page.ReportHeader == null)
            {
                return("");
            }
            ReportSections reportHeader = reportBuilder.Page.ReportHeader;

            strHeader = @"<PageHeader> 
                          <Height>" + reportHeader.Size.Height.ToString() + @"in</Height> 
                          <PrintOnFirstPage>" + reportHeader.PrintOnFirstPage.ToString().ToLower() + @"</PrintOnFirstPage> 
                          <PrintOnLastPage>" + reportHeader.PrintOnLastPage.ToString().ToLower() + @"</PrintOnLastPage> 
                          <ReportItems>";
            ReportTextBoxControl[] headerTxt = reportBuilder.Page.ReportHeader.ReportControlItems.TextBoxControls;
            if (headerTxt != null)
            {
                for (int i = 0; i < headerTxt.Count(); i++)
                {
                    strHeader += GetHeaderTextBox(reportBuilder, headerTxt[i], null);
                }
            }
            strHeader += @" 

                          </ReportItems> 

                          <Style /> 
                        </PageHeader>";
            return(strHeader);
        }
コード例 #2
0
        public void PrintRdlcDataGrid(HttpResponse httpResponse, DataGridHtml dataGridHtml, DomainUtility.ReportExportType reportExportType)
        {
            DataView dataView = dataGridHtml.MakeDataView();
            //Report Viewer, Builder and Engine

            ReportViewer reportViewer = new ReportViewer();

            reportViewer.Reset();

            DataSet DS = new DataSet();

            DS.Tables.Add(dataView.ToTable());

            ReportBuilder reportBuilder = new ReportBuilder();

            reportBuilder.DataSource = DS;
            reportBuilder.Page       = new ReportPage();
            reportBuilder.TableRows  = dataView.Table.Rows.Count;

            string fontFamily = new ConfigurationService(base.UnitOfWork).GetValue(sysBpmsConfiguration.e_NameType.DefaultReportFontFamily.ToString());

            if (!string.IsNullOrWhiteSpace(fontFamily))
            {
                reportBuilder.FontFamily = fontFamily;
            }

            if (!string.IsNullOrWhiteSpace(dataGridHtml.ReportGridHeaderColor))
            {
                reportBuilder.TableHeaderColor = "#" + dataGridHtml.ReportGridHeaderColor.ToStringObj();
            }
            if (!string.IsNullOrWhiteSpace(dataGridHtml.ReportGridFooterColor))
            {
                reportBuilder.TableFooterColor = "#" + dataGridHtml.ReportGridFooterColor.ToStringObj();
            }
            if (!string.IsNullOrWhiteSpace(dataGridHtml.ReportGridEvenColor))
            {
                reportBuilder.TableRowEvenColor = "#" + dataGridHtml.ReportGridEvenColor.ToStringObj();
            }
            if (!string.IsNullOrWhiteSpace(dataGridHtml.ReportGridOddColor))
            {
                reportBuilder.TableRowOddColor = "#" + dataGridHtml.ReportGridOddColor.ToStringObj();
            }

            //report size
            switch (dataGridHtml.ReportPaperSize)
            {
            case "A2":
                reportBuilder.Page.PageSize = new ReportScale()
                {
                    Width = 59.4, Height = 42
                };
                break;

            case "A3":
                reportBuilder.Page.PageSize = new ReportScale()
                {
                    Width = 42, Height = 29.7
                };
                break;

            case "A4":
                reportBuilder.Page.PageSize = new ReportScale()
                {
                    Width = 29.7, Height = 21
                };
                break;

            case "A5":
                reportBuilder.Page.PageSize = new ReportScale()
                {
                    Width = 21, Height = 14.8
                };
                break;

            default:
                reportBuilder.Page.PageSize = new ReportScale()
                {
                    Width = 29.7, Height = 21
                };
                break;
            }

            ReportSections reportFooter      = new ReportSections();
            ReportItems    reportFooterItems = new ReportItems();

            ReportTextBoxControl[] footerTxt = new ReportTextBoxControl[3];
            string footer = string.IsNullOrWhiteSpace(dataGridHtml.ReportFooter) ?
                            $" page {ReportGlobalParameters.CurrentPageNumber} of {ReportGlobalParameters.TotalPages}" : dataGridHtml.ReportFooter;

            footerTxt[0] = new ReportTextBoxControl()
            {
                Name = "txtCopyright", ValueOrExpression = new string[] { footer }
            };
            reportFooterItems.TextBoxControls = footerTxt;
            reportFooter.ReportControlItems   = reportFooterItems;
            reportBuilder.Page.ReportFooter   = reportFooter;

            ReportSections reportHeader = new ReportSections();

            reportHeader.Size        = new ReportScale();
            reportHeader.Size.Height = 0.56849;

            ReportItems reportHeaderItems         = new ReportItems();
            List <ReportTextBoxControl> headerTxt = new List <ReportTextBoxControl>()
            {
            };

            headerTxt.Add(new ReportTextBoxControl()
            {
                Name = "txtReportTitle",
                Size = new ReportScale()
                {
                    Height = 0.6, Width = 5, Left = (reportBuilder.Page.PageSize.Width - 5) / 2, Top = 0.5
                },
                ValueOrExpression = new string[] { dataGridHtml.Label }
            });
            if (dataGridHtml.ReportShowDate)
            {
                headerTxt.Add(new ReportTextBoxControl()
                {
                    Name = "txtReportDateTitle",
                    Size = new ReportScale()
                    {
                        Height = 0.6, Width = 2, Left = 0.5, Top = 1
                    },
                    ValueOrExpression = new string[] { DateTime.Now.ToString("yyyy/MM/dd") }
                });
            }
            reportHeaderItems.TextBoxControls = headerTxt.ToArray();
            reportHeader.ReportControlItems   = reportHeaderItems;
            reportBuilder.Page.ReportHeader   = reportHeader;
            reportViewer.LocalReport.LoadReportDefinition(ReportBuilderEngine.GenerateReport(reportBuilder));


            dataView.Table.Columns.Cast <DataColumn>().ToList().ForEach(c => c.ColumnName = c.ColumnName.Replace(" ", "_"));

            reportViewer.LocalReport.DataSources.Add(
                new ReportDataSource(dataView.Table.TableName, dataView.Table));

            reportViewer.LocalReport.DisplayName = "WastageReport";


            Warning[] warnings;
            string[]  streamids;
            string    mimeType;
            string    encoding;
            string    filenameExtension;

            byte[] bytes   = reportViewer.LocalReport.Render(reportExportType.ToString(), null, out mimeType, out encoding, out filenameExtension, out streamids, out warnings);
            string caption = string.IsNullOrWhiteSpace(dataGridHtml.Label) ? new DynamicFormService(base.UnitOfWork).GetInfo(dataGridHtml.DynamicFormID).Name : dataGridHtml.Label;

            this.Response(httpResponse, bytes, reportExportType, caption, mimeType);
        }