我正在使用Visual Studio使用C#构建影院预订系统。我为该程序设计的主要代码如下所示,没有我创建的用于保存电影,屏幕,客户和显示数据的类。
namespace Glosflix
{
public partial class NewBooking : Form
{
public List<Film> filmList = new List<Film>();
public List<Showing> showingList = new List<Showing>();
public NewBooking()
{
InitializeComponent();
filmList.Add(new Film("Ida", 90, "15", "A young novitiate discovers the fate that befell her Jewish parents during the Nazi occupation of Poland."));
filmList.Add(new Film("Leviathan", 147, "15", "Modern retelling of Job, set in the Barents Sea."));
filmList.Add(new Film("Grand Budapest Hotel", 100, "15", " A hotel concierge inherits a fortune from an aristocrat, and the wrath of her disappointed heirs."));
Screen screenA = new Screen(250, "1");
Screen screenB = new Screen(150, "2");
Screen screenC = new Screen(120, "3");
showingList.Add(new Showing(512, screenA, filmList[0], "9:00"));
showingList.Add(new Showing(612, screenA, filmList[0], "15:00"));
showingList.Add(new Showing(712, screenB, filmList[1], "10:00"));
showingList.Add(new Showing(812, screenB, filmList[1], "16:00"));
showingList.Add(new Showing(912, screenC, filmList[2], "12:00"));
showingList.Add(new Showing(412, screenC, filmList[2], "21:00"));
Customer customerA = new Customer(5238, "Thomas Stearns");
cmbTickets.Items.Add(1);
cmbTickets.Items.Add(2);
cmbTickets.Items.Add(3);
cmbTickets.Items.Add(4);
cmbTickets.Items.Add(5);
cmbTickets.Items.Add(6);
cmbTickets.Items.Add(7);
cmbTickets.Items.Add(8);
cmbTickets.Items.Add(9);
cmbTickets.Items.Add(10);
}
private void NewBooking_Load(object sender, EventArgs e)
{
foreach (Film i in filmList)
cmbFilm.Items.Add(i.getTitle());
}
private void cmbFilm_SelectedIndexChanged(object sender, EventArgs e)
{
cmbShowing.Items.Clear();
String filmTitle = cmbFilm.SelectedItem.ToString();
foreach (Showing i in showingList)
{
if (filmTitle.Equals(i.getFilm().getTitle()))
{
cmbShowing.Items.Add(i.getTime());
}
}
cmbShowing.Enabled = true;
}
private void btnBook_Click(object sender, EventArgs e)
{
if (cmbShowing.SelectedIndex == -1)
{
MessageBox.Show("Please select a film and showing.");
}
else if (cmbTickets.SelectedIndex == -1)
{
MessageBox.Show("Please select the number of tickets required.");
}
}
}
}
在代码中,为了进行预订,用户与组合框进行交互,其中包含所有可用电影的标题。这将在单独的组合框中加载与胶片相关的所有显示时间。最终的组合框保存值1到10,用户可在其中选择预订所需的门票数量。
我希望当用户点击节目界面上的书籍按钮时,根据用户在界面中输入的信息,所有关于节目的信息都显示在列表框中。组合框。我也喜欢根据用户选择的门票数量计算预订总费用的程序,并在组合框中显示。
我认为实现这一目标的最佳方法是创建一个预订类,其中包含的方法会将输入的座位数乘以电影票的成本,从而产生整体预订成本。我该怎么做?