示例#1
0
 public void SetLineupSlot(BattingOrderSlot slot, int idx)
 {
     battingOrder[idx] = slot;
     lineupModified = true;
 }
示例#2
0
        public Team(DataRow row)
        {
            DataTable table;
            Initialize();
            Batter btr;

            name = row["team_name"].ToString();
            abbrev = row["abbrev"].ToString();
            id = Int32.Parse(row["team_id"].ToString());

            table = DbUtils.GetDataTable(string.Format("select * from team_record where team_id = {0}", id));

            if (table.Rows.Count == 0)
            {
                gamesPlayed = wins = losses = 0;
            }
            else
            {
                wins = Int32.Parse(table.Rows[0]["wins"].ToString());
                losses = Int32.Parse(table.Rows[0]["losses"].ToString());
                gamesPlayed = wins + losses;
            }

            table = DbUtils.GetDataTable(string.Format("select * from team_players where team_id = {0}", id));

            if (table.Rows.Count != 0)
            {
                DataTable tablePlayer;
                foreach (DataRow playerRow in table.Rows)
                {

                    tablePlayer = DbUtils.GetDataTable(string.Format("select * from players where player_id = {0}",
                        Int32.Parse(playerRow["player_id"].ToString())));

                    if (tablePlayer.Rows.Count == 0)
                    {
                        continue;
                    }
                    else
                    {
                        bool isBatter = Boolean.Parse(tablePlayer.Rows[0]["batter"].ToString());

                        if (isBatter)
                        {
                            Batter batter = new Batter(tablePlayer.Rows[0]);
                            batterList.Add(batter);
                        }
                        else
                        {
                            Pitcher pitcher = new Pitcher(tablePlayer.Rows[0]);

                            pitcherList.Add(pitcher);
                            if (pitcher.PitcherRole == PitcherType.Starter)
                            {
                                StartingPitchers.Add(pitcher);
                            }
                            else
                            {
                                bullpen.Add(pitcher);
                            }
                        }
                    }
                }
            }

            // now build lineup
            table = DbUtils.GetDataTable(string.Format("select * from team_lineup where team_id = {0} order by lineup_order", id));
            foreach (DataRow lineupRow in table.Rows)
            {
                btr = GetBatterByID(Int32.Parse(lineupRow["player_id"].ToString()));
                if (btr != null)
                {
                    int lineupSlot = Int32.Parse(lineupRow["lineup_order"].ToString()) - 1;
                    battingOrder[lineupSlot] = new BattingOrderSlot();
                    battingOrder[lineupSlot].Hitter = btr;
                    battingOrder[lineupSlot].FieldingPosition = (Position) Int32.Parse(lineupRow["position"].ToString());
                }
            }
        }
示例#3
0
 public void SetLineUp()
 {
     int i = 0;
     foreach(Batter btr in batterList)
     {
         battingOrder[i] = new BattingOrderSlot();
         battingOrder[i].Hitter = btr;
         battingOrder[i].FieldingPosition = btr.PrimaryPosition;
         i++;
     }
 }
示例#4
0
        private void saveButton_Click(object sender, EventArgs e)
        {
            BattingOrderSlot slot;
            int idx;

            if (lineupModified == true)
            {
                foreach (ListViewItem itm in lineupListView.Items)
                {
                    idx = int.Parse(itm.Text);

                    if (itm.SubItems[1].ToString() == "[empty]")
                    {
                        team.SetLineupSlot(null, idx - 1);
                    }
                    else
                    {
                        slot = new BattingOrderSlot();
                        slot.Hitter = (Batter) itm.Tag;
                        slot.FieldingPosition = EnumHelpers.StringToPosition(itm.SubItems[2].Text);
                        team.SetLineupSlot(slot, idx - 1);
                    }
                }
            }

            if (pitcherModified == true)
            {
                team.CurrentPitcher.PlayedThisGame = true;

            }

            DialogResult = DialogResult.OK;
            Close();
        }