Friday, 25 January 2013

To count numbers of specified values in an array using LINQ.


To count numbers of specified values in an array using LINQ. 

string[] str = { "AA", "DD", "CC", "DD", "EE", "FF", "GG", "AA",                     "KK", "DD" };
            
int nCount = str.Count(m => m.Equals("DD"));


Tuesday, 8 January 2013

Create simple WPF application


Create simple wpf application

Open Visual studio 2010
Click on File menu.. Click on new. Click on Project.. you will get new project pop up window.


Click on Visual C#--> Windows.
Then select WPF Application in side content.



You can also able to change the .Net Framework version.  On the top dropdown list you can see the .Net Framework versions.
To change the project name type what name you want to give.
If you want to change the location click on browser and choose where you want to create the project.
Then click on ok.

You will get WPF application. The screen is look like as below.



In the above screen we can see two windows those are Design and XAML editor window.

Controls are available in toolbox.
Drag button control from toolbox to window.




In XAML Editor Window you can change the properties of controls
In the below screen I change the window Title property as My First Window and Button Content property to Click Me



Double click on Click Me Button, Button Click Event is generated in code file.

The changes in the XAML Editor window you can see the below image.




In code file write the following code to show message.
MessageBox.Show("Welcome to WPF..", "Info", MessageBoxButton.OK);

See image below

















Run the program and in window click on click button you will get message box dialog.  The window is look like below screen.







how to create round edge window in WPF Application?




Following XAML to make round edge window in WPF.



Required windows properties set to 


        WindowStyle="None"
        AllowsTransparency="True"
        Background="Transparent"


Then add border control to in windows content
Border syntax is as follows
<Border Name="windowBorder" BorderThickness="2" BorderBrush="DarkBlue" CornerRadius="20" Background="LightBlue">

  </Border>

If you want to design inside the window add grid control or use other layout control to design what you want to wish.

The all code is shown as below


<Window x:Class="NoneBorder.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Withought Border"
        Height="350" Width="525"
        WindowStyle="None"
        AllowsTransparency="True"
        Background="Transparent">
    <Border Name="windowBorder" BorderThickness="2" BorderBrush="DarkBlue" CornerRadius="20" Background="LightBlue">
        <Grid>
            <Button Content="Close" Height="23" HorizontalAlignment="Right" Margin="0,53,121,0" Name="btnClose" VerticalAlignment="Top" Width="75" Click="btnClose_Click" />
        </Grid>  
    </Border>
</Window>



The window is looks like as follows.







Wednesday, 2 January 2013

Script for to find the identity column in a table



SELECT name AS HasIdentity
FROM syscolumns
WHERE OBJECT_NAME(id) = 'table_Name'
AND COLUMNPROPERTY(id, name, 'IsIdentity') = 1