我有这个Windows应用程序咖啡馆,允许用户进行选择,然后显示所选项目的成本,小计,税收,总数,当天进行的交易数量,我需要它来显示总销售额税收也是如此。我认为计算这与计算交易数量的方式类似,但我还没弄清楚。有任何想法吗?
public partial class Form1 : Form
{
int clicks = 0;
double totalSalesTaxCollected = 0;
public Form1()
{
InitializeComponent();
InitializeControls();
}
private void button1_Click(object sender, EventArgs e)
{
clicks++;
displayBill();
}
private void displayBill()
{
// int[] listArray = listBox1.getSelectedIndices();
// SelectedIndexCollection listArray = listBox1.SelectedIndices;
double localTax = 0.01;
double stateTax = 0.06;
double tax;
double subTotal = 0;
double total;
//Set the text area to non-edit mode and start
//with an empty string.
textBox1.ReadOnly = true;
textBox1.Text = "";
textBox1.AppendText(" C# KIOSK A LA CARTE\n\n");
textBox1.AppendText("--------------- Welcome ----------------\n\n");
//Calculate the cost of the items ordered.
for (int index = 0; index < listBox1.SelectedIndices.Count; index++)
{
subTotal = subTotal + yourChoicesPrices[listBox1.SelectedIndices[index]];
}
tax = (localTax + stateTax) * subTotal;
total = subTotal + tax;
//Display the costs.
for (int index = 0; index < listBox1.SelectedIndices.Count; index++)
{
textBox1.AppendText(yourChoicesItems[listBox1.SelectedIndices[index]] +"\n");
}
textBox1.AppendText("\n");
textBox1.AppendText("SUB TOTAL\t\t" + String.Format("{0:C}", subTotal) + "\n");
textBox1.AppendText("TAX \t\t"+ String.Format("{0:C}" , tax) + "\n");
textBox1.AppendText("TOTAL \t\t"+ String.Format("{0:C}" , total) + "\n\n");
textBox1.AppendText("\n");
textBox1.AppendText("Thank you - Have a Nice Day\n\n");
textBox1.AppendText("\n");
textBox1.AppendText("Total sales: \t\t" + clicks + "\n" );
textBox1.AppendText("Total sales tax collected: \t\t" + totalSalesTaxCollected);
//Reset list array.
listBox1.ClearSelected();
}
答案 0 :(得分:1)
除非我错过了,否则我认为你需要..而且我猜这一行:
tax = (localTax + stateTax) * subTotal;
total = subTotal + tax;
添加:
totalSalesTaxCollected+=total;
答案 1 :(得分:1)
tax = (localTax + stateTax) * subTotal;
total = subTotal + tax;
之后
添加totalSalesTaxCollected += tax;