using BS.Shared; using BS.Shared.DataContracts; using BeWo.Validation; using BS.Shared.DataContracts.Compact; using System; namespace BeWo.ViewModel { public class ArbeitszeitEintragVM : AbstractDCMapperVM { public static string PropertyName_UhrzeitVon = "UhrzeitVon"; public static string PropertyName_UhrzeitBis = "UhrzeitBis"; public static string PropertyName_Tag = "Tag"; public static string PropertyName_Notice = "Notice"; public static string PropertyName_Klient = "Klient"; public static string PropertyName_CompactCustomer = "CompactCustomer"; public static string PropertyName_CompactEmployee = "Employee"; private string _UhrzeitVon; private string _UhrzeitBis; private AppointmentDayOfWeek _Tag; private string _Notice; private CompactCustomerDC _CompactCustomer; private CompactEmployeeDC _CompactEmployee; public ArbeitszeitEintragVM(ArbeitszeitEintragDC pDC) : base(pDC, pDC.ArbeitszeitEintragOid == null) { } [Validation(ValidationRule = ValidationRules.NotNullOrStringEmpty)] public string UhrzeitVon { get => _UhrzeitVon; set { if(AreDifferent(_UhrzeitVon, value)) { _UhrzeitVon = value; StoreDirtyInformation(AreDifferent(DataContract.UhrzeitVon, value), PropertyName_UhrzeitVon); FirePropertyChanged(PropertyName_UhrzeitVon); FirePropertyChanged("Infos"); } } } [Validation(ValidationRule = ValidationRules.NotNullOrStringEmpty)] public string UhrzeitBis { get => _UhrzeitBis; set { if(AreDifferent(_UhrzeitBis, value)) { _UhrzeitBis = value; StoreDirtyInformation(AreDifferent(DataContract.UhrzeitBis, value), PropertyName_UhrzeitBis); FirePropertyChanged("Infos"); } } } public AppointmentDayOfWeek Tag { get => _Tag; set { if(AreDifferent(_Tag, value)) { _Tag = value; StoreDirtyInformation(AreDifferent(DataContract.Tag, value), PropertyName_Tag); FirePropertyChanged(PropertyName_Tag); } } } public string Notice { get => _Notice; set { if (AreDifferent(_Notice, value)) { _Notice = value; StoreDirtyInformation(AreDifferent(DataContract.Notice, value), PropertyName_Notice); FirePropertyChanged(PropertyName_Notice); } } } public string Infos { get { if (!string.IsNullOrEmpty(UhrzeitVon) && !string.IsNullOrEmpty(UhrzeitVon)) { String dateStr1 = String.Format("{0:dd.MM.yyyy} {1}", DateTime.Now, UhrzeitVon); String dateStr2 = String.Format("{0:dd.MM.yyyy} {1}", DateTime.Now, UhrzeitBis); DateTime date1; DateTime date2; if (DateTime.TryParse(dateStr1, out date1) && DateTime.TryParse(dateStr2, out date2)) { return String.Format("Gesamtstunden: {0:0.00}", date2.Subtract(date1).TotalHours); } } return ""; } } public string Klient => _CompactCustomer?.FullName; public CompactCustomerDC CompactCustomer { get => _CompactCustomer; set { if (AreDifferent(_CompactCustomer, value)) { _CompactCustomer = value; StoreDirtyInformation(AreDifferent(DataContract.CustomerOid, value.CustomerOid), PropertyName_CompactCustomer); FirePropertyChanged(nameof(CompactCustomer)); FirePropertyChanged(nameof(Klient)); } } } public CompactEmployeeDC Employee { get => _CompactEmployee; set { if (AreDifferent(_CompactEmployee, value)) { _CompactEmployee = value; StoreDirtyInformation(AreDifferent(DataContract.Employee, value), PropertyName_CompactEmployee); FirePropertyChanged(PropertyName_CompactEmployee); } } } protected override void InitByDataContract(ArbeitszeitEintragDC pDataContract) { _Tag = pDataContract.Tag; _UhrzeitVon = pDataContract.UhrzeitVon; _UhrzeitBis = pDataContract.UhrzeitBis; _Notice = pDataContract.Notice; _CompactEmployee = pDataContract.Employee; _CompactCustomer = pDataContract.Customer; } protected override ArbeitszeitEintragDC MapToDataContract(ArbeitszeitEintragDC pDataContract, bool doCommit) { pDataContract.UhrzeitVon = _UhrzeitVon; pDataContract.UhrzeitBis = _UhrzeitBis; pDataContract.Tag = _Tag; pDataContract.Notice = _Notice; pDataContract.Employee = _CompactEmployee; pDataContract.Customer = _CompactCustomer; if(_CompactCustomer != null) { pDataContract.CustomerOid = _CompactCustomer.CustomerOid; } return pDataContract; } } }