private void btnLogin_Click(object sender, EventArgs e) { conn = new SqlConnection("Data Source = (LocalDB)\\MSSQLLocalDB; " + "AttachDbFilename = |DataDirectory|\\TestDB.mdf; Integrated Security = True;" + " Connect Timeout = 30"); string strSQL = "SELECT * FROM Users WHERE Username = '******'" + " AND Password = '******'"; conn.Open(); //create command object cmd = new SqlCommand(strSQL, conn); //execite the sql command and store the result in the reader dr = cmd.ExecuteReader(); if (dr.HasRows) { dr.Read(); if (dr["Role"].Equals("Admin")) { Dashboard dsh = new Dashboard(); dsh.Show(); this.Hide(); } else if (dr["Role"].Equals("Secretary")) { WeeklyReport wr = new WeeklyReport(); wr.Show(); this.Hide(); } else if (dr["Role"].Equals("Student")) { Search sr = new Search(); sr.Show(); this.Hide(); } } else { MessageBox.Show("Wrong username or password.", "Log in failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } dr.Close(); conn.Close(); }
private void btnLogin_Click(object sender, EventArgs e) { Controller ctrl = new Controller(); string role = ctrl.SignIn(txtUsername.Text, txtPw.Text); if (role == "Admin") { Dashboard dsh = new Dashboard(); dsh.Show(); this.Hide(); } else if (role == "Secretary") { WeeklyReport wr = new WeeklyReport(); wr.Show(); this.Hide(); } else if (role == "Student") { Search sr = new Search(); sr.Show(); this.Hide(); } }