Hi, I am using C# Windows Forms in visual studio with different classes performing different functions in my program.
I have a "Program" main class with the following information:
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
and a Screen class with the following information
class Screen
{
public List<Show> shows { get; private set; }
public int ScreenNumber { get; private set; }
public Screen(int screenNumber, params Show[] schedule)
{
this.ScreenNumber = screenNumber;
this.shows = schedule.ToList<Show>();
}
}
and a Seat class with the following information
public class Seat
{
private string name;
public bool IsAvailable { get; set; }
public decimal Price { get; private set; }
public int Number { get; private set; }
public Seat(bool isAvailable, int number)
{
this.IsAvailable = isAvailable;
this.name = String.Format("Seat {0}",number);
this.Price = 7.50m;
this.Number = number;
}
public override string ToString()
{
return this.name;
}
}
and finally a Show class with the following information
public class Show
{
private List<Seat> seats = new List<Seat>();
public string Title { get; private set; }
public string Time { get; private set; }
public int ScreenNumber { get; private set; }
public List<Seat> Seats { get { return this.seats; } }
public Show(string title, DateTime time, int screenNumber, int numberOfSeats)
{
this.Title = title;
this.Time = time.ToShortTimeString();
this.ScreenNumber = screenNumber;
this.initSeats(numberOfSeats);
}
private void initSeats(int numberOfSeats)
{
for (int i = 0; i < numberOfSeats; i++) this.seats.Add(new Seat(true, i + 1));
}
}`
these all feed into two different winForms to create a booking system for shows.
therefore i need to collate the data given in program and output it into a txt file.
any help will be much appreciated
NOTE:
the code for FORM1 which allows the user to select which show they want is:
namespace CindysSeats
{
public partial class Form1 : Form
{
private Cinema cinema = new Cinema();
//booked show could be added to booking object when you create it so that it is easily writable to the external file
private Show selectedShow;
public Form1()
{
InitializeComponent();
this.showList_dg.DataSource = this.cinema.GetShowList();
}
private void showList_dg_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
Show selectedShow = this.selectedShow = this.cinema.GetShowList()[e.RowIndex];
this.showTitle_lbl.Text = selectedShow.Title;
this.showTime_lbl.Text = selectedShow.Time;
this.showScreen_lbl.Text = selectedShow.ScreenNumber.ToString();
}
private void confirmShow_btn_Click(object sender, EventArgs e)
{
if (this.selectedShow == null) return;
Form2 seats = new Form2(this.selectedShow);
seats.Show();
}
And the code for FORM2 which is where the user selects their seats they want is:
namespace CindysSeats
{
public partial class Form2 : Form
{
//booked seats could be added to booking object when you create it so that it is easily writable to the external file
private List<Seat> bookedSeats = new List<Seat>();
private Show selectedShow;
public Form2(Show selectedShow)
{
InitializeComponent();
this.selectedShow = selectedShow;
this.showSeats_dg.DataSource = this.selectedShow.Seats;
}
private void showSeats_dg_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
Seat selectedSeat = this.selectedShow.Seats[e.RowIndex];
if(this.bookedSeats.Contains(selectedSeat)) return;
if(!selectedSeat.IsAvailable) return;
this.bookedSeats.Add(selectedSeat);
this.bookedSeats_lv.Items.Add(selectedSeat.ToString() + " " + selectedSeat.Price.ToString()+"\n");
this.bookedSeats_lv.Invalidate();
}
private void bookSeats_btn_Click(object sender, EventArgs e)
{
}
}
thank you for helping