using System;
using System.Linq;
using BS.Shared;
using BeWo.Report;
using BeWo.Report.ReportObjects;
using BeWo.Data.Entities;
using BeWo.Data.Access;
using System.Collections.Generic;
using BS.Shared.Core;
using BS.Shared.Services;
using BS.Shared.DataContracts;
using BeWo.Service.DCEntityMapper;
using BeWo.Service.ServiceImplementations;

namespace BeWo.DiakonieKKKleve
{
	public partial class FinanzauswertungFls : DevExpress.XtraReports.UI.XtraReport, IBeWoReport<FinanceRO>
    {
		public FinanzauswertungFls()
        {
            InitializeComponent();
        }

		public void SetReportDataSource(FinanceRO pRO)
        {
			if (pRO.ReportStartDate.HasValue && pRO.ReportEndDate.HasValue)
			{
				DateTime start = pRO.ReportStartDate.Value;
				DateTime end = pRO.ReportEndDate.Value;

				if (start.Year == end.Year && start.Month == end.Month && start.Day == 1 &&
				    end.Day == DateTime.DaysInMonth(end.Year, end.Month))
				{
					cellBewilligtImZeitraumHeader.Text = String.Format("bewilligte FLS {0:MMMM}", start);
					cellGeleistetImZeitraumHeader.Text = String.Format("geleistete Std. {0:MMMM}", start);
					
				}
				else
				{
					cellBewilligtImZeitraumHeader.Text = String.Format("bewilligte FLS {0:dd.MM.yyyy}-{1:dd.MM.yyyy}", start, end);
					cellGeleistetImZeitraumHeader.Text = String.Format("geleistete Std. {0:dd.MM.yyyy}-{1:dd.MM.yyyy}", start, end);
					
				}
				if (pRO.RateFactor.HasValue)
				{
					cellRateFactorHeader.Text = String.Format("geleistete Std. x {0:0.##}", pRO.RateFactor);
				}
				else
				{
					cellRateFactorHeader.Visible = false;
					cellRateFactor.Visible = false;
				}
				
			}
			else
			{
				cellBewilligtImZeitraumHeader.Visible = false;
				cellBewilligteFLSImBereich.Visible = false;
				cellGeleistetImBereich.Visible = false;
				cellGeleistetImZeitraumHeader.Visible = false;
				cellRateFactorHeader.Visible = false;
				cellRateFactor.Visible = false;
			}
            this.bindingSource1.DataSource = pRO;
        }

    }

}
