3
Answers

Need help on using System.Collections.Generic

James SN

James SN

16y
6.1k
1

Im beginner using LIST. After study the many example, so far i've have below class

public class ShoppingCartItem

{

//TrxNo

private int _trxNo = 0;

public int TrxNo

{

get { return _trxNo; }

set { _trxNo = value; }

}

//Order Date

private string _OrdDate = "";

public string OrdDate

{

get { return _OrdDate; }

private set { _OrdDate = value; }

}

//Product ID

private string _id = "";

public string ID

{

get { return _id; }

private set { _id = value; }

}

//Product Description

private string _Desc = "";

public string Desc

{

get { return _Desc; }

private set { _Desc = value; }

}

//Quantity

private int _quantity = 1;

public int Quantity

{

get { return _quantity; }

set { _quantity = value; }

}

//Price Per Unit

private decimal _unitPrice;

public decimal UnitPrice

{

get { return _unitPrice; }

private set { _unitPrice = value; }

}

private decimal _subTotal;

public decimal SubTotal {

get { return _subTotal; }

private set { _subTotal = value; }

}

public ShoppingCartItem(int trxno,string ordDate, string id, string desc, int quantity, decimal unitPrice, decimal subTotal)

{

this.TrxNo = trxno;//UniqueID

this.OrdDate = ordDate;//Order Date

this.ID = id;//Product ID

this.Desc = desc;//Product Description

this.Quantity = quantity;//Order Quantity

this.UnitPrice = unitPrice;//Price Per Quantity

this.SubTotal = subTotal;//Price Per Quantity

}

}

For insert into the LIST, i've using

order.Add(new ShoppingCartItem(Convert.ToInt32(Request.QueryString["trxNo"]), Request.QueryString["ordDate"],

Request.QueryString["id"], Request.QueryString["desc"], Convert.ToInt32(Request.QueryString["quantity"]),

Convert.ToDecimal(Request.QueryString["priceperquantity"], ,

Convert.ToDecimal(Request.QueryString["subTotal"])));

Session["Order"] = order; // this all value will display using GridView.

Let's say i've current LIST as follow,

TrxNo  | OrdDate  | ID    | Quantity     | PricePerQuantity       | SubTotal

-------------------------------------------------------------------------------------------------

21         | 8/11/08   | 290   | 1                   | 6.7                                | 6.7

** ID is a unique value

My question is

1. If user choose the same item (ID=290), quantity=2 to ADD TO CART. How to update the current LIST to become as follow

TrxNo  | OrdDate  | ID    | Quantity     | PricePerQuantity       | SubTotal

-------------------------------------------------------------------------------------------------

21         | 8/11/08   | 290   | 3                   | 6.7                                | 20.1

Im really stuck to update the LIST.


Answers (3)