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. 21
      src/AddIns/DisplayBindings/Data/ICSharpCode.Data.Core.UI/Windows/ConnectionWizardWindow.xaml
  2. 35
      src/AddIns/DisplayBindings/Data/ICSharpCode.Data.Core.UI/Windows/ConnectionWizardWindow.xaml.cs
  3. 26
      src/AddIns/DisplayBindings/Data/ICSharpCode.Data.SQLServer/SQLServerDatabaseDriver.cs

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

@ -21,6 +21,7 @@
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition /> <RowDefinition />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
@ -43,7 +44,7 @@
<TextBlock Grid.Row="1" Margin="3">Database driver:</TextBlock> <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}" <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> <ComboBox.ItemTemplate>
<DataTemplate> <DataTemplate>
<TextBlock Text="{Binding Name}" /> <TextBlock Text="{Binding Name}" />
@ -58,7 +59,7 @@
<ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions> </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}"> SelectedItem="{Binding SelectedDatasource, ElementName=This}" ItemsSource="{Binding SelectedDatabaseDriver.Datasources, ElementName=This}">
<ComboBox.ItemTemplate> <ComboBox.ItemTemplate>
<DataTemplate> <DataTemplate>
@ -66,14 +67,16 @@
</DataTemplate> </DataTemplate>
</ComboBox.ItemTemplate> </ComboBox.ItemTemplate>
</ComboBox> </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> </Grid>
<ContentControl Grid.Row="3" Grid.Column="1" Margin="3" Content="{Binding SelectedDatasource.ControlPanel, ElementName=This}" /> <ContentControl Grid.Row="3" Grid.Column="1" Margin="3" Content="{Binding SelectedDatasource.ControlPanel, ElementName=This}" />
<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>
<TextBlock Grid.Row="4" Margin="3">Database:</TextBlock> <ComboBox x:Name="cboDatabases" Grid.Row="5" Grid.Column="1" Margin="3" SelectedItem="{Binding SelectedDatabase, ElementName=This}"
<ComboBox x:Name="cboDatabases" Grid.Row="4" Grid.Column="1" Margin="3" SelectedItem="{Binding SelectedDatabase, ElementName=This}"
ItemsSource="{Binding SelectedDatasource.Databases, ElementName=This}" SelectionChanged="cboDatabases_SelectionChanged"> ItemsSource="{Binding SelectedDatasource.Databases, ElementName=This}" SelectionChanged="cboDatabases_SelectionChanged">
<ComboBox.ItemTemplate> <ComboBox.ItemTemplate>
<DataTemplate> <DataTemplate>
@ -82,13 +85,13 @@
</ComboBox.ItemTemplate> </ComboBox.ItemTemplate>
</ComboBox> </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}"> IsExpanded="{Binding SelectedDatasource.UseUserDefinedConnectionString, ElementName=This}">
<TextBox Text="{Binding SelectedDatasource.UserDefinedConnectionString, ElementName=This}" MinLines="5" /> <TextBox Text="{Binding SelectedDatasource.UserDefinedConnectionString, ElementName=This}" MinLines="5" />
</Expander> </Expander>
<userControls:LoadingCircle Grid.Row="6" Margin="3" IsActivated="{Binding IsLoading, ElementName=This}" /> <userControls:LoadingCircle Grid.Row="7" Margin="3" IsActivated="{Binding IsLoading, ElementName=This}" />
<StackPanel Grid.Row="6" Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right"> <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 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> <Button Margin="3" IsCancel="True" Padding="3" Click="btnCancel_Click">Cancel</Button>
</StackPanel> </StackPanel>

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

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

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

@ -13,6 +13,8 @@ using ICSharpCode.Data.Core.DatabaseObjects;
using System.Data.SqlClient; using System.Data.SqlClient;
using System.Collections.Specialized; using System.Collections.Specialized;
using ICSharpCode.Data.Core.Enums; using ICSharpCode.Data.Core.Enums;
using System.Windows;
using System.Windows.Threading;
#endregion #endregion
@ -171,7 +173,29 @@ namespace ICSharpCode.Data.Core.DatabaseDrivers.SQLServer
SqlConnection sqlConnection = null; SqlConnection sqlConnection = null;
sqlConnection = new SqlConnection(); sqlConnection = new SqlConnection();
sqlConnection.ConnectionString = datasource.ConnectionString; sqlConnection.ConnectionString = datasource.ConnectionString;
sqlConnection.Open();
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; string sqlversion = sqlConnection.ServerVersion;
sqlversion = sqlversion.Split('.').FirstOrDefault(); //major version sqlversion = sqlversion.Split('.').FirstOrDefault(); //major version

Loading…
Cancel
Save