Tuesday, November 13, 2007

G-Phone

Monday, September 24, 2007

Thursday, September 13, 2007

Var Keyword in C# - .Net 3.5 Orcas Feature

In .Net 3.5 Orcas consist of a keyword called var. This keyword can be used to reference any type in c#. For example,


var name = "raja";
var age = 26;
var single = true;


The compiler will infer the type of the "name", "age" and "single" variables based on the type of their initial assignment value

string name = "raja";
int age = 26;
bool single = true;

What are Extension Methods?

Extension methods allow developers to add new methods to the public contract of an existing CLR type, without having to sub-class it or recompile the original type. Extension Methods help blend the flexibility of "duck typing" support popular within dynamic languages today with the performance and compile-time validation of strongly-typed languages.

Extension Methods enable a variety of useful scenarios, and help make possible the really powerful LINQ query framework that is being introduced with .NET as part of the "Orcas" release.


Simple Email validation class in .Net 3.5 - Orcas Feature

There is a class named EmailValidator in .Net 3.5 to validate email address. This class contain a static method called "IsValid" to validate email string. Sample code given below.

string email = "raja@test.com";

if
( EmailValidator.IsValid(email) ) {

}

There is another way to validate email string.

string email = "raja@test.com";

if
( email.IsValidEmailAddress() ) {

}

Monday, July 30, 2007

VS.PHP



VS.Php is a Php integrated development environment based on Visual Studio. With VS.Php you can design, develop, debug and deploy Php applications within the Visual Studio IDE. VS.Php key features are around providing rich Php and Smarty editing capabilities as well as its ability to debug Php scripts locally as well as remotely.

More.....

Wednesday, July 25, 2007

XmlTextWriter Class Sample

XmlTextWriter xmlWriter = new XmlTextWriter("c:\\menus.xml", null);
xmlWriter.Formatting = Formatting.Indented;

xmlWriter.WriteStartElement("menus");
for (int i = 0; i < 10; i++)
{
xmlWriter.WriteStartElement("menu");
xmlWriter.WriteAttributeString("id", "000000-00000-00000-0000");
xmlWriter.WriteAttributeString("name", "coffee");
xmlWriter.WriteFullEndElement();
}
xmlWriter.Close();

Monday, July 16, 2007

Thursday, July 12, 2007

Tuesday, July 10, 2007

Tuesday, July 03, 2007

Convert CString to LPBYTE

CString str = "la-la-la";
LPBYTE pByte = new BYTE[str.GetLength() + 1];
memcpy(pByte, (VOID*)LPCTSTR(str), str.GetLength());

Monday, July 02, 2007

Saturday, June 30, 2007

Convert LRESULT to LPARAM vc++ win32

LRESULT tt =12;
wchar_t buf[20];
_itow_s(tt,buf,20,10);
LPARAM lp = (LPARAM) buf;

Read key string from registry c++ win32

LPTSTR DStudioRegistry::GetStringValue(HKEY hKey, LPCWSTR key, LPCWSTR string)
{
DWORD dwType, dwSize;
HKEY hSubKey;
KString temp;
LPTSTR result;
BYTE buff[512];
if (RegOpenKeyEx(hKey, key, NULL, KEY_ALL_ACCESS ,&hSubKey)== ERROR_SUCCESS)
{
if (RegQueryValueExW(hSubKey, string , NULL, &dwType, buff, &dwSize) == ERROR_SUCCESS)
{
KString str( (LPCTSTR)buff);

result = str.m_sString;
}
}
RegCloseKey(hKey);
return result;
}

Read DWORD from registry c++ win32

DWORD DStudioRegistry::GetDWORDValue(HKEY hKey1, LPCWSTR key, LPCWSTR string)
{
DWORD dwSavePageSettings = 0;
HKEY hKey = NULL;
REGSAM sam = KEY_READ;
char* pszKey = "Software\\Microsoft\\Raja";

if ( ERROR_SUCCESS != RegOpenKeyEx ( hKey1, key, 0, sam, &hKey)) {

return dwSavePageSettings;

} else {

DWORD dwType = REG_DWORD;
DWORD dwSize = sizeof ( DWORD);
if ( ERROR_SUCCESS != RegQueryValueEx ( hKey, string, NULL, &dwType, ( LPBYTE) &dwSavePageSettings, &dwSize))
{
// error
}
}

RegCloseKey ( hKey);

return dwSavePageSettings;
}

How to convert BYTE array to CString

BYTE x[5];
x[0] = 'A';
x[1] = 0;
x[2] = 'B';
x[3] = 'C';
x[4] = 0;
CString str( (LPCSTR) &x, sizeof(x) );

Tuesday, June 12, 2007

Registry Key Creation using RegCreateKey

HKEY hKey;
LONG iSuccess = RegCreateKeyEx( HKEY_CURRENT_USER, L"SOFTWARE\\Raja", 0L,NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey,0);

Wednesday, June 06, 2007

Windows Mobile 5.0 Tweaks

Make WM5 keep CAB files around after installing (2)

An alternative method of making WM5 keep the original .CAB file around after installing the application is by adding the "/nodelete" option to the Windows CE loader:

HKCR\cabfile\Shell\open\command = 'wceload.exe "%1" /nodelete' (REGSZ string, no quotes)

An alternative method of making WM5 ask where to install a program is by adding the "/askdest" option to the Windows CE loader:

HKCR\cabfile\Shell\open\command = 'wceload.exe "%1" /askdest' (REG_SZ string, no quotes)

Brigthness

[HKEY_CURRENT_USER\ControlPanel\BackLight] - ACBrigthness [Dword] 1-6

[HKEY_CURRENT_USER\ControlPanel\BackLight] - BatteryBrigthness [Dword] 1-6

Show clock in task bar

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shell\TaskBar] LimitedClock [Dword] 0

To hide

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shell\TaskBar] LimitedClock [Dword] 1

Remove operator skin from Phone app to remove

[HKEY_LOCAL_MACHINE\Security\Phone\Skin] Enabled [DWord] 0

To show

[HKEY_LOCAL_MACHINE\Security\Phone\Skin] Enabled [DWord] 1

Crazy Multi-Input Touch Screen

Wednesday, May 30, 2007

How to Soft Reset Windows Mobile 5.0

[DllImport("Coredll.dll")]

extern static int KernelIoControl(int dwIoControlCode,

IntPtr lpInBuf,

int nInBufSize,

IntPtr lpOutBuf,

int nOutBufSize,

ref int lpBytesReturned);

[DllImport("Coredll.dll")]

extern static void SetCleanRebootFlag();

public static void ResetDevice(bool l_Is_HardReset)

{

int IOCTL_HAL_REBOOT = 0x101003C;

int bytesReturned = 0;

if (l_Is_HardReset == true)

{

SetCleanRebootFlag();

}

KernelIoControl(IOCTL_HAL_REBOOT, IntPtr.Zero, 0, IntPtr.Zero, 0, ref bytesReturned);

}



Call this method to reset : ResetDevice(true);

Monday, May 21, 2007

Populating the GridView Control

HTML code of the GridView control so that you will have the idea of what the GridView looks like:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating" OnRowDataBound="GridView1_RowDataBound" Font-Names="Verdana" Font-Size="Small">

<Columns>

<asp:BoundField DataField="CategoryID" HeaderText="CategoryID" />

<asp:BoundField DataField="CategoryName" HeaderText="CategoryName" />

<asp:TemplateField HeaderText="Description">

<ItemTemplate>

<asp:Label ID="Label1" Text='<%# Eval("Description") %>' runat="server" Font-Names="Verdana">asp:Label> <br />

<br />

ItemTemplate>

<EditItemTemplate>

<asp:RequiredFieldValidator ErrorMessage="This field cannot be blank" ControlToValidate="TextBox1" ID="RequiredFieldValidator1" runat="server">asp:RequiredFieldValidator>

<asp:TextBox ID="TextBox1" Width="98%" Text='<%# Eval("Description") %>' runat="server">asp:TextBox>

EditItemTemplate>

asp:TemplateField>

<asp:TemplateField HeaderText="Choose">

<ItemTemplate>

<asp:DropDownList ID="DropDownList1" DataSource='<%# PopulateDropDownList() %>' DataTextField="CategoryName" DataValueField="CategoryName" runat="server" Width="116px">

asp:DropDownList><br />

<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="DropDownList1"

ErrorMessage="Please Select the Item" InitialValue="Select an item">asp:RequiredFieldValidator>

ItemTemplate>

asp:TemplateField>

<asp:CommandField ShowEditButton="True" />

Columns>

asp:GridView>

As you can see that two BoundColumns and two TemplateColumns. The CategoryID and Category Name are the Bound columns which are bound to the "CategoryID" and "CategoryName" fields in the Categories table in Northwind Database. The "Description" and "Choose" columns are template columns. The GridView looks something like this:

If you carefully read the HTML code of the GridView which I have posted above then you will notice one very special thing. The RequiredFieldValidator for the TextBox control in the Description column is placed in the EditItemTemplate of the GridView control. This is because the TextBox is in the EditItemTemplate and that is what we need to validate. If you put the RequiredFieldValidator in any ItemTemplate or any other Template supported by GridView you will recieve an error saying that GridView is unable to find the control to validate.

I have done the same thing with the DropDownList. Since the DropDownList is in the ItemTemplate of the GridView control so I placed the RequiredFieldValidator inside the ItemTemplate right beneath the DropDownList control.

It is a common scenario that you want the first item of the DropDownList to be some message saying "Please select an item". For this you can add the item dynamically inside the GridView_RowDataBound event.

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

{

if (e.Row.RowType == DataControlRowType.DataRow)

{

DropDownList ddList = (DropDownList)e.Row.FindControl("DropDownList1");

ddList.Items[0].Text = "Select an item";

ddList.Items[0].Value = "Select an item";

}

}


Don't forget to assign the value property of the DropDownList to "Select an item" or any other text you like. It is this value that is compared against a RequiredFieldValidator. Now, you can easily set the RequiredFieldValidator's InitialValue property to "Select an item" or whatever your text was which means that you cannot leave the control whose value or text property is "Select an item" or the text set by you.

<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="DropDownList1"

ErrorMessage="Select the Item" InitialValue="Select an item">asp:RequiredFieldValidator>


You will also notice that when you loose focus from the control the validation control event will be fired. This is because the validation controls have a property "EnableClientScript" which means that the validation will be fired on the client side first and then on the server side. If you set EnableClientScript = false then client validation won't be fired and the validation control will wait for Page.Validate event to occur. If Page.Validate does not occur then no validation will be fired.

It is a good idea to keep EnableClientScript enabled so validation can be fired both on the client side as well as the server side.

Wednesday, May 09, 2007

Assign Role to Context User

Add the following lines after created authentication cookie. It will assign role for authenticated context user.

string[] str = new string[1];
str[0] = "User";
HttpContext.Current.User = new GenericPrincipal(User.Identity,str);

you can also assign "str" by getting the user role from the database. After added this coed you can check the authenticated user role like this....

if (HttpContext.Current.User.IsInRole("User"))
{
return true;
}

Above code will return true.

Tuesday, May 08, 2007

SQL Server - First Week Day of month

Follwing steps will explain clearly.

select
GETDATE()
-- Result: 2007-05-08 17:47:56.937

select DATEPART(dd, GETDATE())
-- Result: 8

select DATEADD(dd, - DATEPART(dd, GETDATE())+1, GETDATE())
-- Result: 2007-05-01 17:48:27.123

SELECT DATENAME(dw, DATEADD(dd, - DATEPART(dd, GETDATE()) + 1, GETDATE())) AS FirstDay
-- Result: Tuesday

Thursday, May 03, 2007

Wednesday, May 02, 2007

Rajini : Sivaji









Rajini : Sivaji

OOPS: Reusability

Reusability:

This term refers to the ability for multiple programmers to use the same written and debugged existing class of data. This is a time saving device and adds code efficiency to the language. Additionally, the programmer can incorporate new features to the existing class, further developing the application and allowing users to achieve increased performance. This time saving feature optimizes code, helps in gaining secured applications and facilitates easier maintenance on the application.

The implementation of each of the above object-oriented programming features for C++ will be highlighted in later sections.

OOPS: Overloading

Overloading:

Overloading is one type of Polymorphism. It allows an object to have different meanings, depending on its context. When an exiting operator or function begins to operate on new data type, or class, it is understood to be overloaded.

OOPS: Polymorphism

Polymorphism:

Polymorphism allows routines to use variables of different types at different times. An operator or function can be given different meanings or functions. Polymorphism refers to a single function or multi-functioning operator performing in different ways.

OOPS: Data Encapsulation

Data Encapsulation:

Data Encapsulation combines data and functions into a single unit called Class. When using Data Encapsulation, data is not accessed directly; it is only accessible through the functions present inside the class. Data Encapsulation enables the important concept of data hiding possible.

OOPS: Data Abstraction

Data Abstraction:

Data Abstraction increases the power of programming language by creating user defined data types. Data Abstraction also represents the needed information in the program without presenting the details.

OOPS: Inheritance:

Inheritance:

Inheritance is the process of forming a new class from an existing class or base class. The base class is also known as parent class or super class, The new class that is formed is called derived class. Derived class is also known as a child class or sub class. Inheritance helps in reducing the overall code size of the program, which is an important concept in object-oriented programming.
Classes:

Classes are data types based on which objects are created. Objects with similar properties and methods are grouped together to form a Class. Thus a Class represent a set of individual objects. Characteristics of an object are represented in a class as Properties. The actions that can be performed by objects becomes functions of the class and is referred to as Methods.

For example consider we have a Class of Cars under which Santro Xing, Alto and WaganR represents individual Objects. In this context each Car Object will have its own, Model, Year of Manufacture, Colour, Top Speed, Engine Power etc., which form Properties of the Car class and the associated actions i.e., object functions like Start, Move, Stop form the Methods of Car Class.

No memory is allocated when a class is created. Memory is allocated only when an object is created, i.e., when an instance of a class is created.

Monday, April 30, 2007

Using the Validation Controls in ASP.NET 2.0 > Using the ValidationSummary Control

Using the Validation Controls in ASP.NET 2.0 > Using the ValidationSummary Control: "Using the Validation Controls in ASP.NET 2.0"

polymorphism concept

"polymorphism can be acheived two ways
overloading - static binding/early binding
overriding - dynamic binding/late binding

OVERLOADING
in case of overloading, you will have same method names with different signatures within a class.
display(char arr[])
display(char arr[], int sub)
display(char arr[], char subarr[])
display(char arr[],char subarr[],int sub)

NOTE: return type is not considered. only the method parameters should be different. here, the method to be called is decided at the compile time itself, based on the signature.


OVERRIDING
in case of overriding, a simple example would be of inheritance. in case of inheritance, you have a baseclass/interface and subclasses. here, the method signature (which also can have a method body), exists in base class and same method (without modifying the signature) exists in the subclass also.

interface figure -> draw()
class triangle implements figure -> draw()
class polygon implements figure -> draw()

above you can see an interface which has a method draw() and same has been implemented in triangle and polygon (you can have a base class and do extends also). since the reference of a derived class object can be assigned to a base class reference (OOP concept), you can create objects of triangle and polygon and assign it to the interface reference"

Loves

OOPS : Explain the Polymorphism principle.

OOPS : Explain the Polymorphism principle.: "prolymorphism is the concept of using single entity in many ways according to the users request in the programing structure,Multiple methods are entertained from single category is the nature of the polymorphism."