本文介绍了如何在组合框中设置项目以返回计算餐馆账单的价格值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好!我必须创建一个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());

      }

推荐答案

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());

      }


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 =



这篇关于如何在组合框中设置项目以返回计算餐馆账单的价格值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 07:42