如何在保留用户输入数据的同时清除 C# 中的表单?
我正在编写一个定制饮料的程序。该程序允许用户选择尺寸、口味、配料和数量。然后,用户按下“添加饮料到订单”按钮,然后弹出一条消息“您想自定义另一种饮料以添加到您的订单中吗?是,否”我的问题是如何保存第一个自定义饮料以在订单中打印收据和第二杯饮料一起吗?清除表格时数据丢失,正确吗?
I am writing a program for customizing drinks. The program lets the user select a size, flavor, topping, and quantity. The user then presses the button "Add drink to order" and a message pops up "Do you want to customize another drink to add to your order? Yes, No" My question is how do you save the first customized drink to print in the receipt along with the second drink? When clearing the form the data is lost correct?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您的程序必须保存数据。这可以放入数据库或集合中。我认为您还没有使用数据库,因此集合是最好的方法。
创建一个类,该类具有每种类型值的属性。然后列出这些内容并填充值。
Your program has to save the data. This can be into a database, or into a collection. I don't think you are using a database yet, so a collection is the best way.
Create a class that has a property for each type of value. Then make a list of those, populated with values.
首先构建一个表示订单的对象
注意:我使用模糊的
Object
类型,因为我不知道您如何表示这些字段值然后将一个列表添加到您的 然后,当他们单击“添加”
时,填充该对象并将其添加到订单列表中。
然后,您可以清除表格(如果需要)并准备好重新进行。
他们下订单后,您现在就有了一个列表 (
Orders
),您可以将其引用为“购物车”。First build an object that represents the order
Note: I use the vague
Object
type because I don't know how you're representing those field valuesThen add a list to your form that retains the past/future "orders"
Then, when they click add, populate the object and add it to the list of orders.
Then, you can clear the forms (if desired) and be ready to do it all over again.
Once they're done placing orders, you now have a list (
Orders
) you can reference as a "shopping cart".也许你可以把数据放在某个地方?就像一个数组?
Perhaps you could put the data somewhere? Like an array?
您可以使用数据绑定来实现此目的,它很简单并且可以保存多个数据。您可以在此处阅读更多相关信息
You can use Data Binding for this, it's easy and saves multiple data. You can read more about it here