Nazwa forum

Niestety, nikt nie powie Ci czym jest FluxBB - musisz go poznać sam!

Nie jesteś zalogowany na forum.

#1 2018-06-04 23:07:55

xaml
Administrator
Dołączył: 2018-06-04
Liczba postów: 7
WindowsChrome 66.0.3359.181

Baza danych

IFileHelper.cs

using System;
using System.Collections.Generic;
using System.Text;

namespace Przyklad4
{
    public interface IFileHelper
    {
        string GetLocalFilePath(string filename);
    }
}

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:Przyklad4"
             x:Class="Przyklad4.MainPage">
    <ContentPage.Content>
        <StackLayout>
            <Entry x:Name="entryNazwa"/>
            <Entry x:Name="entryOpis"/>
            <StackLayout Orientation="Horizontal"
                         HorizontalOptions="Center">
                <Button x:Name="buttonZapisz"
                        Text="Save"
                        Clicked="clickedSave"/>
                <Button x:Name="buttonOdczytaj"
                        Text="Load"
                        Clicked="clickedLoad"/>
            </StackLayout>
            <Entry x:Name="output"/>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using SQLite;


namespace Przyklad4
{
    public partial class MainPage : ContentPage
    {
        readonly SQLiteConnection database;
        private string databasePath;

        public MainPage()
        {
            InitializeComponent();

            databasePath = DependencyService.Get<IFileHelper>().GetLocalFilePath("BazaSQLite.db3");

            database = new SQLiteConnection(databasePath);

            database.CreateTable<Tabela>();
        }

        private void clickedSave (object sender, EventArgs e)
        {
            Tabela t = new Tabela();
            t.Nazwa = entryNazwa.Text;
            t.Opis = entryOpis.Text;
            t.Zrobione = false;

            var s = database.Insert(t);
        }


        private void clickedLoad(object sender, EventArgs e)
        {
            string wynik="";

            var query = database.Table<Tabela>().Where(v => v.Nazwa.StartsWith("A"));

            foreach (var wiersz in query)
            {
                wynik = wiersz.Nazwa + " " + wiersz.Opis;
            }

            output.Text = wynik;
        }

    }
}

Offline

Użytkowników czytających ten temat: 0, gości: 1
[Bot] claudebot

Stopka