Example #1
0
 public PetDisplayVM()
 {
     if (LoginWindow.AccountToLogin.Type == "Seller")
     {
         ReadInDataFromSeller(LoginWindow.AccountToLogin.id);
     }
     else if (ShopperHomeVM.stype == "Age")
     {
         AnimalCollection = PostgreSQL.searchByAge(ShopperHomeVM.stxt);
     }
     else if (ShopperHomeVM.stype == "Type")
     {
         AnimalCollection = PostgreSQL.searchByType(ShopperHomeVM.stxt);
     }
     else if (ShopperHomeVM.stype == "Price")
     {
         AnimalCollection = PostgreSQL.searchByPrice(ShopperHomeVM.stxt);
     }
     else if (ShopperHomeVM.stype == "Zipcode")
     {
         AnimalCollection = PostgreSQL.searchByZip(ShopperHomeVM.stxt);
     }
     else if (ShopperHomeVM.stype == "All")
     {
         ReadInAllData();
     }
     else
     {
         ReadInAllData();
     }
 }
Example #2
0
        private void UpdateQuantities()
        {
            foreach (Animal a in Parent.Cart)
            {
                foreach (Animal animal in AnimalCollection)
                {
                    if (a.PetID == animal.PetID)
                    {
                        animal.Quantity = (int.Parse(animal.Quantity) - int.Parse(a.PurchasedAmount)).ToString();
                        PostgreSQL.editPet(animal);
                    }
                }

                foreach (Account acc in AccountList)
                {
                    if (acc.id == LoggedInShopper.id)
                    {
                        foreach (Animal o in LoggedInShopper.CartContent.ToList())
                        {
                            if (o.PetID == a.PetID)
                            {
                                //LoggedInShopper.PreviousPurchases.Add(o);
                                LoggedInShopper.CartContent.Remove(o);
                            }
                        }
                        LoggedInShopper.CartTotal = "0";
                        LoggedInShopper.CartItems = "0";
                    }
                }
            }
        }
Example #3
0
        private bool CheckUsernamePassword()
        {
            ObservableCollection <Account> AccountListTemp1 = new ObservableCollection <Account>();
            ObservableCollection <Account> AccountListTemp2 = new ObservableCollection <Account>();

            if (ValidateAllEntries())
            {
                AccountListTemp1 = PostgreSQL.searchByUsername(UsernameEntry.Text);

                if (AccountListTemp1 == null)
                {
                    Verify.Visibility = Visibility.Visible;
                    return(false);
                }
                else
                {
                    AccountListTemp2 = PostgreSQL.validateUsernamePassword(UsernameEntry.Text, PasswordEntry.Password);
                    if (AccountListTemp2.Count == 0)
                    {
                        Verify.Visibility = Visibility.Visible;
                        return(false);
                    }
                    else
                    {
                        AccountToLogin    = AccountListTemp2.FirstOrDefault(a => a.Username == UsernameEntry.Text);
                        Verify.Visibility = Visibility.Hidden;
                        return(true);
                    }
                }
            }
            return(false);
        }
Example #4
0
 public ShoppingCartVM(ShopperHomeVM parent, Account acct)
 {
     Parent           = parent;
     LoggedInUser     = acct;
     AccountList      = PostgreSQL.getAllAccounts();
     AnimalCollection = PostgreSQL.getAllPets();
 }
Example #5
0
        private void ReadInAllData()
        {
            AnimalCollection = PostgreSQL.getAllPets();

            if (AnimalCollection == null)
            {
                AnimalCollection = new ObservableCollection <Animal>();
            }
        }
Example #6
0
        private void ReadInDataFromSeller(int id)
        {
            AnimalCollection = PostgreSQL.getOwnersPets(id);

            if (AnimalCollection == null)
            {
                AnimalCollection = new ObservableCollection <Animal>();
            }
        }
Example #7
0
        public PlaceOrderVM(ShopperHomeVM parent, Account acct)
        {
            this.Parent          = parent;
            this.LoggedInShopper = acct;

            AnimalCollection = PostgreSQL.getAllPets();
            AccountList      = PostgreSQL.getAllAccounts();

            // Receipt Text
            string header = $"Receipt For {LoggedInShopper.FirstName} {LoggedInShopper.LastName}\n";

            this.ReceiptText = header;
            UpdateQuantities();
        }
Example #8
0
        private void SavePetToDatabase(object sender, RoutedEventArgs e)
        {
            petType     = PetTypeEntry.Text;
            petSize     = PetSizeEntry.Text;
            petAge      = PetAgeEntry.Text;
            petQuantity = PetQuantityEntry.Text;
            petPrice    = PetPriceEntry.Text;
            petZip      = PetZipEntry.Text;

            if (CheckEntries())
            {
                MessageBox.Show("Updating database...");
                Animal a = new Animal(petID, LoggedInSeller.id, petType, petAge, petSize, petQuantity, petPrice, petZip);
                PostgreSQL.editPet(a);
                PostgreSQL.editSeller(LoggedInSeller, a);
                SellerHome sh = new SellerHome(LoggedInSeller);
                sh.Show();
                this.Close();
            }
        }
Example #9
0
        private void DeletePet(object o)
        {
            lb = o as ListBox;
            Animal selectedAnimal = lb.SelectedItem as Animal;

            if (selectedAnimal == null)
            {
                MessageBox.Show("Please select an animal before removing it", "Invalid Selection");
            }
            else
            {
                MessageBox.Show("Removing from the database...");
                PostgreSQL.deleteSeller(selectedAnimal.PetID);
                PostgreSQL.deletePet(selectedAnimal.PetID);

                SellerHome sh = new SellerHome(LoggedInSeller);
                closeWindows();
                sh.Show();
            }
        }
Example #10
0
        private void Submit(object sender, RoutedEventArgs e)
        {
            ObservableCollection <Account> acct = PostgreSQL.searchByUsername(UsernameEntry.Text);

            if (acct.Count != 0)
            {
                MessageBox.Show("Username already exists. Please choose another username!");
            }
            if (ValidateEntries() && acct.Count == 0)
            {
                Account Account = new Account();

                Account.FirstName         = FirstNameEntry.Text;
                Account.LastName          = LastNameEntry.Text;
                Account.Telephone         = PhoneEntry.Text;
                Account.Username          = UsernameEntry.Text;
                Account.Password          = PasswordEntry.Password;
                Account.CartItems         = "0";
                Account.CartTotal         = "0";
                Account.CartContent       = new ObservableCollection <Animal>();
                Account.PreviousPurchases = new ObservableCollection <Animal>();


                if (Shopper.IsChecked == true)
                {
                    Account.Type = Shopper.Content.ToString();
                    PostgreSQL.addAccount(Account);
                    ZipCodePanel.Visibility = Visibility.Hidden;
                    openLogin(Account);
                }
                else if (Seller.IsChecked == true)
                {
                    Account.Type = Seller.Content.ToString();
                    PostgreSQL.addAccount(Account);
                    openLogin(Account);
                }
            }
        }
Example #11
0
        private void AddToCartClicked(object obj)
        {
            ObservableCollection <Account> AccountList;

            AnimalCollection = PostgreSQL.getAllPets();
            AccountList      = PostgreSQL.getAllAccounts();

            lb = obj as ListBox;
            Animal selectedAnimal = lb.SelectedItem as Animal;

            isCartEmpty = (Cart.Count == 0) ? true : false;

            if (Quantity == null)
            {
                MessageBox.Show("Please enter a valid quantity to add to your cart", "Invalid Quantity");
            }
            else
            {
                int purchAmt = int.Parse(Quantity);

                if (selectedAnimal == null)
                {
                    MessageBox.Show("Please select an animal before adding it to your cart", "Invalid Selection");
                }
                else if (selectedAnimal.Price == "Pricele$$")
                {
                    MessageBox.Show("This item cannot be purchased", "The Rock Says:");
                }
                else
                {
                    if (isCartEmpty)
                    {
                        if ((int.Parse(selectedAnimal.Quantity) - purchAmt) < 0)
                        {
                            MessageBox.Show($"Requested Quantity Exceeds the number of {selectedAnimal.Type}s in stock", "Invalid Quantity");
                        }
                        else
                        {
                            selectedAnimal.Quantity        = (int.Parse(selectedAnimal.Quantity) - purchAmt).ToString();
                            selectedAnimal.PurchasedAmount = purchAmt.ToString();
                            Cart.Add(selectedAnimal as object);

                            TotalCost += double.Parse(selectedAnimal.Price.Replace("$", "")) * purchAmt;
                            TotalItem += double.Parse(selectedAnimal.PurchasedAmount);
                            CollectionViewSource.GetDefaultView(lb.ItemsSource).Refresh();

                            foreach (Account a in AccountList)
                            {
                                if (a.id == LoggedInUser.id)   // CHANGE THIS TO ACCOUNT ID
                                {
                                    if (LoggedInUser.CartContent == null)
                                    {
                                        LoggedInUser.CartContent = new ObservableCollection <Animal>();
                                    }
                                    LoggedInUser.CartContent.Add(selectedAnimal);
                                    LoggedInUser.CartTotal = TotalCost.ToString();
                                    LoggedInUser.CartItems = TotalItem.ToString();
                                }
                            }
                            CollectionViewSource.GetDefaultView(selectedAnimal.Quantity).Refresh();
                            PostgreSQL.addShopper(LoggedInUser, selectedAnimal);
                        }
                    }
                    else
                    {
                        foreach (object o in Cart.ToList())
                        {
                            Animal amal = o as Animal;
                            if (amal.Type == selectedAnimal.Type)
                            {
                                MessageBox.Show("You already have that animal in your shopping cart. Click Review Order to change the quantity", "Oopsies");
                            }
                            else
                            {
                                selectedAnimal.Quantity        = (int.Parse(selectedAnimal.Quantity) - purchAmt).ToString();
                                selectedAnimal.PurchasedAmount = purchAmt.ToString();
                                Cart.Add(selectedAnimal as object);

                                TotalCost += double.Parse(selectedAnimal.Price.Replace("$", "")) * purchAmt;
                                TotalItem += double.Parse(selectedAnimal.PurchasedAmount);
                                CollectionViewSource.GetDefaultView(lb.ItemsSource).Refresh();

                                foreach (Account a in AccountList)
                                {
                                    if (a.id == LoggedInUser.id)
                                    {
                                        LoggedInUser.CartContent.Add(selectedAnimal);
                                        LoggedInUser.CartTotal = TotalCost.ToString();
                                        LoggedInUser.CartItems = TotalItem.ToString();
                                    }
                                }
                                CollectionViewSource.GetDefaultView(selectedAnimal.Quantity).Refresh();
                                PostgreSQL.addShopper(LoggedInUser, selectedAnimal);
                            }
                        }
                    }
                }
            }
        }