private void CalculateTotal(DataTable dt) { int taxType = 0; decimal total, subTotal, tax, deliveryFee, totalAfterDiscount; total = subTotal = tax = deliveryFee = totalAfterDiscount = 0; ShoppingCartVariables shoppingCartVariables; if (Application["ShoppingCartVariables"] == null) { shoppingCartVariables = objBAL.GetShoppingCartVariables(); Application["ShoppingCartVariables"] = shoppingCartVariables; } else { shoppingCartVariables = (ShoppingCartVariables)Application["ShoppingCartVariables"]; } deliveryFee = shoppingCartVariables.DeliveryFee; if (dt.Rows.Count > 0) { foreach (DataRow row in dt.Rows) { decimal itemAmt = Convert.ToDecimal(row["Qty"]) * Convert.ToDecimal(row["Price"]); subTotal += itemAmt; taxType = Convert.ToInt16(row["TaxType"]); if (taxType == 1) { tax += Math.Round((itemAmt * shoppingCartVariables.FoodTax / 100), 2); } else { tax += Math.Round((itemAmt * shoppingCartVariables.NonFoodTax / 100), 2); } } total += subTotal + tax; if (subTotal < shoppingCartVariables.DeliveryFeeCutOff) { total += deliveryFee; } if (Session["Coupon"] != null) { totalAfterDiscount = total; decimal couponAmt = ((Coupon)Session["Coupon"]).Amount; totalAfterDiscount -= couponAmt; if (totalAfterDiscount < 0) { totalAfterDiscount = 0; } lblTotValueAfterDiscount.Text = Convert.ToString(totalAfterDiscount); ShowHideDiscount(true); } else { ShowHideDiscount(false); } lblDeliveryFeeTot.Text = deliveryFee.ToString(); lblTaxVal.Text = tax.ToString(); lblTotVal.Text = Math.Round(total, 2).ToString(); lblSubTotVal.Text = subTotal.ToString(); } }