Esempio n. 1
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                useDbSql = new UseDatabase.UseDatabase();
                useDbSql.ConnectToDB();

                sUsername = txtUsername.Text;
                sPassword = txtPassword.Text;

                queryString = "SELECT * FROM WORKER WHERE username='******' AND iPassword='******'";
                SqlDataReader reader = useDbSql.ExecuteQuery(queryString);

                //Check if row was found
                if (reader != null && reader.HasRows)
                {
                    reader.Close();

                    queryString = "SELECT * FROM WORKER WHERE username='******' AND iPassword='******' AND position='Supervisor'";
                    reader      = useDbSql.ExecuteQuery(queryString);
                    if (reader.HasRows)
                    {
                        reader.Close();
                        queryString = "UPDATE WORKER SET loggedIn = 'true' WHERE username='******' AND iPassword='******'";
                        bool result = useDbSql.ExecuteCommand(queryString);

                        this.Hide();
                        Admin_HomeForm openAdminHome = new Admin_HomeForm();
                        openAdminHome.ShowDialog();
                    }
                    else
                    {
                        reader.Close();
                        queryString = "UPDATE WORKER SET loggedIn = 'true' WHERE username='******' AND iPassword='******'";
                        bool result = useDbSql.ExecuteCommand(queryString);

                        this.Hide();
                        HomeForm homeFrm = new HomeForm();
                        homeFrm.ShowDialog();
                    }
                }
                else
                {
                    lblResults.Text = "Username or Password is wrong!";
                }
            }
            catch (SqlException se)
            {
                MessageBox.Show("An error has occurred... " + se.Message);
            }
            finally
            {
                useDbSql.DisconnectToDB();
            }
        }