193 lines
6.9 KiB
C#
193 lines
6.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using BeWoPlanerMobil.Models;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.DataContracts.Compact;
|
|
using BS.Shared.Extensions;
|
|
|
|
namespace BeWoPlanerMobil.Util
|
|
{
|
|
public class AppointmentListItem
|
|
{
|
|
public String Identifier { get; }
|
|
|
|
public long? Oid { get; }
|
|
|
|
public string DateTimeInfo { get; }
|
|
|
|
public string Notice { get; }
|
|
|
|
public string Description { get; }
|
|
|
|
public string EmployeeListInfo { get; set; } = string.Empty;
|
|
|
|
public string CustomerListInfo { get; set; } = string.Empty;
|
|
|
|
public string ResourceListInfo { get; set; } = string.Empty;
|
|
|
|
public bool IsTask { get; }
|
|
|
|
public bool IsException { get; }
|
|
|
|
public bool CanBeEdited { get; }
|
|
|
|
public int ColSize
|
|
{
|
|
get
|
|
{
|
|
const int maxColCount = 12;
|
|
|
|
var numberOfCols = 0;
|
|
|
|
if (!string.IsNullOrWhiteSpace(EmployeeListInfo))
|
|
{
|
|
numberOfCols++;
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(CustomerListInfo))
|
|
{
|
|
numberOfCols++;
|
|
}
|
|
|
|
if(!string.IsNullOrWhiteSpace(ResourceListInfo))
|
|
{
|
|
numberOfCols++;
|
|
}
|
|
|
|
return numberOfCols > 0 ? maxColCount / numberOfCols : 12;
|
|
}
|
|
}
|
|
|
|
public string AppointmentColorCss { get; set; }
|
|
|
|
public bool HasEmployeesCustomersOrResources => !string.IsNullOrWhiteSpace(EmployeeListInfo + CustomerListInfo + ResourceListInfo);
|
|
public bool AllDay { get; }
|
|
|
|
public bool HasServiceRecord => (SchedulerAppointment?.ServiceRecordList?.Any() ?? false) || (SchedulerAppointment?.HasServiceRecordEntry ?? false);
|
|
|
|
public string Subject { get; }
|
|
|
|
public SchedulerAppointmentDC SchedulerAppointment { get; }
|
|
|
|
public AppointmentListItem(String id, SchedulerAppointmentDC schedulerAppointment)
|
|
{
|
|
Identifier = id;
|
|
|
|
Subject = schedulerAppointment.Subject;
|
|
|
|
SchedulerAppointment = schedulerAppointment;
|
|
|
|
CanBeEdited = schedulerAppointment.CanBeEdited;
|
|
|
|
Oid = schedulerAppointment.SchedulerAppointmentOid;
|
|
AllDay = schedulerAppointment.AllDay;
|
|
IsTask = schedulerAppointment.IsTask;
|
|
|
|
Notice = schedulerAppointment.CompletedNotice;
|
|
Description = IsTask ? schedulerAppointment.TaskDescription : schedulerAppointment.Description;
|
|
|
|
IsException = schedulerAppointment.Type == 3;
|
|
|
|
var employeeColor = schedulerAppointment.EmployeeList.FirstOrDefault(employee2SchedulerAppointment => !string.IsNullOrWhiteSpace(employee2SchedulerAppointment.Employee.EmployeeColor))?.Employee?.EmployeeColor;
|
|
var customerColor = string.Empty;
|
|
var resourceColor = string.Empty;
|
|
|
|
if(string.IsNullOrWhiteSpace(employeeColor) && schedulerAppointment.EmployeeList.Count == 0 && !string.IsNullOrWhiteSpace(schedulerAppointment.Originator?.EmployeeColor))
|
|
{
|
|
employeeColor = schedulerAppointment.Originator.EmployeeColor;
|
|
}
|
|
|
|
if(employeeColor != null)
|
|
{
|
|
var rgbHexString = GetHexColorValueForCss(employeeColor);
|
|
|
|
AppointmentColorCss = $"border-left-color: {rgbHexString} !important; border-left-width: .25rem !important; ";
|
|
}
|
|
|
|
if(schedulerAppointment.CustomerList.Any())
|
|
{
|
|
customerColor = "#3B7799";
|
|
}
|
|
|
|
if(schedulerAppointment.ResourceList.Any())
|
|
{
|
|
resourceColor = GetHexColorValueForCss(schedulerAppointment.ResourceList.FirstOrDefault()?.Color) ?? "#04B4D0";
|
|
}
|
|
|
|
if(string.IsNullOrWhiteSpace(customerColor) && !string.IsNullOrWhiteSpace(resourceColor))
|
|
{
|
|
customerColor = resourceColor;
|
|
}
|
|
|
|
if(!string.IsNullOrWhiteSpace(customerColor) && string.IsNullOrWhiteSpace(resourceColor))
|
|
{
|
|
resourceColor = customerColor;
|
|
}
|
|
|
|
if(!string.IsNullOrWhiteSpace(resourceColor) && !string.IsNullOrWhiteSpace(customerColor))
|
|
{
|
|
AppointmentColorCss += $"background-image: linear-gradient(to bottom, {customerColor} 50%, {resourceColor} 50% 100%);";
|
|
}
|
|
|
|
var start = schedulerAppointment.StartDate;
|
|
var end = schedulerAppointment.EndDate;
|
|
|
|
if(start.HasValue && end.HasValue)
|
|
{
|
|
DateTimeInfo = start.Value.Date == end.Value.Date ?
|
|
$"{start.Value.ToShortTimeString()} - {end.Value.ToShortTimeString()} " :
|
|
$"{start.Value:dd.MM.yyyy HH:mm} - {end.Value:dd.MM.yyyy HH:mm} ";
|
|
}
|
|
|
|
if(!IsTask && schedulerAppointment.AllDay && start.HasValue && end.HasValue)
|
|
{
|
|
DateTimeInfo = start.Value.Date == end.Value.Date ?
|
|
" " :
|
|
$"{start.Value.ToShortDateString()} - {end.Value.ToShortDateString()} ";
|
|
}
|
|
else if(IsTask && start.HasValue)
|
|
{
|
|
var dueDate = schedulerAppointment.DueDate.HasValue ? $" bis {schedulerAppointment.DueDate.Value.ToShortDateString()} " : string.Empty;
|
|
|
|
DateTimeInfo = $"{schedulerAppointment.Subject} {dueDate}";
|
|
}
|
|
|
|
if(!IsTask)
|
|
{
|
|
DateTimeInfo += schedulerAppointment.Subject;
|
|
}
|
|
|
|
schedulerAppointment.EmployeeList.DoForEach(employee2Appointment => { EmployeeListInfo += $"{employee2Appointment.Employee.LastName}, {employee2Appointment.Employee.FirstName}; "; });
|
|
EmployeeListInfo = EmployeeListInfo.Trim(' ').Trim(';');
|
|
|
|
schedulerAppointment.CustomerList.DoForEach(customer2Appointment => { CustomerListInfo += $"{customer2Appointment.SimpleDescription}; "; });
|
|
CustomerListInfo = CustomerListInfo.Trim(' ').Trim(';');
|
|
|
|
schedulerAppointment.ResourceList.DoForEach(resource => { ResourceListInfo += $"{resource.Name}; "; });
|
|
ResourceListInfo = ResourceListInfo.Trim(' ').Trim(';');
|
|
|
|
if(IsTask && schedulerAppointment.SupportConceptList.Any())
|
|
{
|
|
CustomerListInfo = schedulerAppointment.SupportConceptList.First().CustomerName;
|
|
}
|
|
}
|
|
|
|
private static string GetHexColorValueForCss(string argbHexColorValue)
|
|
{
|
|
try
|
|
{
|
|
var argbInt = Convert.ToInt32(argbHexColorValue.TrimStart('#'), 16);
|
|
|
|
var color = Color.FromArgb(argbInt);
|
|
|
|
return $"#{color.R:X2}{color.G:X2}{color.B:X2}";
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return string.Empty;
|
|
}
|
|
}
|
|
}
|
|
} |