178 lines
4.8 KiB
C#
178 lines
4.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using BS.Shared;
|
|
using BS.Shared.Core;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.Services;
|
|
using BeWo.Data.Access;
|
|
using BeWo.Data.Entities;
|
|
using Castle.Components.DictionaryAdapter;
|
|
using NHibernate.Linq;
|
|
|
|
namespace BeWo.Service.Reporting
|
|
{
|
|
public class JahresBerichtNachAlter : JahresBerichtBase
|
|
{
|
|
private List<Altersstruktur> altersstrukturen;
|
|
private DateTime datum;
|
|
|
|
private Dictionary<Altersstruktur, int> alterM = new Dictionary<Altersstruktur, int>();
|
|
private Dictionary<Altersstruktur, int> alterF = new Dictionary<Altersstruktur, int>();
|
|
private Dictionary<Altersstruktur, int> alterD = new Dictionary<Altersstruktur, int>();
|
|
private Dictionary<Altersstruktur, int> alterUnbekannt = new Dictionary<Altersstruktur, int>();
|
|
|
|
public JahresBerichtNachAlter(String titel, List<Altersstruktur> altersstrukturen, DateTime datum) : base(titel)
|
|
{
|
|
this.altersstrukturen = altersstrukturen;
|
|
this.datum = datum;
|
|
}
|
|
|
|
public override void ProcessCustomer(Customer customer)
|
|
{
|
|
int alter = -1;
|
|
|
|
if (customer.Person.DateOfBirth.HasValue)
|
|
{
|
|
alter = datum.Year - customer.Person.DateOfBirth.Value.Year;
|
|
}
|
|
|
|
Sex? geschlecht = null;
|
|
if (customer.Person.Sex.HasValue)
|
|
{
|
|
geschlecht = customer.Person.Sex;
|
|
}
|
|
|
|
Altersstruktur a = null;
|
|
|
|
foreach (var als in altersstrukturen)
|
|
{
|
|
if (alter >= als.MinAlter && alter <= als.MaxAlter)
|
|
{
|
|
a = als;
|
|
}
|
|
}
|
|
|
|
if (a != null)
|
|
{
|
|
Dictionary<Altersstruktur, int> dict = null;
|
|
|
|
if (geschlecht == null)
|
|
{
|
|
dict = alterUnbekannt;
|
|
}
|
|
else if (geschlecht.Value == Sex.Male)
|
|
{
|
|
dict = alterM;
|
|
}
|
|
else if (geschlecht.Value == Sex.Female)
|
|
{
|
|
dict = alterF;
|
|
}
|
|
else if (geschlecht.Value == Sex.Divers)
|
|
{
|
|
dict = alterD;
|
|
}
|
|
else
|
|
{
|
|
dict = alterUnbekannt;
|
|
}
|
|
if (!dict.ContainsKey(a))
|
|
{
|
|
dict.Add(a, 0);
|
|
}
|
|
|
|
dict[a]++;
|
|
}
|
|
}
|
|
|
|
public override AnnualReportDC CreateAuswertung()
|
|
{
|
|
|
|
var report = new AnnualReportDC();
|
|
report.Name = Titel;
|
|
report.Data = new List<AnnualReportDataDC>();
|
|
var index = 1;
|
|
|
|
foreach (var als in altersstrukturen)
|
|
{
|
|
var d = new AnnualReportDataDC();
|
|
report.Data.Add(d);
|
|
d.Index = index++;
|
|
d.Name = als.Name;
|
|
d.Value = 0;
|
|
|
|
if (alterM.ContainsKey(als))
|
|
{
|
|
d.Value += alterM[als];
|
|
d.Male += alterM[als];
|
|
}
|
|
if (alterF.ContainsKey(als))
|
|
{
|
|
d.Value += alterF[als];
|
|
d.Female += alterF[als];
|
|
}
|
|
if (alterD.ContainsKey(als))
|
|
{
|
|
d.Value += alterD[als];
|
|
d.Divers += alterD[als];
|
|
}
|
|
if (alterUnbekannt.ContainsKey(als))
|
|
{
|
|
d.Value += alterUnbekannt[als];
|
|
d.NoSex += alterUnbekannt[als];
|
|
}
|
|
}
|
|
|
|
return report;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
public class Altersstruktur
|
|
{
|
|
public Altersstruktur(int min, int max)
|
|
{
|
|
MinAlter = min;
|
|
MaxAlter = max;
|
|
}
|
|
|
|
public String Name
|
|
{
|
|
get
|
|
{
|
|
if (MinAlter < 0)
|
|
{
|
|
return String.Format("bis {0} Jahre", MaxAlter);
|
|
}
|
|
if (MaxAlter > 100)
|
|
{
|
|
return String.Format("ab {0} Jahre", MinAlter);
|
|
}
|
|
return String.Format("{0} bis {1} Jahre", MinAlter, MaxAlter);
|
|
}
|
|
}
|
|
|
|
public int MinAlter { get; set; }
|
|
public int MaxAlter { get; set; }
|
|
|
|
public override bool Equals(object obj)
|
|
{
|
|
if (!(obj is Altersstruktur))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
var y = (Altersstruktur)obj;
|
|
|
|
return Name == y.Name;
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
return Name.GetHashCode();
|
|
}
|
|
}
|
|
} |