コード例 #1
0
    protected void btnRemoveItend_Click(object sender, EventArgs e)
    {
        String orderedItems = checkBoxValues.Value;

        char[]   deliminator = { ',' };
        String[] items       = orderedItems.Split(deliminator);

        foreach (String item in items)
        {
            if (item != "")
            {
                SessionVariableManager.removeItemFromCart(Convert.ToInt32(item));
            }

            Server.Transfer("/My-Cart.aspx");
        }
    }
コード例 #2
0
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        Boolean proceed = true;

        String[]             items          = SessionVariableManager.getOrderItems();
        List <InventoryItem> orderInventory = new List <InventoryItem>();
        List <TextBox>       textboxes      = new List <TextBox>();

        OrderManager orderManager = new OrderManager();

        foreach (String item in items)
        {
            if (item != "")
            {
                orderInventory.Add(InventoryManager.getSingleItem(Convert.ToInt32(item)));
            }
        }
        foreach (RepeaterItem rptItem in rptOrderItem.Items)
        {
            textboxes.Add((TextBox)rptItem.FindControl("txtCount"));
        }

        if (orderInventory.Count == textboxes.Count)
        {
            for (int i = 0; i < orderInventory.Count; i++)
            {
                bool success = orderManager.addItemToOrder(orderInventory[i], Convert.ToInt32(textboxes[i].Text));
                if (!success)
                {
                    lblMessage.Text = "You cannot order more than we have in inventory. Please try again! (" + orderInventory[i].getProductName() + ")";
                    proceed         = false;
                    return;
                }
            }
        }
        PaymentInformation userCreditCard = PaymentManager.getUserCreditCard(Convert.ToInt32(ddlPaymentMethod.SelectedValue));

        orderManager.addPaymentInfo(userCreditCard);
        orderManager.setIsCollectOnDelivery(cbCollectOnDelivery.Checked);
        orderManager.setPaymentAmount(Convert.ToDouble(txtPaymentAmount.Text));
        if (proceed)
        {
            int orderNumber = orderManager.submitOrder();
            if (orderNumber > 0)
            {
                lblMessage.Text                        = "Thank you for your order. Your order number is " + orderNumber + ". Keep this number for reference.";
                btnCalculateOrder.Enabled              = false;
                btnSubmit.Enabled                      = false;
                paymentAmountValidator.Enabled         = false;
                paymentAmountRequiredValidator.Enabled = false;

                foreach (InventoryItem item in orderInventory)
                {
                    SessionVariableManager.removeItemFromCart(item.getInventoryId());
                }
            }
            else
            {
                lblMessage.Text = "Sorry, there was an error with your order. Please review your selection and try again.";
            }
        }
    }