Example #1
0
        private void signup_Click(object sender, EventArgs e)
        {
            SqlDb        db      = new SqlDb();
            MySqlCommand command = new MySqlCommand("INSERT INTO `users`(`Username`,`Name`,`Password`,`Admin Id`) VALUES (@usn,@nam,@pass,@Adi)", db.getConnection());

            command.Parameters.Add("@usn", MySqlDbType.VarChar).Value  = Username.Text;
            command.Parameters.Add("@nam", MySqlDbType.VarChar).Value  = NameU.Text;
            command.Parameters.Add("@pass", MySqlDbType.VarChar).Value = Password.Text;
            command.Parameters.Add("@Adi", MySqlDbType.VarChar).Value  = AdiD.Text;

            db.openConnection();
            if (!checkTextBoxesValues())
            {
                if (Password.Text.Equals(PasswordConf.Text))
                {
                    if (checkUsername())
                    {
                        MessageBox.Show("This Username Already Exists, Select A Different One", "Duplicate Username", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
                    }
                    else

                    {
                        if (command.ExecuteNonQuery() == 1)
                        {
                            MessageBox.Show("Your Account Has Been Created", "Account Created", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            this.Hide();
                            Form1 log = new Form1();
                            log.Show();
                        }
                        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);
            }



            db.closeConnection();
        }
Example #2
0
        public Boolean checkUsername()
        {
            SqlDb db = new SqlDb();

            String username = Username.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);


            if (table.Rows.Count > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            SqlDb db = new SqlDb();

            String Usname   = textBoxUsername.Text;
            String Password = textBoxPassword.Text;
            String Admin    = textBoxAdminID.Text;

            DataTable        table   = new DataTable();
            MySqlDataAdapter adapter = new MySqlDataAdapter();
            MySqlCommand     command = new MySqlCommand("SELECT * FROM `users` WHERE `Username`= @usn AND `Password` = @pass AND`Admin Id`= @Adi", db.getConnection());

            command.Parameters.Add("@usn", MySqlDbType.VarChar).Value  = Usname;
            command.Parameters.Add("@pass", MySqlDbType.VarChar).Value = Password;
            command.Parameters.Add("@Adi", MySqlDbType.VarChar).Value  = Admin;


            adapter.SelectCommand = command;

            adapter.Fill(table);
            bool lib = radioButton1.Checked;
            bool stu = radioButton2.Checked;


            if (table.Rows.Count > 0)
            {
                this.Hide();
                HomePage regis = new HomePage();
                regis.Show();
            }
            else
            {
                if (lib)
                {
                    if (Usname.Trim().Equals(""))
                    {
                        MessageBox.Show("Enter Your Username To Login", "Empty Username", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else if (Password.Trim().Equals(""))
                    {
                        MessageBox.Show("Enter Your Password To Login", "Empty Password", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else if (Admin.Trim().Equals(""))
                    {
                        MessageBox.Show("Enter Your Admin Id To Login", "Empty Password", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        MessageBox.Show("Wrong Username Or Password or Wrong Admin Id", "Wrong Data", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else if (stu)
                {
                    MessageBox.Show("Wrong Username Or Password", "Wrong Data", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }