//Load中的代码
foreach (Control c in panel1.Controls)
{
//button在窗体上
Button btn = c as Button;
if (btn != null)
{
//座位是否已被占用
if (data.ResultValue.FirstOrDefault(p => p.SEAT_ID == btn.AccessibleDescription)?.STATE == "N")
{
btn.BackColor = System.Drawing.Color.Red;
btn.Enabled = false;
//判断位置方向
switch (btn.AccessibleName)
{
case "上":
btn.Image = Properties.Resources.座位__已占用__上;
break;
case "下":
btn.Image = Properties.Resources.座位__已占用__下;
break;
case "左":
btn.Image = Properties.Resources.座位__已占用__左;
break;
case "右":
btn.Image = Properties.Resources.座位__已占用__右;
break;
default:
break;
}
}
else if (data.ResultValue.FirstOrDefault(p => p.SEAT_ID == btn.AccessibleDescription)?.STATE == "Y")
{
btn.Enabled = true;
btn.Click += new System.EventHandler(this.ZW_Click);
//判断位置方向
switch (btn.AccessibleName)
{
case "上":
btn.Image = Properties.Resources.座位__未占用__上;
break;
case "下":
btn.Image = Properties.Resources.座位__未占用__下;
break;
case "左":
btn.Image = Properties.Resources.座位__未占用__左;
break;
case "右":
btn.Image = Properties.Resources.座位__未占用__右;
break;
default:
break;
}
}
}
}
效果图:
按钮无法点击