I'm having difficulty fetching the contents of the Entry
Element and comparing it with the value being stored in the SQLite DB.
Here is the code for my class Usuarios
:
public class Usuarios
{
[PrimaryKey, AutoIncrement]
public long? usu_id { get; set; }
[MaxLength(20)]
public string usu_nome { get; set; }
[MaxLength(20)]
public string usu_senha { get; set; }
}
Code of ContentPage
TelaLogin.xaml
:
<StackLayout Margin="10">
<!--Aqui estamos inserindo o logotipo da empresa-->
<Frame HorizontalOptions="CenterAndExpand"
Padding="3" Margin="3">
<Image Source="logo.jpg" />
</Frame>
<Label Text="Login"
HorizontalTextAlignment="Center"
FontSize="Large" TextColor="Cyan" Style="bold"/>
<!--Aqui estamos buscando na tabela Usuarios, o Nome e a Senha-->
<Entry x:Name="txtUsuario"
Placeholder="Usuário"
PlaceholderColor="Cyan"
Text="{Binding Usuario}"
TextColor="Cyan"
Style="bold"/>
<Entry x:Name="txtSenha"
Placeholder="Senha"
PlaceholderColor="Cyan"
IsPassword="True"
Text="{Binding Senha}"
TextColor="Cyan"
Style="bold"/>
<Button Text="Login"
Clicked="btnTelaLogin" />
<Button Text="Tela Usuários"
Clicked="btnTelaUsuarios"
BackgroundColor="Orange" TextColor="White" />
</StackLayout>
DisplayLogin.xaml.cs:
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class TelaLogin : ContentPage
{
public TelaLogin ()
{
InitializeComponent ();
//remove a barra de navegação
NavigationPage.SetHasNavigationBar(this, false);
}
private async void btnTelaLogin(object sender, EventArgs e)
{
Usuarios login = new Usuarios();
if (login.usu_nome != null && login.usu_nome != null)
{
if(login.usu_nome == txtUsuario.Text && login.usu_senha == txtSenha.Text)
{
await Navigation.PushAsync(new TelaPrincipal());
}
else
{
await DisplayAlert("Erro", "Usuário ou Senha Estão Inválidos. Verifique !!!!", "OK");
}
}
else
{
await DisplayAlert("Erro", "Usuário ou Senha Estão Vazios. Verifique as Caixas de texto !!!!", "OK");
}
}
private async void btnTelaUsuarios(object sender, EventArgs e)
{
await Navigation.PushAsync(new TelaUsuarios());
}
}
I'm not able to test in the following line:
if(login.usu_nome == txtUsuario.Text && login.usu_senha == txtSenha.Text)
You are not recognizing txtusuario.Text
and txtSenha.Text
.
User registration is working.
Where can I be wrong?
Thank you for a response, if possible.