Creating a SQL Server Stored Procedure Generator using WPF
page 4 of 8
by Brian Mains
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 12581/ 489

Application Layout

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>

View Entire Article

Article Feedback

Title:  
Name:  
Url: ( Optional )
Comment:  
Please add 6 and 6 and type the answer here:

User Comments

Title: A good start   
Name: Ralph D. Wilson II
Date: 9/19/2007 10:36:05 AM
Comment:
This presents a good start toward creating Stored Procs; however, I can see several limitations in it. Perhaps the most glaring limitation is the fact that it appears to only facilitate the creation of very basic SP's and, while that is useful, I am assisting C#/ASP.Net developers in the creation of much more complex SP's.
Title: type   
Name: Nitin
Date: 9/19/2007 6:17:17 AM
Comment:
it is good but not enough
Title: Useful   
Name: Niall
Date: 8/30/2007 3:32:49 AM
Comment:
This is interesting and I can see a very good use for this type of programming in my current project. One reservation I have though is the use of the WPF. Specifically the Presentation part of WPF.
Title: Code is Attached   
Name: Brian Mains
Date: 8/26/2007 7:26:33 PM
Comment:
The code is attached; see the downloads section.
Title: download this software   
Name: ankti
Date: 8/26/2007 4:22:23 PM
Comment:
i want to see this software






Ads Powered by Lake Quincy Media
Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2008 ASPAlliance.com  |  Page Processed at 7/5/2008 12:29:39 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search