private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(str);
            SqlCommand    cmd = new SqlCommand("select * from Login where Username='******' and Password= '******'", con);

            cmd.CommandType = CommandType.Text;
            SqlDataAdapter sda = new SqlDataAdapter(cmd);
            DataTable      tbl = new DataTable();

            sda.Fill(tbl);

            string usertypeValue = comboBox1.SelectedItem.ToString();

            if (tbl.Rows.Count > 0)
            {
                for (int i = 0; i < tbl.Rows.Count; i++)
                {
                    if (tbl.Rows[i][2].ToString() == usertypeValue)
                    {
                        MessageBox.Show("Successfully Logged In As " + tbl.Rows[i][2]);

                        if (comboBox1.SelectedIndex == 0)
                        {
                            this.Hide();
                            Client c = new Client(textBox1.Text);
                            c.Show();
                        }

                        else if (comboBox1.SelectedIndex == 1)
                        {
                            this.Hide();
                            Guard g = new Guard(textBox1.Text);
                            g.Show();
                        }

                        else
                        {
                            this.Hide();
                            Admin a = new Admin();
                            a.Show();
                        }
                    }
                }
            }

            else
            {
                MessageBox.Show("Check Username or Password or User Type");
            }
        }
Exemplo n.º 2
0
        private void metroButton4_Click(object sender, EventArgs e)
        {
            string username = lusernamebox.Text;
            string password = lpassbox.Text;
            string type     = loginasCombobox.Text;

            // -------------------------  Login --------------------------//
            if (username == "" || password == "" || type == "")
            {
                MessageBox.Show(this, "Fill up every blank.", "Message", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
            }
            else if (type == "Admin")
            {
                int t = bo.admin_login(username, password);
                if (t == 0)
                {
                    MessageBox.Show(this, "Wrong Combination", "Message", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
                }
                else if (t == 1)
                {
                    bo.mainname = username;
                    Admin admin = new Admin(bo);
                    admin.Show();
                    this.Hide();
                }
                else
                {
                    MessageBox.Show(this, "Wrong Combination", "Message", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
                }
            }
            else if (type == "Accountant")
            {
                int t = bo.accountant_login(username, password);
                if (t == 0)
                {
                    MessageBox.Show(this, "Wrong Combination", "Message", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
                }
                else if (t == 1)
                {
                    bo.mainname = username;
                    Accountant_Main_Page acc = new Accountant_Main_Page(bo);
                    acc.Show();
                    this.Hide();
                }
                else
                {
                    MessageBox.Show(this, "Wrong Combination", "Message", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
                }
            }
            else if (type == "Client")
            {
                int t = bo.client_login(username, password);
                if (t == 0)
                {
                    MessageBox.Show(this, "Wrong Combination", "Message", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
                }
                else if (t == 1)
                {
                    bo.mainname = username;
                    Client client = new Client(bo);
                    client.Show();
                    this.Hide();
                }
                else
                {
                    MessageBox.Show(this, "Wrong Combination", "Message", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
                }
            }
        }