Skip to content

Instantly share code, notes, and snippets.

@Rafcik177
Created November 25, 2021 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rafcik177/f16fd3ec914d447ec1e55e1f53347681 to your computer and use it in GitHub Desktop.
Save Rafcik177/f16fd3ec914d447ec1e55e1f53347681 to your computer and use it in GitHub Desktop.
//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