动态生成按钮

1、自动生成按钮

        #region   自动生成 预订管理-房台界面按钮
        /// <summary>
        /// 自动生成 预订管理-房台界面按钮
        /// </summary>
        /// <param name="ds"></param>
        private void  BindRoombutton(DataSet ds)
        {
            Button[] b = new Button[ds.Tables[0].Rows.Count];
            int i = ds.Tables[0].Rows.Count;
            try
            {
                for (int j = 0; j < i; j++)
                {
                    b[j] = new Button();
                    b[j].Size = new Size(90, 50);
                    b[j].Text = ds.Tables[0].Rows[j]["RoomName"].ToString();
                    b[j].Name = ds.Tables[0].Rows[j]["RoomNo"].ToString();
                    b[j].Tag = int.Parse(ds.Tables[0].Rows[j]["RoomState"].ToString());
                    if (j % 7 == 0 && j != 0)
                    {
                        k++;
                    }
                    b[j].MouseClick += new MouseEventHandler(BookRoom_MouseClick);
                    System.Drawing.Point p = new Point(20 + (j % 7) * 90, 15 + k * 50);

                    b[j].Location = p;

                    panelControl1.Controls.AddRange(b);

                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region  点击房台按钮

        /// <summary>
        /// 点击房台按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BookRoom_MouseClick(object sender, MouseEventArgs e)
        {
            this.selectedRoom = (Button)sender;
            Button b = sender as Button;
            //DataSet ds = init.SearchRoom(fshipid);
            //Button[] b1 = BindRoombutton(ds);
            if (b.BackColor == Color.White)
            {
                if (b.Tag.ToString() == "0")
                {
                    b.BackColor = Color.DodgerBlue;
                }
                if (b.Tag.ToString() == "2")
                {
                    b.BackColor = Color.Yellow;
                }
                if (b.Tag.ToString() == "1")
                {
                    b.BackColor = Color.ForestGreen;
                }
                if (b.Tag.ToString() == "3")
                {
                    b.BackColor = Color.Red;
                }
                if (b.Tag.ToString() == "6")
                {
                    b.BackColor = Color.Purple;
                }
                if (b.Tag.ToString() == "4")
                {
                    b.BackColor = Color.Violet;
                }
            }
            else
            {
                b.BackColor = Color.White;
            }
            SelectedRoom();
            InitRoomBookGrid(b);
        }
        #endregion

 

 

posted @ 2012-12-03 17:36  qin孑  阅读(263)  评论(0编辑  收藏  举报