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

using System.Collections.Generic;

namespace BeWo.VKMAachen
{
    public partial class StundenzettelSP : DevExpress.XtraReports.UI.XtraReport, IBeWoReport<ServicesOverviewRO>
    {
		public StundenzettelSP()
        {
            InitializeComponent();
        }

        public void SetReportDataSource(ServicesOverviewRO pRO)
        {
			String empName = String.Empty;
			Dictionary<String, bool> empCountDict = new Dictionary<String, bool>();

            if (pRO.Services != null)
            {
                List<ServicesOverviewRO.ServiceDetail> servicesBillable = new List<ServicesOverviewRO.ServiceDetail>();

                foreach (ServicesOverviewRO.ServiceDetail s in pRO.Services)
                {
	                if (s.IsBillable)
	                {
		                servicesBillable.Add(s);

		                if (!String.IsNullOrEmpty(s.EmployeeFullname))
		                {
			                empName = s.EmployeeFullname;
			                if (!empCountDict.ContainsKey(s.EmployeeFullname))
				                empCountDict.Add(s.EmployeeFullname, true);
		                }
	                }
                }

                pRO.Services = servicesBillable;
            }
			if (empCountDict.Count == 1)
				pRO.MainAttendant = empName;

            this.bindingSource1.DataSource = pRO;
        }
    }
}
