I want to change with a timer helps the color of buttons contains in a flowLayoutPanel1. With my query code the color change right, but when the condition of query turn to false, my button don't change his color (when I create it I set the color to green).
This is my code:
private void timer1_Tick(object sender, EventArgs e)
{
int t = 0;
int st = 0;
try
{
using (SqlConnection cn =new SqlConnection(VisualizzaOrdini.Form1.cnstr))
{
string strSql = "SELECT tavolo,stampa FROM Ordini";
SqlCommand cmd = new SqlCommand(strSql, cn);
cn.Open();
using (SqlDataReader dr = cmd.ExecuteReader())
{
while (dr.Read())
{
t = (int)dr["tavolo"];
st = (int)dr["stampa"];
foreach (Control c in flowLayoutPanel1.Controls)
{
if (st == 0)
{
if (c.Name == Convert.ToString(t))
{
c.BackColor = Color.Red;
}
}
else if (c.Name == Convert.ToString(t))
{
c.BackColor = Color.Green;
}
}
}
}
cn.Close();
}
}
}
catch (Exception)
{
}
I need to implement this in a restaurant program. I want to color table red if it's busy and green if it's free.
This is an image:
https://docs.google.com/file/d/0B-nMmszaCz8EVE9JdjlISHg1aDA/edit?usp=sharing