protected void btnSubmit_Click(object sender, EventArgs e)
    {
        Dictionary<String, PurchaseOrder> purchaseOrders = new Dictionary<String, PurchaseOrder>();

        foreach (RepeaterItem rptItem in OrderItems.Items)
        {

            TextBox orderItemTextBox = (TextBox)rptItem.FindControl("txtAmountToOrder");
            Label itemName = (Label)rptItem.FindControl("lblItemName");
            Label itemPrice = (Label)rptItem.FindControl("lblItemCost");

            PurchaseOrderItem orderItem = new PurchaseOrderItem();
            orderItem.itemName = itemName.Text;
            orderItem.itemPrice = Double.Parse(itemPrice.Text, NumberStyles.Currency);
            orderItem.orderAmount = Convert.ToInt32(orderItemTextBox.Text);

            Label supplier = (Label)rptItem.FindControl("lblSupplier");

          if (!purchaseOrders.ContainsKey(supplier.Text))
          {
              PurchaseOrder newOrder = new PurchaseOrder();

              newOrder.manufacturer.name = supplier.Text;
              newOrder.addItemToOrder(orderItem);

              purchaseOrders[newOrder.manufacturer.name] = newOrder;
          }
          else
          {
              purchaseOrders[supplier.Text].addItemToOrder(orderItem);
          }
          }

        Boolean success = PurchaseManager.processOrder(purchaseOrders.Values.ToList());
        if (success)
        {
            lblMsg.Text = "Purchase orders successfully created.";
        }
        else
        {
            lblMsg.Text = "Sorry, there was an error. Please try again.";
        }
    }
 public void addItemToOrder(PurchaseOrderItem item)
 {
     items.Add(item);
 }
Exemple #3
0
 public void addItemToOrder(PurchaseOrderItem item)
 {
     items.Add(item);
 }