我正在尝试制作一个表单,用户将在其中输入值来计算披萨餐厅的订单。用户计算一个订单后,可以进行多个订单。因此,我试图将每个订单添加到一个数组中,然后将该数组拉出到另一个类中,以便我可以在另一个表单上查看所有订单的摘要。这是我的第一种形式的代码。其他类无法访问任何数组。你能帮帮我吗?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Collections;
namespace MidTermPizzas
{
public partial class Form1 : Form
{
pizzaOrder aOrder = new pizzaOrder();
public static ArrayList pizzaAmountArray = new ArrayList();
public Form1()
{
InitializeComponent();
}
//click File, Exit
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("Enjoy your pizza!");
this.Close();
}
//click View, Summary of Orders Placed
private void summaryOfOrdersToolStripMenuItem_Click(object sender, EventArgs e)
{
SummaryOfOrdersPlaced myForm = new SummaryOfOrdersPlaced();
myForm.Show();
}
//form load
private void Form1_Load(object sender, EventArgs e)
{
}
//text in box to the right of "Amount of Pizzas"
private void textBox1_TextChanged(object sender, EventArgs e)
{
//ArrayList pizzaAmountArray = new ArrayList();
int v;
if (int.TryParse(textBox1.Text, out v))
{
aOrder.numberOfPizzas = v;
pizzaAmountArray.Add(v); //add to array list
}
else aOrder.numberOfPizzas = 0;
}
//text in box to the right of "Amount of Cokes"
private void textBox2_TextChanged(object sender, EventArgs e)
{
ArrayList cokeAmountArray = new ArrayList();
int v;
if(int.TryParse(textBox2.Text, out v))
{
aOrder.numberOfCokes = v;
cokeAmountArray.Add(v); //add to array list
}
else aOrder.numberOfCokes = 0;
}
//click Calculate Amount Due
private void calculateAmountDue_Click(object sender, EventArgs e)
{
textBox3.Text = Convert.ToString(aOrder.GetAmountDue());
}
//click Calculate Sales Tax
private void button2_Click(object sender, EventArgs e)
{
textBox4.Text = Convert.ToString(aOrder.TaxDue());
}
//text in box to the right of "Amount Paid"
private void textBox5_TextChanged_1(object sender, EventArgs e)
{
ArrayList totalAmountPaidArray = new ArrayList();
double v;
if (double.TryParse(textBox5.Text, out v))
{
aOrder.getAmountPaid = v;
totalAmountPaidArray.Add(v); //add to array list
}
else aOrder.getAmountPaid = 0;
}
//click Calculate Change Due button
private void calculateChangeDue_Click(object sender, EventArgs e)
{
textBox6.Text = Convert.ToString(aOrder.GetChangeDue());
}
//reset button
private void button1_Click_1(object sender, EventArgs e)
{
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox5.Clear();
textBox6.Clear();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
namespace MidTermPizzas
{
class DailySummary
{
Form1 aForm1Stuff = new Form1();
public int numberOfPizzas
{
get
{
//not sure what to put here
}
set
{
}
}