I have a animation bar that I want to show after a user has clicked a button. As the animation is going, I want another task to verify that the user information is correct (Login). When the task is finished I want the animation task to stop and display if the credentials were correct.
I've tried making different Tasks but it gets very complicated and complex and I start to lose my self in a complex code.
public async Task LoadingAnimationAsync()
//Animation
{
this.pictureBox1.Hide();
this.badPasswordLabel.Hide();
this.pictureBox2.Hide();
this.loadingLabel.Show();
this.loadingProgressBar.Show();
this.twitchPicture.Hide();
this.usernameTB.Hide();
this.passwordTB.Hide();
this.loginButton.Hide();
await Task.Delay(5000);
this.pictureBox1.Show();
this.pictureBox2.Show();
this.loadingLabel.Hide();
this.loadingProgressBar.Hide();
this.twitchPicture.Show();
this.usernameTB.Show();
this.passwordTB.Show();
this.loginButton.Show();
}
//Code
await LoadingAnimationAsync();
await Task.Run(() =>
{
bool TryLogin = Login.CheckForCredentials(usernameTB.Text, passwordTB.Text);
if (TryLogin == true)
{
MainPanel.Show();
MainPanel.BringToFront();
}
else
{
this.badPasswordLabel.Show();
}
});
//CredentialsCheck
public static bool CheckForCredentials(string Username, string Password)
{
string commandText = "SELECT * FROM Account WHERE Username = @USERNAME AND Password = @PASSWORD";
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand(commandText, connection);
command.Parameters.AddWithValue("@USERNAME", Username);
command.Parameters.AddWithValue("@PASSWORD", Password);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
try
{
if (reader.Read())
{
string CheckAcc = (String.Format("{0}, {1}",
reader["Username"], reader["Password"]));// etc
if (CheckAcc.Length > 0)
{
Console.WriteLine("Ima ga");
return true;
}
}
Console.WriteLine("Nema ga");
return false;
}
finally
{
// Always call Close when done reading.
reader.Close();
}
}
}