作者: | 来源:互联网 | 2023-08-14 02:01
我正在使用c#在Windows窗体中为餐厅制作菜单订购系统,并且希望能够在列表视图中对同一项目进行多次输入。例如,如果人们订购3杯可乐,我希望能够选择三个相同的商品并将其添加到我的订单中。
查看在线注释
class OrderItem // declare a class for item itself
{
int Id {get;set;}
string Description {get;set;}
int Price {get;set;}
string Unit {get;set;} // oz? liter?
public override string ToString() // This will show in the list
{
return $"Description ({Price}/{Unit})";
}
}
class App : Form
{
private OnAddToOrderClick(object sender,EventArgs e)
{
// you have to define RetrieveFoodItem,where do you get available foods?
OrderItem item = RetrieveFoodItem(); // I don't know where you get food from
lstOrderItems.Items.Add();
}
// this is just to show where to go further with it
private OnOrderPrintoutClick(object sender,EventArgs e)
{
// you can use LINQ here to group your items and get the sum per item
var totals = (from itm in lstOrderItems.Items)
.GroupBy(itm => itm.Id)
.Select(g => ......);
}
}