B2025-018 PROMS - Issues with folder order in tree view.
This commit is contained in:
@@ -19,6 +19,7 @@ using System.Drawing;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Linq;
|
||||
|
||||
namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
@@ -143,6 +144,8 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
#endregion
|
||||
#region SortingChildren
|
||||
private static bool IsInManualOrderNullFix = false;
|
||||
|
||||
[NonSerialized]
|
||||
public Csla.SortedBindingList<FolderInfo> _SortedChildFolders;
|
||||
public Csla.SortedBindingList<FolderInfo> SortedChildFolders
|
||||
@@ -151,6 +154,29 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
if (ChildFolders != null)
|
||||
{
|
||||
//B2025-018 Issues with folder order in tree view
|
||||
// if any ChildFolders with a missing Manual Order
|
||||
// set them to the end of the list
|
||||
// use IsInManualOrderNullFix - so, if setting ChildFolders Currently,
|
||||
// do not try to set them (thus creating an infinite loop)
|
||||
if (!IsInManualOrderNullFix && ChildFolders.Any(x => x.ManualOrder == null))
|
||||
{
|
||||
IsInManualOrderNullFix = true;
|
||||
foreach (FolderInfo fi in ChildFolders.Where(x => x.ManualOrder == null))
|
||||
{
|
||||
using (FolderInfo parfolderinfo = FolderInfo.Get(fi.ParentID))
|
||||
{
|
||||
using (Folder fldr = fi.Get())
|
||||
{
|
||||
fldr.ManualOrder = parfolderinfo.NewManualOrder(9999);
|
||||
fldr.Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
RefreshChildFolders();
|
||||
IsInManualOrderNullFix = false;
|
||||
}
|
||||
|
||||
if (_SortedChildFolders == null)
|
||||
{
|
||||
_SortedChildFolders = new SortedBindingList<FolderInfo>(ChildFolders);
|
||||
@@ -166,6 +192,10 @@ namespace VEPROMS.CSLA.Library
|
||||
return _SortedChildFolders;
|
||||
}
|
||||
}
|
||||
|
||||
//B2025-018 Issues with folder order in tree view
|
||||
//Note: this should be called from the parent item
|
||||
//As you want to put this into the sorted order of the parent item
|
||||
public double? NewManualOrder(int index)
|
||||
{
|
||||
double? retval = 1;
|
||||
@@ -174,13 +204,27 @@ namespace VEPROMS.CSLA.Library
|
||||
else if (index == 0)
|
||||
{
|
||||
if (retval >= SortedChildFolders[index].ManualOrder) // If one is too big, then divide first value in half
|
||||
retval = SortedChildFolders[index].ManualOrder / 2;
|
||||
retval = SortedChildFolders[index].ManualOrder / 2.0;
|
||||
}
|
||||
else if (SortedChildFolders.Count > index)
|
||||
{
|
||||
retval += SortedChildFolders[index - 1].ManualOrder; // Just go to the next whole number
|
||||
if (retval >= SortedChildFolders[index].ManualOrder)
|
||||
retval = (SortedChildFolders[index - 1].ManualOrder + SortedChildFolders[index].ManualOrder) / 2;
|
||||
//B2025-018 Issues with folder order in tree view
|
||||
//filter to just items with the same parent
|
||||
//want new order to be halfway between the previous item
|
||||
//and the next ManualOrder
|
||||
var tmp = SortedChildFolders.Where(x => x.ParentID == FolderID);
|
||||
var lbound = SortedChildFolders[index - 1].ManualOrder;
|
||||
var ubound = tmp.OrderBy(y => y.ManualOrder).FirstOrDefault(x => x.ManualOrder > lbound)?.ManualOrder;
|
||||
if (ubound != null)
|
||||
{
|
||||
retval = ((ubound - lbound) / 2.0) + lbound;
|
||||
}
|
||||
else
|
||||
{
|
||||
//in this case, item before is highest for that parent
|
||||
//so just make this 1 more
|
||||
retval = lbound + 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Reference in New Issue
Block a user