{
public partial class BookNow : Form
{
private const int CP_NOCLOSE_BUTTON = 0x200;
private string title;
private string ad; //Adult
private string ch; //Child
private string sd; //StartDate
private string rd; //ReturnDate
private string ins; //Insurance
private string extb; //Extra Baggage
private int people;
private double total = 0;
Cart c = new Cart();
ArrayList arr = new ArrayList(30);
public BookNow()
{
InitializeComponent();
adult.SelectedIndex = 1;
child.SelectedIndex = 0;
insuranceNo.Checked = true;
tenKG.Checked = true;
}
private void Next_Click(object sender, EventArgs e)
{
if (tour.Text == "Choose A Tour")
{
MessageBox.Show("Please select a tour of your choice", "Choice of Tour Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
tour.Focus();
}
else if (adult.Text == "0" && child.Text == "0")
{
MessageBox.Show("Please select number of Travellers", "Number of Travellers Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
adult.Focus();
}
else if (startDate.Text == returnDate.Text)
{
MessageBox.Show("Start Date and Return Date Cannot be the Same. Please Edit Dates to Continue", "Dates Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
returnDate.Focus();
}
else
{
if (tour.Text == "TSIN - Singapore's Discovery")
total += 1299.00;
else if (tour.Text == "TSEO - Seoul's Highlights")
total += 1899.00;
else if(tour.Text == "TTAI - Taiwan Spotlight")
total += 1000.00;
title = tour.Text;
ad = adult.Text;
ch = child.Text ;
sd = startDate.Text;
rd = returnDate.Text;
if (insuranceYes.Checked)
{
ins += insuranceYes.Text;
total += 29.99;
}
else
{
ins = insuranceNo.Text;
}
if (tenKG.Checked)
extb = tenKG.Text;
else if (twentyKG.Checked)
{
extb = twentyKG.Text;
total += 50.00;
}
else
{
extb = thirtyKG.Text;
total += 80.00;
}
people = int.Parse(ad) + int.Parse(ch);
total = total * people;
cartNow(c);
total = 0;
var result = MessageBox.Show("Added To Cart, Continue To Your Cart?","Cart Updated", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (result == DialogResult.Yes)
{
c.add(c);
Hotel h = new Hotel();
h.Show();
}
}
}
private void Reset_Click(object sender, EventArgs e)
{
}
private void Cart_Click(object sender, EventArgs e)
{
c.Show();
}
此方法是添加到我的列表视图中,以便我可以显示并尝试使用数组但仍无法执行此操作
public void cartNow (Cart instance)
{
ListViewItem lvl = new ListViewItem(arr[0].ToString());
lvl.SubItems.Add(arr[1].ToString());
lvl.SubItems.Add(ch);
lvl.SubItems.Add(sd);
lvl.SubItems.Add(rd);
lvl.SubItems.Add(ins);
lvl.SubItems.Add(extb);
lvl.SubItems.Add(total.ToString("c2"));
instance.listView1.Items.Add(lvl);
}
private void Close_Click(object sender, EventArgs e)
{
var confirmResult = MessageBox.Show("Closing the booking System will result in clearing the Cart.","Are You sure you want to continue?",
MessageBoxButtons.YesNo);
if (confirmResult == DialogResult.Yes)
{
this.WindowState = FormWindowState.Minimized;
this.ShowInTaskbar = false;
}
}
public void showCart()
{
c.Show();
}
protected override CreateParams CreateParams
{
get
{
CreateParams myCp = base.CreateParams;
myCp.ClassStyle = myCp.ClassStyle | CP_NOCLOSE_BUTTON;
return myCp;
}
}
}
}
我可以打开我的购物车并显示我的列表视图中的项目,但是当我关闭购物车并想要从另一个表单运行时,它不起作用,因为信息变空,例如(具有成人数量的可变广告)变为null,如果我尝试从另一个类
运行cartNow()方法,将显示第n个