//组选6中奖判断 public static string DisorderSix(int[] Boon, int[] Choose) { int numberWin = 0; //标记选中的号码个数 int n = Boon.Length; //选号的组合方式 List <int[]> ListCombination = PermutationAndCombination <int> .GetCombination(Choose, 3); //选择Choose中的n排列方式 foreach (int[] arr in ListCombination) { for (int i = 0; i < n; i++) { if (arr[i] == Boon[i]) { numberWin += 1; if (numberWin == n) { return("中奖" + "\n(投注数:" + ListCombination.Count + ")"); } } } numberWin = 0; } return("未中奖" + "\n(投注数:" + ListCombination.Count + ")"); }
public static List <AllDanTuoCombinedModel> CalculateAllDanTuoCombinationModels() { var result = new List <AllDanTuoCombinedModel>(); var dan2List = PermutationAndCombination <int> .GetCombination(SscConst.BetNumbers.ToArray(), 2); foreach (var dan2 in dan2List) { var rest = SscConst.BetNumbers.ToList(); rest.RemoveAll(x => dan2.Contains(x)); var tuo4List = PermutationAndCombination <int> .GetCombination(rest.ToArray(), 4); foreach (var tuo4 in tuo4List) { var danNums = dan2.ToList(); var tuoNums = tuo4.ToList(); var tmp = GetCombinedDanTuoNos(danNums, tuoNums); var dantuoModels = tmp.Select(model => new DanTuoModel() { DanTuoNums = model, MissingCount = 0 }).ToList(); result.Add(new AllDanTuoCombinedModel() { DanNums = dan2.ToList(), TuoNums = tuo4.ToList(), DanTuoModel = dantuoModels }); } } return(result); }
/// <summary> /// 暴力搜索 /// </summary> /// <param name="sodukuString"></param> /// <returns></returns> private string ForceSearch(string sodukuString) { var list = StaticTools.GetSubString(sodukuString); var index = 1; foreach (var subString in list) { Console.WriteLine("处理字符串 " + index + " " + subString); index += 1; var market = new SudokuMarket(subString); var result = market.GetCellInfos().Where(c => c.Value.Value == 0). Select(c1 => c1.Value).ToList(); Dictionary <int, List <int> > locationRest = new Dictionary <int, List <int> >(); foreach (var cell in result) { locationRest.Add(cell.location, cell.initrest); } var locationcombine = PermutationAndCombination <int> .GetCombination(locationRest.Keys.ToArray(), 2); foreach (var combine in locationcombine) { var location1 = combine[0]; var location2 = combine[1]; var rest1 = locationRest[location1]; var rest2 = locationRest[location2]; foreach (var value1 in rest1) { Dictionary <int, string> one = new Dictionary <int, string> { { location1, "" + value1 } }; if (new DanceLink().solution_count(StaticTools.SetValues(sodukuString, one)) > 0) { foreach (var value2 in rest2) { Dictionary <int, string> two = new Dictionary <int, string> { { location1, "" + value1 }, { location2, "" + value2 } }; var result1 = StaticTools.SetValues(sodukuString, two); if (StaticTools.IsPearl(result1)) { string dir = AppDomain.CurrentDomain.BaseDirectory; var noticeCount = StaticTools.GetLocations(result1).Count; string configName = Path.Combine(dir, "提示数个数" + noticeCount + "生成于" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt"); File.WriteAllText(configName, result1); Console.WriteLine("当前表达式为:" + result1 + "提示数个数为:" + noticeCount); return(result1); } } } } } } return(""); }
/// <summary> /// 前二三任选玩法中奖判断 /// </summary> /// <param name="Boon"></param> /// <param name="Choose"></param> /// <param name="n"></param> /// <returns></returns> public static string Judge_Predisorder_2to3(int[] Boon, int[] Choose, int n) { int numberWin = 0; //标记选中的号码个数 int chooseWin = 0; //中奖注数 List <int[]> ListCombination = PermutationAndCombination <int> .GetCombination(Choose, n); //选择Choose中的n排列方式 foreach (int[] arr in ListCombination) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (arr[i] == Boon[j]) { numberWin += 1; if (numberWin == n) { chooseWin += 1; numberWin = 0; } } } } numberWin = 0; } return(chooseWin > 0 ? "中奖" + chooseWin.ToString() + "注" + "\n(投注数:" + ListCombination.Count + ")" : "未中奖" + "\n(投注数:" + ListCombination.Count + ")"); }
public void CombinationTest() { List <string> list = new List <string> { "a", "bb", "ccc" }; int count = 2; int process = 0; List <string[]> ret = PermutationAndCombination <string> .GetCombination(list.ToArray(), count); // List<List<string>> comList = new List<List<string>>(); // foreach(string str in list){ // List<string> inList = new List<string>(); // inList.Add(str); // inList.AddRange(ret[process]); // } foreach (string[] strArr in ret) { StringBuilder sb = new StringBuilder("["); foreach (string str in strArr) { sb.Append(str); } sb.Append("]"); Debug.Log("comb=" + sb.ToString()); } }
public static List <List <int> > CombineDanTuoNo(List <int> danList, List <int> tuoList) { //danList.Sort(); //tuoList.Sort(); //danList.Reverse(); //tuoList.Reverse(); var combinedList = new List <List <int> >(); var a2 = PermutationAndCombination <int> .GetCombination(tuoList.ToArray(), 2); var a3 = PermutationAndCombination <int> .GetCombination(tuoList.ToArray(), 3); var a4 = PermutationAndCombination <int> .GetCombination(tuoList.ToArray(), 4); var danListCopy = danList.ToList(); danListCopy.Reverse(); //防止倒叙 var d1 = PermutationAndCombination <int> .GetCombination(danListCopy.ToArray(), 1); var d2 = PermutationAndCombination <int> .GetCombination(danList.ToArray(), 2); var finalDan = new List <int[]>(); finalDan.AddRange(d1); finalDan.AddRange(d2); foreach (var danArray in finalDan) { var dan = new List <int>(); foreach (var a in danArray) { dan.Add(a); } foreach (var tuo in a2) { var t = new List <int>(); t.AddRange(dan); t.AddRange(tuo); combinedList.Add(t); } foreach (var tuo in a3) { var t = new List <int>(); t.AddRange(dan); t.AddRange(tuo); combinedList.Add(t); } if (dan.Count == 1) { foreach (var tuo in a4) { var t = new List <int>(); t.AddRange(dan); t.AddRange(tuo); combinedList.Add(t); } } } return(combinedList); }
/// <summary> /// 将数独指定位置的数进行交换构成标准数独。 /// /// </summary> /// <example> /// new ComfirmedPostion().GenConfirmedPosition(StaticTools.ListToString(sodukuMatrix)); /// </example> /// <param name="sodukuString"></param> public string GenSudoku(string sodukuString, string fileName = "") { var matrix = StaticTools.StringToList(sodukuString); Console.WriteLine(sodukuString); var list = StaticTools.GetLocations(matrix); Console.WriteLine(JsonConvert.SerializeObject(list)); var switchList = PermutationAndCombination <int> .GetCombination(list.ToArray(), 2); //switchList.Reverse(); Console.WriteLine("list" + list.Count); Console.WriteLine("switchList" + switchList.Count); Dictionary <string, int> expressCount = new Dictionary <string, int>(); List <string> tryedList = new List <string> { sodukuString }; var min = GetMinCount(sodukuString, expressCount, switchList); while (min != 1) { var result = (from item1 in expressCount where !(tryedList.Any(item2 => item2 == item1.Key)) select item1).Where(c => c.Value != 0).ToList(); if (result.Count == 0) { //所有该尝试的组合都已经尝试过了 //表明已知提示数在固定位置的确无法构成唯一解。 return(null); } var newSeed = result.OrderBy(c => c.Value).Last(); var newMin = result.OrderBy(c => c.Value).First(); if (true) { Console.WriteLine(fileName + "最少的终盘个数: " + newMin.Value + "表达式为 " + newMin.Key + " 最多的终盘个数: " + newSeed.Value + "表达式为 " + newSeed.Key); } min = GetMinCount(newSeed.Key, expressCount, switchList); tryedList.Add(newSeed.Key); } string Value = expressCount.Where(c => c.Value == 1).Select(c => c.Key).First(); string dir = AppDomain.CurrentDomain.BaseDirectory; var noticeCount = StaticTools.GetLocations(Value).Count; string configName = Path.Combine(dir, fileName + "生成于" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt"); File.WriteAllText(configName, Value); return(Value); }
private List <string[]>[] GetAllCustomVariants(string[] keywords) { List <string[]>[] result = new List <string[]> [keywords.Length]; for (int i = 0; i < keywords.Length; i++) { result[i] = PermutationAndCombination <string> .GetCombination(keywords, i + 1); } return(result); }
public void Call_test() { int[] arr = new int[6]; for (int i = 0; i < arr.Length; i++) { arr[i] = i + 1; } //求排列 List <int[]> lst_Permutation = PermutationAndCombination <int> .GetPermutation(arr, 3); //求组合 List <int[]> lst_Combination = PermutationAndCombination <int> .GetCombination(arr, 3); }
public static List <List <int> > CombineBetNo(List <int> danList, List <int> tuoList) { var combinedList = CombineDanTuoNo(danList, tuoList); var combinedBet = new List <List <int> >(); var leftList = new List <int>(); leftList.AddRange(SscConst.BetNumbers); danList.ForEach(a => leftList.Remove(a)); tuoList.ForEach(a => leftList.Remove(a)); var left1 = PermutationAndCombination <int> .GetCombination(leftList.ToArray(), 1); var left2 = PermutationAndCombination <int> .GetCombination(leftList.ToArray(), 2); foreach (var tempCombined in combinedList) { if (tempCombined.Count == 3) { foreach (var add in left2) { var bet = new List <int>(); bet.AddRange(tempCombined); bet.AddRange(add); combinedBet.Add(bet); } } else if (tempCombined.Count == 4) { foreach (var add in left1) { var bet = new List <int>(); bet.AddRange(tempCombined); bet.AddRange(add); combinedBet.Add(bet); } } else { //var j = new List<string>(); //tempCombined.ForEach(t => j.Add(t.ToString())); //var s = string.Join(",", j.ToArray()); //Console.WriteLine("---------{0}>>{1}",tempCombined.Count,s); var bet = new List <int>(); bet.AddRange(tempCombined); combinedBet.Add(bet); } } combinedBet.Reverse(); return(combinedBet); }
/// <summary> /// 初始化路径码 /// </summary> public bool InitPathCode() { using (var scope = _dbContextScopeFactory.Create()) { var db = scope.DbContexts.Get <JuCheapContext>(); var dbSet = db.Set <PathCodeEntity>(); //生成路径码 var codes = new List <string>(26); for (int i = 65; i <= 90; i++) { codes.Add(((char)i).ToString()); } int len = 2; //求组合 List <string[]> ermutation = PermutationAndCombination <string> .GetCombination(codes.ToArray(), len); List <PathCodeEntity> list = new List <PathCodeEntity>(); ermutation.ForEach(item => { list.Add(new PathCodeEntity { Id = _instance.GetId(), Code = string.Join(string.Empty, item), Len = len }); list.Add(new PathCodeEntity { Id = _instance.GetId(), Code = string.Join(string.Empty, item.Reverse()), Len = len }); }); Func <IEnumerable <PathCodeEntity> > getSameKeyFunc = () => { return(codes.Select(key => new PathCodeEntity { Id = _instance.GetId(), Code = string.Join(string.Empty, key, key), Len = len })); }; list.AddRange(getSameKeyFunc()); list = list.OrderBy(item => item.Code).ToList(); db.Database.ExecuteSqlCommand("DELETE FROM PathCodes"); dbSet.AddRange(list); return(scope.SaveChanges() > 0); } }
//组合3中奖判断: 组合数另外计算 listSum public static string DisorderThree(int[] Boon, int[] Choose) { int numberWin = 0; //标记选中的号码个数 int n = Boon.Length; //选号的组合方式 List <int[]> ListCombination = PermutationAndCombination <int> .GetCombination(Choose, 2); //组三的复注选号列表 List <int[]> listSum = new List <int[]>(new int { }); List <int[]> ListThree = PermutationAndCombination <int> .GetPermutation(Choose, 2); foreach (int [] list in ListThree) { int[] listCopy = new int[] { list[0], list[0], list[1] }; listSum.Add(listCopy); } Console.WriteLine(listSum.Count); //组三中奖,若开奖号未出现重号,则不可能开出组三奖 bool signThree = (Boon[0] - Boon[1]) == 0 || (Boon[0] - Boon[2]) == 0; if (signThree == true) { return("未中奖" + "\n(投注数:" + ListCombination.Count * 2 + ")"); } //组三中奖判断,用组合2的顺序,逐个对应中奖号的百位,十位,个位 foreach (int[] arr in ListCombination) { for (int i = 0; i < n; i++) { for (int j = 0; j < 2; j++) { if (arr[j] == Boon[i]) { numberWin += 1; } if (numberWin == n) { return("中奖" + "\n(投注数:" + listSum.Count + ")"); } } numberWin = 0; } } return("未中奖" + "\n(投注数:" + listSum.Count + ")"); }
/// <summary> /// 获取路径码 /// </summary> /// <returns></returns> public static List <PathCodeEntity> GetPathCodes() { var instance = BaseIdGenerator.Instance; //生成路径码 var codes = new List <string>(26); for (var i = 65; i <= 90; i++) { codes.Add(((char)i).ToString()); } const int len = 2; //求组合 var ermutation = PermutationAndCombination <string> .GetCombination(codes.ToArray(), len); var list = new List <PathCodeEntity>(); ermutation.ForEach(item => { list.Add(new PathCodeEntity { Id = instance.GetId(), Code = string.Join(string.Empty, item), Len = len }); list.Add(new PathCodeEntity { Id = instance.GetId(), Code = string.Join(string.Empty, item.Reverse()), Len = len }); }); Func <IEnumerable <PathCodeEntity> > getSameKeyFunc = () => { return(codes.Select(key => new PathCodeEntity { Id = instance.GetId(), Code = string.Join(string.Empty, key, key), Len = len })); }; list.AddRange(getSameKeyFunc()); list = list.OrderBy(item => item.Code).ToList(); return(list); }
private string GetPureGene(string oneAnswer, string clues, IEnumerable <int> pure) { var choose = 2; var ints = PermutationAndCombination <int> .GetCombination(pure.ToArray(), choose); //Console.WriteLine("组合元素个数 " + pure.Count()); //Console.WriteLine("choose " + choose); //Console.WriteLine("组合个数 " + ints.Count); var locations = StaticTools.GetLocations(clues); int computedCount = 0; int index = 0; foreach (var t in ints) { var newClues = StaticTools.SetZero(oneAnswer, StaticTools.allLocations.Except(t.Union(locations))); computedCount += 1; if (computedCount == 10000) { index += 1; computedCount = 0; Console.WriteLine("已处理 " + index + "万条数据" + DateTime.Now); } if (StaticTools.IsPearl(newClues)) { var result = newClues; return(result); } } return(""); }
//public Point3D<double> BasePos { get; set; } //public PositionOffset DeltaPos { get; set; } /////// <summary> /////// 教导点 /////// </summary> ////public Dictionary<int,Point3D<double>> TeachPos { get; set; } /////// <summary> /////// 盘格编号位置 /////// </summary> ////public Dictionary <int,Index> TeachPoint { get; set; } //public ArrayCal() //{ // //TeachPos = new Dictionary<int, Point3D<double>>(); // //TeachPoint = new Dictionary<int, Index>(); //} /// <summary> /// 计算基准坐标,及各项偏差值 /// </summary> /// <param name="TeachPos">教导坐标集合</param> /// <param name="TrayPoint">Tray盘点阵标记值集合</param> /// <returns></returns> public static PositionOffset?BaseCalculate(Dictionary <int, Point3D <double> > TeachPos, Dictionary <int, Index> TrayPoint) { //判断教导点数量是否大于等于3,否则计算失败! if (TeachPos.Count < 3) { return(null); } int[] keys = new int[TeachPos.Count]; var i = 0; foreach (var key in TrayPoint.Keys) { keys[i] = key; i++; } try { //排列组合计算 List <int[]> ListCombination = PermutationAndCombination <int> .GetCombination(keys, 3); List <int[]> ListSave = new List <int[]>(); //找出任意三点不在同一直线上的项 foreach (var list in ListCombination) { var Ra = TrayPoint[list[0]].Row - TrayPoint[list[1]].Row; var Rb = TrayPoint[list[0]].Row - TrayPoint[list[2]].Row; var Ca = TrayPoint[list[0]].Col - TrayPoint[list[1]].Col; var Cb = TrayPoint[list[0]].Col - TrayPoint[list[2]].Col; if (Ra != Rb && Ca != Cb) { ListSave.Add(list); } } if (ListSave.Count < 1) { return(null); } PositionOffset[] PosOffset = new PositionOffset[ListSave.Count]; var j = 0; foreach (var list in ListSave) { //X2-X1=(a2-a1)Cxf+(b2-b1)Rxf //X3-X1=(a3-a1)Cxf+(b3-b1)Rxf //Y2-Y1=(a2-a1)Cyf+(b2-b1)Ryf //Y3-Y1=(a3-a1)Cyf+(b3-b1)Ryf //若a2-a1==0 var DeltaRa = TrayPoint[list[1]].Row - TrayPoint[list[0]].Row; //若b2-b1==0 var DeltaRb = TrayPoint[list[1]].Col - TrayPoint[list[0]].Col; //若a3-a1==0 var DeltaCa = TrayPoint[list[2]].Row - TrayPoint[list[0]].Row; //若b3-b1==0 var DeltaCb = TrayPoint[list[2]].Col - TrayPoint[list[0]].Col; //若a2-a1==0 if (DeltaRa == 0 && DeltaRb != 0 && DeltaCa != 0 && DeltaCb != 0) { PosOffset[j].Cxf = (TeachPos[list[1]].X - TeachPos[list[0]].X) / DeltaRb; PosOffset[j].Cyf = (TeachPos[list[1]].Y - TeachPos[list[0]].Y) / DeltaRb; PosOffset[j].Rxf = (TeachPos[list[2]].X - TeachPos[list[0]].X - PosOffset[j].Cxf * DeltaCb) / DeltaCa; PosOffset[j].Ryf = (TeachPos[list[2]].Y - TeachPos[list[0]].Y - PosOffset[j].Cyf * DeltaCb) / DeltaCa; } //若b2-b1==0 if (DeltaRa != 0 && DeltaRb == 0 && DeltaCa != 0 && DeltaCb != 0) { PosOffset[j].Rxf = (TeachPos[list[1]].X - TeachPos[list[0]].X) / DeltaRa; PosOffset[j].Ryf = (TeachPos[list[1]].Y - TeachPos[list[0]].Y) / DeltaRa; PosOffset[j].Cxf = (TeachPos[list[2]].X - TeachPos[list[0]].X - PosOffset[j].Rxf * DeltaCa) / DeltaCb; PosOffset[j].Cyf = (TeachPos[list[2]].Y - TeachPos[list[0]].Y - PosOffset[j].Ryf * DeltaCa) / DeltaCb; } //若a3-a1==0 if (DeltaRa != 0 && DeltaRb != 0 && DeltaCa == 0 && DeltaCb != 0) { PosOffset[j].Cxf = (TeachPos[list[2]].X - TeachPos[list[0]].X) / DeltaCb; PosOffset[j].Cyf = (TeachPos[list[2]].Y - TeachPos[list[0]].Y) / DeltaCb; PosOffset[j].Rxf = (TeachPos[list[1]].X - TeachPos[list[0]].X - PosOffset[j].Cxf * DeltaRb) / DeltaRa; PosOffset[j].Ryf = (TeachPos[list[1]].Y - TeachPos[list[0]].Y - PosOffset[j].Cyf * DeltaRb) / DeltaRa; } //若b3-b1==0 if (DeltaRa != 0 && DeltaRb != 0 && DeltaCa != 0 && DeltaCb == 0) { PosOffset[j].Rxf = (TeachPos[list[2]].X - TeachPos[list[0]].X) / DeltaCa; PosOffset[j].Ryf = (TeachPos[list[2]].Y - TeachPos[list[0]].Y) / DeltaCa; PosOffset[j].Cxf = (TeachPos[list[1]].X - TeachPos[list[0]].X - PosOffset[j].Rxf * DeltaRa) / DeltaRb; PosOffset[j].Cyf = (TeachPos[list[1]].Y - TeachPos[list[0]].Y - PosOffset[j].Ryf * DeltaRa) / DeltaRb; } //若a2-a1!=0、b2-b1!=0、a3-a1!=0、b3-b1!=0 if (DeltaRa != 0 && DeltaRb != 0 && DeltaCa != 0 && DeltaCb != 0) { var NumeratorX = (TeachPos[list[2]].X - TeachPos[list[0]].X) * DeltaRa - (TeachPos[list[1]].X - TeachPos[list[0]].X) * DeltaCa; var NumeratorY = (TeachPos[list[2]].Y - TeachPos[list[0]].Y) * DeltaRa - (TeachPos[list[1]].Y - TeachPos[list[0]].Y) * DeltaCa; var Denominator = DeltaRa * DeltaCb - DeltaCa * DeltaRb; PosOffset[j].Cxf = NumeratorX / Denominator; PosOffset[j].Cyf = NumeratorY / Denominator; PosOffset[j].Rxf = (TeachPos[list[1]].X - TeachPos[list[0]].X - PosOffset[j].Cxf * DeltaRb) / DeltaRa; PosOffset[j].Ryf = (TeachPos[list[1]].Y - TeachPos[list[0]].Y - PosOffset[j].Cyf * DeltaRb) / DeltaRa; } //计算出起始点坐标 PosOffset[j].BasePos.X = TeachPos[list[0]].X - TrayPoint[list[0]].Row * PosOffset[j].Rxf - TrayPoint[list[0]].Col * PosOffset[j].Cxf; PosOffset[j].BasePos.Y = TeachPos[list[0]].Y - TrayPoint[list[0]].Row * PosOffset[j].Ryf - TrayPoint[list[0]].Col * PosOffset[j].Cyf; PosOffset[j].BasePos.Z = TeachPos[list[0]].Z; } var Num = ListSave.Count; double TotalRxf = 0, TotalRyf = 0, TotalCxf = 0, TotalCyf = 0; Point3D <double> TotalPos = new Point3D <double>(); for (var k = 0; k < Num; k++) { TotalRxf += PosOffset[k].Rxf; TotalRyf += PosOffset[k].Ryf; TotalCxf += PosOffset[k].Cxf; TotalCyf += PosOffset[k].Cyf; TotalPos.X += PosOffset[k].BasePos.X; TotalPos.Y += PosOffset[k].BasePos.Y; TotalPos.Z += PosOffset[k].BasePos.Z; } //求各项数据的平均值 var Value = new PositionOffset(); Value.Rxf = TotalRxf / Num; Value.Ryf = TotalRyf / Num; Value.Cxf = TotalCxf / Num; Value.Cyf = TotalCyf / Num; Value.BasePos.X = TotalPos.X / Num; Value.BasePos.Y = TotalPos.Y / Num; Value.BasePos.Z = TotalPos.Z / Num; return(Value); } catch (Exception) { return(null); } }
public void btnOK_Click(object sender, EventArgs e) { #region 检测输入 if (this.cbox.SelectedIndex == 0) { MessageEx.ShowWarning("请选择客户"); return; } if (string.IsNullOrWhiteSpace(this.txtMoney.Text)) { MessageEx.ShowWarning("请输入单注金额"); return; } if (string.IsNullOrWhiteSpace(txtIssue.Text)) { MessageEx.ShowWarning("请输入期号"); return; } if (txtIssue.Text.Trim().Length != 7) { MessageEx.ShowWarning("请输入正确的期号"); return; } #endregion #region 获取输入 Dictionary <int, decimal> list = new Dictionary <int, decimal>(); foreach (var control in this.groupBox2.Controls) { if (control is CheckBox) { var ck = control as CheckBox; if (ck.Checked) { var sdsdsdsd = this.groupBox2.Controls.Find("PL", false); var lb = this.groupBox2.Controls.Find("PL", false).FirstOrDefault(x => x.Tag == ck.Tag); if (lb != null) { var l = lb as Label; list.Add(ck.Tag.ToTryInt(), Convert.ToDecimal(l.Text)); } } } } #endregion if (list.Count < MinCount) { MessageEx.ShowWarning("内容不正确,请重新下注"); } else { Frm.fmConfirmLX fm = new Frm.fmConfirmLX(); #region 创建订单对象 string OrderId = Guid.NewGuid().ToString("n"); //订单主体 var order = new Order <OrderLXLM>() { Create_Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Create_User_Id = "0", Customer_Id = cbox.SelectedValue.ToString().ToTryInt(), Id = OrderId, IsDel = 0, Issue = txtIssue.Text.Trim(), Order_No = ServiceNum.GetOrderNo(), Order_Type = OrderType, Child_Type = ChildType, Update_Time = "", Update_User_Id = "" }; //需要组合的号码 List <int> InCombinationList = new List <int>(); foreach (var item in list) { InCombinationList.Add(item.Key); } //生成号码组合 List <int[]> ListCombination = PermutationAndCombination <int> .GetCombination(InCombinationList.ToArray(), MinCount); //求全部的3-3组合 //根据号码组合创建订单明细 int index = 1; foreach (int[] arr in ListCombination) { OrderLXLM detail = new OrderLXLM(); int childIndex = 0; var str = ""; foreach (int item in arr) { switch (childIndex) { case 0: detail.Code1 = item.ToString(); detail.Zodiac1 = ServiceNum.GetNumZodiac(item); break; case 1: detail.Code2 = item.ToString(); detail.Zodiac2 = ServiceNum.GetNumZodiac(item); break; case 2: detail.Code3 = item.ToString(); detail.Zodiac3 = ServiceNum.GetNumZodiac(item); break; case 3: detail.Code4 = item.ToString(); detail.Zodiac4 = ServiceNum.GetNumZodiac(item); break; case 4: detail.Code5 = item.ToString(); detail.Zodiac5 = ServiceNum.GetNumZodiac(item); break; } str += ServiceNum.GetNumZodiac(item) + "、"; childIndex = childIndex + 1; } detail.Id = Guid.NewGuid().ToString("n"); detail.Sort = index; detail.ChildType = ChildType; detail.Remarks = str.Remove(str.Length - 1, 1); detail.OrderId = OrderId; detail.Odds = GetMinOdds(list, arr.ToList()); detail.InMoney = Convert.ToDecimal(txtMoney.Text); detail.OutMoney = detail.InMoney * detail.Odds; detail.Status = (int)ResultStatus.Wait; detail.Flag = 1; order.OrderDetails.Add(detail); index = index + 1; } order.Total_In_Money = order.OrderDetails.Sum(x => x.InMoney); order.Total_Out_Money = 0.00M; #endregion fm.InitForm(order); if (fm.ShowDialog() == DialogResult.OK) { OrderImpl service = new OrderImpl(); if (service.AddOrderLXLM(order).Code == 0) { MessageEx.Show("下单成功"); btnReset_Click(null, null); } else { MessageEx.Show("下单失败"); } } } }
private void btnOK_Click(object sender, EventArgs e) { var v = 0; var childtype = 0; var pl = 0M; if (radioButton5.Checked) { v = 3; childtype = (int)ChildType.中三; pl = Convert.ToDecimal(lbSZS.Text); } if (radioButton6.Checked) { v = 3; childtype = (int)ChildType.全中; pl = Convert.ToDecimal(lbSQZ.Text); } if (radioButton7.Checked) { v = 2; childtype = (int)ChildType.二全中; pl = Convert.ToDecimal(lbEZE.Text); } if (radioButton8.Checked) { v = 2; childtype = (int)ChildType.特碰; pl = Convert.ToDecimal(lbTP.Text); } //需要组合的号码 List <string> InCombinationList = new List <string>(); #region 获取输入 var controls = this.groupBox3.Controls.Find("CK", false); var r = 0; foreach (var control in controls) { if (control is CheckBox) { var ck = control as CheckBox; if (ck.Checked) { r += 1; var sd = this.groupBox3.Controls.Find("Code", false); var lb = sd.FirstOrDefault(x => x.Tag == ck.Tag); if (lb != null) { var lbCode = lb as Label; InCombinationList.Add(lbCode.Text); } } } } #endregion #region 检测输入 if (!radioButton5.Checked && !radioButton6.Checked && !radioButton7.Checked && !radioButton8.Checked) { MessageEx.ShowWarning("请选择连码类型"); return; } if (cbox.SelectedIndex == 0) { MessageEx.ShowWarning("请选择客户"); return; } if (string.IsNullOrWhiteSpace(txtMoney.Text)) { MessageEx.ShowWarning("请输入金额"); return; } if (r < v) { MessageEx.ShowWarning("内容不正确,请重新选择"); return; } #endregion Frm.fmConfirmLX fm = new Frm.fmConfirmLX(); #region 创建订单对象 string OrderId = Guid.NewGuid().ToString("n"); //订单主体 var order = new Order <OrderLXLM>() { Create_Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Create_User_Id = "0", Customer_Id = cbox.SelectedValue.ToString().ToTryInt(), Id = OrderId, IsDel = 0, Issue = txtIssue.Text.Trim(), Order_No = ServiceNum.GetOrderNo(), Order_Type = (int)OrderType.连码, Child_Type = childtype, Update_Time = "", Update_User_Id = "" }; //生成号码组合 List <string[]> ListCombination = PermutationAndCombination <string> .GetCombination(InCombinationList.ToArray(), v); //求全部的3-3组合 //根据号码组合创建订单明细 int index = 1; foreach (string[] arr in ListCombination) { OrderLXLM detail = new OrderLXLM(); int childIndex = 0; var str = ""; foreach (string item in arr) { switch (childIndex) { case 0: detail.Code1 = item.ToString(); break; case 1: detail.Code2 = item.ToString(); break; case 2: detail.Code3 = item.ToString(); break; case 3: detail.Code4 = item.ToString(); break; } str += item + "、"; childIndex = childIndex + 1; } detail.Id = Guid.NewGuid().ToString("n"); detail.Sort = index; detail.Remarks = str.Remove(str.Length - 1, 1); detail.OrderId = OrderId; detail.Odds = pl; detail.ChildType = childtype; detail.InMoney = Convert.ToDecimal(txtMoney.Text); detail.OutMoney = detail.InMoney * detail.Odds; if (childtype == (int)ChildType.中三) { detail.MinOdds = Convert.ToDecimal(lbSZE.Text); detail.MinOutMoney = detail.InMoney * detail.MinOdds; detail.MaxOdds = pl; detail.MaxOutMoney = detail.InMoney * detail.MaxOdds; } detail.Status = (int)ResultStatus.Wait; detail.Flag = 1; order.OrderDetails.Add(detail); index = index + 1; } order.Total_In_Money = order.OrderDetails.Sum(x => x.InMoney); order.Total_Out_Money = 0.00M; #endregion fm.InitForm(order); if (fm.ShowDialog() == DialogResult.OK) { OrderImpl service = new OrderImpl(); if (service.AddOrderLXLM(order).Code == 0) { MessageEx.Show("下单成功"); } else { MessageEx.Show("下单失败"); } } }
private static void AddDictionary(List <Type> addList) { var dataProcessorBaseType = typeof(DataProcessor); var type = typeof(DictionaryProcessor <, , ,>); var list = new List <Type>(); for (var i = 0; i < addList.Count; i++) { if (!addList[i].HasImplementedRawGeneric(typeof(GenericDataProcessor <>))) { continue; } var memberInfo = addList[i].BaseType; if (memberInfo != null) { list.Add(addList[i]); } } var keyValueList = PermutationAndCombination <Type> .GetCombination(list.ToArray(), 2).ToList(); var reverseList = keyValueList.Select(types => new [] { types[1], types[0] }).ToList(); keyValueList.AddRange(reverseList); foreach (var value in list) { keyValueList.Add(new[] { value, value }); } foreach (var keyValue in keyValueList) { var keyType = keyValue[0].BaseType; var valueType = keyValue[1].BaseType; if (keyType != null && valueType != null) { Type[] typeArgs = { keyValue[0], keyValue[1], keyType.GenericTypeArguments[0], valueType.GenericTypeArguments[0] }; var dictionaryType = type.MakeGenericType(typeArgs); if (dataProcessorBaseType.IsAssignableFrom(dictionaryType)) { var dataProcessor = (DataProcessor)Activator.CreateInstance(dictionaryType); var keyDataProcessor = (DataProcessor)Activator.CreateInstance(keyValue[0]); var valueDataProcessor = (DataProcessor)Activator.CreateInstance(keyValue[1]); foreach (var typeString in dataProcessor.GetTypeStrings()) { foreach (var key in keyDataProcessor.GetTypeStrings()) { foreach (var value in valueDataProcessor.GetTypeStrings()) { var str = Utility.Text.Format(typeString.ToLower(), key, value); s_DataProcessors.Add(str, dataProcessor); } } } } } } }
/// <summary> /// 生成初盘提示数个数为noticeValue的具有唯一解的初盘 /// </summary> /// <param name="wholeSudoku">完整数独</param> /// <param name="noticeCounts">提示数个数</param> /// <returns></returns> public SudokuMarket AutoQuestion(List <List <int> > wholeSudoku, int noticeCounts) { var tempValue = 0; bool flag = true; var RandomValue = 30; if (noticeCounts >= 81) { noticeCounts = 80; } if (noticeCounts < 17) { noticeCounts = 17; } List <int> locations = new List <int>(); List <List <int> > result; if (noticeCounts >= RandomValue) { #region 多余30个提示数 直接采取随机数生成。 return(SubAutoQuestion(wholeSudoku, noticeCounts, ref locations)); #endregion } else { bool flag1 = true; int trytimes = 0; SudokuMarket market = null; List <SudokuMarket> markets = new List <SudokuMarket>(); while (flag1) { market = SubAutoQuestion(wholeSudoku, RandomValue, ref locations); markets.Add(market); result = market.initValues; var needlist = GetAllNeedList(result, locations); if (needlist.Count > noticeCounts) { } else if (needlist.Count == noticeCounts) { var valueCopy = JsonConvert.DeserializeObject <List <List <int> > >(JsonConvert.SerializeObject(result)); StaticTools.InitQuestion(needlist, valueCopy); if (StaticTools.IsVaildSudoku(valueCopy)) { return(new SudokuMarket(valueCopy)); } } else { var chooseValue = noticeCounts - needlist.Count; var values = locations.Except(needlist).ToArray(); List <int[]> listCombination = PermutationAndCombination <int> .GetCombination(values, chooseValue); int index = 0; foreach (var items in listCombination) { var c = items.ToList(); var location1 = needlist.Union(c).ToList(); var valueCopy = JsonConvert.DeserializeObject <List <List <int> > >(JsonConvert.SerializeObject(result)); StaticTools.InitQuestion(location1, valueCopy); if (StaticTools.ValidNoticeList(location1)) { if (StaticTools.IsVaildSudoku(valueCopy)) { return(new SudokuMarket(valueCopy)); } } index += 1; } } trytimes += 1; if (trytimes == 3) { flag1 = false; } } return(markets.OrderBy(c => c.difficult).Last()); } }
private void btnAdd_Click(object sender, EventArgs e) { #region 检测输入 if (cbxCustomer.SelectedIndex == 0) { MessageEx.ShowWarning("请选择客户"); return; } if (comboBox1.SelectedIndex == 0) { MessageEx.ShowWarning("请选择连肖类型"); return; } if (string.IsNullOrWhiteSpace(txtCode.Text)) { MessageEx.ShowWarning("请输入组合代码"); txtCode.Text = ""; txtCode.Focus(); return; } else { if (comboBox1.SelectedIndex == 1) { MinCount = 1; if (txtCode.Text.Trim().Length != 1 && checkBox1.Checked == false) { MessageEx.ShowWarning("您输入的组合代码不符合规则,请重新输入"); txtCode.Focus(); return; } } if (comboBox1.SelectedIndex == 2) { MinCount = 2; if (txtCode.Text.Trim().Length != 2 && checkBox1.Checked == false) { MessageEx.ShowWarning("您输入的组合代码不符合规则,请重新输入"); txtCode.Focus(); return; } } if (comboBox1.SelectedIndex == 3) { MinCount = 3; if (txtCode.Text.Trim().Length != 3 && checkBox1.Checked == false) { MessageEx.ShowWarning("您输入的组合代码不符合规则,请重新输入"); txtCode.Focus(); return; } } if (comboBox1.SelectedIndex == 4) { MinCount = 4; if (txtCode.Text.Trim().Length != 4 && checkBox1.Checked == false) { MessageEx.ShowWarning("您输入的组合代码不符合规则,请重新输入"); txtCode.Focus(); return; } } if (comboBox1.SelectedIndex == 5) { MinCount = 5; if (txtCode.Text.Trim().Length != 5 && checkBox1.Checked == false) { MessageEx.ShowWarning("您输入的组合代码不符合规则,请重新输入"); txtCode.Focus(); return; } } bool flag = true; foreach (var itemss in txtCode.Text.Trim()) { if (!charList.Contains(itemss.ToString())) { flag = false; break; } } if (!flag) { MessageEx.ShowWarning("您输入的组合代码不符合规则,请重新输入"); txtCode.Focus(); return; } } if (string.IsNullOrWhiteSpace(txtMoney.Text)) { MessageEx.ShowWarning("請輸入金額!"); txtMoney.Focus(); return; } #endregion if (checkBox1.Checked == false) { #region 非复试 var detail = new OrderLXLM(); detail.Id = Guid.NewGuid().ToString("n"); detail.Status = (int)ResultStatus.Wait; detail.Sort = listView1.Items.Count + 1; detail.InMoney = Convert.ToDecimal(txtMoney.Text); var item = new ListViewItem(); item.UseItemStyleForSubItems = false; item.SubItems[0].Text = (listView1.Items.Count + 1).ToString(); string str = ""; int charIndex = 0; foreach (var itemss in txtCode.Text.Trim()) { string sd = itemss.ToString().Replace("1", "鼠").Replace("2", "牛").Replace("3", "虎") .Replace("Q", "兔").Replace("q", "兔") .Replace("W", "龙").Replace("w", "龙") .Replace("E", "蛇").Replace("e", "蛇") .Replace("A", "马").Replace("a", "马") .Replace("S", "羊").Replace("s", "羊") .Replace("D", "猴").Replace("d", "猴") .Replace("Z", "鸡").Replace("z", "鸡") .Replace("X", "狗").Replace("x", "狗") .Replace("C", "猪").Replace("c", "猪"); var code = zodiacArray.First(x => x.Value == sd).Key; tempList.Add(code); str += sd + "、"; switch (charIndex) { case 0: detail.Code1 = code.ToString(); detail.Zodiac1 = sd; break; case 1: detail.Code2 = code.ToString(); detail.Zodiac2 = sd; break; case 2: detail.Code3 = code.ToString(); detail.Zodiac3 = sd; break; case 3: detail.Code4 = code.ToString(); detail.Zodiac4 = sd; break; case 4: detail.Code5 = code.ToString(); detail.Zodiac5 = sd; break; } charIndex = charIndex + 1; } detail.ChildType = comboBox1.SelectedValue.ToTryInt(); detail.Odds = GetMinOdds(odds.List, tempList); detail.OutMoney = detail.InMoney * detail.Odds; str = str.Substring(0, str.Length - 1); detail.Remarks = str; orderDetails.Add(detail); item.SubItems.Add(str); item.SubItems.Add(detail.Odds.ToMoney()); item.SubItems.Add(txtMoney.Text.Trim()); listView1.Items.Insert(0, item); tempList.Clear(); txtCode.Text = ""; txtCode.Focus(); #endregion } else { var ttt = new List <OrderLXLM>(); foreach (var itemss in txtCode.Text.Trim()) { string sd = itemss.ToString().Replace("1", "鼠").Replace("2", "牛").Replace("3", "虎") .Replace("Q", "兔").Replace("q", "兔") .Replace("W", "龙").Replace("w", "龙") .Replace("E", "蛇").Replace("e", "蛇") .Replace("A", "马").Replace("a", "马") .Replace("S", "羊").Replace("s", "羊") .Replace("D", "猴").Replace("d", "猴") .Replace("Z", "鸡").Replace("z", "鸡") .Replace("X", "狗").Replace("x", "狗") .Replace("C", "猪").Replace("c", "猪"); var code = zodiacArray.First(x => x.Value == sd).Key; tempList.Add(code); } //需要组合的号码 List <int> InCombinationList = new List <int>(); foreach (var item in tempList) { InCombinationList.Add(item); } //生成号码组合 List <int[]> ListCombination = PermutationAndCombination <int> .GetCombination(InCombinationList.ToArray(), MinCount); //求全部的3-3组合 //根据号码组合创建订单明细 int index = 1; foreach (int[] arr in ListCombination) { OrderLXLM detail = new OrderLXLM(); int childIndex = 0; var str = ""; foreach (int item in arr) { switch (childIndex) { case 0: detail.Code1 = item.ToString(); detail.Zodiac1 = ServiceNum.GetNumZodiac(item); break; case 1: detail.Code2 = item.ToString(); detail.Zodiac2 = ServiceNum.GetNumZodiac(item); break; case 2: detail.Code3 = item.ToString(); detail.Zodiac3 = ServiceNum.GetNumZodiac(item); break; case 3: detail.Code4 = item.ToString(); detail.Zodiac4 = ServiceNum.GetNumZodiac(item); break; case 4: detail.Code5 = item.ToString(); detail.Zodiac5 = ServiceNum.GetNumZodiac(item); break; } str += ServiceNum.GetNumZodiac(item) + "、"; childIndex = childIndex + 1; } detail.Id = Guid.NewGuid().ToString("n"); detail.Sort = listView1.Items.Count + index; detail.ChildType = comboBox1.SelectedValue.ToTryInt(); detail.Remarks = str.Remove(str.Length - 1, 1); detail.Odds = GetMinOdds(odds.List, arr.ToList()); detail.InMoney = Convert.ToDecimal(txtMoney.Text); detail.OutMoney = detail.InMoney * detail.Odds; detail.Status = (int)ResultStatus.Wait; detail.Flag = 1; ttt.Add(detail); index = index + 1; } ttt.ForEach(x => { orderDetails.Add(x); var lvitem = new ListViewItem(); lvitem.UseItemStyleForSubItems = false; lvitem.SubItems[0].Text = (listView1.Items.Count + 1).ToString(); lvitem.SubItems.Add(x.Remarks); lvitem.SubItems.Add(x.Odds.ToMoney()); lvitem.SubItems.Add(txtMoney.Text.Trim()); listView1.Items.Insert(0, lvitem); }); tempList.Clear(); txtCode.Text = ""; txtCode.Focus(); } }
private static void GenerateDataTableExtensionDictionary( IDictionary <string, DataTableProcessor.DataProcessor> dataProcessors) { var keyValueList = PermutationAndCombination <DataTableProcessor.DataProcessor> .GetCombination(dataProcessors.Values.ToArray(), 2).ToList(); var reverseList = keyValueList.Select(types => new[] { types[1], types[0] }).ToList(); keyValueList.AddRange(reverseList); foreach (var dataProcessor in dataProcessors.Values) { keyValueList.Add(new[] { dataProcessor, dataProcessor }); } var sb = new StringBuilder(); AddNameSpaces(sb); sb.AppendLine($"namespace {NameSpace}"); sb.AppendLine("{"); sb.AppendLine("\tpublic static partial class DataTableExtension"); sb.AppendLine("\t{"); foreach (var item in keyValueList) { var dataProcessorT1 = item[0]; var dataProcessorT2 = item[1]; (string, string)names = GetNames(dataProcessorT1, dataProcessorT2); sb.AppendLine( $"\t\tpublic static Dictionary<{dataProcessorT1.LanguageKeyword},{dataProcessorT2.LanguageKeyword}> Parse{names.Item1}{names.Item2}Dictionary(string value)"); sb.AppendLine("\t\t{"); sb.AppendLine("\t\t\tif (string.IsNullOrEmpty(value) || value.ToLowerInvariant().Equals(\"null\"))"); sb.AppendLine("\t\t\t\treturn null;"); sb.AppendLine("\t\t\tstring[] splitValue = value.Split('|');"); sb.AppendLine( $"\t\t\tDictionary<{dataProcessorT1.LanguageKeyword},{dataProcessorT2.LanguageKeyword}> dictionary = new Dictionary<{dataProcessorT1.LanguageKeyword},{dataProcessorT2.LanguageKeyword}>(splitValue.Length);"); sb.AppendLine("\t\t\tfor (int i = 0; i < splitValue.Length; i++)"); sb.AppendLine("\t\t\t{"); sb.AppendLine("\t\t\t\tstring[] keyValue = splitValue[i].Split('#');"); if (dataProcessorT1.IsSystem) { if (dataProcessorT2.IsSystem) { if (dataProcessorT1.LanguageKeyword == "string" && dataProcessorT2.LanguageKeyword == "string") { sb.AppendLine( "\t\t\t\tdictionary.Add(keyValue[0].Substring(1),keyValue[1].Substring(0, keyValue[1].Length - 1));"); } else if (dataProcessorT1.LanguageKeyword == "string") { sb.AppendLine( $"\t\t\t\tdictionary.Add(keyValue[0].Substring(1),{dataProcessorT2.Type.Name}.Parse(keyValue[1].Substring(0, keyValue[1].Length - 1)));"); } else if (dataProcessorT2.LanguageKeyword == "string") { sb.AppendLine( $"\t\t\t\tdictionary.Add({dataProcessorT1.Type.Name}.Parse(keyValue[0].Substring(1)),keyValue[1].Substring(0, keyValue[1].Length - 1));"); } else { sb.AppendLine( $"\t\t\t\tdictionary.Add({dataProcessorT1.Type.Name}.Parse(keyValue[0].Substring(1)),{dataProcessorT2.Type.Name}.Parse(keyValue[1].Substring(0, keyValue[1].Length - 1)));"); } } else { if (dataProcessorT1.LanguageKeyword == "string") { if (dataProcessorT2.IsEnum) { sb.AppendLine( $"\t\t\t\tdictionary.Add(keyValue[0].Substring(1),({dataProcessorT2.LanguageKeyword})int.Parse(keyValue[1].Substring(0, keyValue[1].Length - 1)));"); } else { sb.AppendLine( $"\t\t\t\tdictionary.Add(keyValue[0].Substring(1),Parse{dataProcessorT2.Type.Name}(keyValue[1].Substring(0, keyValue[1].Length - 1)));"); } } else if (dataProcessorT2.IsEnum) { sb.AppendLine( $"\t\t\t\tdictionary.Add({dataProcessorT1.Type.Name}.Parse(keyValue[0].Substring(1)),({dataProcessorT2.LanguageKeyword}) int.Parse(keyValue[1].Substring(0, keyValue[1].Length - 1)));"); } else { sb.AppendLine( $"\t\t\t\tdictionary.Add({dataProcessorT1.Type.Name}.Parse(keyValue[0].Substring(1)),Parse{dataProcessorT2.Type.Name}(keyValue[1].Substring(0, keyValue[1].Length - 1)));"); } } } else { if (dataProcessorT2.IsSystem) { if (dataProcessorT2.LanguageKeyword == "string") { if (dataProcessorT1.IsEnum) { sb.AppendLine( $"\t\t\t\tdictionary.Add(({dataProcessorT1.LanguageKeyword}) int.Parse(keyValue[0].Substring(1)),keyValue[1].Substring(0, keyValue[1].Length - 1));"); } else { sb.AppendLine( $"\t\t\t\tdictionary.Add(Parse{dataProcessorT1.Type.Name}(keyValue[0].Substring(1)),keyValue[1].Substring(0, keyValue[1].Length - 1));"); } } else if (dataProcessorT1.IsEnum) { sb.AppendLine( $"\t\t\t\tdictionary.Add(({dataProcessorT1.LanguageKeyword}) int.Parse(keyValue[0].Substring(1)),{dataProcessorT2.Type.Name}.Parse(keyValue[1].Substring(0, keyValue[1].Length - 1)));"); } else { sb.AppendLine( $"\t\t\t\tdictionary.Add(Parse{dataProcessorT1.Type.Name}(keyValue[0].Substring(1)),{dataProcessorT2.Type.Name}.Parse(keyValue[1].Substring(0, keyValue[1].Length - 1)));"); } } else { if (dataProcessorT2.IsEnum) { sb.AppendLine( dataProcessorT1.IsEnum ? $"\t\t\t\tdictionary.Add(({dataProcessorT1.LanguageKeyword}) int.Parse(keyValue[1].Substring(0, keyValue[1].Length - 1)),({dataProcessorT2.LanguageKeyword}) int.Parse(keyValue[1].Substring(0, keyValue[1].Length - 1)));" : $"\t\t\t\tdictionary.Add(Parse{dataProcessorT1.Type.Name}(keyValue[0].Substring(1)),({dataProcessorT2.LanguageKeyword}) int.Parse(keyValue[1].Substring(0, keyValue[1].Length - 1)));"); } else if (dataProcessorT1.IsEnum) { sb.AppendLine( $"\t\t\t\tdictionary.Add(({dataProcessorT1.LanguageKeyword}) int.Parse(keyValue[1].Substring(0, keyValue[1].Length - 1)),Parse{dataProcessorT2.Type.Name}(keyValue[0].Substring(1)));"); } else { sb.AppendLine( $"\t\t\t\tdictionary.Add(Parse{dataProcessorT1.Type.Name}(keyValue[0].Substring(1)),Parse{dataProcessorT2.Type.Name}(keyValue[1].Substring(0, keyValue[1].Length - 1)));"); } } } sb.AppendLine("\t\t\t}"); sb.AppendLine("\t\t\treturn dictionary;"); sb.AppendLine("\t\t}"); } sb.AppendLine("\t}"); sb.AppendLine("}"); GenerateCodeFile("DataTableExtension.Dictionary", sb.ToString()); }
private static void GenerateBinaryReaderExtensionDictionary( IDictionary <string, DataTableProcessor.DataProcessor> dataProcessors) { var keyValueList = PermutationAndCombination <DataTableProcessor.DataProcessor> .GetCombination(dataProcessors.Values.ToArray(), 2).ToList(); var reverseList = keyValueList.Select(types => new[] { types[1], types[0] }).ToList(); keyValueList.AddRange(reverseList); foreach (var dataProcessor in dataProcessors.Values) { keyValueList.Add(new[] { dataProcessor, dataProcessor }); } var sb = new StringBuilder(); AddNameSpaces(sb); sb.AppendLine($"namespace {NameSpace}"); sb.AppendLine("{"); sb.AppendLine("\tpublic static partial class BinaryReaderExtension"); sb.AppendLine("\t{"); foreach (var item in keyValueList) { var dataProcessorT1 = item[0]; var dataProcessorT2 = item[1]; (string, string)names = GetNames(dataProcessorT1, dataProcessorT2); sb.AppendLine( $"\t\tpublic static Dictionary<{dataProcessorT1.LanguageKeyword},{dataProcessorT2.LanguageKeyword}> Read{names.Item1}{names.Item2}Dictionary(this BinaryReader binaryReader)"); sb.AppendLine("\t\t{"); sb.AppendLine("\t\t\tint count = binaryReader.Read7BitEncodedInt32();"); sb.AppendLine( $"\t\t\tDictionary<{dataProcessorT1.LanguageKeyword},{dataProcessorT2.LanguageKeyword}> dictionary = new Dictionary<{dataProcessorT1.LanguageKeyword},{dataProcessorT2.LanguageKeyword}>(count);"); sb.AppendLine("\t\t\tfor (int i = 0; i < count; i++)"); sb.AppendLine("\t\t\t{"); var t1LanguageKeyword = dataProcessorT1.LanguageKeyword; var t2LanguageKeyword = dataProcessorT2.LanguageKeyword; if (dataProcessorT1.IsSystem && dataProcessorT1.Type != typeof(DateTime)) { if (dataProcessorT2.IsSystem && dataProcessorT2.Type != typeof(DateTime)) { if (t1LanguageKeyword == "int" || t1LanguageKeyword == "uint" || t1LanguageKeyword == "long" || t1LanguageKeyword == "ulong") { if (t2LanguageKeyword == "int" || t2LanguageKeyword == "uint" || t2LanguageKeyword == "long" || t2LanguageKeyword == "ulong") { sb.AppendLine( $"\t\t\t\tdictionary.Add(binaryReader.Read7BitEncoded{dataProcessorT1.Type.Name}(),binaryReader.Read7BitEncoded{dataProcessorT2.Type.Name}());"); } else { sb.AppendLine( $"\t\t\t\tdictionary.Add(binaryReader.Read7BitEncoded{dataProcessorT1.Type.Name}(),binaryReader.Read{dataProcessorT2.Type.Name}());"); } } else { sb.AppendLine( $"\t\t\t\tdictionary.Add(binaryReader.Read{dataProcessorT1.Type.Name}(),binaryReader.Read{dataProcessorT2.Type.Name}());"); } } else { if (t1LanguageKeyword == "int" || t1LanguageKeyword == "uint" || t1LanguageKeyword == "long" || t1LanguageKeyword == "ulong") { if (dataProcessorT2.IsEnum) { sb.AppendLine( $"\t\t\t\tdictionary.Add(binaryReader.Read7BitEncoded{dataProcessorT1.Type.Name}(),({dataProcessorT2.LanguageKeyword}) binaryReader.Read7BitEncoded{dataProcessorT2.Type.Name}());"); } else { sb.AppendLine( $"\t\t\t\tdictionary.Add(binaryReader.Read7BitEncoded{dataProcessorT1.Type.Name}(), Read{dataProcessorT2.LanguageKeyword}(binaryReader));"); } } else if (dataProcessorT2.IsEnum) { sb.AppendLine( $"\t\t\t\tdictionary.Add(binaryReader.Read{dataProcessorT1.Type.Name}(),({dataProcessorT2.LanguageKeyword}) binaryReader.Read7BitEncoded{dataProcessorT2.Type.Name}());"); } else { sb.AppendLine( $"\t\t\t\tdictionary.Add(binaryReader.Read{dataProcessorT1.Type.Name}(),Read{dataProcessorT2.LanguageKeyword}(binaryReader));"); } } } else { if (dataProcessorT2.IsSystem && dataProcessorT2.Type != typeof(DateTime)) { if (t2LanguageKeyword == "int" || t2LanguageKeyword == "uint" || t2LanguageKeyword == "long" || t2LanguageKeyword == "ulong") { if (dataProcessorT1.IsEnum) { sb.AppendLine( $"\t\t\t\tdictionary.Add(({dataProcessorT1.LanguageKeyword}) binaryReader.Read7BitEncoded{dataProcessorT1.Type.Name}(),({dataProcessorT2.LanguageKeyword}) binaryReader.Read7BitEncoded{dataProcessorT2.Type.Name}());"); } else { sb.AppendLine( $"\t\t\t\tdictionary.Add(Read{dataProcessorT1.LanguageKeyword}(binaryReader),binaryReader.Read7BitEncoded{dataProcessorT2.Type.Name}());"); } } else if (dataProcessorT1.IsEnum) { sb.AppendLine( $"\t\t\t\tdictionary.Add(({dataProcessorT1.LanguageKeyword}) binaryReader.Read7BitEncoded{dataProcessorT1.Type.Name}(),binaryReader.Read{dataProcessorT2.Type.Name}());"); } else { sb.AppendLine( $"\t\t\t\tdictionary.Add(Read{dataProcessorT1.LanguageKeyword}(binaryReader),binaryReader.Read{dataProcessorT2.Type.Name}());"); } } else { if (dataProcessorT2.IsEnum) { sb.AppendLine( dataProcessorT1.IsEnum ? $"\t\t\t\tdictionary.Add(({dataProcessorT1.LanguageKeyword}) binaryReader.Read7BitEncoded{dataProcessorT1.Type.Name}(),({dataProcessorT2.LanguageKeyword}) binaryReader.Read7BitEncoded{dataProcessorT2.Type.Name}());" : $"\t\t\t\tdictionary.Add(Read{dataProcessorT1.LanguageKeyword}(binaryReader),({dataProcessorT2.LanguageKeyword}) binaryReader.Read7BitEncoded{dataProcessorT2.Type.Name}());"); } else if (dataProcessorT1.IsEnum) { sb.AppendLine( $"\t\t\t\tdictionary.Add(({dataProcessorT1.LanguageKeyword}) binaryReader.Read7BitEncoded{dataProcessorT1.Type.Name}(),Read{dataProcessorT2.LanguageKeyword}(binaryReader));"); } else { sb.AppendLine( $"\t\t\t\tdictionary.Add(Read{dataProcessorT1.LanguageKeyword}(binaryReader),Read{dataProcessorT2.LanguageKeyword}(binaryReader));"); } } } sb.AppendLine("\t\t\t}"); sb.AppendLine("\t\t\treturn dictionary;"); sb.AppendLine("\t\t}"); } sb.AppendLine("\t}"); sb.AppendLine("}"); GenerateCodeFile("BinaryReaderExtension.Dictionary", sb.ToString()); }