private void AddServerListToTree(ServerList serverList, TreeNode parentNode) { var self = new TreeNode(serverList.Name); self.ContextMenuStrip = ctxmenu_DBTree_RightClick; if (serverList.Servers != null) { foreach (var s in serverList.Servers) { if (txtSearchServer.Text.Trim().Length == 0 || s.servername.ToUpper().Contains(txtSearchServer.Text.Trim().ToUpper())) { var serverNode = new TreeNode(s.servername, 1, 1); serverNode.ToolTipText = s.svr; serverNode.Tag = s; serverNode.Checked = (txtSearchServer.Text.Trim().Length > 0); serverNode.ContextMenuStrip = ctxmenu_DBTree_RightClick; self.Nodes.Add(serverNode); } } } if (serverList.ServerLists != null) { foreach (var s in serverList.ServerLists) { AddServerListToTree(s, self); } } self.Tag = serverList; //if (self.Nodes.Count > 0) //{ if (parentNode == null) { dbTree.Nodes.Clear(); dbTree.Nodes.Add(self); if (txtSearchServer.Text.Trim().Length > 0) { self.ExpandAll(); } else { self.Expand(); } } else { parentNode.Nodes.Add(self); } if (serverList.Expanded) { self.Expand(); } //} }
private void EnsureDBDefsExist(string configFile) { if (!File.Exists(configFile)) { var s = new XmlSerializer(typeof(ServerList)); var obj = new ServerList(); obj.Expanded = true; using (TextWriter w = new StreamWriter(configFile)) { s.Serialize(w, obj); } } }
private void LoadDatabaseDefinitions() { var configFile = Path.Combine(FormUtility.getServersFileLocation()); EnsureDBDefsExist(configFile); var s = new XmlSerializer(typeof(ServerList)); using (TextReader r = new StreamReader(configFile)) { _ServerList = (ServerList)s.Deserialize(r); } AddServerListToTree(_ServerList, null); }
private ServerList ExtractData(TreeNode tn, bool expanded) { var retval = new ServerList(); retval.Name = tn.Text; retval.Expanded = expanded; foreach (TreeNode node in tn.Nodes) { if (node.Tag.GetType() == typeof(ServerList)) { if (retval.ServerLists == null) { retval.ServerLists = new List <ServerList>(); } retval.ServerLists.Add(ExtractData(node, node.IsExpanded)); } else if (node.Tag.GetType() == typeof(Server)) { retval.AddServer((Server)node.Tag); } } return(retval); }
private void UpdateServerList() { _ServerList = ExtractData(dbTree.Nodes[0], dbTree.Nodes[0].IsExpanded); }
private void btn_Save_Click(object sender, EventArgs e) { if (rdoFolder.Checked) { var svrList = new ServerList(); svrList.Name = tb_Name.Text; if (IsEdit) { tn.Text = tb_Name.Text; tn.Tag = svrList; } else { TreeNode node = new TreeNode(); node.Text = svrList.Name; node.Tag = svrList; if (tn.Tag.GetType() == typeof(Server)) { tn.Parent.Nodes.Add(node); } else if (tn.Tag.GetType() == typeof(ServerList)) { tn.Nodes.Add(node); tn.Expand(); } } } else if (rdoServer.Checked) { var svr = new Server(); svr.servername = tb_Name.Text; svr.database = tb_Database.Text; svr.svr = tb_Location.Text; svr.password = cb_UseSqlCredentials.Checked ? tb_Password.Text : null; svr.username = cb_UseSqlCredentials.Checked ? tb_Username.Text : null; svr.usesspi = !cb_UseSqlCredentials.Checked; if (IsEdit) { if (tn.Tag.GetType() == typeof(Server)) { tn.Text = svr.servername; tn.Tag = svr; } } else { TreeNode node = new TreeNode(); node.Text = tb_Name.Text; node.Tag = svr; if (tn.Tag.GetType() == typeof(Server)) { tn.Parent.Nodes.Add(node); } else if (tn.Tag.GetType() == typeof(ServerList)) { tn.Nodes.Add(node); tn.Expand(); } } } this.DialogResult = DialogResult.OK; this.Close(); }
private void btn_Save_Click(object sender, EventArgs e) { if (rdoFolder.Checked) { var svrList = new ServerList(); svrList.Name = tb_Name.Text; if (IsEdit) { tn.Text = tb_Name.Text; tn.Tag = svrList; } else { TreeNode node = new TreeNode(); node.Text = svrList.Name; node.Tag = svrList; if (tn.Tag.GetType() == typeof(Server)) { tn.Parent.Nodes.Add(node); } else if (tn.Tag.GetType() == typeof(ServerList)) { tn.Nodes.Add(node); tn.Expand(); } } } else if (rdoServer.Checked) { var svr = new Server(); svr.servername = tb_Name.Text; svr.database = tb_Database.Text; svr.svr = tb_Location.Text; svr.password = cb_UseSqlCredentials.Checked ? tb_Password.Text : null; svr.username = cb_UseSqlCredentials.Checked ? tb_Username.Text : null; svr.usesspi = !cb_UseSqlCredentials.Checked; if (IsEdit) { if (tn.Tag.GetType() == typeof(Server)) { tn.Text = svr.servername; tn.Tag = svr; } } else { TreeNode node = new TreeNode(); node.Text = tb_Name.Text; node.Tag = svr; if (tn.Tag.GetType() == typeof(Server)) { tn.Parent.Nodes.Add(node); } else if (tn.Tag.GetType() == typeof(ServerList)) { tn.Nodes.Add(node); tn.Expand(); } } } this.DialogResult = DialogResult.OK; this.Close(); }