Example #1
0
        // check if the username already exists
        public Boolean checkUsername()
        {
            CONNECT db = new CONNECT();

            String username = textBoxUsername.Text;

            DataTable table = new DataTable();

            MySqlDataAdapter adapter = new MySqlDataAdapter();

            MySqlCommand command = new MySqlCommand("SELECT * FROM `users` WHERE `username` = @usn", db.getConnection());

            command.Parameters.Add("@usn", MySqlDbType.VarChar).Value = username;

            adapter.SelectCommand = command;

            adapter.Fill(table);

            // check if this username already exists in the database
            if (table.Rows.Count > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #2
0
        private void buttonlogin_Click(object sender, EventArgs e)
        {
            CONNECT          conn    = new CONNECT();
            DataTable        table   = new DataTable();
            MySqlDataAdapter adapter = new MySqlDataAdapter();
            MySqlCommand     command = new MySqlCommand();
            String           query   = "SELECT * FROM `users`  WHERE `username`=@usn AND `password`=@pass";

            command.CommandText = query;
            command.Connection  = conn.getConnection();

            command.Parameters.Add("@usn", MySqlDbType.VarChar).Value  = textBoxUsername.Text;
            command.Parameters.Add("@pass", MySqlDbType.VarChar).Value = textBoxPassword.Text;

            adapter.SelectCommand = command;
            adapter.Fill(table);

            if (textBoxUsername.Text.Trim().Equals("admin".ToLower()) & textBoxPassword.Text.Trim().Equals("12123"))
            {
                // show the admain form
                this.Hide();
                AdminMainForm mform = new AdminMainForm(textBoxUsername.Text);
                mform.Show();
            }
            else if (table.Rows.Count > 0)
            {
                // show the main form
                this.Hide();
                MemberMainForm m1form = new MemberMainForm(textBoxUsername.Text);
                m1form.Show();
            }
            else
            {
                if (textBoxUsername.Text.Trim().Equals(""))
                {
                    MessageBox.Show("Enter Your Username to Login", "Empty Username", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (textBoxPassword.Text.Trim().Equals(""))
                {
                    MessageBox.Show("Enter Your Password to Login", "Empty Password", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show("This Username Or Password Doesn't Exists", "Wrong Data", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        public void comboadditem()
        {
            CONNECT          conn     = new CONNECT();
            MySqlCommand     command1 = new MySqlCommand("SELECT * FROM `count`", conn.getConnection());
            MySqlDataAdapter adapterr = new MySqlDataAdapter();
            MySqlDataReader  myReader;

            try
            {
                conn.openConnection();
                myReader = command1.ExecuteReader();
                while (myReader.Read())
                {
                    string sName = myReader.GetString("id");
                    comboBox1.Items.Add(sName);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        public void comboadditem()
        {
            String           username = textBoxUsername.Text;
            CONNECT          conn     = new CONNECT();
            MySqlCommand     command1 = new MySqlCommand("SELECT * FROM `count` WHERE `username` = @username", conn.getConnection());
            MySqlDataAdapter adapterr = new MySqlDataAdapter();
            MySqlDataReader  myReader;

            command1.Parameters.Add("@username", MySqlDbType.VarChar).Value = username;
            try
            {
                conn.openConnection();
                myReader = command1.ExecuteReader();
                while (myReader.Read())
                {
                    string sName = myReader.GetString("id");
                    comboBox1.Items.Add(sName);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #5
0
        private void buttonsignup_Click(object sender, EventArgs e)
        {
            CONNECT      conn    = new CONNECT();
            MySqlCommand command = new MySqlCommand("INSERT INTO `users`(`username`, `password`) VALUES (@usn, @pass)", conn.getConnection());

            command.Parameters.Add("@usn", MySqlDbType.VarChar).Value  = textBoxUsername.Text;
            command.Parameters.Add("@pass", MySqlDbType.VarChar).Value = textBoxPassword.Text;

            conn.openConnection();

            if (textBoxUsername.Text.Trim().Equals(""))
            {
                MessageBox.Show("Enter Your Username to Register", "Empty Username", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (textBoxPassword.Text.Trim().Equals(""))
            {
                MessageBox.Show("Enter Your Password to Register", "Empty Password", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (textBoxPasswordConfirm.Text.Trim().Equals(""))
            {
                MessageBox.Show("Enter Your Confirm Password to Register", "Empty Data", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (!checkTextBoxesValues())
            {
                // check if the password equal the confirm password
                if (textBoxPassword.Text.Equals(textBoxPasswordConfirm.Text))
                {
                    // check if this username already exists
                    if (checkUsername())
                    {
                        MessageBox.Show("This Username Already Exists, Select A Different One", "Duplicate Username", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
                    }
                    else
                    {
                        // execute the query
                        if (command.ExecuteNonQuery() == 1)
                        {
                            this.Close();
                            MessageBox.Show("Your Account Has Been Created", "Account Created", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            MessageBox.Show("ERROR");
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Wrong Confirmation Password", "Password Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Enter Your Informations First", "Empty Data", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
            }



            // close the connection
            conn.closeConnection();
        }