Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have 40 button which is for seat selection on my Windows Application project.

Anyone can pick up one of these button for select a seat in a bus.

These seat button will be disable if any passenger select the seat button before on same Departing date,same time, same Leaving place and going place.

What I have tried:

I can't solve this problem after trying many times.
So please help me to solve this problem.
Posted
Updated 3-Apr-16 1:43am
Comments
F-ES Sitecore 3-Apr-16 6:30am    
What exactly are you having a problem doing? Identifying when a seat is taken? Identifying which button to disable? Disabling the button itself? There are so many factors at play you'll need to narrow it down.
Dalim Mohammad 3-Apr-16 7:01am    
How can I retrieve these button which are saved on my database for checking the condition?
Suppose button A1,A2,A3,A4 are taken for a particular date and particular time then these button should disable.
F-ES Sitecore 3-Apr-16 8:00am    
How can anyone answer that when you haven't even said what database you are using? Or what database access technology? Or what the schema of your tables are? We only know what you've posted.
Dalim Mohammad 4-Apr-16 3:39am    
public void check()
{
SqlConnection con = new SqlConnection("Data Source=DESKTOP-NGRLFB4\\SQLEXPRESS;Initial Catalog=FinalProject;Integrated Security=True");
SqlDataAdapter SDA = new SqlDataAdapter("SELECT Count(*) FROM CustomerInformation where LeavingFrom = '" + txtLeave.Text + "' and GoingTo ='" + txtGo.Text + "'and DepartingDate ='" + dateTimePicker1.Value + "'AND Time ='" + txtDeptTime.Text + "'AND SeatNo ='" + btnA1.Text + "'OR SeatNo ='" + btnA2.Text + "'OR SeatNo ='" + btnA3.Text + "'OR SeatNo ='" + btnA4.Text + '", con);
DataTable dt = new DataTable();
SDA.Fill(dt);

if (dt.Rows[0][0].ToString() == "1")
{
if(btnA1.Text == "1")
{
btnA1.BackColor = Color.Black;
btnA1.Enabled = false;
}
else if (btnA2.Text == "1")
{
btnA2.BackColor = Color.Black;
btnA2.Enabled = false;
}
else if (btnA3.Text == "1")
{
btnA3.BackColor = Color.Black;
btnA3.Enabled = false;
}
else if (btnA4.Text == "1")
{
btnA4.BackColor = Color.Black;
btnA4.Enabled = false;
}
}

1 solution

There are a whole load of ways you could do this.
You could store all the buttons in an array, then store the "taken" indexes in the DB. When you read them back, set the Button.Enabled property to false.
You could set the Seat Number as the Text of the button, and store that. (This helps if your seat identification is row number, column letter: 7C, 3D and so forth).
You could the seat number info in the Button.Tag property and look for that when you retrieve your info.
Or if you were desperate, you could use the Button Name property and loop for that.

It really depends on you and how you like to do things.

Me? I probably wouldn't use Buttons, as 40 of them is a lot to manage! Instead, I'd probably use an image of the seat layout for the bus and detect the seat by the X and Y location clicked on. I'd then convert that to a seat index, and store that. But that's a bit more work - even if it looks a lot better in the end!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900