Пример #1
0
        /// <summary>
        /// Add Tabs to the Connections Tab Control based on the in-memory values (connection dictionary).
        /// </summary>
        private void AddConnectionTabPages()
        {
            IntPtr localHandle = tabControlConnections.Handle;

            foreach (var connection in TeamConfiguration.ConnectionDictionary)
            {
                // Adding tabs on the Tab Control
                var lastIndex = tabControlConnections.TabCount - 1;
                CustomTabPageConnection localCustomTabPage = new CustomTabPageConnection(connection.Value);
                localCustomTabPage.OnDeleteConnection += DeleteConnection;
                localCustomTabPage.OnChangeMainText   += UpdateMainInformationTextBox;
                localCustomTabPage.OnSaveConnection   += SaveConnection;
                tabControlConnections.TabPages.Insert(lastIndex, localCustomTabPage);
                tabControlConnections.SelectedIndex = 0;

                // Adding items in the drop down list
                comboBoxMetadataConnection.Items.Add(new KeyValuePair <TeamConnection, string>(connection.Value, connection.Value.ConnectionKey));
                comboBoxMetadataConnection.ValueMember   = "Key";
                comboBoxMetadataConnection.DisplayMember = "Value";
            }
        }
Пример #2
0
        /// <summary>
        /// Check if the last tab rectangle contains the mouse clicked point, then insert a tab before the last tab.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tabControlConnections_MouseDown(object sender, MouseEventArgs e)
        {
            var lastIndex = tabControlConnections.TabCount - 1;

            if (tabControlConnections.GetTabRect(lastIndex).Contains(e.Location))
            {
                //tabControlConnections.TabPages.Insert(lastIndex, "New Tab");
                TeamConnection connectionProfile = new TeamConnection();
                connectionProfile.ConnectionInternalId = Utility.CreateMd5(new[] { Utility.GetRandomString(100) }, " % $@");
                connectionProfile.ConnectionName       = "New connection";
                connectionProfile.ConnectionKey        = "New";
                connectionProfile.ConnectionType       = ConnectionTypes.Database;

                TeamDatabaseConnection connectionDatabase = new TeamDatabaseConnection();
                connectionDatabase.SchemaName         = "<Schema Name>";
                connectionDatabase.ServerName         = "<Server Name>";
                connectionDatabase.DatabaseName       = "<Database Name>";
                connectionDatabase.NamedUserName      = "******";
                connectionDatabase.NamedUserPassword  = "******";
                connectionDatabase.authenticationType = ServerAuthenticationTypes.NamedUser;

                TeamFileConnection connectionFile = new TeamFileConnection();
                connectionFile.FilePath = @"<File Path>";
                connectionFile.FileName = @"<File Name>";

                connectionProfile.DatabaseServer = connectionDatabase;
                connectionProfile.FileConnection = connectionFile;


                //localCustomTabPage.OnChangeMainText += UpdateMainInformationTextBox;
                //localCustomTabPage.OnClearMainText += (ClearMainInformationTextBox);

                bool newTabExists = false;
                foreach (TabPage customTabPage in tabControlConnections.TabPages)
                {
                    if (customTabPage.Name == "New")
                    {
                        newTabExists = true;
                    }
                    else
                    {
                        // Do nothing
                    }
                }

                if (newTabExists == false)
                {
                    // Create a new tab page using the connection profile (a TeamConnection class object) as input.
                    CustomTabPageConnection localCustomTabPage = new CustomTabPageConnection(connectionProfile);
                    localCustomTabPage.OnDeleteConnection += DeleteConnection;
                    localCustomTabPage.OnChangeMainText   += UpdateMainInformationTextBox;
                    localCustomTabPage.OnSaveConnection   += SaveConnection;
                    tabControlConnections.TabPages.Insert(lastIndex, localCustomTabPage);
                    tabControlConnections.SelectedIndex = lastIndex;

                    GlobalParameters.TeamEventLog.Add(Event.CreateNewEvent(EventTypes.Information, $"A new connection was created."));
                }
                else
                {
                    richTextBoxInformation.AppendText("There is already a 'new connection' tab open. Please close or save this first.\r\n");
                }
            }
        }