0
I’m having a hard time finding the content of the Element Entry
and compare to the value being stored in the BD Sqlite.
Follow the code of 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>
Code of Telalogin.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 getting the test on the following line:
if(login.usu_nome == txtUsuario.Text && login.usu_senha == txtSenha.Text)
You don’t recognize the txtusuario.Text
and the txtSenha.Text
.
User registration is working.
Where can I be missing?
Grateful for an answer, if possible.
How did you state these names right on
Xaml
, should recognize. Could be some cache problem. Try to delete foldersbin
andobj
of your project, make a clean and a rebuild. Warns if the problem persists– Diego Rafael Souza
Thank you Epal help Diego. That was it, I did the cleaning and the objects were recognized. Now I am not able to compare what is typed in the text box txtusuario and txtSelf, cm the value that is saved in the database, usu_name and usu_password, where I can be missing?
– Montesuma
I will post as an answer to finalize this thread. From there Oce opens a new question for us to address specifically this comparison there that mentioned. It was not very clear to me
– Diego Rafael Souza