Esempio n. 1
0
        private void AddAllPlayers(League lge)
        {
            DataTable tablePlayer;

            tablePlayer = DbUtils.GetDataTable(string.Format("select * from players"));

            if (tablePlayer.Rows.Count == 0)
            {
                return;
            }
            else
            {
                foreach (DataRow row in tablePlayer.Rows)
                {
                    bool isBatter = Boolean.Parse(row["batter"].ToString());

                    if (isBatter)
                    {
                        Batter batter = new Batter(row);
                        lge.AddPlayer(batter);
                    }
                    else
                    {
                        Pitcher pitcher = new Pitcher(row);
                        lge.AddPlayer(pitcher);
                    }
                }
            }

            return;
        }
Esempio n. 2
0
        public SelectTeamsForm(League activeLeague)
        {
            InitializeComponent();

            league = activeLeague;

            FillTeamList(league);
        }
Esempio n. 3
0
        public League LoadLeague(int leagueID)
        {
            League league = new League();

            foreach (Team team in GetTeams(leagueID))
            {
                league.AddTeam(team);
            }

            return league;
        }
Esempio n. 4
0
        public League LoadLeague2(int leagueID)
        {
            DbUtils.SetPath(@"Data Source=D:\github-repos\ShowDownSharp\db\showdown.db");
            League league = new League();
            AddAllPlayers(league);
            foreach (Team team in GetTeams2(leagueID, league))
            {
                league.AddTeam(team);
            }

            return league;
        }
Esempio n. 5
0
        public void BindTeams(League lge)
        {
            teamGrid.Columns["abbrevColumn"].DataPropertyName = "Abbrev";
            teamGrid.Columns["teamNameColumn"].DataPropertyName = "Name";
            teamGrid.Columns["winsColumn"].DataPropertyName = "Wins";
            teamGrid.Columns["lossesColumn"].DataPropertyName = "Losses";

            bindingList = new SortableBindingList<Team>();

            teams = lge.Teams;

            foreach (Team tm in teams)
            {
                bindingList.Add(tm);
            }

            teamGrid.DataSource = bindingList;
        }
Esempio n. 6
0
        public void BindPlayers(League lge)
        {
            playerGrid.Columns[0].DataPropertyName = "Name";
            playerGrid.Columns[1].DataPropertyName = "CardSeason";
            playerGrid.Columns[2].DataPropertyName = "CardTeam";
            playerGrid.Columns[3].DataPropertyName = "Points";
            playerGrid.Columns[4].DataPropertyName = "PositionText";
            playerGrid.Columns[5].DataPropertyName = "KeyStatLine";

            SortableBindingList<Player> players = new SortableBindingList<Player>();

            foreach (Player plyr in lge.PlayerList.Values)
            {
                players.Add(plyr);
            }

            playerGrid.DataSource = players;
        }
Esempio n. 7
0
        public LeagueManager()
        {
            dbEngine = new DBEngine();
            Form frm = new SplashForm();

            Cursor = Cursors.WaitCursor;

            frm.Show();
            frm.Update();

            System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch() ;

            watch.Start();
            league = dbEngine.LoadLeague3(1);
            watch.Stop();

            MessageBox.Show(watch.Elapsed.ToString());

            InitializeComponent();

            frm.Hide();
            Cursor = Cursors.Default;

            //InitializeComponent();

            DockPanel dockPanel = new DockPanel();
            dockPanel.Dock = DockStyle.Fill;
            dockPanel.BackColor = Color.Beige;
            Controls.Add(dockPanel);
            dockPanel.BringToFront();

            leagueForm = new LeagueListForm();
            leagueForm.ShowHint = DockState.Document;
            leagueForm.Show(dockPanel);

            playerForm = new PlayerListForm();
            playerForm.ShowHint = DockState.Document;
            playerForm.Show(dockPanel);

            teamForm = new TeamListForm();
            teamForm.ShowHint = DockState.Document;
            teamForm.Show(dockPanel);
        }
Esempio n. 8
0
        private void loadLeagueToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DBEngine dbEngine = new DBEngine();
            Cursor = Cursors.WaitCursor;
            //league = dbEngine.LoadLeague(1);
            //league = dbEngine.LoadLeague2(1);
            league = dbEngine.LoadLeague3(1);

            selectTeamsToolStripMenuItem.Enabled = true;
            mnuGamePlayball.Enabled = false;
            mnuGamePlaySimulated.Enabled = false;
            mnuTeamsCreate.Enabled = false;

            AddTeamMenus();

            resetSeasonStatsToolStripMenuItem.Enabled = true;
            standingsToolStripMenuItem.Enabled = true;

            Cursor = Cursors.Default;
        }
Esempio n. 9
0
        public Team(DataRow row, League lge)
        {
            DataTable table;
            Initialize();

            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)
            {
                foreach (DataRow playerRow in table.Rows)
                {
                    Player player;
                    player = lge.GetPlayer(Int32.Parse(playerRow["player_id"].ToString()));
                    if (player == (Player)null)
                    {
                        continue;
                    }
                    else
                    {
                        player.IsOnATeam = true;
                        if (player is Batter)
                        {
                            batterList.Add((Batter)player);
                        }
                        else
                        {
                            Pitcher pitcher = (Pitcher) player;

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

            // now build lineup
            Batter btr;
            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());
                }
            }
        }
Esempio n. 10
0
 private void FillTeamList(League league)
 {
     foreach (Team team in league.Teams)
     {
         teamListBox.Items.Add(team);
     }
 }
Esempio n. 11
0
 public GameService()
 {
     engine = new GameEngine();
     dbEngine = new DBEngine();
     league = dbEngine.LoadLeague3(1);
 }
Esempio n. 12
0
        private List<Team> GetTeams2(int leagueId, League lge)
        {
            DataTable table;
            List<Team> teamList = new List<Team>();

            table = DbUtils.GetDataTable(string.Format("select * from teams where league_id = {0}", leagueId));
            foreach (DataRow row in table.Rows)
            {
                Team team = new Team(row, lge);
                teamList.Add(team);
            }

            return teamList;
        }
Esempio n. 13
0
        private void AddAllPlayers2(League lge)
        {
            Dictionary<long, DataRow> batterStats = LoadDictionary("select * from batter_stats", "player_id");
            Dictionary<long, DataRow> batterSkill = LoadDictionary("select * from batting_skill", "player_id");
            Dictionary<long, DataRow> pitcherStats = LoadDictionary("select * from pitcher_stats", "player_id");
            Dictionary<long, DataRow> pitcherSkill = LoadDictionary("select * from pitcher_skill", "player_id");
            long id;
            DataTable tablePlayer;

            tablePlayer = DbUtils.GetDataTable(string.Format("select * from players"));

            if (tablePlayer.Rows.Count == 0)
            {
                return;
            }
            else
            {
                foreach (DataRow row in tablePlayer.Rows)
                {
                    id = long.Parse(row["player_id"].ToString());

                    bool isBatter = Boolean.Parse(row["batter"].ToString());

                    if (isBatter)
                    {
                        Batter batter = new Batter(row, batterStats[id], batterSkill[id]);
                        lge.AddPlayer(batter);
                    }
                    else
                    {
                        Pitcher pitcher = new Pitcher(row, pitcherStats[id], pitcherSkill[id]);
                        lge.AddPlayer(pitcher);
                    }
                }
            }

            return;
        }