using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Windows; using System.Windows.Media; using System.Windows.Media.Imaging; using BeWo.Core; using BeWo.Core.Service; using BeWo.Validation; using BS.Shared; using BS.Shared.Core; using BS.Shared.DataContracts; using BS.Shared.DataContracts.ClientPartials; using BS.Shared.DataContracts.Compact; using BS.Shared.Extensions; using Brush = System.Windows.Media.Brush; using Brushes = System.Windows.Media.Brushes; using Color = System.Windows.Media.Color; namespace BeWo.ViewModel { // Claude: ICustomerRelatedContext -> steuert die Dokumentationspflicht beim Bearbeiten public class ServiceRecordVM : AbstractDCMapperVM, ICustomerRelatedContext { public String ATEST { get; set; } #region Constants and Fields public static string PropertyName_Category = "Category"; public static string PropertyName_Category2Services = "Category2Services"; public static string PropertyName_SortedCategories = "SortedCategories"; public static string PropertyName_CostBearer = "CostBearer"; public static string PropertyName_Customer = "Customer"; public static string PropertyName_Duration = "Duration"; public static string PropertyName_Employee = "Employee"; public static string PropertyName_GoalTree = "GoalTree"; public static string PropertyName_GroupEmployeeCount = "GroupEmployeeCount"; public static string PropertyName_GroupPersonCount = "GroupPersonCount"; public static string PropertyName_GroupRoundedDuration = "GroupRoundedDuration"; public static string PropertyName_IsGoalTreeVisible = "IsGoalTreeVisible"; public static string PropertyName_Notice = "Notice"; public static string PropertyName_Notice2 = "Notice2"; public static string PropertyName_Notice3 = "Notice3"; public static string PropertyName_Notice4 = "Notice4"; public static string PropertyName_Notice5 = "Notice5"; public static string PropertyName_RTFNotice = "RTFNotice"; public static string PropertyName_RTFNotice2 = "RTFNotice2"; public static string PropertyName_RTFNotice3 = "RTFNotice3"; public static string PropertyName_RTFNotice4 = "RTFNotice4"; public static string PropertyName_RTFNotice5 = "RTFNotice5"; public static string PropertyName_PossibleCostBearers = "PossibleCostBearers"; public static string PropertyName_PossibleCustomers = "PossibleCustomers"; public static string PropertyName_PossibleServiceDescriptions = "PossibleServiceDescriptions"; public static string PropertyName_PossibleSupportConcepts = "PossibleSupportConcepts"; public static string PropertyName_RoundedDuration = "RoundedDuration"; public static string PropertyName_SelectedGoals = "SelectedGoals"; public static string PropertyName_ServiceDescription = "ServiceDescription"; public static string PropertyName_SupportConcept = "SupportConcept"; public static string PropertyName_ServiceRecordType = "ServiceRecordType"; public static string PropertyName_IsServiceRecordTypeDefaultActivity = "IsServiceRecordTypeDefaultActivity"; public static string PropertyName_IsServiceRecordTypeContent = "IsServiceRecordTypeContent"; public static string PropertyName_DistanceInMeter = "DistanceInMeter"; public static string PropertyName_DauerEinheit = "DauerEinheit"; public static string PropertyName_ServiceRecordFormat = "ServiceRecordFormat"; public static string PropertyName_OnlyMonth = "OnlyMonth"; public static string PropertyName_OnlyYear = "OnlyYear"; public static string PropertyName_DurationMonthYearGes = "DurationMonthYearGes"; public static string PropertyName_Betrag = "Betrag"; public static string PropertyName_EditStartDate = "EditStartDate"; public static string PropertyName_EditEndDate = "EditEndDate"; public static string PropertyName_StartTimeString = "StartTimeString"; public static string PropertyName_EndTimeString = "EndTimeString"; private static readonly DateTime NULL_TIME = new DateTime(2000, 1, 1, 0, 0, 1); private static BitmapImage haekchenBitmapImage = null; private Dictionary> _Category2Services; //private readonly List _Tree; private List _AllGoalCategories; private List _AllGoals; private ServiceCategoryDC _Category; private FlatSupportConceptTreeNodeDC _ChoosenNode; private CompactOrganisationDC _CostBearer; private CompactCustomerDC _Customer; private bool _DeleteAllowed = true; private decimal _Duration; private bool _EditAllowed = true; private CompactEmployeeDC _Employee; private List _GoalTree; private int? _GroupEmployeeCount; private long? _GroupOid; private long? _SignatureOid; private int? _GroupPersonCount; private decimal? _GroupRoundedDuration; private string _InsUser; private DateTime? _InsertedOn; private string _Notice; private string _Notice2; private string _Notice3; private string _Notice4; private string _Notice5; private string _RTFNotice; private string _RTFNotice2; private string _RTFNotice3; private string _RTFNotice4; private string _RTFNotice5; private decimal? _Betrag; private decimal _RoundedDuration; private ObservableSortCollection _SelectedGoals; private ServiceDescriptionDC _ServiceDescription; private CompactSupportConceptDC _SupportConcept; private ServiceRecordTypeId _ServiceRecordType = ServiceRecordTypeId.DefaultActivity; public List _ServiceAccountings; private decimal? _DistanceInMeter; private ZeiterfassungsDauer _DauerEinheit = ZeiterfassungsDauer.Minuten; private ServiceRecordFormate _ServiceRecordFormat; private string _OnlyMonth; private string _OnlyYear; private decimal? _DurationMonthYearGes; private DateTime? _StartDate; private DateTime? _EndDate; private DateTime? _EditStartDate; private DateTime? _EditEndDate; private string _StartTimeString; private string _EndTimeString; private List _Statistics; private string[] _MonateBinden = { "Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember" }; #endregion #region Constructors and Destructors public ServiceRecordVM() { DataContract = new ServiceRecordDC { Notice = "" }; _Duration = 0; } public ServiceRecordVM( ServiceRecordDC pDC, Dictionary> pCategory2Services, List pAllGoalCategories, List pAllGoals) : base(pDC, pDC.ServiceRecordOid == null) { EditAlwaysAllowed = false; _Category2Services = pCategory2Services; ChangeGoalTree(pAllGoalCategories, pAllGoals); } #endregion #region Properties public override bool IsDirty { get { return base.IsDirty || !SameRatingChecked(SelectedGoals, this.DataContract.Goals); } } public decimal? DistanceInMeter { get { return _DistanceInMeter; } set { if (AreDifferent(_DistanceInMeter, value)) { _DistanceInMeter = value; StoreDirtyInformation(AreDifferent(DataContract.DistanceInMeterDecimal, value), PropertyName_DistanceInMeter); FirePropertyChanged(PropertyName_DistanceInMeter); } } } public decimal AssistanceDuration { get { if (GroupOid != null) { return RoundedDuration; } //if (_Duration != null) //{ return Duration; //} //return 0; } } //ALT Das kann irgendwann weg public Brush BackgroundBrush { get { Brush brush = null; //if (_GroupOid != null) //{ // brush = Application.Current.FindResource("GroupBookingBackgroundBrush") as Brush; //} if (!String.IsNullOrEmpty(BackgroundColor)) { return new SolidColorBrush((Color)System.Windows.Media.ColorConverter.ConvertFromString(BackgroundColor)); } return brush ?? Brushes.White; } } public String BackgroundColor { get; set; } public String CategoryString { get { return _Category != null ? _Category.ToString() : null; } } public String ServiceDescriptionString { get { return _ServiceDescription != null ? _ServiceDescription.ToString() : null; } } public List AllGoalCategories { get { return _AllGoalCategories; } set { _AllGoalCategories = value; } } public List AllGoals { get { return _AllGoals; } set { _AllGoals = value; } } public ServiceCategoryDC Category { get { return _Category; } set { if (AreDifferent(_Category, value)) { _Category = value; ServiceDescription = null; FirePropertyChanged(PropertyName_Category); FirePropertyChanged(PropertyName_PossibleServiceDescriptions); } } } public Dictionary> Category2Services { get { return _Category2Services; } set { _Category2Services = value; FirePropertyChanged(PropertyName_Category2Services); FirePropertyChanged(PropertyName_SortedCategories); FirePropertyChanged(PropertyName_PossibleServiceDescriptions); } } public IList SortedCategories { get { return Category2Services != null ? Category2Services.Keys.OrderBy(cat => cat.Position).ToList() : null; } } public FlatSupportConceptTreeNodeDC ChoosenNode { get { return _ChoosenNode; } set { _ChoosenNode = value; if (value != null) { if (value.SupportConceptTreeNodeDC != null) { if (Employee == null) { Employee = value.SupportConceptTreeNodeDC.Employee; } Customer = value.SupportConceptTreeNodeDC.Customer; SupportConcept = value.SupportConceptTreeNodeDC.SupportConcept; CostBearer = value.SupportConceptTreeNodeDC.CostBearer; } } else { Employee = null; Customer = null; SupportConcept = null; CostBearer = null; } } } public CompactOrganisationDC CostBearer { get { return _CostBearer; } set { if (AreDifferent(_CostBearer, value)) { _CostBearer = value; StoreDirtyInformation(!AreEqual(DataContract.CostBearer, value), PropertyName_CostBearer); FirePropertyChanged(PropertyName_CostBearer); FirePropertyChanged(PropertyName_RoundedDuration); } } } [Validation(ValidationRule = ValidationRules.NotNullOrStringEmpty)] public CompactCustomerDC Customer { get { return _Customer; } set { if (AreDifferent(_Customer, value)) { _Customer = value; StoreDirtyInformation(!AreEqual(DataContract.Customer, value), PropertyName_Customer); FirePropertyChanged(PropertyName_Customer); } } } public DateTime StartDate { get { var date = _EditStartDate ?? DateTime.Now.Date; if (!String.IsNullOrEmpty(_StartTimeString)) { String dtStr = String.Format("{0:dd.MM.yyyy} {1}", date, _StartTimeString); DateTime dt; if (DateTime.TryParse(dtStr, out dt)) _StartDate = dt; else _StartDate = date.Date.AddSeconds(1); } else { _StartDate = date.Date.AddSeconds(1); } return _StartDate.Value; } } public DateTime EndDate { get { var date = _EditEndDate ?? DateTime.Now.Date; if (!String.IsNullOrEmpty(_EndTimeString)) { String dtStr = String.Format("{0:dd.MM.yyyy} {1}", date, _EndTimeString); DateTime dt; if (DateTime.TryParse(dtStr, out dt)) _EndDate = dt; else _EndDate = date.Date.Date.AddSeconds(1); } else { if (date.Second == 0) { date = date.AddSeconds(1); } _EndDate = date; } return _EndDate.Value; } } public DateTime RoundedEndDate { get { var date = StartDate; if (this.GroupRoundedDuration.HasValue) { return date.AddMinutes((double)GroupRoundedDuration); } return date.AddMinutes((double)RoundedDuration); } } public DateTime? StartMinutes { get { if (StartDate.Second == 0) { return StartDate; } return null; } } public DateTime? RoundedEndMinutes { get { if (RoundedEndDate.Second == 0) { return RoundedEndDate; } return null; } } public DateTime? EditStartDate { get { return _EditStartDate; } set { if (AreDifferent(_EditStartDate, value)) { _EditStartDate = value; if (_EditStartDate.HasValue) { var newEnddate = _EditStartDate.Value.Date; if (BeWoApp.AppSettings.IsEndDateVisible || ServiceRecordFormat == ServiceRecordFormate.ZeiterfassungMitEndDatum) { if (!EditEndDate.HasValue || value.Value.Date > EditEndDate.Value.Date) { _EditEndDate = new DateTime(value.Value.Year, value.Value.Month, value.Value.Day, newEnddate.Hour, newEnddate.Minute, newEnddate.Second); FirePropertyChanged(PropertyName_EditEndDate); } } else { _EditEndDate = _EditStartDate; if (Duration > 0) { if (DauerEinheit == ZeiterfassungsDauer.Minuten) _EditEndDate = _EditStartDate.Value.Date.AddMinutes((double)Duration); else _EditEndDate = _EditStartDate.Value.Date.AddHours((double)Duration); } if (String.IsNullOrEmpty(_EndTimeString) && _EditEndDate.Value.Second == 0) { _EditEndDate = _EditEndDate.Value.AddSeconds(1); } FirePropertyChanged(PropertyName_EditEndDate); } } StoreDirtyInformation(!AreEqual(DataContract.Start, EditStartDate), PropertyName_EditStartDate); FirePropertyChanged(PropertyName_EditStartDate); UpdateDurationAfterDateChange(); } } } public DateTime? EditEndDate { get { return _EditEndDate; } set { if (AreDifferent(_EditEndDate, value)) { _EditEndDate = value; if (BeWoApp.AppSettings.IsEndDateVisible || ServiceRecordFormat == ServiceRecordFormate.ZeiterfassungMitEndDatum) { if (_EditEndDate.HasValue) { var newStartdate = _EditEndDate.Value.Date; if (EditStartDate.HasValue) { newStartdate = EditStartDate.Value; } if (!EditStartDate.HasValue || value.Value.Date < EditStartDate.Value.Date) { _EditStartDate = new DateTime(value.Value.Year, value.Value.Month, value.Value.Day, newStartdate.Hour, newStartdate.Minute, newStartdate.Second); FirePropertyChanged(PropertyName_EditStartDate); } } } StoreDirtyInformation(!AreEqual(DataContract.End, EditEndDate), PropertyName_EditEndDate); FirePropertyChanged(PropertyName_EditEndDate); UpdateDurationAfterDateChange(); } } } public String StartTimeString { get { return _StartTimeString; } set { String newTime = value; //if (!String.IsNullOrEmpty(newTime) && String.IsNullOrEmpty(EndTimeString)) //{ // _StartTimeString = newTime; // FirePropertyChanged(PropertyName_StartTimeString); // return; //} if (!String.IsNullOrEmpty(newTime)) { var dtStr = String.Format("{0:dd.MM.yyyy} {1}", DateTime.Now.Date, newTime); DateTime dt; if (DateTime.TryParse(dtStr, out dt)) { newTime = String.Format("{0:HH:mm}", dt); } } if (AreDifferent(_StartTimeString, newTime)) { _StartTimeString = newTime; StoreDirtyInformation(!AreEqual(String.Format("{0:HH:mm}", DataContract.Start), value), PropertyName_StartTimeString); FirePropertyChanged(PropertyName_StartTimeString); CheckEndDateAfterStartDateChange(); UpdateDurationAfterDateChange(); } } } private void CheckEndDateAfterStartDateChange() { if (!String.IsNullOrEmpty(StartTimeString) && String.IsNullOrEmpty(EndTimeString)) { var endTimeString = StartTimeString; if (Duration > 0) { UpdateEndTimeStringAfterDurationChange(); //var dtStr = String.Format("{0:dd.MM.yyyy} {1}", DateTime.Now.Date, endTimeString); //DateTime dt; //if (DateTime.TryParse(dtStr, out dt)) //{ // endTimeString = String.Format("{0:HH:mm}", dt); //} } else { EndTimeString = endTimeString; } } else if (!String.IsNullOrEmpty(StartTimeString) && !String.IsNullOrEmpty(EndTimeString)) { if (StartDate > EndDate) { EndTimeString = StartTimeString; EditEndDate = EditStartDate; } } else if (String.IsNullOrEmpty(StartTimeString) && !String.IsNullOrEmpty(EndTimeString)) { _EndTimeString = ""; if (DauerEinheit == ZeiterfassungsDauer.Minuten) EditEndDate = StartDate.Date.AddMinutes((double) Duration).AddSeconds(1); else EditEndDate = StartDate.Date.AddHours((double) Duration).AddSeconds(1); FirePropertyChanged(PropertyName_EndTimeString); } else if (String.IsNullOrEmpty(StartTimeString) && String.IsNullOrEmpty(EndTimeString)) { if (DauerEinheit == ZeiterfassungsDauer.Minuten) EditEndDate = StartDate.Date.AddMinutes((double)Duration).AddSeconds(1); else EditEndDate = StartDate.Date.AddHours((double)Duration).AddSeconds(1); } } public String EndTimeString { get { return _EndTimeString; } set { String newTime = value; if (String.IsNullOrEmpty(newTime) && !String.IsNullOrEmpty(StartTimeString)) { _EndTimeString = newTime; FirePropertyChanged(PropertyName_EndTimeString); return; } if (!String.IsNullOrEmpty(newTime)) { var dtStr = String.Format("{0:dd.MM.yyyy} {1}", DateTime.Now.Date, newTime); DateTime dt; if (DateTime.TryParse(dtStr, out dt)) { newTime = String.Format("{0:HH:mm}", dt); } } if (AreDifferent(_EndTimeString, newTime)) { _EndTimeString = newTime; StoreDirtyInformation(!AreEqual(String.Format("{0:HH:mm}", DataContract.End), value), PropertyName_EndTimeString); FirePropertyChanged(PropertyName_EndTimeString); CheckStartDateAfterEndDateChange(); UpdateDurationAfterDateChange(); UpdateEndDateWithDuration(); } } } private void CheckStartDateAfterEndDateChange() { if (!String.IsNullOrEmpty(EndTimeString) && String.IsNullOrEmpty(StartTimeString)) { StartTimeString = EndTimeString; } else if (!String.IsNullOrEmpty(StartTimeString) && !String.IsNullOrEmpty(EndTimeString)) { if (StartDate > EndDate) { StartTimeString = EndTimeString; EditEndDate = EditStartDate; } } else if (!String.IsNullOrEmpty(StartTimeString) && String.IsNullOrEmpty(EndTimeString)) { //_StartTimeString = ""; UpdateEndDateWithDuration(); FirePropertyChanged(PropertyName_StartTimeString); } } private void UpdateEndDateWithDuration() { DateTime newEndDate = DateTime.MinValue; if (Duration > 0) { if (String.IsNullOrEmpty(StartTimeString)) { newEndDate = StartDate.Date; } else { newEndDate = StartDate; } if (DauerEinheit == ZeiterfassungsDauer.Minuten) newEndDate = newEndDate.AddMinutes((double)Duration); else newEndDate = newEndDate.AddHours((double)Duration); if (String.IsNullOrEmpty(_EndTimeString) && newEndDate.Second == 0) { newEndDate = newEndDate.AddSeconds(1); } EditEndDate = newEndDate; } else { EditEndDate = EditStartDate; } } private void UpdateDurationAfterDateChange() { var x = EndDate.Subtract(StartDate); decimal newDuration = 0; if (DauerEinheit == ZeiterfassungsDauer.Minuten) { newDuration = (decimal) x.TotalMinutes; } else { newDuration = (decimal) x.TotalHours; } if (_Duration != newDuration) { _Duration = newDuration; FirePropertyChanged(PropertyName_Duration); } } private void UpdateEndTimeStringAfterDurationChange() { var date = StartDate; if (DauerEinheit == ZeiterfassungsDauer.Minuten) _EditEndDate = date.AddMinutes((double)_Duration); else _EditEndDate = date.AddHours((double)_Duration); FirePropertyChanged(PropertyName_EditEndDate); if (!String.IsNullOrEmpty(EndTimeString) || StartDate.Second == 0) { _EndTimeString = String.Format("{0:HH:mm}", _EditEndDate); FirePropertyChanged(PropertyName_EndTimeString); } } public String Id { get { return String.Format("{0}", DataContract.ServiceRecordOid); } } [Validation(ValidationRule = ValidationRules.GreaterThanOrEqualZero)] public decimal Duration { get { return _Duration; } set { if (AreDifferent(_Duration, value)) { _Duration = value; UpdateEndTimeStringAfterDurationChange(); StoreDirtyInformation(!AreEqual(String.Format("{0:HH:mm}", DataContract.End), EndTimeString), PropertyName_EndTimeString); FirePropertyChanged(PropertyName_Duration); FirePropertyChanged(PropertyName_RoundedDuration); } } } public string DurationAndRoundedDuration { get { var rd = BeWoWpfUtils.GetDecimalValueWithMaxDecimal(RoundedDuration, 2); if (Category != null && Category.Percentage > 0 && Category.Percentage < 100) { rd = rd * Category.Percentage / 100; } //if(_ServiceRecordFormat == ServiceRecordFormate.ZeiterfassungMitEndDatum) { // var strResult = _GroupOid != null ? string.Format("{0} ({0})", rd) : $"{DurationSTD} ({rd})"; // return strResult; //} if (_ServiceRecordFormat == ServiceRecordFormate.ZeiterfassungMitMonatJahr) { var strResult = _GroupOid != null ? string.Format("{0:0.##} ({0:0.##})", rd) : $"{DurationMonthYearGes} ({rd})"; return strResult; } if (DauerEinheit == ZeiterfassungsDauer.Stunden) { return _GroupOid != null ? string.Format("{0:0.##} ({0:0.##})", rd / 60) : $"{Duration:0.##} ({rd / 60:0.##})"; } return _GroupOid != null ? $"{rd} ({rd})" : $"{Duration} ({rd})"; } } public bool EditAlwaysAllowed { get; set; } public bool EditAllowed { get { if (EditAlwaysAllowed) { return true; } var allowed = false; if (BeWoApp.LoggedOnUser.HasRight(UserRightType.ServiceRecordView_Edit)) { allowed = true; } else if (BeWoApp.LoggedOnUser.HasRight(UserRightType.ServiceRecord_AllowChangeWithin24Hours)) { if (_InsertedOn != null) { if (DateTime.Now < _InsertedOn.Value.AddHours(BeWoApp.AppSettings.ServiceRecordAllowChangeHours)) { allowed = true; } } } if (allowed && BeWoApp.AppSettings.MaxDaysEditServiceRecordsAllowed > 0) { if (!BeWoApp.LoggedOnUser.HasRight(UserRightType.ServiceRecord_AllowEditAfterMaxDaysInNextMonth)) { var dt = new DateTime(StartDate.Year, StartDate.Month, 1); dt = dt.AddMonths(1); dt = dt.AddDays(BeWoApp.AppSettings.MaxDaysEditServiceRecordsAllowed); if (DateTime.Now >= dt) { allowed = false; } } } if (allowed && !BeWoApp.LoggedOnUser.HasRight(UserRightType.ServiceRecord_AllowEditForOtherEmployees)) { if (BeWoApp.LoggedOnEmployee.EmployeeOid != Employee.EmployeeOid) allowed = false; } if (allowed && GroupOid.HasValue) { if (!BeWoApp.LoggedOnUser.HasRight(UserRightType.ServiceRecord_AllowCreatingGroupBooking)) { allowed = false; } } if (allowed && BeWoApp.AppSettings.AnzTageZeiterfassErfolgt > 0 && this.SupportConcept != null) { if (!BeWoApp.LoggedOnUser.HasRight(UserRightType.ServiceRecordAllowEditAfterMindays)) { var dt = new DateTime(StartDate.Year, StartDate.Month, StartDate.Day); dt = dt.AddDays(BeWoApp.AppSettings.AnzTageZeiterfassErfolgt + 1); if (DateTime.Now >= dt) { allowed = false; } } } return _EditAllowed && allowed; } set { _EditAllowed = value; } } public bool DeleteAllowed { get { var allowed = false; if (BeWoApp.LoggedOnUser.HasRight(UserRightType.ServiceRecordView_Delete)) { allowed = true; } else if (BeWoApp.LoggedOnUser.HasRight(UserRightType.ServiceRecord_AllowChangeWithin24Hours)) { if (_InsertedOn != null) { if (DateTime.Now < _InsertedOn.Value.AddHours(BeWoApp.AppSettings.ServiceRecordAllowChangeHours)) { allowed = true; } } } if (allowed && BeWoApp.AppSettings.MaxDaysEditServiceRecordsAllowed > 0) { if (!BeWoApp.LoggedOnUser.HasRight(UserRightType.ServiceRecord_AllowEditAfterMaxDaysInNextMonth)) { if (StartDate != null) { var dt = new DateTime(StartDate.Year, StartDate.Month, 1); dt = dt.AddMonths(1); dt = dt.AddDays(BeWoApp.AppSettings.MaxDaysEditServiceRecordsAllowed); if (DateTime.Now >= dt) { allowed = false; } } } } if (allowed && BeWoApp.AppSettings.AnzTageZeiterfassErfolgt > 0) { if (!BeWoApp.LoggedOnUser.HasRight(UserRightType.ServiceRecordAllowEditAfterMindays)) { if (StartDate != null) { var dt = new DateTime(StartDate.Year, StartDate.Month, StartDate.Day); dt = dt.AddDays(BeWoApp.AppSettings.AnzTageZeiterfassErfolgt + 1); if (DateTime.Now >= dt) { allowed = false; } } } } if (allowed && !BeWoApp.LoggedOnUser.HasRight(UserRightType.ServiceRecord_AllowEditForOtherEmployees)) { if (BeWoApp.LoggedOnEmployee.EmployeeOid != Employee.EmployeeOid) allowed = false; } if (allowed && GroupOid.HasValue) { if (!BeWoApp.LoggedOnUser.HasRight(UserRightType.ServiceRecord_AllowCreatingGroupBooking)) { allowed = false; } } return _DeleteAllowed && allowed; } set { _DeleteAllowed = value; } } public static bool IsHistoryAllowed { get { return BeWoApp.LoggedOnUser.HasRight(UserRightType.ServiceRecord_ShowHistory); } } [Validation(ValidationRule = ValidationRules.NotNullOrStringEmpty)] public CompactEmployeeDC Employee { get { return _Employee; } set { if (AreDifferent(_Employee, value)) { _Employee = value; StoreDirtyInformation(!AreEqual(DataContract.Employee, value), PropertyName_Employee); FirePropertyChanged(PropertyName_Employee); } } } public string EmployeeName { get { if (_Employee != null) { return _Employee.FirstName + " " + _Employee.LastName; } return string.Empty; } } public List GoalTree { get { return _GoalTree; } set { _GoalTree = value; FirePropertyChanged(PropertyName_GoalTree); FirePropertyChanged(PropertyName_IsGoalTreeVisible); } } public int? GroupEmployeeCount { get { return _GroupEmployeeCount; } set { if (AreDifferent(_GroupEmployeeCount, value)) { _GroupEmployeeCount = value; StoreDirtyInformation(AreDifferent(DataContract.GroupEmployeeCount, value), PropertyName_GroupEmployeeCount); FirePropertyChanged(PropertyName_GroupEmployeeCount); } } } public long? GroupOid { get { return _GroupOid; } set { _GroupOid = value; } } public long? SignatureOid { get { return _SignatureOid; } set { _SignatureOid = value; } } public ImageSource HatUnterschriftImage { get { if(_SignatureOid != null) { if (haekchenBitmapImage == null) { haekchenBitmapImage = CreateImage("pack://application:,,,/BeWoPlaner;component/Ressources/Icons/Haeckchen.png"); } return haekchenBitmapImage; } else { return null; } } } private BitmapImage CreateImage(String path) { BitmapImage bix = new BitmapImage(); bix.BeginInit(); bix.CreateOptions = BitmapCreateOptions.PreservePixelFormat; bix.CacheOption = BitmapCacheOption.OnLoad; bix.UriSource = new Uri(path); bix.EndInit(); return bix; } public int? GroupPersonCount { get { return _GroupPersonCount; } set { if (AreDifferent(_GroupPersonCount, value)) { _GroupPersonCount = value; StoreDirtyInformation(AreDifferent(DataContract.GroupPersonCount, value), PropertyName_GroupPersonCount); FirePropertyChanged(PropertyName_GroupPersonCount); } } } public decimal? GroupRoundedDuration { get { return _GroupRoundedDuration; } set { if (AreDifferent(_GroupRoundedDuration, value)) { _GroupRoundedDuration = value; StoreDirtyInformation(AreDifferent(DataContract.GroupRoundedDuration, value), PropertyName_GroupRoundedDuration); FirePropertyChanged(PropertyName_GroupRoundedDuration); } } } public int Index { get; set; } public string InsUser { get { return _InsUser; } set { _InsUser = value; } } public string InsertedOn { get { if (_InsertedOn != null) { return _InsertedOn.Value.ToShortDateString() + " " + _InsertedOn.Value.ToShortTimeString(); } return null; } } public DateTime? InsertedOnDateTime { get { return _InsertedOn; } } public bool IsGoalTreeVisible { get { return _GoalTree != null && _GoalTree.Count > 0; } } public string LongDateString { get { var date = string.Empty; string time = string.Empty; string endtime = string.Empty; var timeDt = StartDate; if (timeDt.Second == 0) { time = timeDt.ToShortTimeString(); if (DauerEinheit == ZeiterfassungsDauer.Stunden) { if (GroupOid != null && GroupRoundedDuration != null) { timeDt = timeDt.AddMinutes((double)GroupRoundedDuration); } else { timeDt = timeDt.AddMinutes((double)RoundedDuration); } } else { if (GroupOid != null && GroupRoundedDuration != null) { timeDt = timeDt.AddMinutes((double)GroupRoundedDuration); } else { timeDt = timeDt.AddMinutes((double)RoundedDuration); } } endtime = timeDt.ToShortTimeString(); //time = time + " - " + timeDt.ToShortTimeString(); } if (endtime.Equals("") && time.Equals("")) { date = DateTimeFormatInfo.CurrentInfo.GetAbbreviatedDayName(StartDate.DayOfWeek) + ", " + StartDate.ToShortDateString(); } else { if (EndDate.Date != StartDate.Date) { time = StartDate.TimeOfDay.ToString(); endtime = EndDate.TimeOfDay.ToString(); date = DateTimeFormatInfo.CurrentInfo.GetAbbreviatedDayName(StartDate.DayOfWeek) + ", " + StartDate.ToShortDateString() + " " + time + " - " + EndDate.ToShortDateString() + " " + endtime; } else { time = time + " - " + endtime; date = DateTimeFormatInfo.CurrentInfo.GetAbbreviatedDayName(StartDate.DayOfWeek) + ", " + StartDate.ToShortDateString() + " " + time; } } //date += " " + time; if (GroupOid != null && GroupPersonCount != null && GroupRoundedDuration != null) { if (DauerEinheit == ZeiterfassungsDauer.Stunden) { date += " Gruppe (" + GroupPersonCount.Value + " Teilnehmer, " + GroupEmployeeCount.Value + " Betreuer). Dauer: " + BeWoWpfUtils.GetDecimalValueWithMaxDecimal(GroupRoundedDuration.Value / 60, 2) + " Stunden."; } else { date += " Gruppe (" + GroupPersonCount.Value + " Teilnehmer, " + GroupEmployeeCount.Value + " Betreuer). Dauer: " + BeWoWpfUtils.GetDecimalValueWithMaxDecimal(GroupRoundedDuration.Value, 2) + " Minuten."; } } return date; } } public Brush MouseOverBackgroundBrush { get { Brush brush = null; if (_GroupOid != null) { brush = Application.Current.FindResource("GroupBookingMouseOverBackgroundBrush") as Brush; } return brush ?? new SolidColorBrush(Color.FromArgb(0xFF, 0xCC, 0xE0, 0xFF)); } } // Claude: Klientenbezug fuer die Dokumentationspflicht beim Bearbeiten eines bestehenden // Eintrags (ServiceRecordEditView / ServiceRecordGroupEditView binden direkt an dieses VM). // Beim Laden aus dem DataContract ist Customer gesetzt, wenn der Eintrag zu einem // Klienten gehoert - kundenlose Eintraege haben Customer == null. // Achtung: Am PrototypeVM der Neuerfassung ist Customer immer null; dort liefert // ServiceRecordListVM.IsCustomerRelated den Kontext (DataItem hat im AttributeValidator // Vorrang), weil der Kunde erst nach der Validierung an den Klon geschrieben wird. public bool IsCustomerRelated { get { return Customer != null; } } [Validation(ValidationRule = ValidationRules.EmptyNoticeInNewServiceRecordsAllowed)] public string Notice { get { return _Notice; } set { if (AreDifferent(_Notice, value)) { _Notice = value; StoreDirtyInformation(AreDifferent(DataContract.Notice, value), PropertyName_Notice); FirePropertyChanged(PropertyName_Notice); } } } public string Notice2 { get { return _Notice2; } set { if (AreDifferent(_Notice2, value)) { _Notice2 = value; StoreDirtyInformation(AreDifferent(DataContract.Notice2, value), PropertyName_Notice2); FirePropertyChanged(PropertyName_Notice2); } } } public string Notice3 { get { return _Notice3; } set { if (AreDifferent(_Notice3, value)) { _Notice3 = value; StoreDirtyInformation(AreDifferent(DataContract.Notice3, value), PropertyName_Notice3); FirePropertyChanged(PropertyName_Notice3); } } } public string Notice4 { get { return _Notice4; } set { if (AreDifferent(_Notice4, value)) { _Notice4 = value; StoreDirtyInformation(AreDifferent(DataContract.Notice4, value), PropertyName_Notice4); FirePropertyChanged(PropertyName_Notice4); } } } public string Notice5 { get { return _Notice5; } set { if (AreDifferent(_Notice5, value)) { _Notice5 = value; StoreDirtyInformation(AreDifferent(DataContract.Notice5, value), PropertyName_Notice5); FirePropertyChanged(PropertyName_Notice5); } } } public string DocField1 { get; set; } public string DocField2 { get; set; } public string DocField3 { get; set; } public string DocField4 { get; set; } public string DocField5 { get; set; } public string AllNotices { get { if (String.IsNullOrEmpty(DocField2)) // Nur ein Dokufeld vorhanden { return Notice; } String all = ""; if (!String.IsNullOrEmpty(Notice)) { all = String.Format("{0}:\n{1}", DocField1, Notice); } if (!String.IsNullOrEmpty(Notice2)) { if (all.Length > 0) { all += "\n\n"; } all += String.Format("{0}:\n{1}", DocField2, Notice2); } if (!String.IsNullOrEmpty(Notice3)) { if (all.Length > 0) { all += "\n\n"; } all += String.Format("{0}:\n{1}", DocField3, Notice3); } if (!String.IsNullOrEmpty(Notice4)) { if (all.Length > 0) { all += "\n\n"; } all += String.Format("{0}:\n{1}", DocField4, Notice4); } if (!String.IsNullOrEmpty(Notice5)) { if (all.Length > 0) { all += "\n\n"; } all += String.Format("{0}:\n{1}", DocField5, Notice5); } return all; } set { } } public string RTFNotice { get { return _RTFNotice; } set { if (AreDifferent(_RTFNotice, value)) { _RTFNotice = value; StoreDirtyInformation(AreDifferent(DataContract.RTFNotice1, value), PropertyName_RTFNotice); FirePropertyChanged(PropertyName_RTFNotice); } } } public string RTFNotice2 { get { return _RTFNotice2; } set { if (AreDifferent(_RTFNotice2, value)) { _RTFNotice2 = value; StoreDirtyInformation(AreDifferent(DataContract.RTFNotice2, value), PropertyName_RTFNotice2); FirePropertyChanged(PropertyName_RTFNotice2); } } } public string RTFNotice3 { get { return _RTFNotice3; } set { if (AreDifferent(_RTFNotice3, value)) { _RTFNotice3 = value; StoreDirtyInformation(AreDifferent(DataContract.RTFNotice3, value), PropertyName_RTFNotice3); FirePropertyChanged(PropertyName_RTFNotice3); } } } public string RTFNotice4 { get { return _RTFNotice4; } set { if (AreDifferent(_RTFNotice4, value)) { _RTFNotice4 = value; StoreDirtyInformation(AreDifferent(DataContract.RTFNotice4, value), PropertyName_RTFNotice4); FirePropertyChanged(PropertyName_RTFNotice4); } } } public string RTFNotice5 { get { return _RTFNotice5; } set { if (AreDifferent(_RTFNotice5, value)) { _RTFNotice5 = value; StoreDirtyInformation(AreDifferent(DataContract.RTFNotice5, value), PropertyName_RTFNotice5); FirePropertyChanged(PropertyName_RTFNotice5); } } } public List PossibleServiceDescriptions { get { if (_Category == null) { return null; } return _Category2Services.ContainsKey(_Category) ? _Category2Services[_Category] : null; } } public decimal RoundedDurationAnzeige { get { if (_ServiceRecordFormat == ServiceRecordFormate.ZeiterfassungMitMonatJahr || DauerEinheit == ZeiterfassungsDauer.Stunden) { return _RoundedDuration/60; } else { return _RoundedDuration; } } } public decimal RoundedDuration { get { return _RoundedDuration; } set { _RoundedDuration = value; } } public decimal? Betrag { get { return _Betrag; } set { if (AreDifferent(_Betrag, value)) { _Betrag = value; StoreDirtyInformation(AreDifferent(DataContract.Betrag, value), PropertyName_Betrag); FirePropertyChanged(PropertyName_Betrag); } } } public Brush SelectedBackgroundBrush { get { Brush brush = null; if (_GroupOid != null) { brush = Application.Current.FindResource("GroupBookingSelectedBackgroundBrush") as Brush; } return brush ?? new SolidColorBrush(Color.FromArgb(0xFF, 0x93, 0xBC, 0xFF)); } } public bool HasGoals { get { return SelectedGoals.Count > 0; } } public String GoalString { get { var goals = ""; foreach (var goal in SelectedGoals) { if (goals.Length > 0) goals += ", "; goals += CreateGoalString(goal); } return goals; } } public String OnlyGoalString { get { //CB: Ich muss das hier so kompliziert machen, weil ich eine unsortierte Liste von Zielen und Maßnahmen in ein sortierte Liste innerhalb der Ziele/Maßnahmen Baumstruktur überführen muss var goals = new List(); var firstLevelGoals = new List(); Dictionary oid2Entry = new Dictionary(); Dictionary> oid2ChildList = new Dictionary>(); foreach (var goal in SelectedGoals) { if (goal.Type == ValueListEntryType.SupportConceptGoalCategoryType || goal.Type == ValueListEntryType.SupportConceptIndividualGoalCategoryType) { if (!goals.Contains(goal)) { goals.Add(goal); } } else if (goal.ParentOid.HasValue) { var parent = Cache.GetInstance().GetGoalEntry(goal.ParentOid.Value); if (parent != null && !goals.Contains(parent)) { goals.Add(parent); } } } foreach (var item in goals) { if (item.ValueListEntryOid.HasValue && !oid2Entry.ContainsKey(item.ValueListEntryOid.Value)) { oid2Entry.Add(item.ValueListEntryOid.Value, item); } } foreach (var item in goals) { if (!item.ParentOid.HasValue || !oid2Entry.ContainsKey(item.ParentOid.Value)) { firstLevelGoals.Add(item); } if (item.ParentOid.HasValue) { if (!oid2ChildList.ContainsKey(item.ParentOid.Value)) { oid2ChildList.Add(item.ParentOid.Value, new List()); } oid2ChildList[item.ParentOid.Value].Add(item); } } var sortedGoals = new List(); foreach (var item in firstLevelGoals.OrderBy(g => g.DisplayName)) { AddGoalWithChildren(item, oid2ChildList, sortedGoals); } var goalString = ""; foreach (var goal in sortedGoals) { if (goalString.Length > 0) goalString += ", "; goalString += CreateGoalString(goal); } return goalString; } } private void AddGoalWithChildren(ValueListEntryDC item, Dictionary> oid2ChildList, List sortedGoals) { sortedGoals.Add(item); if (oid2ChildList.ContainsKey(item.ValueListEntryOid.Value)) { foreach (var child in oid2ChildList[item.ValueListEntryOid.Value].OrderBy(g => g.DisplayName)) { AddGoalWithChildren(child, oid2ChildList, sortedGoals); } } } public String MassnahmenString { get { var goals = ""; foreach (var goal in SelectedGoals) { if (goal.Type == ValueListEntryType.SupportConceptGoalType || goal.Type == ValueListEntryType.SupportConceptIndividualGoalType) { if (goals.Length > 0) goals += ", "; goals += CreateGoalString(goal); } } return goals; } } private string CreateGoalString(ValueListEntryDC goal) { String name = goal.TypeDescription; if (goal.CatalogOid.HasValue) { if (goal.CatalogItem == null) { goal.CatalogItem = Cache.GetInstance().GetValueListEntry(ValueListEntryType.MassnahmenKatalog, goal.CatalogOid.Value); } if (goal.CatalogItem != null) { name = goal.CatalogItem.TypeDescription; } } if (!String.IsNullOrWhiteSpace(goal.Abbreviation)) { String code = goal.Abbreviation; if (goal.RatingTypeOid.HasValue) { var rdc = Cache.GetInstance().GetAllRatingTypeList().FirstOrDefault(r => r.RatingTypeOid == goal.RatingTypeOid); if (rdc != null && rdc.RatingId.HasValue) { code = String.Format("{0}.{1}", code, rdc.RatingId.Value); } } name = String.Format("{0}: {1}", code, name); } return name; } public ObservableSortCollection SelectedGoals { get { return _SelectedGoals ?? (_SelectedGoals = new ObservableSortCollection(Comparer.ValueListEntryDCComparer)); } } [Validation(ValidationRule = ValidationRules.NotNullOrStringEmpty)] public ServiceDescriptionDC ServiceDescription { get { return _ServiceDescription; } set { if (AreDifferent(_ServiceDescription, value)) { _ServiceDescription = value; StoreDirtyInformation(!AreEqual(DataContract.ServiceDescription, value), PropertyName_ServiceDescription); FirePropertyChanged(PropertyName_ServiceDescription); } } } public string ShortNotice { get { var desc = Notice; if (desc.IndexOf("\r\n") > 0) { desc = desc.Substring(0, desc.IndexOf("\r\n")); } return desc; } } //public DateTime? StartTime //{ // get // { // if(_StartTime != null) // return _StartTime.Value.Second != 0 ? null : _StartTime; // else // { // return new DateTime(); // } // } // set // { // DateTime? newStartTime = value ?? NULL_TIME; // Console.WriteLine("Change StartTime " + newStartTime.Value.ToShortTimeString()); // if ((_StartTime == null && newStartTime != NULL_TIME) || // (_StartTime != null && _StartTime.Value.TimeOfDay != newStartTime.Value.TimeOfDay)) // { // _StartTime = newStartTime; // if (_StartTime.Value.Second == 0) // { // if (_EndTime == null && Duration.HasValue) // { // if (_DurationInStunden == ZeiterfassungsDauer.Stunden) // { // _EndTime = _StartTime.Value.AddHours((int)Duration.Value); // } // else // { // _EndTime = _StartTime.Value.AddMinutes((int)Duration.Value); // } // } // if (_EndTime != null) // { // var end = new DateTime(_StartTime.Value.Year, _StartTime.Value.Month, _StartTime.Value.Day, // _EndTime.Value.Hour, _EndTime.Value.Minute, 0); // if (_EndTime.Value.Second > 0 && Duration.HasValue) // { // end = new DateTime(_StartTime.Value.Year, _StartTime.Value.Month, _StartTime.Value.Day, // _StartTime.Value.Hour, _StartTime.Value.Minute, 0); // if (_DurationInStunden == ZeiterfassungsDauer.Stunden) // { // end = end.AddHours((int)Duration.Value); // } // else // { // end = end.AddMinutes((int)Duration.Value); // } // } // var diff = end.Subtract(_StartTime.Value); // if (diff.TotalSeconds < 0) // { // EndTime = _StartTime; // end = EndTime.Value; // } // diff = end.Subtract(_StartTime.Value); // if (BeWoApp.AppSettings.IsEndDateVisible && ServiceRecordFormat == null || ServiceRecordFormat == ServiceRecordFormate.ZeiterfassungMitEndDatum) // { // EditableEndDate = end; // } // if (_DurationInStunden == ZeiterfassungsDauer.Stunden) // { // Duration = (decimal) diff.TotalHours; // } // else // { // Duration = (decimal)diff.TotalMinutes; // } // FirePropertyChanged(PropertyName_Duration); // TimeCheck(); // } // //else // //{ // // if (BeWoApp.AppSettings.IsEndDateVisible) // // { // // if (_DurationInStunden == ZeiterfassungsDauer.Stunden) // // { // // EndTime = _StartTime.Value.AddHours(DurationSTD.Value); // // }else{ // // EndTime = _StartTime.Value.AddMinutes(DurationSTD.Value); // // } // // }else{ // // if (_DurationInStunden == ZeiterfassungsDauer.Stunden) // // { // // EndTime = _StartTime.Value.AddHours(Duration.Value); // // }else{ // // EndTime = _StartTime.Value.AddMinutes(Duration.Value); // // } // // } // //} // } // else // { // TimeCheck(); // } // StoreDirtyInformation(true, PropertyName_SupportConcept); // FirePropertyChanged(PropertyName_StartTime); // var test = this.IsDirty; // } // } //} public CompactSupportConceptDC SupportConcept { get { return _SupportConcept; } set { if (AreDifferent(_SupportConcept, value)) { _SupportConcept = value; CostBearer = null; StoreDirtyInformation(!AreEqual(DataContract.SupportConcept, value), PropertyName_SupportConcept); FirePropertyChanged(PropertyName_SupportConcept); FirePropertyChanged(PropertyName_PossibleCostBearers); } } } public ServiceRecordTypeId ServiceRecordType { get { return _ServiceRecordType; } set { if (AreDifferent(_ServiceRecordType, value)) { _ServiceRecordType = value; StoreDirtyInformation(!AreEqual(DataContract.ServiceRecordType, value), PropertyName_ServiceRecordType); FirePropertyChanged(PropertyName_ServiceRecordType); FirePropertyChanged(PropertyName_IsServiceRecordTypeContent); FirePropertyChanged(PropertyName_IsServiceRecordTypeDefaultActivity); } } } public bool IsServiceRecordTypeContent { get { return ServiceRecordType == ServiceRecordTypeId.Content; } set { ServiceRecordType = value ? ServiceRecordTypeId.Content : ServiceRecordTypeId.DefaultActivity; } } public bool IsServiceRecordTypeDefaultActivity { get { return ServiceRecordType == ServiceRecordTypeId.DefaultActivity; } set { ServiceRecordType = value ? ServiceRecordTypeId.DefaultActivity : ServiceRecordTypeId.Content; } } public ZeiterfassungsDauer DauerEinheit { get { return _DauerEinheit; } set { if (AreDifferent(_DauerEinheit, value)) { if (value == ZeiterfassungsDauer.Minuten && _DauerEinheit == ZeiterfassungsDauer.Stunden) { _Duration *= 60; } else if (value == ZeiterfassungsDauer.Stunden && _DauerEinheit == ZeiterfassungsDauer.Minuten) { _Duration /= 60; } _DauerEinheit = value; StoreDirtyInformation(AreDifferent(DataContract.DurationInStunden, value), PropertyName_DauerEinheit); FirePropertyChanged(PropertyName_DauerEinheit); FirePropertyChanged(PropertyName_Duration); } } } public ServiceRecordFormate ServiceRecordFormat { get{ return _ServiceRecordFormat; } set { if (AreDifferent(_ServiceRecordFormat, value)) { _ServiceRecordFormat = value; StoreDirtyInformation(AreDifferent(DataContract.ServiceRecordFormat, value), PropertyName_ServiceRecordFormat); FirePropertyChanged(PropertyName_ServiceRecordFormat); } } } public string OnlyMonth { get { if (_OnlyMonth.IsNullOrEmpty()) { _OnlyMonth = DateTime.Now.ToString("MMMM"); } return _OnlyMonth; } set { if (AreDifferent(_OnlyMonth, value)) { _OnlyMonth = value; FirePropertyChanged(PropertyName_OnlyMonth); } } } public string[] MonateBinden { get { return _MonateBinden; } } public string[] JahreBind() { string[] s = new string[11]; int x = -5; for (int i = 0; i < 11; i++) { var a = DateTime.Now.Year + x; s[i] = a.ToString(); x++; } return s; } public string[] JahreBinden { get { return JahreBind(); } } public string OnlyYear { get { if (_OnlyYear.IsNullOrEmpty()) { _OnlyYear = DateTime.Now.Year.ToString(); } return _OnlyYear; } set { if (AreDifferent(_OnlyYear, value)) { _OnlyYear = value; FirePropertyChanged(PropertyName_OnlyYear); } } } [Validation(ValidationRule = ValidationRules.GreaterThanOrEqualZero)] public decimal? DurationMonthYearGes { get { if (_DurationMonthYearGes == null) { return 0; } else { return _DurationMonthYearGes; } } set { if (AreDifferent(_DurationMonthYearGes, value)) { _DurationMonthYearGes = value; StoreDirtyInformation(AreDifferent(DataContract.RoundedDuration, value), PropertyName_DurationMonthYearGes); FirePropertyChanged(PropertyName_DurationMonthYearGes); FirePropertyChanged(PropertyName_RoundedDuration); TimeCheckMonatJahr(); } } } #endregion public List Statistics { get { return _Statistics; } set { _Statistics = value; FirePropertyChanged("Statistics"); FirePropertyChanged("HasStatistics"); } } public bool HasStatistics { get { return _Statistics != null && _Statistics.Count > 0; } } #region Public Methods public void ChangeGoalTree(List goalCats, List goals) //, List goalsAndCats) { //if (!MussGoalTreeAktualisieren(goalCats, goals)) //{ //ValueListEntryDC kopieren? _AllGoalCategories = goalCats; _AllGoals = goals; var newList = new List(); if (_AllGoalCategories != null) { newList.AddRange(_AllGoalCategories); } if (_AllGoals != null) { newList.AddRange(_AllGoals); } GoalTree = SupportConceptService.CreateGoalTree(newList, SelectedGoals); AddPropertyChangedHandler(GoalTree); } private void AddPropertyChangedHandler(List goalTree) { if (goalTree != null) { foreach (var goal in goalTree) { goal.PropertyChanged += (s, e) => { var selectedGoal = s as SupportConceptGoalDC; if (selectedGoal != null) { if (selectedGoal.IsChecked) { if (!SelectedGoals.Contains(selectedGoal.GoalEntryDC)) { SelectedGoals.Add(selectedGoal.GoalEntryDC); } } else { SelectedGoals.Remove(selectedGoal.GoalEntryDC); } } }; AddPropertyChangedHandler(goal.Children); } } } //private bool MussGoalTreeAktualisieren(List goalCats, List goals) //{ // if (IstGleich(goalCats, _AllGoalCategories) && IstGleich(_AllGoals, goals)) // { // } // return false; //} public void UpdateServiceAccountings(List serviceAccountings, Dictionary> allDict, bool hilfeplanAusgewaehlt) { _ServiceAccountings = serviceAccountings; var newCategoryDict = new Dictionary>(); foreach (var cat in allDict.Keys) { bool add = true; if (hilfeplanAusgewaehlt && cat.OhneHilfeplan.HasValue && cat.OhneHilfeplan.Value == AccountingvisibilityType.NichtKlientenbezogen) { add = false; } else if (!hilfeplanAusgewaehlt && cat.OhneHilfeplan.HasValue && cat.OhneHilfeplan.Value == AccountingvisibilityType.NurKlientenbezogen) { add = false; } else if (cat.OhneHilfeplan.HasValue && cat.OhneHilfeplan.Value == AccountingvisibilityType.Never) { add = false; } if (add) { newCategoryDict.Add(cat, allDict[cat]); } } ServiceCategoryDC firstCat = null; if (_ServiceAccountings != null && allDict != null) { var globalServices = _ServiceAccountings.FindAll(sa => sa.ServiceDescription.ScopeType == ScopeTypeId.Global && (!sa.ServiceDescription.Category.OhneHilfeplan.HasValue || sa.ServiceDescription.Category.OhneHilfeplan.Value != AccountingvisibilityType.Never)); var individualServices = _ServiceAccountings.FindAll(sa => sa.ServiceDescription.ScopeType == ScopeTypeId.Individual && (!sa.ServiceDescription.Category.OhneHilfeplan.HasValue || sa.ServiceDescription.Category.OhneHilfeplan.Value != AccountingvisibilityType.Never)); if (globalServices.Count > 0) { newCategoryDict = new Dictionary>(); foreach (var cat in allDict.Keys) { var sdList = allDict[cat]; var newSdList = sdList.Where(sd => globalServices.Exists(sa => sa.ServiceDescription.Equals(sd))).ToList(); if (newSdList.Count > 0) { if (firstCat == null || cat.Position < firstCat.Position) firstCat = cat; newCategoryDict.Add(cat, newSdList); } } } if (individualServices.Count > 0) { newCategoryDict.Add(individualServices[0].ServiceDescription.Category, individualServices.Select(sa => sa.ServiceDescription).ToList()); } } Category2Services = newCategoryDict; if (Category == null) { if (firstCat == null) { firstCat = SortedCategories.FirstOrDefault(); } Category = firstCat; } } public ServiceRecordVM Clone() { var dc = new ServiceRecordDC(); return new ServiceRecordVM(CopyToDataContract(dc), _Category2Services, _AllGoalCategories, _AllGoals); } public void CopyTo(ServiceRecordVM copy) { copy.Notice = Notice; copy.Notice2 = Notice2; copy.Notice3 = Notice3; copy.Notice4 = Notice4; copy.Notice5 = Notice5; copy.RTFNotice = RTFNotice; copy.RTFNotice2 = RTFNotice2; copy.RTFNotice3 = RTFNotice3; copy.RTFNotice4 = RTFNotice4; copy.RTFNotice5 = RTFNotice5; copy.EditStartDate = EditStartDate; copy.StartTimeString = StartTimeString; copy.EditEndDate = EditEndDate; copy.EndTimeString = EndTimeString; copy.Duration = Duration; copy.RoundedDuration = RoundedDuration; copy.ServiceRecordType = ServiceRecordType; copy.DistanceInMeter = DistanceInMeter; copy.Employee = Employee; copy.Customer = Customer; copy.SupportConcept = SupportConcept; copy.CostBearer = CostBearer; copy.Category = Category; copy.ServiceDescription = ServiceDescription; copy.GroupEmployeeCount = GroupEmployeeCount; copy.GroupPersonCount = GroupPersonCount; copy.GroupOid = GroupOid; copy.GroupRoundedDuration = GroupRoundedDuration; copy.SignatureOid = SignatureOid; copy.DauerEinheit = DauerEinheit; copy.ServiceRecordFormat = ServiceRecordFormat; copy.Betrag = Betrag; copy.BackgroundColor = BackgroundColor; copy.SelectedGoals.Clear(); foreach (var item in SelectedGoals) { copy.SelectedGoals.Add(item); } copy.GoalTree = GoalTree; } public void SetInsertedOn(DateTime dt) { _InsertedOn = dt; } public override string ToString() { return _Customer + ": " + StartDate.ToLongDateString() + string.Format("- Dauer: {0:0.00} min", RoundedDuration); } #endregion #region Methods protected override void InitByDataContract(ServiceRecordDC pDataContract) { _DauerEinheit = pDataContract.DurationInStunden ?? ZeiterfassungsDauer.Minuten; _EditStartDate = pDataContract.Start ?? DateTime.Now.Date.AddSeconds(1); _EditEndDate = pDataContract.End ?? DateTime.Now.Date.AddSeconds(1); if (pDataContract.Start.HasValue && pDataContract.Start.Value.Second == 0) { _StartTimeString = String.Format("{0:HH:mm}", pDataContract.Start); } if (pDataContract.End.HasValue && pDataContract.End.Value.Second == 0) { _EndTimeString = String.Format("{0:HH:mm}", pDataContract.End); } if (_DauerEinheit == ZeiterfassungsDauer.Stunden) { _Duration = (decimal)(_EditEndDate.Value - _EditStartDate.Value).TotalHours; } else { _Duration = (_EditEndDate.Value - _EditStartDate.Value).GetTotalMinutes(); } _Notice = pDataContract.Notice; _Notice2 = pDataContract.Notice2; _Notice3 = pDataContract.Notice3; _Notice4 = pDataContract.Notice4; _Notice5 = pDataContract.Notice5; _RTFNotice = pDataContract.RTFNotice1; _RTFNotice2 = pDataContract.RTFNotice2; _RTFNotice3 = pDataContract.RTFNotice3; _RTFNotice4 = pDataContract.RTFNotice4; _RTFNotice5 = pDataContract.RTFNotice5; _ServiceDescription = pDataContract.ServiceDescription; _Employee = pDataContract.Employee; _Customer = pDataContract.Customer; _SupportConcept = pDataContract.SupportConcept; _CostBearer = pDataContract.CostBearer; _ServiceDescription = pDataContract.ServiceDescription; if (pDataContract.ServiceDescription != null) { _Category = pDataContract.ServiceDescription.Category; } _RoundedDuration = pDataContract.RoundedDuration; _InsertedOn = pDataContract.InsertedOn; _InsUser = pDataContract.InsUser; _GroupEmployeeCount = pDataContract.GroupEmployeeCount; _GroupPersonCount = pDataContract.GroupPersonCount; _GroupRoundedDuration = pDataContract.GroupRoundedDuration; _GroupOid = pDataContract.GroupOid; _ServiceRecordType = pDataContract.ServiceRecordType; _DistanceInMeter = pDataContract.DistanceInMeterDecimal; _Betrag = pDataContract.Betrag; _ServiceRecordFormat = pDataContract.ServiceRecordFormat ?? ServiceRecordFormate.OriginaleZeiterfassung; _SignatureOid = pDataContract.SignatureOid; BackgroundColor = pDataContract.BackgroundColor; if (pDataContract.Goals != null) { _SelectedGoals = new ObservableSortCollection(GoalService.CopyGoals(pDataContract.Goals, true), Comparer.ValueListEntryDCComparer); } SelectedGoals.CollectionChanged += (s, e) => { StoreDirtyInformation(!SelectedGoals.ContainsSameItemsAs(pDataContract.Goals), PropertyName_SelectedGoals); }; if (pDataContract.ServiceRecordType == ServiceRecordTypeId.Wohnheimbuchung) { _EditAllowed = _DeleteAllowed = false; } } private bool SameRatingChecked(ObservableSortCollection selectedGoals, List goals) { if (goals != null) { foreach (var selectedGoal in selectedGoals) { foreach (var goalDc in goals) { if (selectedGoal.Equals(goalDc)) { bool equalRating = true; if (selectedGoal.RatingTypeOid == null && goalDc.RatingTypeOid == null) { equalRating = true; } else if (selectedGoal.RatingTypeOid == null && goalDc.RatingTypeOid != null) { equalRating = false; } else if (selectedGoal.RatingTypeOid != null && goalDc.RatingTypeOid == null) { equalRating = false; } else if (selectedGoal.RatingTypeOid != null && goalDc.RatingTypeOid != null && selectedGoal.RatingTypeOid != goalDc.RatingTypeOid) { equalRating = false; } if (!equalRating) { StoreDirtyInformation(true, "Rating"); return false; } } } } } StoreDirtyInformation(false, "Rating"); return true; } protected override ServiceRecordDC MapToDataContract(ServiceRecordDC pDataContract, bool doCommit) { return CopyToDataContract(pDataContract); } private ServiceRecordDC CopyToDataContract(ServiceRecordDC pDataContract) { pDataContract.ServiceRecordFormat = ServiceRecordFormate.OriginaleZeiterfassung; if (!String.IsNullOrEmpty(StartTimeString) && String.IsNullOrEmpty(EndTimeString)) { DateTime newEndDate = StartDate; if (DauerEinheit == ZeiterfassungsDauer.Minuten) newEndDate = newEndDate.AddMinutes((double)Duration); else newEndDate = newEndDate.AddHours((double)Duration); EndTimeString = String.Format("{0:HH:mm}", newEndDate); } else if (String.IsNullOrEmpty(StartTimeString) && !String.IsNullOrEmpty(EndTimeString)) { //_EndTimeString = ""; } if (BeWoApp.AppSettings.IsEndDateVisible) { pDataContract.ServiceRecordFormat = ServiceRecordFormate.ZeiterfassungMitEndDatum; } pDataContract.Start = StartDate; pDataContract.End = EndDate; var d = Duration; if (DauerEinheit == ZeiterfassungsDauer.Stunden) { d *= 60; } pDataContract.RoundedDuration = d; pDataContract.Notice = _Notice; pDataContract.Notice2 = _Notice2; pDataContract.Notice3 = _Notice3; pDataContract.Notice4 = _Notice4; pDataContract.Notice5 = _Notice5; pDataContract.RTFNotice1 = _RTFNotice; pDataContract.RTFNotice2 = _RTFNotice2; pDataContract.RTFNotice3 = _RTFNotice3; pDataContract.RTFNotice4 = _RTFNotice4; pDataContract.RTFNotice5 = _RTFNotice5; pDataContract.ServiceRecordType = _ServiceRecordType; pDataContract.DistanceInMeter = null; // Die Eigenschaft muss leider drin bleiben um die Abwärtskompatibilität zu gewährleistung pDataContract.DistanceInMeterDecimal = _DistanceInMeter; pDataContract.DurationInStunden = DauerEinheit; pDataContract.Employee = _Employee; pDataContract.Customer = _Customer; pDataContract.SupportConcept = _SupportConcept; pDataContract.CostBearer = _CostBearer; pDataContract.RoundedDuration = RoundedDuration; pDataContract.ServiceDescription = _ServiceDescription; pDataContract.Betrag = _Betrag; //Hack Story dirty information SameRatingChecked(SelectedGoals, this.DataContract.Goals); pDataContract.Goals = GetSelectedGoals(); #if DEBUG if (pDataContract.Goals.Count == 0) { int test = 0; } #endif pDataContract.GroupEmployeeCount = GroupEmployeeCount; pDataContract.GroupPersonCount = GroupPersonCount; pDataContract.GroupRoundedDuration = GroupRoundedDuration; pDataContract.GroupOid = GroupOid; pDataContract.BackgroundColor = BackgroundColor; pDataContract.SignatureOid = _SignatureOid; return pDataContract; } private List GetSelectedGoals() { var goals = new List(); AddCheckedGoals(GoalTree, goals); return goals; } private static void AddCheckedGoals(IEnumerable goals, ICollection selectedGoals) { foreach (var item in goals) { if (item.IsChecked) { selectedGoals.Add(item.GoalEntryDC); } if (item.Children == null || item.Children.Count == 0) { //if (item.IsChecked) //{ // selectedGoals.Add(item.GoalEntryDC); //} } else { AddCheckedGoals(item.Children, selectedGoals); } } } private void TimeCheckMonatJahr() { //var duration = 0; decimal duration = 0; if (_DurationMonthYearGes.HasValue) { duration = _DurationMonthYearGes.Value; } var dates = DateTime.Parse("1." + _OnlyMonth + _OnlyYear); var StartDatetime = new DateTime(dates.Year, dates.Month, 1, 0, 0, 1); StoreDirtyInformation( AreDifferent(DataContract.End, StartDatetime.AddHours((double)duration).AddSeconds(1)) || AreDifferent(DataContract.Start, StartDatetime), "TIME"); } //private void TimeCheckForDurationSTD() //{ // double duration = 0; // if (_DurationSTD.HasValue) { // duration = (double)_DurationSTD.Value; // } // //####################### ich glaub das wars ########################## // if (_DurationInStunden == ZeiterfassungsDauer.Minuten) // { // if (_StartTime != null && _EndTime != null) // { // _StartTime = new DateTime(_Date.Value.Year, _Date.Value.Month, _Date.Value.Day, // _StartTime.Value.Hour, _StartTime.Value.Minute, _StartTime.Value.Second); // _EndTime = _StartTime.Value.AddMinutes(duration); // if (_EndTime.Value.Second > 1) // { // _EndTime = new DateTime(_EndTime.Value.Year, _EndTime.Value.Month, _EndTime.Value.Day, _EndTime.Value.Hour , _EndTime.Value.Minute, 0); // } // } // if (_StartTime == null && _EndTime != null && duration == 0) // { // _StartTime = new DateTime(_Date.Value.Year, _Date.Value.Month, _Date.Value.Day, _EndTime.Value.Hour, _EndTime.Value.Minute, _EndTime.Value.Second); // } // else if (_StartTime == null && _EndTime != null) // { // _StartTime = _EndTime.Value.AddMinutes(duration * -1); // } // if (_StartTime != null && _EndTime == null && duration == 0) // { // _EndTime = new DateTime(_EditableEndDate.Value.Year, _EditableEndDate.Value.Month, _EditableEndDate.Value.Day, _StartTime.Value.Hour, _StartTime.Value.Minute, _StartTime.Value.Second); // } // else if (_StartTime != null && _EndTime == null) // { // _StartTime = new DateTime(_Date.Value.Year, _Date.Value.Month, _Date.Value.Day, // _StartTime.Value.Hour, _StartTime.Value.Minute, _StartTime.Value.Second); // _EndTime = _StartTime.Value.AddMinutes(duration); // if (_EndTime.Value.Second > 1) // { // _EndTime = new DateTime(_EndTime.Value.Year, _EndTime.Value.Month, _EndTime.Value.Day, _EndTime.Value.Hour, _EndTime.Value.Minute, 0); // } // } // if (_StartTime == null && _EndTime == null && duration == 0) // { // _StartTime = new DateTime(_Date.Value.Year, _Date.Value.Month, _Date.Value.Day, 0, 0, 1); // _EndTime = new DateTime(_EditableEndDate.Value.Year, _EditableEndDate.Value.Month, _EditableEndDate.Value.Day, 0, 0, 1); // } // else if (_StartTime == null && _EndTime == null) // { // //start 1 sek und end duration + 1 sek // _StartTime = new DateTime(_Date.Value.Year, _Date.Value.Month, _Date.Value.Day, 0, 0, 1); // _EndTime = new DateTime(_EditableEndDate.Value.Year, _EditableEndDate.Value.Month, _EditableEndDate.Value.Day, 0, 0, 1); // _EndTime = _EndTime.Value.AddMinutes(duration); // } // _Date = new DateTime(_Date.Value.Year, _Date.Value.Month, _Date.Value.Day, _StartTime.Value.Hour, _StartTime.Value.Minute, _StartTime.Value.Second); // _EditableEndDate = new DateTime(_EndTime.Value.Year, _EndTime.Value.Month, _EndTime.Value.Day, _EndTime.Value.Hour, _EndTime.Value.Minute, _EndTime.Value.Second); // var diff = _EditableEndDate.Value.Subtract(_Date.Value); // duration = (double)diff.TotalMinutes; // _DurationSTD = (decimal)duration; // //StoreDirtyInformation(AreDifferent(DataContract.End, (_Date.Value + _StartTime.Value.TimeOfDay).AddMinutes((double)duration)) || AreDifferent(DataContract.Start, _Date.Value + _StartTime.Value.TimeOfDay), "TIME"); // StoreDirtyInformation(AreDifferent(DataContract.End, _EndTime) || AreDifferent(DataContract.Start, _StartTime), "TIME"); // } // else if (_DurationInStunden == ZeiterfassungsDauer.Stunden) // { // if (_StartTime != null && _EndTime != null) // { // _StartTime = new DateTime(_Date.Value.Year, _Date.Value.Month, _Date.Value.Day, // _StartTime.Value.Hour, _StartTime.Value.Minute, _StartTime.Value.Second); // _EndTime = _StartTime.Value.AddHours(duration); // if (_EndTime.Value.Second > 1) // { // _EndTime = new DateTime(_EndTime.Value.Year, _EndTime.Value.Month, _EndTime.Value.Day, _EndTime.Value.Hour, _EndTime.Value.Minute, 0); // } // } // if (_StartTime == null && _EndTime != null && duration == 0) // { // _StartTime = new DateTime(_Date.Value.Year, _Date.Value.Month, _Date.Value.Day, _EndTime.Value.Hour, _EndTime.Value.Minute, _EndTime.Value.Second); // } // else if (_StartTime == null && _EndTime != null) // { // _StartTime = _EndTime.Value.AddHours(duration * -1); // } // if (_StartTime != null && _EndTime == null && duration == 0) // { // _EndTime = new DateTime(_EditableEndDate.Value.Year, _EditableEndDate.Value.Month, _EditableEndDate.Value.Day, _StartTime.Value.Hour, _StartTime.Value.Minute, _StartTime.Value.Second); // } // else if (_StartTime != null && _EndTime == null) // { // _StartTime = new DateTime(_Date.Value.Year, _Date.Value.Month, _Date.Value.Day, // _StartTime.Value.Hour, _StartTime.Value.Minute, _StartTime.Value.Second); // _EndTime = _StartTime.Value.AddHours(duration); // if (_EndTime.Value.Second > 1) // { // _EndTime = new DateTime(_EndTime.Value.Year, _EndTime.Value.Month, _EndTime.Value.Day, _EndTime.Value.Hour, _EndTime.Value.Minute, 0); // } // } // if (_StartTime == null && _EndTime == null && duration == 0) // { // _StartTime = new DateTime(_Date.Value.Year, _Date.Value.Month, _Date.Value.Day, 0, 0, 1); // _EndTime = new DateTime(_EditableEndDate.Value.Year, _EditableEndDate.Value.Month, _EditableEndDate.Value.Day, 0, 0, 1); // } // else if (_StartTime == null && _EndTime == null) // { // //start 1 sek und end duration + 1 sek // _StartTime = new DateTime(_Date.Value.Year, _Date.Value.Month, _Date.Value.Day, 0, 0, 1); // _EndTime = new DateTime(_EditableEndDate.Value.Year, _EditableEndDate.Value.Month, _EditableEndDate.Value.Day, 0, 0, 1); // _EndTime = _EndTime.Value.AddHours(duration); // } // _Date = new DateTime(_Date.Value.Year, _Date.Value.Month, _Date.Value.Day, _StartTime.Value.Hour, _StartTime.Value.Minute, _StartTime.Value.Second); // _EditableEndDate = new DateTime(_EndTime.Value.Year, _EndTime.Value.Month, _EndTime.Value.Day, _EndTime.Value.Hour, _EndTime.Value.Minute, _EndTime.Value.Second); // var diff = _EditableEndDate.Value.Subtract(_Date.Value); // duration = (double)diff.TotalHours; // _DurationSTD = (decimal)Math.Round(duration,2); // StoreDirtyInformation(AreDifferent(DataContract.End, _EndTime) || AreDifferent(DataContract.Start, _StartTime), "TIME"); // } // FirePropertyChanged(PropertyName_DurationSTD); // FirePropertyChanged(PropertyName_StartTime); // FirePropertyChanged(PropertyName_EndTime); // FirePropertyChanged(PropertyName_Date); // FirePropertyChanged(PropertyName_EditableEndDate); // } #endregion } }