Пример #1
0
 public Partie()
 {
     Shots                  = new List <Shot>();
     CurrentClub            = GolfXMLReader.getClubFromName("Fer3");
     ScoreOfThisPartie      = new ScorePartie();
     this.holeFinishedCount = -1;
 }
        /**
         * Inserts a golf course in the database from an xml string describing the golf course
         * xmlGolfCourse : the xml string describing the golf course
         */
        private void InsertGolfCourseBdd(String xmlGolfCourse)
        {
            GolfCourse gc;

            try
            {
                gc = GolfXMLReader.getSingleGolfCourseFromText(xmlGolfCourse);
                SQLite.SQLiteConnection connection = DependencyService.Get <ISQLiteDb>().GetConnection();
                try
                {
                    connection.CreateTable <Hole>();
                    connection.CreateTable <MyPosition>();
                    connection.CreateTable <GolfCourse>();
                    connection.BeginTransaction();
                    SQLiteNetExtensions.Extensions.WriteOperations.InsertWithChildren(connection, gc, true);
                    connection.Commit();
                    this.DisplayAlert("Succès", "Le " + this.pins.Count + " trous : " + golfNameEntry.Text + " a été créé avec succès", "Continuer");
                    this.ManageAllPinsDelete();
                }
                catch (SQLiteException bddException)
                {
                    this.DisplayAlert("Erreur avec la base de donnée", bddException.Source + " : Ce nom de golf existe déjà ou une autre erreur inattendu s'est produite", "Ok");
                    connection.Rollback();
                }
            }
            catch (Exception xmlConversionException)
            {
                this.DisplayAlert("Erreur lors de la conversion XML -> GolfCourse", xmlConversionException.StackTrace, "Ok");
            }
        }
        /**
         * When the index is completed by the user, update the profile in the database and the average distance of each club
         */
        private async void OnIndexCompleted(object sender, EventArgs e)
        {
            LocalUser.Index = double.Parse(((Entry)sender).Text);
            DBconnection.Update(LocalUser);
            List <Club> clubs = await GestionGolfs.getListClubsAsync(null);

            List <Club> xmlClubs = GolfXMLReader.getListClubFromXMLFiles();

            foreach (Club club in clubs)
            {
                club.DistanceMoyenne = xmlClubs.Find(c => c.Name.Equals(club.Name)).DistanceMoyenne;
            }
            DBconnection.UpdateAll(clubs);
        }
Пример #4
0
        /**
         * Gets a list of clubs using a filter
         * if the filter is null, then all clubs are returned
         * */
        public static async Task <List <Club> > getListClubsAsync(Func <Club, bool> filtre)
        {
            if (filtre == null)
            {
                filtre = x => true;
            }

            SQLite.SQLiteAsyncConnection connection = DependencyService.Get <ISQLiteDb>().GetConnectionAsync();
            List <Club> clubs = new List <Club>();
            await connection.CreateTableAsync <Club>();

            clubs = (await SQLiteNetExtensionsAsync.Extensions.ReadOperations.GetAllWithChildrenAsync <Club>(connection));

            if (clubs.Count == 0)//if no clubs in the datatbase
            {
                //parse the default clubs from the XML files and add them (Ressources/Clubs)
                clubs = GolfXMLReader.getListClubFromXMLFiles();
                await connection.InsertAllAsync(clubs);
            }
            return(clubs);
        }
Пример #5
0
        /**
         * Gets a list of golf courses using a filter
         * if the filter is null, then all golf courses are returned
         */
        public static async Task <List <GolfCourse> > getListGolfsAsync(Func <GolfCourse, bool> filtre)
        {
            if (filtre == null)
            {
                filtre = x => true;
            }

            SQLite.SQLiteAsyncConnection connection = DependencyService.Get <ISQLiteDb>().GetConnectionAsync();
            await connection.CreateTableAsync <Hole>();

            await connection.CreateTableAsync <MyPosition>();

            await connection.CreateTableAsync <GolfCourse>();

            List <GolfCourse> gfcs = (await SQLiteNetExtensionsAsync.Extensions.ReadOperations.GetAllWithChildrenAsync <GolfCourse>(connection, recursive: true));

            if (gfcs.Count == 0)//if no golf courses in the datatbase
            {
                //parse the default golf courses of Rennes from the XML files and add them (Ressources/GolfCourses)
                gfcs = GolfXMLReader.getListGolfCourseFromXMLFiles();
                await SQLiteNetExtensionsAsync.Extensions.WriteOperations.InsertOrReplaceAllWithChildrenAsync(connection, gfcs, true);
            }
            return(gfcs);
        }