Exemple #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            UserHome userhome = new UserHome();

            userhome.Show();
            this.Hide();
        }
Exemple #2
0
        private void BackButton_Click(object sender, EventArgs e)
        {
            UserHome UH = new UserHome();

            UH.Show();
            this.Hide();
        }
Exemple #3
0
        private void ButtonLogin_Click(object sender, EventArgs e)
        {
            //mai's con
            //SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=IS Project;Integrated Security=True");

            //mohie's con
            SqlConnection con = new SqlConnection("Data Source=LELOUCH;Initial Catalog=\"IS Project\";Integrated Security=True");

            con.Open();
            if (AdminUsername == TextBoxUsername.Text && AdminPassword == TextBoxPassword.Text)
            {
                AdminHome admin_home = new AdminHome();
                admin_home.Show();
                this.Close();
            }

            else
            {
                bool          alreadyuser        = false;
                SqlCommand    show_username_pass = new SqlCommand("select username , password from users", con);
                SqlDataReader username_password  = show_username_pass.ExecuteReader();
                while (username_password.Read())
                {
                    if ((string)username_password["username"] == TextBoxUsername.Text && (string)username_password["password"] == TextBoxPassword.Text)
                    {
                        currentUsername = TextBoxUsername.Text;
                        UserHome user_home = new UserHome();
                        user_home.Show();
                        this.Close();
                        alreadyuser = true;
                    }
                    else if ((string)username_password["username"] == TextBoxUsername.Text && (string)username_password["password"] != TextBoxPassword.Text)
                    {
                        MessageBox.Show("The Username or Password is incorrect please retry.");
                        alreadyuser = true;
                    }
                }

                if (alreadyuser == false)
                {
                    MessageBox.Show("The Username or Password is incorrect please retry or Register.");
                }
                username_password.Close();
            }

            con.Close();
        }
        public void Insert()
        {
            string user          = textBoxUsername.Text;
            string EnterPassWord = textBoxPassword.Text;
            string ConPassWord   = textBoxConfirmPassword.Text;

            if (textBoxPhone.Text.Count() != 11)
            {
                MessageBox.Show("Phone number must be 11 digits.");
                return;
            }

            //mai con
            //SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=IS Project;Integrated Security=True");

            //mohie con
            SqlConnection con = new SqlConnection("Data Source = LELOUCH; Initial Catalog =\"IS Project\";Integrated Security=True");

            //connection_awad
            //SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=\"IS Project\";Integrated Security=True");

            if (string.IsNullOrEmpty(textBoxUsername.Text) || string.IsNullOrEmpty(textBoxPassword.Text) || string.IsNullOrEmpty(textBoxEmail.Text) || string.IsNullOrEmpty(textBoxPhone.Text) || comboBoxWayOfPayment.Text == "Select")
            {
                MessageBox.Show("Empty fields are not allowed.");
            }

            else
            {
                con.Open();

                string Insetstr = @"insert into Users (Username, Mail, Phone, WayofPayment, password)
                                    values (@UserName, @Email, @Phone, @WayOfPayment, @Password)";


                SqlCommand cmd = new SqlCommand(Insetstr, con);

                if (EnterPassWord != ConPassWord && EnterPassWord.Length != 0)
                {
                    MessageBox.Show("Please Re-Enter the Correct Password.", "Inavlid Input");
                    return;
                }

                SqlParameter UserName = new SqlParameter("@UserName", textBoxUsername.Text);
                cmd.Parameters.Add(UserName);

                SqlParameter PassWord = new SqlParameter("@Password", textBoxPassword.Text);
                cmd.Parameters.Add(PassWord);

                SqlParameter Email = new SqlParameter("@Email", textBoxEmail.Text);
                cmd.Parameters.Add(Email);

                SqlParameter Phone = new SqlParameter("@Phone", textBoxPhone.Text);
                cmd.Parameters.Add(Phone);

                SqlParameter WayOfPayment = new SqlParameter("@WayOfPayment", comboBoxWayOfPayment.Text);
                cmd.Parameters.Add(WayOfPayment);


                SqlCommand    comand = new SqlCommand("select Username from Users", con);
                SqlDataReader rdr    = comand.ExecuteReader();

                while (rdr.Read())
                {
                    if (user == rdr["Username"].ToString())
                    {
                        MessageBox.Show("This Username is Already taken.", "Change Username!");
                        rdr.Close();
                        con.Close();
                        return;
                    }
                }

                rdr.Close();
                cmd.ExecuteNonQuery();
                con.Close();
                Login.currentUsername = textBoxUsername.Text;
                MessageBox.Show("Welcome!", "New User");

                //the user should go to UserHome form
                UserHome h = new UserHome();
                h.Show();
                this.Hide();
            }
        }