如何在组合框中设置项目以返回计算餐馆账单的价格值?
问题描述:
您好!我必须创建一个Windows From,这样用户就可以从其中一个ComboBoxes(Beverages,Appetizers,Main Course,Dessert)中选择一个项目添加到餐馆桌面帐单。在组合框中选择每个项目时,将该项目的价格添加到帐单中。用户可以单击清除帐单按钮将小计:,税:和总计:字段恢复为0.00美元。我一直坚持如何从组合框中返回每个项目及其价格进行计算。
我的尝试:
Hello! I have to create a Windows From so a user can choose from one of these ComboBoxes (Beverages, Appetizers, Main Course, Dessert) to add an item to a restaurant table bill. As each item is selected in the ComboBoxes, add the price of that item to the bill. The user can click the Clear Bill Button to restore the Subtotal:, Tax: and Total: fields to $0.00.. I'm stuck on how to return each item and its price from the comboBox for calculation.
What I have tried:
public partial class Form1 : Form
{
public struct MenuOrders
{
public static string item;
public static double price;
}
double subtotal = 0;
double tax = .03;
double taxes;
double total = 0;
MenuOrders itemOrder = new MenuOrders();
private void getValue()
{
itemOrder.price = Convert.ToDouble(itemOrder);
outputBox1.Items.Add("Price: " + itemOrder.price);
Bill();
}
private void Bill()
{
subtotal += itemOrder.price;
total += itemOrder.price + (itemOrder.price * tax);
taxes += itemOrder.price * tax;
outputBox1.Items.Add("Subtotal: " + subtotal.ToString("C2"));
outputBox1.Items.Add("Tax: " + taxes.ToString("C2"));
outputBox1.Items.Add("Total: " + total.ToString("C2"));
}
private void changingDropdown(object sender, EventArgs e)
{
if (sender == beverageComboBox)
getValue(beverageComboBox.SelectedItem.ToString());
else if (sender == appetizerComboBox)
getValue(appetizerComboBox.SelectedItem.ToString());
else if (sender == MainecourseComboBox)
getValue(MaincourseComboBox.SelectedItem.ToString());
else getValue(dessertComboBox.SelectedItem.ToString());
}
答
0.00 ..我坚持如何退回每件商品以及来自comboBox的价格进行计算。
我尝试过:
0.00.. I'm stuck on how to return each item and its price from the comboBox for calculation.
What I have tried:
public partial class Form1 : Form
{
public struct MenuOrders
{
public static string item;
public static double price;
}
double subtotal = 0;
double tax = .03;
double taxes;
double total = 0;
MenuOrders itemOrder = new MenuOrders();
private void getValue()
{
itemOrder.price = Convert.ToDouble(itemOrder);
outputBox1.Items.Add("Price: " + itemOrder.price);
Bill();
}
private void Bill()
{
subtotal += itemOrder.price;
total += itemOrder.price + (itemOrder.price * tax);
taxes += itemOrder.price * tax;
outputBox1.Items.Add("Subtotal: " + subtotal.ToString("C2"));
outputBox1.Items.Add("Tax: " + taxes.ToString("C2"));
outputBox1.Items.Add("Total: " + total.ToString("C2"));
}
private void changingDropdown(object sender, EventArgs e)
{
if (sender == beverageComboBox)
getValue(beverageComboBox.SelectedItem.ToString());
else if (sender == appetizerComboBox)
getValue(appetizerComboBox.SelectedItem.ToString());
else if (sender == MainecourseComboBox)
getValue(MaincourseComboBox.SelectedItem.ToString());
else getValue(dessertComboBox.SelectedItem.ToString());
}
这里你去...快速破解...
Here you go... A quick hack...
using System;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;
namespace WFRestaurantBill
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
for (int i = 0; i < 10; i++)
{
lbBeverage.Items.Add(new MenuItem { Name =
Beverage {i},Price =( decimal )(i * 3 。 33 )});
lbAppetizer.Items.Add( new MenuItem {Name =
"Beverage {i}", Price = (decimal)(i * 3.33) }); lbAppetizer.Items.Add(new MenuItem { Name =