/* Connection string to database */ //String connectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Gestiune.mdf;Integrated Security=True;"; private void OnClickLogin(object sender, EventArgs e) { if (_txtUsername.Text == "" || _txtPassword.Text == "") { MessageBox.Show("Please provide a Username and Password!", "Warning"); return; } try { /* Create a new sql connection */ //SqlConnection sqlConnection = new SqlConnection(connectionString); //SqlCommand sqlCheckUserCommand = new SqlCommand("Select * from Credentials where Username = @username and Password = @password", sqlConnection); //sqlCheckUserCommand.Parameters.AddWithValue("@username", _txtUsername.Text); //sqlCheckUserCommand.Parameters.AddWithValue("@password", _txtPassword.Text); //sqlConnection.Open(); var db = new GestiuneEntities(); var loginAttempt = db.Credentials.FirstOrDefault(u => u.Username == _txtUsername.Text && u.Password == _txtPassword.Text); if (loginAttempt != null) { this.Hide(); AdminAccountingAppForm adminAccAppForm = new AdminAccountingAppForm(); adminAccAppForm.Show(); } else { MessageBox.Show("Login Failed!", "Failure"); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
private void OnClickLogin(object sender, EventArgs e) { bool loginAttempt; loginAttempt = Login.ValidateCredentials(txtUsername.Text, txtPassword.Text); if (loginAttempt == true) { this.Hide(); AdminAccountingAppForm adminAccAppForm = new AdminAccountingAppForm(); adminAccAppForm.Closed += (s, args) => this.Close(); adminAccAppForm.Show(); } }