public static decimal CalcPlayerPoolTime( Player player, DateTime endTime )
        {
            decimal total = 0.0M;

            if ( player.Timestamps.Count > 0 )
            {
                var orderedTimestamps = from timestamp in player.Timestamps
                                        orderby timestamp.StartTime
                                        select timestamp;

                Timestamp[] timestampArr = orderedTimestamps.ToArray();

                for ( int i = 0; i < timestampArr.Length; i++ )
                {
                    int numPlayers = timestampArr[i].NumPlayers;
                    DateTime startTime = timestampArr[i].StartTime;
                    DateTime stopTime;
                    decimal ratePerHour = GetHourlyPlayerRate( numPlayers );

                    if ( i < timestampArr.Length - 1 )
                    {
                        stopTime = timestampArr[i + 1].StartTime;
                    } else
                    {
                        stopTime = endTime;
                    }

                    total += CalcPoolTime( startTime, stopTime, ratePerHour );
                }
            }

            return total;
        }
        public static void ChangePlayerStartTime( Player player, DateTime newStartTime, DateTime currentTime )
        {
            Timestamp timestamp = null;

            IOrderedEnumerable<Timestamp> timestamps = player.Timestamps.OrderBy( t => t.ID );
            Timestamp[] timestampArr = timestamps.ToArray();
            int numTimestamps = timestampArr.Length;

            if ( newStartTime <= currentTime )
            {
                if ( numTimestamps > 1 )
                {
                    for ( int i = 1; i < numTimestamps; i++ )
                    {
                        timestamp = timestampArr[i];

                        if ( newStartTime >= timestamp.StartTime )
                        {
                            TimestampDataService.DeleteTimestamp( timestampArr[i - 1] );
                        }
                    }
                }

                IOrderedEnumerable<Timestamp> newTimestamps = player.Timestamps.OrderBy( t => t.ID );
                Timestamp firstTimestamp = newTimestamps.First();
                firstTimestamp.StartTime = newStartTime;
                firstTimestamp.Player.StartTime = newStartTime;

                TablesDB.DataContext.SubmitChanges();
            } else
            {
                throw new Exception( "Woops! Player's start time must be in the past..." );
            }
        }
        public static Player AddPlayer(string playerName, int tableNum, int numPlayers, DateTime startTime)
        {
            PoolTable table = TableDataService.GetTable(tableNum);
            Player newPlayer = new Player(tableNum, playerName, startTime);
            table.Players.Add(newPlayer);
            TablesDB.DataContext.Players.InsertOnSubmit(newPlayer);

            return newPlayer;
        }
Example #4
0
        } // end method OnPlayerAdded

        // when a player is removed from this table set the player's
        // PoolTable property to null
        private void OnPlayerRemoved(Player removedPlayer)
        {
            if (this.Players.Count < 2)
            {
                this.Status = TableStatus.Inactive;
            }

            removedPlayer.PoolTable = null;
            AddPlayerTimestamps();
        } // end method OnPlayerRemoved
Example #5
0
        } // end constructor

        // when a player is added to this table set the player's
        // PoolTable property to this
        private void OnPlayerAdded(Player addedPlayer)
        {
            if (this.Status == TableStatus.Inactive)
            {
                this.Status = TableStatus.Active;
            }

            addedPlayer.PoolTable = this;
            AddPlayerTimestamps();
        } // end method OnPlayerAdded
        public static void AddPlayer(int tableNum, string name, DateTime startTime)
        {
            PoolTable table = TableDataService.GetTable(tableNum);
            Player newPlayer = new Player(tableNum, name, startTime);
            table.Players.Add(newPlayer);
            TablesDB.DataContext.Players.InsertOnSubmit(newPlayer);
            TablesDB.DataContext.SubmitChanges();

            Timestamp newTimestamp = new Timestamp(newPlayer.ID, tableNum, startTime);
            newPlayer.Timestamps.Add(newTimestamp);
            TablesDB.DataContext.Timestamps.InsertOnSubmit(newTimestamp);
            TablesDB.DataContext.SubmitChanges();
        }
Example #7
0
        public ViewPlayerForm(Player player)
        {
            _player = player;
            _timestamps = _player.Timestamps;
            _oldStartTime = _player.StartTime;

            InitializeComponent();

            this.Text = "Table " + Convert.ToString( _player.PoolTable.TableNum ) + ": "
                 + _player.Name;

            this.lblTitle.Text = _player.Name + "'s Details";
        }
        public static void DeletePlayer( Player player )
        {
            player.PoolTable = null;

            if ( player.Timestamps.Count > 0 )
            {
                foreach ( Timestamp timestamp in player.Timestamps )
                {
                    TablesDB.DataContext.Timestamps.DeleteOnSubmit( timestamp );
                }
            }

            TablesDB.DataContext.Players.DeleteOnSubmit( player );
        }
        public static double CalcTotalPlayerHours( Player player, DateTime endTime )
        {
            double total = 0.0;

            if ( player.Timestamps.Count > 0 )
            {
                DateTime stopTime;

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

                Timestamp[] timestampArr = orderedTimestamps.ToArray();

                for ( int i = 0; i < timestampArr.Length; i++ )
                {
                    DateTime startTime = timestampArr[i].StartTime;

                    if ( i < timestampArr.Length - 1 )
                    {
                        stopTime = timestampArr[i + 1].StartTime;
                    } else
                    {
                        stopTime = endTime;
                    }

                    if ( startTime <= stopTime )
                    {
                        total += ( stopTime - startTime ).TotalHours;
                    } else
                    {
                        total += 0;
                    }
                }
            }

            return total;
        }
        public static void SetPlayerStartTime( Player player )
        {
            var timestamps = from timestamp in player.Timestamps
                             orderby timestamp.StartTime
                             select new { StartTime = timestamp.StartTime };

            player.StartTime = timestamps.First().StartTime;
        }