示例#1
0
        /// <summary>
        /// Function to get product details
        /// </summary>
        /// <param name="shoppingCart">Shopping cart cookie string</param>
        /// <returns>Data table containing product details</returns>
        public DataTable GetShoppingCart(string shoppingCart)
        {
            DataTable dt        = new DataTable();
            int       qty       = 0;
            string    productID = String.Empty;

            try
            {
                dt.Columns.Add("ProductID");
                dt.Columns.Add("ProductName");
                dt.Columns.Add("Qty");
                dt.Columns.Add("Price");
                dt.Columns.Add("Size");
                dt.Columns.Add("TaxType");

                if (shoppingCart.Trim().Length > 0)
                {
                    string[] splitChar   = { "|@|" };
                    string[] productList = shoppingCart.Split(splitChar, StringSplitOptions.None);

                    //Loop through the shopping cart string.
                    for (int i = 0; i < productList.Length; i += 2)
                    {
                        productID = Convert.ToString(productList[i]);
                        qty       = Convert.ToInt32(productList[i + 1]);

                        //Get the product details of a product.
                        DataRow row = objDAL.GetProductDetails(productID, qty);

                        //Flag to check if the product is repeated in the shopping cart.
                        bool isRepeated = false;

                        if (dt.Rows.Count > 0)
                        {
                            productID = Convert.ToString(row["ProductID"]);

                            foreach (DataRow dataRow in dt.Rows)
                            {
                                //Check if the product is already stored in the data table.
                                if (productID == Convert.ToString(dataRow["ProductID"]))
                                {
                                    dataRow["Qty"] = Convert.ToInt32(dataRow["Qty"]) + Convert.ToInt32(row["Qty"]);
                                    isRepeated     = true;
                                }
                            }
                        }

                        if (!isRepeated)
                        {
                            dt.Rows.Add(GetProductDataRow(dt, row));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                objDAL.LogError(ex.Message, ex.StackTrace);
            }

            return(dt);
        }