Exemple #1
0
        private void login_BT_Click(object sender, EventArgs e)
        {
            MY_DB          db  = new MY_DB();
            Check_in_out   ck  = new Check_in_out();
            SqlDataAdapter da  = new SqlDataAdapter();
            DataTable      dt  = new DataTable();
            SqlCommand     com = new SqlCommand("SELECT * FROM Accounts, Employees, EmployeeAccounts WHERE username=@user AND password=@pass AND Accounts.acc_id = EmployeeAccounts.acc_id AND Employees.emp_id = EmployeeAccounts.emp_id", db.getConnection);

            if (radioManager.Checked)
            {
                com.CommandText += " AND (title='Manager' OR title = 'Admin')";
            }
            else if (radioEmp.Checked)
            {
                com.CommandText += " AND (title='Receptionist' OR title='Janitor')";
            }
            com.Parameters.Add("@user", SqlDbType.VarChar).Value = username_TB.Text;
            com.Parameters.Add("@pass", SqlDbType.VarChar).Value = password_TB.Text;

            da.SelectCommand = com;
            da.Fill(dt);

            if (dt.Rows.Count > 0)
            {
                MessageBox.Show("Login Successful");
                this.DialogResult = DialogResult.OK;
            }
            else
            {
                MessageBox.Show("Invalid Username Or Password", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }