193 lines
7.3 KiB
C#
193 lines
7.3 KiB
C#
|
using Kingdee.BOS.Util;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace Pilot_KD_Parino.Common
|
|||
|
{
|
|||
|
public class CombinationGenerator
|
|||
|
{
|
|||
|
|
|||
|
|
|||
|
public static List<DataItem> DeleteCombinationsDataByList(List<DataItem> List, List<string> FBILLNO)
|
|||
|
{
|
|||
|
foreach (var item in FBILLNO)
|
|||
|
{
|
|||
|
List.RemoveAll(t => t.FBIllNO.Contains(item));
|
|||
|
}
|
|||
|
return List;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
public static List<DataItem> GetCombinationsDataByList(List<DataItem> List, double FAllAmount, int FClient)
|
|||
|
{
|
|||
|
return List.Where(t => t.FALLAMOUNT == FAllAmount && t.FClient2.Contains(FClient)).ToList();
|
|||
|
}
|
|||
|
|
|||
|
public static List<DataItem> GetCombinationsDataByListTK(List<DataItem> List, double FAllAmount, int FClient)
|
|||
|
{
|
|||
|
var TestList = List.Where(t => t.FALLAMOUNT == FAllAmount && t.FClient2.Contains(FClient)).ToList();
|
|||
|
foreach (var item in TestList)
|
|||
|
{
|
|||
|
var fbnumber = item.FBIllNO;
|
|||
|
item.FBIllNO2 = fbnumber;
|
|||
|
item.FBIllNO = new List<string>();
|
|||
|
}
|
|||
|
return TestList;
|
|||
|
}
|
|||
|
|
|||
|
public static List<DataItem> GetCombinationsDataByList2(List<DataItem> List, double FAllAmount,int FClient)
|
|||
|
{
|
|||
|
return List.Where(t => t.FALLAMOUNT == FAllAmount && t.FBIllNO.Count == 1 && t.FClient2[0].Equals(FClient)).ToList();
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 计算取值
|
|||
|
/// </summary>
|
|||
|
/// <param name="List"></param>
|
|||
|
/// <param name="index"></param>
|
|||
|
/// <param name="FBILLNOLIST"></param>
|
|||
|
/// <param name="result"></param>
|
|||
|
/// <param name="FAllAmount"></param>
|
|||
|
public static void GetCombinations(List<CombinaClass> List, int index, List<string> FBILLNOLIST, List<int> FClient, ref List<DataItem> result, double FAllAmount)
|
|||
|
{
|
|||
|
var FBILLNOLIST2 = new List<string>(FBILLNOLIST);
|
|||
|
var FClient2 = new List<int>(FClient);
|
|||
|
var item = List.GroupBy(a => a.FClient).ToList();
|
|||
|
|
|||
|
for (int i = index; i < List.Count; i++)
|
|||
|
{
|
|||
|
FBILLNOLIST2.Add(List[i].FBIllNO);
|
|||
|
FClient2.Add(List[i].FClient);
|
|||
|
DataItem DataItem = new DataItem();
|
|||
|
DataItem.FBIllNO = new List<string>(FBILLNOLIST2);
|
|||
|
DataItem.FClient2 = new List<int>(FClient2);
|
|||
|
DataItem.FALLAMOUNT = FAllAmount + List[i].FALLAMOUNT;
|
|||
|
result.Add(DataItem);
|
|||
|
if (i < 9)
|
|||
|
{
|
|||
|
GetCombinations(List, i + 1, FBILLNOLIST2, FClient2, ref result, FAllAmount + List[i].FALLAMOUNT);
|
|||
|
}
|
|||
|
FBILLNOLIST2 = new List<string>(FBILLNOLIST);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 计算取值
|
|||
|
/// </summary>
|
|||
|
/// <param name="List"></param>
|
|||
|
/// <param name="index"></param>
|
|||
|
/// <param name="FBILLNOLIST"></param>
|
|||
|
/// <param name="result"></param>
|
|||
|
/// <param name="FAllAmount"></param>
|
|||
|
public static void GetCombinations2(List<CombinaClass> List, int index, List<string> FBILLNOLIST, List<int> FClient, ref List<DataItem> result, double FAllAmount)
|
|||
|
{
|
|||
|
var FBILLNOLIST2 = new List<string>(FBILLNOLIST);
|
|||
|
var FClient2 = new List<int>(FClient);
|
|||
|
var item = List.GroupBy(a => a.FClient).ToList();
|
|||
|
|
|||
|
for (int i = index; i < List.Count; i++)
|
|||
|
{
|
|||
|
FBILLNOLIST2.Add(List[i].FBIllNO);
|
|||
|
FClient2.Add(List[i].FClient);
|
|||
|
DataItem DataItem = new DataItem();
|
|||
|
DataItem.FBIllNO = new List<string>(FBILLNOLIST2);
|
|||
|
DataItem.FClient2 = new List<int>(FClient2);
|
|||
|
DataItem.FALLAMOUNT = FAllAmount + List[i].FDAMOUNT;
|
|||
|
result.Add(DataItem);
|
|||
|
if (i < 10)
|
|||
|
{
|
|||
|
GetCombinations2(List, i + 1, FBILLNOLIST2, FClient2, ref result, FAllAmount + List[i].FDAMOUNT);
|
|||
|
}
|
|||
|
FBILLNOLIST2 = new List<string>(FBILLNOLIST);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
public static List<List<T>> GetCombinations2<T>(T[] array)
|
|||
|
{
|
|||
|
List<double> FAllmount = new List<double>();
|
|||
|
List<int> FDaySum = new List<int>();
|
|||
|
List<List<T>> result = new List<List<T>>();
|
|||
|
Combine2(array, 0, new List<T>(), FAllmount, FDaySum, ref result);
|
|||
|
return result;
|
|||
|
}
|
|||
|
|
|||
|
static void Combine2<T>(T[] array, int index, List<T> combination, List<double> FAllmount, List<int> FDaySum, ref List<List<T>> result)
|
|||
|
{
|
|||
|
for (int i = index; i < array.Length; i++)
|
|||
|
{
|
|||
|
|
|||
|
combination.Add(array[i]);
|
|||
|
Combine2(array, i + 1, combination, FAllmount, FDaySum, ref result);
|
|||
|
combination.RemoveAt(combination.Count - 1); // 回溯
|
|||
|
}
|
|||
|
if (combination.Count > 0)
|
|||
|
{
|
|||
|
result.Add(new List<T>(combination));
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
public static List<string[]> GetCombinations(List<string[]> array)
|
|||
|
{
|
|||
|
List<string[]> result = new List<string[]>();
|
|||
|
List<string> FIDList = new List<string>();
|
|||
|
List<string> FEntryList = new List<string>();
|
|||
|
List<double> FAllmount = new List<double>();
|
|||
|
List<int> FDaySum = new List<int>();
|
|||
|
Combine(array, 0, new List<string[]>(), FIDList, FEntryList, FAllmount, FDaySum, ref result);
|
|||
|
return result;
|
|||
|
}
|
|||
|
|
|||
|
static void Combine(List<string[]> array, int index, List<string[]> combination, List<string> FIDList, List<string> FEntryList,
|
|||
|
List<double> FAllmount, List<int> FDaySum, ref List<string[]> result)
|
|||
|
{
|
|||
|
for (int i = index; i < array.Count; i++)
|
|||
|
{
|
|||
|
FIDList.Add(Convert.ToString(array[i][0]));
|
|||
|
FEntryList.Add(Convert.ToString(array[i][3]));
|
|||
|
FAllmount.Add(Convert.ToDouble(array[i][2]));
|
|||
|
FDaySum.Add(CulDayByDate(Convert.ToDateTime(array[i][1]), DateTime.Now));
|
|||
|
combination.Add(new string[4] { string.Join("-", FIDList), string.Join("-", FEntryList), "0", "0" });
|
|||
|
Combine(array, i + 1, combination, FIDList, FEntryList, FAllmount, FDaySum, ref result);
|
|||
|
//FIDList.RemoveAt(FIDList.Count - 1); // 回溯
|
|||
|
//FEntryList.RemoveAt(FEntryList.Count - 1); // 回溯
|
|||
|
//FAllmount.RemoveAt(combination.Count - 1); // 回溯
|
|||
|
//FDaySum.RemoveAt(FDaySum.Count - 1); // 回溯
|
|||
|
combination.RemoveAt(combination.Count - 1); // 回溯
|
|||
|
}
|
|||
|
//if (FIDList.Count > 0)
|
|||
|
//{
|
|||
|
result.Add(new string[4] { string.Join("-", FIDList), string.Join("-", FEntryList), FAllmount.Sum().ToString(), FDaySum.Sum().ToString() });
|
|||
|
//}
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 计算两日期天数差
|
|||
|
/// </summary>
|
|||
|
/// <param name="date1"></param>
|
|||
|
/// <param name="date2"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public static int CulDayByDate(DateTime date1, DateTime date2)
|
|||
|
{
|
|||
|
TimeSpan difference = date2.Subtract(date1);
|
|||
|
return difference.Days;
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
}
|