public void calculateHighLowTeamStats(String league, String division, Team.CATEGORY cat) { ReportScope scope = new ReportScope(); if (league.Length > 0) { scope.League = league; } if (division.Length > 0) { scope.Division = division; scope.League = "X"; } List <Team> teams = getTeamsByScope(scope); Team leader = null; Team trailing = null; foreach (Team t in teams) { if (leader == null || trailing == null) { leader = t; trailing = t; } processCategory(ref leader, ref trailing, t, cat); } leader.setLeader(cat); trailing.setTrailing(cat); }
/* * public List<Team> getTeamsByName(ReportScope scope) * { * List<Team> matches = getTeamsByScope(scope); * * matches.Sort(delegate (Team x, Team y) * { * if (scope.OrderAscending) * { * if (x.Name == null && y.Name == null) return 0; * else if (x.Name == null) return -1; * else if (y.Name == null) return 1; * else return x.Name.ToUpper().CompareTo(y.Name.ToUpper()); * } * else * { * if (x.Name == null && y.Name == null) return 0; * else if (x.Name == null) return -1; * else if (y.Name == null) return 1; * else return y.Name.ToUpper().CompareTo(x.Name.ToUpper()); * } * * }); * * return matches; * } */ /* * public void calculateHighLowTeamStats(String league, String division, Team.CATEGORY cat) * { * ReportScope scope = new ReportScope(); * if (league.Length > 0) * scope.League = league; * if (division.Length > 0) * { * scope.Division = division; * scope.League = "X"; * } * List<Team> teams = getTeamsByScope(scope); * Team leader = null; * Team trailing = null; * foreach (Team t in teams) * { * if (leader == null || trailing == null) * { * leader = t; * trailing = t; * } * processCategory(ref leader, ref trailing, t, cat); * } * * leader.setLeader(cat); * trailing.setTrailing(cat); * } */ private void processCategory(ref Team leader, ref Team trailing, Team t, Team.CATEGORY cat) { if (cat == Team.CATEGORY.BATTING_AVERAGE) { if (t.BattingAverage > leader.BattingAverage) { leader = t; } else if (t.BattingAverage < trailing.BattingAverage) { trailing = t; } } else if (cat == Team.CATEGORY.EARNED_RUNS_AVG) { if (t.EarnedRunAvg < leader.EarnedRunAvg) { leader = t; } else if (t.EarnedRunAvg > trailing.EarnedRunAvg) { trailing = t; } } else if (cat == Team.CATEGORY.HOME_RUNS) { if (t.HomeRuns > leader.HomeRuns) { leader = t; } else if (t.HomeRuns < trailing.HomeRuns) { trailing = t; } } }