Пример #1
0
    protected void BtnSubmit_Click1(object sender, EventArgs e)
    {
        ReceivingDeskScreen r = new ReceivingDeskScreen();
        productdb           p = createPart();

        lblResult.Text = r.insertParts(p);
    }
Пример #2
0
    private void CreateShopTable(IEnumerable <cart> carts, out double subTotal)
    {
        subTotal = new double();

        ReceivingDeskScreen model = new ReceivingDeskScreen();

//        ProductModel model = new ProductModel();

        foreach (cart cart in carts)
        {
            int pid = Convert.ToInt32(cart.ProductId);
            //Create HTML elements and fill values with database data
            productdb     product = model.GetProduct(pid);
            LegacyPartsDB l       = new LegacyPartsDB();
            part          pt      = l.chooseParts(pid);

            ImageButton btnImage = new ImageButton
            {
                ImageUrl    = string.Format("~/Images/Products/{0}", product.image),
                PostBackUrl = string.Format("~/Pages/ChooseProduct.aspx?id={0}", product.id)
            };

            LinkButton lnkDelete = new LinkButton
            {
                PostBackUrl = string.Format("~/Pages/ShoppingCart.aspx?productId={0}", cart.id),
                Text        = "Delete Item",
                ID          = "del" + cart.id,
            };

            lnkDelete.Click += Delete_Item;

            //Fill amount list with numbers

            int          q         = Convert.ToInt32(product.qty);
            int[]        amount    = Enumerable.Range(1, q).ToArray();
            DropDownList ddlAmount = new DropDownList
            {
                DataSource           = amount,
                AppendDataBoundItems = true,
                AutoPostBack         = true,
                ID = cart.id.ToString()
            };
            ddlAmount.DataBind();
            ddlAmount.SelectedValue         = cart.Amount.ToString();
            ddlAmount.SelectedIndexChanged += ddlAmount_SelectedIndexChanged;


            //Create table to hold shopping cart details
            Table table = new Table {
                CssClass = "CartTable"
            };
            TableRow row1 = new TableRow();
            TableRow row2 = new TableRow();

            TableCell cell1_1 = new TableCell {
                RowSpan = 2, Width = 50
            };
            TableCell cell1_2 = new TableCell
            {
                Text = string.Format("<h4>{0}</h4><br />{1}<br/>In Stock",
                                     pt.description, "Item No:" + product.id),
                HorizontalAlign = HorizontalAlign.Left,
                Width           = 350,
            };
            TableCell cell1_3 = new TableCell {
                Text = "Unit Price<hr/>"
            };
            TableCell cell1_4 = new TableCell {
                Text = "Quantity<hr/>"
            };
            TableCell cell1_5 = new TableCell {
                Text = "Item Total<hr/>"
            };
            TableCell cell1_6 = new TableCell();
            double    pri     = Convert.ToDouble(pt.price);
            TableCell cell2_1 = new TableCell();
            TableCell cell2_2 = new TableCell {
                Text = "$ " + pt.price
            };
            TableCell cell2_3 = new TableCell();
            TableCell cell2_4 = new TableCell {
                Text = "$ " + Math.Round((cart.Amount * pri), 2)
            };
            TableCell cell2_5 = new TableCell();


            //Set custom controls
            cell1_1.Controls.Add(btnImage);
            cell1_6.Controls.Add(lnkDelete);
            cell2_3.Controls.Add(ddlAmount);

            //Add rows & cells to table
            row1.Cells.Add(cell1_1);
            row1.Cells.Add(cell1_2);
            row1.Cells.Add(cell1_3);
            row1.Cells.Add(cell1_4);
            row1.Cells.Add(cell1_5);
            row1.Cells.Add(cell1_6);

            row2.Cells.Add(cell2_1);
            row2.Cells.Add(cell2_2);
            row2.Cells.Add(cell2_3);
            row2.Cells.Add(cell2_4);
            row2.Cells.Add(cell2_5);
            table.Rows.Add(row1);
            table.Rows.Add(row2);
            ShoppingCart.Controls.Add(table);


            //Add total of current purchased item to subtotal
            //Math.Round((subTotal += (cart.Amount * pri)), 2);
            subTotal += (cart.Amount * pri);
        }

        //Add selected objects to Session
        //Session[User.Identity.GetUserId()] = carts;
    }