The Way to Programming
The Way to Programming
C# Form Help Needed – Hotel Booking Form
I Have two forms. These forms are for a theoretical hotel
Form 1 – Booking Form
This Is where the user inputs the date of arrival nights how many rooms and how many people are going.
Form 2 – Personal Details
Name of booker
Address
Town
Post code
email
telephone
ect
Form 3 – The Receipt – The Printout screen
All this information is outputted to.
My job is to collect all the information from form 1 and 2 and have it print out in the fields in form 3
How do i do this please?
This is a group assignment and i was ill for a while. This work is due Monday and I beg for your help!
I got it. Thanks
First off, we need a way to share data between these forms. One way to do this is to create a shared class
that will hold all the booking and personal details.
[dm_code_snippet background="yes" background-mobile="yes" slim="no" line-numbers="no" bg-color="#abb8c3" theme="dark" language="php" wrapped="no" height="" copy-text="Copy Code" copy-confirmed="Copied"]
public class BookingDetails { public DateTime ArrivalDate { get; set; } public int Nights { get; set; } public int Rooms { get; set; } public int People { get; set; } public string BookerName { get; set; } public string Address { get; set; } public string Town { get; set; } public string PostCode { get; set; } public string Email { get; set; } public string Telephone { get; set; } }
[/dm_code_snippet]
In both forms, you’ll collect the data and populate this shared BookingDetails
object.
For example, in Form 1:
[dm_code_snippet background="yes" background-mobile="yes" slim="no" line-numbers="no" bg-color="#abb8c3" theme="dark" language="php" wrapped="no" height="" copy-text="Copy Code" copy-confirmed="Copied"]
public partial class Form1 : Form { public BookingDetails bookingDetails = new BookingDetails(); private void btnNext_Click(object sender, EventArgs e) { bookingDetails.ArrivalDate = dateTimePicker1.Value; bookingDetails.Nights = (int)nudNights.Value; bookingDetails.Rooms = (int)nudRooms.Value; bookingDetails.People = (int)nudPeople.Value; // Open Form 2 and pass the bookingDetails object Form2 form2 = new Form2(bookingDetails); form2.Show(); } }
[/dm_code_snippet]
And similarly, in Form 2:
[dm_code_snippet background="yes" background-mobile="yes" slim="no" line-numbers="no" bg-color="#abb8c3" theme="dark" language="php" wrapped="no" height="" copy-text="Copy Code" copy-confirmed="Copied"]
public partial class Form2 : Form { public BookingDetails bookingDetails; public Form2(BookingDetails details) { InitializeComponent(); bookingDetails = details; } private void btnGenerateReceipt_Click(object sender, EventArgs e) { bookingDetails.BookerName = txtName.Text; bookingDetails.Address = txtAddress.Text; // ... (similarly populate other fields) // Open Form 3 and pass the bookingDetails object Form3 form3 = new Form3(bookingDetails); form3.Show(); } }
[/dm_code_snippet]
Finally, in Form 3, you’ll display all these details. You’ll populate the fields based on the BookingDetails
object passed to it.
[dm_code_snippet background="yes" background-mobile="yes" slim="no" line-numbers="no" bg-color="#abb8c3" theme="dark" language="php" wrapped="no" height="" copy-text="Copy Code" copy-confirmed="Copied"]
public partial class Form3 : Form { public Form3(BookingDetails details) { InitializeComponent(); lblArrivalDate.Text = details.ArrivalDate.ToString(); lblNights.Text = details.Nights.ToString(); lblRooms.Text = details.Rooms.ToString(); lblPeople.Text = details.People.ToString(); lblBookerName.Text = details.BookerName; lblAddress.Text = details.Address; // ... (similarly populate other fields) } }
[/dm_code_snippet]
This project involves some intricate data sharing between multiple forms, but once you break it down, it’s not too bad. The key is to have a central data structure (BookingDetails
) and make sure each form updates it and passes it along.
Alright, I hope this crash course helps you catch up on your group assignment. Just take it one step at a time, and you’ll have it knocked out before you know it. Good luck, and may the code be with you! ??
Hi, You design the forms as per the instructions provided to you by the team leader. After finishing the UI, get the project files from rest of your team and add it into your project in which you’ve designed the UI for third form. Then finish the coding part which is of only displaying appropriate data along with some messages.
Sign in to your account