Exemple #1
0
        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;
                }
            }
        }
Exemple #2
0
 private void cmdEditConnection(string arg)
 {
     ConnectionSettings cs = (ConnectionSettings)SelectedObject;
     FormConnect f = new FormConnect();
     f.txtDBName.Text = cs.DbName;
     f.txtHost.Text = cs.Host;
     f.txtPassword.Text = cs.Password;
     f.cbProvider.SelectedItem = cs.Provider.ToString();
     f.txtUserName.Text = cs.UserName;
     while (f.ShowDialog() == DialogResult.OK)
     {
         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;
         try
         {
             cs.RefreshDatabaseSchema();
             treeView.SelectedNode.Name = treeView.SelectedNode.Text = cs.ToString();
             break;
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "Cinar Database Tools", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             f.DialogResult = DialogResult.None;
         }
     }
 }