private void btnOkRegister_Click(object sender, EventArgs e) { if (txtUsernameRegister.Text == "" || txtPasswordRegister.Text == "") { MessageBox.Show("Username and password must be filled out."); return; } tblLogin l = new tblLogin(); foreach (var p in dbe.tblLogin) { if (p.Username == txtUsernameRegister.Text) { MessageBox.Show("Username already exists, please pick another one."); return; } else { l.Username = txtUsernameRegister.Text; l.Password = txtPasswordRegister.Text; l.Name = txtNameRegister.Text; l.Surname = txtSurnameRegister.Text; l.Email = txtEmailRegister.Text; dbe.tblLogin.Add(l); dbe.SaveChanges(); this.Close(); this.DialogResult = DialogResult.OK; MessageBox.Show("Successfully registered."); break; } } }
private void btnLogin_Click(object sender, EventArgs e) { if (txtUsernameLogin.Text == "" || txtPasswordLogin.Text == "") { MessageBox.Show("Please enter username and password."); return; } tblLogin l = new tblLogin(); foreach (var p in dbe.tblLogin) { if (p.Username == txtUsernameLogin.Text && p.Password == txtPasswordLogin.Text) { MessageBox.Show("Successfully Logged In."); ContentForm c = new ContentForm(); var query = from g in dbe.tblLogin select g; var queryList = query.ToList(); c.dataGridView1.DataSource = queryList; c.Show(); return; } } foreach (var p in dbe.tblLogin) { if (p.Username != txtUsernameLogin.Text || p.Password != txtPasswordLogin.Text) { MessageBox.Show("Wrong Username and/or Password."); return; } } }