2016-06-27 01:45:38 +02:00
using System ;
using System.Collections.Generic ;
using System.Collections.ObjectModel ;
using System.ComponentModel ;
using System.Linq ;
2019-08-26 16:11:00 +02:00
using System.Windows ;
2016-06-27 01:45:38 +02:00
using System.Windows.Forms.VisualStyles ;
using BeWo.Core ;
using BeWo.Core.Service ;
2019-02-28 12:38:29 +01:00
using BeWo.Scheduler.ViewModel ;
2016-06-27 01:45:38 +02:00
using BeWo.ServiceProxy ;
using BeWo.Validation ;
2019-08-26 16:11:00 +02:00
using BeWo.View ;
using BeWo.View.Controls ;
2016-06-27 01:45:38 +02:00
using BeWo.ViewModel.ListViewModel ;
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 ;
namespace BeWo.ViewModel
{
public class SupportConceptVM : AbstractDCMapperVM < SupportConceptDC >
{
public static string PropertyName_ApprovalDate = "ApprovalDate" ;
public static string PropertyName_Conference = "Conference" ;
public static string PropertyName_IsConferenceYes = "IsConferenceYes" ;
public static string PropertyName_IsConferenceNo = "IsConferenceNo" ;
public static string PropertyName_IsConferenceOpen = "IsConferenceOpen" ;
public static string PropertyName_CombinedGoals = "CombinedGoals" ;
public static string PropertyName_ConferenceDate = "ConferenceDate" ;
public static string PropertyName_ConferenceVenue = "ConferenceVenue" ;
public static string PropertyName_ConsultingNeeded = "ConsultingNeeded" ;
public static string PropertyName_CostBearerRelations = "CostBearerRelations" ;
public static string PropertyName_Customer = "Customer" ;
public static string PropertyName_CustomerString = "CustomerString" ;
public static string PropertyName_Goals = "Goals" ;
public static string PropertyName_IsArchived = "IsArchived" ;
public static string PropertyName_Notice = "Notice" ;
public static string PropertyName_Originator = "Originator" ;
public static string PropertyName_RenewalSendDate = "RenewalSendDate" ;
public static string PropertyName_RequisitionSendDate = "RequisitionSendDate" ;
public static string PropertyName_SupportConceptSendDate = "SupportConceptSendDate" ;
public static string PropertyName_Tasks = "Tasks" ;
public static string PropertyName_GlobalServiceAccountings = "GlobalServiceAccountings" ;
2019-02-28 12:38:29 +01:00
public static string PropertyName_VarFields = "VarFields" ;
2020-08-17 15:50:00 +02:00
public static string PropertyName_Ratings = "Ratings" ;
2019-02-28 12:38:29 +01:00
private DateTime ? _ApprovalDate ;
private bool? _Conference ;
private DateTime ? _ConferenceDate ;
private string _ConferenceVenue ;
private bool _ConsultingNeeded ;
private SupportConceptCostBearerRelListVM _CostBearerRelations ;
private CompactCustomerDC _Customer ;
private bool _IsArchived ;
private string _Notice ;
private CompactEmployeeDC _Originator ;
private DateTime ? _RenewalSendDate ;
private DateTime ? _RequisitionSendDate ;
private DateTime ? _SupportConceptSendDate ;
private SchedulerAppointmentListVM _Tasks ;
2016-06-27 01:45:38 +02:00
private ObservableSortCollection < ServiceAccountingDC > _SelectedGlobalServices ;
2019-02-28 12:38:29 +01:00
private ServiceAccountingListVM _IndividualServices ;
private VarFieldListVM _VarFields ;
2020-08-17 15:50:00 +02:00
private RatingListVM _Ratings ;
2016-06-27 01:45:38 +02:00
private ObservableSortCollection < ValueListEntryDC > _Goals ;
private GenericValueListEntryListVM _CombinedGoals ;
private GenericValueListEntryListVM _IndividualGoals ;
private List < ValueListEntryDC > Children2Delete ;
private List < ValueListEntryDC > selectedGoals ;
2019-08-06 13:08:15 +02:00
private ObservableSortCollection < BudgetDC > _Budgets ;
2016-06-27 01:45:38 +02:00
public SupportConceptVM (
SupportConceptDC pDataContract ,
List < ValueListEntryDC > pAllGoalCategories ,
List < ValueListEntryDC > pAllGoals ,
2019-08-06 13:08:15 +02:00
Dictionary < ServiceCategoryDC , List < ServiceDescriptionDC > > serviceCategoryDict ,
List < BudgetDC > budgets )
2016-06-27 01:45:38 +02:00
{
2019-08-06 13:08:15 +02:00
IsNew = pDataContract . SupportConceptOid = = null ;
DataContract = pDataContract ;
_Budgets = budgets . ToObservableSortCollection ( ) ;
InitByDataContract ( DataContract ) ;
2016-06-27 01:45:38 +02:00
//InitGoalCategories(pAllGoalCategories, pAllGoals);
checkedStateChangedGoals = new List < ValueListEntryVM > ( ) ;
InitServiceTrees ( serviceCategoryDict ) ;
InitCombinedGoalTree ( ) ;
2019-08-06 13:08:15 +02:00
2016-06-27 01:45:38 +02:00
}
private void InitCombinedGoalTree ( )
{
var ziele = _IndividualGoals . VMList . Select ( s = > s . DataContract ) . ToList ( ) ;
ziele . AddRange ( ServiceFacade . DoValueListServiceSync ( s = > s . GetAllValueListEntrysByTypes ( new List < ValueListEntryType > { ValueListEntryType . SupportConceptGoalCategoryType , ValueListEntryType . SupportConceptGoalType } ) ) ) ;
_CombinedGoals = new GenericValueListEntryListVM ( ziele ) ;
var categoriesWithParent = new List < SupportConceptGoalTreeItem > ( ) ;
2024-02-20 14:42:04 +01:00
var goalList = GoalService . GetZieleMassnahmenTree ( _CombinedGoals . VMList . ToList ( ) , false ) . OrderBy ( s = > s . Name ) ;
2016-06-27 01:45:38 +02:00
var iGoalList = new ObservableSortCollection < SupportConceptGoalTreeItem > ( ) ;
var dictOid2TreeItem = new Dictionary < long , SupportConceptGoalTreeItem > ( ) ;
foreach ( var category in goalList )
{
2020-10-16 13:02:29 +02:00
if ( category . GoalEntryDC . ValueListEntryOid > 596 )
{
int test = 0 ;
}
2016-06-27 01:45:38 +02:00
var item = new SupportConceptGoalTreeItem
{
GoalEntryDC = category . GoalEntryDC ,
GoalEntryVM = _CombinedGoals . VMList . FirstOrDefault ( f = > f . DataContract . ValueListEntryOid . Value = = category . GoalEntryDC . ValueListEntryOid . Value ) ,
IsExpanded = true ,
ParentGoal = category . ParentGoal ,
IsChecked = _Goals ! = null & & _Goals . Contains ( category . GoalEntryDC )
} ;
item . PropertyChanged + = MassnahmeCheckStatusChanged ;
if ( item . GoalEntryDC . ParentOid = = null )
{
iGoalList . Add ( item ) ;
}
else
{
categoriesWithParent . Add ( item ) ;
}
2025-02-20 00:20:46 +01:00
if ( ! dictOid2TreeItem . ContainsKey ( category . GoalEntryDC . ValueListEntryOid . Value ) )
{
dictOid2TreeItem . Add ( category . GoalEntryDC . ValueListEntryOid . Value , item ) ;
}
2016-06-27 01:45:38 +02:00
}
2024-02-20 14:42:04 +01:00
foreach ( var category in categoriesWithParent . OrderBy ( s = > s . Name ) )
2016-06-27 01:45:38 +02:00
{
if ( category . GoalEntryDC . ParentOid = = null | | category . GoalEntryDC . ValueListEntryOid = = null )
continue ;
if ( dictOid2TreeItem . ContainsKey ( category . GoalEntryDC . ParentOid . Value ) )
{
var parent = dictOid2TreeItem [ category . GoalEntryDC . ParentOid . Value ] ;
parent . Items . Add ( dictOid2TreeItem [ category . GoalEntryDC . ValueListEntryOid . Value ] ) ;
category . ParentGoal = parent ;
}
}
var categoriesWithParents = dictOid2TreeItem . Values . Where ( w = > w . GoalEntryDC . ParentOid ! = null ) . ToList ( ) ;
2024-02-20 14:42:04 +01:00
foreach ( var goalCategory in categoriesWithParents . OrderBy ( s = > s . Name ) )
2016-06-27 01:45:38 +02:00
{
if ( dictOid2TreeItem . ContainsKey ( goalCategory . GoalEntryDC . ParentOid . Value ) )
{
dictOid2TreeItem [ goalCategory . GoalEntryDC . ParentOid . Value ] . Children . Add ( goalCategory ) ;
}
}
foreach ( var goal in _CombinedGoals . VMList . Where ( w = > w . Type . Equals ( ValueListEntryType . SupportConceptGoalType ) | | w . Type . Equals ( ValueListEntryType . SupportConceptIndividualGoalType ) ) )
{
var item = new SupportConceptGoalTreeItem
{
GoalEntryVM = goal ,
GoalEntryDC = goal . DataContract ,
IsChecked = _Goals ! = null & & _Goals . Contains ( goal . DataContract )
} ;
item . PropertyChanged + = MassnahmeCheckStatusChanged ;
2020-08-17 15:50:00 +02:00
if ( goal . ParentEntry = = null | | ! goal . ParentEntry . ValueListEntryOid . HasValue | | ! dictOid2TreeItem . ContainsKey ( goal . ParentEntry . ValueListEntryOid . Value ) )
2020-10-16 13:02:29 +02:00
//if (goal. == null || !goal.ParentEntry.ValueListEntryOid.HasValue || !dictOid2TreeItem.ContainsKey(goal.ParentEntry.ValueListEntryOid.Value))
2016-06-27 01:45:38 +02:00
{
iGoalList . Add ( item ) ;
}
else
{
var parent = dictOid2TreeItem [ goal . ParentEntry . ValueListEntryOid . Value ] ;
parent . Items . Add ( item ) ;
if ( ! parent . Children . Contains ( item ) )
{
parent . Children . Add ( item ) ;
}
item . ParentGoal = parent ;
}
}
_CombinedGoalTree = iGoalList ;
}
private readonly List < ValueListEntryVM > checkedStateChangedGoals ;
private void MassnahmeCheckStatusChanged ( object sender , PropertyChangedEventArgs e )
{
if ( e . PropertyName . Equals ( "IsChecked" ) )
{
var item = ( SupportConceptGoalTreeItem ) sender ;
if ( item . IsChecked ! = _Goals . Contains ( item . GoalEntryVM . DataContract ) )
{
checkedStateChangedGoals . Add ( item . GoalEntryVM ) ;
}
else if ( checkedStateChangedGoals . Contains ( item . GoalEntryVM ) )
{
checkedStateChangedGoals . Remove ( item . GoalEntryVM ) ;
}
2020-08-17 15:50:00 +02:00
UpdateGoalsInRatings ( ) ;
2016-06-27 01:45:38 +02:00
}
}
2020-08-17 15:50:00 +02:00
private void UpdateGoalsInRatings ( )
{
}
public IList < ValueListEntryDC > GetSelectedGoals1 ( )
{
return null ;
}
2016-06-27 01:45:38 +02:00
// Veraltet
//private void InitGoalCategories(List<ValueListEntryDC> pAllGoalCategories, List<ValueListEntryDC> pAllGoals)
//{
// var goalList = GoalService.GetGoalTree(pAllGoalCategories, pAllGoals, false);
// var iGoalList = new BindingList<SupportConceptGoalTreeItem>();
// var dictOid2TreeItem = new Dictionary<long, SupportConceptGoalTreeItem>();
// foreach (var goalCat in goalList)
// {
// foreach (var goal in goalCat.Children)
// {
// if (_Goals != null)
// {
// foreach (var existingGoal in _Goals)
// {
// if (existingGoal.Equals(goal.GoalEntryDC))
// {
// goal.IsChecked = true;
// }
// }
// }
// goal.PropertyChanged += ChildItem_PropertyChanged;
// }
// var item = new SupportConceptGoalTreeItem {GoalEntryDC = goalCat.GoalEntryDC, IsExpanded = true};
// iGoalList.Add(item);
// dictOid2TreeItem.Add(goalCat.GoalEntryDC.ValueListEntryOid.Value, item);
// }
// //GoalCategories = goalList;
// //Create GoalTree
// foreach (var goal in _IndividualGoals.VMList)
// {
// var item = new SupportConceptGoalTreeItem {GoalEntryVM = goal};
// if (goal.ParentEntry == null || !dictOid2TreeItem.ContainsKey(goal.ParentEntry.ValueListEntryOid.Value))
// iGoalList.Add(item);
// else
// {
// var parent = dictOid2TreeItem[goal.ParentEntry.ValueListEntryOid.Value];
// parent.Items.Add(item);
// item.ParentGoal = parent;
// }
// }
// IndividualGoalTree = iGoalList;
//}
private void InitServiceTrees ( Dictionary < ServiceCategoryDC , List < ServiceDescriptionDC > > serviceCategoryDict )
{
var categories = new List < ServiceCategoryDC > ( ) ;
var descriptions = new List < ServiceDescriptionDC > ( ) ;
foreach ( var cat in serviceCategoryDict . Keys )
{
if ( cat . ScopeType = = ScopeTypeId . Global )
{
categories . Add ( cat ) ;
descriptions . AddRange ( serviceCategoryDict [ cat ] ) ;
}
}
var serviceList = SupportConceptService . CreateServiceTree ( categories , descriptions , _SelectedGlobalServices ) ;
foreach ( var cat in serviceList )
{
foreach ( var sd in cat . Children )
{
2021-06-29 15:13:20 +02:00
// Es existierten bereits ServiceAccounting-Einträge in der Datenbank
2016-06-27 01:45:38 +02:00
if ( this . _SelectedGlobalServices ! = null & & _SelectedGlobalServices . Count > 0 )
{
foreach ( var existingSd in this . _SelectedGlobalServices )
{
if ( existingSd . ServiceDescription . Equals ( sd . ServiceAccounting . ServiceDescription ) )
{
sd . IsChecked = true ;
cat . SetChecked ( true ) ;
}
}
}
2021-06-29 15:13:20 +02:00
else // Es existieren noch keine ServiceAccounting-Einträge in der Datenbank
2016-06-27 01:45:38 +02:00
{
sd . IsChecked = true ;
if ( ! cat . IsChecked )
cat . IsChecked = true ;
}
sd . PropertyChanged + = this . GlobalServiceTreeItem_PropertyChanged ;
}
}
this . GlobalServiceTree = serviceList ;
//Create IndividualTree
BindingList < ServiceCategoryTreeItem > iserviceList = new BindingList < ServiceCategoryTreeItem > ( ) ;
foreach ( var svm in _IndividualServices . VMList )
{
ServiceCategoryTreeItem item = new ServiceCategoryTreeItem ( ) ;
item . ServiceAccountingVM = svm ;
iserviceList . Add ( item ) ;
}
this . IndividualServiceTree = iserviceList ;
}
public DateTime ? ApprovalDate
{
get { return this . _ApprovalDate ; }
set
{
if ( this . AreDifferent ( this . _ApprovalDate , value ) )
{
this . _ApprovalDate = value ;
this . StoreDirtyInformation ( this . AreDifferent ( this . DataContract . ApprovalDate , value ) , PropertyName_ApprovalDate ) ;
this . FirePropertyChanged ( PropertyName_ApprovalDate ) ;
}
}
}
public bool? Conference
{
get { return this . _Conference ; }
set
{
if ( this . AreDifferent ( this . _Conference , value ) )
{
this . _Conference = value ;
this . StoreDirtyInformation ( value = = this . DataContract . Conference , PropertyName_Conference ) ;
this . FirePropertyChanged ( PropertyName_Conference ) ;
}
}
}
public bool IsConferenceYes
{
get { return _Conference . HasValue & & _Conference . Value ; }
set
{
if ( value & & ( ! _Conference . HasValue | | ! _Conference . Value ) )
{
_Conference = true ;
StoreDirtyInformation ( true , "Conference" ) ;
FirePropertyChanged ( PropertyName_IsConferenceYes ) ;
FirePropertyChanged ( PropertyName_IsConferenceNo ) ;
FirePropertyChanged ( PropertyName_IsConferenceOpen ) ;
}
}
}
public bool IsConferenceNo
{
get { return _Conference . HasValue & & ! _Conference . Value ; }
set
{
if ( value & & ( ! _Conference . HasValue | | _Conference . Value ) )
{
_Conference = false ;
StoreDirtyInformation ( true , "Conference" ) ;
FirePropertyChanged ( PropertyName_IsConferenceYes ) ;
FirePropertyChanged ( PropertyName_IsConferenceNo ) ;
FirePropertyChanged ( PropertyName_IsConferenceOpen ) ;
}
}
}
public bool IsConferenceOpen
{
get { return ! _Conference . HasValue ; }
set
{
if ( _Conference . HasValue & & value )
{
_Conference = null ;
StoreDirtyInformation ( true , "Conference" ) ;
FirePropertyChanged ( PropertyName_IsConferenceYes ) ;
FirePropertyChanged ( PropertyName_IsConferenceNo ) ;
FirePropertyChanged ( PropertyName_IsConferenceOpen ) ;
}
}
}
public DateTime ? ConferenceDate
{
get { return this . _ConferenceDate ; }
set
{
if ( this . AreDifferent ( this . _ConferenceDate , value ) )
{
this . _ConferenceDate = value ;
this . StoreDirtyInformation ( this . AreDifferent ( this . DataContract . ConferenceDate , value ) , PropertyName_ConferenceDate ) ;
this . FirePropertyChanged ( PropertyName_ConferenceDate ) ;
}
}
}
public string ConferenceVenue
{
get { return this . _ConferenceVenue ; }
set
{
if ( this . AreDifferent ( this . _ConferenceVenue , value ) )
{
this . _ConferenceVenue = value ;
this . StoreDirtyInformation ( this . AreDifferent ( this . DataContract . ConferenceVenue , value ) , PropertyName_ConferenceVenue ) ;
this . FirePropertyChanged ( PropertyName_ConferenceVenue ) ;
}
}
}
public bool ConsultingNeeded
{
get { return _ConsultingNeeded ; }
set
{
if ( AreDifferent ( _ConsultingNeeded , value ) )
{
_ConsultingNeeded = value ;
StoreDirtyInformation ( AreDifferent ( DataContract . ConsultingNeeded , value ) , PropertyName_ConsultingNeeded ) ;
FirePropertyChanged ( PropertyName_ConsultingNeeded ) ;
}
}
}
public SupportConceptCostBearerRelListVM CostBearerRelations
{
get { return _CostBearerRelations ; }
}
2020-08-17 15:50:00 +02:00
public RatingListVM Ratings
{
get { return _Ratings ; }
}
2016-06-27 01:45:38 +02:00
public CompactCustomerDC Customer
{
get { return _Customer ; }
set
{
if ( AreDifferent ( _Customer , value ) )
{
_Customer = value ;
StoreDirtyInformation ( ! AreEqual ( value , DataContract . Customer ) , PropertyName_Customer ) ;
FirePropertyChanged ( PropertyName_Customer ) ;
FirePropertyChanged ( PropertyName_CustomerString ) ;
}
}
}
[Validation(ValidationRule = ValidationRules.NotNullOrStringEmpty)]
public string CustomerString
{
get { return _Customer . ToStringNullCheck ( ) ; } // Validation Workaround
set { }
}
public List < SupportConceptGoalDC > GoalCategories { get ; private set ; }
public BindingList < SupportConceptGoalTreeItem > IndividualGoalTree { get ; private set ; }
private ObservableCollection < SupportConceptGoalTreeItem > _CombinedGoalTree ;
public ObservableCollection < SupportConceptGoalTreeItem > CombinedGoalTree
{
get
{
return _CombinedGoalTree ? ? ( _CombinedGoalTree = new ObservableCollection < SupportConceptGoalTreeItem > ( ) ) ;
}
}
public List < ServiceCategoryTreeItem > GlobalServiceTree { get ; private set ; }
public BindingList < ServiceCategoryTreeItem > IndividualServiceTree { get ; private set ; }
2019-02-28 12:38:29 +01:00
public ObservableSortCollection < ValueListEntryDC > Goals = > _Goals ? ? ( _Goals = new ObservableSortCollection < ValueListEntryDC > ( Comparer . ValueListEntryDCComparer ) ) ;
2016-06-27 01:45:38 +02:00
public ObservableSortCollection < ServiceAccountingDC > SelectedGlobalServices
{
get { return _SelectedGlobalServices ? ? ( _SelectedGlobalServices = new ObservableSortCollection < ServiceAccountingDC > ( Comparer . ServiceAccountingDCComparer ) ) ; }
}
public bool IsArchived
{
get { return _IsArchived ; }
set
{
if ( AreDifferent ( _IsArchived , value ) )
{
_IsArchived = value ;
StoreDirtyInformation (
( value & & DataContract . ActivationType = = ActivationTypeId . Active ) | | ( ! value & & DataContract . ActivationType = = ActivationTypeId . Archived ) , PropertyName_IsArchived ) ;
FirePropertyChanged ( PropertyName_IsArchived ) ;
}
}
}
public override bool IsDirty
{
get
{
if ( CostBearerRelations = = null | | Tasks = = null )
{
return false ;
}
2018-10-08 11:57:16 +02:00
return base . IsDirty | | CostBearerRelations . IsDirty | | Tasks . IsDirty | | ( _VarFields ! = null & & _VarFields . IsDirty ) | |
2020-08-17 15:50:00 +02:00
_IndividualServices . IsDirty | | _CombinedGoals . IsDirty | | changedGoalds . Count > 0 | | Ratings . IsDirty | | checkedStateChangedGoals . Count > 0 ; ;
2016-06-27 01:45:38 +02:00
}
}
public string Notice
{
get { return _Notice ; }
set
{
if ( AreDifferent ( _Notice , value ) )
{
_Notice = value ;
StoreDirtyInformation ( AreDifferent ( DataContract . Notice , value ) , PropertyName_Notice ) ;
FirePropertyChanged ( PropertyName_Notice ) ;
}
}
}
public CompactEmployeeDC Originator
{
get { return _Originator ; }
set
{
if ( AreDifferent ( _Originator , value ) )
{
_Originator = value ;
StoreDirtyInformation ( ! AreEqual ( value , DataContract . Originator ) , PropertyName_Originator ) ;
FirePropertyChanged ( PropertyName_Originator ) ;
}
}
}
2020-08-17 15:50:00 +02:00
2016-06-27 01:45:38 +02:00
public DateTime ? RenewalSendDate
{
get { return _RenewalSendDate ; }
set
{
if ( AreDifferent ( _RenewalSendDate , value ) )
{
_RenewalSendDate = value ;
StoreDirtyInformation ( AreDifferent ( DataContract . RenewalSendDate , value ) , PropertyName_RenewalSendDate ) ;
FirePropertyChanged ( PropertyName_RenewalSendDate ) ;
}
}
}
public virtual DateTime ? RequisitionSendDate
{
get { return _RequisitionSendDate ; }
set
{
if ( AreDifferent ( _RequisitionSendDate , value ) )
{
_RequisitionSendDate = value ;
StoreDirtyInformation ( AreDifferent ( DataContract . RequisitionSendDate , value ) , PropertyName_RequisitionSendDate ) ;
FirePropertyChanged ( PropertyName_RequisitionSendDate ) ;
}
}
}
public virtual DateTime ? SupportConceptSendDate
{
get { return _SupportConceptSendDate ; }
set
{
if ( AreDifferent ( _SupportConceptSendDate , value ) )
{
_SupportConceptSendDate = value ;
StoreDirtyInformation ( AreDifferent ( DataContract . SupportConceptSendDate , value ) , PropertyName_SupportConceptSendDate ) ;
FirePropertyChanged ( PropertyName_SupportConceptSendDate ) ;
}
}
}
public GenericValueListEntryListVM CombinedGoals
{
get { return _CombinedGoals ; }
set
{
if ( AreDifferent ( _CombinedGoals , value ) )
{
_CombinedGoals = value ;
StoreDirtyInformation ( AreDifferent ( DataContract . Goals , value ) , PropertyName_CombinedGoals ) ;
FirePropertyChanged ( PropertyName_CombinedGoals ) ;
}
}
}
2019-02-28 12:38:29 +01:00
public SchedulerAppointmentListVM Tasks
2016-06-27 01:45:38 +02:00
{
2019-02-28 12:38:29 +01:00
get = > _Tasks ;
2016-06-27 01:45:38 +02:00
set
{
if ( AreDifferent ( _Tasks , value ) )
{
_Tasks = value ;
FirePropertyChanged ( PropertyName_Tasks ) ;
}
}
}
2018-10-08 11:57:16 +02:00
public VarFieldListVM VarFields
{
get { return _VarFields ; }
set
{
if ( AreDifferent ( _VarFields , value ) )
{
_VarFields = value ;
FirePropertyChanged ( PropertyName_VarFields ) ;
}
}
}
2020-08-17 15:50:00 +02:00
private List < SupportConceptGoalTreeItem > changedGoalds = new List < SupportConceptGoalTreeItem > ( ) ;
public List < SupportConceptGoalTreeItem > ChangedGoals
{
get { return changedGoalds ; }
set { changedGoalds = value ; }
}
2016-06-27 01:45:38 +02:00
public void AddIndividualService ( ServiceCategoryTreeItem parent )
{
var newItem = new ServiceCategoryTreeItem ( ) ;
//if (parent == null)
//{
// ServiceCategoryDC newCategory = new ServiceCategoryDC();
// newCategory.Name = "Neue Kategorie";
// newItem.ServiceCategory = newCategory;
//}
//else
//{
var vm = _IndividualServices . NewVM ;
vm . ServiceDescription . Name = "Neue Leistung" ;
vm . ServiceDescription . ScopeType = ScopeTypeId . Individual ;
newItem . ServiceAccountingVM = vm ;
//newSd.Category = parent.ServiceCategory;
//parent.Children.Add(newItem);
//newItem.Parent = parent;
_IndividualServices . AddNewVMToList ( ) ;
//}
IndividualServiceTree . Add ( newItem ) ;
}
internal void DeleteIndividualService ( ServiceCategoryTreeItem selectedItem )
{
IndividualServiceTree . Remove ( selectedItem ) ;
_IndividualServices . VMList . Remove ( selectedItem . ServiceAccountingVM ) ;
}
internal void DeleteIndividualGoal ( SupportConceptGoalTreeItem selectedItem )
{
Children2Delete = new List < ValueListEntryDC > ( ) ;
TraverseCollection ( selectedItem ) ;
var parent = selectedItem . ParentGoal as SupportConceptGoalTreeItem ;
if ( parent ! = null & & parent . Items ! = null )
parent . Items . Remove ( selectedItem ) ;
else
CombinedGoalTree . Remove ( selectedItem ) ;
CombinedGoals . VMList . Remove ( selectedItem . GoalEntryVM ) ;
individualGoals2Delete = new List < long > ( ) ;
CollectGoals2Delete ( selectedItem ) ;
foreach ( var goal in CombinedGoalTree )
{
if ( RemoveGoalFromGoalTree ( goal , selectedItem ) )
{
break ;
}
}
Goals . RemoveRange ( Goals . Where ( w = > w . ValueListEntryOid . HasValue & & individualGoals2Delete . Contains ( w . ValueListEntryOid . Value ) ) ) ;
_IndividualGoals . VMList . RemoveRange ( _IndividualGoals . VMList . Where ( w = > ! w . IsNew & & w . DataContract . ValueListEntryOid . HasValue & & individualGoals2Delete . Contains ( w . DataContract . ValueListEntryOid . Value ) ) ) ;
}
private List < long > individualGoals2Delete ;
private void CollectGoals2Delete ( SupportConceptGoalDC selectedItem )
{
if ( selectedItem . GoalEntryDC ! = null & & selectedItem . GoalEntryDC . ValueListEntryOid . HasValue )
{
individualGoals2Delete . Add ( selectedItem . GoalEntryDC . ValueListEntryOid . Value ) ;
}
foreach ( var child in selectedItem . Children )
{
CollectGoals2Delete ( child ) ;
}
}
private static bool RemoveGoalFromGoalTree ( SupportConceptGoalDC currentGoal , SupportConceptGoalDC goal2Delete )
{
var shouldBreak = currentGoal . Children . Remove ( goal2Delete ) ;
foreach ( var child in currentGoal . Children )
{
shouldBreak = RemoveGoalFromGoalTree ( child , goal2Delete ) ;
}
return shouldBreak ;
}
private void TraverseCollection ( SupportConceptGoalTreeItem item )
{
var result = new List < ValueListEntryDC > { item . GoalEntryDC ? ? item . GoalEntryVM . CommitToDataContract ( ) } ;
foreach ( var child in item . Items )
{
TraverseCollection ( child ) ;
}
Children2Delete . AddRange ( result ) ;
}
2019-08-26 16:11:00 +02:00
//public void AddZielOrMassnahme(SupportConceptGoalTreeItem parent, bool isCategory)
//{
// var newItem = new SupportConceptGoalTreeItem();
// var vm = _CombinedGoals.NewVM;
// vm.Type = isCategory ? ValueListEntryType.SupportConceptIndividualGoalCategoryType : ValueListEntryType.SupportConceptIndividualGoalType;
// vm.Description = isCategory ? "Neues individuelles Ziel" : "Neue individuelle Maßnahme";
// newItem.GoalEntryVM = vm;
// newItem.GoalEntryDC = vm.CommitToDataContract();
// _CombinedGoals.AddNewVMToList();
// newItem.ParentGoal = parent;
// //CombinedGoalTree.Add(newItem);
2016-06-27 01:45:38 +02:00
2019-08-26 16:11:00 +02:00
// var vorhanden = CombinedGoals.VMList.Contains(newItem.GoalEntryVM);
// if (parent != null)
// {
// vm.ParentEntry = parent.GoalEntryDC ?? parent.GoalEntryVM.CommitToDataContract();
// parent.GoalEntryVM = parent.GoalEntryVM;
// parent.Items.Add(newItem);
// parent.IsExpanded = true;
// }
//}
2022-12-15 23:16:04 +01:00
public SupportConceptGoalTreeItem AddTreeItem ( SupportConceptGoalTreeItem parent , ValueListEntryType valueListEntryType , string description , string abbreviation , string notice , long? catalogOid )
2016-06-27 01:45:38 +02:00
{
2025-02-20 00:20:46 +01:00
//if (!valueListEntryType.HasFlag(ValueListEntryType.SupportConceptIndividualGoalCategoryType) &&
// !valueListEntryType.HasFlag(ValueListEntryType.SupportConceptIndividualGoalType))
// throw new ArgumentOutOfRangeException();
2019-08-26 16:11:00 +02:00
2016-06-27 01:45:38 +02:00
var vm = _CombinedGoals . NewVM ;
2019-08-26 16:11:00 +02:00
vm . Type = valueListEntryType ;
vm . Description = description ;
vm . Abbreviation = abbreviation ;
vm . Notice = notice ;
2022-12-15 23:16:04 +01:00
vm . CatalogOid = catalogOid ;
2016-06-27 01:45:38 +02:00
2019-08-26 16:11:00 +02:00
var newItem = new SupportConceptGoalTreeItem
{
GoalEntryVM = vm ,
GoalEntryDC = vm . CommitToDataContract ( ) ,
ParentGoal = parent
} ;
2016-06-27 01:45:38 +02:00
_CombinedGoals . AddNewVMToList ( ) ;
foreach ( var item in CombinedGoalTree )
{
FindGoalVMInTreeView ( item , newItem ) ;
}
2025-02-20 00:20:46 +01:00
if ( parent = = null )
{
//Neues Element ohne Vater auf der obersten Ebene hinzufügen
CombinedGoalTree . Add ( newItem ) ;
return newItem ;
}
2019-08-26 16:11:00 +02:00
vm . ParentEntry = parent . GoalEntryDC ? ? parent . GoalEntryVM . CommitToDataContract ( ) ;
parent . GoalEntryVM = parent . GoalEntryVM ;
parent . Items . Add ( newItem ) ;
2025-02-20 00:20:46 +01:00
//parent.Children.Add(newItem);
2019-08-26 16:11:00 +02:00
parent . IsExpanded = true ;
return newItem ;
}
public void EditTreeItem ( ValueListEntryVM valueListEntry )
{
if ( valueListEntry = = null ) return ;
2022-12-15 23:16:04 +01:00
var katalog = Cache . GetInstance ( ) . GetAllValueListEntrysByTypeSync ( ValueListEntryType . MassnahmenKatalog ) ;
var control = new ValueListEntryEditControl ( valueListEntry , katalog ) ;
2019-08-26 16:11:00 +02:00
var beWoWindow = new BeWoWindow ( ) ;
control . CancelButtonClicked + = ( ) = >
2016-06-27 01:45:38 +02:00
{
2019-08-26 16:11:00 +02:00
if ( control . ValueListEntry . IsDirty )
{
if ( MessageBox . Show ( "Möchten Sie die Änderung verwerfen?" , "Änderungen vorhanden" , MessageBoxButton . YesNo , MessageBoxImage . Question ) ! = MessageBoxResult . Yes )
return ;
control . ResetValueListEntry ( ) ;
}
beWoWindow . Close ( ) ;
} ;
2020-11-10 02:25:15 +01:00
control . SaveButtonClicked + = ( ) = >
{
control . ValueListEntry . CommitToDataContract ( ) ;
beWoWindow . Close ( ) ;
} ;
2019-08-26 16:11:00 +02:00
beWoWindow . Height = 200 ;
beWoWindow . Width = 500 ;
beWoWindow . WindowStartupLocation = WindowStartupLocation . CenterOwner ;
beWoWindow . GroupBoxContent = control ;
beWoWindow . Owner = BeWoApp . CurrentBeWo . MainWindow ;
beWoWindow . rootGroupBox . Header = "Bearbeiten" ;
beWoWindow . ShowDialog ( ) ;
}
public void AddTreeItemWithControl ( SupportConceptGoalTreeItem parent , ValueListEntryType valueListEntryType , string viewHeader )
{
2022-12-15 23:16:04 +01:00
var katalog = Cache . GetInstance ( ) . GetAllValueListEntrysByTypeSync ( ValueListEntryType . MassnahmenKatalog ) ;
2024-01-09 11:36:29 +01:00
var newVm = new ValueListEntryVM ( new ValueListEntryDC { Type = valueListEntryType } ) ;
newVm . Type = valueListEntryType ;
var control = new ValueListEntryEditControl ( newVm , katalog ) ;
2019-08-26 16:11:00 +02:00
var beWoWindow = new BeWoWindow ( ) ;
control . CancelButtonClicked + = ( ) = >
{
if ( control . ValueListEntry . IsDirty )
{
if ( MessageBox . Show ( "Möchten Sie die Änderung verwerfen?" , "Änderungen vorhanden" , MessageBoxButton . YesNo , MessageBoxImage . Question ) ! = MessageBoxResult . Yes )
return ;
control . ResetValueListEntry ( ) ;
}
beWoWindow . Close ( ) ;
} ;
control . SaveButtonClicked + = ( ) = >
{
var vm = control . ValueListEntry ;
2022-12-15 23:16:04 +01:00
AddTreeItem ( parent , valueListEntryType , vm . Description , vm . Abbreviation , vm . Notice , vm . CatalogOid ) ;
2019-08-26 16:11:00 +02:00
beWoWindow . Close ( ) ;
} ;
beWoWindow . Height = 200 ;
beWoWindow . Width = 500 ;
beWoWindow . WindowStartupLocation = WindowStartupLocation . CenterOwner ;
beWoWindow . GroupBoxContent = control ;
beWoWindow . Owner = BeWoApp . CurrentBeWo . MainWindow ;
beWoWindow . rootGroupBox . Header = viewHeader ;
beWoWindow . ShowDialog ( ) ;
2016-06-27 01:45:38 +02:00
}
private bool TreeViewContainsVM ;
private void FindGoalVMInTreeView ( SupportConceptGoalDC item , SupportConceptGoalDC wantedItem )
{
if ( item . Children . Contains ( wantedItem ) )
{
TreeViewContainsVM = true ;
}
foreach ( var child in item . Children )
{
FindGoalVMInTreeView ( child , wantedItem ) ;
}
}
//public ServiceAccountingListVM ServiceAccountings
//{
// get { return this._ServiceAccountings; }
// set
// {
// if (this.AreDifferent(this._ServiceAccountings, value))
// {
// this._ServiceAccountings = value;
// this.StoreDirtyInformation(this.AreDifferent(this.DataContract.ServiceAccountings, value), PropertyName_ServiceAccountings);
// this.FirePropertyChanged(PropertyName_ServiceAccountings);
// }
// }
//}
protected override void InitByDataContract ( SupportConceptDC pDataContract )
{
//if (!IsNew)
//{
_Conference = pDataContract . Conference ;
_IsArchived = pDataContract . ActivationType = = ActivationTypeId . Archived ;
_Originator = pDataContract . Originator ;
_Customer = pDataContract . Customer ;
_Notice = pDataContract . Notice ;
_ConferenceDate = pDataContract . ConferenceDate ;
_ApprovalDate = pDataContract . ApprovalDate ;
_RenewalSendDate = pDataContract . RenewalSendDate ;
_RequisitionSendDate = pDataContract . RequisitionSendDate ;
_SupportConceptSendDate = pDataContract . SupportConceptSendDate ;
_ConferenceVenue = pDataContract . ConferenceVenue ;
if ( pDataContract . ConsultingNeeded = = null )
{
_ConsultingNeeded = false ;
}
else
{
_ConsultingNeeded = pDataContract . ConsultingNeeded . Value ;
}
if ( pDataContract . Goals ! = null )
{
2019-02-28 12:38:29 +01:00
var globalGoals = pDataContract . Goals . FindAll ( g = > g . Type = = ValueListEntryType . SupportConceptGoalType | | g . Type = = ValueListEntryType . SupportConceptGoalCategoryType ) ;
2016-06-27 01:45:38 +02:00
2019-02-28 12:38:29 +01:00
var individualGoals = pDataContract . Goals . FindAll ( g = > g . Type = = ValueListEntryType . SupportConceptIndividualGoalType | | g . Type = = ValueListEntryType . SupportConceptIndividualGoalCategoryType ) ;
2016-06-27 01:45:38 +02:00
_Goals = new ObservableSortCollection < ValueListEntryDC > ( globalGoals , Comparer . ValueListEntryDCComparer ) ;
_IndividualGoals = new GenericValueListEntryListVM ( individualGoals ) ;
}
Goals . CollectionChanged + = ( s , e ) = > StoreDirtyInformation ( ! _Goals . ContainsSameItemsAs ( pDataContract . Goals ) , PropertyName_Goals ) ;
if ( pDataContract . ServiceAccountings ! = null )
{
2019-02-28 12:38:29 +01:00
var globalServices = pDataContract . ServiceAccountings . FindAll ( sa = > sa . ServiceDescription . ScopeType = = ScopeTypeId . Global ) ;
2016-06-27 01:45:38 +02:00
2019-02-28 12:38:29 +01:00
var individualServices = pDataContract . ServiceAccountings . FindAll ( sa = > sa . ServiceDescription . ScopeType = = ScopeTypeId . Individual ) ;
2016-06-27 01:45:38 +02:00
_SelectedGlobalServices = new ObservableSortCollection < ServiceAccountingDC > ( globalServices , Comparer . ServiceAccountingDCComparer ) ;
_IndividualServices = new ServiceAccountingListVM ( individualServices ) ;
//this._ServiceAccountings = new ServiceAccountingListVM(pDataContract.ServiceAccountings);
}
//}
if ( _IndividualGoals = = null )
2019-02-28 12:38:29 +01:00
{
2016-06-27 01:45:38 +02:00
_IndividualGoals = new GenericValueListEntryListVM ( new List < ValueListEntryDC > ( ) ) ;
2019-02-28 12:38:29 +01:00
}
2016-06-27 01:45:38 +02:00
if ( _IndividualServices = = null )
2019-02-28 12:38:29 +01:00
{
2016-06-27 01:45:38 +02:00
_IndividualServices = new ServiceAccountingListVM ( new List < ServiceAccountingDC > ( ) ) ;
2019-02-28 12:38:29 +01:00
}
2016-06-27 01:45:38 +02:00
if ( _SelectedGlobalServices = = null )
2019-02-28 12:38:29 +01:00
{
2016-06-27 01:45:38 +02:00
_SelectedGlobalServices = new ObservableSortCollection < ServiceAccountingDC > ( Comparer . ServiceAccountingDCComparer ) ;
2019-02-28 12:38:29 +01:00
}
2016-06-27 01:45:38 +02:00
_SelectedGlobalServices . CollectionChanged + = ( s , e ) = > StoreDirtyInformation ( _SelectedGlobalServices . Count > 0 , PropertyName_GlobalServiceAccountings ) ;
2019-02-28 12:38:29 +01:00
Cache . GetInstance ( ) . GetAllActiveEmployeesCompact ( employees = >
{
if ( BeWoApp . LoggedOnEmployeeOid . HasValue & & DataContract ? . SupportConceptOid ! = null )
{
ServiceFacade . DoResourceServiceAsync ( s = >
{
var tasks = s . GetSchedulerAppointmentTasksForEmployeeBySupportConecpt ( BeWoApp . LoggedOnEmployeeOid . Value , DataContract . SupportConceptOid . Value ) ;
2016-06-27 01:45:38 +02:00
2019-02-28 12:38:29 +01:00
_Tasks = new SchedulerAppointmentListVM ( tasks , new List < CompactCustomerDC > ( ) , employees , new Dictionary < ValueListEntryDC , List < ResourceDC > > ( ) ) ;
_Tasks . NewVM . EmployeeList . Add ( new Employee2SchedulerAppointmentDC { Employee = BeWoApp . CompactLoggedOnEmployee } ) ;
FirePropertyChanged ( nameof ( Tasks ) ) ;
} ) ;
}
else
{
_Tasks = new SchedulerAppointmentListVM ( new List < SchedulerAppointmentDC > ( ) , new List < CompactCustomerDC > ( ) , employees , new Dictionary < ValueListEntryDC , List < ResourceDC > > ( ) ) ;
FirePropertyChanged ( nameof ( Tasks ) ) ;
}
} ) ;
2016-06-27 01:45:38 +02:00
2019-08-06 13:08:15 +02:00
VMFactory . CreateSupportConceptCostBearerRelVMAsync ( pDataContract . CostBearerRelations ? ? ( pDataContract . CostBearerRelations = new List < SupportConceptCostBearerRelDC > ( ) ) , _Budgets , cb = > _CostBearerRelations = cb ) ;
2018-10-08 11:57:16 +02:00
2020-08-17 15:50:00 +02:00
if ( pDataContract . Ratings = = null )
{
pDataContract . Ratings = new List < RatingDC > ( ) ;
}
_Ratings = new RatingListVM ( pDataContract . Ratings ) ;
2018-10-08 11:57:16 +02:00
_VarFields = new VarFieldListVM ( pDataContract . VarFields ) ;
2016-06-27 01:45:38 +02:00
}
protected override SupportConceptDC MapToDataContract ( SupportConceptDC pDataContract , bool doCommit )
{
pDataContract . Conference = _Conference ;
pDataContract . ActivationType = _IsArchived ? ActivationTypeId . Archived : ActivationTypeId . Active ;
pDataContract . Originator = _Originator ;
pDataContract . Customer = _Customer ;
pDataContract . Notice = _Notice ;
pDataContract . ConferenceDate = _ConferenceDate ;
pDataContract . ApprovalDate = _ApprovalDate ;
pDataContract . RenewalSendDate = _RenewalSendDate ;
pDataContract . ConsultingNeeded = _ConsultingNeeded ;
pDataContract . RequisitionSendDate = _RequisitionSendDate ;
pDataContract . SupportConceptSendDate = _SupportConceptSendDate ;
pDataContract . ConferenceVenue = _ConferenceVenue ;
pDataContract . CostBearerRelations = _CostBearerRelations . CopyToDCList ( doCommit ) ;
2020-08-17 15:50:00 +02:00
pDataContract . Ratings = _Ratings . CopyToDCList ( doCommit ) ;
2016-06-27 01:45:38 +02:00
pDataContract . ServiceAccountings = GetSelectedGlobalServices ( ) ;
if ( _IndividualServices . VMList . Count > 0 )
{
if ( pDataContract . ServiceAccountings = = null )
2019-02-28 12:38:29 +01:00
{
2016-06-27 01:45:38 +02:00
pDataContract . ServiceAccountings = new List < ServiceAccountingDC > ( ) ;
2019-02-28 12:38:29 +01:00
}
2016-06-27 01:45:38 +02:00
pDataContract . ServiceAccountings . AddRange ( _IndividualServices . CopyToDCList ( doCommit ) ) ;
}
pDataContract . Goals = GetSelectedGoals ( ) ;
2019-02-28 12:38:29 +01:00
2018-10-08 11:57:16 +02:00
if ( _VarFields ! = null )
{
pDataContract . VarFields = _VarFields . CopyToDCList ( doCommit ) ;
}
2019-02-28 12:38:29 +01:00
2016-06-27 01:45:38 +02:00
return pDataContract ;
}
2020-08-17 15:50:00 +02:00
public List < ValueListEntryDC > GetSelectedGoals ( )
2016-06-27 01:45:38 +02:00
{
selectedGoals = new List < ValueListEntryDC > ( ) ;
var vms = CombinedGoals . VMList . Where ( w = > ( w . Type . Equals ( ValueListEntryType . SupportConceptIndividualGoalType ) | | w . Type . Equals ( ValueListEntryType . SupportConceptIndividualGoalCategoryType ) ) & & w . IsNew ) ;
2017-03-28 11:01:28 +02:00
var test = vms . ToList ( ) ;
2016-06-27 01:45:38 +02:00
foreach ( var item in _CombinedGoalTree )
{
IterateThroughSelectedGoalsAndMassnahmen ( item ) ;
}
selectedGoals . AddRange ( vms . Select ( s = > s . CommitToDataContract ( ) ) ) ;
return selectedGoals ;
}
public void IterateThroughSelectedGoalsAndMassnahmen ( SupportConceptGoalDC category )
{
if ( ( category . IsChecked & & category . GoalEntryDC . Type . Equals ( ValueListEntryType . SupportConceptGoalType ) ) | |
( ( ( category . GoalEntryDC . Type . Equals ( ValueListEntryType . SupportConceptIndividualGoalType ) | | category . GoalEntryDC . Type . Equals ( ValueListEntryType . SupportConceptIndividualGoalCategoryType ) ) & & category . GoalEntryDC . ValueListEntryOid ! = null ) )
| | category . IsChecked & & category . Children . Count = = 0 )
{
selectedGoals . Add ( category . GoalEntryDC ) ;
}
foreach ( var item in category . Children )
{
IterateThroughSelectedGoalsAndMassnahmen ( item ) ;
}
}
public List < SupportConceptGoalTreeItem > TreeViewItemsList ;
public void GetAllTreeViewItems ( )
{
foreach ( var parent in CombinedGoalTree . Where ( w = > ! w . HasParent ) )
{
TraverseTreeViewItem ( parent ) ;
}
}
private void TraverseTreeViewItem ( SupportConceptGoalTreeItem item )
{
TreeViewItemsList . Add ( item ) ;
foreach ( var child in item . Items )
{
TraverseTreeViewItem ( child ) ;
}
}
private List < ServiceAccountingDC > GetSelectedGlobalServices ( )
{
var services = new List < ServiceAccountingDC > ( ) ;
var everyItemChecked = true ;
foreach ( var item in GlobalServiceTree )
{
foreach ( var child in item . Children )
{
if ( child . IsChecked )
{
services . Add ( child . ServiceAccounting ) ;
} else
{
everyItemChecked = false ;
}
}
}
return everyItemChecked ? null : services ;
}
private void GlobalServiceTreeItem_PropertyChanged ( object sender , PropertyChangedEventArgs e )
{
var treeItem = sender as ServiceCategoryTreeItem ;
if ( treeItem ! = null & & treeItem . ServiceAccounting ! = null )
{
if ( treeItem . IsChecked )
{
SelectedGlobalServices . Add ( treeItem . ServiceAccounting ) ;
}
else
{
if ( _SelectedGlobalServices . Count = = 0 ) //Wenn alle gecheckt sind, erst mal alle zufügen
{
foreach ( var sc in GlobalServiceTree )
{
foreach ( var child in sc . Children )
{
if ( child . ServiceAccounting ! = null )
SelectedGlobalServices . Add ( child . ServiceAccounting ) ;
}
}
}
SelectedGlobalServices . Remove ( treeItem . ServiceAccounting ) ;
}
}
}
}
}