public int getUserID(string email, string password)
        {
            string    clause = "WHERE email = '" + email + "' AND password = '******';";
            DataTable dt     = DatabaseHandler.Select("Users", clause);

            return(int.Parse(dt.Rows[0][0].ToString()));
        }
Пример #2
0
        public bool addItem(string name, string category, string picture, string description, string date, string location)
        {
            itemID             = DatabaseHandler.Select("Item", "").Rows.Count + 1;
            this.name          = name;
            this.category      = category;
            this.pictureString = picture;
            this.description   = description;
            this.date          = date;
            this.location      = location;
            if (Login.loginUser)
            {
                userID = Login.loginUserID;
            }
            if (SignUp.signUpUser)
            {
                userID = SignUp.signUpUserID;
            }
            bool success;

            try
            {
                DatabaseHandler.Insert("Item", new string[]
                {
                    itemID.ToString(),
                    name,
                    category,
                    picture,
                    description,
                    date,
                    location,
                    userID.ToString()
                });
                success = true;
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception thrown");
                success = false;
                throw e;
            }
            if (success)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public bool login(string email, string password)
        {
            User      user   = new User();
            string    clause = "WHERE email = '" + email + "' AND password = '******';";
            DataTable dt     = DatabaseHandler.Select("Users", clause);

            if (dt.Rows.Count == 0)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
        public bool addUser(string firstName, string lastName, string email, string mobileNumber, string gender, int age, string password)
        {
            userID            = DatabaseHandler.Select("Users", "").Rows.Count + 1;
            this.firstName    = firstName;
            this.lastName     = lastName;
            this.email        = email;
            this.mobileNumber = mobileNumber;
            this.gender       = gender;
            this.age          = age;
            this.password     = password;
            string    clause = "WHERE email = '" + email + "';";
            DataTable dt     = DatabaseHandler.Select("Users", clause);

            if (dt.Rows.Count == 0)
            {
                try
                {
                    int count = DatabaseHandler.Select("Users", "").Rows.Count + 1;
                    DatabaseHandler.Insert("Users", new string[]
                    {
                        count.ToString(),
                        firstName,
                        lastName,
                        email,
                        mobileNumber.ToString(),
                        age.ToString(),
                        gender.ToString(),
                        password,
                    });
                    return(true);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Exception thrown");
                    throw e;
                }
            }
            else
            {
                return(false);
            }
        }
        public User getUser(string email, string password)
        {
            User   user   = new User();
            string clause = "WHERE email = '" + email + "' AND password = '******';";

            try
            {
                DataTable dt = DatabaseHandler.Select("Users", clause);
                user.userID       = int.Parse(dt.Rows[0][0].ToString());
                user.firstName    = dt.Rows[0][1].ToString();
                user.lastName     = dt.Rows[0][2].ToString();
                user.email        = dt.Rows[0][3].ToString();
                user.mobileNumber = dt.Rows[0][4].ToString();
                user.age          = int.Parse(dt.Rows[0][5].ToString());
                user.gender       = dt.Rows[0][6].ToString();
                user.password     = dt.Rows[0][7].ToString();
                return(user);
            }
            catch (Exception e)
            {
                Console.WriteLine("Couldn't select User");
                throw e;
            }
        }
 private void LoginButtonClicked(object sender, RoutedEventArgs e)
 {
     EmailTextBox.Text.ToLower();
     if (EmailTextBox.Text == "" || PasswordTextBox.Password == "")
     {
         MessageBox.Show("Please enter your Email or Password \nEmail & Password can't be empty", "Error", MessageBoxButton.OK);
     }
     else
     {
         bool login = new User().login(EmailTextBox.Text, PasswordTextBox.Password);
         if (login)
         {
             loginUser         = true;
             SignUp.signUpUser = false;
             DataTable dt = DatabaseHandler.Select("Users", new string[] { "userID" }, $"WHERE email = '{EmailTextBox.Text}';");
             loginUserID = int.Parse(dt.Rows[0][0].ToString());
             NavigationService.Navigate(new Uri("Home.xaml", UriKind.RelativeOrAbsolute));
         }
         else
         {
             MessageBox.Show("Please SignUp \nthe email you entered isn't registered", "Error", MessageBoxButton.OK);
         }
     }
 }
Пример #7
0
 private void SignUpClicked(object sender, RoutedEventArgs e)
 {
     if (FirstNameTextBox.Text != "" || LastNameTextBox.Text != "" || EmailTextBox.Text != "" || MobileNumberTextBox.Text != "" ||
         AgeTextBox.Text != "" || GenderTextBox.Text != "" || PasswordTextBox.Password != "" || ConfirmPasswordTextBox.Password != "")
     {
         if (notContainsAlphabet(AgeTextBox.Text))
         {
             if (MobileNumberTextBox.Text.Length == 11 && notContainsAlphabet(MobileNumberTextBox.Text))
             {
                 if (PasswordTextBox.Password == ConfirmPasswordTextBox.Password)
                 {
                     string    clause = "WHERE email = '" + EmailTextBox.Text + "';";
                     DataTable dt     = DatabaseHandler.Select("Users", clause);
                     if (dt.Rows.Count == 0)
                     {
                         if (new User().addUser(
                                 FirstNameTextBox.Text,
                                 LastNameTextBox.Text,
                                 EmailTextBox.Text,
                                 MobileNumberTextBox.Text,
                                 GenderTextBox.Text,
                                 int.Parse(AgeTextBox.Text),
                                 PasswordTextBox.Password))
                         {
                             DataTable dt2 = DatabaseHandler.Select("Users", new string[] { "userID" }, $"WHERE email = '{EmailTextBox.Text}';");
                             signUpUserID    = int.Parse(dt2.Rows[0][0].ToString());
                             signUpUser      = true;
                             Login.loginUser = false;
                             MessageBox.Show("Signed up Successfully", "Done!", MessageBoxButton.OK);
                             NavigationService.Navigate(new Uri("Home.xaml", UriKind.RelativeOrAbsolute));
                         }
                         else
                         {
                             MessageBox.Show("An unknown error occured /nPlease try again", "Error", MessageBoxButton.OK);
                         }
                     }
                     else
                     {
                         MessageBox.Show("This email already exists, please login", "Error", MessageBoxButton.OK);
                     }
                 }
                 else
                 {
                     MessageBox.Show("The passwords don't match", "Error", MessageBoxButton.OK);
                 }
             }
             else
             {
                 MessageBox.Show("Please enter your mobile number correctly", "Error", MessageBoxButton.OK);
             }
         }
         else
         {
             MessageBox.Show("Please enter your age correctly", "Error", MessageBoxButton.OK);
         }
     }
     else
     {
         MessageBox.Show("Please make sure that you entered all the fields correctly", "Error", MessageBoxButton.OK);
     }
 }