Files
BeWoPlaner/BeWo/View/Detail/Report/IcfImportControl.xaml.cs
2021-12-13 08:07:09 +01:00

174 lines
5.9 KiB
C#

using BeWo.Core;
using BeWo.ServiceProxy;
using BS.Shared.Extensions;
using DevExpress.Utils;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using BeWo.ViewModel;
using BS.Shared;
using BS.Shared.DataContracts;
using BS.Shared.DataContracts.ClientPartials;
using DevExpress.Data;
using DevExpress.Mvvm.Native;
using DevExpress.Xpf.Grid;
using DevExpress.Xpf.Scheduler.UI;
using DevExpress.XtraExport.Xls;
using static BeWo.View.Detail.Report.FlexibleReportView;
namespace BeWo.View.Detail.Report
{
public partial class IcfImportControl
{
public event Action ButtonImportClicked;
public event Action ButtonCancelClicked;
private List<ValueListEntryDC> _GanzerICF;
private SupportConceptGoalDC _TreeViewGoalItem;
public IcfImportControl(List<ValueListEntryDC> icfNachAbzug)
{
InitializeComponent();
DataContext = this;
//_GanzerICF = ServiceFacade.DoOperationsServiceSync(s => s.GetWholeIcf());
InitTreeView(icfNachAbzug);
}
public IcfImportControl(List<ValueListEntryDC> icfs, List<ValueListEntryDC> vorhandeneKapitel)
{
InitializeComponent();
DataContext = this;
InitTreeView(icfs);
}
private void ButtonImport_Click(object sender, RoutedEventArgs e)
{
ButtonImportClicked?.Invoke();
}
private void ButtonCancel_Click(object sender, RoutedEventArgs e)
{
ButtonCancelClicked?.Invoke();
}
public SupportConceptGoalDC TreeViewGoalItem
{
get => _TreeViewGoalItem;
set
{
_TreeViewGoalItem = value;
TreeView.ItemsSource = new List<SupportConceptGoalDC>() { value };
}
}
private static SupportConceptGoalDC GetSupportConceptGoal(SupportConceptGoalDC parent, ValueListEntryDC actual, List<ValueListEntryDC> allIcfs)
{
// Hier muss eine zusätzliche Verschachtelungsstufe erstellt werden, also ICF -> Kategorie -> Einschränkungsarten/Ziele
// Erzeugt das Objekt
var goalItem = new SupportConceptGoalDC
{
GoalEntryDC = actual,
ParentGoal = parent
};
if (parent == null)
{
goalItem.IsExpanded = true;
}
// Sucht nach Einträgen, wo die ParentID gleich der actual.Oid ist
List<ValueListEntryDC> remaining = new List<ValueListEntryDC>();
foreach (var item in allIcfs)
{
if (item != null)
{
if (item.ParentOid == actual.ValueListEntryOid)
remaining.Add(item);
}
}
// Schaut, ob welche gefunden worden, sonst bleibt Children leer
if (remaining.Any())
{
goalItem.Children = remaining.Select(x => GetSupportConceptGoal(goalItem, x, allIcfs)).ToList();
}
return goalItem;
}
// in icfNachAbzug stehen alle Ziele, die noch NICHT in die Ansicht importiert wurden, aber die Überkategorien sind noch vorhanden, auch wenn sie leer sind
private static SupportConceptGoalDC GetSupportConceptGoalVersion2(SupportConceptGoalDC parent, ValueListEntryDC actual, List<ValueListEntryDC> icfNachAbzug,
List<ValueListEntryDC> allIcfs)
{
var goalItem = new SupportConceptGoalDC
{
GoalEntryDC = actual,
ParentGoal = parent
};
if (parent == null)
{
goalItem.IsExpanded = true;
}
// Sucht nach Einträgen, wo die ParentID gleich der actual.Oid ist
List<ValueListEntryDC> remaining = new List<ValueListEntryDC>();
foreach (var item in icfNachAbzug)
{
if (item != null)
{
if (item.ParentOid == actual.ValueListEntryOid)
remaining.Add(item);
}
}
List<ValueListEntryDC> toRemove = new List<ValueListEntryDC>();
foreach (var chapter in remaining)
{
if (allIcfs.Any(i => i.ParentOid == chapter.ValueListEntryOid)) // Checken, ob das Kapitel EIGENTLICH Children hat
{
if (!icfNachAbzug.Any(c => c.ParentOid == chapter.ValueListEntryOid)) // Checken, ob die Children da sind und wenn nicht, aus remaining entfernen
{
icfNachAbzug.Remove(chapter);
if (remaining.Contains(chapter))
toRemove.Add(chapter);
}
}
}
remaining.RemoveRange(toRemove);
// Schaut, ob welche gefunden worden, sonst bleibt Children leer
if (remaining.Any())
{
goalItem.Children = remaining.Select(x => GetSupportConceptGoalVersion2(goalItem, x, icfNachAbzug, allIcfs)).ToList();
}
return goalItem;
}
private void InitTreeView(List<ValueListEntryDC> icfNachAbzug)
{
if (icfNachAbzug == null || icfNachAbzug.All(x => x.ParentOid != -1))
return;
TreeViewGoalItem = GetSupportConceptGoal(null, icfNachAbzug.Find(x => x.ParentOid == -1), icfNachAbzug);
//#if DEBUG
// TreeViewGoalItem = GetSupportConceptGoalVersion2(null, icfNachAbzug.Find(x => x.ParentOid == -1), icfNachAbzug, _GanzerICF);
//#endif
// Hier müsste eigentlich alle ohne Children, die eigentlich welche haben, aussortiert werden..
}
}
}