public void validate_user(string new_name, string old_name, string type)
        {
            bool        valid = true;
            sql_queries query = new sql_queries("Data Source=(local);Initial Catalog=Auction_mangement_system;Integrated Security=True");

            for (int i = 0; i < new_name.Length; i++)
            {
                if (!char.IsDigit(new_name[i]) && !char.IsLetter(new_name[i]))
                {
                    valid = false;
                }
            }
            if (!valid)
            {
                MessageBox.Show("The username must contain only letters and digits !");
            }
            else if (new_name.Length == 0)
            {
                MessageBox.Show("Please enter the " + type);
            }
            else if (new_name.Length > 10 || new_name.Length < 5)
            {
                MessageBox.Show("The " + type + " must be between 5 and 10 characters");
            }
            else if (type == "username" && query.check_username(new_name))
            {
                MessageBox.Show("This username is already taken !");
            }
            else
            {
                query.update_user(new_name, old_name, type);
                if (type == "username")
                {
                    User.username = new_name;
                }
                else if (type == "profile_name")
                {
                    User.profilename = new_name;
                }
                else
                {
                    User.password = new_name;
                }
                MessageBox.Show("The " + type + " is updated successfully");
            }
        }
Esempio n. 2
0
 private void RemoveButton(object sender, RoutedEventArgs e)
 {
     if (UserName.Text == "")
     {
         MessageBox.Show("Please Enter UserName");
     }
     else // two cases if it not found , else remove it from database
     {
         sql_queries sql   = new sql_queries("Data Source=(local);Initial Catalog=Auction_mangement_system;Integrated Security=True");
         bool        found = sql.check_username(UserName.Text);
         if (found) // e3mel delete query ll username
         {
             sql.Delete_user(UserName.Text);
             MessageBox.Show("User Removed Successfully");
         }
         else
         {
             MessageBox.Show("This UserName isn't Exist");
         }
     }
 }
        public void validate_signup(string username, string password, string repassword, string profilenme)
        {
            bool        valid = true; string notvalid = "";
            sql_queries query = new sql_queries("Data Source=(local);Initial Catalog=Auction_mangement_system;Integrated Security=True");

            for (int i = 0; i < username.Length; i++)
            {
                if (!char.IsDigit(username[i]) && !char.IsLetter(username[i]))
                {
                    notvalid = "username";
                    valid    = false;
                }
            }
            for (int i = 0; i < password.Length; i++)
            {
                if (!char.IsDigit(password[i]) && !char.IsLetter(password[i]))
                {
                    notvalid = "password";
                    valid    = false;
                }
            }
            for (int i = 0; i < profilenme.Length; i++)
            {
                if (!char.IsDigit(profilenme[i]) && !char.IsLetter(profilenme[i]))
                {
                    notvalid = "profile_name";
                    valid    = false;
                }
            }

            if (!valid)
            {
                MessageBox.Show("The " + notvalid + " must contain only letters and digits !");
            }
            else if (username == "" || password == "" || profilenme == "")
            {
                MessageBox.Show("Fill the username , password and profile name first");
            }
            else if (password.Length > 10 || password.Length < 5)
            {
                MessageBox.Show("The password should be between 5 and 10 characters ");
            }
            else if (username.Length > 10 || username.Length < 5)
            {
                MessageBox.Show("The username should be between 5 and 10 characters ");
            }
            else if (profilenme.Length > 10 || profilenme.Length < 5)
            {
                MessageBox.Show("The profile name should be between 5 and 10 characters ");
            }
            else if (repassword.Length == 0)
            {
                MessageBox.Show("Confirm the password");
            }
            else if (repassword != password)
            {
                MessageBox.Show("The two password don't match !");
            }
            else
            {
                if (query.check_username(username))
                {
                    MessageBox.Show("This username is already taken!");
                }
                else
                {
                    query.insert_user_information(profilenme, username, password);
                    MessageBox.Show("Registrated successifly!");
                    Sign_in    signin     = new Sign_in();
                    MainWindow mainWindow = new MainWindow();
                    mainWindow.Close();
                    signin.Show();
                }
            }
        }