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 DeleteCombinationsDataByList(List List, List FBILLNO) { foreach (var item in FBILLNO) { List.RemoveAll(t => t.FBIllNO.Contains(item)); } return List; } public static List GetCombinationsDataByList(List List, double FAllAmount, int FClient) { return List.Where(t => t.FALLAMOUNT == FAllAmount && t.FClient2.Contains(FClient)).ToList(); } public static List GetCombinationsDataByListTK(List 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(); } return TestList; } public static List GetCombinationsDataByList2(List List, double FAllAmount,int FClient) { return List.Where(t => t.FALLAMOUNT == FAllAmount && t.FBIllNO.Count == 1 && t.FClient2[0].Equals(FClient)).ToList(); } /// /// 计算取值 /// /// /// /// /// /// public static void GetCombinations(List List, int index, List FBILLNOLIST, List FClient, ref List result, double FAllAmount) { var FBILLNOLIST2 = new List(FBILLNOLIST); var FClient2 = new List(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(FBILLNOLIST2); DataItem.FClient2 = new List(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(FBILLNOLIST); } } /// /// 计算取值 /// /// /// /// /// /// public static void GetCombinations2(List List, int index, List FBILLNOLIST, List FClient, ref List result, double FAllAmount) { var FBILLNOLIST2 = new List(FBILLNOLIST); var FClient2 = new List(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(FBILLNOLIST2); DataItem.FClient2 = new List(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(FBILLNOLIST); } } public static List> GetCombinations2(T[] array) { List FAllmount = new List(); List FDaySum = new List(); List> result = new List>(); Combine2(array, 0, new List(), FAllmount, FDaySum, ref result); return result; } static void Combine2(T[] array, int index, List combination, List FAllmount, List FDaySum, ref List> 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(combination)); } } public static List GetCombinations(List array) { List result = new List(); List FIDList = new List(); List FEntryList = new List(); List FAllmount = new List(); List FDaySum = new List(); Combine(array, 0, new List(), FIDList, FEntryList, FAllmount, FDaySum, ref result); return result; } static void Combine(List array, int index, List combination, List FIDList, List FEntryList, List FAllmount, List FDaySum, ref List 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() }); //} } /// /// 计算两日期天数差 /// /// /// /// public static int CulDayByDate(DateTime date1, DateTime date2) { TimeSpan difference = date2.Subtract(date1); return difference.Days; } } }