private void FillDropinTable(Pool pool) { //Calcuate stats for dropins List <Player> players = GetDropinPlayers(pool); foreach (Player player in players) { Dropin dropin = CurrentPool.Dropins.FindByPlayerId(player.Id); if (dropin != null) { TableRow row = CreateDropinTableRow(player); 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; } } } this.DropinNameTb.Visible = false; }
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); } } }
protected void DropinListbox_SelectedIndexChanged(object sender, EventArgs e) { Dropin dropin = CurrentPool.Dropins.FindByPlayerId(DropinListbox.SelectedValue); this.DropinCoopCb.Checked = dropin.IsCoop; this.WaiveBenefitCb.Checked = dropin.WaiveBenefit; //Response.Redirect(Request.RawUrl); }
protected void DropinListbox_SelectedIndexChanged(object sender, EventArgs e) { Dropin dropin = CurrentPool.Dropins.Find(attendee => attendee.Id == DropinListbox.SelectedValue); this.DropinCoopCb.Checked = dropin.IsCoop; this.DropinSuspendedCb.Checked = dropin.IsSuspended; //Response.Redirect(Request.RawUrl); }
protected void SaveDropinBtn_Click(object sender, EventArgs e) { Dropin dropin = CurrentPool.Dropins.Find(attendee => attendee.Id == DropinListbox.SelectedValue); dropin.IsCoop = this.DropinCoopCb.Checked; dropin.IsSuspended = this.DropinSuspendedCb.Checked; DataAccess.Save(Manager); // Response.Redirect(Request.RawUrl); }
//Get number of coop for the date public int GetNumberOfReservedCoops(DateTime date) { Game game = FindGameByDate(date); int coop = 0; foreach (Pickup pickup in game.Pickups.Items) { Dropin dropin = this.Dropins.Find(drop_in => drop_in.Id == pickup.PlayerId); if (dropin != null && dropin.IsCoop) { coop++; } } return(coop); }
private Dropin FindBestCoopCandidateToMoveBackOrignalPool(Pool highPool, Game highPoolGame, Game lowPoolGame) { Dropin coopCandidate = null; //Find the best candidate of coop //Filter the coop who cancelled his spot for coming game in his original pool List <Dropin> coopPickups = highPool.Dropins.Items.FindAll(coop => coop.IsCoop && // highPoolGame.Dropins.FindByPlayerId(coop.PlayerId) != null && highPoolGame.Dropins.FindByPlayerId(coop.PlayerId).Status == InOutNoshow.In && // lowPoolGame.AllPlayers.FindByPlayerId(coop.PlayerId) != null && lowPoolGame.AllPlayers.FindByPlayerId(coop.PlayerId).Status == InOutNoshow.Out); //Compare the last coop date to find the best one foreach (Dropin dropin in coopPickups) { if (coopCandidate == null || coopCandidate.LastCoopDate <= dropin.LastCoopDate) { coopCandidate = dropin; } } return(coopCandidate); }
protected void AddNewDropin_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(DropinNameTb.Text)) { return; } ImageButton lbtn = (ImageButton)sender; TextBox nameTb = DropinNameTb;//(TextBox)FindControl("DropinNameTb"); Player nmb = Manager.FindPlayerByName(nameTb.Text); if (nmb == null) { nmb = new Player(nameTb.Text.Trim(), null, false); Dropin dropin = new Dropin(nmb.Id); CurrentPool.Dropins.Add(dropin); } DataAccess.Save(Manager); Response.Redirect(Request.RawUrl); //TableRow row = CreateDropinTableRow(dropin); // this.DropinTable.Rows.AddAt(this.DropinTable.Rows.Count -1, row); }
public Dropin FindNextCoopCandidateToMoveHighPool(Pool highPool, Game highPoolGame, Game lowPoolGame) { Dropin coopCandidate = null; //Find the best candidate of coop //Excluding the coop who cancelled his spot for coming game in his original pool, but including the intern is the first one in waiting list List <Dropin> interns = highPool.Dropins.Items.FindAll(coop => coop.IsCoop && // highPoolGame.Dropins.FindByPlayerId(coop.PlayerId) != null && highPoolGame.Dropins.FindByPlayerId(coop.PlayerId).Status == InOutNoshow.Out && // lowPoolGame.AllPlayers.FindByPlayerId(coop.PlayerId) != null && (lowPoolGame.AllPlayers.FindByPlayerId(coop.PlayerId).Status == InOutNoshow.In || // (lowPoolGame.WaitingList.Count > 0 && lowPoolGame.WaitingList[0].PlayerId == coop.PlayerId))); //intern is the first peron in waiting list //If search result is empty, //Compare the last coop date to find the best one List <Dropin> candidates = new List <Dropin>(); foreach (Dropin dropin in interns) { //ignore the intern who did not attend the game in low pool last time Game previewGame = Manager.FindSameDayPool(highPool).Games.OrderByDescending(game => game.Date).ToList <Game>().Find(game => game.Date < lowPoolGame.Date); //Game previewHighPoolGame = highPool.FindGameByDate(previewGame.Date); if (previewGame != null && previewGame.AllPlayers.Items.Exists(p => p.PlayerId == dropin.PlayerId && p.Status == InOutNoshow.In))// || // //previewHighPoolGame.AllPlayers.Items.Exists(p => p.PlayerId == dropin.PlayerId && p.Status == InOutNoshow.In))) { candidates.Add(dropin); } } //if no one in the result, then all the interns will be candidetes if (candidates.Count == 0) { candidates = interns; } foreach (Dropin dropin in candidates) { if (coopCandidate == null || coopCandidate.LastCoopDate > dropin.LastCoopDate) { coopCandidate = dropin; } } return(coopCandidate); }
protected void SaveDropinBtn_Click(object sender, EventArgs e) { Dropin dropin = CurrentPool.Dropins.FindByPlayerId(DropinListbox.SelectedValue); dropin.IsCoop = this.DropinCoopCb.Checked; dropin.WaiveBenefit = this.WaiveBenefitCb.Checked; //dropin.IsSuspended = this.DropinSuspendedCb.Checked; //Update future game foreach (Game game in CurrentPool.Games) { if (game.Date >= DateTime.Today) { Pickup attendee = game.Dropins.FindByPlayerId(dropin.PlayerId); if (attendee != null) { attendee.IsCoop = dropin.IsCoop; } } } DataAccess.Save(Manager); // Response.Redirect(Request.RawUrl); }
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; } }
public void AddDropin(Player player) { Dropin dropin = new Dropin(player.Id); Dropins.Add(dropin); }
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; } // Calculate attendence statistics for games; int less12 = 0; int less12WithoutCoop = 0; int less14 = 0; int less14WithoutCoop = 0; int full = 0; int fullWithoutCoop = 0; int fullAndWaiting = 0; int fullAndWaitingWithoutCoop = 0; List <Game> fullGames = new List <Game>(); foreach (Game game in CurrentPool.Games) { if (CurrentPool.GetNumberOfAvaliableMembers() - game.Absences.Count + game.Pickups.Count < 12) { less12++; } if (CurrentPool.GetNumberOfAvaliableMembers() - game.Absences.Count + game.Pickups.Count < 14) { less14++; } else { full++; if (game.WaitingList.Count > 0) { fullAndWaiting++; // this.PoolStatTable.Caption = this.PoolStatTable.Caption + "|" + game.Date.ToShortDateString(); } } } foreach (Game game in CurrentPool.Games) { int pickups = 0; foreach (Pickup pickup in game.Pickups.Items) { Dropin dropin = CurrentPool.Dropins.Find(player => player.Id == pickup.PlayerId); if (dropin == null || !dropin.IsCoop) { pickups++; } } if (CurrentPool.GetNumberOfAvaliableMembers() - game.Absences.Count + pickups < 12) { less12WithoutCoop++; } if (CurrentPool.GetNumberOfAvaliableMembers() - game.Absences.Count + pickups < 14) { less14WithoutCoop++; } else { fullWithoutCoop++; fullGames.Add(game); foreach (Waiting waiting in game.WaitingList.Items) { Dropin dropin = CurrentPool.Dropins.Find(player => player.Id == waiting.PlayerId); if (dropin == null || !dropin.IsCoop) { fullAndWaitingWithoutCoop++; break; } } } } TableRow row = new TableRow(); //Total TableCell cell = new TableCell(); cell.Text = CurrentPool.Games.Count.ToString(); row.Cells.Add(cell); //Less 12 cell = new TableCell(); cell.Text = less12WithoutCoop.ToString();// + " / "+ less14.ToString(); row.Cells.Add(cell); //Less 14 cell = new TableCell(); cell.Text = (less14WithoutCoop - less12WithoutCoop).ToString();// + " / "+ less14.ToString(); row.Cells.Add(cell); //Full no waiting cell = new TableCell(); cell.Text = fullWithoutCoop.ToString();// +"/ " + full.ToString(); row.Cells.Add(cell); //Full and waiting cell = new TableCell(); cell.Text = fullAndWaitingWithoutCoop.ToString();// +" / " + fullAndWaiting.ToString(); row.Cells.Add(cell); this.PoolStatTable.Rows.Add(row); //Fill ful game table int index = 1; foreach (Game fullGame in fullGames) { row = new TableRow(); //Order cell = new TableCell(); cell.Text = (index++).ToString(); row.Cells.Add(cell); //Date cell = new TableCell(); cell.Text = fullGame.Date.ToShortDateString(); row.Cells.Add(cell); //Waiting list cell = new TableCell(); String waitingListNames = null; foreach (Waiting waiting in fullGame.WaitingList.Items) { Player player = Manager.FindPlayerById(waiting.PlayerId); waitingListNames = waitingListNames == null ? player.Name : waitingListNames + "," + player.Name; } cell.Text = waitingListNames; row.Cells.Add(cell); this.FullTable.Rows.Add(row); } }
private void AddMember(String playerId) { CurrentPool.Members.Add(new Member(playerId)); //Add to reserved list for the future games foreach (Game game in CurrentPool.Games) { if (game.Date >= DateTime.Today) { game.Members.Add(new Attendee(playerId, InOutNoshow.In)); } } //Change the player to club registered member and create membership fee it is club member mode Player player = Manager.FindPlayerById(playerId); if (Manager.ClubMemberMode) { if (!player.IsRegisterdMember) { player.IsRegisterdMember = true; Fee fee = new Fee(Fee.FEETYPE_CLUB_MEMBERSHIP, Manager.RegisterMembeshipFee); fee.FeeType = FeeTypeEnum.Membership.ToString(); fee.Date = DateTime.Today; player.Fees.Add(fee); } } else { Fee fee = new Fee(CurrentPool.MembershipFee); fee.FeeType = FeeTypeEnum.Membership.ToString(); fee.FeeDesc = String.Format(Fee.FEETYPE_MEMBERSHIP, CurrentPool.Name); fee.Date = DateTime.Today; player.Fees.Add(fee); } this.MemberListbox.DataSource = GetPlayers(CurrentPool.Members); this.MemberListbox.DataBind(); this.MemberLb.Text = "Members(" + CurrentPool.Members.Count + ")"; if (CurrentPool.DayOfWeek == DayOfWeek.Friday) { return; } //Register Friday games on same week or next week foreach (Pool pool in Manager.FindFridayPools()) { Dropin dropin = pool.Dropins.FindByPlayerId(player.Id); if (dropin != null && !dropin.IsCoop) { //Add reservation for all the games in this pool foreach (Game game in pool.Games) { if (game.Date >= Manager.EastDateTimeToday) { Pickup pickup = game.Dropins.FindByPlayerId(playerId); if (pickup == null) { pickup = new Pickup(playerId); game.Dropins.Add(new Pickup(playerId)); } pickup.Status = InOutNoshow.In; } } } DataAccess.Save(Manager); } }