Example #1
0
        public static double getTotal(int custID)
        {
            double total = 0.0;

            List <int> pIDs       = new List <int>();
            List <int> quantities = new List <int>();

            string        connectionString = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
            SqlConnection connection       = new SqlConnection(connectionString);
            String        sql = "SELECT ProductID, Quantity FROM [ShoppingCart] WHERE CustomerID = @CustomerID";

            SqlCommand    command = new SqlCommand(sql, connection);
            SqlDataReader reader;


            connection.Open();

            command.Parameters.Add("@CustomerID", SqlDbType.Int);
            command.Parameters["@CustomerID"].Value = custID;

            reader = command.ExecuteReader();
            while (reader.HasRows)
            {
                while (reader.Read())
                {
                    pIDs.Add(reader.GetInt32(0));
                    quantities.Add(reader.GetInt32(1));
                }
                reader.NextResult();
            }


            connection.Close();


            for (int i = 0; i < pIDs.Count; i++)
            {
                total += StandardProduct.getProductPrice(pIDs[i]) * quantities[i];
            }

            return(total);
        }