Wednesday, January 16, 2013

JSON ISO 8601 date formatting, Kendo MVVM using Kendo templates

Here is a quick tip how to bind to JSON ISO 8601 date.

Parsing and formatting to local date is done using Kendo framework.

	<div data-bind="source: expirationDate" data-template="format-date-template"></div>

	<script id="format-date-template" type="text/x-kendo-template">
	<span>#: kendo.toString(kendo.parseDate(data),"d") #</span>
	</script>

and add the warning icon if expired:

	# if (kendo.parseDate(data) < (new Date())) { #
		<span class="icon warning" title="Expired"><span>
	# } #
Links:
Kendo UI
Kendo Templating
Kendo Globalization Date helpers

Wednesday, April 29, 2009

Parse SQL Connection String in C#

It is actually very easy, but not very popular
SqlConnectionStringBuilder scsb = new SqlConnectionStringBuilder(connectionString);

Then you can alter different properties for example modify timeout to 5 min from default.
scsb.ConnectTimeout = 300;

Finally to use it simply execute
scsb.ToString();

Enjoy
J.

Friday, February 9, 2007

How to set AUTO_CLOSE OFF for all databases in MSDE or SQL Express instance

Inspired by recommendation at SQL Magazine here is the code to set all MSDE or SQL Express databases with AUTO_CLOSE OFF

DECLARE @db SYSNAME
DECLARE @sSQL NVARCHAR(2000)

DECLARE db_cursor CURSOR READ_ONLY FOR
SELECT [name]
FROM master..sysdatabases
WHERE LOWER([name]) NOT IN ('master','pubs','msdb','tempdb','northwind') -- 'model' changed as well for all feature DBs to be OFF

OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @db

WHILE (@@FETCH_STATUS <> -1)
BEGIN
    SET @sSQL = ('ALTER DATABASE ' + QUOTENAME(@db) + N' SET AUTO_CLOSE OFF')
    EXEC sp_executesql @stmt = @sSQL
    FETCH NEXT FROM db_cursor INTO @db
END

CLOSE db_cursor
DEALLOCATE db_cursor


Enjoy!
J.

Wednesday, January 10, 2007

WPF ComboBox automatic onchange ToolTip in XAML only

Is dead simple as this (XAML):

<ComboBox
...
    ToolTip="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=Text}"
...

Enjoy!
J.

How to make simple (Free!) Grid in WPF with XAML from DataSet or DataTable

This is just a concept you can start with to make your own Grid in XAML.

XAML Part:

<ListBox x:Name="tgData"
Grid.Row="1"
IsSynchronizedWithCurrentItem="True"
ItemsSource="{Binding Path=TableOne}"
>
<ListBox.ItemTemplate>
<DataTemplate>
<ListBox
Style="{DynamicResource HorizontalList}"
ItemsSource="{Binding Path=Row.ItemArray}"
>
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Width="100" Text="{Binding}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

XAML Style for Horizontal List for columns:
<Style x:Key="HorizontalList" TargetType="{x:Type ListBox}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<StackPanel Orientation="Horizontal" Panel.IsItemsHost= "True"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

Code Behind (VB.Net):
Dim sConnectionString As String = "Data Source=Kelner;Database=Northwind;Integrated Security=SSPI;"
Dim sQueryString As String = "SELECT * FROM dbo.Customers"

Dim dsCustomer As New DataSet("CustomerData")
Dim conn As SqlClient.SqlConnection = New SqlClient.SqlConnection(sConnectionString)
Dim adapter As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter(sQueryString, conn)

Dim customers As DataSet = New DataSet
adapter.Fill(dsCustomer, "TableOne")
tgData.DataContext = dsCustomer

Enjoy!
J.

Hello World!

My first post I guess!

Hi there. I always wanted to put a place on "the web" where can share some nice trick encountered in my daily work on various software technologies.

So here it is!

Enjoy!
J.