using System;
using System.Collections.Generic;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.Utils.Drawing.Helpers;
using DevExpress.XtraReports.UI;
using BS.Shared.Extensions;
using BeWo.Report.ReportObjects;
using BeWo.Report;

namespace BeWo.IBPReports
{
    public partial class Hilfeplanuebersicht : DevExpress.XtraReports.UI.XtraReport, IBeWoReport<SupportConceptListRO>
    {
        public Hilfeplanuebersicht()
        {
            InitializeComponent();
        }

        public void SetReportDataSource(SupportConceptListRO pRO)
        {
	        if (pRO.AppointedDate.HasValue)
	        {
		        List<SupportConceptListRO.SupportConceptDetail> deleted =
			        new List<SupportConceptListRO.SupportConceptDetail>();
		        foreach (var scd in pRO.SupportConceptDetailList)
		        {
			        bool inTimeSpan = true;

			        if (scd.StartDate >= pRO.AppointedDate.Value.Date.AddDays(1))
			        {
				        inTimeSpan = false;
			        }
			        if (scd.EndDate < new DateTime(pRO.AppointedDate.Value.Date.Year, pRO.AppointedDate.Value.Date.Month, 1))
			        {
				        inTimeSpan = false;
			        }
			        if (!inTimeSpan)
			        {
				        deleted.Add(scd);
			        }
		        }

		        foreach (var supportConceptDetail in deleted)
		        {
			        pRO.SupportConceptDetailList.Remove(supportConceptDetail);
		        }

		        int index = 1;
				foreach (var scd in pRO.SupportConceptDetailList)
				{
					scd.RowIndex = index++;
				}
	        }
	        this.bindingSource1.DataSource = pRO;
        }
    }
}
