Renames + Bug fix (wiederholtes Tauschen wird nicht geupdatet)

This commit is contained in:
2023-05-22 11:59:43 +02:00
parent 02d276b6e8
commit a0dd8ff853
2 changed files with 59 additions and 78 deletions

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)
{

View File

@@ -154,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;
@@ -212,7 +212,7 @@ namespace BeWo.View.Detail
}
else if (menuitem.Header.Equals("Einfügen"))
{
menuitem.IsEnabled = goal != null && !goal.IsGoal && Bearbeitungsmodus && _CopyItem != null && (_CopyType == MassnahmenTreeCopyType.Node || !ContainsItem(_CopyItem, goal));
menuitem.IsEnabled = goal != null && !goal.IsGoal && Bearbeitungsmodus && _CopyItem != null && (_CopyType == MassnahmenTreeCopyType.Node || !ContainsTreeItem(_CopyItem, goal));
}
else if (menuitem.Header.Equals("Elementbaum kopieren"))
{
@@ -341,7 +341,7 @@ namespace BeWo.View.Detail
private void StartCopyItem(SupportConceptGoalTreeItem _item, SupportConceptGoalTreeItem _copy)
{
if (ContainsItem(_copy, _item))
if (ContainsTreeItem(_copy, _item))
MessageBox.Show("Kopieren in tiefere Ziele/Maßnamhen nicht möglich!");
else
CopyTreeItem(_item, _copy, false);
@@ -349,7 +349,7 @@ namespace BeWo.View.Detail
}
private void StartMoveItem(SupportConceptGoalTreeItem _draggedItem, SupportConceptGoalTreeItem _parent)
{
if (ContainsItem(_draggedItem, _parent))
if (ContainsTreeItem(_draggedItem, _parent))
MessageBox.Show("Kopieren in tiefere Ziele/Maßnamhen nicht möglich!");
else
MoveTreeItem(_draggedItem, _parent);
@@ -407,8 +407,10 @@ namespace BeWo.View.Detail
{
Point currentPosition = e.GetPosition(TreeView);
if ((Math.Abs(currentPosition.X - _lastMouseDown.X) > 0.0) ||
(Math.Abs(currentPosition.Y - _lastMouseDown.Y) > 0.0))
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);
@@ -636,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)
{
@@ -691,17 +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)
@@ -795,7 +788,8 @@ namespace BeWo.View.Detail
beWoWindow.rootGroupBox.Header = viewHeader;
beWoWindow.ShowDialog();
}
public SupportConceptGoalTreeItem AddTreeItem(SupportConceptGoalTreeItem parent, ValueListEntryType valueListEntryType, string description, string abbreviation, string notice)
private SupportConceptGoalTreeItem AddTreeItem(SupportConceptGoalTreeItem parent, ValueListEntryType valueListEntryType, string description, string abbreviation, string notice)
{
if (!valueListEntryType.HasFlag(ValueListEntryType.SupportConceptGoalCategoryType) &&
!valueListEntryType.HasFlag(ValueListEntryType.SupportConceptGoalType))
@@ -825,10 +819,10 @@ namespace BeWo.View.Detail
return newItem;
}
internal void DeleteIndividualGoal(SupportConceptGoalTreeItem selectedItem)
private void DeleteTreeItem(SupportConceptGoalTreeItem selectedItem)
{
_Children2Delete = new List<ValueListEntryDC>();
TraverseCollection(selectedItem);
DeleteTreeItemRec(selectedItem);
var parent = selectedItem.ParentGoal as SupportConceptGoalTreeItem;
if (parent != null && parent.Items != null)
@@ -838,6 +832,17 @@ namespace BeWo.View.Detail
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)
@@ -857,7 +862,7 @@ namespace BeWo.View.Detail
}
private void MoveTreeItem(SupportConceptGoalTreeItem child, SupportConceptGoalTreeItem parent)
{
var ex_parent = FindParent(child);
var ex_parent = GetParent(child);
if (ex_parent == parent)
return;
@@ -871,6 +876,7 @@ namespace BeWo.View.Detail
// Setze child Parent Entry
parent.GoalEntryDC = parent.GoalEntryVM.CommitToDataContract();
child.GoalEntryVM.ParentEntry = parent.GoalEntryDC;
child.ParentGoal = parent;
//CopyTreeItem(parent, child, true);
@@ -892,50 +898,15 @@ namespace BeWo.View.Detail
if (_sourceItem == null || _targetItem == null)
return false;
//Check whether the target item is meeting your condition
if (_targetItem.Items.Contains(_sourceItem))
return false;
var source = _sourceItem as SupportConceptGoalTreeItem;
var target = _targetItem as SupportConceptGoalTreeItem;
if (FindAncestor(_sourceItem, _targetItem))
return false;
bool _isEqual = false;
// Unterschiedlicher Parent
if (!IstGleichesZiel(source.GoalEntryVM, target.GoalEntryVM))
{
_isEqual = true;
}
//if (source.GoalEntryVM.ParentEntry.ValueListEntryOid.Value != target.GoalEntryDC.ValueListEntryOid.Value)
//{
// // Nicht eigener
// if (!IstGleichesZiel(source.GoalEntryVM, target.GoalEntryVM))
// {
// _isEqual = true;
// }
//}
return _isEqual;
return _sourceItem != _targetItem;
}
private bool IstGleichesZiel(ValueListEntryVM ziel1, ValueListEntryVM ziel2)
{
if (ziel1.DataContract.ValueListEntryOid.HasValue && ziel2.DataContract.ValueListEntryOid.HasValue)
{
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))
{
bool test = ziel1.Equals(ziel2);
return ziel1.Description == ziel2.Description;
}
else if (ziel1.ParentEntry == null && ziel2.ParentEntry == null)
{
return ziel1.Description == ziel2.Description;
}
}
return false;
}
private bool ContainsItem(SupportConceptGoalTreeItem root, SupportConceptGoalTreeItem item)
private bool ContainsTreeItem(SupportConceptGoalTreeItem root, SupportConceptGoalTreeItem item)
{
if (root == item)
return true;
@@ -943,26 +914,35 @@ namespace BeWo.View.Detail
if (root.Items is object && root.Items.Any())
foreach (var child in root.Items)
{
if (ContainsItem(child, item))
if (ContainsTreeItem(child, item))
return true;
}
return false;
}
private SupportConceptGoalTreeItem FindParent(SupportConceptGoalTreeItem lostchild)
private bool FindAncestor(SupportConceptGoalTreeItem ancestor, SupportConceptGoalTreeItem child)
{
foreach (var root_goal in GoalTree)
{
if(FindParent(null, root_goal, lostchild, out var found))
{
return found;
}
}
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)