// // Utility Test Methods // private void runLineupTest(List <Dictionary <int, int> > calculatedResults, LineupDataObj lineup, int expectedAB) { int estimated = lookupEstimatedAtBatForLineup(calculatedResults, lineup); Assert.AreEqual(expectedAB, estimated, "Inital Version estimates does not match for " + lineup); }
private void createColumn(LineupDataObj lineup, int columnIndex, double width) { String text = lineup.ToString() + " (" + lineup.EstimatedAtBats + ")"; ColumnDefinition col = createColumn(text, columnIndex, width); col.SetValue(dp, lineup); }
private LineupDataObj createTestTeamLineup(String arm, String start, String end) { LineupDataObj lineup = new LineupDataObj(RecordIndex.getNextId(RecordIndex.INDEX.TestLineupDataId)); lineup.PitcherArm = arm; // Converts 1R to the int 1 and letter 'R' if (start.Equals("E")) { lineup.BalanceItemFrom = balanceItems[hackyLookupIndex(0, start)]; } else { lineup.BalanceItemFrom = balanceItems[hackyLookupIndex(Int32.Parse(start.Substring(0, 1)), start.Substring(1, 1))]; } if (end.Equals("E")) { lineup.BalanceItemTo = balanceItems[hackyLookupIndex(0, start)]; } else { lineup.BalanceItemTo = balanceItems[hackyLookupIndex(Int32.Parse(end.Substring(0, 1)), end.Substring(1, 1))]; } return(lineup); }
public LineupMgrDlg(LineupDataObj originalData) : this(false) { WorkingLineup = originalData; String s = WorkingLineup.BalanceItemFrom.ToString(); int i = CB_FROM.FindString(s); CB_FROM.SelectedIndex = i; CB_TO.SelectedItem = WorkingLineup.BalanceItemTo; radioButtonLH.Checked = WorkingLineup.PitcherArm.Equals("L"); radioButtonRH.Checked = !WorkingLineup.PitcherArm.Equals("L"); updateLabel(); }
public void setPlayers(List <Player> players) { int ABAdjustment = Int32.Parse(Properties.Settings.Default.ABAddition); clearInfoTable(InfoGrid); List <Player> sorted = players.OrderBy(o => o.Name).ToList(); int postion = 1; foreach (Player player in sorted) { int totalAB = 0; Dictionary <POSITIONS, int> positions = new Dictionary <POSITIONS, int>(); foreach (Object obj in LineupGrid.Children) { if (obj is ComboBox) { ComboBox cb = (ComboBox)obj; if (cb.SelectedItem != null && cb.SelectedItem is DefenseComboBoxItem) { LineupDataObj lineup = (LineupDataObj)cb.GetValue(MainWindow.dp); Player selectedPlayer = ((DefenseComboBoxItem)cb.SelectedItem).Value; if (selectedPlayer == player) { POSITIONS pos = ((PositionObj)cb.GetValue(MainWindow.dpPos)).Position; adjustPostionCount(positions, pos); totalAB += lineup.EstimatedAtBats; } } } } int remaining = (player.Actual + ABAdjustment) - totalAB; RowDefinition row = new RowDefinition(); row.Height = GridLength.Auto; InfoGrid.RowDefinitions.Add(row); InfoGrid.Children.Add(BuildPlayerInfoRow(player.Name, COLUMNS.NAME, postion, remaining >= 0 ? Colors.Black : Colors.Red)); InfoGrid.Children.Add(BuildPlayerInfoRow(Convert.ToString(totalAB), COLUMNS.PROJECTED, postion, Colors.Black)); if (ABAdjustment > 0) { InfoGrid.Children.Add(BuildPlayerInfoRow(String.Format("{0}+{1}", player.Actual, ABAdjustment), COLUMNS.ACTUAL, postion, Colors.Black)); } else { InfoGrid.Children.Add(BuildPlayerInfoRow(player.Actual.ToString(), COLUMNS.ACTUAL, postion, Colors.Black)); } InfoGrid.Children.Add(BuildPlayerInfoRow(Convert.ToString(remaining), COLUMNS.REMAINING, postion, remaining >= 0 ? Colors.Black : Colors.Red)); InfoGrid.Children.Add(BuildPlayerInfoRow(player.Bal, COLUMNS.BAL, postion, Colors.Black)); InfoGrid.Children.Add(BuildPlayerInfoRow(buildPositionDisplayString(positions), COLUMNS.POSITIONS, postion, Colors.Black)); postion++; } }
private void BTN_DELETE_Click(object sender, EventArgs e) { LineupDataObj selected = (LineupDataObj)listBox1.SelectedItem; if (selected != null) { listBox1.Items.Remove(selected); storedLineups.Lineups.Remove(selected.getLineupData()); BTN_DELETE.Enabled = listBox1.Items.Count > 0; BTN_EDIT.Enabled = listBox1.Items.Count > 0; BTN_SAVE.Enabled = true; } }
private void btnMoveDown_Click(object sender, EventArgs e) { LineupDataObj selected = (LineupDataObj)listBox1.SelectedItem; int index = listBox1.Items.IndexOf(selected); listBox1.Items.Remove(selected); index = index + 1; listBox1.Items.Insert(index, selected); listBox1.Refresh(); listBox1.SelectedItem = selected; btnMoveUp.Enabled = index > listBox1.Items.Count - 1; }
private void lineup_player_SelectionChanged(object sender, SelectionChangedEventArgs e) { ComboBox cb = (ComboBox)sender; if (cb.SelectedItem != null) { LineupDataObj lineup = (LineupDataObj)cb.GetValue(MainWindow.dp); PositionObj position = (PositionObj)cb.GetValue(MainWindow.dpPos); Team team = (Team)this.CB_LIST_OF_TEAMS.SelectedItem; List <Player> players = engine.TeamReportFile.getTeamBatters(team); batterInfo.setPlayers(players); return; } }
public LineupMgrDlg(Boolean testMode) { if (!testMode) { InitializeComponent(); } WorkingLineup = new LineupDataObj(RecordIndex.getNextId(RecordIndex.INDEX.LineupDataId)); balanceItems = LineupTools.buildDefaultLineupTypes(); if (!testMode) { populateComboBoxes(CB_FROM, CB_TO, null); } }
private void BTN_SAVE_Click(object sender, EventArgs e) { if (CB_FROM.SelectedItem == null || CB_TO.SelectedItem == null || ((LineupBalanceItem)CB_FROM.SelectedItem).Value > ((LineupBalanceItem)CB_TO.SelectedItem).Value) { MessageBox.Show("FROM Selection must be less than or equal to the TO Selection"); return; } WorkingLineup = new LineupDataObj(RecordIndex.getNextId(RecordIndex.INDEX.LineupDataId)); WorkingLineup.BalanceItemFrom = (LineupBalanceItem)CB_FROM.SelectedItem; WorkingLineup.BalanceItemTo = (LineupBalanceItem)CB_TO.SelectedItem; WorkingLineup.PitcherArm = radioButtonLH.Checked ? "L" : "R"; this.Close(); }
private void BTN_EDIT_Click(object sender, EventArgs e) { LineupDataObj selected = (LineupDataObj)listBox1.SelectedItem; LineupMgrDlg dlg = new LineupMgrDlg(selected); if (dlg.ShowDialog(this) == DialogResult.OK) { int index = listBox1.Items.IndexOf(selected); listBox1.Items.Remove(selected); selected = dlg.WorkingLineup; listBox1.Items.Insert(index, selected); listBox1.Refresh(); BTN_SAVE.Enabled = true; } }
private void LineupListDlg_Load(object sender, EventArgs e) { BTN_DELETE.Enabled = false; BTN_SAVE.Enabled = false; BTN_EDIT.Enabled = false; int index = 0; foreach (LineupData data in storedLineups.Lineups) { LineupDataObj obj = new LineupDataObj(data); listBox1.Items.Add(obj); BTN_DELETE.Enabled = true; index++; } }
private void BTN_ADD_Click(object sender, EventArgs e) { LineupMgrDlg dlg = new LineupMgrDlg(); if (dlg.ShowDialog(this) == DialogResult.OK) { LineupDataObj data = dlg.WorkingLineup; storedLineups.Lineups.Add(data.getLineupData()); listBox1.Items.Add(data); } if (listBox1.Items.Count > 0) { BTN_SAVE.Enabled = true; BTN_DELETE.Enabled = true; } }
private ComboBox BuildPlayerPostitionBox(int col, POSITIONS postion, LineupDataObj teamLineup, List <Player> players, int index) { ComboBox playerBox = new ComboBox(); playerBox.Items.Add("NOT SET"); // playerBox.Items.Add(index.ToString()); playerBox.FontSize = 12; playerBox.FontWeight = FontWeights.Normal; playerBox.Foreground = new SolidColorBrush(Colors.Green); playerBox.VerticalAlignment = VerticalAlignment.Top; playerBox.SelectedIndex = 0; playerBox.SelectionChanged += lineup_player_SelectionChanged; playerBox.SetValue(dp, teamLineup); playerBox.SetValue(dpPos, new PositionObj(postion)); addPlayersByPosition(playerBox, players, postion, teamLineup.EstimatedAtBats); Grid.SetRow(playerBox, (int)postion); Grid.SetColumn(playerBox, col); return(playerBox); }
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(); }
private int lookupEstimatedAtBatForLineup(List <Dictionary <int, int> > results, LineupDataObj lineup) { int pitcherArmIndex = lineup.PitcherArm.Equals("L") ? 0 : 1; LineupData data = lineup.getLineupData(); int estimatedAtBats = SOMTeamReportFile.calculateAtBatsByLineup(results[pitcherArmIndex], data); return(estimatedAtBats); }