using System;
using System.Linq;

using BeWo.Report;
using BeWo.Report.ReportObjects;

using DevExpress.XtraPrinting;
using DevExpress.XtraReports.UI;

namespace BeWo.Convoi
{
    public partial class Stundenzettel : XtraReport, IBeWoReport<ServicesOverviewRO>
    {
        public Stundenzettel()
        {
            InitializeComponent();
        }

        public void SetReportDataSource(ServicesOverviewRO pRO)
        {
            if (pRO.Services != null)
            {
                var servicesBillable = pRO.Services.Where(s => s.IsBillable).ToList();

	            pRO.Services = servicesBillable;
            }

	        if (!String.IsNullOrEmpty(pRO.AbsenceTimes))
	        {
		        pRO.AbsenceTimes = "Abwesenheit: " + pRO.AbsenceTimes;
	        }
			//if (pRO.SupportConceptCostBearer != null)
			//{
			//	var ats = pRO.SupportConceptCostBearer.SupportConcept.Customer.AbsenceTimes;

			//	for (var i = 0; i < ats.Count; i++)
			//	{

			//		var at = ats[i];
			//		var cellText = string.Format("Abwesenheit: {0}.{1}. - {2}.{3}. {4}",
			//			at.AbsenceSpan.StartDate.Day < 10
			//				? " " + at.AbsenceSpan.StartDate.Day
			//				: at.AbsenceSpan.StartDate.Day.ToString(), at.AbsenceSpan.StartDate.Month,
			//			at.AbsenceSpan.EndDate.Day < 10 ? " " + at.AbsenceSpan.EndDate.Day : at.AbsenceSpan.EndDate.Day.ToString(),
			//			at.AbsenceSpan.EndDate.Month, at.Reason);

			//		if (i == 0)
			//		{
			//			abwesenheitsTabelle.Rows[0].Cells[0].Text = cellText;
			//		}
			//		else
			//		{
			//			var reihe = new XRTableRow();
			//			reihe.Cells.Add(new XRTableCell {Text = cellText, TextAlignment = TextAlignment.MiddleLeft});
			//			abwesenheitsTabelle.Rows.Add(reihe);
			//		}
			//	}
			//}
	        bindingSource1.DataSource = pRO;
        }
    }
}
