using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Windows.Media; namespace BS.Shared.DataContracts.ClientPartials { public class SupportConceptGoalDC : INotifyPropertyChanged, IFilterableDC { private List _Children; private ValueListEntryDC _GoalEntryDC; private bool _IsChecked; private bool _IsExpanded; private bool _ShowNotice; private bool _CheckRecursive = true; public long? KeyField => GoalEntryDC?.ValueListEntryOid; public long? ParentField => ParentGoal?.GoalEntryDC?.ValueListEntryOid; public bool CheckRecursive { get { return _CheckRecursive; } set { _CheckRecursive = value; } } public List Children { get { return _Children ?? (_Children = new List()); } set { _Children = value; } } public ValueListEntryDC GoalEntryDC { get { return _GoalEntryDC; } set { _GoalEntryDC = value; } } public bool HasParent => ParentGoal != null; public bool HasNotice => GoalEntryDC != null && !string.IsNullOrEmpty(GoalEntryDC.Notice); public bool ShowNotice { get => _ShowNotice; set { _ShowNotice = value; RaisePropertyChanged("ShowNotice"); } } public bool IsChecked { get => _IsChecked; set { _IsChecked = value; if (CheckRecursive) { foreach (var item in Children) { item.IsChecked = value; } } RaisePropertyChanged("IsChecked"); } } public bool IsExpanded { get => _IsExpanded; set { _IsExpanded = value; RaisePropertyChanged("IsExpanded"); } } public string Name => DetailDescription; public SupportConceptGoalDC ParentGoal { get; set; } public event PropertyChangedEventHandler PropertyChanged; public SolidColorBrush FilterableBrush => new SolidColorBrush(Colors.Transparent); protected void RaisePropertyChanged(string propertyName) { var propertyChanged = PropertyChanged; propertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } public override string ToString() { return GoalEntryDC == null ? "-" : GoalEntryDC.TypeDescription; } #region IFilterableDC Members public string IconPath { get { return string.Empty; } } public string DetailDescription { get { return GoalEntryDC.DisplayName; } } public string FilterRelevants { get { String filter = this.Name + " " + this.GoalEntryDC?.Abbreviation; if (this.Children != null) { foreach (var child in this.Children) { filter += " "; filter += child.FilterRelevants; } } return filter; } } public bool SupportsActivationType { get { return true; } } public long Version { get { return 0; } set { } } public string SimpleDescription { get { return Name; } } public ActivationTypeId ActivationType { get { return ActivationTypeId.Active; } set { } } #endregion public void SetRatingType(RatingTypeDC rt) { if (GoalEntryDC != null && rt != null) { GoalEntryDC.RatingTypeOid = rt.RatingTypeOid.Value; RatingName = rt.DisplayName; } if (rt == null && GoalEntryDC != null) { GoalEntryDC.RatingTypeOid = null; RatingName = ""; //foreach (var item in Children) //{ // item.SetRatingType(null); //} } RaisePropertyChanged("HasRating"); RaisePropertyChanged("RatingName"); } public bool HasRating => GoalEntryDC != null && GoalEntryDC.RatingTypeOid.HasValue; public string RatingName { get; set; } public bool IsZiel { get { return IsOfType(ValueListEntryType.SupportConceptGoalCategoryType); } } public bool IsIndZiel { get { return IsOfType(ValueListEntryType.SupportConceptIndividualGoalCategoryType); } } public bool IsMassnahme { get { return IsOfType(ValueListEntryType.SupportConceptGoalType); } } public bool IsIndMassnahme { get { return IsOfType(ValueListEntryType.SupportConceptIndividualGoalType); } } public bool IsOfType(ValueListEntryType t) { if (_GoalEntryDC != null) { return _GoalEntryDC.Type == t; } return false; } } }