public CashOutTableForm(PoolTable table)
        {
            _table = table;

            InitializeComponent();

            this.SetTableData();

            this.SetPlayerData();
        }
        public TableDetailsForm(PoolTable table)
        {
            _table = table;
            _players = table.Players;
            _oldStartTime = TableDataService.GetStartTime(_table);

            InitializeComponent();

            this.Text = "Table " + Convert.ToString( _table.TableNum );
            this.lblTitle.Text = "Table " + Convert.ToString( _table.TableNum ) + "'s Details";
        }
        public static List<string> GetPlayerNames( PoolTable table )
        {
            List<string> playerNames = new List<string>();

            foreach (Player player in table.Players )
            {
                playerNames.Add( player.Name );
            }

            return playerNames;
        }
        public static void ChangeTableStartTime( PoolTable _table, DateTime newStartTime, DateTime currentTime )
        {
            if ( newStartTime <= currentTime )
            {

                foreach ( Player player in _table.Players )
                {
                    var oldTimestamps = from timestamp in player.Timestamps
                                        where timestamp.StartTime <= newStartTime
                                        select timestamp;

                    if ( oldTimestamps != null )
                    {
                        for ( int i = 0; i < oldTimestamps.Count(); i++ )
                        {
                            TimestampDataService.DeleteTimestamp( oldTimestamps.First() );
                        }
                    }

                    var otherTableTimestamps = from timestamp in player.Timestamps
                                     where timestamp.TableNum != _table.TableNum
                                     select timestamp;

                    if ( otherTableTimestamps != null )
                    {
                        for ( int i = 0; i < otherTableTimestamps.Count(); i++ )
                        {
                            TimestampDataService.DeleteTimestamp( otherTableTimestamps.First() );
                        }
                    }

                    var timestamps = from timestamp in player.Timestamps
                                     orderby timestamp.StartTime
                                     select timestamp;

                    if ( timestamps != null )
                    {
                        timestamps.First().StartTime = newStartTime;
                    }

                    PlayerDataService.SetPlayerStartTime( player );
                }

                TablesDB.DataContext.SubmitChanges();
            } else
            {
                throw new Exception( "Woops! Player's start time must be in the past..." );
            }
        }
        public static double CalcTotalTableHours( PoolTable table, DateTime endTime )
        {
            double total = 0.0;

            if ( table.Players.Count > 0 )
            {
                var players = from player in table.Players
                              orderby player.StartTime
                              select player;

                Player[] playersArr = players.ToArray();

                DateTime startTime = playersArr[0].StartTime;

                if ( startTime <= endTime )
                {
                    total = ( endTime - startTime ).TotalHours;
                } else
                {
                    total = 0.0;
                }
            }

            return total;
        }
        public static decimal CalcTablePoolTime( PoolTable table, DateTime endTime )
        {
            decimal total = 0.0M;

            if ( table.Players.Count > 0 )
            {
                foreach ( Player player in table.Players )
                {
                    total += CalcPlayerPoolTime( player, endTime );
                }
            }

            return total;
        }
        public static void UpdateTimestamps( PoolTable table, DateTime timestamp)
        {
            if ( table.Players.Count > 0 )
            {
                int numPlayers = table.Players.Count;

                foreach ( Player player in table.Players )
                {
                    Timestamp newTimestamp = new Timestamp(
                        player.ID, table.TableNum, numPlayers, timestamp );

                    player.Timestamps.Add( newTimestamp );

                    TablesDB.DataContext.Timestamps.InsertOnSubmit( newTimestamp );
                }
            }
        }
        public static void StopTable(PoolTable table)
        {
            List<Player> players = new List<Player>();

            foreach ( Player player in table.Players )
            {
                players.Add( player );
            }

            table.Players.Clear();

            foreach ( Player player in players )
            {
                PlayerDataService.DeletePlayer( player );
            }

            TablesDB.DataContext.SubmitChanges();
        }
        public static DateTime GetStartTime( PoolTable table )
        {
            var players = from player in table.Players
                          orderby player.StartTime
                          select new { StartTime = player.StartTime };

            return players.First().StartTime;
        }