Beispiel #1
0
        public MainWindow()
        {
            InitializeComponent();

            QueryComposerResources.Init();

            // datacontext of window is inherited by all controls
            this.DataContext = currentSelectedServerLink;

            // listsource for combobox
            cbType.ItemsSource       = AppDBTypes.List();
            cbType.DisplayMemberPath = "Value";
            cbType.SelectedValuePath = "Key";

            if (LoadConnectionSettings())
            {
                RefreshConnectionList();
                EnableDisable();
            }
            else
            {
                // note: other options here http://stackoverflow.com/questions/2820357/how-to-exit-a-wpf-app-programmatically
                Application.Current.Shutdown();
            }
        }
Beispiel #2
0
        public void Initialize(AppDBQueryLink linkQueryRow, IQueryableConnection connection)
        {
            currentQuery     = linkQueryRow;
            completionHelper = QueryComposerResources.ComposerHelper(connection);

            Reset();
        }
Beispiel #3
0
        /// <summary>
        /// Open a new tab for the selected server, if we can connect to the server.
        /// </summary>
        /// <param name="connection_id">id</param>
        /// <param name="title">connection name to put in the tab header, should probably be accompanied by the id?</param>
        private void ConnectToServer(AppDBServerLink connection)
        {
            try
            {
                var tabcontent = new ConnectionTabControl();

                tabcontent.Height = double.NaN;
                tabcontent.Width  = double.NaN;

                tabcontent.Margin = new Thickness(0, 0, 0, 0);
                tabcontent.HorizontalAlignment = HorizontalAlignment.Stretch;
                tabcontent.VerticalAlignment   = VerticalAlignment.Stretch;

                // setup the datasource to provide querynames
                tabcontent.Initialize(appDB, connection.id);

                // this also connects to the database and will throw an exception when we can't connect
                tabcontent.SetDatabaseConnection((AppDBServerType)connection.type, connection.GetConnectionString());

                // create a new tab with usercontrol instance and stretch align that to the tab
                var tab = new TabItem();

                var header = new CloseableTabHeader(connection.name);
                header.OnClose = () =>
                {
                    // implementation when x button is used on tab
                    pgTabs.Items.Remove(tab);
                    QueryComposerResources.UnsetComposerHelper(tabcontent.DBConnection);
                };
                tab.Header  = header;
                tab.Content = tabcontent;

                pgTabs.Items.Add(tab);
                pgTabs.SelectedIndex = pgTabs.Items.IndexOf(tab);

                // if updatelayout() isn't used, recalculatesize() won't work
                pgTabs.UpdateLayout();
                header.RecalculateSize();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Connecting", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }