Esempio n. 1
0
        private void button_cancel_Click(object sender, EventArgs e)
        {
            string type = Form1.usertype;

            if (type == "admin")
            {
                //Admin Dashboard
                adminPanel admin = new adminPanel();
                admin.Show();
                this.Hide();
            }
            else
            {
                //User Dashboard
                userPanel home = new userPanel();
                home.Show();
                this.Close();
            }
        }
        private void btn_login_Click(object sender, EventArgs e)
        {
            //Username
            string user = textBox_user.Text;
            //Password
            string pass = textBox_pwd.Text;
            //Usertype
            string uType = comboBox_utype.Text.Trim();

            //Database connection
            MySqlConnection conn = new MySqlConnection("server=localhost;user id=root;database=bugtrack");

            try
            {
                MySqlDataAdapter adapter = new MySqlDataAdapter("Select count(*) from userdetails where username='******'and password='******' and usertype='" + comboBox_utype.Text + "'", conn);
                DataTable        dt      = new DataTable();
                adapter.Fill(dt);//

                if (user.Equals(null) || pass.Equals(null) || uType.Equals(null))
                {
                    MessageBox.Show("U must Fill all the forms", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    if (dt.Rows[0][0].ToString() == "1")
                    {
                        // loggedIn = user;
                        // loggedIN_utype = uType;
                        userpasswor = pass;
                        uname       = user;

                        usertype = uType;
                        switch (uType)
                        {
                        case "admin":
                        {
                            // Admin Panel
                            //  loggedIN_utype = uType;
                            adminPanel admin = new adminPanel();
                            MessageBox.Show("Login was succesful.");
                            admin.Show();
                            this.Hide();

                            break;
                        }

                        //user
                        case "user":
                        {
                            // User Dashboard is displayed
                            userPanel umenu = new userPanel();
                            MessageBox.Show("Login was succesful.");
                            umenu.Show();
                            this.Hide();
                            break;
                        }

                        case "programmer":
                        {
                            //Programmer Dashboard is displayed
                            ProgrammerPanel pmenu = new ProgrammerPanel();
                            MessageBox.Show("Login was succesful.");
                            pmenu.Show();
                            this.Hide();
                            break;
                        }
                        }
                    }
                    else
                    {
                        MessageBox.Show("Username or password is incorrect", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
            finally
            {
                //Step :CLose Connection
                conn.Close();
            }
        }