private void BTN_MANAGE_LINEUPS_Click(object sender, RoutedEventArgs e) { Object item = CB_LIST_OF_TEAMS.SelectedItem; if (item is Team) { Team team = (Team)item; LineupListDlg dlg = new LineupListDlg(team, engine.StoredLineups[team.Abrv]); System.Windows.Forms.DialogResult result = dlg.ShowDialog(); if (result == System.Windows.Forms.DialogResult.OK && dlg.ApplyAsTemplate) { List <Team> teams = engine.TeamReportFile.getTeams(); foreach (Team otherTeam in teams) { if (team == otherTeam) { continue; } TeamLineup otherTeamLineup = LineupPersistence.lookupTeamLineup(engine.StoredLineups, otherTeam); dlg.applyConfigurationToAnotherTeam(otherTeamLineup); syncUpTheData(engine.StoredLineups); LineupPersistence.saveDatabase(engine.StoredLineups); } //Update the table! CB_LIST_OF_TEAMS_SelectionChanged(this, null); } else if (result == System.Windows.Forms.DialogResult.OK) { //Update the table! CB_LIST_OF_TEAMS_SelectionChanged(this, null); } } }
public void applyConfigurationToAnotherTeam(TeamLineup team) { foreach (LineupDataObj item in listBox1.Items) { team.Lineups.Add(item.getLineupData()); } }
private void CB_LIST_OF_TEAMS_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (dialogInitialized) { if (CB_LIST_OF_TEAMS.SelectedItem is Team) { currentlySelectedTeam = (Team)CB_LIST_OF_TEAMS.SelectedItem; TeamLineup selectedTeamLineup = LineupPersistence.lookupTeamLineup(engine.StoredLineups, currentlySelectedTeam); System.Console.WriteLine(currentlySelectedTeam.Abrv + " contains " + selectedTeamLineup.Lineups.Count + " lineups."); List <Player> players = engine.TeamReportFile.getTeamBatters(currentlySelectedTeam); batterInfo.setPlayers(players); IUsageCalculator calculator = CalculatorFactory.getCalculator(USAGE_CALCULATOR, engine.TeamReportFile, currentlySelectedTeam); calculator.setOptions(CalculatorOptions.OPTION_IN_DIVISION_GAMES, engine.TeamLineupData.InDivisionGameCount); calculator.setOptions(CalculatorOptions.OPTION_OUT_DIVISION_GAMES, engine.TeamLineupData.OutofDivisionGameCount); //TODO: Add UI element for Target At Bats calculator.setOptions(CalculatorOptions.OPTION_TARGET_AT_BAT, 615); engine.BalanceAtBats = balanceUsage.buildTable(calculator); updateWorkbook(currentlySelectedTeam, players); fillBoxesWithSavedDataData(); BTN_MANAGE_LINEUPS.IsEnabled = true; } } }
public LineupListDlg(Team team, TeamLineup lineups) { this.team = team; this.storedLineups = lineups; InitializeComponent(); ApplyAsTemplate = false; }
private void fillWithTestTeams(Dictionary <String, TeamLineup> lineups, int count) { for (int i = 1; i <= count; i++) { String teamName = "MyTeam" + i; TeamLineup lineup = new TeamLineup(); LineupData lupLeft = new LineupData(RecordIndex.getNextId(RecordIndex.INDEX.TestLineupDataId), "L", new LineupBalanceItem(0, 9, "L"), new LineupBalanceItem(18, 9, "R"), 77); lineup.Lineups.Add(lupLeft); List <Player> players = new List <Player>(); String[] names = { "CatcherL1", "FirstL1", "SecondL1", "ThirdL1", "ShortstopL1", "LeftL1", "CenterL1", "RightL1", "DesignatedL1" }; foreach (String name in names) { players.Add(createTestPlayer(name)); } LineupData lupRight = new LineupData(RecordIndex.getNextId(RecordIndex.INDEX.TestLineupDataId), "R", new LineupBalanceItem(0, 9, "L"), new LineupBalanceItem(18, 9, "R"), 888); lineup.Lineups.Add(lupRight); String[] namesR = { "CatcherR1", "FirstR1", "SecondR1", "ThirdR1", "ShortstopR1", "LeftR1", "CenterR1", "RightR1", "DesignatedR1" }; foreach (String name in namesR) { players.Add(createTestPlayer(name)); } lineup.playerByGRID = players; lineups.Add(teamName, lineup); } }
public TeamLineup AddTeamLineup([FromBody] TeamLineupJson data) { var lineup = GetLineup(data.id); var teamLineup = new TeamLineup(data.teamId, data.players, DateTime.UtcNow); if (lineup?.TeamLineups == null) { lineup = new Lineup(data.id, FplDataProvider.Season); lineup.TeamLineups.Add(teamLineup); _mongoLineupProvider.AddLineup(lineup); } else { if (lineup.TeamLineups.Count(x => x.TeamId == data.teamId) > 0) { lineup.TeamLineups.FirstOrDefault(x => x.TeamId == data.teamId).Players = data.players; lineup.TeamLineups.FirstOrDefault(x => x.TeamId == data.teamId).DateSet = teamLineup.DateSet; } else { lineup.TeamLineups.Add(teamLineup); } _mongoLineupProvider.UpdateLineup(data.id, lineup); } return(teamLineup); }
public TeamLineup GetTeamLineup(int id, int teamId) { var lineup = _mongoLineupProvider.Get(id).Result; var teamLineup = new TeamLineup(teamId, new List <int>(), DateTime.UtcNow); if (lineup.TeamLineups != null && lineup.TeamLineups.Any()) { teamLineup = lineup.TeamLineups.FirstOrDefault(x => x.TeamId == teamId); } return(teamLineup); }
public void testStoreAndLoadPersistenceObject() { int TEST_COUNT = 5; Dictionary <String, TeamLineup> teamLineups = LineupPersistence.loadDatabase(); Assert.IsTrue(teamLineups.Count == 0); fillWithTestTeams(teamLineups, TEST_COUNT); LineupPersistence.saveDatabase(teamLineups); Dictionary <String, TeamLineup> lineup2 = LineupPersistence.loadDatabase(); Assert.IsTrue(lineup2.Count() == TEST_COUNT); Assert.IsTrue(lineup2.ContainsKey(TEST_TEAM_NAME + "1")); TeamLineup lineup = teamLineups[TEST_TEAM_NAME + "1"]; Assert.IsTrue(lineup.Lineups.Count == 2); Assert.AreEqual(18, lineup2[TEST_TEAM_NAME + "1"].playerByGRID.Count); Assert.AreEqual(18, lineup2[TEST_TEAM_NAME + "2"].playerByGRID.Count); }
private void updateWorkbook(Team team, List <Player> players) { if (GRID.ColumnDefinitions.Count > 0) { GRID.ColumnDefinitions.RemoveRange(0, GRID.ColumnDefinitions.Count); GRID.Children.RemoveRange(0, GRID.Children.Count); } buildWorksheetLabelColumn(); TeamLineup lineups = engine.StoredLineups[team.Abrv]; int index = 1; int box = 1; foreach (LineupData lineupData in lineups.Lineups) { LineupDataObj lineup = new LineupDataObj(lineupData); int pitcherArmIndex = lineup.PitcherArm.Equals("L") ? 0 : 1; lineup.EstimatedAtBats = calculateAtBatsByLineup(engine.BalanceAtBats[pitcherArmIndex], lineup.getLineupData()); GRID.Children.Add(BuildPlayerPostitionBox(index, POSITIONS.CATCHER, lineup, players, box++)); GRID.Children.Add(BuildPlayerPostitionBox(index, POSITIONS.FIRSTBASE, lineup, players, box++)); GRID.Children.Add(BuildPlayerPostitionBox(index, POSITIONS.SECONDBASE, lineup, players, box++)); GRID.Children.Add(BuildPlayerPostitionBox(index, POSITIONS.THIRDBASE, lineup, players, box++)); GRID.Children.Add(BuildPlayerPostitionBox(index, POSITIONS.SHORTSTOP, lineup, players, box++)); GRID.Children.Add(BuildPlayerPostitionBox(index, POSITIONS.LEFTFIELD, lineup, players, box++)); GRID.Children.Add(BuildPlayerPostitionBox(index, POSITIONS.CENTERFIELD, lineup, players, box++)); GRID.Children.Add(BuildPlayerPostitionBox(index, POSITIONS.RIGHTFIELD, lineup, players, box++)); GRID.Children.Add(BuildPlayerPostitionBox(index, POSITIONS.DH, lineup, players, box++)); createColumn(lineup, index, 160); index++; } GRID.UpdateLayout(); }