private void DatabaseConfigForm_Load(object sender, EventArgs e) { if (DesignMode) { return; } try { string a = FileHelper.ReadFile("//temp//dbconfig.json"); if (!string.IsNullOrWhiteSpace(a)) { var list = JsonConvert.DeserializeObject <List <uc_statusbar_datasource> >(a); foreach (var li in list) { uc_dbtooltip tip = new uc_dbtooltip(); tip.Dock = DockStyle.Top; tip.DataSource = new uc_statusbar_datasource() { provider = li.provider, dbaddr = li.dbaddr, username = li.username, userpwd = li.userpwd, }; tip.Databind(); tip.SelectedHandler += tip_SelectedHandler; tip.DeleteControlHandler += tip_DeleteControlHandler; pnldb.Controls.Add(tip); } } } catch (Exception ex) { MessageBox.Show(" 读取配置失败!详细信息:" + ex.ToString()); } }
private void button2_Click(object sender, EventArgs e) { uc_dbtooltip tip = new uc_dbtooltip(); tip.DataSource = new uc_statusbar_datasource() { provider = txtprovider.Text, dbaddr = dbaddr.Text, username = username.Text, userpwd = userpwd.Text, }; tip.Databind(); tip.SelectedHandler += tip_SelectedHandler; tip.DeleteControlHandler += tip_DeleteControlHandler; tip.Dock = DockStyle.Top; pnldb.Controls.Add(tip); //保存到文件 List <uc_statusbar_datasource> conifg = new List <uc_statusbar_datasource>(); foreach (uc_dbtooltip contorl in pnldb.Controls) { conifg.Add(contorl.DataSource); } FileHelper.WriteFile("//temp//dbconfig.json", JsonConvert.SerializeObject(conifg)); }