对于我所掌握的结构造成的任何不便表示歉心。
我有一个存储字符串数据的数组,然后显示在列表框中 我也有数组保存成本然后乘以数字上下值 该按钮当前显示基于复选框的结果,该复选框是字符串数据 然后将成本乘以列表框中显示的数字上下值。
我希望能够选择一个表编号,并且当前显示的表编号来自字符串数组中的数据,该数据包含食品类型和成本。 当用户循环显示表号时,数据在列表视图中更新
所以可以查看表1 - 25的订单。
这是类
的代码public class MyMenu
{
public string[] pizza = { "Cheese and Ham", "Ham and Pineapple", "Vegetarian", "MeatFeast", "Seafood" };
public decimal[] price = { 3.50M, 4.20M, 5.20M, 5.80M, 5.60M };
public string GetMenuItem(int select)
{
string choice = pizza[select];
return choice;
}
public decimal GetMenuCost(int select)
{
decimal cost = price[select];
return cost;
}
}
这是表单代码
public partial class Form1 : Form
{
MyMenu MenuMaker = new MyMenu();
public Form1()
{
InitializeComponent();
}
string choice;
decimal cost;
decimal totalCost;
private void button1_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
totalCost = 0;
choice = "";
if (numericUpDown1.Value > 0)
{
if (checkBox1.Checked)
{
cost = MenuMaker.GetMenuCost(0);
choice = MenuMaker.GetMenuItem(0);
totalCost += cost * numericUpDown1.Value;
listBox1.Items.Add(choice + " Qty x " + numericUpDown1.Value + "\n" + " Cost = " + cost * numericUpDown1.Value);
}
}
else
{
if (checkBox1.Checked)
{
MessageBox.Show("Please enter Quantity for Cheese and tomato");
}
}
//NumericUpDown2 is Ham and Pinapple
if (numericUpDown2.Value > 0)
{
if (checkBox2.Checked)
{
cost = MenuMaker.GetMenuCost(1);
choice = MenuMaker.GetMenuItem(1);
totalCost += cost * numericUpDown2.Value;
listBox1.Items.Add(choice + "Qty x " + numericUpDown2.Value + "\n" + " Cost = " + cost * numericUpDown2.Value);
}
}
else
{
if (checkBox2.Checked)
{
MessageBox.Show("Please Enter Quantity for Ham and Pineaplle");
}
}
if (numericUpDown3.Value > 0)
{
if (chckBxVegetarian.Checked)
{
cost = MenuMaker.GetMenuCost(2);
choice = MenuMaker.GetMenuItem(2);
totalCost += cost * numericUpDown3.Value;
listBox1.Items.Add(choice + " Qty x " + numericUpDown3.Value + " Cost = " + cost * numericUpDown3.Value);
}
}
else
{
if (chckBxVegetarian.Checked)
{
MessageBox.Show("Please enter Quantity for Vegetarian");
}
}
if (numericUpDown4.Value > 0)
{
if (chkBxMeatFeast.Checked)
{
cost = MenuMaker.GetMenuCost(3);
choice = MenuMaker.GetMenuItem(3);
totalCost += cost * numericUpDown4.Value;
listBox1.Items.Add(choice + "Qty x " + numericUpDown4.Value + "Cost = " + cost * numericUpDown4.Value);
}
}
else
{
if (chkBxMeatFeast.Checked)
{
MessageBox.Show("Please enter Quantity for MeatFeast");
}
}
if (numericUpDown5.Value > 0)
{
if (chkBxSeafood.Checked)
{
cost = MenuMaker.GetMenuCost(4);
choice = MenuMaker.GetMenuItem(4);
totalCost += cost * numericUpDown5.Value;
listBox1.Items.Add(choice + "Qty x " + numericUpDown5.Value + "Cost = " + cost * numericUpDown5.Value);
}
}
else
{
if (chkBxSeafood.Checked)
{
MessageBox.Show("Please enter Quantity for Seafood");
}
}
if (totalCost > 0)
{
listBox1.Items.Add("The total Cost is " + totalCost);
}
}