private void btnSignUp_Click(object sender, EventArgs e) { using (TestdbEntities context = new TestdbEntities()) { Akun akun = new Akun(); akun.Username = tbUsername.Text; akun.Password = tbPassword.Text; akun.Name = tbName.Text; try { akun.Age = Int16.Parse(tbAge.Text); } catch (FormatException) { MessageBox.Show("Masukkan angka pada kolom Age"); } context.Akuns.Add(akun); context.SaveChanges(); LoginForm loginForm = new LoginForm(); if (akun.Username != null && akun.Password != null && akun.Name != null && akun.Age != null) { loginForm.Show(); this.Hide(); } } }
private void btnLogin_Click(object sender, EventArgs e) { using (TestdbEntities context = new TestdbEntities()) { /*foreach (var akun in context.Akuns) * { * if (akun.Username == tbUsername.Text && akun.Password == tbPassword.Text) * { * Dashboard dashboard = new Dashboard(); * dashboard.Show(); * this.Hide(); * } * else * { * MessageBox.Show("Username/Password Salah"); * } * }*/ Akun akun = context.Akuns.FirstOrDefault(a => a.Username == tbUsername.Text); if (akun == null) { MessageBox.Show("Username tidak ada"); } else { if (akun.Password == tbPassword.Text) { Dashboard dashboard = new Dashboard(); dashboard.Show(); this.Hide(); } else { MessageBox.Show("Password Salah"); } } /*bool adaData = false; * foreach (var akunCheck in context.Akuns) * { * akunCheck.Username = tbUsername.Text; * if (akunCheck.Username != null) * { * adaData = true; * } * } * if (adaData) * { * if (akun.Password == tbPassword.Text) * { * Dashboard dashboard = new Dashboard(); * dashboard.Show(); * this.Hide(); * } * else * { * MessageBox.Show("Username / Password Salah oi"); * } * }*/ } }