private void btnLogin_Click(object sender, EventArgs e)
        {
            bool   found = false;
            string _username = "", _role = "", _name = "";

            cn.Open();
            cm = new SqlCommand("select * from tblUser where username = @username and password = @password", cn);
            cm.Parameters.AddWithValue("@username", txtUsername.Text);
            cm.Parameters.AddWithValue("@password", txtPass.Text);
            dr = cm.ExecuteReader();
            dr.Read();
            if (dr.HasRows)
            {
                found     = true;
                _username = dr["username"].ToString();
                _role     = dr["role"].ToString();
                _name     = dr["name"].ToString();
            }
            else
            {
                found = false;
            }

            if (found == true)
            {
                if (_role == "Cashier")
                {
                    MessageBox.Show("Welcome " + _name + "!", "Access Granted", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtPass.Clear();
                    txtUsername.Clear();
                    this.Hide();
                    POS frm = new POS();
                    frm.lblName.Text = _name + " | " + _role;
                    frm.ShowDialog();
                }
                else
                {
                    MessageBox.Show("Welcome " + _name + "!", "Access Granted", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtPass.Clear();
                    txtUsername.Clear();
                    this.Hide();
                    Form1 frm = new Form1();
                    frm.lblName.Text = _name;
                    frm.lblRole.Text = _role;
                    frm.ShowDialog();
                }
            }
            else
            {
                MessageBox.Show("Invalid username or password", "Access Denied", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            dr.Close();
            cn.Close();
        }
Exemple #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            POS frm = new POS();

            frm.ShowDialog();
        }