One of the things I am fond is reducing the time to perform tasks in the software world. Sometimes that involves lots of code such as a custom testing system I am building for a client. But even lots of the code for the test system can be automated.For instance, consider the application that’s using SQL Server on the backend. The following two select statements spit out labels and textboxes for a WPF window:

select '<Label Content="' + COLUMN_NAME + '" Grid.Row="1" Grid.Column="0"  Foreground="Azure" />'  from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = 'AutomatedTestImplementation'
select '<TextBox Text="{Binding ' + COLUMN_NAME + ',Mode=TwoWay}" Grid.Row="1" Grid.Column="1" />'  from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = 'AutomatedTestImplementation'

These two statements results in the following code:

<Label Content="ID" Grid.Row="1" Grid.Column="0"  Foreground="Azure" />
 < Label Content="SourceSQL" Grid.Row="1" Grid.Column="0"  Foreground="Azure" />
 < Label Content="TargetSQL" Grid.Row="1" Grid.Column="0"  Foreground="Azure" />
 < Label Content="ResultOperatorId" Grid.Row="1" Grid.Column="0"  Foreground="Azure" />
 < Label Content="ImplementationName" Grid.Row="1" Grid.Column="0"  Foreground="Azure" />
 < Label Content="RequiredData" Grid.Row="1" Grid.Column="0"  Foreground="Azure" />
 < Label Content="ResultDescription" Grid.Row="1" Grid.Column="0"  Foreground="Azure" />
<TextBox Text="{Binding ID,Mode=TwoWay}" Grid.Row="1" Grid.Column="1" />
 < TextBox Text="{Binding SourceSQL,Mode=TwoWay}" Grid.Row="1" Grid.Column="1" />
 < TextBox Text="{Binding TargetSQL,Mode=TwoWay}" Grid.Row="1" Grid.Column="1" />
 < TextBox Text="{Binding ResultOperatorId,Mode=TwoWay}" Grid.Row="1" Grid.Column="1" />
 < TextBox Text="{Binding ImplementationName,Mode=TwoWay}" Grid.Row="1" Grid.Column="1" />
 < TextBox Text="{Binding RequiredData,Mode=TwoWay}" Grid.Row="1" Grid.Column="1" />
 < TextBox Text="{Binding ResultDescription,Mode=TwoWay}" Grid.Row="1" Grid.Column="1" />

 

So, I just pasted that into XAML and change the row definitions and boom I have a databound form.

The following scripts spit out properties for the entities we are using and also some code to wire those entities up.

select 'Public Property ' + COLUMN_NAME + ' as ' + DATA_TYPE from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = 'AutomatedTestImplementation'
select 'Private _' + COLUMN_NAME + ' as ' + DATA_TYPE from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = 'AutomatedTestImplementation'
select '.' + COLUMN_NAME + ' = rw("' + COLUMN_NAME + '")' from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = 'AutomatedTestImplementation'

The output from the 1st statement looks like the following:

Public Property ID as int
 Public Property SourceSQL as varchar
 Public Property TargetSQL as varchar
 Public Property ResultOperatorId as int
 Public Property ImplementationName as varchar
 Public Property RequiredData as varchar
 Public Property ResultDescription as varchar

 

These are small things but they add up to big time savers.

 

Latest posts by Ken Spencer (see all)