Merge branch 'feature_rene_11_massnahme_drag'

This commit is contained in:
2023-09-11 12:46:45 +02:00
5 changed files with 463 additions and 172 deletions

View File

@@ -3057,6 +3057,9 @@
<Resource Include="Ressources\Icons\imassnahme.png" />
<Resource Include="Ressources\Icons\iziel.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Ressources\Icons\Copy24.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>

View File

@@ -1,19 +1,20 @@
using System.ComponentModel;
using BeWo.ViewModel;
using BS.Shared;
using BeWo.ViewModel;
using BS.Shared.DataContracts.ClientPartials;
using BS.Shared.Extensions;
using System.ComponentModel;
using System.Diagnostics;
namespace BeWo.Core
{
[DebuggerDisplay("{GoalEntryVM.Abbreviation}: {GoalEntryVM.Description}")]
public class SupportConceptGoalTreeItem : SupportConceptGoalDC
{
private ValueListEntryVM _GoalEntryVM;
private BindingList<SupportConceptGoalTreeItem> _Children;
private bool _ShowNotice;
public SupportConceptGoalTreeItem() { }
public ValueListEntryVM GoalEntryVM
{
get => _GoalEntryVM;
@@ -56,7 +57,7 @@ namespace BeWo.Core
return IsOfType(ValueListEntryType.SupportConceptIndividualGoalType);
}
}
public bool IsOfType(ValueListEntryType t)
{

Binary file not shown.

After

Width:  |  Height:  |  Size: 784 B

View File

@@ -29,6 +29,22 @@
<Image Source="..\..\Ressources\Icons\Rename24.png"/>
</MenuItem.Icon>
</MenuItem>
<Separator />
<MenuItem Header="Einzelnes Element kopieren">
<MenuItem.Icon>
<Image Source="..\..\Ressources\Icons\Copy24.png"/>
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Elementbaum kopieren">
<MenuItem.Icon>
<Image Source="..\..\Ressources\Icons\Copy24.png"/>
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Einfügen">
<MenuItem.Icon>
<Image Source="..\..\Ressources\Icons\Paste24.png"/>
</MenuItem.Icon>
</MenuItem>
<!--<MenuItem Header="Umbenennen">
<MenuItem.Icon>
<Image Source="..\..\Ressources\Icons\Rename24.png"/>
@@ -53,19 +69,23 @@
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Content="Neues Ziel" />
<TextBox Grid.Column="1" Margin="1" VerticalContentAlignment="Center" Text="{Binding ViewModel.NewVM.Description, UpdateSourceTrigger=PropertyChanged}" />
<Button Grid.Column="2" Height="25" Content="Hinzufügen" Margin="1" Click="ZielHinzufuegenButton_Click" />
<Button Grid.Column="3" Height="25" Content="Icf Importieren" Margin="1" Click="IcfImport_Click" />
<Button Grid.Column="2" Height="25" Content="Hinzufügen" Margin="3" Click="ZielHinzufuegenButton_Click" />
<Button Grid.Column="3" Height="25" Content="Icf Importieren" Margin="3" Click="IcfImport_Click" />
<ToggleButton Grid.Column="4" Height="25" Content="Bearbeiten" Margin="3" Checked="ToggleButton_Checked" Unchecked="ToggleButton_Unchecked" />
</Grid>
<GroupBox Grid.Row="1" Style="{StaticResource ObjectEditGroupBox}">
<TreeView x:Name="TreeView" Margin="3 3 7 3" Grid.Row="1" Padding="0 5 10 5"
ItemContainerStyle="{DynamicResource igoal_treeitemstyle}"
ItemTemplate="{DynamicResource igoal_treeitemtemplate}" Grid.RowSpan="1" ContextMenu="{StaticResource cmGoals}"
PreviewMouseDown="GoalTreeViewItem_PreviewMouseRightButtonDown"
ItemsSource="{Binding IndividualGoalTree, UpdateSourceTrigger=PropertyChanged}" >
ItemsSource="{Binding IndividualGoalTree, UpdateSourceTrigger=PropertyChanged}"
MouseDown="TreeView_MouseDown" MouseMove="TreeView_MouseMove"
AllowDrop="True" PreviewDragOver="TreeView_PreviewDragOver" PreviewDrop="TreeView_PreviewDrop" >
<TreeView.Resources>
<Style x:Key="igoal_treeitemstyle" TargetType="TreeViewItem">
<Setter Property="IsExpanded" Value="{Binding Path=IsExpanded, Mode=TwoWay}" />
@@ -84,7 +104,7 @@
<TextBox Margin="0,0,0,0" Cursor="Arrow" Background="Transparent" Height="21" Padding="0,3,0,0" VerticalAlignment="Center"
LostFocus="TextBox_LostFocus" KeyDown="TextBox_KeyDown" BorderThickness="0"
IsReadOnly="True" Text="{Binding Path=GoalEntryVM.DisplayName, UpdateSourceTrigger=PropertyChanged, Mode=OneWay}"
FontWeight="{Binding Path=IsGoal, Converter={StaticResource ValueListEntryTypeToFontWeightConverter}}" ToolTipService.ShowDuration="100000">
FontWeight="{Binding Path=IsGoal, Converter={StaticResource ValueListEntryTypeToFontWeightConverter}}" ToolTipService.ShowDuration="100000" Focusable="False">
<TextBox.ToolTip>
<StackPanel Orientation="Vertical">
<Label FontWeight="Bold" Content="{Binding Path=GoalEntryVM.DisplayName, Mode=OneWay}"/>

View File

@@ -1,6 +1,17 @@
using System;
using BeWo.Core;
using BeWo.Core.Service;
using BeWo.ServiceProxy;
using BeWo.View.Controls;
using BeWo.View.Detail.Report;
using BeWo.ViewModel;
using BeWo.ViewModel.ListViewModel;
using BS.Shared;
using BS.Shared.Core;
using BS.Shared.DataContracts;
using BS.Shared.DataContracts.ClientPartials;
using BS.Shared.Extensions;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Windows;
@@ -11,30 +22,27 @@ using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;
using BeWo.Core;
using BeWo.Core.Service;
using BeWo.ServiceProxy;
using BeWo.View.Controls;
using BeWo.View.Detail.Report;
using BeWo.ViewModel;
using BeWo.ViewModel.ListViewModel;
using BS.Shared;
using BS.Shared.Core;
using BS.Shared.DataContracts;
using BS.Shared.DataContracts.ClientPartials;
using BS.Shared.Extensions;
namespace BeWo.View.Detail
{
public enum MassnahmenTreeCopyType
{
Node, Subtree
}
public partial class MassnahmenTreeViewView
{
private bool _Bearbeitungsmodus;
private TreeViewItem _SelectedGoalTreeNode;
private GenericValueListEntryListVM _ViewModel;
private List<ValueListEntryDC> _Children2Delete;
private List<SupportConceptGoalTreeItem> _TreeViewItemsList;
private MassnahmenTreeCopyType _CopyType;
private SupportConceptGoalTreeItem _CopyItem;
private Point _lastMouseDown;
private SupportConceptGoalTreeItem _draggedItem;
private SupportConceptGoalTreeItem _parent;
public MassnahmenTreeViewView(GenericValueListEntryListVM pViewModel)
{
@@ -43,8 +51,44 @@ namespace BeWo.View.Detail
ViewModel = pViewModel;
DataContext = this;
Bearbeitungsmodus = false;
}
public static bool IsAllowedToEditGoals => BeWoApp.LoggedOnUser.HasRight(UserRightType.SupportConcept_AllowEditGoals);
public GenericValueListEntryListVM ViewModel
{
get => _ViewModel;
set
{
_ViewModel = value;
InitGoalCategoriesTreeView();
TreeView.ItemsSource = GoalTree;
}
}
public bool Bearbeitungsmodus
{
get
{
return _Bearbeitungsmodus;
}
set
{
// Wenn True aber keine Rechte
if (value && !IsAllowedToEditGoals)
return;
_Bearbeitungsmodus = value;
TreeView.AllowDrop = _Bearbeitungsmodus;
}
}
public ObservableSortCollection<SupportConceptGoalTreeItem> GoalTree { get; private set; }
public override bool IsDirty => ViewModel != null && ViewModel.IsDirty;
private void GoalTreeViewItem_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
@@ -63,13 +107,16 @@ namespace BeWo.View.Detail
{
_SelectedGoalTreeNode = null;
}
}
if (e.ChangedButton == MouseButton.Left)
{
_lastMouseDown = e.GetPosition(TreeView);
}
}
private void TextBox_LostFocus(object sender, RoutedEventArgs e)
{
UpdateSelectedTreeItemText((TextBox)sender);
}
private void TextBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Return)
@@ -77,7 +124,6 @@ namespace BeWo.View.Detail
UpdateSelectedTreeItemText((TextBox)sender);
}
}
private void ContextMenuGoals_Click(object sender, RoutedEventArgs e)
{
if (!(e.OriginalSource is MenuItem twi)) return;
@@ -108,7 +154,7 @@ namespace BeWo.View.Detail
"Alle verknüpften Eintragungen in der Zeiterfassung bleiben erhalten.\n\n" +
"Wollen Sie " + zielOderMassnahme + " '" + selectedItem.GoalEntryVM?.DisplayName + "' wirklich löschen?", "Löschen bestätigen", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
{
DeleteIndividualGoal(selectedItem);
DeleteTreeItem(selectedItem);
}
}
break;
@@ -116,9 +162,34 @@ namespace BeWo.View.Detail
if (selectedItem != null)
EditTreeItem(selectedItem.GoalEntryVM);
break;
case "Einzelnes Element kopieren":
if (selectedItem != null)
{
_CopyItem = selectedItem;
_CopyType = MassnahmenTreeCopyType.Node;
}
break;
case "Elementbaum kopieren":
if (selectedItem != null)
{
_CopyItem = selectedItem;
_CopyType = MassnahmenTreeCopyType.Subtree;
}
break;
case "Einfügen":
if (!_Bearbeitungsmodus)
{
MessageBox.Show("Bearbeitungsmodus deaktiviert", "Aktion nicht möglich");
}
else
{
if (selectedItem != null)
StartCopyItem(selectedItem, _CopyItem);
}
break;
}
}
private void ContextMenuGoals_Opened(object sender, RoutedEventArgs e)
{
if (e.OriginalSource is ContextMenu menu)
@@ -139,12 +210,23 @@ namespace BeWo.View.Detail
{
menuitem.IsEnabled = goal != null; // && goal.IsGoal;
}
else if (menuitem.Header.Equals("Einfügen"))
{
menuitem.IsEnabled = goal != null && !goal.IsGoal && Bearbeitungsmodus && _CopyItem != null && (_CopyType == MassnahmenTreeCopyType.Node || !ContainsTreeItem(_CopyItem, goal));
}
else if (menuitem.Header.Equals("Elementbaum kopieren"))
{
menuitem.IsEnabled = goal != null && !goal.IsGoal && Bearbeitungsmodus;
}
else if (menuitem.Header.Equals("Einzelnes Element kopieren"))
{
menuitem.IsEnabled = goal != null && Bearbeitungsmodus;
}
menuitem.IsEnabled = menuitem.IsEnabled && IsAllowedToEditGoals;
}
}
}
private void GoalTreeItemContainerGenerator_StatusChanged(object sender, EventArgs e)
{
var ig = (ItemContainerGenerator)sender;
@@ -172,7 +254,6 @@ namespace BeWo.View.Detail
_SelectedGoalTreeNode.ItemContainerGenerator.StatusChanged -= GoalTreeItemContainerGenerator_StatusChanged;
}
private void ZielHinzufuegenButton_Click(object sender, RoutedEventArgs e)
{
var newItem = new SupportConceptGoalTreeItem();
@@ -186,7 +267,6 @@ namespace BeWo.View.Detail
GoalTree.Sort((x, y) => x.GoalEntryVM?.DisplayName?.CompareTo(y.GoalEntryVM?.DisplayName) ?? string.Compare(string.Empty, y.GoalEntryVM?.DisplayName, StringComparison.Ordinal));
}
private void IcfImport_Click(object sender, RoutedEventArgs e)
{
var vorhandeneZiele = new List<ValueListEntryDC>();
@@ -196,7 +276,7 @@ namespace BeWo.View.Detail
vorhandeneZiele.AddRange(GetAllChildren(item, null));
}
//#if DEBUG
//#if DEBUG
var control2 = new IcfImportControl(ServiceFacade.DoOperationsServiceSync(x => x.GetWholeIcfOhneImportierte(vorhandeneZiele)));
var beWoWindow2 = new BeWoWindow
@@ -223,7 +303,7 @@ namespace BeWo.View.Detail
beWoWindow2.ShowDialog();
return;
//#endif
//#endif
//var control = new IcfImportControl(ServiceFacade.DoOperationsServiceSync(x => x.GetWholeIcf()));
//var beWoWindow = new BeWoWindow
@@ -250,6 +330,126 @@ namespace BeWo.View.Detail
//beWoWindow.ShowDialog();
}
private void ToggleButton_Checked(object sender, RoutedEventArgs e)
{
Bearbeitungsmodus = true;
}
private void ToggleButton_Unchecked(object sender, RoutedEventArgs e)
{
Bearbeitungsmodus = false;
}
private void StartCopyItem(SupportConceptGoalTreeItem _item, SupportConceptGoalTreeItem _copy)
{
if (ContainsTreeItem(_copy, _item))
MessageBox.Show("Kopieren in tiefere Ziele/Maßnamhen nicht möglich!");
else
CopyTreeItem(_item, _copy, false);
}
private void StartMoveItem(SupportConceptGoalTreeItem _draggedItem, SupportConceptGoalTreeItem _parent)
{
if (ContainsTreeItem(_draggedItem, _parent))
MessageBox.Show("Kopieren in tiefere Ziele/Maßnamhen nicht möglich!");
else
MoveTreeItem(_draggedItem, _parent);
}
private void TreeView_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left && Bearbeitungsmodus)
{
_lastMouseDown = e.GetPosition(TreeView);
}
}
private void TreeView_MouseMove(object sender, MouseEventArgs e)
{
try
{
if (e.LeftButton == MouseButtonState.Pressed && Bearbeitungsmodus)
{
Point currentPosition = e.GetPosition(TreeView);
if ((Math.Abs(currentPosition.X - _lastMouseDown.X) > 10.0) ||
(Math.Abs(currentPosition.Y - _lastMouseDown.Y) > 10.0))
{
_draggedItem = (SupportConceptGoalTreeItem)TreeView.SelectedItem;
if (_draggedItem != null)
{
DragDropEffects finalDropEffect = DragDrop.DoDragDrop(TreeView, _SelectedGoalTreeNode, DragDropEffects.Move);
//Checking target is not null and item is
//dragging(moving)
if ((finalDropEffect == DragDropEffects.Move) && (_parent != null) && _parent != _draggedItem)
{
StartMoveItem(_draggedItem, _parent);
//var origin_parent = _draggedItem.ParentGoal as SupportConceptGoalTreeItem;
//var parent = _parent;
//var child = _draggedItem;
//origin_parent.Items.Remove(child);
//child.GoalEntryVM.ParentEntry = parent.GoalEntryDC ?? parent.GoalEntryVM.CommitToDataContract();
//parent.Items.Add(_draggedItem);
//parent.IsExpanded = true;
//TreeView.RefreshUI();
}
}
}
}
}
catch (Exception)
{
}
}
private void TreeView_PreviewDragOver(object sender, DragEventArgs e)
{
try
{
Point currentPosition = e.GetPosition(TreeView);
e.Effects = DragDropEffects.None;
if ((Math.Abs(currentPosition.X - _lastMouseDown.X) > 10.0) ||
(Math.Abs(currentPosition.Y - _lastMouseDown.Y) > 10.0))
{
// Verify that this is a valid drop and then store the drop target
var item = GetNearestContainer(e.OriginalSource as UIElement);
if (CheckDropTarget(_draggedItem, item))
{
e.Effects = DragDropEffects.Move;
}
else
{
e.Effects = DragDropEffects.None;
}
}
e.Handled = true;
}
catch (Exception ex)
{
}
}
private void TreeView_PreviewDrop(object sender, DragEventArgs e)
{
try
{
e.Effects = DragDropEffects.None;
e.Handled = true;
// Verify that this is a valid drop and then store the drop target
var target = GetNearestContainer(e.OriginalSource as UIElement);
if (target != null && _draggedItem != null)
{
_parent = target;
e.Effects = DragDropEffects.Move;
}
}
catch (Exception ex)
{
}
}
public List<ValueListEntryDC> GetAllChildren(SupportConceptGoalTreeItem treeItem, SupportConceptGoalDC dcItem)
{
@@ -258,7 +458,7 @@ namespace BeWo.View.Detail
if (dcItem == null)
{
returnThis.Add(treeItem.GoalEntryDC);
if (treeItem.Children.Count > 0)
{
foreach (var child in treeItem.Children)
@@ -282,104 +482,6 @@ namespace BeWo.View.Detail
return returnThis;
}
public static bool IsAllowedToEditGoals => BeWoApp.LoggedOnUser.HasRight(UserRightType.SupportConcept_AllowEditGoals);
public GenericValueListEntryListVM ViewModel
{
get => _ViewModel;
set
{
_ViewModel = value;
InitGoalCategoriesTreeView();
TreeView.ItemsSource = GoalTree;
}
}
public ObservableSortCollection<SupportConceptGoalTreeItem> GoalTree { get; private set; }
public override bool IsDirty => ViewModel != null && ViewModel.IsDirty;
public void AddTreeItemWithControl(SupportConceptGoalTreeItem parent, ValueListEntryType valueListEntryType, string viewHeader)
{
var control = new ValueListEntryEditControl(new ValueListEntryVM(new ValueListEntryDC()), null);
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;
AddTreeItem(parent, valueListEntryType, vm.Description, vm.Abbreviation, vm.Notice);
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();
}
public SupportConceptGoalTreeItem AddTreeItem(SupportConceptGoalTreeItem parent, ValueListEntryType valueListEntryType, string description, string abbreviation, string notice)
{
if (!valueListEntryType.HasFlag(ValueListEntryType.SupportConceptGoalCategoryType) &&
!valueListEntryType.HasFlag(ValueListEntryType.SupportConceptGoalType))
throw new ArgumentOutOfRangeException();
var vm = ViewModel.NewVM;
vm.Type = valueListEntryType;
vm.Description = description;
vm.Abbreviation = abbreviation;
vm.Notice = notice;
var newItem = new SupportConceptGoalTreeItem
{
GoalEntryVM = vm,
GoalEntryDC = vm.CommitToDataContract(),
ParentGoal = parent
};
ViewModel.AddNewVMToList();
if (parent == null) return newItem;
vm.ParentEntry = parent.GoalEntryDC ?? parent.GoalEntryVM.CommitToDataContract();
parent.GoalEntryVM = parent.GoalEntryVM;
parent.Items.Add(newItem);
parent.IsExpanded = true;
return newItem;
}
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
GoalTree.Remove(selectedItem);
ViewModel.VMList.Remove(selectedItem.GoalEntryVM);
}
protected override void Save()
{
var lToDos = new List<Action<IValueListService>>();
@@ -421,7 +523,6 @@ namespace BeWo.View.Detail
Cache.GetInstance().ClearAllValueListEntries();
}
private static void EditTreeItem(ValueListEntryVM valueListEntry)
{
if (valueListEntry == null) return;
@@ -453,7 +554,6 @@ namespace BeWo.View.Detail
beWoWindow.rootGroupBox.Header = "Bearbeiten";
beWoWindow.ShowDialog();
}
private static void EditItem(TreeView tv, TreeViewItem tvi, object item, bool isNoticeTextBox = false)
{
if (item != null)
@@ -483,7 +583,6 @@ namespace BeWo.View.Detail
}
}
}
private static void UpdateSelectedTreeItemText(TextBoxBase textBox)
{
if (!textBox.IsReadOnly)
@@ -494,7 +593,6 @@ namespace BeWo.View.Detail
textBox.Padding = new Thickness(1, 3, 1, 3);
}
}
private static SupportConceptGoalTreeItem SearchGoalTreeItem(SupportConceptGoalTreeItem supportConceptGoalTreeItem,
string description, string abbreviation, string notice)
{
@@ -524,7 +622,6 @@ namespace BeWo.View.Detail
ViewModel = vm;
}));
}
private void InitGoalCategoriesTreeView()
{
var categoriesWithParent = new List<SupportConceptGoalTreeItem>();
@@ -541,6 +638,7 @@ namespace BeWo.View.Detail
GoalEntryVM = ViewModel.VMList.FirstOrDefault(f => f.DataContract.ValueListEntryOid.Value == category.GoalEntryDC.ValueListEntryOid.Value),
IsExpanded = true,
ParentGoal = category.ParentGoal
};
if (item.GoalEntryDC.ParentOid == null)
{
@@ -579,7 +677,7 @@ namespace BeWo.View.Detail
foreach (var goal in ViewModel.VMList.Where(w => w.Type.Equals(ValueListEntryType.SupportConceptGoalType)))
{
var item = new SupportConceptGoalTreeItem { GoalEntryVM = goal };
if (goal.ParentEntry == null || !goal.ParentEntry.ValueListEntryOid.HasValue || !dictOid2TreeItem.ContainsKey(goal.ParentEntry.ValueListEntryOid.Value))
@@ -596,19 +694,7 @@ namespace BeWo.View.Detail
GoalTree = iGoalList;
}
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);
}
private void GetAllTreeViewItems()
{
foreach (var parent in GoalTree)
@@ -616,7 +702,6 @@ namespace BeWo.View.Detail
TraverseTreeViewItem(parent);
}
}
private void TraverseTreeViewItem(SupportConceptGoalTreeItem item)
{
_TreeViewItemsList.Add(item);
@@ -625,7 +710,6 @@ namespace BeWo.View.Detail
TraverseTreeViewItem(child);
}
}
private void ImportIcf(SupportConceptGoalDC goal)
{
if (goal == null) return;
@@ -635,7 +719,6 @@ namespace BeWo.View.Detail
if (goal.IsChecked)
AddIcf(goal);
}
private SupportConceptGoalTreeItem AddIcf(SupportConceptGoalDC goal)
{
if (goal == null) return null;
@@ -672,27 +755,211 @@ namespace BeWo.View.Detail
return AddTreeItem(parent, ValueListEntryType.SupportConceptGoalCategoryType,
goal.GoalEntryDC.TypeDescription, goal.GoalEntryDC.Abbreviation, goal.GoalEntryDC.Notice);
}
private bool IstGleichesZiel(ValueListEntryVM ziel1, ValueListEntryVM ziel2)
public void AddTreeItemWithControl(SupportConceptGoalTreeItem parent, ValueListEntryType valueListEntryType, string viewHeader)
{
if (ziel1.DataContract.ValueListEntryOid.HasValue && ziel2.DataContract.ValueListEntryOid.HasValue)
var control = new ValueListEntryEditControl(new ValueListEntryVM(new ValueListEntryDC()), null);
var beWoWindow = new BeWoWindow();
control.CancelButtonClicked += () =>
{
return ziel1.DataContract.ValueListEntryOid.Value == ziel2.DataContract.ValueListEntryOid.Value;
}
else if (!ziel1.DataContract.ValueListEntryOid.HasValue && !ziel2.DataContract.ValueListEntryOid.HasValue)
{
if (ziel1.ParentEntry != null && ziel2.ParentEntry != null && ziel1.ParentEntry.Equals(ziel1.ParentEntry))
if (control.ValueListEntry.IsDirty)
{
bool test = ziel1.Equals(ziel2);
return ziel1.Description == ziel2.Description;
if (MessageBox.Show("Möchten Sie die Änderung verwerfen?", "Änderungen vorhanden", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
return;
control.ResetValueListEntry();
}
else if (ziel1.ParentEntry == null && ziel2.ParentEntry == null)
beWoWindow.Close();
};
control.SaveButtonClicked += () =>
{
var vm = control.ValueListEntry;
AddTreeItem(parent, valueListEntryType, vm.Description, vm.Abbreviation, vm.Notice);
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();
}
private SupportConceptGoalTreeItem AddTreeItem(SupportConceptGoalTreeItem parent, ValueListEntryType valueListEntryType, string description, string abbreviation, string notice)
{
if (!valueListEntryType.HasFlag(ValueListEntryType.SupportConceptGoalCategoryType) &&
!valueListEntryType.HasFlag(ValueListEntryType.SupportConceptGoalType))
throw new ArgumentOutOfRangeException();
var vm = ViewModel.NewVM;
vm.Type = valueListEntryType;
vm.Description = description;
vm.Abbreviation = abbreviation;
vm.Notice = notice;
var newItem = new SupportConceptGoalTreeItem
{
GoalEntryVM = vm,
GoalEntryDC = vm.CommitToDataContract(),
ParentGoal = parent
};
ViewModel.AddNewVMToList();
if (parent == null) return newItem;
vm.ParentEntry = parent.GoalEntryDC ?? parent.GoalEntryVM.CommitToDataContract();
parent.GoalEntryVM = parent.GoalEntryVM;
parent.Items.Add(newItem);
parent.IsExpanded = true;
return newItem;
}
private void DeleteTreeItem(SupportConceptGoalTreeItem selectedItem)
{
_Children2Delete = new List<ValueListEntryDC>();
DeleteTreeItemRec(selectedItem);
var parent = selectedItem.ParentGoal as SupportConceptGoalTreeItem;
if (parent != null && parent.Items != null)
parent.Items.Remove(selectedItem);
else
GoalTree.Remove(selectedItem);
ViewModel.VMList.Remove(selectedItem.GoalEntryVM);
}
private void DeleteTreeItemRec(SupportConceptGoalTreeItem item)
{
var result = new List<ValueListEntryDC> { item.GoalEntryDC ?? item.GoalEntryVM.CommitToDataContract() };
foreach (var child in item.Items)
{
DeleteTreeItemRec(child);
}
_Children2Delete.AddRange(result);
}
private void CopyTreeItem(SupportConceptGoalTreeItem parent, SupportConceptGoalTreeItem source, bool force_deep_copy)
{
if (source == null || parent == null)
throw new NotImplementedException("#43298467891364987");
var wm = source.GoalEntryVM;
var childs = source.Items.ToList();
var node = AddTreeItem(parent, wm.Type, wm.Description, wm.Abbreviation, wm.Notice);
if (_CopyType == MassnahmenTreeCopyType.Subtree || force_deep_copy)
{
foreach (var child in childs)
{
return ziel1.Description == ziel2.Description;
CopyTreeItem(node, child, force_deep_copy);
}
}
}
private void MoveTreeItem(SupportConceptGoalTreeItem child, SupportConceptGoalTreeItem parent)
{
var ex_parent = GetParent(child);
if (ex_parent == parent)
return;
// Entferne child aus Ex-Parent
ex_parent.Items.Remove(child);
// Füge child parent hinzu
parent.Items.Add(child);
// Setze child Parent Entry
parent.GoalEntryDC = parent.GoalEntryVM.CommitToDataContract();
child.GoalEntryVM.ParentEntry = parent.GoalEntryDC;
child.ParentGoal = parent;
//CopyTreeItem(parent, child, true);
//DeleteIndividualGoal(child);
}
private SupportConceptGoalTreeItem GetNearestContainer(UIElement element)
{
TreeViewItem container = element as TreeViewItem;
while ((container == null) && (element != null))
{
element = VisualTreeHelper.GetParent(element) as UIElement;
container = element as TreeViewItem;
}
return container?.DataContext as SupportConceptGoalTreeItem;
}
private bool CheckDropTarget(SupportConceptGoalTreeItem _sourceItem, SupportConceptGoalTreeItem _targetItem)
{
if (_sourceItem == null || _targetItem == null)
return false;
if (_targetItem.Items.Contains(_sourceItem))
return false;
if (FindAncestor(_sourceItem, _targetItem))
return false;
return _sourceItem != _targetItem;
}
private bool ContainsTreeItem(SupportConceptGoalTreeItem root, SupportConceptGoalTreeItem item)
{
if (root == item)
return true;
if (root.Items is object && root.Items.Any())
foreach (var child in root.Items)
{
if (ContainsTreeItem(child, item))
return true;
}
return false;
}
private bool FindAncestor(SupportConceptGoalTreeItem ancestor, SupportConceptGoalTreeItem child)
{
if (child == null || ancestor == null)
return false;
var parent = GetParent(child);
if (parent is object)
return parent == ancestor || FindAncestor(ancestor, parent);
return false;
}
private SupportConceptGoalTreeItem GetParent(SupportConceptGoalTreeItem lostchild)
{
if (lostchild.ParentGoal is SupportConceptGoalTreeItem item)
return item;
return null;
throw new IndexOutOfRangeException("#3432432431a4 - Parent Support Goal Tree Item not found");
}
private bool FindParent(SupportConceptGoalTreeItem parent, SupportConceptGoalTreeItem current, SupportConceptGoalTreeItem lostchild, out SupportConceptGoalTreeItem foundchild)
{
if (current == lostchild)
{
foundchild = parent;
return true;
}
foreach (var current_child in current.Items)
{
if(FindParent(current, current_child, lostchild, out foundchild))
{
return true;
}
}
foundchild = null;
return false;
}
}