using System;
using BeWo.Report.ReportObjects;
using BeWo.Report;
using DevExpress.XtraReports.UI;
using System.Data;

namespace BeWo.Report.DefaultReports
{
    public partial class Bericht : DevExpress.XtraReports.UI.XtraReport, IBeWoReport<QueryRO>
    {
        public Bericht()
        {
            InitializeComponent();

        }

        public void SetReportDataSource(QueryRO pRO)
        {
            InitTable(pRO);
            this.bindingSource1.DataSource = pRO;
        }

        private void InitTable(QueryRO ro)
        {
            xrTableRowHeader.Cells.Clear();
            xrTableRowDetail.Cells.Clear();
            int index = 1;
            foreach (DataColumn column in ro.DataTable.Columns)
	        {
                Type type = column.DataType;
		        XRTableCell headerCell = new XRTableCell();
                headerCell.Text = column.ColumnName;
                headerCell.WidthF = xrTableHeader.WidthF / ro.DataTable.Columns.Count;
                this.xrTableRowHeader.Cells.Add(headerCell);

                XRTableCell rowCell = new XRTableCell();
                rowCell.WidthF = xrTableHeader.WidthF / ro.DataTable.Columns.Count;

                if (type == typeof(DateTime))
                    rowCell.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] {
                        new DevExpress.XtraReports.UI.XRBinding("Text", null, "Rows.Field" + index, "{0:dd/MM/yyyy}")});
                else
                    rowCell.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] {
                        new DevExpress.XtraReports.UI.XRBinding("Text", null, "Rows.Field" + index)});
                
                this.xrTableRowDetail.Cells.Add(rowCell);

                index++;
	        }

            foreach (XRTableCell cell in xrTableRowHeader.Cells)
            {
                cell.WidthF = xrTableHeader.WidthF / ro.DataTable.Columns.Count;
            }

            foreach (XRTableCell cell in xrTableRowDetail.Cells)
            {
                cell.WidthF = xrTableHeader.WidthF / ro.DataTable.Columns.Count;
            }
            
        }

    }
}
