/** * Manages the end of the current hole * saveForStatistics : true to save the stats of the current hole, false to not save them */ public void holeFinished(bool saveForStatistics) { ScoreHole sh = StatistiquesGolf.saveForStats(this, itHole.Current, saveForStatistics); ScoreOfThisPartie.add(sh); Shots.Clear(); }
/** * Saves the data of a hole * game : the game * hole : the hole to save * save : true to save the hole stats, false otherwise. false returns the ScoreHole anyway * return the created ScoreHole */ public static ScoreHole saveForStats(Partie game, Hole hole, bool save) { ScoreHole h = new ScoreHole(hole, game.getPenalityCount(), game.getCurrentScore(), isHit(game.Shots, hole.Par), nbCoupPutt(game.Shots), DateTime.Now); if (save) { if (game.Shots.Count == 0) { throw new Exception("0 shots dans la liste des shots."); } SQLite.SQLiteConnection connection = DependencyService.Get <ISQLiteDb>().GetConnection(); connection.CreateTable <Club>(); connection.CreateTable <MyPosition>(); connection.CreateTable <Shot>(); //first let's insert in the database all the shots currently stored in the game SQLiteNetExtensions.Extensions.WriteOperations.InsertOrReplaceAllWithChildren(connection, game.Shots, true); connection.CreateTable <ScoreHole>(); //then creates a ScoreHole object that stores the hole statistics and insert it in the database SQLiteNetExtensions.Extensions.WriteOperations.InsertWithChildren(connection, h, false); string sql = @"select last_insert_rowid()"; h.Id = connection.ExecuteScalar <int>(sql); } return(h); }
public DisplayScoreCard(int i, ScoreHole sh) { number = i.ToString(); par = sh.Hole.Par.ToString(); putt = sh.NombrePutt.ToString(); penalities = sh.Penality.ToString(); score = (sh.Score + sh.Hole.Par).ToString(); this.setScoreSymbol(sh.Score, sh.Hole.Par); secondFrameWidth = firstFrameWidth - 2; }
/** * Adds a ScoreHole in the scoreHole list */ public void add(ScoreHole sh) { scoreHoles.Add(sh); if (scoreHoles.Count == 1)//if first element added then init GolfName { var id = this.scoreHoles[0].Hole.Id; System.Diagnostics.Debug.WriteLine("before"); SQLite.SQLiteConnection connection = DependencyService.Get <ISQLiteDb>().GetConnection(); connection.CreateTable <GolfCourse>(); List <GolfCourse> allGolfCourses = SQLiteNetExtensions.Extensions.ReadOperations.GetAllWithChildren <GolfCourse>(connection); foreach (GolfCourse gc in allGolfCourses) { foreach (Hole h in gc.Holes) { if (h.Id.Equals(id)) { this.GolfName = gc.Name; break; } } } System.Diagnostics.Debug.WriteLine("after"); } }
/** * Creates a filled ScorePartie and insert it recursivly in the database. * Values used to create the statistics have not necessarily any sense */ public static ScorePartie CreateScorePartie() { SQLite.SQLiteConnection connection = DependencyService.Get <ISQLiteDb>().GetConnection(); connection.CreateTable <GolfCourse>(); connection.CreateTable <ScorePartie>(); connection.CreateTable <ScoreHole>(); connection.CreateTable <Shot>(); connection.CreateTable <MyPosition>(); List <GolfCourse> golfCourses = SQLiteNetExtensions.Extensions.ReadOperations.GetAllWithChildren <GolfCourse>(connection); Random r = new Random(); var holes = golfCourses[r.Next() % (golfCourses.Count)].Holes; //var holes = golfCourses[0].Holes; //DateTime date = new DateTime(2019, DateTime.Now.Month, (TestClassFactory.createdScorePartieCount % 28) + 1); DateTime date = DateTime.Now; ScorePartie sp = new ScorePartie(date); List <Shot> shots = new List <Shot>(); List <Club> clubs = SQLiteNetExtensions.Extensions.ReadOperations.GetAllWithChildren <Club>(connection); int i = 0; if (holes != null) { foreach (Hole hole in holes) { int randPutt = r.Next() % 3 + 1; int randScore = r.Next() % 9 - 3; if (TestClassFactory.createdScorePartieCount == 0) { randScore = 10; } //int randScore = 1; System.Diagnostics.Debug.WriteLine("randPutt = " + randPutt + " randScore = " + randScore + "\n"); for (int j = 0; j < randScore; ++j) { shots.Add(new Shot(clubs[2], RandomEnumValue <Shot.ShotCategory>(), DateTime.Now)); } if (i == 7 && r.Next() % 3 == 1) { randPutt = 0; } ScoreHole sh = new ScoreHole(hole, 0, randScore, randPutt == 2, randPutt, DateTime.Now); sp.add(sh); i++; } } System.Diagnostics.Debug.WriteLine("\n"); sp.DateFin = DateTime.Now; try { SQLiteNetExtensions.Extensions.WriteOperations.InsertAllWithChildren(connection, shots, true); SQLiteNetExtensions.Extensions.WriteOperations.InsertAllWithChildren(connection, sp.scoreHoles, true); SQLiteNetExtensions.Extensions.WriteOperations.InsertWithChildren(connection, sp, true); } catch (SQLiteException sqlex) { System.Diagnostics.Debug.WriteLine(sqlex.StackTrace); } List <Shot> shotss = SQLiteNetExtensions.Extensions.ReadOperations.GetAllWithChildren <Shot>(connection); System.Diagnostics.Debug.WriteLine(shotss.Count); TestClassFactory.createdScorePartieCount++; return(sp); }