-
-
Save Rafcik177/f16fd3ec914d447ec1e55e1f53347681 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//plik ze strukturą bazy | |
using SQLite; | |
namespace Fiszki | |
{ | |
public class Fiszkibaza | |
{ | |
[PrimaryKey, AutoIncrement] | |
public int Id { get; set; } | |
[Unique] | |
public string WyrazPL { get; set; } | |
public string WyrazEN { get; set; } | |
public string Obrazek { get; set; } | |
public int Wyswietlono { get; set; } | |
} | |
} | |
//plik z odczytywaniem z bazy | |
using System.Collections.Generic; | |
using System.Threading.Tasks; | |
using SQLite; | |
namespace Fiszki | |
{ | |
public class Database | |
{ | |
private readonly SQLiteAsyncConnection _database; | |
public Database(string dbPath) | |
{ | |
_database = new SQLiteAsyncConnection(dbPath); | |
_database.CreateTableAsync<Fiszkibaza>(); | |
} | |
public Task<List<Fiszkibaza>> PolskieSlowo(int numer) | |
{ | |
return _database.QueryAsync<Fiszkibaza>("select Id, WyrazPL, Wyswietlono from Fiszkibaza Where Id = ?", numer ); | |
} | |
public Task<List<Fiszkibaza>> AngielskieSlowo(int numer) | |
{ | |
return _database.QueryAsync<Fiszkibaza>("select * from Fiszkibaza Where Id = ?", numer); | |
} | |
public Task<List<Fiszkibaza>> UpdateWyswietlono(int numer) | |
{ | |
return _database.QueryAsync<Fiszkibaza>("Update Fiszkibaza SET Wyswietlono = 1 Where Id = ?", numer); | |
` } | |
public Task<int> SavePersonAsync(Fiszkibaza rekord) | |
{ | |
return _database.InsertOrReplaceAsync(rekord); | |
} | |
} | |
} | |
//plik strona.xaml.cs | |
public async void Odkryj(object sender, EventArgs e) | |
{ | |
if(klikanie == 0) | |
{ | |
collectionView.ItemsSource = await App.Database.PolskieSlowo(numer); | |
(sender as Button).Text = "Odkryj! [id="+ numer+"]"; | |
klikanie = 1; | |
} | |
else if(klikanie==1) | |
{ | |
collectionView.ItemsSource = await App.Database.AngielskieSlowo(numer); | |
(sender as Button).Text = "Następny! [id=" + numer+ "]"; | |
await App.Database.UpdateWyswietlono(numer); | |
klikanie = 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment