389 lines
12 KiB
C#
389 lines
12 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 PflegedienstWessel
|
|
{
|
|
[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";
|
|
}
|
|
|
|
try
|
|
{
|
|
var start = new DateTime(abfrageMonat.Year, abfrageMonat.Month, 1);
|
|
var end = new DateTime(abfrageMonat.Year, abfrageMonat.Month, 1).AddMonths(1);
|
|
List<ServiceRecordInfo> srList = new List<ServiceRecordInfo>();
|
|
|
|
while (start < end)
|
|
{
|
|
var list = DAOFactory.SearchDAO.GetSqlResult(String.Format(@"
|
|
SELECT sr.Oid, sr.StartDate, sr.EndDate, sr.EmployeeOid, sr.CustomerOid, sr.GroupOid, sr.costbearer2supportconceptoid, sd.Name, sc.Name
|
|
FROM ServiceRecord sr
|
|
inner join ServiceDescription sd on sr.ServiceDescriptionOid = sd.Oid
|
|
inner join ServiceCategory sc on sd.ServiceCategoryOid = sc.Oid
|
|
WHERE sc.Billable = 1 and sr.StartDate >= '{0:yyyy-MM-dd}' and sr.StartDate < '{1:yyyy-MM-dd}'", start, start.AddDays(1)));
|
|
|
|
foreach (object[] item in list)
|
|
{
|
|
var sr = new ServiceRecordInfo();
|
|
sr.Oid = (long)item[0];
|
|
sr.StartDate = (DateTime)item[1];
|
|
sr.EndDate = (DateTime)item[2];
|
|
sr.EmployeeOid = (long)item[3];
|
|
sr.CustomerOid = (long?)item[4];
|
|
sr.GroupOid = (long?)item[5];
|
|
sr.C2SOid = (long?)item[6];
|
|
sr.ServiceDescription = (String)item[7];
|
|
sr.ServiceCategory = (String)item[8];
|
|
|
|
srList.Add(sr);
|
|
}
|
|
|
|
start = start.AddDays(1);
|
|
}
|
|
|
|
//var srArray = DAOFactory.SearchDAO.GetBillableServiceRecordsSqlArray(new DateTime(abfrageMonat.Year, abfrageMonat.Month, 1), new DateTime(abfrageMonat.Year, abfrageMonat.Month, 1).AddMonths(1));
|
|
|
|
|
|
//sr.Oid, sr.StartDate, sr.EndDate, sr.EmployeeOid, sr.CustomerOid, sr.GroupOid, sr.costbearer2supportconceptoid, sd.Name, sc.Name
|
|
|
|
|
|
|
|
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 < srList.Count - 1; i++)
|
|
{
|
|
for (int j = i + 1; j < srList.Count; j++)
|
|
{
|
|
|
|
ServiceRecordInfo sr1 = srList[i];
|
|
ServiceRecordInfo sr2 = srList[j];
|
|
|
|
|
|
if (sr1.CustomerOid.HasValue && sr2.CustomerOid.HasValue && sr1.C2SOid.HasValue && sr2.C2SOid.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) && !empOids.Contains(sr2.EmployeeOid))
|
|
{
|
|
check = false;
|
|
}
|
|
}
|
|
if (check)
|
|
{
|
|
|
|
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 = DAOFactory.GenericDAO.LoadByID<Customer>(overlappingPair.ServiceRecord1.CustomerOid.Value);
|
|
name1 = String.Format("{0}, {1}", c1.Person.LastName, c1.Person.FirstName);
|
|
|
|
Customer c2 = DAOFactory.GenericDAO.LoadByID<Customer>(overlappingPair.ServiceRecord2.CustomerOid.Value);
|
|
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 = DAOFactory.GenericDAO.LoadByID<Employee>(overlappingPair.ServiceRecord1.EmployeeOid);
|
|
Employee e2 = DAOFactory.GenericDAO.LoadByID<Employee>(overlappingPair.ServiceRecord2.EmployeeOid);
|
|
|
|
CostBearer2SupportConcept c2s1 = DAOFactory.GenericDAO.LoadByID<CostBearer2SupportConcept>(overlappingPair.ServiceRecord1.C2SOid.Value);
|
|
CostBearer2SupportConcept c2s2 = DAOFactory.GenericDAO.LoadByID<CostBearer2SupportConcept>(overlappingPair.ServiceRecord2.C2SOid.Value);
|
|
|
|
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.StartDate);
|
|
row.Field4 = String.Format("{0:HH:mm} - {1:HH:mm}", overlappingPair.ServiceRecord1.StartDate, overlappingPair.ServiceRecord1.EndDate);
|
|
row.Field11 = overlappingPair.ServiceRecord1.ServiceDescription;
|
|
|
|
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.StartDate);
|
|
row.Field8 = String.Format("{0:HH:mm} - {1:HH:mm}", overlappingPair.ServiceRecord2.StartDate, overlappingPair.ServiceRecord2.EndDate);
|
|
row.Field12 = overlappingPair.ServiceRecord2.ServiceDescription;
|
|
|
|
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.StartDate);
|
|
}
|
|
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.StartDate);
|
|
row.Field4 = String.Format("{0:HH:mm} - {1:HH:mm}", overlappingPair.ServiceRecord1.StartDate, overlappingPair.ServiceRecord1.EndDate);
|
|
row.Field11 = overlappingPair.ServiceRecord1.ServiceDescription;
|
|
|
|
row.Field6 = String.Format("{0} {1}", e2.Person.FirstName, e2.Person.LastName);
|
|
|
|
row.Field7 = String.Format("{0:dd.MM.yy}", overlappingPair.ServiceRecord2.StartDate);
|
|
row.Field8 = String.Format("{0:HH:mm} - {1:HH:mm}", overlappingPair.ServiceRecord2.StartDate, overlappingPair.ServiceRecord2.EndDate);
|
|
row.Field12 = overlappingPair.ServiceRecord2.ServiceDescription;
|
|
//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.StartDate);
|
|
//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;
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
var emsg = new ErrorMessage();
|
|
var ix = ex.InnerException;
|
|
if (ix != null)
|
|
{
|
|
ix = ix.InnerException;
|
|
if (ix != null)
|
|
{
|
|
ix = ix.InnerException;
|
|
if (ix != null)
|
|
{
|
|
emsg.Message = ix.Message;
|
|
|
|
emsg.MessageDetails = ix.StackTrace;
|
|
}
|
|
}
|
|
|
|
}
|
|
if (String.IsNullOrEmpty(emsg.MessageDetails))
|
|
{
|
|
emsg.Message = "Keine 3 Inner Ex";
|
|
emsg.MessageDetails = ex.ToString();
|
|
}
|
|
|
|
emsg.Datum = DateTime.Now;
|
|
|
|
DAOFactory.GenericDAO.Insert(emsg);
|
|
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
private bool TimeSpanOverlapsWithOtherTimeSpan(ServiceRecordInfo sr1, ServiceRecordInfo sr2)
|
|
{
|
|
|
|
if (sr1.StartDate.Second > 0)
|
|
return false;
|
|
if (sr2.StartDate.Second > 0)
|
|
return false;
|
|
|
|
return !(sr1.EndDate <= sr2.StartDate || sr1.StartDate >= sr2.EndDate);
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
class ServiceRecordInfo
|
|
{
|
|
public long Oid;
|
|
public long EmployeeOid;
|
|
public long? CustomerOid;
|
|
public long? GroupOid;
|
|
public long? C2SOid;
|
|
public DateTime StartDate { get; set; }
|
|
public DateTime EndDate { get; set; }
|
|
public String ServiceDescription { get; set; }
|
|
public String ServiceCategory { get; set; }
|
|
}
|
|
|
|
class OverlappingPair
|
|
{
|
|
public ServiceRecordInfo ServiceRecord1;
|
|
public ServiceRecordInfo ServiceRecord2;
|
|
}
|
|
|
|
}
|