コード例 #1
0
        private void button4_Click(object sender, EventArgs e)
        {
            this.Hide();
            SystemAdminPage ss = new SystemAdminPage();

            ss.Show();
        }
コード例 #2
0
        private void btnlogin_Click(object sender, EventArgs e)
        {
            string usertype;
            string username;
            string userpassword;

            usertype     = comtype.SelectedItem.ToString();
            username     = txtname.Text;
            userpassword = txtpw.Text;
            MySqlConnection sqlCon = null;
            string          connection;

            connection = "server =127.0.0.1;database =payrollmanagments; user =root;Sslmode= none";

            sqlCon = new MySqlConnection(connection);
            sqlCon.Open();

            MySqlCommand    command;
            MySqlDataReader reader;

            if (usertype == "System Administrator")
            {
                command = new MySqlCommand(@"SELECT* FROM systemadmin WHERE SystemAdminName='" + username + "'", sqlCon);
                reader  = command.ExecuteReader();
                reader.Read();

                if (reader.HasRows)
                {
                    string databaseUserName;
                    string databasePassword;
                    databaseUserName = reader.GetString(0);
                    databasePassword = reader.GetString(2);

                    if (userpassword == databasePassword)
                    {
                        this.Hide();
                        SystemAdminPage ss = new SystemAdminPage();
                        ss.Show();
                    }
                    else
                    {
                        MessageBox.Show("Invalied Password");
                    }
                }
                else
                {
                    MessageBox.Show("Invalied User name!");
                }
            }
            else if (usertype == "HR")
            {
                command = new MySqlCommand(@"SELECT* FROM hr WHERE Name='" + username + "'", sqlCon);
                reader  = command.ExecuteReader();
                reader.Read();

                if (reader.HasRows)
                {
                    string databaseUserName;
                    string databasePassword;
                    databaseUserName = reader.GetString(1);
                    databasePassword = reader.GetString(2);

                    if (userpassword == databasePassword)
                    {
                        this.Hide();
                        HR ss = new HR();
                        ss.Show();
                    }
                    else
                    {
                        MessageBox.Show("Invalied Password");
                    }
                }
                else
                {
                    MessageBox.Show("Invalied User name!");
                }
            }
            else if (usertype == "Employee")
            {
                command = new MySqlCommand(@"SELECT* FROM employee WHERE EmployeeName='" + username + "'", sqlCon);
                reader  = command.ExecuteReader();
                reader.Read();

                if (reader.HasRows)
                {
                    string databaseUserName;
                    string databasePassword;
                    databaseUserName = reader.GetString(1);
                    databasePassword = reader.GetString(2);

                    if (userpassword == databasePassword)
                    {
                        this.Hide();
                        Employee ss = new Employee();
                        ss.Show();
                    }
                    else
                    {
                        MessageBox.Show("Invalied Password");
                    }
                }
                else
                {
                    MessageBox.Show("Invalied User name!");
                }
            }
        }