private TreeNode createConnectionNode(ConnectionSettings cs) { TreeNode node = rootNode.Nodes.Add(cs.ToString(), cs.ToString(), cs.Provider.ToString(), cs.Provider.ToString()); node.NodeFont = new Font(treeView.Font, FontStyle.Underline); node.Tag = cs; cbActiveConnection.Items.Add(cs); return node; }
private void cmdNewConnection(string arg) { FormConnect f = new FormConnect(); if (arg == "create") f.Text = "Create Database"; if (SelectedObject is ConnectionSettings) { ConnectionSettings curr = SelectedObject as ConnectionSettings; f.txtDBName.Text = ""; f.txtHost.Text = curr.Host; f.txtPassword.Text = curr.Password; f.cbProvider.SelectedItem = curr.Provider.ToString(); f.txtUserName.Text = curr.UserName; } while (f.ShowDialog() == DialogResult.OK) { ConnectionSettings cs = new ConnectionSettings(); cs.DbName = f.txtDBName.Text; cs.Host = f.txtHost.Text; cs.Password = f.txtPassword.Text; cs.Provider = (DatabaseProvider)Enum.Parse(typeof(DatabaseProvider), f.cbProvider.SelectedItem.ToString()); cs.UserName = f.txtUserName.Text; cs.CreateDatabaseIfNotExist = f.cbCreateDatabase.Checked; try { cs.RefreshDatabaseSchema(); Provider.Connections.Add(cs); TreeNode tn = rootNode.Nodes.Add(cs.ToString(), cs.ToString(), cs.Provider.ToString(), cs.Provider.ToString()); tn.Tag = cs; tn.NodeFont = new Font(this.Font, FontStyle.Underline); cbActiveConnection.Items.Add(cs); treeView.SelectedNode = tn; tn.Expand(); break; } catch (Exception ex) { MessageBox.Show(ex.Message, "Cinar Database Tools", MessageBoxButtons.OK, MessageBoxIcon.Warning); f.DialogResult = DialogResult.None; } } }