private void btnBack_OnClick(object sender, EventArgs e)
 {
     if (navFromTag)
     {
         TaggedInForm taggedInForm = new TaggedInForm(dbConnection, securityStatus, memberId);
     }
     else
     {
         MemberForm secretaryForm = new MemberForm(dbConnection, securityStatus, memberId);
         secretaryForm.Show();
     }
     otherWindowOpen = true;
     this.Close();
 }
Example #2
0
        private void btnSignIn_Click(object sender, EventArgs e)
        {
            if (txtUsername.TextLength > 0)
            {
                if (txtPassword.TextLength > 0)
                {
                    if (dbConnection.OpenConnection())
                    {
                        int    memberId       = 0;
                        String username       = "";
                        String password       = "";
                        int    securityStatus = 0;

                        MySqlCommand command = new MySqlCommand();

                        command.Connection  = dbConnection.getConnection();
                        command.CommandText = "SELECT member_id, username, password, security_status FROM user_login WHERE username=@username";

                        command.Parameters.AddWithValue("@username", this.txtUsername.Text);

                        using (MySqlDataReader dr = command.ExecuteReader())
                        {
                            while (dr.Read())
                            {
                                memberId       = Int32.Parse(dr[0].ToString());
                                username       = dr[1].ToString();
                                password       = dr[2].ToString();
                                securityStatus = Int32.Parse(dr[3].ToString());
                            }
                        }

                        dbConnection.CloseConnection();
                        command.Dispose();

                        if (username.Equals(txtUsername.Text) && password.Equals(txtPassword.Text))
                        {
                            switch (securityStatus)
                            {
                            case 1:     // System administrator
                                SystemAdminForm systemAdminForm = new SystemAdminForm(dbConnection);
                                systemAdminForm.Show();
                                signIn = true;
                                this.Close();
                                break;

                            case 2:     // Secretary
                            case 3:     // member
                            case 4:     // chair
                                MemberForm memberForm = new MemberForm(dbConnection, securityStatus, memberId);
                                memberForm.Show();
                                signIn = true;
                                this.Close();
                                break;
                            }
                        }
                        else
                        {
                            MessageBox.Show(this, "Invalid username or password.", "Sign In", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
                else
                {
                    MessageBox.Show(this, "Please enter a valid password.", "Invalid Password", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show(this, "Please enter a valid username.", "Invalid Username", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }