init
This commit is contained in:
commit
e124a47765
19374 changed files with 9806149 additions and 0 deletions
122
Kreta.BusinessLogic/Classes/ComboBox/ComboBoxHelper.cs
Normal file
122
Kreta.BusinessLogic/Classes/ComboBox/ComboBoxHelper.cs
Normal file
|
@ -0,0 +1,122 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Kreta.BusinessLogic.Classes.ComboBox
|
||||
{
|
||||
public static class ComboBoxHelper
|
||||
{
|
||||
public static List<GroupComboBoxListItem> ConvertDataToGroup(List<ComboBoxListItem> resourceList, string[] dedicatedOrder = null, bool customThenByOrder = false)
|
||||
{
|
||||
if (dedicatedOrder == null)
|
||||
{
|
||||
dedicatedOrder = new string[0];
|
||||
}
|
||||
var result = new List<GroupComboBoxListItem>();
|
||||
|
||||
var groups = resourceList.OrderBy(a => a.GroupName).Select(a => a.GroupName).Distinct().ToList();
|
||||
|
||||
foreach (var item in dedicatedOrder)
|
||||
{
|
||||
groups.Remove(item);
|
||||
}
|
||||
|
||||
var myOrder = dedicatedOrder.ToList();
|
||||
myOrder.AddRange(groups);
|
||||
|
||||
foreach (var item in resourceList)
|
||||
{
|
||||
int index = myOrder.IndexOf(item.GroupName) + 1;
|
||||
result.Add(new GroupComboBoxListItem { GroupName = item.GroupName, Order = index, Text = item.Text, Value = item.Value });
|
||||
}
|
||||
|
||||
if (customThenByOrder)
|
||||
{
|
||||
result = result.OrderBy(c => c.Order).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
result = result.OrderBy(c => c.Order).ThenBy(c => c.Text).ToList();
|
||||
}
|
||||
foreach (var item in result.GroupBy(x => new { x.Order }).Select(x => x.First()).ToList())
|
||||
{
|
||||
item.First = true;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
public static List<MultipleOrderGroupComboBoxListItem> ConvertDataToGroupWMultipleOrderColumns(List<MultipleOrderComboBoxListItem> resourceList, string[] dedicatedOrder = null, bool customThenByOrder = false)
|
||||
{
|
||||
if (dedicatedOrder == null)
|
||||
{
|
||||
dedicatedOrder = new string[0];
|
||||
}
|
||||
var result = new List<MultipleOrderGroupComboBoxListItem>();
|
||||
var multipleOrderColNumber = 0;
|
||||
|
||||
var groups = resourceList.OrderBy(a => a.GroupName).Select(a => a.GroupName).Distinct().ToList();
|
||||
foreach (var item in dedicatedOrder)
|
||||
{
|
||||
groups.Remove(item);
|
||||
}
|
||||
|
||||
var myOrder = dedicatedOrder.ToList();
|
||||
myOrder.AddRange(groups);
|
||||
|
||||
foreach (var item in resourceList)
|
||||
{
|
||||
int index = myOrder.IndexOf(item.GroupName) + 1;
|
||||
if (item.MultipleOrderParameterArray != null)
|
||||
multipleOrderColNumber = item.MultipleOrderParameterArray.Length;
|
||||
result.Add(new MultipleOrderGroupComboBoxListItem { GroupName = item.GroupName, Order = index, MultipleOrderParameterArray = item.MultipleOrderParameterArray, Text = item.Text, Value = item.Value });
|
||||
}
|
||||
|
||||
if (multipleOrderColNumber > 0)
|
||||
{
|
||||
if (!customThenByOrder)
|
||||
result = result.OrderBy(c => c.Text).ToList();
|
||||
for (int i = multipleOrderColNumber - 1; i >= 0; i--)
|
||||
{
|
||||
result = result.OrderBy(c => c.MultipleOrderParameterArray[i]).ToList();
|
||||
}
|
||||
result = result.OrderBy(c => c.Order).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
result = result.OrderBy(c => c.Order).ThenBy(c => c.Text).ToList();
|
||||
}
|
||||
foreach (var item in result.GroupBy(x => new { x.Order }).Select(x => x.First()).ToList())
|
||||
{
|
||||
item.First = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public class MultipleOrderComboBoxListItem : ComboBoxListItem
|
||||
{
|
||||
public string[] MultipleOrderParameterArray { get; set; }
|
||||
}
|
||||
public class MultipleOrderGroupComboBoxListItem : GroupComboBoxListItem
|
||||
{
|
||||
public string[] MultipleOrderParameterArray { get; set; }
|
||||
}
|
||||
public class GroupComboBoxListItem : ComboBoxListItem
|
||||
{
|
||||
public int Order { get; set; }
|
||||
public bool First { get; set; }
|
||||
}
|
||||
|
||||
public class ComboBoxListItem
|
||||
{
|
||||
public string Value { get; set; }
|
||||
public string Text { get; set; }
|
||||
public string GroupName { get; set; }
|
||||
}
|
||||
|
||||
public class ComboListGroup
|
||||
{
|
||||
public bool Disabled { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue