private void AddContent(DataTable table)
        {
            XRTable dynamicTable = XRTable.CreateTable(
                new Rectangle(0,
                              0,
                              TableWidth,
                              20),
                1,
                0);

            dynamicTable.Width = TableWidth;
            dynamicTable.Rows.FirstRow.Width = TableWidth;
            dynamicTable.Borders             = DevExpress.XtraPrinting.BorderSide.All;
            dynamicTable.BorderWidth         = 1;
            int i = 0;

            dynamicTable.BeginInit();
            foreach (DataColumn dc in table.Columns)
            {
                XRTableCell cell = new XRTableCell();

                XRBinding binding = new XRBinding("Text", table, table.Columns[i].ColumnName);
                cell.DataBindings.Add(binding);
                cell.CanGrow = false;
                cell.Width   = 100;
                cell.Text    = dc.ColumnName;
                dynamicTable.Rows.FirstRow.Cells.Add(cell);
                i++;
            }
            dynamicTable.Font = new Font("Verdana", 8F);
            dynamicTable.EndInit();
            Detail.HeightF = 20f;
            Detail.Controls.Add(dynamicTable);
        }
        private void AddDataFieldsToBand(DataTable dataTable, DetailBand band, string dataPath, bool addKeyFields)
        {
            XRTable table     = XRTable.CreateTable(new Rectangle(indent, 0, report.PageWidth - report.Margins.Left - report.Margins.Right - indent - 1, 25), 1, dataTable.Columns.Count - (addKeyFields ? 0 : 2));
            int     cellIndex = 0;

            for (int i = 0; i < dataTable.Columns.Count; i++)
            {
                DataColumn dataColumn = dataTable.Columns[i];

                if (addKeyFields || (!addKeyFields && !dataColumn.ColumnName.ToUpper().Contains("ID")))
                {
                    table.Rows[0].Cells[cellIndex++].DataBindings.Add("Text", null, dataPath + "." + dataColumn.ColumnName);
                }
            }

            table.Padding = new DevExpress.XtraPrinting.PaddingInfo(2, 2, 0, 0);
            band.Controls.Add(table);
            indent += 50;
        }
        private void AddHeaders(DataTable table)
        {
            XRTable headers = XRTable.CreateTable(
                new Rectangle(0,
                              0,
                              TableWidth,
                              20),
                1,
                0);

            headers.BeginInit();
            foreach (DataColumn dc in table.Columns)
            {
                XRTableCell cell = new XRTableCell();
                cell.CanGrow   = false;
                cell.Width     = 100;
                cell.Text      = dc.ColumnName;
                cell.BackColor = Color.LightGray;
                headers.Rows.FirstRow.Cells.Add(cell);
            }
            headers.HeightF = 100f;
            headers.EndInit();
            ReportHeader.Controls.Add(headers);
        }
Example #4
0
        public static void CreateReport(XtraReport report, string[] fields)
        {
            PageHeaderBand pageHeader = new PageHeaderBand()
            {
                HeightF = 23, Name = "pageHeaderBand"
            };
            int     tableWidth  = report.PageWidth - report.Margins.Left - report.Margins.Right;
            XRTable headerTable = XRTable.CreateTable(
                new Rectangle(0,                    // rect X
                              0,                    // rect Y
                              tableWidth,           // width
                              40),                  // height
                1,                                  // table row count
                0);                                 // table column count

            headerTable.Borders             = DevExpress.XtraPrinting.BorderSide.All;
            headerTable.BackColor           = Color.Gainsboro;
            headerTable.Font                = new Font("Verdana", 10, FontStyle.Bold);
            headerTable.Rows.FirstRow.Width = tableWidth;
            headerTable.BeginInit();
            foreach (string field in fields)
            {
                XRTableCell cell = new XRTableCell();
                cell.Width         = 100;
                cell.Text          = field;
                cell.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
                headerTable.Rows.FirstRow.Cells.Add(cell);
            }
            headerTable.EndInit();
            headerTable.AdjustSize();
            pageHeader.Controls.Add(headerTable);



            DetailBand detail = new DetailBand()
            {
                HeightF = 23, Name = "detailBand"
            };
            XRTable detailTable = XRTable.CreateTable(
                new Rectangle(0,                // rect X
                              0,                // rect Y
                              tableWidth,       // width
                              40),              // height
                1,                              // table row count
                0);                             // table column count



            detailTable.Width = tableWidth;
            detailTable.Rows.FirstRow.Width = tableWidth;
            detailTable.Borders             = DevExpress.XtraPrinting.BorderSide.Left | DevExpress.XtraPrinting.BorderSide.Right | DevExpress.XtraPrinting.BorderSide.Bottom;
            detailTable.BeginInit();
            foreach (string field in fields)
            {
                XRTableCell       cell    = new XRTableCell();
                ExpressionBinding binding = new ExpressionBinding("BeforePrint", "Text", String.Format("[{0}]", field));
                cell.ExpressionBindings.Add(binding);
                cell.Width         = 100;
                cell.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleLeft;
                if (field.Contains("Date"))
                {
                    cell.TextFormatString = "{0:MM/dd/yyyy}";
                }
                detailTable.Rows.FirstRow.Cells.Add(cell);
            }
            detailTable.Font = new Font("Verdana", 8F);
            detailTable.EndInit();
            detailTable.AdjustSize();
            detail.Controls.Add(detailTable);
            report.Bands.AddRange(new Band[] { detail, pageHeader });
        }
Example #5
0
        //-----------------------------------------------------------------------------------------------------------------------------------------//

        public RepKargoPlani(DataTable p_TableResult)
        {
            // Initialize
            InitializeComponent();

            // DateTime
            txtDateTime.Text = DateTime.Now.ToString(alfaDate.DTFormat);

            // Version
            txtVersion.Text = alfaVer.GetAppVersion();

            // Operator
            txtOperator.Text = alfaSession.FullName;

            // Create rowHeader
            DataRow rowHeader = p_TableResult.NewRow();

            foreach (DataColumn col in p_TableResult.Columns)
            {
                // Assign Text
                rowHeader[col.ColumnName] = col.ColumnName;
            }

            // Add to Table
            p_TableResult.Rows.InsertAt(rowHeader, 0);

            //========================================== Create XRTable ========================================//

            int p_Padding    = 10;
            int p_TableWidth = this.PageWidth - this.Margins.Left - this.Margins.Right - p_Padding * 2;
            int p_ColWidth   = p_TableWidth / p_TableResult.Columns.Count;

            // Create Dynamic XRTable
            XRTable repTable = XRTable.CreateTable(new Rectangle(p_Padding, 2, p_TableWidth, 40), 1, 0);

            repTable.BorderWidth         = 2;
            repTable.Width               = p_TableWidth;
            repTable.Rows.FirstRow.Width = p_TableWidth;
            repTable.Font    = new Font("Tahoma", 10, FontStyle.Bold);
            repTable.Borders = DevExpress.XtraPrinting.BorderSide.All;

            // Begin
            repTable.BeginInit();

            foreach (DataColumn col in p_TableResult.Columns)
            {
                // Create Cell
                XRTableCell cell = new XRTableCell();

                // Binding
                XRBinding binding = new XRBinding("Text", this.DataSource, col.ColumnName);

                // Cell Properties
                cell.TextAlignment = TextAlignment.MiddleCenter;
                cell.DataBindings.Add(binding);
                cell.Text      = col.ColumnName;
                cell.Width     = p_ColWidth;
                cell.Multiline = true;
                cell.CanShrink = false;
                cell.CanGrow   = false;

                // Add Cell
                repTable.Rows.FirstRow.Cells.Add(cell);
            }

            // Add to Detail
            Detail.Controls.Add(repTable);

            repTable.BeforePrint += new System.Drawing.Printing.PrintEventHandler(repTable_BeforePrint);

            // Adjust
            repTable.AdjustSize();

            // Begin
            repTable.EndInit();



            //========================================== Create XRTable ========================================//
        }
    public TestReport(string tableName)
    {
        InitializeComponent();
        //
        // TODO: Add constructor logic here
        //

        this.Bands.Add(new PageHeaderBand());

        DevExpress.DataAccess.Sql.SqlDataSource dataSource = new DevExpress.DataAccess.Sql.SqlDataSource("nwind");
        string queryString = string.Format("SELECT * FROM {0}", tableName);

        DevExpress.DataAccess.Sql.SelectQuery parameterQuery = DevExpress.DataAccess.Sql.SelectQueryFluentBuilder
                                                               .AddTable(tableName)
                                                               .SelectAllColumns()
                                                               .Build(tableName);
        dataSource.Queries.Add(parameterQuery);
        dataSource.RebuildResultSchema();
        dataSource.Fill();
        int rowCount = ((IList)dataSource.Result[tableName]).Count;

        XRLabel label = new XRLabel();

        label.Width = 500;
        label.Font  = new System.Drawing.Font("Verdana", 10F, FontStyle.Bold);
        this.Bands[BandKind.PageHeader].Controls.Add(label);

        if (rowCount > 0)
        {
            int padding    = 10;
            int tableWidth = this.PageWidth - this.Margins.Left - this.Margins.Right - padding * 2;

            XRTable dynamicTable = XRTable.CreateTable(
                new Rectangle(padding,                    // rect X
                              2,                          // rect Y
                              tableWidth,                 // width
                              40),                        // height
                1,                                        // table row count
                0);                                       // table column count

            dynamicTable.Width = tableWidth;
            dynamicTable.Rows.FirstRow.Width = tableWidth;
            dynamicTable.Borders             = DevExpress.XtraPrinting.BorderSide.All;
            dynamicTable.BorderWidth         = 1;

            dynamicTable.BeginInit();
            foreach (DevExpress.DataAccess.Sql.DataApi.IColumn dc in dataSource.Result[tableName].Columns)
            {
                XRTableCell cell = new XRTableCell();

                ExpressionBinding binding = new ExpressionBinding("BeforePrint", "Text", dc.Name);
                cell.ExpressionBindings.Add(binding);
                cell.CanGrow = false;
                cell.Width   = 100;
                cell.Text    = dc.Name;
                dynamicTable.Rows.FirstRow.Cells.Add(cell);
            }
            dynamicTable.Font = new System.Drawing.Font("Verdana", 8F);
            dynamicTable.EndInit();
            Detail.Controls.Add(dynamicTable);

            label.Text = string.Format("Data table: {0}", tableName);

            this.DataSource = dataSource;
            this.DataMember = tableName;
        }
        else
        {
            label.Text = string.Format("There's no data to display or the table doesn't exist.");
        }
    }