311 lines
11 KiB
C#
311 lines
11 KiB
C#
using System;
|
|
using System.Linq;
|
|
using BeWo.Report;
|
|
using BeWo.Report.ReportObjects;
|
|
using BeWo.Data.Entities;
|
|
using BeWo.Data.Access;
|
|
using System.Collections.Generic;
|
|
using BS.Shared;
|
|
using BS.Shared.Core;
|
|
using DevExpress.XtraPrinting;
|
|
|
|
namespace BeWo.SeWo
|
|
{
|
|
[IDSpecificClass(Identifier = "UeberschneidungenInZeiterfassung")]
|
|
public partial class Doppeleintraege : DevExpress.XtraReports.UI.XtraReport, IBeWoReport<QueryRO>
|
|
{
|
|
|
|
public Doppeleintraege()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
public void SetReportDataSource(QueryRO pRO)
|
|
{
|
|
|
|
this.bindingSource1.DataSource = CreateDataSource(pRO);
|
|
}
|
|
|
|
private QueryRO CreateDataSource(QueryRO ro)
|
|
{
|
|
QueryRO newQueryRo = new QueryRO();
|
|
|
|
bool checkMitarbeiter = true;
|
|
DateTime abfrageMonat = DateTime.Now;
|
|
long? teamOid = null;
|
|
|
|
if (ro.Rows != null && ro.Rows.Count > 0)
|
|
{
|
|
if (ro.Rows[0].Field1 != null)
|
|
{
|
|
int i = 1;
|
|
|
|
if (Int32.TryParse(ro.Rows[0].Field1.ToString(), out i))
|
|
{
|
|
if (i == 2)
|
|
{
|
|
checkMitarbeiter = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (ro.Rows[0].Field2 != null)
|
|
{
|
|
DateTime dtTemp = DateTime.Now;
|
|
|
|
if (DateTime.TryParse(ro.Rows[0].Field2.ToString(), out dtTemp))
|
|
{
|
|
abfrageMonat = dtTemp;
|
|
}
|
|
}
|
|
if (ro.Rows[0].Field3 != null)
|
|
{
|
|
long oid = 0;
|
|
|
|
if (Int64.TryParse(ro.Rows[0].Field3.ToString(), out oid) && oid > 0)
|
|
{
|
|
teamOid = oid;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (checkMitarbeiter)
|
|
{
|
|
lblTitel.Text = "Doppeleinträge Mitarbeiter";
|
|
cellHeader1.Text = "Mitarbeiter/in";
|
|
cellHeader2.Text = "Kunde/Hilfeplan 1";
|
|
cellHeader3.Text = "Kunde/Hilfeplan 2";
|
|
}
|
|
else
|
|
{
|
|
lblTitel.Text = "Doppeleinträge Kunden";
|
|
cellHeader1.Text = "Kunde";
|
|
cellHeader2.Text = "Mitarbeiter/in 1";
|
|
cellHeader3.Text = "Mitarbeiter/in 2";
|
|
}
|
|
|
|
|
|
var srArray = DAOFactory.SearchDAO.GetBillableServiceRecords(new DateTime(abfrageMonat.Year, abfrageMonat.Month, 1), new DateTime(abfrageMonat.Year, abfrageMonat.Month, 1).AddMonths(1).AddTicks(-1)).ToArray();
|
|
|
|
List<OverlappingPair> overlappingList = new List<OverlappingPair>();
|
|
|
|
Dictionary<String, bool> groupOids = new Dictionary<String, bool>();
|
|
|
|
List<long> empOids = new List<long>();
|
|
|
|
if (teamOid.HasValue && teamOid.Value > 0)
|
|
{
|
|
var team = DAOFactory.GenericDAO.LoadByID<Team>(teamOid.Value);
|
|
foreach (var employee in team.MemberList)
|
|
{
|
|
if (!empOids.Contains(employee.Oid.Value))
|
|
{
|
|
empOids.Add(employee.Oid.Value);
|
|
}
|
|
}
|
|
if (!empOids.Contains(team.Leader.Oid.Value))
|
|
{
|
|
empOids.Add(team.Leader.Oid.Value);
|
|
}
|
|
}
|
|
|
|
for (int i = 0; i < srArray.Length - 1; i++)
|
|
{
|
|
for (int j = i + 1; j < srArray.Length; j++)
|
|
{
|
|
|
|
ServiceRecord sr1 = srArray[i];
|
|
ServiceRecord sr2 = srArray[j];
|
|
|
|
|
|
if (sr1.CustomerOid.HasValue && sr2.CustomerOid.HasValue && sr1.EmployeeOid.HasValue && sr2.EmployeeOid.HasValue &&
|
|
(!sr1.GroupOid.HasValue || !sr2.GroupOid.HasValue || sr1.GroupOid != sr2.GroupOid))
|
|
{
|
|
|
|
|
|
bool overlaps = TimeSpanOverlapsWithOtherTimeSpan(sr1, sr2);
|
|
|
|
if (overlaps)
|
|
{
|
|
bool check = true;
|
|
|
|
if (checkMitarbeiter)
|
|
{
|
|
check = sr1.EmployeeOid == sr2.EmployeeOid;
|
|
|
|
}
|
|
else
|
|
{
|
|
check = sr1.CustomerOid == sr2.CustomerOid;
|
|
}
|
|
if (check && empOids.Count > 0)
|
|
{
|
|
if (!empOids.Contains(sr1.EmployeeOid.Value) && !empOids.Contains(sr2.EmployeeOid.Value))
|
|
{
|
|
check = false;
|
|
}
|
|
}
|
|
if (check)
|
|
{
|
|
|
|
if (sr1.SupportConcept.IsActive != ActivationTypeId.Deleted && sr2.SupportConcept.IsActive != ActivationTypeId.Deleted &&
|
|
sr1.Customer.IsActive != ActivationTypeId.Deleted && sr2.Customer.IsActive != ActivationTypeId.Deleted)
|
|
{
|
|
|
|
if (sr1.EmployeeOid == 61)
|
|
{
|
|
int test = 0;
|
|
}
|
|
|
|
bool cont = true;
|
|
|
|
if (sr1.GroupOid.HasValue && sr2.GroupOid.HasValue)
|
|
{
|
|
String key = String.Format("{0}_{1}", sr1.GroupOid.Value, sr2.GroupOid.Value);
|
|
String key2 = String.Format("{0}_{1}", sr2.GroupOid.Value, sr1.GroupOid.Value);
|
|
|
|
if (groupOids.ContainsKey(key) || groupOids.ContainsKey(key2))
|
|
cont = false;
|
|
else
|
|
groupOids.Add(key, true);
|
|
}
|
|
|
|
if (cont)
|
|
overlappingList.Add(new OverlappingPair {ServiceRecord1 = sr1, ServiceRecord2 = sr2});
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
foreach (var overlappingPair in overlappingList)
|
|
{
|
|
QueryRO.Row row = new QueryRO.Row();
|
|
|
|
String name1 = "";
|
|
String name2 = "";
|
|
|
|
Customer c1 = overlappingPair.ServiceRecord1.Customer;
|
|
name1 = String.Format("{0}, {1}", c1.Person.LastName, c1.Person.FirstName);
|
|
|
|
Customer c2 = overlappingPair.ServiceRecord2.Customer;
|
|
name2 = String.Format("{0}, {1}", c2.Person.LastName, c2.Person.FirstName);
|
|
|
|
if (overlappingPair.ServiceRecord1.GroupOid.HasValue)
|
|
name1 += " (Gruppe)";
|
|
|
|
|
|
if (overlappingPair.ServiceRecord2.GroupOid.HasValue)
|
|
name2 += " (Gruppe)";
|
|
|
|
|
|
Employee e1 = overlappingPair.ServiceRecord1.Employee;
|
|
Employee e2 = overlappingPair.ServiceRecord2.Employee;
|
|
|
|
CostBearer2SupportConcept c2s1 = overlappingPair.ServiceRecord1.CostBearer2SupportConcept;
|
|
CostBearer2SupportConcept c2s2 = overlappingPair.ServiceRecord2.CostBearer2SupportConcept;
|
|
|
|
if (checkMitarbeiter)
|
|
{
|
|
row.Field1 = String.Format("{0}\n{1:dd.MM.yy} - {2:dd.MM.yy}", name1, c2s1.StartDate, c2s1.EndDate);
|
|
//row.Field2 = String.Format("{0:dd.MM.yy} - {1:dd.MM.yy}", c2s1.StartDate, c2s1.EndDate);
|
|
//row.Field2 = String.Format("{0:dd.MM.yy HH:mm} - {1:HH:mm}\n{2} {3}", overlappingPair.ServiceRecord1.Start, overlappingPair.ServiceRecord1.End,
|
|
// e1.Person.FirstName, e1.Person.LastName);
|
|
row.Field2 = String.Format("{0:dd.MM.yy}", overlappingPair.ServiceRecord1.Start);
|
|
row.Field4 = String.Format("{0:HH:mm} - {1:HH:mm}", overlappingPair.ServiceRecord1.Start, overlappingPair.ServiceRecord1.End);
|
|
row.Field11 = overlappingPair.ServiceRecord1.ServiceDescription.Name;
|
|
|
|
row.Field6 = String.Format("{0}\n{1:dd.MM.yy} - {2:dd.MM.yy}", name2, c2s2.StartDate, c2s2.EndDate);
|
|
//row.Field7 = String.Format("{0:dd.MM.yy} - {1:dd.MM.yy}", c2s2.StartDate, c2s2.EndDate);
|
|
//row.Field7 = String.Format("{0:dd.MM.yy HH:mm} - {1:HH:mm}\n{2} {3}", overlappingPair.ServiceRecord2.Start, overlappingPair.ServiceRecord2.End,
|
|
// e2.Person.FirstName, e2.Person.LastName);
|
|
row.Field7 = String.Format("{0:dd.MM.yy}", overlappingPair.ServiceRecord2.Start);
|
|
row.Field8 = String.Format("{0:HH:mm} - {1:HH:mm}", overlappingPair.ServiceRecord2.Start, overlappingPair.ServiceRecord2.End);
|
|
row.Field12 = overlappingPair.ServiceRecord2.ServiceDescription.Name;
|
|
|
|
row.Field3 = String.Format("{0} {1}", e1.Person.FirstName, e1.Person.LastName);
|
|
|
|
|
|
row.Field10 = String.Format("{1}, {0}_{2:yyyyMMddHHmm}", e1.Person.FirstName, e1.Person.LastName, overlappingPair.ServiceRecord1.Start);
|
|
}
|
|
else
|
|
{
|
|
row.Field3 = String.Format("{0}\n{1:dd.MM.yy} - {2:dd.MM.yy}", name1, c2s1.StartDate, c2s1.EndDate);
|
|
|
|
row.Field1 = String.Format("{0} {1}", e1.Person.FirstName, e1.Person.LastName);
|
|
|
|
row.Field2 = String.Format("{0:dd.MM.yy}", overlappingPair.ServiceRecord1.Start);
|
|
row.Field4 = String.Format("{0:HH:mm} - {1:HH:mm}", overlappingPair.ServiceRecord1.Start, overlappingPair.ServiceRecord1.End);
|
|
row.Field11 = overlappingPair.ServiceRecord1.ServiceDescription.Name;
|
|
|
|
row.Field6 = String.Format("{0} {1}", e2.Person.FirstName, e2.Person.LastName);
|
|
|
|
row.Field7 = String.Format("{0:dd.MM.yy}", overlappingPair.ServiceRecord2.Start);
|
|
row.Field8 = String.Format("{0:HH:mm} - {1:HH:mm}", overlappingPair.ServiceRecord2.Start, overlappingPair.ServiceRecord2.End);
|
|
row.Field12 = overlappingPair.ServiceRecord2.ServiceDescription.Name;
|
|
//row.Field2 = String.Format("{0:dd.MM.yy} - {1:dd.MM.yy}", c2s1.StartDate, c2s1.EndDate);
|
|
//row.Field2 = String.Format("{0:dd.MM.yy HH:mm} - {1:HH:mm}\n{2} {3}", overlappingPair.ServiceRecord1.Start, overlappingPair.ServiceRecord1.End,
|
|
// e1.Person.FirstName, e1.Person.LastName);
|
|
|
|
//row.Field6 = String.Format("{0}\n{1:dd.MM.yy} - {2:dd.MM.yy}", name2, c2s2.StartDate, c2s2.EndDate);
|
|
//row.Field7 = String.Format("{0:dd.MM.yy HH:mm} - {1:HH:mm}\n{2} {3}", overlappingPair.ServiceRecord2.Start, overlappingPair.ServiceRecord2.End,
|
|
// e2.Person.FirstName, e2.Person.LastName);
|
|
|
|
//row.Field3 = String.Format("{0} {1}", e1.Person.FirstName, e1.Person.LastName);
|
|
|
|
//cellHeader1.Visible = false;
|
|
//xrTableRow2.Cells[xrTableRow2.Cells.Count - 1].Visible = false;
|
|
|
|
row.Field10 = String.Format("{0}_{1:yyyyMMddHHmm}", name1, overlappingPair.ServiceRecord1.Start);
|
|
//row.Field10 = name1;
|
|
}
|
|
//row.Field10 = String.Format("{0:yyyyMMddHHmm}", overlappingPair.ServiceRecord1.Start);
|
|
|
|
|
|
newQueryRo.Rows.Add(row);
|
|
}
|
|
|
|
newQueryRo.Rows.Sort((a, b) => a.Field10.ToString().CompareTo(b.Field10));
|
|
|
|
if (newQueryRo.Rows.Count == 0)
|
|
{
|
|
lblGefunden.Visible = true;
|
|
xrTable2.Visible = false;
|
|
}
|
|
else
|
|
{
|
|
lblGefunden.Visible = false;
|
|
}
|
|
|
|
|
|
return newQueryRo;
|
|
}
|
|
|
|
private bool TimeSpanOverlapsWithOtherTimeSpan(ServiceRecord sr1, ServiceRecord sr2)
|
|
{
|
|
|
|
if (sr1.Start.HasValue && sr2.Start.HasValue && sr1.End.HasValue && sr2.End.HasValue)
|
|
{
|
|
if (sr1.Start.Value.Second > 0)
|
|
return false;
|
|
if (sr2.Start.Value.Second > 0)
|
|
return false;
|
|
|
|
return !(sr1.End <= sr2.Start || sr1.Start >= sr2.End);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
class OverlappingPair
|
|
{
|
|
public ServiceRecord ServiceRecord1;
|
|
public ServiceRecord ServiceRecord2;
|
|
}
|
|
|
|
}
|