Files
BeWoPlaner/BeWo/View/Detail/Report/IcfImportControl.xaml.cs
2021-11-02 12:50:37 +01:00

111 lines
3.3 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 SupportConceptGoalDC _TreeViewGoalItem;
public IcfImportControl(List<ValueListEntryDC> icfs)
{
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)
{
// Erzeugt das O
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
//var remaining = allIcfs.Where(x =>
//x.ParentOid == actual.ValueListEntryOid).ToList();
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;
}
private void InitTreeView(List<ValueListEntryDC> icfs)
{
if (icfs == null || icfs.All(x => x.ParentOid != -1))
return;
TreeViewGoalItem = GetSupportConceptGoal(null, icfs.Find(x => x.ParentOid == -1), icfs);
// Hier müssen die Children alle Oberkategorien sein und erst nach diesen die Unterkategorien
}
}
}