304 lines
13 KiB
C#
304 lines
13 KiB
C#
using BeWo.Data.Access;
|
|
using BeWo.Data.Entities;
|
|
using BeWo.Service.ServiceUtils;
|
|
using BS.Shared;
|
|
using BS.Shared.Extensions;
|
|
using BS.Shared.Translation;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace BeWo.Service.Reporting
|
|
{
|
|
public class ExportAndPrintHelper
|
|
{
|
|
// Hier ist der Code, der die StringArrays für den Excel-Export und die Print-Versionen des Exports erstellt
|
|
public virtual string[] PrepareHeaderArrayForCustomerExport()
|
|
{
|
|
string[] lHeaderCaption = {
|
|
"Nachname", // 0
|
|
"Vorname", // 1
|
|
"Geburtsdatum", // 3
|
|
"Beruf", // 4
|
|
"Geschlecht", // 5
|
|
"Familienstand", // 6
|
|
"Telefon", // 7
|
|
"Mobil", // 8
|
|
"Mail", // 9
|
|
"Fax", // 10
|
|
"Strasse", // 11
|
|
"PLZ", // 12
|
|
"Ort", // 13
|
|
"Bemerkung", // 14
|
|
"Erstbetreuung", // 15
|
|
"Betreuung begonnen", // 16
|
|
"Betreuung beendet", // 17
|
|
"Grund für Beendigung" // 18
|
|
};
|
|
|
|
return lHeaderCaption;
|
|
}
|
|
|
|
public virtual string[][] PrepareContentArrayForCustomerExport(long[] pSortedOids)
|
|
{
|
|
var lCustomers = DAOFactory.GenericDAO.LoadByIDs<Customer>(pSortedOids);
|
|
|
|
var lHeaderCaption = PrepareHeaderArrayForCustomerExport();
|
|
|
|
var lContent = new string[lCustomers.Count][];
|
|
|
|
for (int iRowCount = 0; iRowCount < lCustomers.Count; iRowCount++)
|
|
{
|
|
lContent[iRowCount] = new string[lHeaderCaption.Count()];
|
|
|
|
lContent[iRowCount][0] = lCustomers[iRowCount].Person.LastName;
|
|
lContent[iRowCount][1] = lCustomers[iRowCount].Person.FirstName;
|
|
//lContent[iRowCount][2] = lCustomers[iRowCount].ReferenceNumber;
|
|
|
|
if (lCustomers[iRowCount].Person.DateOfBirth.HasValue)
|
|
{
|
|
lContent[iRowCount][2] = lCustomers[iRowCount].Person.DateOfBirth.Value.ToShortDateString();
|
|
}
|
|
|
|
lContent[iRowCount][3] = lCustomers[iRowCount].Person.Profession;
|
|
|
|
lContent[iRowCount][4] = lCustomers[iRowCount].Person.Sex == Sex.Male
|
|
? "männlich"
|
|
: "weiblich";
|
|
|
|
if (lCustomers[iRowCount].Person.FamilyStatus != null)
|
|
{
|
|
switch (lCustomers[iRowCount].Person.FamilyStatus.Value)
|
|
{
|
|
case FamilyStatus.Divorced:
|
|
lContent[iRowCount][5] = "geschieden";
|
|
break;
|
|
case FamilyStatus.Married:
|
|
lContent[iRowCount][5] = "verheiratet";
|
|
break;
|
|
case FamilyStatus.Single:
|
|
lContent[iRowCount][5] = "ledig";
|
|
break;
|
|
case FamilyStatus.Widowed:
|
|
lContent[iRowCount][5] = "verwitwet";
|
|
break;
|
|
case FamilyStatus.Partner:
|
|
lContent[iRowCount][5] = "in Partnerschaft";
|
|
break;
|
|
case FamilyStatus.PartnerDivorced:
|
|
lContent[iRowCount][5] = "getrennt lebend";
|
|
break;
|
|
case FamilyStatus.PartnerDead:
|
|
lContent[iRowCount][5] = "partnerhinterblieben";
|
|
break;
|
|
case FamilyStatus.PartnerMarried:
|
|
lContent[iRowCount][5] = "verpartnert";
|
|
break;
|
|
case FamilyStatus.Entpartnert:
|
|
lContent[iRowCount][5] = "entpartnert";
|
|
break;
|
|
}
|
|
}
|
|
|
|
foreach (var iContact in lCustomers[iRowCount].Person.Contacts)
|
|
{
|
|
switch (iContact.Type)
|
|
{
|
|
case ContactType.business_Phone:
|
|
lContent[iRowCount][6] = iContact.Value;
|
|
break;
|
|
case ContactType.business_MobilePhone:
|
|
lContent[iRowCount][7] = iContact.Value;
|
|
break;
|
|
case ContactType.business_Mail:
|
|
lContent[iRowCount][8] = iContact.Value;
|
|
break;
|
|
case ContactType.business_Fax:
|
|
lContent[iRowCount][9] = iContact.Value;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (lCustomers[iRowCount].Person.Address != null)
|
|
{
|
|
lContent[iRowCount][10] = lCustomers[iRowCount].Person.Address.Street;
|
|
lContent[iRowCount][11] = lCustomers[iRowCount].Person.Address.PostalCode;
|
|
lContent[iRowCount][12] = lCustomers[iRowCount].Person.Address.Town;
|
|
}
|
|
|
|
lContent[iRowCount][13] = lCustomers[iRowCount].Notice;
|
|
|
|
if (lCustomers[iRowCount].Employee2CustomerList == null)
|
|
continue;
|
|
|
|
foreach (var e2c in lCustomers[iRowCount].Employee2CustomerList)
|
|
{
|
|
foreach (var vle in e2c.ValueList.Select(vle2o => vle2o.Entry).Where(vle => vle.SystemEntryID != null && vle.SystemEntryID.Value == SystemEntryID.EmployeeRoleMainAttendant))
|
|
{
|
|
lHeaderCaption[14] = vle.Value;
|
|
lContent[iRowCount][14] = e2c.Employee.Person.FirstName + " " + e2c.Employee.Person.LastName;
|
|
}
|
|
}
|
|
|
|
lContent[iRowCount][15] = String.Format("{0:dd.MM.yyyy}", lCustomers[iRowCount].AssistanceBegin);
|
|
lContent[iRowCount][16] = String.Format("{0:dd.MM.yyyy}", lCustomers[iRowCount].TerminationDate);
|
|
|
|
if (lCustomers[iRowCount].TerminationReason != null)
|
|
{
|
|
lContent[iRowCount][17] = lCustomers[iRowCount].TerminationReason.Value;
|
|
}
|
|
else
|
|
{
|
|
lContent[iRowCount][17] = "";
|
|
}
|
|
}
|
|
|
|
return lContent;
|
|
}
|
|
|
|
public virtual string[] PrepareHeaderArrayForPersonExport()
|
|
{
|
|
return new string[] {
|
|
"Titel", // 0
|
|
"Nachname", // 1
|
|
"Vorname", // 2
|
|
"Funktion", // 3
|
|
"Geburtsdatum", // 4
|
|
"Strasse", // 5
|
|
"PLZ", // 6
|
|
"Ort", // 7
|
|
"Telefon", // 8
|
|
"Mobil", // 9
|
|
"Mail", // 10
|
|
"Fax", // 11
|
|
"Bemerkung" // 12
|
|
};
|
|
}
|
|
|
|
public virtual string[][] PrepareContentArrayForPersonExport(long[] pSortedOids)
|
|
{
|
|
var lPersons = DAOFactory.GenericDAO.LoadByIDs<Person>(pSortedOids);
|
|
|
|
string[][] lContent = new string[lPersons.Count][];
|
|
|
|
for (int iRowCount = 0; iRowCount < lPersons.Count; iRowCount++)
|
|
{
|
|
lContent[iRowCount] = new string[PrepareHeaderArrayForPersonExport().Count()];
|
|
|
|
if (lPersons[iRowCount].Title != null)
|
|
{
|
|
lContent[iRowCount][0] = lPersons[iRowCount].Title.Value;
|
|
}
|
|
else
|
|
{
|
|
lContent[iRowCount][0] = string.Empty;
|
|
}
|
|
lContent[iRowCount][1] = lPersons[iRowCount].LastName;
|
|
|
|
|
|
lContent[iRowCount][2] = lPersons[iRowCount].FirstName;
|
|
|
|
|
|
if (lPersons[iRowCount].Function != null)
|
|
{
|
|
lContent[iRowCount][3] = lPersons[iRowCount].Function.Value;
|
|
}
|
|
else
|
|
{
|
|
lContent[iRowCount][3] = string.Empty;
|
|
}
|
|
|
|
lContent[iRowCount][4] = lPersons[iRowCount].DateOfBirth.DoIfNotNull(d => d.ToShortDateString());
|
|
|
|
// lContent[iRowCount][4] = lPersons[iRowCount].Sex == Sex.Male ? "männlich" : "weiblich";
|
|
if (lPersons[iRowCount].Address != null)
|
|
{
|
|
lContent[iRowCount][5] = lPersons[iRowCount].Address.Street;
|
|
lContent[iRowCount][6] = lPersons[iRowCount].Address.PostalCode;
|
|
lContent[iRowCount][7] = lPersons[iRowCount].Address.Town;
|
|
}
|
|
|
|
foreach (var iContact in lPersons[iRowCount].Contacts)
|
|
{
|
|
switch (iContact.Type)
|
|
{
|
|
case ContactType.private_Phone:
|
|
lContent[iRowCount][8] = iContact.Value;
|
|
break;
|
|
case ContactType.private_MobilePhone:
|
|
lContent[iRowCount][9] = iContact.Value;
|
|
break;
|
|
case ContactType.private_Mail:
|
|
lContent[iRowCount][10] = iContact.Value;
|
|
break;
|
|
case ContactType.private_Fax:
|
|
lContent[iRowCount][11] = iContact.Value;
|
|
break;
|
|
}
|
|
}
|
|
|
|
lContent[iRowCount][12] = lPersons[iRowCount].Notice;
|
|
}
|
|
|
|
return lContent;
|
|
}
|
|
|
|
public virtual string[] PrepareHeaderArrayForUserExport()
|
|
{
|
|
return new string[]{ "Mitarbeiter", "Login", "zugeordnete Benutzergruppen" };
|
|
}
|
|
|
|
public virtual string[][] PrepareContentArrayForUserExport(long[] pSortedOids)
|
|
{
|
|
var lUser = DAOFactory.GenericDAO.LoadByIDs<ApplicationUser>(pSortedOids);
|
|
|
|
string[][] lContent = new string[lUser.Count][];
|
|
|
|
for (int iRowCount = 0; iRowCount < lUser.Count; iRowCount++)
|
|
{
|
|
lContent[iRowCount] = new string[3];
|
|
if (lUser[iRowCount].Employee != null)
|
|
{
|
|
lContent[iRowCount][0] = lUser[iRowCount].Employee.Person.ToString();
|
|
}
|
|
else
|
|
{
|
|
lContent[iRowCount][0] = "";
|
|
}
|
|
|
|
lContent[iRowCount][1] = lUser[iRowCount].LoginName;
|
|
lContent[iRowCount][2] = string.Join(", ", lUser[iRowCount].UserGroups.Select(ug => ug.Name).ToArray());
|
|
}
|
|
|
|
return lContent;
|
|
}
|
|
|
|
public virtual string[] PrepareHeaderArrayForUserGroupExport()
|
|
{
|
|
return new string[] { "Name", "Beschreibung", "zugeordnete Rechte" };
|
|
}
|
|
|
|
public virtual string[][] PrepareContentArrayForUserGroupExport(long[] pSortedOids)
|
|
{
|
|
Translator t = new Translator(new ServiceTranslator());
|
|
|
|
var lUserGroups = DAOFactory.GenericDAO.LoadByIDs<UserGroup>(pSortedOids);
|
|
|
|
string[][] lContent = new string[lUserGroups.Count][];
|
|
|
|
for (int iRowCount = 0; iRowCount < lUserGroups.Count; iRowCount++)
|
|
{
|
|
lContent[iRowCount] = new string[3];
|
|
|
|
lContent[iRowCount][0] = lUserGroups[iRowCount].Name;
|
|
lContent[iRowCount][1] = lUserGroups[iRowCount].Description;
|
|
lContent[iRowCount][2] = string.Join(", ", lUserGroups[iRowCount].Rights.Select(r => BS.Shared.Core.EnumTranslations.UserRightType2Translations[r.RightType]).OrderBy(s => s).ToArray());
|
|
}
|
|
|
|
return lContent;
|
|
}
|
|
}
|
|
}
|