Browse Source

Data Add-In Connection Wizard: new UI

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/reports@6308 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Philipp Maihart 15 years ago
parent
commit
bd6cd43f3a
  1. 19
      src/AddIns/DisplayBindings/Data/ICSharpCode.Data.Core.UI/Windows/ConnectionWizardWindow.xaml
  2. 33
      src/AddIns/DisplayBindings/Data/ICSharpCode.Data.Core.UI/Windows/ConnectionWizardWindow.xaml.cs
  3. 24
      src/AddIns/DisplayBindings/Data/ICSharpCode.Data.SQLServer/SQLServerDatabaseDriver.cs

19
src/AddIns/DisplayBindings/Data/ICSharpCode.Data.Core.UI/Windows/ConnectionWizardWindow.xaml

@ -21,6 +21,7 @@ @@ -21,6 +21,7 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
@ -43,7 +44,7 @@ @@ -43,7 +44,7 @@
<TextBlock Grid.Row="1" Margin="3">Database driver:</TextBlock>
<ComboBox x:Name="cboDatabaseDriver" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" Margin="3" SelectedItem="{Binding SelectedDatabaseDriver, ElementName=This}"
ItemsSource="{x:Static data:DatabaseDriver.DatabaseDrivers}" SelectionChanged="cboDatabaseDriver_SelectionChanged">
ItemsSource="{x:Static data:DatabaseDriver.DatabaseDrivers}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" />
@ -58,7 +59,7 @@ @@ -58,7 +59,7 @@
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ComboBox x:Name="cboDatasources" Margin="3" IsEditable="True" KeyDown="cboDatasources_KeyDown" SelectionChanged="cboDatasources_SelectionChanged"
<ComboBox x:Name="cboDatasources" Margin="3" IsEditable="True" KeyDown="cboDatasources_KeyDown"
SelectedItem="{Binding SelectedDatasource, ElementName=This}" ItemsSource="{Binding SelectedDatabaseDriver.Datasources, ElementName=This}">
<ComboBox.ItemTemplate>
<DataTemplate>
@ -66,14 +67,16 @@ @@ -66,14 +67,16 @@
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<userControls:ErrorRetryButton x:Name="erbDatasources" Grid.Column="1" UseExclamationMark="True" Exception="{Binding DatasourceException, ElementName=This}" MouseLeftButtonUp="erbDatasources_MouseLeftButtonUp" />
<Button Grid.Column="1" Margin="3" Content="Auto Discover" Click="btnAutoDiscover_Click" />
</Grid>
<ContentControl Grid.Row="3" Grid.Column="1" Margin="3" Content="{Binding SelectedDatasource.ControlPanel, ElementName=This}" />
<TextBlock Grid.Row="4" Margin="3">Database:</TextBlock>
<Button x:Name="btnConnect" Grid.Row="4" Grid.Column="1" Margin="3" Content="Connect" HorizontalAlignment="Right" Click="btnConnect_Click" />
<TextBlock Grid.Row="5" Margin="3">Database:</TextBlock>
<ComboBox x:Name="cboDatabases" Grid.Row="4" Grid.Column="1" Margin="3" SelectedItem="{Binding SelectedDatabase, ElementName=This}"
<ComboBox x:Name="cboDatabases" Grid.Row="5" Grid.Column="1" Margin="3" SelectedItem="{Binding SelectedDatabase, ElementName=This}"
ItemsSource="{Binding SelectedDatasource.Databases, ElementName=This}" SelectionChanged="cboDatabases_SelectionChanged">
<ComboBox.ItemTemplate>
<DataTemplate>
@ -82,13 +85,13 @@ @@ -82,13 +85,13 @@
</ComboBox.ItemTemplate>
</ComboBox>
<Expander Grid.Row="5" Grid.Column="1" Margin="2" Header="Connection String" VerticalAlignment="Top"
<Expander Grid.Row="6" Grid.Column="1" Margin="2" Header="Connection String" VerticalAlignment="Top"
IsExpanded="{Binding SelectedDatasource.UseUserDefinedConnectionString, ElementName=This}">
<TextBox Text="{Binding SelectedDatasource.UserDefinedConnectionString, ElementName=This}" MinLines="5" />
</Expander>
<userControls:LoadingCircle Grid.Row="6" Margin="3" IsActivated="{Binding IsLoading, ElementName=This}" />
<StackPanel Grid.Row="6" Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right">
<userControls:LoadingCircle Grid.Row="7" Margin="3" IsActivated="{Binding IsLoading, ElementName=This}" />
<StackPanel Grid.Row="7" Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right">
<Button x:Name="btnAdd" Margin="3" Padding="3" Click="btnAdd_Click" IsEnabled="False">Add</Button>
<Button Margin="3" IsCancel="True" Padding="3" Click="btnCancel_Click">Cancel</Button>
</StackPanel>

33
src/AddIns/DisplayBindings/Data/ICSharpCode.Data.Core.UI/Windows/ConnectionWizardWindow.xaml.cs

@ -54,6 +54,11 @@ namespace ICSharpCode.Data.Core.UI.Windows @@ -54,6 +54,11 @@ namespace ICSharpCode.Data.Core.UI.Windows
get { return _selectedDatasource; }
set
{
if (value != null)
btnConnect.IsEnabled = true;
else
btnConnect.IsEnabled = false;
_selectedDatasource = value;
OnPropertyChanged("SelectedDatasource");
}
@ -133,7 +138,6 @@ namespace ICSharpCode.Data.Core.UI.Windows @@ -133,7 +138,6 @@ namespace ICSharpCode.Data.Core.UI.Windows
thread.SetApartmentState(ApartmentState.STA);
thread.IsBackground = true;
thread.Start();
}
private void PopulateDatabases()
@ -152,7 +156,10 @@ namespace ICSharpCode.Data.Core.UI.Windows @@ -152,7 +156,10 @@ namespace ICSharpCode.Data.Core.UI.Windows
}
catch (Exception ex)
{
SetException(ex);
Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
{
MessageBox.Show(this, ex.Message, this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
}));
}
SetIsLoading(false);
@ -168,17 +175,12 @@ namespace ICSharpCode.Data.Core.UI.Windows @@ -168,17 +175,12 @@ namespace ICSharpCode.Data.Core.UI.Windows
#region Event handlers
private void cboDatabaseDriver_SelectionChanged(object sender, SelectionChangedEventArgs e)
private void btnAutoDiscover_Click(object sender, RoutedEventArgs e)
{
PopulateDatasources();
}
private void cboDatasources_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
PopulateDatabases();
}
private void erbDatasources_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
private void btnConnect_Click(object sender, RoutedEventArgs e)
{
PopulateDatabases();
}
@ -189,18 +191,7 @@ namespace ICSharpCode.Data.Core.UI.Windows @@ -189,18 +191,7 @@ namespace ICSharpCode.Data.Core.UI.Windows
{
if (SelectedDatabaseDriver != null)
{
IDatasource newDatasource = SelectedDatabaseDriver.AddNewDatasource(cboDatasources.Text);
try
{
if (newDatasource.PopulateDatabases())
SetSelectedDatasource(newDatasource);
}
catch (Exception ex)
{
SetException(ex);
SetSelectedDatasource(newDatasource);
}
SelectedDatasource = SelectedDatabaseDriver.AddNewDatasource(cboDatasources.Text);
}
}
}

24
src/AddIns/DisplayBindings/Data/ICSharpCode.Data.SQLServer/SQLServerDatabaseDriver.cs

@ -13,6 +13,8 @@ using ICSharpCode.Data.Core.DatabaseObjects; @@ -13,6 +13,8 @@ using ICSharpCode.Data.Core.DatabaseObjects;
using System.Data.SqlClient;
using System.Collections.Specialized;
using ICSharpCode.Data.Core.Enums;
using System.Windows;
using System.Windows.Threading;
#endregion
@ -171,7 +173,29 @@ namespace ICSharpCode.Data.Core.DatabaseDrivers.SQLServer @@ -171,7 +173,29 @@ namespace ICSharpCode.Data.Core.DatabaseDrivers.SQLServer
SqlConnection sqlConnection = null;
sqlConnection = new SqlConnection();
sqlConnection.ConnectionString = datasource.ConnectionString;
try
{
sqlConnection.Open();
}
catch (SqlException ex)
{
switch (ex.Number)
{
case 2:
case 3:
case 53:
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
{
Datasources.Remove(datasource as SQLServerDatasource);
}));
break;
default:
break;
}
throw ex;
}
string sqlversion = sqlConnection.ServerVersion;
sqlversion = sqlversion.Split('.').FirstOrDefault(); //major version

Loading…
Cancel
Save