At the top of the application is a grid which lays out the
application horizontally. At the top is a Menu control, which contains the menu
item to connect to the database. Clicking the connect button pops up a popup
window, which takes the name of a database and a server (using windows
authentication only).
Listing 4
<MenuItem Header="File">
<MenuItem Header="Connect" x:Name="ConnectMenuItem"
Click="OnConnectMenuItemClick"/>
<MenuItem Command="ApplicationCommands.Close" Header="Exit"/>
</MenuItem>
Upon clicking the menu item, the following code runs:
Listing 5
this.ConnectPopup.IsOpen = true;
this.ConnectPopup.StaysOpen = false;
This opens the following popup, but ensures it does not stay
open permanently.
Listing 6
<Popup x:Name="ConnectPopup" Grid.Row="0" PopupAnimation="Fade"
PlacementTarget="{Binding ElementName=TabLayout}" Placement="Bottom"
PlacementRectangle="20,25,40,30">
<Grid Width="200" Height="100" Background="LightYellow">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="75" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0" Width="50">Server</Label>
<TextBox Name="Server" Grid.Row="0" Grid.Column="1" Width="50" />
<Label Grid.Row="1" Grid.Column="0" Width="50">Database Name</Label>
<TextBox Name="Database" Grid.Row="1" Grid.Column="1" Width="50" />
<Button Name="ConnectButton" Content="Connect" Grid.ColumnSpan="2"
Grid.Row="2" Click="OnConnectButtonClick" />
</Grid>
</Popup>
Notice the popup definition above which has certain
attributes. I explain about the popup in my
blog, but I will reiterate some of the information here. The Popup control
can take a container control as its child, which is commonly a grid (but could
be another control as well). This grid control, if
you are unfamiliar with it, specifies the grid-like structure that a group
of controls will adapt to. The grid uses the RowDefinitions/ColumnDefinitions
to setup the grid, and uses the Grid.Row or Grid.Column properties to set the
child controls to appear in a specific region.
The popup control can specify the location to appear through
the Placement, PlacementTarget, and the PlacementRectangle properties. Upon
entering the server/database and clicking connect, the tables are loaded into
the sidebar shown below.
Listing 7
<DockPanel>
<TreeView Name="TablesListing" DockPanel.Dock="Left"
HorizontalAlignment="Left" Width="150px" Background="#FFF2F0CD"
BorderThickness="1,1,1,1" Foreground="#FF6182F5"
SelectedItemChanged="OnTablesListingSelectedItemChanged"/>
</DockPanel>
The TreeView tables/columns are loaded, and upon selecting
each table, the string builder generates itself inside an expander control,
within a text box so the user can copy/paste them into SQL Server. The expander
groups control very nicely inside it, and allows the other stored procedures to
remain hidden.
Listing 8
<StackPanel Orientation="Vertical" DockPanel.Dock="Top">
<Expander Header="Create Procedure">
<TextBox Name="CreateProcedure" Style="{StaticResource SPStyle}" />
</Expander>
<Expander Header="Delete Procedure">
<TextBox Name="DeleteProcedure" Style="{StaticResource SPStyle}" />
</Expander>
<Expander Header="Update Procedure">
<TextBox Name="UpdateProcedure" Style="{StaticResource SPStyle}" />
</Expander>
<Expander Header="Select Procedure">
<TextBox Name="SelectProcedure" Style="{StaticResource SPStyle}" />
</Expander>
</StackPanel>