public void InitOrderGrid(ArrayList cartTable, GridView grdOrder)
    {
        if (cartTable.Count > 0)
        {
            DataColumn colQuantity;
            DataColumn colTotalPrice;

            colQuantity              = new DataColumn();
            colQuantity.DataType     = System.Type.GetType("System.Int32");
            colQuantity.ColumnName   = "quantity";
            colQuantity.DefaultValue = 1;

            colTotalPrice            = new DataColumn();
            colTotalPrice.DataType   = System.Type.GetType("System.Double");
            colTotalPrice.ColumnName = "total";

            //String sql = GetCartListSql(cartTable);
            //DataTable dtOrder = dbHandler.GetDataTable(sql);
            grdOrder.Columns[0].HeaderText = "  " + (string)base.GetGlobalResourceObject("string", "lblCategory");
            grdOrder.Columns[1].HeaderText = (string)base.GetGlobalResourceObject("string", "productdescription");
            //grdOrder.Columns[2].HeaderText = (string)base.GetGlobalResourceObject("string", "price");
            grdOrder.Columns[3].HeaderText = (string)base.GetGlobalResourceObject("string", "price");
            grdOrder.Columns[4].HeaderText = (string)base.GetGlobalResourceObject("string", "quantity");
            grdOrder.Columns[5].HeaderText = (string)base.GetGlobalResourceObject("string", "total");
            //dtOrder.Columns.Add(colTotalPrice);
            // dtOrder.Columns.Add(colQuantity);

            //int rowCount = dtOrder.Rows.Count;
            DataTable dtOrder = new DataTable();
            dtOrder.Columns.Add("articlecode");
            dtOrder.Columns.Add("productType");
            dtOrder.Columns.Add("title");
            dtOrder.Columns.Add("subtitle");
            dtOrder.Columns.Add("publisher");
            dtOrder.Columns.Add("price");
            dtOrder.Columns.Add("quantity");
            dtOrder.Columns.Add("total");
            dtOrder.Columns.Add("vatpc");
            dtOrder.Columns.Add("deliverytime");
            int       i         = 0;
            ArrayList shopItems = (ArrayList)Session["order"];
            enu = shopItems.GetEnumerator();
            while (enu.MoveNext())
            {
                DataRow row = dtOrder.NewRow();
                order = (Order)enu.Current;
                row["articlecode"]  = order.articlecode.ToString();
                row["productType"]  = order.productType.ToString();
                row["publisher"]    = order.publisherName.ToString();
                row["title"]        = order.productdescription.ToString();
                row["subtitle"]     = order.subtitle.ToString();
                row["price"]        = string.Format("{0:F2}", order.vatIncludedPrice);
                row["quantity"]     = order.quantity.ToString();
                row["vatpc"]        = string.Format("{0:F2}", order.vatpc);
                row["deliverytime"] = order.deliveryTime;
                qty += (int)order.quantity;
                Session["CartItems"] = qty;
                double total = Math.Round((order.vatIncludedPrice * order.quantity), 2);


                double vatIncludePrice = VatCalculator.GetVatIncludedPrice(total, order.vatpc);

                totalPrice  += total;
                row["total"] = string.Format("{0:F2}", total);
                dtOrder.Rows.Add(row);
                i++;
            }


            grdOrder.DataSource = dtOrder;
            grdOrder.DataBind();
            lblHeaderTotPrice.Text = (string)base.GetGlobalResourceObject("string", "total") + "  " + (string)base.GetGlobalResourceObject("string", "price");
            lblTotalPrice.Text     = string.Format("{0:F2}", totalPrice);
        }
        else
        {
            grdOrder.DataSource = null;
            grdOrder.DataBind();
            lblTotalPrice.Text   = "0";
            grdOrder.Visible     = false;
            lblEmptyCart.Visible = true;
            btnContinue.Enabled  = false;
        }
    }
示例#2
0
    public void InitOrderGrid(ArrayList cartTable, GridView grdOrder)
    {
        if (cartTable.Count > 0)
        {
            DataColumn colQuantity;
            DataColumn colTotalPrice;

            colQuantity              = new DataColumn();
            colQuantity.DataType     = System.Type.GetType("System.Int32");
            colQuantity.ColumnName   = "quantity";
            colQuantity.DefaultValue = 1;

            colTotalPrice            = new DataColumn();
            colTotalPrice.DataType   = System.Type.GetType("System.Double");
            colTotalPrice.ColumnName = "total";

            //String sql = GetCartListSql(cartTable);
            //DataTable dtOrder = DataAccessHelper.GetInstance().GetDataTable(sql);
            grdOrder.Columns[0].HeaderText = "  " + (string)base.GetGlobalResourceObject("string", "lblCategory");
            grdOrder.Columns[1].HeaderText = (string)base.GetGlobalResourceObject("string", "productdescription");
            //grdOrder.Columns[2].HeaderText = (string)base.GetGlobalResourceObject("string", "price");
            grdOrder.Columns[3].HeaderText = (string)base.GetGlobalResourceObject("string", "price");
            grdOrder.Columns[4].HeaderText = (string)base.GetGlobalResourceObject("string", "quantity");
            grdOrder.Columns[5].HeaderText = (string)base.GetGlobalResourceObject("string", "total");
            //dtOrder.Columns.Add(colTotalPrice);
            // dtOrder.Columns.Add(colQuantity);

            //int rowCount = dtOrder.Rows.Count;
            DataTable dtOrder = new DataTable();
            dtOrder.Columns.Add("articlecode");
            dtOrder.Columns.Add("productType");
            dtOrder.Columns.Add("title");
            dtOrder.Columns.Add("subtitle");
            dtOrder.Columns.Add("publisher");
            dtOrder.Columns.Add("price");
            dtOrder.Columns.Add("quantity");
            dtOrder.Columns.Add("total");
            dtOrder.Columns.Add("vatpc");
            dtOrder.Columns.Add("deliverytime");
            int i = 0;

            enu = cartTable.GetEnumerator();


            while (enu.MoveNext())
            {
                DataRow row = dtOrder.NewRow();
                order = (Order)enu.Current;



                row["articlecode"]  = order.articlecode.ToString();
                row["productType"]  = order.productType.ToString();
                row["publisher"]    = order.publisherName.ToString();
                row["title"]        = order.productdescription.ToString();
                row["subtitle"]     = order.subtitle.ToString();
                row["deliverytime"] = order.deliveryTime;


                double discount = Math.Round((order.price * (order.discountpc / 100)), 2);

                double price = Math.Round((order.price - discount), 2);

                row["price"]    = string.Format("{0:F2}", price);
                row["quantity"] = order.quantity.ToString();
                row["vatpc"]    = string.Format("{0:F2}", order.vatpc);
                qty            += (int)order.quantity;



                double total = Math.Round((price * order.quantity), 2);


                double vatIncludePrice = VatCalculator.GetVatIncludedPrice(total, order.vatpc);

                totalVat += (vatIncludePrice - total);

                totalPrice  += total;
                row["total"] = string.Format("{0:F2}", total);
                dtOrder.Rows.Add(row);
                i++;
            }



            totalVat            = Math.Round(totalVat, 2);
            grdOrder.DataSource = dtOrder;
            grdOrder.DataBind();

            double totalShippingCosts = CalculateShippingCostsWithVat(cartTable);

            double grandTotalPrice = Math.Round((totalPrice + totalVat + totalShippingCosts), 2);

            ViewState["GrandTotalPrice"] = grandTotalPrice;

            ViewState["TotalVat"]      = totalVat;
            ViewState["TotalNetPrice"] = totalPrice;

            ViewState["TotalShippingCosts"] = totalShippingCosts;

            // Session["gtotal"] = string.Format("{0:F2}", grandTotoal);
            lblSubTotal.Text     = "€ " + string.Format("{0:F2}", totalPrice.ToString()) + " ";
            lblVat.Text          = "€ " + string.Format("{0:F2}", totalVat.ToString()) + " ";
            lblTotal.Text        = "€ " + string.Format("{0:F2}", grandTotalPrice.ToString()) + " ";
            lblShippingCost.Text = "€ " + string.Format("{0:F2}", totalShippingCosts.ToString()) + " ";
        }
        else
        {
            grdOrder.DataSource = null;
            grdOrder.DataBind();
            grdOrder.Visible     = false;
            lblSubTotal.Text     = "€ 0 ";
            lblVat.Text          = "€ 0 ";
            lblTotal.Text        = "€ 0 ";
            lblShippingCost.Text = "€ 0 ";
        }
    }