Example #1
0
        public void AssignDropinSpotToWaiting(Pool thePool, Game theGame)
        {
            if (IsReservationLocked(theGame.Date) || theGame.WaitingList.Count == 0 || !IsSpotAvailable(thePool, theGame.Date))
            {
                return;
            }
            Waiting waiting  = theGame.WaitingList[0];
            String  playerId = waiting.PlayerId;
            Player  player   = Manager.FindPlayerById(playerId);

            ReserveSpot(thePool, theGame, player);
            Manager.ReCalculateFactor(thePool, theGame.Date);
            theGame.WaitingList.Remove(playerId);
            Manager.AddReservationNotifyWechatMessage(playerId, null, Constants.WAITING_TO_RESERVED, thePool, thePool, theGame.Date);
            LogHistory log = CreateLog(Manager.EastDateTimeNow, theGame.Date, GetUserIP(), thePool.Name, Manager.FindPlayerById(playerId).Name, "Reserved", "Admin");

            Manager.Logs.Add(log);
            theGame.WaitingList.Remove(playerId);
            //Cancel the member spot in another pool on same day
            Pool sameDayPool = Manager.Pools.Find(pool => pool.Name != thePool.Name && pool.DayOfWeek == thePool.DayOfWeek);

            if (CancelSpot(sameDayPool, sameDayPool.FindGameByDate(theGame.Date), player))
            {
                Manager.ReCalculateFactor(sameDayPool, theGame.Date);
                Manager.AddReservationNotifyWechatMessage(playerId, null, Constants.CANCELLED, sameDayPool, sameDayPool, theGame.Date);
                AssignDropinSpotToWaiting(sameDayPool, sameDayPool.FindGameByDate(theGame.Date));
            }
        }
Example #2
0
        //Calculate factor for next reservation
        public decimal CalculateNextFactor(Pool pool, DateTime gameDate)
        {
            Pool   anotherDayPool             = Manager.Pools.Find(p => p.DayOfWeek != pool.DayOfWeek && p.IsLowPool == pool.IsLowPool);
            Game   game                       = pool.FindGameByDate(gameDate);
            int    currentPoolNumberOfPlayer  = game.NumberOfReservedPlayers;
            Pool   sameDayPool                = Manager.Pools.Find(p => p.DayOfWeek == pool.DayOfWeek && p.Name != pool.Name);
            Game   sameDayPoolGame            = sameDayPool.FindGameByDate(gameDate);
            int    sameDayPoolNumberOfPlayers = sameDayPoolGame.NumberOfReservedPlayers;
            Factor factor                     = null;

            if (pool.IsLowPool)
            {
                int coopNumberOfPlayers = sameDayPool.FindGameByDate(gameDate).Dropins.Items.FindAll(pickup => pickup.IsCoop && pickup.Status == InOutNoshow.In).Count;
                //sameDayPoolNumberOfPlayers = sameDayPoolNumberOfPlayers - coopNumberOfPlayers;
                int moveIntern = CalculateMoveIntern(sameDayPool, pool, sameDayPoolGame, game);
                if (gameDate == Manager.EastDateTimeToday && Manager.EastDateTimeNow.Hour >= pool.ReservHourForCoop && Manager.EastDateTimeNow.Hour < pool.SettleHourForCoop && //
                    moveIntern == 1 && DropinSpotAvailableForCoop(sameDayPool, gameDate))                                                                                       //Move to high pool
                {
                    coopNumberOfPlayers++;
                    sameDayPoolNumberOfPlayers++; //A
                }
                else
                {
                    currentPoolNumberOfPlayer++;                                                                                                                                                                              //B
                }
                factor = Manager.Factors.Find(f => f.PoolName == anotherDayPool.Name && f.LowPoolName == pool.Name && f.LowPoolNumberFrom <= currentPoolNumberOfPlayer && currentPoolNumberOfPlayer <= f.LowPoolNumberTo &&   //
                                              f.CoopNumberFrom <= coopNumberOfPlayers && coopNumberOfPlayers <= f.CoopNumberTo && f.HighPoolName == sameDayPool.Name && f.HighPoolNumberFrom <= sameDayPoolNumberOfPlayers && //
                                              sameDayPoolNumberOfPlayers <= f.HighPoolNumberTo);
            }
            else
            {
                int coopNumberOfPlayers = pool.FindGameByDate(gameDate).Dropins.Items.FindAll(pickup => pickup.IsCoop && pickup.Status == InOutNoshow.In).Count;
                //currentPoolNumberOfPlayer = currentPoolNumberOfPlayer - coopNumberOfPlayers;
                int moveIntern = CalculateMoveIntern(pool, sameDayPool, game, sameDayPoolGame);
                if (gameDate == Manager.EastDateTimeToday && Manager.EastDateTimeNow.Hour >= pool.ReservHourForCoop && Manager.EastDateTimeNow.Hour < pool.SettleHourForCoop && //
                    coopNumberOfPlayers > 0 && moveIntern == -1 && sameDayPoolGame.NumberOfReservedPlayers < sameDayPool.MaximumPlayerNumber)                                   //Move back to low pool
                {
                    coopNumberOfPlayers--;
                    sameDayPoolNumberOfPlayers++;//B
                }
                else
                {
                    currentPoolNumberOfPlayer++;                                                                                                                                                                                     //A
                }
                factor = Manager.Factors.Find(f => f.PoolName == anotherDayPool.Name && f.LowPoolName == sameDayPool.Name && f.LowPoolNumberFrom <= sameDayPoolNumberOfPlayers && sameDayPoolNumberOfPlayers <= f.LowPoolNumberTo && //
                                              f.CoopNumberFrom <= coopNumberOfPlayers && coopNumberOfPlayers <= f.CoopNumberTo && f.HighPoolName == pool.Name && f.HighPoolNumberFrom <= currentPoolNumberOfPlayer &&                //
                                              currentPoolNumberOfPlayer <= f.HighPoolNumberTo);
            }
            if (factor == null)
            {
                return(0);
            }
            return(factor.Value);
        }
Example #3
0
        public void AutoMoveCoopPlayers(DayOfWeek day, DateTime gameDate)
        {
            List <Pool> pools = Manager.Pools.FindAll(pool => pool.DayOfWeek == day);

            if (pools.Count != 2)
            {
                return;
            }
            Pool highPool = Manager.Pools.Find(pool => pool.DayOfWeek == day && !pool.IsLowPool);
            Pool lowPool  = Manager.Pools.Find(pool => pool.DayOfWeek == day && pool.IsLowPool);

            if (highPool.AutoCoopReserve && Manager.EastDateTimeToday == gameDate.Date && Manager.EastDateTimeNow.Hour >= highPool.ReservHourForCoop)
            {
                //Set last coop date for each coop player
                CalculatelastCoopDate(highPool, gameDate);
                Game highPoolGame = highPool.FindGameByDate(gameDate);
                Game lowPoolGame  = lowPool.FindGameByDate(gameDate);
                int  moveIntern   = CalculateMoveIntern(highPool, lowPool, highPoolGame, lowPoolGame);
                if (moveIntern == -1 && Manager.EastDateTimeNow.Hour < highPool.SettleHourForCoop)
                {
                    Dropin coopDropin = FindBestCoopCandidateToMoveBackOrignalPool(highPool, highPoolGame, lowPoolGame);
                    if (coopDropin != null)
                    {
                        Player coopPlayer = Manager.FindPlayerById(coopDropin.PlayerId);
                        MoveReservation(lowPool, lowPoolGame, coopPlayer);
                        Manager.ReCalculateFactor(lowPool, gameDate);
                        //Manager.ReCalculateFactor(highPool, gameDate);
                        String wechatMessage = String.Format("Sorry, but we had to move your spot back to pool {0} for tonight's volleyball in order to balance the players in each pool. However we may move your spot again later when things change.", lowPool.Name);
                        Manager.WechatNotifier.AddNotifyWechatMessage(coopPlayer, wechatMessage);
                        Manager.AddReservationNotifyWechatMessage(coopPlayer.Id, CurrentUser.Id, Constants.MOVED, lowPool, highPool, lowPoolGame.Date);
                        LogHistory log = CreateLog(Manager.EastDateTimeNow, gameDate.Date, GetUserIP(), lowPool.Name, coopPlayer.Name, "Moved from " + highPool.Name, "Admin");
                        Manager.Logs.Add(log);
                        DataAccess.Save(Manager);
                    }
                    return;
                }
                //Check to see if moving coop to high level pool required, and number of reserved coop players already reaches maximum
                while (moveIntern == 1 && DropinSpotAvailableForCoop(highPool, gameDate))
                {
                    //Find the best coop
                    Dropin coopDropin = FindNextCoopCandidateToMoveHighPool(highPool, highPoolGame, lowPoolGame);
                    if (coopDropin == null)
                    {
                        break;
                    }
                    Player coopPlayer = Manager.FindPlayerById(coopDropin.PlayerId);
                    MoveReservation(highPool, highPoolGame, coopPlayer);
                    Manager.ReCalculateFactor(lowPool, gameDate);
                    //Manager.ReCalculateFactor(highPool, gameDate);
                    String wechatMessage = String.Format("We have moved your spot from pool {0} to pool {1} for tonight's volleyball in order to balance the players in each pool. However we may move you back later when things change." //
                                                         + " if you don't receive any further notification by {2} o'clock, then this is the final arrangement.", lowPool.Name, highPool.Name, highPool.SettleHourForCoop);
                    Manager.WechatNotifier.AddNotifyWechatMessage(coopPlayer, wechatMessage);
                    Manager.AddReservationNotifyWechatMessage(coopPlayer.Id, null, Constants.MOVED, highPool, lowPool, lowPoolGame.Date);
                    LogHistory log = CreateLog(Manager.EastDateTimeNow, gameDate.Date, GetUserIP(), highPool.Name, coopPlayer.Name, "Moved from " + lowPool.Name, "Admin");
                    Manager.Logs.Add(log);
                    DataAccess.Save(Manager);
                    moveIntern = CalculateMoveIntern(highPool, lowPool, highPoolGame, lowPoolGame);
                }
            }
        }
Example #4
0
        private decimal CalculateFactorBonus(Pool thePool, Player player)
        {
            decimal sum = 0;

            if (thePool.StatsType == StatsTypes.None.ToString())
            {
                return(sum);
            }
            if (thePool.StatsType == StatsTypes.Week.ToString())
            {
                Pool sameLevelPool = Manager.Pools.Find(p => p.DayOfWeek != thePool.DayOfWeek && p.IsLowPool == thePool.IsLowPool);
                foreach (Game game in sameLevelPool.Games)
                {
                    //Skip the games that are earlier than specified date or later than today
                    if (game.Date < Manager.AttendRateStartDate.Date || game.Date.Date >= Manager.EastDateTimeToday.Date)
                    {
                        continue;
                    }
                    if (game.AllPlayers.Items.Exists(member => member.PlayerId == player.Id && member.Status == InOutNoshow.In))
                    {
                        sum = sum + game.Factor;
                    }
                    else
                    {
                        Pool otherPoolOnSameDay = Manager.Pools.Find(p => p.IsLowPool != sameLevelPool.IsLowPool && p.DayOfWeek == sameLevelPool.DayOfWeek);
                        Game theGame            = otherPoolOnSameDay.FindGameByDate(game.Date);
                        if (theGame.AllPlayers.Items.Exists(member => member.PlayerId == player.Id && member.Status == InOutNoshow.In))
                        {
                            sum = sum + game.Factor;
                        }
                    }
                }
            }
            return(sum);
        }
Example #5
0
        public decimal CalculateFactor(Pool pool, Pool lowPool, Pool highPool, DateTime gameDate)
        {
            int lowPoolNumberOfPlayer  = lowPool.FindGameByDate(gameDate).NumberOfReservedPlayers;
            int highPoolNumberOfPlayer = highPool.FindGameByDate(gameDate).NumberOfReservedPlayers;
            int coopNumberOfPlayers    = highPool.FindGameByDate(gameDate).Dropins.Items.FindAll(pickup => pickup.IsCoop && pickup.Status == InOutNoshow.In).Count;
            //highPoolNumberOfPlayer = highPoolNumberOfPlayer - coopNumberOfPlayers;
            Factor factor = Manager.Factors.Find(f => f.PoolName == pool.Name && f.LowPoolName == lowPool.Name && f.LowPoolNumberFrom <= lowPoolNumberOfPlayer && lowPoolNumberOfPlayer <= f.LowPoolNumberTo &&           //
                                                 f.CoopNumberFrom <= coopNumberOfPlayers && coopNumberOfPlayers <= f.CoopNumberTo && f.HighPoolName == highPool.Name && f.HighPoolNumberFrom <= highPoolNumberOfPlayer && //
                                                 highPoolNumberOfPlayer <= f.HighPoolNumberTo);

            if (factor == null)
            {
                return(0);
            }
            return(factor.Value);
        }
Example #6
0
        //

        /*     public bool IsPlayerAttendedThisMondayGameWithPowerReserveFactor(Pool fridayPool, DateTime fridayGameDate, Player player)
         *   {
         *       if (fridayPool.Dropins.FindByPlayerId(player.Id).WaiveBenefit || !IsPlayerAttendedThisWeekMondayGame(fridayGameDate, player)) return false;
         *       Pool mondayPool = Pools.Find(p => p.DayOfWeek != fridayPool.DayOfWeek && p.IsLowPool == fridayPool.IsLowPool);
         *       Game mostRecentGame = mondayPool.Games.Find(game => game.Date.AddDays(4) == fridayGameDate.Date);
         *       return mostRecentGame != null && mostRecentGame.Factor >= mondayPool.FactorForPowerReserve;
         *   }
         */
        //Calculate factor for current moment
        public void ReCalculateFactor(Pool pool, DateTime gameDate)
        {
            Pool anotherDayPoolWithSameLevel      = Pools.Find(p => p.DayOfWeek != pool.DayOfWeek && p.IsLowPool == pool.IsLowPool);
            Pool anotherDayPoolWithDifferentLevel = Pools.Find(p => p.DayOfWeek != pool.DayOfWeek && p.IsLowPool != pool.IsLowPool);
            Game game = pool.FindGameByDate(gameDate);
            int  currentPoolNumberOfPlayer = game.NumberOfReservedPlayers;
            Pool sameDayPool                = Pools.Find(p => p.DayOfWeek == pool.DayOfWeek && p.Name != pool.Name);
            Game sameDayPoolGame            = sameDayPool.FindGameByDate(gameDate);
            int  sameDayPoolNumberOfPlayers = sameDayPoolGame.NumberOfReservedPlayers;

            if (pool.IsLowPool)
            {
                int    coopNumberOfPlayers = sameDayPool.FindGameByDate(gameDate).Dropins.Items.FindAll(pickup => pickup.IsCoop && pickup.Status == InOutNoshow.In).Count;
                Factor factor = Factors.Find(f => f.PoolName == anotherDayPoolWithSameLevel.Name && f.LowPoolName == pool.Name && f.LowPoolNumberFrom <= currentPoolNumberOfPlayer && currentPoolNumberOfPlayer <= f.LowPoolNumberTo && //
                                             f.CoopNumberFrom <= coopNumberOfPlayers && coopNumberOfPlayers <= f.CoopNumberTo && f.HighPoolName == sameDayPool.Name && f.HighPoolNumberFrom <= sameDayPoolNumberOfPlayers &&            //
                                             sameDayPoolNumberOfPlayers <= f.HighPoolNumberTo);
                if (factor != null)
                {
                    game.Factor = factor.Value;
                }
                factor = Factors.Find(f => f.PoolName == anotherDayPoolWithDifferentLevel.Name && f.LowPoolName == pool.Name && f.LowPoolNumberFrom <= currentPoolNumberOfPlayer && currentPoolNumberOfPlayer <= f.LowPoolNumberTo && //
                                      f.CoopNumberFrom <= coopNumberOfPlayers && coopNumberOfPlayers <= f.CoopNumberTo && f.HighPoolName == sameDayPool.Name && f.HighPoolNumberFrom <= sameDayPoolNumberOfPlayers &&                 //
                                      sameDayPoolNumberOfPlayers <= f.HighPoolNumberTo);
                if (factor != null)
                {
                    sameDayPoolGame.Factor = factor.Value;
                }
            }
            else
            {
                int    coopNumberOfPlayers = pool.FindGameByDate(gameDate).Dropins.Items.FindAll(pickup => pickup.IsCoop && pickup.Status == InOutNoshow.In).Count;
                Factor factor = Factors.Find(f => f.PoolName == anotherDayPoolWithSameLevel.Name && f.LowPoolName == sameDayPool.Name && f.LowPoolNumberFrom <= sameDayPoolNumberOfPlayers && sameDayPoolNumberOfPlayers <= f.LowPoolNumberTo && //
                                             f.CoopNumberFrom <= coopNumberOfPlayers && coopNumberOfPlayers <= f.CoopNumberTo && f.HighPoolName == pool.Name && f.HighPoolNumberFrom <= currentPoolNumberOfPlayer &&                             //
                                             currentPoolNumberOfPlayer <= f.HighPoolNumberTo);
                if (factor != null)
                {
                    game.Factor = factor.Value;
                }
                factor = Factors.Find(f => f.PoolName == anotherDayPoolWithDifferentLevel.Name && f.LowPoolName == sameDayPool.Name && f.LowPoolNumberFrom <= sameDayPoolNumberOfPlayers && sameDayPoolNumberOfPlayers <= f.LowPoolNumberTo && //
                                      f.CoopNumberFrom <= coopNumberOfPlayers && coopNumberOfPlayers <= f.CoopNumberTo && f.HighPoolName == pool.Name && f.HighPoolNumberFrom <= currentPoolNumberOfPlayer &&                                  //
                                      currentPoolNumberOfPlayer <= f.HighPoolNumberTo);
                if (factor != null)
                {
                    sameDayPoolGame.Factor = factor.Value;
                }
            }
        }
Example #7
0
        private void FillGameInfoTable(Pool pool, DateTime gameDate)
        {
            FillNavTable();
            int memberPlayers = pool.GetNumberOfAttendingMembers(gameDate);
            int dropinPlayers = pool.GetNumberOfDropins(gameDate);
            int span          = 7;

            FillGameInfoRow("Date", 1, ((DateTime)Session[Constants.GAME_DATE]).ToString("ddd, MMM d, yyyy"), span);
            if (gameDate.DayOfWeek == DayOfWeek.Thursday)
            {
                FillGameInfoRow("Time", 1, Constants.THURSDAY_GAME_TIME, span);
            }
            else
            {
                FillGameInfoRow("Time", 1, pool.GameScheduleTime, span);
            }
            //Manager.ReCalculateFactor(pool, gameDate);
            Game game = pool.FindGameByDate(gameDate);

            if (game.Factor > 0)
            {
                FillGameInfoRow("Factor/Next", span, game.Factor.ToString() + " / " + Handler.CalculateNextFactor(CurrentPool, gameDate).ToString(), 1);
            }
            FillGameInfoRow("Members", span, memberPlayers.ToString(), 1);
            TableRow  dropinRow   = new TableRow();
            TableCell dropinLabel = new TableCell();

            dropinLabel.Text            = "Drop-ins";
            dropinLabel.HorizontalAlign = HorizontalAlign.Left;
            dropinRow.Cells.Add(dropinLabel);
            for (int i = 0; i < span - 1; i++)
            {
                TableCell cell = new TableCell();
                cell.Text = "&nbsp;";
                dropinRow.Cells.Add(cell);
            }
            TableCell dropinValue = new TableCell();

            //dropinValue.Text = dropinPlayers.ToString() + " / " + (pool.MaximumPlayerNumber - memberPlayers - dropinPlayers < 0 ? 0 : pool.MaximumPlayerNumber - memberPlayers - dropinPlayers);
            dropinValue.Text            = dropinPlayers.ToString();
            dropinValue.HorizontalAlign = HorizontalAlign.Right;
            dropinRow.Cells.Add(dropinValue);
            this.GameInfoTable.Rows.Add(dropinRow);
            //FillGameInfoRow("Drop-ins",span, dropinPlayers.ToString(),1);
            if (pool.HasCap)
            {
                FillGameInfoRow("Total/Max", span, (memberPlayers + dropinPlayers).ToString() + " / " + pool.MaximumPlayerNumber, 1);
            }
            else
            {
                FillGameInfoRow("Total Players", span, (memberPlayers + dropinPlayers).ToString(), 1);
            }
        }
Example #8
0
        protected void MemberChangeAttendance_Click(object sender, ImageClickEventArgs e)
        {
            ImageButton btn      = (ImageButton)sender;
            String      playerId = btn.ID.Split(',')[0];

            if (!IsAuthencated(playerId))
            {
                return;
            }
            DateTime date   = DateTime.Parse(btn.ID.Split(',')[1]);
            Player   player = Manager.FindPlayerById(playerId);
            Game     game   = CurrentPool.FindGameByDate(date);

            if (game.Absences.Exists(playerId))
            {
                Absence absence = (Absence)game.Absences.FindByPlayerId(playerId);
                if (absence.TransferId != null)
                {
                    Transfer transfer = player.FindTransferById(absence.TransferId);
                    player.Transfers.Remove(transfer);
                }
                game.Absences.Remove(absence);
            }
            else
            {
                //Check authorization
                if (!this.IsAdmin)
                {
                    if (Request.Cookies[Constants.PRIMARY_USER] == null)
                    {
                        ShowMessage("Sorry, but your device is not linked to the user " + player.Name + ", Please contact admin for advice");
                        return;
                    }

                    String operatorId = Request.Cookies[Constants.PRIMARY_USER].Value;
                    if (operatorId != player.Id && !player.AuthorizedUsers.Contains(operatorId))
                    {
                        ShowMessage("Sorry, but you are not authorized to make the cancellation for " + player.Name + ", Please contact admin for advice");
                        return;
                    }
                }
                Absence absence = new Absence(playerId);
                if (!Manager.ClubMemberMode)
                {
                    Transfer transfer = new Transfer(game.Date);
                    player.Transfers.Add(transfer);
                    absence.TransferId = transfer.TransferId;
                }
                game.Absences.Add(absence);
            }
            DataAccess.Save(Manager);
            Response.Redirect(Request.RawUrl);
        }
Example #9
0
        private List <Player> GetDropinPlayers(Pool pool, DateTime gameDate)
        {
            List <Player> players = new List <Player>();
            Game          game    = pool.FindGameByDate(gameDate);

            foreach (Attendee attendee in game.Dropins.Items)
            {
                Player player = Manager.FindPlayerById(attendee.PlayerId);
                players.Add(player);
            }
            return(players.OrderBy(dropin => dropin.Name).ToList());
        }
Example #10
0
        private IEnumerable <Player> OrderMembersByName(Pool pool, DateTime gameDate)
        {
            Game          game    = pool.FindGameByDate(gameDate);
            List <Player> players = new List <Player>();

            foreach (Attendee attendee in game.Members.Items)
            {
                Player player = Manager.FindPlayerById(attendee.PlayerId);
                //player.TotalPlayedCount = CalculatePlayedStats(player, CurrentPool.StatsType);
                players.Add(player);
            }
            //return players.OrderByDescending(p => p.TotalPlayedCount);
            return(players.OrderBy(p => p.Name));
        }
Example #11
0
        private bool IsReservedInAnotherPool(String playerId)
        {
            //Check to see if the player has dropin spot in another pool on same day
            Pool sameDayPool = Manager.Pools.Find(pool => pool.Name != CurrentPool.Name && pool.DayOfWeek == CurrentPool.DayOfWeek);

            if (sameDayPool != null)
            {
                if (sameDayPool.FindGameByDate(TargetGameDate).Members.Items.Exists(member => member.PlayerId == playerId && member.Status == InOutNoshow.In) ||
                    sameDayPool.FindGameByDate(TargetGameDate).Dropins.Items.Exists(dropin => dropin.PlayerId == playerId && dropin.Status == InOutNoshow.In))
                {
                    Session[Constants.ACTION_TYPE] = Constants.ACTION_MOVE_RESERVATION;
                    ShowPopupModal("You have aleady reserved a spot in pool " + sameDayPool.Name + " on the same day. Would you like to cancel that and reserve this?");
                    return(true);
                }
                else if (sameDayPool.FindGameByDate(TargetGameDate).WaitingList.Exists(playerId))
                {
                    Session[Constants.ACTION_TYPE] = Constants.ACTION_MOVE_RESERVATION;
                    ShowPopupModal("You are aleady on the waiting list of pool " + sameDayPool.Name + " on the same day. Would you like to cancel that and reserve this?");
                    return(true);
                }
            }
            return(false);
        }
Example #12
0
        protected void AddWaitingList_Confirm_Click(object sender, ImageClickEventArgs e)
        {
            String playerId = Session[Constants.CURRENT_PLAYER_ID].ToString();
            Game   game     = CurrentPool.FindGameByDate(TargetGameDate);

            if (game.WaitingList.Exists(playerId))
            {
                return;
            }
            Pool otherPool = Manager.Pools.Find(p => p.Name != CurrentPool.Name && p.DayOfWeek == CurrentPool.DayOfWeek);

            if (otherPool != null && otherPool.Members.Exists(playerId) && !otherPool.FindGameByDate(TargetGameDate).Members.Items.Exists(member => member.PlayerId == playerId && member.Status == InOutNoshow.In))
            {
                //Changed to allow holding a member spot in another pool when putting into waiting list
                // ShowMessage("Sorry, But you have aleady reserved a spot in pool " + pool.Name + " on the same day. Cancel that spot before adding onto the waiting list");
                //return;
            }
            if (otherPool != null && otherPool.Dropins.Exists(playerId) && otherPool.FindGameByDate(TargetGameDate).Dropins.Items.Exists(dropin => dropin.PlayerId == playerId && dropin.Status == InOutNoshow.In))
            {
                ShowMessage("Sorry, But you have aleady reserved a dropin spot in pool " + otherPool.Name + " on the same day. Cancel that spot beforeadding onto the waiting list");
                return;
            }
            else if (otherPool.FindGameByDate(TargetGameDate).WaitingList.Exists(playerId))
            {
                ShowMessage("Sorry, But you are on waiting list in pool " + otherPool.Name + " on the same day. Cancel that before adding onto the waiting list");
                return;
            }
            Handler.AddToWaitingList(CurrentPool, game, Manager.FindPlayerById(playerId));
            Manager.AddReservationNotifyWechatMessage(playerId, CurrentUser.Id, Constants.WAITING, CurrentPool, CurrentPool, TargetGameDate);
            LogHistory log = Handler.CreateLog(Manager.EastDateTimeNow, game.Date, Handler.GetUserIP(), CurrentPool.Name, Manager.FindPlayerById(playerId).Name, "Added to waiting list", CurrentUser.Name);

            Manager.Logs.Add(log);
            Handler.AutoMoveCoopPlayers(CurrentPool.DayOfWeek, game.Date);
            DataAccess.Save(Manager);
            Response.Redirect(Constants.RESERVE_PAGE);
        }
Example #13
0
        //Return the original pool where spot is moved from
        public Pool MoveReservation(Pool pool, Game game, Player player)
        {
            ReserveSpot(pool, game, player);
            //Cancel the spot in other pool
            Pool sameDayPool = Manager.Pools.Find(p => p.DayOfWeek == pool.DayOfWeek && p.Name != pool.Name);

            if (CancelSpot(sameDayPool, sameDayPool.FindGameByDate(game.Date), player))
            {
                return(sameDayPool);
            }
            else
            {
                return(null);
            }
        }
Example #14
0
        protected void Move_Confirm_Click(object sender, EventArgs e)
        {
            Game   game     = CurrentPool.FindGameByDate(TargetGameDate);
            String playerId = Session[Constants.CURRENT_PLAYER_ID].ToString();
            Player player   = Manager.FindPlayerById(playerId);

            if (game.Members.Items.Exists(member => member.PlayerId == playerId && member.Status == InOutNoshow.In) ||
                game.Dropins.Items.Exists(dropin => dropin.PlayerId == playerId && dropin.Status == InOutNoshow.In) ||
                game.WaitingList.Exists(playerId))
            {
                Pool sameDayPool = Manager.Pools.Find(p => p.DayOfWeek == CurrentPool.DayOfWeek && p.Name != CurrentPool.Name);
                game = sameDayPool.FindGameByDate(TargetGameDate);
                MoveSpot(sameDayPool, game, player);
                return;
            }

            MoveSpot(CurrentPool, game, player);
        }
Example #15
0
        public bool AllowMemberAddReservation(Pool pool, DateTime gameDate, Player player)
        {
            DateTime reserveDate = gameDate;

            //Allow member to reserve before the time of dropin reservation
            if (Manager.EastDateTimeNow < reserveDate.AddDays(-1 * pool.DaysToReserve).AddHours(-1 * reserveDate.Hour + Manager.DropinSpotOpeningHour))
            {
                return(true);
            }
            else //Allow member to add back to reservation list if no dropin yet
            {
                Game game = pool.FindGameByDate(gameDate);
                if (game.Dropins.Items.FindAll(d => d.Status == InOutNoshow.In).Count == 0)
                {
                    return(true);
                }
            }
            return(false);
        }
Example #16
0
        private void RanderPoolFactorList()
        {
            Pool poolA = Manager.Pools.Find(p => p.DayOfWeek == DayOfWeek.Monday && !p.IsLowPool);
            Pool poolB = Manager.Pools.Find(p => p.DayOfWeek == DayOfWeek.Monday && p.IsLowPool);

            if (poolA == null || poolB == null)
            {
                return;
            }
            foreach (Game gameA in poolA.Games.FindAll(g => g.Date <= Manager.EastDateTimeToday))
            {
                Game     gameB = poolB.FindGameByDate(gameA.Date);
                TableRow row   = new TableRow();
                AddTableCell(row, gameA.Date.ToShortDateString());
                AddTableCell(row, gameB.NumberOfReservedPlayers.ToString());
                AddTableCell(row, gameB.Factor);
                AddTableCell(row, gameA.Dropins.Items.FindAll(d => d.IsCoop && d.Status == InOutNoshow.In).Count.ToString());
                AddTableCell(row, gameA.NumberOfReservedPlayers.ToString());
                AddTableCell(row, gameA.Factor);
                this.PoolGameFactorTable.Rows.Add(row);
            }
        }
Example #17
0
        private void FillMemberTable(Pool pool, DateTime date)
        {
            IEnumerable <Player> playerQuery = OrderMembersByName(pool, date);
            bool spotsFilledup  = !Handler.IsSpotAvailable(pool, date);
            bool alterbackcolor = false;

            foreach (Player player in playerQuery)
            {
                //If this player is on the waiting list, don't list it in member section
                Game comingGame = pool.FindGameByDate(date);
                if (comingGame.WaitingList.Exists(player.Id))
                {
                    continue;
                }
                //
                Member   member = pool.Members.FindByPlayerId(player.Id);
                TableRow row    = new TableRow();
                if (alterbackcolor)
                {
                    row.BackColor = MemberTable.BorderColor;
                }
                alterbackcolor = !alterbackcolor;
                if (player.Id == GetOperatorId())
                {
                    row.BackColor   = System.Drawing.Color.CadetBlue;
                    row.BorderStyle = BorderStyle.Outset;
                }
                TableCell  nameCell = new TableCell();
                LinkButton nameLink = new LinkButton();
                nameLink.Text      = player.Name;
                nameLink.Font.Bold = true;
                nameLink.Font.Size = new FontUnit(Constants.LINKBUTTON_FONTSIZE);
                nameLink.ID        = player.Id + ",MEMEBER";
                this.MemberTable.Rows.Add(row);
                nameCell.Controls.Add(nameLink);

                /* if (player.Marked)
                 * {
                 *   Image image = new Image();
                 *   image.ImageUrl = "~/Icons/Colorball.png";
                 *   //nameCell.Controls.Add(image);
                 * }*/
                foreach (Fee fee in player.Fees)
                {
                    if (!fee.IsPaid && fee.Amount > 0)
                    {
                        Image image = new Image();
                        image.ImageUrl = "~/Icons/dollar.png";
                        nameCell.Controls.Add(image);
                    }
                }
                row.Cells.Add(nameCell);
                TableCell statusCell = new TableCell();
                statusCell.HorizontalAlign = HorizontalAlign.Right;
                ImageButton imageBtn = new ImageButton();
                imageBtn.ID = player.Id;
                //If current user is not permit to reserve for this player, disable the image btn
                if (Handler.IsPermitted(Actions.View_Player_Details, player))
                {
                    nameLink.Click += new EventHandler(Username_Click);
                }
                if (!Handler.IsPermitted(Actions.Reserve_Player, player))
                {
                    imageBtn.Enabled = false;
                }
                Game     game     = pool.FindGameByDate(date);
                Attendee attdenee = game.Members.FindByPlayerId(player.Id);
                if (attdenee.Status == InOutNoshow.Out)
                {
                    imageBtn.ImageUrl = "~/Icons/Out.png";
                    imageBtn.Click   += new ImageClickEventHandler(Reserve_Click);
                }
                else if (attdenee.Status == InOutNoshow.In)
                {
                    if (attdenee.Confirmed)
                    {
                        imageBtn.ImageUrl = "~/Icons/In.png";
                        imageBtn.Click   += new ImageClickEventHandler(Cancel_Click);
                        if (CurrentPool.IsLowPool && Manager.ActionPermitted(Actions.Move_To_High_Pool, CurrentUser.Role))
                        {
                            ImageButton moveBtn = new ImageButton();
                            moveBtn.ID       = player.Id + ",move";
                            moveBtn.Width    = new Unit(Constants.IMAGE_BUTTON_SIZE);
                            moveBtn.Height   = new Unit(Constants.IMAGE_BUTTON_SIZE);
                            moveBtn.ImageUrl = "~/Icons/Move.png";
                            moveBtn.Click   += MoveFromCurrentPool_Click;
                            statusCell.Controls.Add(moveBtn);
                        }
                    }
                    else
                    {
                        imageBtn.ImageUrl = "~/Icons/toConfirm.png";
                        imageBtn.Click   += new ImageClickEventHandler(Confirm_Click);
                    }
                }
                else//No show
                {
                    imageBtn.ImageUrl = "~/Icons/noShow.png";
                    imageBtn.Click   += new ImageClickEventHandler(Cancel_Click);
                }
                //imageBtn.Click += new ImageClickEventHandler(MemberChangeAttendance_Click);
                imageBtn.Width  = new Unit(Constants.IMAGE_BUTTON_SIZE);
                imageBtn.Height = new Unit(Constants.IMAGE_BUTTON_SIZE);
                //  imageBtn.CssClass = "imageBtn";
                statusCell.Controls.Add(imageBtn);
                row.Cells.Add(statusCell);
            }
        }
Example #18
0
        protected void Page_Load(object sender, EventArgs e)
        {
            String poolName = this.Request.Params[Constants.POOL];

            if (poolName != null)
            {
                Session[Constants.POOL] = poolName;
                if (CurrentPool == null)
                {
                    return;
                }
            }
            else
            {
                return;
            }
            this.PoolStatTable.Caption = Manager.Season + this.PoolStatTable.Caption;
            //  Calculate attendence statistics for games;
            int         less12         = 0;
            int         less14         = 0;
            int         full           = 0;
            int         fullAndWaiting = 0;
            List <Game> fullGames      = new List <Game>();

            foreach (Game game in CurrentPool.Games.FindAll(g => g.Date < Manager.EastDateTimeToday))
            {
                int attended = game.AllPlayers.Items.FindAll(p => p.Status == InOutNoshow.In).Count;
                if (attended < 12)
                {
                    less12++;
                }
                else if (attended < 14)
                {
                    less14++;
                }
                else
                {
                    full++;
                    if (game.WaitingList.Count > 0)
                    {
                        fullAndWaiting++;
                        // this.PoolStatTable.Caption = this.PoolStatTable.Caption + "|" + game.Date.ToShortDateString();
                    }
                }
            }
            TableRow row = new TableRow();
            //Total
            TableCell cell = new TableCell();

            cell.Text = CurrentPool.Games.FindAll(g => g.Date < Manager.EastDateTimeToday).Count.ToString();
            row.Cells.Add(cell);
            //Less 12
            cell      = new TableCell();
            cell.Text = less12.ToString();// + " / "+ less14.ToString();
            row.Cells.Add(cell);
            //Less 14
            cell      = new TableCell();
            cell.Text = (less14).ToString();// + " / "+ less14.ToString();
            row.Cells.Add(cell);
            //Full no waiting
            cell      = new TableCell();
            cell.Text = full.ToString();// +"/ " + full.ToString();
            row.Cells.Add(cell);
            //Full and waiting
            cell      = new TableCell();
            cell.Text = fullAndWaiting.ToString();// +" / " + fullAndWaiting.ToString();
            row.Cells.Add(cell);
            this.PoolStatTable.Rows.Add(row);
            //Fill ful game table
            int index = 1;

            foreach (Game game in CurrentPool.Games.FindAll(g => g.Date.Date < Manager.EastDateTimeToday))
            {
                row = new TableRow();
                //Order
                cell      = new TableCell();
                cell.Text = (index++).ToString();
                row.Cells.Add(cell);
                //Date
                cell      = new TableCell();
                cell.Text = game.Date.ToShortDateString();
                row.Cells.Add(cell);
                //reserved
                cell      = new TableCell();
                cell.Text = game.AllPlayers.Items.FindAll(p => p.Status == InOutNoshow.In).Count.ToString();
                row.Cells.Add(cell);
                //Intern
                cell = new TableCell();
                int intern = 0;
                if (CurrentPool.IsLowPool)
                {
                    Pool highPool = Manager.FindSameDayPool(CurrentPool);
                    intern = highPool.FindGameByDate(game.Date).Dropins.Items.FindAll(d => d.Status == InOutNoshow.In && d.IsCoop).Count;
                }
                cell.Text = intern.ToString();
                row.Cells.Add(cell);
                //Waiting list
                cell      = new TableCell();
                cell.Text = game.WaitingList.Count.ToString();;
                row.Cells.Add(cell);
                //Factor
                cell      = new TableCell();
                cell.Text = game.Factor.ToString();;
                row.Cells.Add(cell);
                this.FullTable.Rows.Add(row);
            }
        }
Example #19
0
        private void FillDropinTable(Pool pool, DateTime gameDate)
        {
            //Calcuate stats for dropins
            Game game = pool.FindGameByDate(gameDate);

            if (game.DropinRestricted)
            {
                DropinCandidateTable.Caption = "Dropin Restricted for this time!";
                return;
            }
            List <Player> players    = GetDropinPlayers(pool, gameDate);
            Dropin        nextIntern = null;

            if (!pool.IsLowPool && pool.AutoCoopReserve)
            {
                Game lowPoolGame = Manager.FindSameDayPool(pool).FindGameByDate(gameDate);
                nextIntern = Handler.FindNextCoopCandidateToMoveHighPool(CurrentPool, game, lowPoolGame);
            }
            foreach (Player player in players)
            {
                Attendee attdenee = game.Dropins.FindByPlayerId(player.Id);
                if (attdenee.Status != InOutNoshow.Out)
                {
                    TableRow row = CreateDropinTableRow(player, attdenee, game.WaitingList.Exists(player.Id));
                    this.DropinTable.Rows.Add(row);
                    this.DropinTable.Visible = true;
                }
                else if (!game.WaitingList.Exists(player.Id))// if (dropinSpotAvailable)
                {
                    Dropin dropin = CurrentPool.Dropins.FindByPlayerId(player.Id);
                    if (dropin != null)
                    {
                        if (!Manager.ActionPermitted(Actions.Power_Reserve, CurrentUser.Role) && dropin.IsCoop && pool.AutoCoopReserve && (nextIntern == null || nextIntern.PlayerId != dropin.PlayerId))
                        {
                            continue;
                        }
                        TableRow row = CreateDropinTableRow(player, attdenee, game.WaitingList.Exists(player.Id));
                        this.DropinCandidateTable.Rows.Add(row);
                        if (DropinCandidateTable.Rows.Count % 2 == 1)
                        {
                            row.BackColor = DropinCandidateTable.BorderColor;
                        }
                        if (player.Id == GetOperatorId())
                        {
                            row.BorderStyle = BorderStyle.Double;
                            row.BackColor   = System.Drawing.Color.DarkOrange;
                        }
                        if (nextIntern != null && nextIntern.PlayerId == dropin.PlayerId)
                        {
                            row.BorderStyle = BorderStyle.Double;
                            row.BackColor   = System.Drawing.Color.Beige;
                        }
                    }
                }
            }

            // List<Player> waitingList = Manager.FindPlayersByIds(game.WaitingList.getPlayerIds());
            foreach (Waiting waiting in game.WaitingList.Items)
            {
                Player   player = Manager.FindPlayerById(waiting.PlayerId);
                TableRow row    = CreateDropinTableRow(player, game.Dropins.FindByPlayerId(player.Id), game.WaitingList.Exists(player.Id));
                this.DropinWaitingTable.Rows.Add(row);
                this.DropinWaitingTable.Visible = true;
            }

            if (pool.AllowAddNewDropinName && Manager.ActionPermitted(Actions.Add_New_Player, CurrentUser.Role))
            {
                TableRow  addRow      = new TableRow();
                TableCell addNameCell = new TableCell();
                // TextBox nameTb = new TextBox();
                //nameTb.ID = "DropinNameTb";
                //this.DropinNameTb.Visible = true;
                addNameCell.Controls.Add(DropinNameTb);
                // addNameCell.Controls.Add(RequiredFieldValidator);
                addRow.Cells.Add(addNameCell);
                TableCell addCell = new TableCell();
                addCell.HorizontalAlign = HorizontalAlign.Right;
                ImageButton addImageBtn = new ImageButton();
                addImageBtn.ImageUrl = "~/Icons/Add.png";
                addImageBtn.Width    = new Unit(Constants.IMAGE_BUTTON_SIZE);
                addImageBtn.Height   = new Unit(Constants.IMAGE_BUTTON_SIZE);
                addImageBtn.Click   += new ImageClickEventHandler(AddNewDropin_Click);
                addCell.Controls.Add(addImageBtn);
                addRow.Cells.Add(addCell);
                this.DropinCandidateTable.Rows.Add(addRow);
            }
            else
            {
                this.DropinNameTb.Visible = false;
            }
        }
Example #20
0
        public void AddReservationNotifyWechatMessage(String playerId, String operatorId, String result, Pool targetPool, Pool originalPool, DateTime gameDate)
        {
            if (IsReservationLocked(gameDate))
            {
                return;
            }
            Player player = FindPlayerById(playerId);
            //if (player.Marked && result == Constants.CANCELLED) return;
            Player user    = operatorId == null ? null : FindPlayerById(operatorId);
            String message = null;
            int    numberOfReservedPlayerInTargetPool = targetPool.FindGameByDate(gameDate).NumberOfReservedPlayers;

            String poolAndGameDate = " of the " + targetPool.DayOfWeek + " volleyball on " + gameDate.ToString("MM/dd/yyyy") + " in pool " + targetPool.Name + ".";
            String playerNumber    = " Total player number in pool : " + numberOfReservedPlayerInTargetPool;

            if (result == Constants.RESERVED || result == Constants.CANCELLED)
            {
                if (playerId == operatorId)
                {
                    message = "You " + result.ToString() + poolAndGameDate;
                }
                else
                {
                    message = (user == null ? "Admin" : user.Name) + " " + result.ToString() + poolAndGameDate;
                }
                if (EastDateTimeToday.AddDays(7) < gameDate)
                {
                    WechatNotifier.AddNotifyWechatMessage(targetPool, player, message);
                }
                else
                {
                    message = message + playerNumber;
                    Game game = targetPool.FindGameByDate(gameDate);
                    if (game.Factor > 0)
                    {
                        message = message + ". Current factor is " + game.Factor;
                    }
                    WechatNotifier.AddNotifyWechatMessage(targetPool, player, message);
                    if (player.Role != (int)Roles.Guest && result == Constants.RESERVED && wechatNotifier.EnableReserveEmoMessage)
                    {
                        int emoType = (int)EmoTypes.Reserve;
                        WechatNotifier.AddNotifyWechatMessage(targetPool, player, wechatNotifier.GetEmoMessage(emoType, numberOfReservedPlayerInTargetPool));
                    }
                    if (player.Role != (int)Roles.Guest && result == Constants.CANCELLED && wechatNotifier.EnableCancelEmoMessage)
                    {
                        int emoType = (int)EmoTypes.Cancel;
                        WechatNotifier.AddNotifyWechatMessage(targetPool, player, wechatNotifier.GetEmoMessage(emoType, numberOfReservedPlayerInTargetPool));
                    }
                }
            }
            else if (result == Constants.WAITING_TO_RESERVED)
            {
                message = "Congratus! One spot became available in pool " + targetPool.Name + ", and reserved it for you." + playerNumber;
                Game game = targetPool.FindGameByDate(gameDate);
                if (game.Factor > 0)
                {
                    message = message + ". Current factor is " + game.Factor;
                }
                WechatNotifier.AddNotifyWechatMessage(player, message);
                if (EastDateTimeToday == gameDate.Date && EastDateTimeNow.Hour >= lockWaitingListHour)
                {
                    WechatNotifier.AddNotifyWechatMessage(player, "It is kind of late, if you cannot make it, please cancel it right away. Thank you!");
                }
                WechatNotifier.AddNotifyWechatMessage(targetPool, player, message);
            }
            else if (result == Constants.MOVED)
            {
                message = result.ToString() + " from pool " + originalPool.Name + " to pool " + targetPool.Name + " for the " + targetPool.DayOfWeek + " volleyball on " + gameDate.ToString("MM/dd/yyyy");
                WechatNotifier.AddNotifyWechatMessage(player, message);
                String wechatMessage = message + ". Total player number in pool " + originalPool.Name + ": " + originalPool.FindGameByDate(gameDate).NumberOfReservedPlayers;
                Game   game          = originalPool.FindGameByDate(gameDate);
                if (game.Factor > 0)
                {
                    wechatMessage = wechatMessage + ". Current factor is " + game.Factor;
                }
                WechatNotifier.AddNotifyWechatMessage(originalPool, player, wechatMessage);
                wechatMessage = message + ". Total player number in pool " + targetPool.Name + ": " + numberOfReservedPlayerInTargetPool;
                game          = targetPool.FindGameByDate(gameDate);
                if (game.Factor > 0)
                {
                    wechatMessage = wechatMessage + ". Current factor is " + game.Factor;
                }
                WechatNotifier.AddNotifyWechatMessage(targetPool, player, wechatMessage);
                if (wechatNotifier.EnableReserveEmoMessage)
                {
                    WechatNotifier.AddNotifyWechatMessage(targetPool, player, wechatNotifier.GetEmoMessage((int)EmoTypes.Move, numberOfReservedPlayerInTargetPool));
                }
            }
            else if (result == Constants.WAITING)
            {
                message = (user == null ? "Admin" : (playerId == operatorId? "You" : user.Name)) + " " + result.ToString();
                WechatNotifier.AddNotifyWechatMessage(targetPool, player, message + poolAndGameDate);
            }
        }