Пример #1
0
        /// <summary>
        /// 填充页面
        /// </summary>
        public void LoadSource()
        {
            panel2.VerticalScroll.Visible = true;//主面板

            DataTable dt = User_BLL.GetAllUserX();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string user_name = dt.Rows[i]["h_UserName"].ToString();
                Panel  p_row     = new Panel();//分面板
                p_row.Name      = "panel_" + user_name;
                p_row.Size      = new Size(1331, 34);
                p_row.BackColor = Color.CornflowerBlue;
                #region  label
                Label l_name = new Label();
                l_name.Name     = "lb_" + user_name;
                l_name.Text     = user_name;
                l_name.Font     = new Font(l_name.Font.FontFamily, 15, l_name.Font.Style);
                l_name.Location = new System.Drawing.Point(2, 5);
                p_row.Controls.Add(l_name);
                #endregion

                #region CheckBoxComboBox
                CheckBoxComboBox cbcb;
                Size             s = new Size();
                s.Width = 181;
                Dictionary <int, ListSelectionWrapper <Status> > dicX = SaveMessage();
                for (int j = 0; j < dicX.Count; j++)
                {
                    string str_power = EncryPtForMy.Class1.DecryptDES(dt.Rows[i]["Power"].ToString());
                    Dictionary <int, List <int> > dic_POWER = Split_Power(str_power);
                    cbcb            = new CheckBoxComboBox();
                    cbcb.Name       = "cbcb" + j;
                    cbcb.DataSource = dicX[j];
                    cbcb.DisplayMemberSingleItem = "Name";
                    cbcb.DisplayMember           = "NameConcatenated";
                    cbcb.ValueMember             = "Selected";
                    if (dic_POWER.Count > 0)    //为了判断
                    {
                        if (dic_POWER[j].ToList() != null)
                        {
                            List <int> list = dic_POWER[j].ToList();
                            for (int K = 0; K < list.Count; K++)
                            {
                                dicX[j][list[K]].Selected = true;
                            }
                        }
                    }
                    //dicX[j].FindObjectWithItem(sDD).Selected = true;
                    cbcb.Size      = s;
                    cbcb.Font      = new Font(cbcb.Font.FontFamily, 13, cbcb.Font.Style);
                    cbcb.BackColor = Color.Azure;
                    cbcb.Enabled   = false;
                    cbcb.Location  = new System.Drawing.Point(142 + j * 195, 5);
                    p_row.Controls.Add(cbcb);
                }
                #endregion
                #region button
                Button bt_alter = new Button();
                bt_alter.Text      = "修改";
                bt_alter.Name      = user_name;
                bt_alter.Click    += new EventHandler(Alter_Power);
                bt_alter.FlatStyle = FlatStyle.Popup;
                bt_alter.Size      = new Size(50, 30);
                bt_alter.Tag       = 9999;
                bt_alter.Location  = new System.Drawing.Point(142 + 5 * 195, 2);

                Button btX_save = new Button();
                btX_save.Text      = "保存";
                btX_save.Name      = user_name;
                btX_save.Click    += new EventHandler(Save_Power);
                btX_save.FlatStyle = FlatStyle.Popup;
                btX_save.Tag       = 9999;
                btX_save.Size      = new Size(50, 30);
                btX_save.Location  = new System.Drawing.Point(141 + 5 * 195 + 55, 2);

                Button bt_see = new Button();
                bt_see.Text      = "查看";
                bt_see.Name      = user_name;
                bt_see.Click    += new EventHandler(Check_Power);
                bt_see.FlatStyle = FlatStyle.Popup;
                bt_see.Tag       = 9999;
                bt_see.Size      = new Size(50, 30);
                bt_see.Location  = new System.Drawing.Point(143 + 5 * 195 + 106, 2);

                Button bt_delete = new Button();
                bt_delete.Text      = "删除";
                bt_delete.Name      = user_name;
                bt_delete.Click    += new EventHandler(Delete_User);
                bt_delete.FlatStyle = FlatStyle.Popup;
                bt_delete.Tag       = 9999;
                bt_delete.Size      = new Size(50, 30);
                bt_delete.Location  = new System.Drawing.Point(142 + 5 * 195 + 163, 2);

                p_row.Controls.Add(bt_alter);
                p_row.Controls.Add(btX_save);
                p_row.Controls.Add(bt_see);
                p_row.Controls.Add(bt_delete);
                #endregion
                p_row.Location = new System.Drawing.Point(5, 45 * (i + 1) + 10 * i);
                panel2.Controls.Add(p_row);
            }
        }