예제 #1
0
        public List <ItemToPurchaseClass> getMostBoughtItems(string itemtype)
        {
            try
            {
                DatabaseHelperClass dbHelper   = DatabaseHelperClass.Instance; //SINGLETON PATTERN
                SqlConnection       connection = dbHelper.getConnection();
                SqlCommand          command    = new SqlCommand("SELECT S.itemid,S.picture,S.name,S.paymentamount,SUM(S.quantity) AS totalquantity FROM ShoppingCartTable S WHERE S.itemtype = @itemtype GROUP BY S.itemid, S.picture, S.name, S.paymentamount Order by totalquantity desc", connection);
                command.Parameters.AddWithValue("@itemtype", itemtype);

                List <ItemToPurchaseClass> list = new List <ItemToPurchaseClass>();
                SqlDataReader readShoppingCart  = command.ExecuteReader();
                if (readShoppingCart != null)
                {
                    while (readShoppingCart.Read())
                    {
                        ItemToPurchaseClass item = new ItemToPurchaseClass();
                        ProductClass        book = new BookClass();
                        item.product       = book;
                        item.product.id    = readShoppingCart["itemid"].ToString();
                        item.quantity      = Convert.ToInt32(readShoppingCart["totalquantity"]);
                        item.product.price = Convert.ToDouble(readShoppingCart["paymentamount"]);
                        item.product.name  = readShoppingCart["name"].ToString();
                        item.product.cover_page_picture = readShoppingCart["picture"].ToString();
                        list.Add(item);
                    }
                }
                return(list);
            }
            catch (Exception e)
            {
                FileWriterClass.WriteFile(AppConstants.EXCEPTION_LOG_FILE_LOCATION, "Exception at getMostBoughtItems function" + e.Message);
                Console.WriteLine("Click {0}", e.Message);
                return(null);
            }
        }
예제 #2
0
        /**@brief getAllUserPurchases() function
         *
         * @param int userID
         */

        public List <ItemToPurchaseClass> getAllUserPurchases(int userID)
        {
            try
            {
                DatabaseHelperClass dbHelper   = DatabaseHelperClass.Instance; //SINGLETON PATTERN
                SqlConnection       connection = dbHelper.getConnection();
                SqlCommand          command    = new SqlCommand("SELECT * FROM ShoppingCartTable WHERE customerid=@id", connection);
                command.Parameters.AddWithValue("@id", userID);

                List <ItemToPurchaseClass> list = new List <ItemToPurchaseClass>();
                SqlDataReader readShoppingCart  = command.ExecuteReader();
                if (readShoppingCart != null)
                {
                    while (readShoppingCart.Read())
                    {
                        ItemToPurchaseClass item = new ItemToPurchaseClass();
                        ProductClass        book = new BookClass();
                        item.product       = book;
                        item.product.id    = readShoppingCart["itemid"].ToString();
                        item.quantity      = Convert.ToInt32(readShoppingCart["quantity"]);
                        item.product.price = Convert.ToDouble(readShoppingCart["paymentamount"]);
                        item.product.name  = readShoppingCart["name"].ToString();
                        item.product.cover_page_picture = readShoppingCart["picture"].ToString();
                        list.Add(item);
                    }
                }
                return(list);
            }
            catch (Exception e)
            {
                FileWriterClass.WriteFile(AppConstants.EXCEPTION_LOG_FILE_LOCATION, "Exception at getAllUserPurchases function" + e.Message);
                Console.WriteLine("Click {0}", e.Message);
                return(null);
            }
        }
예제 #3
0
        /** @brief remove product() function
         * @param ItemToPurchaseClass itemToPurchase
         * calls remove() and   shoppingCartUpdate() function
         */
        public static void removeProduct(ItemToPurchaseClass itemToPurchase)
        {
            var element = itemsToPurchase.Find(el => el.product.id == itemToPurchase.product.id);

            itemsToPurchase.Remove(element);
        }
예제 #4
0
 /**@brief add itemToPurchase
  * @param ItemToPurchaseClass itemToPurchase
  */
 public static void addProduct(ItemToPurchaseClass itemToPurchase)
 {
     itemsToPurchase.Add(itemToPurchase);
 }