예제 #1
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (txtUsername.Text != "Username")
            {
                if (txtPassword.Text != "Password")
                {
                    bool   login = false;
                    string username, password;
                    string inUsername, inPassword;
                    inUsername = txtUsername.Text;
                    inPassword = txtPassword.Text;

                    OleDbDataReader reader = Program.readData("SELECT  UserName, Password FROM tblStaff");

                    while (reader.Read())
                    {
                        username = reader[0].ToString();
                        password = reader[1].ToString();

                        if (username.Equals(inUsername) && password.Equals(inPassword))
                        {
                            login = true;
                            break;
                        }
                    }
                    reader.Close();
                    Program.con.Close();

                    if (login)
                    {
                        Main_Form f = new Main_Form();
                        f.Show();
                        this.Hide();
                    }
                    else
                    {
                        MessageBox.Show("Incorrect Username or Password!!!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        txtUsername.Clear();
                        txtPassword.Clear();
                        txtUsername_Leave(sender, e);
                        txtPassword_Leave(sender, e);
                        txtUsername.Focus();
                    }
                }
                else
                {
                    txtPassword.BackColor = Color.Red;
                    MessageBox.Show("Please input Password!!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    txtPassword.BackColor = Color.White;
                    txtPassword.SelectAll();
                    txtPassword.Focus();
                }
            }
            else
            {
                txtUsername.BackColor = Color.Red;
                MessageBox.Show("Please input Username!!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                txtUsername.BackColor = Color.White;
                txtUsername.SelectAll();
                txtUsername.Focus();
            }
        }
예제 #2
0
        private void Sell_FormClosing(object sender, FormClosingEventArgs e)
        {
            Main_Form f = new Main_Form();

            f.Show();
        }