public static List <MatchGroupTableAthleteModel> GetAllAthletesByGroupProject(string matchId, string groupName, string sex) { var result = new List <MatchGroupTableAthleteModel>(); var sql = $"select name,team_name, bar_GROUP_GAMES_STATUS,bar_INDIVIDUAL_GAMES_STATUS,team_short_name from athletes where " + $"match_id = '{matchId}' and group_name = '{groupName}' and sex='{sex}' and " + $"(bar_GROUP_GAMES_STATUS ='参加' or bar_INDIVIDUAL_GAMES_STATUS = '参加')"; var dataSet = SQLiteHelper.ExecuteDataSet(SQLiteHelper.LocalDbConnectionString, sql, CommandType.Text); var rows = dataSet.Tables[0].Rows; for (var i = 0; i < rows.Count; i++) { // 设置姓名,代表队, 是否是只参加个人赛 var model = new MatchGroupTableAthleteModel(); var name = rows[i].ItemArray[0] != DBNull.Value ? (string)rows[i].ItemArray[0] : ""; var teamName = rows[i].ItemArray[1] != DBNull.Value ? (string)rows[i].ItemArray[1] : ""; var inGroup = rows[i].ItemArray[2] != DBNull.Value ? (string)rows[i].ItemArray[2] : ""; var inIndividual = rows[i].ItemArray[3] != DBNull.Value ? (string)rows[i].ItemArray[3] : ""; var shortName = rows[i].ItemArray[4] != DBNull.Value ? (string)rows[i].ItemArray[4] : ""; model.Name = name; model.TeamName = teamName; model.TeamShortName = shortName; if (inGroup != "参加" && inIndividual == "参加") { model.IsIndividualGroupMatch = true; } else { model.IsIndividualGroupMatch = false; } result.Add(model); } return(result); }
private MatchGroupTableAthleteModel FindMaxCellTwoRound(List <MatchGroupTableAthleteModel> table, MatchGroupTableAthleteModel cellAthlete) { var maxCell = new MatchGroupTableAthleteModel() { Row = -1 }; for (var n = 1; n < table.Last().Row + 1; n++) { foreach (var cell in table) { if (maxCell.Row + maxCell.Column < cell.Row + cell.Column && string.IsNullOrWhiteSpace(table.Where(x => x.Row == cell.Row && x.Column == cell.Column).First().Name) && table.Where(x => x.Row == cell.Row && x.TeamName == cellAthlete.TeamName).Count() == 0 && table.Where(x => x.Column == cell.Column && x.TeamName == cellAthlete.TeamName).Count() == n) { maxCell = cell; } } if (maxCell.Row != -1) { break; } } return(maxCell); }
private List <MatchGroupTableAthleteModel> GenerateMatchTable(int rowCount, int columnCout) { var table = new List <MatchGroupTableAthleteModel>(); for (var i = 0; i < rowCount; i++) { for (var j = 0; j < columnCout; j++) { var cell = new MatchGroupTableAthleteModel(); cell.Row = i; cell.Column = j; table.Add(cell); } } return(table.OrderBy(x => x.Row).ThenBy(x => x.Column).ToList()); }
/// <summary> /// 第三轮: 不同列同行数不超过2人,行 + 列,最小/最大位置切换填充人员,遇到行 + 列数目相同的单元格,选择列中同队人员最小的一个 /// </summary> /// <param name="table"></param> /// <param name="cellAthlete"></param> /// <returns></returns> private MatchGroupTableAthleteModel FindMinCellThreeRound(List <MatchGroupTableAthleteModel> table, MatchGroupTableAthleteModel cellAthlete) { var minCell = new MatchGroupTableAthleteModel() { Row = 10000 }; foreach (var cell in table) { if (minCell.Row + minCell.Column > cell.Row + cell.Column && string.IsNullOrWhiteSpace(table.Where(x => x.Row == cell.Row && x.Column == cell.Column).First().Name) && table.Where(x => x.Row == cell.Row && x.TeamName == cellAthlete.TeamName).Count() == 1) { minCell = cell; } } return(minCell); }
// 获取决赛的不同项目的表格数据 public static List <MatchGroupTableAthleteModel> GetFinalEveryGroupTable(string matchId, string groupName, string sexName) { var result = new List <MatchGroupTableAthleteModel>(); var sql = $"select name,team_name, ROW,COLUMN,ISINDIVIDUAL,team_short_name from MATCH_GROUP where " + $"match_id = '{matchId}' and group_name='{groupName}' and SEX_NAME = '{sexName}'and is_final is not null"; var dataSet = SQLiteHelper.ExecuteDataSet(SQLiteHelper.LocalDbConnectionString, sql, CommandType.Text); var rows = dataSet.Tables[0].Rows; for (var i = 0; i < rows.Count; i++) { var cell = new MatchGroupTableAthleteModel(); cell.Name = rows[i].ItemArray[0] != DBNull.Value ? (string)rows[i].ItemArray[0] : ""; cell.TeamName = rows[i].ItemArray[1] != DBNull.Value ? (string)rows[i].ItemArray[1] : ""; cell.Row = rows[i].ItemArray[2] != DBNull.Value ? Convert.ToInt32(rows[i].ItemArray[2]) : -1; cell.Column = rows[i].ItemArray[3] != DBNull.Value ? Convert.ToInt32(rows[i].ItemArray[3]) : -1; cell.IsIndividualGroupMatch = rows[i].ItemArray[4] != DBNull.Value ? Convert.ToBoolean(rows[i].ItemArray[4]) : false; cell.TeamShortName = DBHelper.GetRowIndexStringValue(rows[i], 5); result.Add(cell); } return(result); }
private MatchGroupTableAthleteModel[] RemoveAthleteIntoTable(List <MatchGroupTableAthleteModel> table, MatchGroupTableAthleteModel[] athletesArray, int roundNum) { var isMin = true; Random rd = new Random(); while (athletesArray.Length > 0) { var number = rd.Next(0, athletesArray.Length); var cellAthlete = athletesArray[number]; if (isMin) // 移入到table中 { var minCell = new MatchGroupTableAthleteModel(); if (roundNum == 1) { minCell = FindMinCellOneRound(table, cellAthlete); } else if (roundNum == 2) { minCell = FindMinCellTwoRound(table, cellAthlete); } else if (roundNum == 3) { minCell = FindMinCellThreeRound(table, cellAthlete); } if (minCell.Row == 10000) { isMin = true; break; } var tableCell = table.Where(x => x.Row == minCell.Row && x.Column == minCell.Column).First(); tableCell.Name = cellAthlete.Name; tableCell.TeamName = cellAthlete.TeamName; tableCell.TeamShortName = cellAthlete.TeamShortName; tableCell.IsIndividualGroupMatch = cellAthlete.IsIndividualGroupMatch; isMin = false; } else { var maxCell = new MatchGroupTableAthleteModel(); if (roundNum == 1) { maxCell = FindMaxCellOneRound(table, cellAthlete); } else if (roundNum == 2) { maxCell = FindMaxCellTwoRound(table, cellAthlete); } else if (roundNum == 3) { maxCell = FindMaxCellThreeRound(table, cellAthlete); } if (maxCell.Row == -1) { isMin = true; break; } var tableCell = table.Where(x => x.Row == maxCell.Row && x.Column == maxCell.Column).First(); tableCell.Name = cellAthlete.Name; tableCell.TeamName = cellAthlete.TeamName; tableCell.TeamShortName = cellAthlete.TeamShortName; tableCell.IsIndividualGroupMatch = cellAthlete.IsIndividualGroupMatch; isMin = true; } athletesArray = athletesArray.Where((source, index) => source != cellAthlete).ToArray(); // 移除挑选出来的运动员 } return(athletesArray); }