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.