我正在开发酒店软件,我希望在运行时显示带有标签的WinForm上的所有房间。房间状态将从数据库中拉出,标签的颜色将根据房间状态而变化。请问如何创建这个。
下面是我想要实现的表单布局的示例。
编辑:
private void Charts(GroupBox group, Label label, string roomNo)
{
var room = RoomServices.CheckRoom(roomNo);
MessageBox.Show(Convert.ToString(room.Id));
try
{
if (room.RoomStatusId == 4)
{
group.BackColor = Color.Red;
group.ForeColor = Color.White;
group.Text = roomNo;
var c = RoomServices.FindCheckIn(room.Id);
string name = c.Guest.FirstName + " " + c.Guest.Surname;
label.Text = name;
}
else if (room.RoomStatusId == 3)
{
group.BackColor = Color.Orange;
group.ForeColor = Color.White;
group.Text = roomNo;
label.Text = "OUT of Order";
}
else if (room.RoomStatusId == 2)
{
group.BackColor = Color.Brown;
group.ForeColor = Color.White;
group.Text = roomNo;
label.Text = "Room Dirty";
}
else if (room.RoomStatusId == 5)
{
group.BackColor = Color.Coral;
group.ForeColor = Color.White;
group.Text = roomNo;
label.Text = "Room Reserved";
}
else
{
group.BackColor = Color.Green;
group.ForeColor = Color.White;
group.Text = roomNo;
label.Text = "Room Arrival";
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
答案 0 :(得分:0)
使用UserControl和FlowLayoutPanel来解决此问题