Пример #1
0
        private Panel StructureControl()
        {
            var tag = pl_CbConfig.Tag.ConvertInt32();

            pl_CbConfig.Tag = tag + 1;
            var   y  = 40 * (tag + 1);
            Panel pl = new Panel();

            pl.Location = new System.Drawing.Point(3, y);
            pl.Name     = tag.ToString();
            pl.Size     = new System.Drawing.Size(580, 33);
            DropDownSearch table = new DropDownSearch();

            table.Location              = new System.Drawing.Point(30, 5);
            table.Name                  = "table";
            table.Size                  = new System.Drawing.Size(200, 20);
            table.SelectedIndexChanged += new System.EventHandler(this.SelectedIndexChanged);
            DropDownSearch cbzd = new DropDownSearch();

            cbzd.Location = new System.Drawing.Point(259, 5);
            cbzd.Name     = "cbzd";
            cbzd.Size     = new System.Drawing.Size(80, 20);
            DropDownSearch zbzd = new DropDownSearch();

            zbzd.Location = new System.Drawing.Point(372, 5);
            zbzd.Name     = "zbzd";
            zbzd.Size     = new System.Drawing.Size(80, 20);
            zbzd.Text     = cbx_TablePk.Text;
            Button btn = new Button();

            btn.Location = new System.Drawing.Point(480, 5);
            btn.Name     = "btn_" + tag.ToString();
            btn.Size     = new System.Drawing.Size(75, 20);
            btn.Text     = "删除";
            btn.UseVisualStyleBackColor = true;
            btn.Click += new System.EventHandler(this.DeleteCbPz);
            pl.Controls.AddRange(new Control[] { table, cbzd, zbzd, btn });
            pl_CbConfig.Controls.Add(pl);
            if (tempData == null)
            {
                tempData = (cbx_TableList.DataSource as DataTable).Select($" name<>'{cbx_TableList.Text.ConvertString()}'").CopyToDataTable();
            }
            table.SetDataSource(tempData, "name");
            cbzd.SetDataSource(DBInfo.GetTableInfo_DT(table.Text.ConvertString()), "COLUMN_NAME");
            zbzd.SetDataSource(cbx_TablePk.DataSource, "COLUMN_NAME");
            return(pl);
        }
Пример #2
0
        private void SelectedIndexChanged(object sender, EventArgs e)
        {
            var cbx = (DropDownSearch)sender;

            if (!string.IsNullOrEmpty(cbx.Text.ConvertString()))
            {
                var            data   = DBInfo.GetTableInfo_DT(cbx.Text.ConvertString());
                DropDownSearch cbc_kz = null;
                if (cbx.Name == cbx_TableList.Name)
                {
                    cbc_kz = cbx_TablePk;
                }
                else
                {
                    cbc_kz = cbx.Parent.Controls["cbzd"] as DropDownSearch;
                }
                if (cbc_kz != null)
                {
                    cbc_kz.SetDataSource(data, "COLUMN_NAME");
                    if (string.IsNullOrEmpty(cbc_kz.Text))
                    {
                        var key = data.Select(" IsKey=1");
                        if (key.Length > 0)
                        {
                            cbc_kz.Text = key[0]["COLUMN_NAME"].ConvertString();
                        }
                    }
                }
                if (cbx.Name == cbx_TableList.Name)
                {
                    tempData = cbx_TableList.DataSource.Select($" name<>'{cbx_TableList.Text.ConvertString()}'").CopyToDataTable();
                    foreach (var item in pl_CbConfig.Controls)
                    {
                        if (item is Panel)
                        {
                            var _temp = (item as Panel).Controls["zbzd"] as DropDownSearch;
                            _temp.SetDataSource(data, "COLUMN_NAME");
                            _temp.Text = cbx.Text;
                            var _temp2 = (item as Panel).Controls["table"] as DropDownSearch;
                            _temp2.SetDataSource(tempData, "name");
                        }
                    }
                }
            }
        }
Пример #3
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         string          connetionString = null;
         MySqlConnection con;
         connetionString = "server=localhost;database=coffeedb;Uid=root;Pwd=;";
         con             = new MySqlConnection(connetionString);
         con.Open();
         MySqlCommand    sda = new MySqlCommand("SELECT branch_Id FROM tbl_revenue", con);
         MySqlDataReader dr;
         dr = sda.ExecuteReader();
         DropDownSearch.Items.Clear();
         while (dr.Read())
         {
             DropDownSearch.Items.Add(new ListItem(dr[0].ToString(), dr[0].ToString()));
         }
         DropDownSearch.DataBind();
         con.Close();
     }
 }