Thursday, April 30, 2009

Using enum Search Database

Using enum Search Database

This example demonstrates the use of enum.
How this enum is used to set the way to fecth data from the database

Declaring enum



/// this enum will define in which way the search should be made
/// all stats that the parameter should exactly match
/// start states that the vlaue passed should be serched for any value starting with
/// End states that the vlaue passed should be serched for any value ending with
/// Middle states that the vlaue passed should be serched for any value which conatins these charates any where
///

public enum SearchDirection
{
All=0,
Start=1,
End=2,
Middle=3
}


Declaring and Defining the function



///
/// Checks the Field Value whether exist in database or not
///

/// Value to check for
/// Value to check in which field
/// Value to Check in which Table
/// Specifies the search direction
///
public Int32 CheckFieldValue(String fldValue, String fldName,String TblName,SearchDirection SearchDir)
{

String strquery = "";
String str=Enum.GetName(typeof(SearchDirection),SearchDir);
if(((Int32)Enum.Parse(typeof(SearchDirection),str))==0)
{
strquery = "select * from " + TblName + " where " + fldName + " ='" + fldValue + "'";
}
else if (((Int32)Enum.Parse(typeof(SearchDirection), str)) == 1)
{
strquery = "select * from " + TblName + " where " + fldName + " like'" + fldValue + "%'";
}
else if (((Int32)Enum.Parse(typeof(SearchDirection), str)) == 2)
{
strquery = "select * from " + TblName + " where " + fldName + " like'%" + fldValue + "'";
}
else if (((Int32)Enum.Parse(typeof(SearchDirection), str)) == 3)
{
strquery = "select * from " + TblName + " where " + fldName + " like'%" + fldValue + "%'";
}

SqlConnection DBConnection = new SqlConnection();
SqlCommand DBCommand = new SqlCommand();
if (DBConnection.State == ConnectionState.Closed)
{
DBConnection.ConnectionString = "yourConnectionString";
DBConnection.Open();
}
DBCommand.Connection = DBConnection;
DBCommand.CommandText = strquery;
Int32 i=DBCommand.ExecuteNonQuery();
DBConnection.Close();
return i;

}



++
Thanks and Regards
Meetu Choudhary
http://msdotnetmentor.com

Wednesday, April 29, 2009

MVM from DotnetSpider.com

Its a very cool Morning today. I got a call from Gaurav Arora informing me that I got the MVM Award and then foolwed by a mail from Raghav , The webmaster of http//:dotnetspider.com regarding the Most Valuable Member award from Dotnetspider. This is the moment of my dreams come true. Here are the few lines from the mail :

Congratulations from dotnetspider.com! Your contributions to the technology world is recognized by dotnetspider.com, one of the most respected technology community. We are glad to inform you that you are selected as the MOST VALUABLE MEMBER (MVM) for your active participation and contribution to dotnetspider.com. You will be awarded with a certificate of appreciation from us.Visit this page for the list of winners - http://www.dotnetspider.com/credits/Index.aspx
and you can catch the annoucment at
http://www.dotnetspider.com/forum/203217-Winners-MVM-award.aspx

My thanks to DNS family for this award and special thanks to Raghav who showed the faith in me and to Gaurav Arora who have nominated me for this prestigious award.

Sunday, April 26, 2009

How to Scale your entire App and its Elements to your Browsers Size

How to Scale your entire App and its Elements to your Browsers Size



Wow, Today I found the answer of the question "How to Scale your entire App and its Elements to your Browsers Size?" And the answer provided to me is by the silverlight 2.0. I always wonder that how can i scale my application to different browser sizes... and to different screen resolutions I found some PHP sites which were scalable according to the browser size but was unable to handle the same in my ASP.net applications... I have Hear-ed a lot about the silverlight and its applications but never give a thought to it and now finally when my client needs the scalable sites then i have no other option left with me i have to search it and thought to go ahead with silverlight and today only i get all the essentials for the silverlight and started to find the solution and to my wonders i found the solution so simple and easy... Here I would like to share it with you all...

we can achieve it in simple two steps

Step 1:

Add the following line of code to the canvas... in page.xaml....
[code]
< Canvas.RenderTransform >
< ScaleTransform x:Name="CanvasScale" ScaleX="1" ScaleY="1" > < /ScaleTransform >
< /Canvas.RenderTransform >
[/code]

and the example code i took to demonstrate it is
[code]
<
UserControl xmlns:inputToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit" x:Class="SilverlightApplication1.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300" >
< Grid x:Name="LayoutRoot" Background="White" >
< Canvas Height="150" Width="400" Background="Bisque" VerticalAlignment="Center" >
< Canvas.RenderTransform >
< ScaleTransform x:Name="CanvasScale" ScaleX="1" ScaleY="1" > < /ScaleTransform >
< /Canvas.RenderTransform >
< Button x:Name="myButton" Canvas.Top="50"
Canvas.Left="75" Content="Click Me"
Height="37" Width="118" Click="myButton_Click"
ToolTipService.ToolTip ="Click to change above text"/ >
< Button x:Name="myButton1" Canvas.Top="50"
Canvas.Left="195" Content="Click Me"
Height="37" Width="118"/ >
< /Canvas >
< /Grid >
< /
UserControl >
[/code]


Step 2:

Add the following piece of code in the page.xaml.cs
in page()
[code]
App.Current.Host.Content.Resized += new EventHandler(Content_Resized);
[/code]

and the function
[code]
void
Content_Resized(object sender, EventArgs e)
{
double height = App.Current.Host.Content.ActualHeight;
double width = App.Current.Host.Content.ActualWidth;
CanvasScale.ScaleX = width / _startingWidth;
CanvasScale.ScaleY = height / _startingHeight;
}
[/code]

in my example
[code]
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Net;
using
System.Windows;
using
System.Windows.Controls;
using
System.Windows.Documents;
using
System.Windows.Input;
using
System.Windows.Media;
using
System.Windows.Media.Animation;
using
System.Windows.Shapes;
namespace
SilverlightApplication1
{
public partial class Page : UserControl
{
private int _startingWidth = 800;
private int _startingHeight = 600;
public Page()
{
InitializeComponent();
App.Current.Host.Content.Resized += new EventHandler(Content_Resized);
}
private void myButton_Click(object sender, RoutedEventArgs e)
{
}
void Content_Resized(object sender, EventArgs e)
{
double height = App.Current.Host.Content.ActualHeight;
double width = App.Current.Host.Content.ActualWidth;
CanvasScale.ScaleX = width / _startingWidth;
CanvasScale.ScaleY = height / _startingHeight;
}
}
}
[/code]


Test Yourself....
I am sure you will also enjoy as I did.....



Thanks and Regards
Meetu Choudhary

Tuesday, April 7, 2009

Makecer.exe

makecer.exe



makecer.exe is te tool which omes with the visual studio using this tool we can create self signed certificates.



steps once have to follow to create the self signned document



1. open the visual studio command promt

2. type the foolowing command to check the makecer.exe is installed on your system or not 99.9% it is instaled in your system as it is the tool hich vs provieds you

[code]

makecer

[/code]



3. If the above command works then use the following command to create a certificate.



[code]

makecert -sk "MyContainer" -ss MY -r -n "CN=YourCommonName" mycer.cer

[/code]



this will creates an RSA key-pair and a matching certificate in the CurrentUser "MY" certificate store, and also give the output as a public certificate to the file mycer.cer.



The matching private key is placed in the CryptoAPI keycontainer named "MyContainer"(which contains the encrypted private key for this certificate).

The cert is self-signed (-r) and is exportable with private key (-pe).


You can use that keycontainer name (MyContainer) to instantiate a .NET CSP instance too.





++



Thanks and Regards

Meetu Choudhary

http://msdotnetmentor.com

Subscribe via email

Enter your email address:

Delivered by FeedBurner

MSDotnetMentor

MSDotnetMentor My Website http://msdotnetmentor.com