示例#1
0
        public void Can_remove_a_DbConnectionDefinition_object()
        {
            DbConnectionDefinitionList definitionList = new DbConnectionDefinitionList();

            definitionList.DefaultName = "def";
            var conn1 = new DbConnectionDefinition {
                ConnectionString = "cs1", Name = "nm1", ProviderName = "p1"
            };
            var conn2 = new DbConnectionDefinition {
                ConnectionString = "cs2", Name = "nm2", ProviderName = "p2"
            };
            var conn3unused = new DbConnectionDefinition {
                ConnectionString = "cs3", Name = "nm3", ProviderName = "p3"
            };

            definitionList.Definitions = new[] { conn1, conn2 };
            Assert.That(definitionList.Definitions.Length, Is.EqualTo(2));
            bool remove1 = definitionList.RemoveDefinition(conn2);

            Assert.That(remove1, Is.EqualTo(true));
            Assert.That(definitionList.Definitions.Length, Is.EqualTo(1));
            Assert.That(definitionList.Definitions[0].Name, Is.EqualTo("nm1"));
            bool remove2 = definitionList.RemoveDefinition(conn3unused);

            Assert.That(remove2, Is.EqualTo(false));
            Assert.That(definitionList.Definitions.Length, Is.EqualTo(1));
        }
示例#2
0
 /// <summary>The add to list.</summary>
 /// <param name="definition">The definition.</param>
 private void AddToList(DbConnectionDefinition definition)
 {
     if (!lstConnections.Items.Contains(definition))
     {
         lstConnections.Items.Add(definition);
     }
 }
示例#3
0
 /// <summary>The remove from list.</summary>
 /// <param name="definition">The definition.</param>
 private void RemoveFromList(DbConnectionDefinition definition)
 {
     if (lstConnections.Items.Contains(definition))
     {
         lstConnections.Items.Remove(definition);
     }
 }
示例#4
0
        /// <summary>The tool strip button edit conn str_ click.</summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        private void toolStripButtonEditConnStr_Click(object sender, EventArgs e)
        {
            DbConnectionDefinition definition = lstConnections.SelectedItem as DbConnectionDefinition;

            if (definition != null)
            {
                ManageDefinition(definition);
            }
        }
示例#5
0
        /// <summary>The lst connections_ double click.</summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        private void lstConnections_DoubleClick(object sender, EventArgs e)
        {
            DbConnectionDefinition definition = lstConnections.SelectedItem as DbConnectionDefinition;

            if (definition != null)
            {
                ManageDefinition(definition);
            }
        }
示例#6
0
 /// <summary>The tool strip combo box connection_ selected index changed.</summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The e.</param>
 private void toolStripComboBoxConnection_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (_initialized)
     {
         DbConnectionDefinition dbConnectionDefinition = (DbConnectionDefinition)toolStripComboBoxConnection.SelectedItem;
         _settings.ConnectionDefinition = dbConnectionDefinition;
         SetWindowTitle(dbConnectionDefinition.Name);
     }
 }
 /// <summary>Initializes a new instance of the <see cref="ConnectionStringBuilderForm"/> class.</summary>
 /// <param name="hostWindow">The host window.</param>
 /// <param name="definition">The definition.</param>
 /// <param name="services">The services.</param>
 public ConnectionStringBuilderForm(IHostWindow hostWindow, DbConnectionDefinition definition, IApplicationServices services)
     : this(hostWindow, services)
 {
     ConnectionDefinition = definition;
     ConnectionName       = ConnectionDefinition.Name;
     Comments             = ConnectionDefinition.Comment;
     _initProvider        = ConnectionDefinition.ProviderName;
     _connStr             = ConnectionDefinition.ConnectionString;
 }
示例#8
0
        /// <summary>The tool strip button copy as new_ click.</summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        private void toolStripButtonCopyAsNew_Click(object sender, EventArgs e)
        {
            DbConnectionDefinition definition = lstConnections.SelectedItem as DbConnectionDefinition;

            if (definition != null)
            {
                DbConnectionDefinition newDefinition = DbConnectionDefinition.FromXml(definition.ToXml());
                newDefinition.Name = "Copy of " + newDefinition.Name;
                ManageDefinition(newDefinition);
            }
        }
        /// <summary>The write values back.</summary>
        protected void WriteValuesBack()
        {
            if (ConnectionDefinition == null)
            {
                ConnectionDefinition = new DbConnectionDefinition();
            }

            ConnectionDefinition.Name             = ConnectionName;
            ConnectionDefinition.ProviderName     = ProviderName;
            ConnectionDefinition.ConnectionString = ConnectionString;
            ConnectionDefinition.Comment          = Comments;
            _dirty = false;
        }
示例#10
0
        /// <summary>The tool strip button delete_ click.</summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        private void toolStripButtonDelete_Click(object sender, EventArgs e)
        {
            DbConnectionDefinition definition = lstConnections.SelectedItem as DbConnectionDefinition;

            if (definition != null)
            {
                int newIndex = Math.Max(lstConnections.SelectedIndex - 1, 0);
                _definitionList.RemoveDefinition(definition);
                RemoveFromList(definition);
                if (lstConnections.Items.Count > 0)
                {
                    lstConnections.SelectedIndex = newIndex;
                }
            }
        }
示例#11
0
        public DbConnectionDefinitionBase GetConnectionDefinition(DbConnectionDefinition entity)
        {
            switch (entity.Type)
            {
            case DatabaseType.SqlServer:
                return(new SqlServerConnectionDefinition(entity.Id, entity.Name, entity.Description, entity.ConnectionString));

            case DatabaseType.ODBC:
                return(new ODBCConnectionDefinition(entity.Id, entity.Name, entity.Description, entity.ConnectionString));

            case DatabaseType.Oracle:
                return(new OracleConnectionDefinition(entity.Id, entity.Name, entity.Description, entity.ConnectionString));

            default:
                throw new InvalidOperationException();
            }
        }
示例#12
0
 /// <summary>The update details panel.</summary>
 /// <param name="definition">The definition.</param>
 private void UpdateDetailsPanel(DbConnectionDefinition definition)
 {
     if (definition != null)
     {
         txtName.Text     = definition.Name;
         txtProvider.Text = definition.ProviderName;
         txtConn.Text     = definition.ConnectionString;
         txtComment.Text  = definition.Comment;
     }
     else
     {
         txtName.Clear();
         txtProvider.Clear();
         txtConn.Clear();
         txtComment.Clear();
     }
 }
示例#13
0
        /// <summary>The manage definition.</summary>
        /// <param name="definition">The definition.</param>
        private void ManageDefinition(DbConnectionDefinition definition)
        {
            ConnectionStringBuilderForm frm;
            string oldName = null;

            if (definition == null)
            {
                frm = new ConnectionStringBuilderForm(_hostWindow, _services);                 // new blank form
            }
            else
            {
                oldName = definition.Name;
                frm     = new ConnectionStringBuilderForm(_hostWindow, definition, _services);
            }

            frm.ShowDialog(this);

            if (frm.DialogResult == DialogResult.OK)
            {
                SetDirty();

                if (lstConnections.Items.Contains(frm.ConnectionDefinition) && definition != null)
                {
                    if (definition.Name != oldName)
                    {
                        // want the list text to update due to name change
                        UpdateListView();
                        lstConnections.SelectedItem = definition;
                    }
                    else
                    {
                        UpdateDetailsPanel(lstConnections.SelectedItem as DbConnectionDefinition);
                    }
                }
                else
                {
                    _definitionList.AddDefinition(frm.ConnectionDefinition);
                    AddToList(frm.ConnectionDefinition);
                    lstConnections.SelectedItem = frm.ConnectionDefinition;
                }
            }
        }
示例#14
0
        /// <summary>The tool strip button test_ click.</summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        private void toolStripButtonTest_Click(object sender, EventArgs e)
        {
            // do a standalone raw connection test
            DbConnectionDefinition definition = lstConnections.SelectedItem as DbConnectionDefinition;

            if (definition != null)
            {
                Exception exp = QueryRunner.TestDbConnection(definition.ProviderName, definition.ConnectionString);
                if (exp == null)
                {
                    string msg = string.Format("Connected to '{0}' successfully.", definition.Name);
                    _hostWindow.DisplaySimpleMessageBox(this, msg, "Connection Successful");
                }
                else
                {
                    string msg = string.Format("Failed connecting to '{0}'.{1}{2}", definition.Name, Environment.NewLine, exp.Message);
                    _hostWindow.DisplaySimpleMessageBox(this, msg, "Connection Failed");
                }
            }
        }
示例#15
0
        /// <summary>The lst connections_ selected value changed.</summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        private void lstConnections_SelectedValueChanged(object sender, EventArgs e)
        {
            DbConnectionDefinition definition = lstConnections.SelectedItem as DbConnectionDefinition;

            UpdateDetailsPanel(definition);
        }