2016-06-27 01:45:38 +02:00
|
|
|
|
using System;
|
2019-12-19 14:27:03 +01:00
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
|
using System.Windows;
|
2016-06-27 01:45:38 +02:00
|
|
|
|
using BeWo.Validation;
|
|
|
|
|
|
using BS.Shared.DataContracts;
|
2019-12-19 14:27:03 +01:00
|
|
|
|
using BS.Shared.Extensions;
|
2016-06-27 01:45:38 +02:00
|
|
|
|
|
|
|
|
|
|
namespace BeWo.ViewModel
|
|
|
|
|
|
{
|
2019-12-19 14:27:03 +01:00
|
|
|
|
public class AbsenceTimeVM : AbstractDCMapperVM<AbsenceTimeDC>, IDataErrorInfo
|
2016-06-27 01:45:38 +02:00
|
|
|
|
{
|
|
|
|
|
|
public static string PropertyName_End = "End";
|
|
|
|
|
|
|
|
|
|
|
|
public static string PropertyName_Notice = "Notice";
|
|
|
|
|
|
|
|
|
|
|
|
public static string PropertyName_Reason = "Reason";
|
|
|
|
|
|
|
|
|
|
|
|
public static string PropertyName_Start = "Start";
|
|
|
|
|
|
|
2017-04-28 14:08:23 +02:00
|
|
|
|
public static string PropertyName_KrankheitsMeldung = "KrankheitsMeldung";
|
|
|
|
|
|
|
2016-06-27 01:45:38 +02:00
|
|
|
|
private DateTime? _End;
|
|
|
|
|
|
|
|
|
|
|
|
private string _Notice;
|
|
|
|
|
|
|
|
|
|
|
|
private AbsenceReasonDC _Reason;
|
|
|
|
|
|
|
|
|
|
|
|
private DateTime? _Start;
|
|
|
|
|
|
|
2017-04-28 14:08:23 +02:00
|
|
|
|
private DateTime? _KrankheitsMeldung;
|
|
|
|
|
|
|
2021-02-23 09:57:51 +01:00
|
|
|
|
private string _BackgroundColor;
|
|
|
|
|
|
|
2019-12-19 14:27:03 +01:00
|
|
|
|
public AbsenceTimeVM(AbsenceTimeDC pDC) : base(pDC, pDC.AbsenceTimeOid == null) {}
|
2016-06-27 01:45:38 +02:00
|
|
|
|
|
|
|
|
|
|
public DateTime? End
|
|
|
|
|
|
{
|
2019-12-19 14:27:03 +01:00
|
|
|
|
get => _End;
|
2016-06-27 01:45:38 +02:00
|
|
|
|
|
2019-12-19 14:27:03 +01:00
|
|
|
|
set
|
2016-06-27 01:45:38 +02:00
|
|
|
|
{
|
|
|
|
|
|
if (AreDifferent(_End, value))
|
|
|
|
|
|
{
|
|
|
|
|
|
_End = value;
|
|
|
|
|
|
StoreDirtyInformation(AreDifferent(DataContract.End, value), PropertyName_End);
|
|
|
|
|
|
FirePropertyChanged(PropertyName_End);
|
2019-12-19 14:27:03 +01:00
|
|
|
|
FirePropertyChanged(nameof(Start));
|
|
|
|
|
|
FirePropertyChanged(nameof(EndTime));
|
2016-06-27 01:45:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string Notice
|
|
|
|
|
|
{
|
2019-12-19 14:27:03 +01:00
|
|
|
|
get => _Notice;
|
2016-06-27 01:45:38 +02:00
|
|
|
|
|
2019-12-19 14:27:03 +01:00
|
|
|
|
set
|
2016-06-27 01:45:38 +02:00
|
|
|
|
{
|
|
|
|
|
|
if (AreDifferent(_Notice, value))
|
|
|
|
|
|
{
|
|
|
|
|
|
_Notice = value;
|
|
|
|
|
|
StoreDirtyInformation(AreDifferent(DataContract.Notice, value), PropertyName_Notice);
|
|
|
|
|
|
FirePropertyChanged(PropertyName_Notice);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Validation(ValidationRule = ValidationRules.NotNullOrStringEmpty)]
|
|
|
|
|
|
public AbsenceReasonDC Reason
|
|
|
|
|
|
{
|
2019-12-19 14:27:03 +01:00
|
|
|
|
get => _Reason;
|
2016-06-27 01:45:38 +02:00
|
|
|
|
|
2019-12-19 14:27:03 +01:00
|
|
|
|
set
|
2016-06-27 01:45:38 +02:00
|
|
|
|
{
|
|
|
|
|
|
if (AreDifferent(_Reason, value))
|
|
|
|
|
|
{
|
|
|
|
|
|
_Reason = value;
|
|
|
|
|
|
StoreDirtyInformation(!AreEqual(value, DataContract.Reason), PropertyName_Reason);
|
|
|
|
|
|
FirePropertyChanged(PropertyName_Reason);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Validation(ValidationRule = ValidationRules.NotNullOrStringEmpty)]
|
|
|
|
|
|
public DateTime? Start
|
|
|
|
|
|
{
|
2019-12-19 14:27:03 +01:00
|
|
|
|
get => _Start;
|
2016-06-27 01:45:38 +02:00
|
|
|
|
|
2019-12-19 14:27:03 +01:00
|
|
|
|
set
|
2016-06-27 01:45:38 +02:00
|
|
|
|
{
|
|
|
|
|
|
if (AreDifferent(_Start, value))
|
|
|
|
|
|
{
|
|
|
|
|
|
_Start = value;
|
|
|
|
|
|
StoreDirtyInformation(AreDifferent(DataContract.Start, value), PropertyName_Start);
|
|
|
|
|
|
FirePropertyChanged(PropertyName_Start);
|
2019-12-19 14:27:03 +01:00
|
|
|
|
FirePropertyChanged(nameof(End));
|
|
|
|
|
|
FirePropertyChanged(nameof(StartTime));
|
2016-06-27 01:45:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-19 14:27:03 +01:00
|
|
|
|
private bool _IsAllDay;
|
|
|
|
|
|
|
|
|
|
|
|
public bool IsAllDay
|
|
|
|
|
|
{
|
|
|
|
|
|
get => _IsAllDay;
|
|
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
if (AreDifferent(_IsAllDay, value))
|
|
|
|
|
|
{
|
|
|
|
|
|
_IsAllDay = value;
|
|
|
|
|
|
|
|
|
|
|
|
Start = _Start?.MergeDatesByDate(_Start.Value.Date);
|
|
|
|
|
|
End = _End?.MergeDatesByDate(_End.Value.Date);
|
|
|
|
|
|
|
|
|
|
|
|
FirePropertyChanged(nameof(IsAllDay));
|
|
|
|
|
|
FirePropertyChanged(nameof(DateEditColumnSpan));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string StartTime
|
|
|
|
|
|
{
|
2020-11-25 11:40:05 +01:00
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_Start != null && _Start.Value.Hour == 0 && _Start.Value.Minute == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return "";
|
|
|
|
|
|
}
|
|
|
|
|
|
return _Start?.ToString("HH:mm");
|
|
|
|
|
|
}
|
2019-12-19 14:27:03 +01:00
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_Start.HasValue && DateTime.TryParse($"{_Start.Value.ToLongDateString()} {value}", out var newTime))
|
|
|
|
|
|
{
|
|
|
|
|
|
Start = newTime;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-11-25 11:40:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string EndTime
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_End != null && _End.Value.Hour == 0 && _End.Value.Minute == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return "";
|
|
|
|
|
|
}
|
|
|
|
|
|
return _End?.ToString("HH:mm");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
set
|
2019-12-19 14:27:03 +01:00
|
|
|
|
{
|
|
|
|
|
|
if (_End.HasValue && DateTime.TryParse($"{_End.Value.ToLongDateString()} {value}", out var newTime))
|
|
|
|
|
|
{
|
|
|
|
|
|
End = newTime;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-11-25 11:40:05 +01:00
|
|
|
|
}
|
2019-12-19 14:27:03 +01:00
|
|
|
|
|
2021-02-23 09:57:51 +01:00
|
|
|
|
public string BackgroundColor
|
|
|
|
|
|
{
|
|
|
|
|
|
get => _BackgroundColor;
|
|
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
if (AreDifferent(_BackgroundColor, value))
|
|
|
|
|
|
{
|
|
|
|
|
|
_BackgroundColor = value;
|
|
|
|
|
|
StoreDirtyInformation(AreDifferent(DataContract.BackgroundColor, value), _BackgroundColor);
|
|
|
|
|
|
FirePropertyChanged(_BackgroundColor);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Validation(ValidationRule = ValidationRules.NotNullOrStringEmpty)]
|
2017-04-28 14:08:23 +02:00
|
|
|
|
public DateTime? KrankheitsMeldung
|
|
|
|
|
|
{
|
2019-12-19 14:27:03 +01:00
|
|
|
|
get => _KrankheitsMeldung;
|
2017-04-28 14:08:23 +02:00
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
if (AreDifferent(_KrankheitsMeldung, value))
|
|
|
|
|
|
{
|
|
|
|
|
|
_KrankheitsMeldung = value;
|
|
|
|
|
|
StoreDirtyInformation(AreDifferent(DataContract.Start, value), PropertyName_KrankheitsMeldung);
|
|
|
|
|
|
FirePropertyChanged(PropertyName_KrankheitsMeldung);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-19 14:27:03 +01:00
|
|
|
|
public int DateEditColumnSpan => _IsAllDay ? 2 : 1;
|
|
|
|
|
|
|
|
|
|
|
|
protected override void InitByDataContract(AbsenceTimeDC pDataContract)
|
2016-06-27 01:45:38 +02:00
|
|
|
|
{
|
|
|
|
|
|
if (!IsNew)
|
|
|
|
|
|
{
|
|
|
|
|
|
_Start = pDataContract.Start;
|
|
|
|
|
|
_End = pDataContract.End;
|
|
|
|
|
|
_Notice = pDataContract.Notice;
|
|
|
|
|
|
|
|
|
|
|
|
_Reason = pDataContract.Reason;
|
2017-04-28 14:08:23 +02:00
|
|
|
|
_KrankheitsMeldung = pDataContract.KrankheitsMeldung;
|
2019-12-19 14:27:03 +01:00
|
|
|
|
|
|
|
|
|
|
_IsAllDay = _Start.HasValue && _Start.Value.IsTimeZero() && (_End == null || _End.Value.IsTimeZero());
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
_IsAllDay = true;
|
|
|
|
|
|
}
|
2016-06-27 01:45:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override AbsenceTimeDC MapToDataContract(AbsenceTimeDC pDataContract, bool doCommit)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_Reason != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
pDataContract.Reason = _Reason;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-02-07 15:21:36 +01:00
|
|
|
|
pDataContract.Start = _Start;
|
|
|
|
|
|
pDataContract.End = _End;
|
2016-06-27 01:45:38 +02:00
|
|
|
|
pDataContract.Notice = _Notice;
|
|
|
|
|
|
|
2017-04-28 14:08:23 +02:00
|
|
|
|
pDataContract.KrankheitsMeldung = _KrankheitsMeldung;
|
|
|
|
|
|
|
2016-06-27 01:45:38 +02:00
|
|
|
|
return pDataContract;
|
|
|
|
|
|
}
|
2019-12-19 14:27:03 +01:00
|
|
|
|
|
|
|
|
|
|
string IDataErrorInfo.Error
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
var me = (IDataErrorInfo)this;
|
|
|
|
|
|
var error = me[nameof(Start)] +
|
2020-02-07 15:21:36 +01:00
|
|
|
|
me[nameof(End)] +
|
|
|
|
|
|
me[nameof(Reason)];
|
2019-12-19 14:27:03 +01:00
|
|
|
|
|
|
|
|
|
|
return error;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string IDataErrorInfo.this[string columnName]
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
2020-02-07 15:21:36 +01:00
|
|
|
|
if (columnName.Equals(nameof(Start)) && Start == null)
|
2019-12-19 14:27:03 +01:00
|
|
|
|
{
|
2020-02-07 15:21:36 +01:00
|
|
|
|
return "Das Startdatum muss einen Wert haben.\n";
|
2019-12-19 14:27:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-02-07 15:21:36 +01:00
|
|
|
|
if (columnName.Equals(nameof(End)) && End != null && End.Value < Start)
|
2019-12-19 14:27:03 +01:00
|
|
|
|
{
|
2020-02-07 15:21:36 +01:00
|
|
|
|
return "Das Startdatum muss vor dem Enddatum liegen.\n";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (columnName.Equals(nameof(Reason)) && Reason == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return "Die Kategorie darf nicht leer sein.\n";
|
2019-12-19 14:27:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void ValidateDates(Action callback)
|
|
|
|
|
|
{
|
|
|
|
|
|
var error = ((IDataErrorInfo) this).Error;
|
|
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(error))
|
|
|
|
|
|
{
|
2020-02-07 15:21:36 +01:00
|
|
|
|
MessageBox.Show(error, "Ungültige Eingabe", MessageBoxButton.OK, MessageBoxImage.Error);
|
2019-12-19 14:27:03 +01:00
|
|
|
|
FirePropertyChanged(nameof(Start));
|
|
|
|
|
|
FirePropertyChanged(nameof(End));
|
2020-02-07 15:21:36 +01:00
|
|
|
|
FirePropertyChanged(nameof(Reason));
|
2019-12-19 14:27:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
callback();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2016-06-27 01:45:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|