Skip to content
Permalink
Browse files
Log in page
  • Loading branch information
efstathioa committed Nov 18, 2020
1 parent e95d259 commit e370d35704b8ecc63e19b41d9bda0db63c4e6c8b
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 1 deletion.
@@ -18,6 +18,12 @@
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Views\LogInPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Views\MainPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Views\RegisterPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Coursework1.Views.LogInPage">
<ContentPage.Content>
<ScrollView>
<StackLayout>
<Grid VerticalOptions="CenterAndExpand">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>

<Entry Placeholder="Username" x:Name="EntryUsername" Grid.Row="0"/>
<Entry Placeholder="Passwrod" x:Name="EntryPassword" Grid.Row="1"/>
<Button Text="Log In" Grid.Row="2" BackgroundColor="Blue" TextColor="White" Clicked="Button_Clicked_1"/>
<Button Text="SignUp" Grid.Row="3" BackgroundColor="Blue" TextColor="White" Clicked="Button_Clicked"/>

</Grid>
</StackLayout>
</ScrollView>
</ContentPage.Content>
</ContentPage>
@@ -0,0 +1,52 @@
using Coursework1.Tables;
using SQLite;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace Coursework1.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class LogInPage : ContentPage
{
public LogInPage()
{
InitializeComponent();
}

async void Button_Clicked(object sender, EventArgs e)
{
await Navigation.PushModalAsync(new RegisterPage());
}

void Button_Clicked_1(object sender, EventArgs e)
{
var dbpath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "UserDatabase.db");
var db = new SQLiteConnection(dbpath);
var myquery = db.Table<RegisteredUsers>().Where(u => u.Username.Equals(EntryUsername.Text) && u.Password.Equals(EntryPassword.Text)).FirstOrDefault();

if (myquery != null)
{
App.Current.MainPage = new NavigationPage(new MainPage());
}

else
{
Device.BeginInvokeOnMainThread(async () =>
{
var result = await this.DisplayAlert("Log In Failed", "Check both Username and Password", "Okay", "Cancel");
if (result)
await Navigation.PushModalAsync(new LogInPage());

});
}

}
}
}
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Coursework1.Views.MainPage">
<ContentPage.Content>
<StackLayout>
<Label Text="Welcome to Xamarin.Forms!"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand" />
</StackLayout>
</ContentPage.Content>
</ContentPage>
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace Coursework1.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
}
}
@@ -7,6 +7,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;


using Xamarin.Forms;
using Xamarin.Forms.Xaml;

@@ -35,7 +36,12 @@ namespace Coursework1.Views
};

db.Insert(item);

Device.BeginInvokeOnMainThread(async () =>
{
var result = await this.DisplayAlert("Registration Succesful", "Press okay to go to log in page", "Okay", "Cancel");
if (result)
await Navigation.PushModalAsync(new LogInPage());
});


}

0 comments on commit e370d35

Please sign in to comment.