Example #1
0
        private async void btnConnect_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
                if (_connectionBase != null && _connectionBase.State != ConnectionState.Closed)
                {
                    _connectionBase.Close();
                }
                var selectedIndex = cboDataSource.SelectedIndex;

                switch (selectedIndex)
                {
                case 0:
                    C1ODataConnection oDataConn = new C1ODataConnection(txtConnString.Text);
                    await oDataConn.OpenAsync();

                    _connectionBase = oDataConn;
                    break;

                case 1:
                    C1D365SConnection d365SalesConn = new C1D365SConnection(txtConnString.Text);
                    await d365SalesConn.OpenAsync();

                    _connectionBase = d365SalesConn;     //Because C1D365SConnection wraps over C1ODataConnection
                    break;
                }

                if (selectedIndex != -1)
                {
                    //Populating TreeView
                    var schemas = _connectionBase.GetSchema().DefaultView;
                    treeView.ItemsSource = schemas;
                }
            }
            catch (Exception ex)
            {
                MessageBoxResult result = MessageBox.Show($"Error: {ex.Message}");
            }
            finally
            {
                Mouse.OverrideCursor = System.Windows.Input.Cursors.Arrow;
            }
        }