private void buttonNewBreak_Clicked(object sender, EventArgs e) { if (App.Navigator.GetOpenedPage(typeof(RecordBreakPage)) != null) { return; } var page = new RecordBreakPage(this.metadata, false, true); App.Navigator.NavPage.Navigation.PushModalAsync(page); page.Done += async(s1, e1) => { SnookerBreak snookerBreak = e1; this.metadataControl.Fill(this.metadata); if (snookerBreak == null) { return; } if (page.IsOpponentsBreak == false) { // save this as a notable break Result result = new Result(); snookerBreak.PostToResult(result); result.AthleteID = App.Repository.GetMyAthleteID(); result.TimeModified = DateTimeHelper.GetUtcNow(); App.Repository.AddResult(result); await App.Navigator.GoToMyProfile(ProfilePersonStateEnum.Breaks, true); App.Navigator.StartSyncAndCheckForNotifications(); } else { // save this as opponent's break Result result = new Result(); snookerBreak.PostToResult(result); result.AthleteID = metadata.OpponentAthleteID; result.OpponentAthleteID = App.Repository.GetMyAthleteID(); result.TimeModified = DateTimeHelper.GetUtcNow(); result.IsNotAcceptedByAthleteYet = true; App.Repository.AddResult(result); App.Navigator.StartSyncAndCheckForNotifications(); App.Navigator.DisplayAlertRegular("The break was recorded as a notable break for '" + metadata.OpponentAthleteName + "'. Once the data is synced with snookerbyb.com, '" + metadata.OpponentAthleteName + "' will be able to accept it."); } }; }
void ctrl_UserWantsToEditBreak(object sender, SnookerEventArgs e) { if (this.IsMyAthlete == false) { return; } SnookerBreak snookerBreak = e.SnookerBreak; if (snookerBreak.OpponentConfirmation == OpponentConfirmationEnum.Confirmed) { App.Navigator.DisplayAlertRegular("Cannot edit a confirmed break."); return; } var page = new RecordBreakPage(snookerBreak, false, true); App.Navigator.NavPage.Navigation.PushModalAsync(page); page.Done += async(s1, e1) => { snookerBreak = e1; if (snookerBreak == null) { return; } // update Result result = App.Repository.GetResult(snookerBreak.ID); result.TimeModified = DateTimeHelper.GetUtcNow(); result.OpponentConfirmation = (int)OpponentConfirmationEnum.NotYet; snookerBreak.PostToResult(result); App.Repository.UpdateResult(result); await App.Navigator.GoToMyProfile(ProfilePersonStateEnum.Breaks, true); App.Navigator.StartSyncAndCheckForNotifications(); }; }
private async void listOfBreaksInMatchControl_UserTappedOnBreak(object sender, SnookerBreak snookerBreak) { if (Config.IsTablet == false && this.isPastBreaksExpanded == false) { this.panelPastBreaksTapped(); return; } string strPoints = snookerBreak.Points.ToString(); string strOtherPlayer = ((snookerBreak.AthleteID == MatchScore.YourAthleteID) ? (MatchScore.OpponentName ?? "Opponent") : MatchScore.YourName); string strEdit = "Edit"; string strDelete = "Delete"; string strReassign = "Assign to " + strOtherPlayer; string strResult1 = await this.DisplayActionSheet(snookerBreak.Points.ToString() + " point break", "Cancel", null, strDelete, strReassign, strEdit); if (string.IsNullOrEmpty(strResult1) || strResult1 == "Cancel") { return; } if (strResult1 == strEdit) { RecordBreakPage page = new RecordBreakPage(snookerBreak, false, false); await this.Navigation.PushModalAsync(page); page.Done += (s1, updatedBreak) => { if (updatedBreak == null || updatedBreak.Points == 0) { return; } // update balls on table this.snookerBreakControl.breakEdited(snookerBreak, updatedBreak); int diff = updatedBreak.Points - snookerBreak.Points; if (snookerBreak.OpponentAthleteID != this.MatchScore.YourAthleteID) { this.CurrentFrameScore.A = System.Math.Max(0, this.CurrentFrameScore.A + diff); } else { this.CurrentFrameScore.B = System.Math.Max(0, this.CurrentFrameScore.B + diff); } snookerBreak.Points = updatedBreak.Points; snookerBreak.NumberOfBalls = updatedBreak.NumberOfBalls; snookerBreak.Balls = updatedBreak.Balls.ToList(); snookerBreak.IsFoul = updatedBreak.IsFoul; this.listOfBreaksInMatchControl.Fill(this.MatchScore, this.MatchScore.FrameScores.IndexOf(this.CurrentFrameScore) + 1); updateFrameScoreInSnookerBreakControl(); this.snookerBreakControl.updateFrameScoreOnBreakEdit((int)this.entryCurrentFrameA.Number, (int)this.entryCurrentFrameB.Number); }; return; } else if (strResult1 == strDelete) { string strSubtractScore = "Remove " + strPoints + " from the score?"; string strKeepScore = "Keep the score"; string strResult2 = await this.DisplayActionSheet("Frame score", "Cancel", null, strSubtractScore, strKeepScore); if (string.IsNullOrEmpty(strResult2) || strResult2 == "Cancel") { return; } if (strResult2 == strSubtractScore) { // update ballsOnTable this.snookerBreakControl.breakDeleted(snookerBreak); if (snookerBreak.OpponentAthleteID != this.MatchScore.YourAthleteID) { this.CurrentFrameScore.A = System.Math.Max(0, this.CurrentFrameScore.A - snookerBreak.Points); } else if (snookerBreak.OpponentAthleteID == this.MatchScore.YourAthleteID) { this.CurrentFrameScore.B = System.Math.Max(0, this.CurrentFrameScore.B - snookerBreak.Points); } this.MatchScore.YourBreaks.Remove(snookerBreak); this.MatchScore.OpponentBreaks.Remove(snookerBreak); } else if (strResult2 == strKeepScore) { this.MatchScore.YourBreaks.Remove(snookerBreak); this.MatchScore.OpponentBreaks.Remove(snookerBreak); } this.listOfBreaksInMatchControl.Fill(this.MatchScore, this.MatchScore.FrameScores.IndexOf(this.CurrentFrameScore) + 1); updateFrameScoreInSnookerBreakControl(); return; } else if (strResult1 == strReassign) { string strMoveScore; if (snookerBreak.OpponentAthleteID != this.MatchScore.YourAthleteID) { strMoveScore = MatchScore.YourName + " -" + snookerBreak.Points.ToString() + ", " + MatchScore.OpponentName + " +" + snookerBreak.Points.ToString(); } else { strMoveScore = MatchScore.YourName + " +" + snookerBreak.Points.ToString() + ", " + MatchScore.OpponentName + " -" + snookerBreak.Points.ToString(); } string strKeepScore = "Do NOT change the frame scores"; string strResult2 = await this.DisplayActionSheet("Re-assign the break and...", "Cancel", null, strMoveScore, strKeepScore); if (string.IsNullOrEmpty(strResult2) || strResult2 == "Cancel") { return; } if (strResult2 == strMoveScore) { if (snookerBreak.OpponentAthleteID != this.MatchScore.YourAthleteID) { this.CurrentFrameScore.A = System.Math.Max(0, this.CurrentFrameScore.A - snookerBreak.Points); this.CurrentFrameScore.B += snookerBreak.Points; } else if (snookerBreak.OpponentAthleteID == this.MatchScore.YourAthleteID) { this.CurrentFrameScore.B = System.Math.Max(0, this.CurrentFrameScore.B - snookerBreak.Points); this.CurrentFrameScore.A += snookerBreak.Points; } } if (strResult2 == strMoveScore || strResult2 == strKeepScore) { this.MatchScore.YourBreaks.Remove(snookerBreak); this.MatchScore.OpponentBreaks.Remove(snookerBreak); int a = snookerBreak.AthleteID; snookerBreak.AthleteID = snookerBreak.OpponentAthleteID; snookerBreak.OpponentAthleteID = a; string n = snookerBreak.AthleteName; snookerBreak.AthleteName = snookerBreak.OpponentName; snookerBreak.OpponentName = snookerBreak.AthleteName; snookerBreak.OpponentConfirmation = OpponentConfirmationEnum.NotYet; if (snookerBreak.AthleteID == this.MatchScore.YourAthleteID) { this.MatchScore.YourBreaks.Add(snookerBreak); } else { this.MatchScore.OpponentBreaks.Add(snookerBreak); } } this.listOfBreaksInMatchControl.Fill(this.MatchScore, this.MatchScore.FrameScores.IndexOf(this.CurrentFrameScore) + 1); updateFrameScoreInSnookerBreakControl(); return; } }