private void FrmdiepSheBei_Load()
{
width = panel2.Width / 15; ////面板宽度
timer1.Interval = dp.getboardTime();
addButton("", "在用", panel2, "龙华厂");
}
private void addButton(String strDept, String strState, Panel p, String strFName)
{
p.Controls.Clear();
blist.Clear();
st = dp.getColorSheBei();
DataTable dtGree = st.Tables[0];
DataTable dtRed = st.Tables[1];
dt = dp.getSheBei(strDept, strState, strFName);
if (strState == "正常")
{
DataTable dt2 = dp.getSheBei(strDept, "在用", strFName);
for (int i = 0; i < dt2.Rows.Count; i++)
{
dt.ImportRow(dt2.Rows[i]);
}
}
Button[] bn = new Button[dt.Rows.Count];
int x = 50;
int y = 0;
for (int i = 0; i < dt.Rows.Count; i++)
{
bn[i] = new Button();
bn[i].Name = i.ToString();
bn[i].Text = dt.Rows[i][0].ToString();
bn[i].Font = new System.Drawing.Font("宋体", 25, FontStyle.Regular);
bn[i].Size = new System.Drawing.Size(width, height);
x = (width + 18) * (i % 12);
bn[i].Location = new Point(x, y);
if ((i + 1) % 12 == 0 && i != 0)
{
y = (height + y) + 20;
}
///在用
if (strState == "在用")
{
bn[i].BackColor = Color.DodgerBlue;
//判断停用
for (int yw = 0; yw < dtGree.Rows.Count; yw++)
{
if (bn[i].Text == dtGree.Rows[yw]["jiCode"].ToString())
{
//设备背景色为绿色
bn[i].BackColor = Color.Green;
break;
}
}
//判断是否为维修中
for (int r = 0; r < dtRed.Rows.Count; r++)
{
if (bn[i].Text == dtRed.Rows[r]["jiCode"].ToString())
{
//设备背景色为红色
bn[i].BackColor = Color.Red;
blist.Add(bn[i]);
break;
}
}
}
bn[i].FlatStyle = System.Windows.Forms.FlatStyle.Flat;
bn[i].MouseHover += new System.EventHandler(this.buttonAll_MouseHove);
p.Controls.Add(bn[i]);
}
#region 遍历窗体上的所有Button 添加到blist 集合中
//遍历Form上的所有控件
//foreach (System.Windows.Forms.Control control in this.Controls)
//{
// if (control is System.Windows.Forms.Button)
// {
// System.Windows.Forms.Button btn = (System.Windows.Forms.Button)control;
// if (btn.Name != "button3" && btn.BackColor == Color.Red)
// {
// blist.Add(btn);
// }
// }
//}
#endregion
}