Files
BeWoPlaner/ReportImp/EndartFabrik/CustomReportCreator.cs

108 lines
5.0 KiB
C#

using BeWo.Data.Access;
using BeWo.Data.Entities;
using BeWo.Report;
using BeWo.Report.ReportObjects;
using BS.Shared.Extensions;
using DevExpress.XtraReports.UI;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EndartFabrik
{
public class CustomReportCreator : DefaultReportCreator
{
public override XtraReport CreateCustomerListReport(List<long> oids)
{
var queryReport = FindReportImp<QueryRO>(null, "Klienten");
var customers = DAOFactory.GenericDAO.LoadByIDs<Customer>(oids);
DataTable table = new DataTable();
// Anpassung: neue Spalten "Hauptbetreuung", "Stellvertretung"
string[] spalten = new string[] { "Name", "Geburtsdatum", "Anschrift", "Telefon", "Mobil", "Mail",
"Betreuung begonnen", "Betreuung beendet", "Haupt-betreuung", "Stell-vertretung" };
for (int i = 0; i < spalten.Length; i++)
table.Columns.Add(spalten[i], typeof(string));
for (int i = 0; i < customers.Count; i++)
{
DataRow row = table.NewRow();
Customer customer = customers[i];
Person person = customer.Person;
if (person != null)
{
row[0] = person.LastNameFirstName;
row[1] = String.Format("{0:dd.MM.yyyy}", person.DateOfBirth);
var address = person.Address;
if (address != null)
{
row[2] = address.Street + ", " + address.PostalCode + " " + address.Town;
}
var contacts = person.Contacts;
if (contacts != null)
{
row[3] = contacts.FirstOrDefault(c => c.Type == BS.Shared.ContactType.business_Phone)?.Value;
row[4] = contacts.FirstOrDefault(c => c.Type == BS.Shared.ContactType.business_MobilePhone)?.Value;
row[5] = contacts.FirstOrDefault(c => c.Type == BS.Shared.ContactType.business_Mail)?.Value;
}
}
row[6] = String.Format("{0:dd.MM.yyyy}", customer.AssistanceBegin);
row[7] = String.Format("{0:dd.MM.yyyy}", customer.TerminationDate);
string hauptbetreuung = "";
string stellvertretung = "";
foreach (var item in customer.Employee2CustomerList)
{
foreach (var vl in item.ValueList)
{
if (vl.Entry != null && vl.Entry.Type == BS.Shared.ValueListEntryType.StaffRoleType && vl.Entry.Value.IsNotNullOrEmpty())
{
if (item.StartDate == null && item.EndDate == null ||
item.StartDate.HasValue && item.StartDate.Value <= DateTime.Now.Date && item.EndDate == null ||
item.StartDate.HasValue && item.StartDate.Value <= DateTime.Now.Date && item.EndDate.HasValue && item.EndDate.Value >= DateTime.Now.Date ||
item.StartDate == null && item.EndDate.HasValue && item.EndDate.Value >= DateTime.Now.Date)
{
if (vl.Entry.Value == "Hauptbetreuung")
{
hauptbetreuung = item.Employee.Person.FirstNameLastName;
//hauptbetreuung = string.Format("{0} ({1}{2})", item.Employee.Person.FirstNameLastName,
// item.StartDate.HasValue ? string.Format("{0:dd.MM.yyyy}", item.StartDate) : "",
// item.EndDate.HasValue ? string.Format(" bis {0:dd.MM.yyyy}", item.EndDate) : "");
}
else if (vl.Entry.Value == "Stellvertretung")
{
stellvertretung = item.Employee.Person.FirstNameLastName;
//stellvertretung = string.Format("{0} ({1}{2})", item.Employee.Person.FirstNameLastName,
// item.StartDate.HasValue ? string.Format("{0:dd.MM.yyyy}", item.StartDate) : "",
// item.EndDate.HasValue ? string.Format(" bis {0:dd.MM.yyyy}", item.EndDate) : "");
}
}
}
}
}
row[8] = hauptbetreuung;
row[9] = stellvertretung;
table.Rows.Add(row);
}
var queryReportObject = QueryRO.Create(new Query() { Title = "Klienten" }, table);
queryReportObject.Name = "Klienten";
queryReport.SetReportDataSource(queryReportObject);
return queryReport as XtraReport;
}
}
}