Files
BeWoPlaner/BeWo/ViewModel/ArbeitszeitVM.cs

201 lines
6.1 KiB
C#
Raw Permalink Normal View History

using BS.Shared.DataContracts;
using System;
2017-05-17 08:28:12 +02:00
using System.Collections.Generic;
using BeWo.ViewModel.ListViewModel;
using BS.Shared.DataContracts.Compact;
namespace BeWo.ViewModel
{
public class ArbeitszeitVM : AbstractDCMapperVM<ArbeitszeitDC>
{
public static string PropertyName_GueltigVon = "GueltigVon";
public static string PropertyName_GueltigBis = "GueltigBis";
public static string PropertyName_Notice = "Notice";
2017-05-17 08:28:12 +02:00
public static string PropertyName_ArbeitszeitEintragListeVM = "ArbeitszeitEintragListeVM";
2017-05-17 08:28:12 +02:00
public static string PropertyName_ArbeitszeitString = "ArbeitszeitString";
public static string PropertyName_CompactCustomer = "CompactCustomer";
public static string PropertyName_Klient = "Klient";
2019-09-27 15:55:01 +02:00
private CompactCustomerDC _Customer;
2017-05-17 08:28:12 +02:00
private DateTime? _GueltigVon;
private DateTime? _GueltigBis;
private string _Notice;
2017-05-17 08:28:12 +02:00
private ArbeitszeitEintragListVM _ArbeitszeitEintraege;
2019-09-27 15:55:01 +02:00
public ArbeitszeitVM(ArbeitszeitDC pDC) : base(pDC, pDC.ArbeitszeitOid == null)
2017-05-17 08:28:12 +02:00
{
}
public override bool IsDirty
{
get
{
FirePropertyChanged(nameof(DetailText)); // Hack um die Aktualisierung des Textes zu erzwingen
return base.IsDirty || ArbeitszeitEintraege != null && ArbeitszeitEintraege.IsDirty;
}
}
2019-09-27 15:55:01 +02:00
public CompactCustomerDC Customer
{
2019-09-27 15:55:01 +02:00
get => _Customer;
set
2017-05-17 08:28:12 +02:00
{
2019-09-27 15:55:01 +02:00
if(AreDifferent(_Customer, value))
{
_Customer = value;
StoreDirtyInformation(AreDifferent(DataContract.Customer, value), nameof(Customer));
FirePropertyChanged(nameof(Customer));
}
2017-05-17 08:28:12 +02:00
}
}
2017-05-17 08:28:12 +02:00
public DateTime? GueltigVon
{
2019-09-27 15:55:01 +02:00
get => _GueltigVon;
set
{
2019-09-27 15:55:01 +02:00
if(AreDifferent(_GueltigVon, value))
{
2019-09-27 15:55:01 +02:00
_GueltigVon = value;
StoreDirtyInformation(AreDifferent(DataContract.GueltigVon, value), nameof(GueltigVon));
FirePropertyChanged(nameof(GueltigVon));
FirePropertyChanged(nameof(ArbeitszeitString));
}
}
}
2017-05-17 08:28:12 +02:00
public DateTime? GueltigBis
{
2019-09-27 15:55:01 +02:00
get => _GueltigBis;
set
{
2019-09-27 15:55:01 +02:00
if(AreDifferent(_GueltigBis, value))
{
2019-09-27 15:55:01 +02:00
_GueltigBis = value;
StoreDirtyInformation(AreDifferent(DataContract.GueltigBis, value), nameof(GueltigBis));
FirePropertyChanged(nameof(GueltigBis));
FirePropertyChanged(nameof(ArbeitszeitString));
}
}
}
public string Notice
{
2019-09-27 15:55:01 +02:00
get => _Notice;
set
{
2019-09-27 15:55:01 +02:00
if(AreDifferent(_Notice, value))
{
_Notice = value;
2019-09-27 15:55:01 +02:00
StoreDirtyInformation(AreDifferent(DataContract.Notice, value), nameof(Notice));
FirePropertyChanged(nameof(Notice));
}
}
}
2017-05-17 08:28:12 +02:00
public string ArbeitszeitString
{
get
{
2019-09-27 15:55:01 +02:00
var text = "Zeitraum: ";
if(_GueltigVon.HasValue)
2017-05-17 08:28:12 +02:00
{
2019-09-27 15:55:01 +02:00
text = $"{_GueltigVon:dd.MM.yyyy}";
2017-05-17 08:28:12 +02:00
2019-09-27 15:55:01 +02:00
if(_GueltigBis.HasValue)
2017-05-17 08:28:12 +02:00
{
2019-09-27 15:55:01 +02:00
text += $" - {_GueltigBis:dd.MM.yyyy}";
2017-05-17 08:28:12 +02:00
}
}
else
{
2019-09-27 15:55:01 +02:00
if(_GueltigBis.HasValue)
2017-05-17 08:28:12 +02:00
{
2019-09-27 15:55:01 +02:00
text = $"bis {_GueltigBis:dd.MM.yyyy}";
2017-05-17 08:28:12 +02:00
}
}
2019-09-27 15:55:01 +02:00
if(string.IsNullOrEmpty(text))
2017-05-17 08:28:12 +02:00
{
2018-10-08 11:57:16 +02:00
//if (this.IsNew)
2019-09-27 15:55:01 +02:00
text = "<Neuer Zeitraum>";
2018-10-08 11:57:16 +02:00
//else
// text = "Arbeitszeitplanung";
2017-05-17 08:28:12 +02:00
}
2019-09-27 15:55:01 +02:00
2017-05-17 08:28:12 +02:00
return text;
}
}
public String DetailText
{
get
{
decimal stunden = 0;
foreach (var ae in ArbeitszeitEintraege.VMList)
{
String dateStr1 = String.Format("{0:dd.MM.yyyy} {1}", DateTime.Now, ae.UhrzeitVon);
String dateStr2 = String.Format("{0:dd.MM.yyyy} {1}", DateTime.Now, ae.UhrzeitBis);
DateTime date1;
DateTime date2;
if (DateTime.TryParse(dateStr1, out date1) && DateTime.TryParse(dateStr2, out date2))
{
stunden += (decimal)date2.Subtract(date1).TotalHours;
}
}
return String.Format("Gesamtstunden: {0:0.00}", stunden);
}
}
2017-05-17 08:28:12 +02:00
public ArbeitszeitEintragListVM ArbeitszeitEintraege
{
2019-09-27 15:55:01 +02:00
get => _ArbeitszeitEintraege;
2017-05-17 08:28:12 +02:00
set
{
_ArbeitszeitEintraege = value;
2019-09-27 15:55:01 +02:00
FirePropertyChanged(nameof(ArbeitszeitEintraege));
2017-05-17 08:28:12 +02:00
}
}
2019-09-27 15:55:01 +02:00
protected override void InitByDataContract(ArbeitszeitDC pDataContract)
{
2019-09-27 15:55:01 +02:00
_GueltigBis = pDataContract.GueltigBis;
_GueltigVon = pDataContract.GueltigVon;
_Notice = pDataContract.Notice;
_Customer = pDataContract.Customer;
2017-05-17 08:28:12 +02:00
2019-09-27 15:55:01 +02:00
ArbeitszeitEintraege = VMFactory.CreateArbeitszeitEintragListVm(pDataContract.Eintraege ?? (pDataContract.Eintraege = new List<ArbeitszeitEintragDC>()));
}
protected override ArbeitszeitDC MapToDataContract(ArbeitszeitDC pDataContract, bool doCommit)
{
pDataContract.GueltigVon = _GueltigVon;
pDataContract.GueltigBis = _GueltigBis;
2017-05-17 08:28:12 +02:00
pDataContract.Notice = _Notice;
2019-09-27 15:55:01 +02:00
pDataContract.Customer = _Customer;
2017-05-17 08:28:12 +02:00
2019-09-27 15:55:01 +02:00
pDataContract.Eintraege = ArbeitszeitEintraege.CopyToDCList(doCommit);
return pDataContract;
}
}
}