private void OpenConnectInfos() { try { string path = Application.StartupPath + "\\connectconfigures.json"; FileStream fs = File.Open(path, FileMode.Open); StreamReader sr = new StreamReader(fs); string str = sr.ReadToEnd(); sr.Close(); sr.Dispose(); fs.Dispose(); List<DbConnectConfigure> configures = Newtonsoft.Json.JsonConvert.DeserializeObject<List<DbConnectConfigure>>(str); foreach (DbConnectConfigure item in configures) { TreeNode node = new TreeNode(); ConnectInfo info = new ConnectInfo(node); tvConnectList.Nodes[0].Nodes.Add(node); node.Tag = info; info.DbConnectConfigure = item; } tvConnectList.ExpandAll(); } catch (Exception) { } }
private void DoOpen(ConnectInfo info) { if (info != null) { if (info.FrmDataBase != null) { ShowOrActiveForm(info.FrmDataBase); } else if (info.DbConnectConfigure != null) { FrmDatabase frmdb = new FrmDatabase(null); info.FrmDataBase = frmdb; ShowOrActiveForm(frmdb); frmdb.DbConnectConfigure = info.DbConnectConfigure; } } }
private void NewConnectDb(DbConnectConfigure configure = null,ConnectInfo info = null, TreeNode node=null) { FrmOpenDb openDb = new FrmOpenDb(); DialogResult dr = openDb.ShowDialog(this); if (dr == DialogResult.Cancel) { return; } else { if (node == null) { node = new TreeNode(); tvConnectList.Nodes[0].Nodes.Add(node); } if (info==null) { info = new ConnectInfo(node); } node.Tag = info; info.DbConnectConfigure = openDb.DbConnectConfigure; if (dr == DialogResult.OK) { FrmDatabase frmdb = new FrmDatabase(openDb.DbClass); frmdb.DbConnectConfigure = info.DbConnectConfigure; info.FrmDataBase = frmdb; ShowOrActiveForm(frmdb); } info.Node = node; tvConnectList.ExpandAll(); SaveConnectInfos(); } }