Exemple #1
0
        private void bttnCancel_Click(object sender, EventArgs e)
        {
            switch (Login.getUserType())
            {
            case "admin":
                HomeAdmin homeAdmin = new HomeAdmin();
                homeAdmin.Show();
                this.Close();
                break;

            case "moderator":
                HomeModerator homeMod = new HomeModerator();
                homeMod.Show();
                this.Close();
                break;

            case "consumer":
                HomeConsumer homeConsumer = new HomeConsumer();
                homeConsumer.Show();
                this.Close();
                break;

            case "provider":
                HomeProvider homeProvider = new HomeProvider();
                homeProvider.Show();
                this.Close();
                break;
            }
        }
Exemple #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Assign text box fields
            string enteredUsername = txtUserName.Text;
            string enteredPassword = txtPassword.Text;

            //Connect to database
            try
            {
                con = new SqlConnection(@"Data Source=(local);Initial Catalog=ImageBaseDatabase;Integrated Security=True");
                con.Open();
                //Check username
                cmd            = new SqlCommand("SELECT * FROM tblUser WHERE userUsername='******' AND userPassword='******'");
                cmd.Connection = con;
                dr             = cmd.ExecuteReader();
                int    count = 0;
                string type  = "";
                while (dr.Read())
                {
                    count = count + 1;
                    type  = dr.GetString(5);
                    setUserType(type);
                }

                if (count == 1)
                {
                    if (type == "admin")
                    {
                        MessageBox.Show("Welcome - Logged in as Admin");
                        HomeAdmin Check = new HomeAdmin();
                        Check.Show();
                        Hide();
                    }
                    else if (type == "moderator")
                    {
                        MessageBox.Show("Welcome - Logged in as Moderator");
                        ModerateImages Check = new ModerateImages();
                        Check.Show();
                        Hide();
                    }
                    else if (type == "consumer")
                    {
                        MessageBox.Show("Welcome - Logged in as Consumer");
                        HomeConsumer Check = new HomeConsumer();
                        Check.Show();
                        Hide();
                    }
                    else if (type == "provider")
                    {
                        MessageBox.Show("Welcome - Logged in as Provider");
                        HomeProvider Check = new HomeProvider();
                        Check.Show();
                        Hide();
                    }
                    else
                    {
                        MessageBox.Show("Invalid User Type.. Please speak to an admin");
                    }
                    setUser(enteredUsername);
                }
                else if (count > 1)
                {
                    MessageBox.Show("Duplicate Username and/or password.. Access Denied");
                }
                else
                {
                    MessageBox.Show("Username or password is incorrect.. Please try again");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                MessageBox.Show("Could not connect to database");
            }
        }