Friday, June 15, 2012

Install IIS 7 for windows 7 & vista


1. To open the Windows Features dialog box, click Start, and then click Control Panel
2. In the Control Panel, click Programs


3. Click Turn Windows features on or off.
4. You may receive the Windows Security warning. Click Allow to continue. The Windows Features dialog box is displayed.
 
 5. Expand Internet Information Services. Additional categories of IIS features are displayed. Select Internet Information Services to choose the default features for installation.

6. Expand the additional categories displayed, and select any additional features you want to install, such as Web Management Tools.

 
7. If you are installing IIS 7 for evaluation purposes, you may want to select additional features to install. Select the check boxes for all IIS features you want to install, and then click OK to start installation. 

 
8. The progress indicator appears.


9. When the installation completes, the Windows Features dialog box closes, and the Control Panel is displayed.

 
10. IIS 7 is now installed with a default configuration on Windows Vista or Windows 7. To confirm that the installation succeeded, type the following URL into your browser,  


11. Next, you can use Internet Information Services Manager to manage and configure IIS. To open IIS Manager, click Start, type inetmgr in the Run command box, and then press ENTER.


 

Crystal reports for visuval studio 2010

Tuesday, June 5, 2012

Constructors

Constructors are class methods that are executed when an object of a class or struct is created. They have the same name as the class or struct, and usually initialize the data members of the new object.
A class or struct may have multiple constructors that take different arguments. Constructors enable the programmer to set default values, limit instantiation, and write code that is flexible and easy to read.
If you do not provide a constructor for your object, C# will create one by default that instantiates the object and sets member variables to the default values as listed in Default Values Table (C# Reference). Static classes and structs can also have constructors.
Constructor Overloading :
C# supports overloading of constructors, that means we can have constructors with different set of parameters. So our class can be like this :
public class mySampleClass
{
public mySampleClass()
{
// This is the no parameter constructor method.
// First Constructor
}
public mySampleClass(int Age)
{
// This is the constructor with one parameter.
// Second Constructor
}
public mySampleClass(int Age, string Name)
{
// This is the constructor with two parameters.
// Third Constructor
}
// rest of the class members goes here.
}

Point to remember about constructor

1. A constructor can't be inherited, although a derived class can class the base class constructor.
2. You have to explicitly write a default constructor (see below) while overloading constructors.
3. Concept declaring multiple constructors of a class with different sets of parameters known as constructor overloading.
4. A constructor can call another constructor of the same class using this().

Types of Constructor(basic of parameters):

1. Default constructor: A constructor that takes no parameters is called a default constructor. Default constructors are invoked whenever an object is instantiated by using the new operator and no arguments are provided to new.

2. Parameterized constructor: when we initialize class members during instantiation we can use a parameterized constructor which is similar to a default constructor except with parameters.

The following is a code example:

public class demo
{
public demo()
{
//A default Constructor
}
public demo(String Name)
{
//A parameterized Constructor having one parameter|
}
public demo(String FirstName, String LastName)
{
//A parameterized Constructor having two parameters
}
//Class members
}

When you create a parameterized constructor, we need to also declare a default constructor explicitly.

Access modifier for constructor(Basic of Access Modifier)

1. Public constructor: Constructors are public by default.

2. Private constructor: It is a special instance constructor. It is commonly used in classes that contain static members only. If a class has one or more private constructors and no public constructors, then other classes (except nested classes) are not allowed to create instances of this class.

public class demo
{
private demo()
{
//A default Constructor as private
}
}

So when we will try to create an object of this class, it will generate an error.

I.e. demo object = new demo () //Error

Is there any way to create an object of this class.
We can instantiate the class above by declaring another public constructor that has parameters.

public class demo
{
private demo()
{
//A default Constructor as private
}
public demo(String strName): this()
{
System.Console.WriteLine("Hello Mr. : " + strName);
}
//Class members
}

And now you can initialize an object of this class:
demo object = new demo() , which will work fine.

3. Static Constructor: A static constructor is used to initialize any static data, or to perform an action that needs to be performed only once. It is called automatically before the first instance is created or any static members are referenced.

public class demo
{
static demo()
{
//A static Constructor
// Can only access static members here.
System.Console.WriteLine("I am a static constructor.");
}
}

So when we create an object of this class, "I am a static constructor" gets printed.

Examine the code below as well:

public class demo
{
static demo()
{
//A static Constructor
// Can only access static members here.
System.Console.WriteLine("I am a static constructor.");
}
public demo()
{
//A default Constructor
}
//Class members
}

This example also prints the same result, "I am a static constructor".

Point to remember about static constructor:
1. A static constructor should not be declared with any access modifier.
2. A static constructor does not accept parameters.
3. A static constructor is called automatically.
4. There is no way to call a static constructor directly.

How to call parent class constructor in derived class during inheritance

Answer: It can be achieved by using base().

Example: An Imp. Things Regards calling Sequence of constructors

class Program
{
public class parent
{
public parent ()
{
//A default Constructor
}
public parent (String strName)
{
//A parameterized Constructor having one parameter
}
//Class members
}
public class child : parent
{
public child ()
{
//A default Constructor
}
public child (String strName) : base(strName)
{
//A parameterized Constructor having one parameter
}
//Class members
static void Main()
{
child object1 = new child (); //1*
child object2 = new child ("Vishal Nayan"); //2*
}
}

Sequence is important here in which constructor is called

1. First parent class public constructor, parent() is called then child class public constructor, child()
2. First parent (String strName) and then child (String strName).
 
copy constructor.(does Not Support in C# )
C# does not provide a copy constructor. If you create a new object and want to copy the values from an existing object, you have to write the appropriate method yourself. For example:




What is Polymorphisms?

Another primary concept of object-oriented programming is Polymorphism. It allows you to invoke derived class methods through a base class reference during run-time. This is handy when you need to assign a group of objects to an array and then invoke each of their methods. They won't necessarily have to be the same object type. However, if they're related by inheritance, you can add them to the array as the inherited type. Then if they all share the same method name, that method of each object can be invoked. This lesson will show you how to accomplish this.
OR: A SINGLE ENTITY represents multiple forms depending on the context.
We can divide the polymorphism into 2 types.
1. Static polymorphism (done by Method Overloading- answered after this artical)
2. Dynamic polymorphism (done by Method Over-riding answered after this)

1. Static Polymorphism
In Static Polymorphism, Which method is to be called is decided at compile-time only. Method Overloading is an example of Static Polymorphism.
Method overloading is a concept where we use the same method name many times in the same class, but different parameters. Depending on the parameters we pass, it is decided at compile-time only, which method is to Calles. The same method name with the same parameters is an error and it is a case of duplication of methods which c# does not permits. In Static Polymorphism decision is taken at compile time.
Example: Static Polymorphism
public Class StaticPolyDemo
{
public void display(int x)
{
Console.WriteLine (“Area of a Square:”+x*x);
}
public void display(int x, int y)
{
Console.WriteLine(“Area of a Square:”+x*y);
}
public static void main(String args[])
{
StaticPolyDemo spd=new StaticPolyDemo ();
Spd.display (5);
Spd.display (10, 3);
}
}
2. Dynamic Polymorphism
In this Mechanism by which a call to an overridden function is resolved at a Run-Time( not at Compile-time). If a Base Class contains method must be a Virtual method in C# to be overridden..
Example: Dynamic Polymorphism
Class Test
{
Public virtual void show()
{
Cosnsole.WriteLine (“From base class show method”);
}
}
Public Class DynamicPolyDemo1 : Test
{
Public override void show()
{
Console.WriteLine(“From Demo1 Class show method”);
}
}
Public Class DynamicPolyDemo2: Test
{
Public override void show ()
{
Console.WriteLine (“From Demo2 Class show method”);
}
Public static void main (String args[])
{
Test objtst;
int x;
//take value from users as input
if(x==1)
{
Objtst=new DynamicPolyDemo1();
}
else
Objtst=new DynamicPolyDemo2();
objtst.show();
}
}

Overloading: Define methods with same name , same return type with different parameters or with different datatypes or with different order of parameters.

Over-riding: Re-define method in the sub-class with same signature. One restriction is method modifier can't be more liberal than in parent class. (i.e. private in parent class and public in sub-class).



HOW TO CREATE THE TRIGGER

CREATE TABLE Employee_Test
(
Emp_ID INT Identity,
Emp_name Varchar(100),
Emp_Sal Decimal (10,2)
)
INSERT INTO Employee_Test VALUES ('Anees',1000);
INSERT INTO Employee_Test VALUES ('Rick',1200);
INSERT INTO Employee_Test VALUES ('John',1100);
INSERT INTO Employee_Test VALUES ('Stephen',1300);
INSERT INTO Employee_Test VALUES ('Maria',1400);
CREATE TABLE Employee_Test_Audit
(
Emp_ID int,
Emp_name varchar(100),
Emp_Sal decimal (10,2),
Audit_Action varchar(100),
Audit_Timestamp datetime
)
CREATE TRIGGER trgAfterInsert ON [Employee_Test]
FOR INSERT
AS
declare @empid int;
declare @empname varchar(100);
declare @empsal decimal(10,2);
declare @audit_action varchar(100);
select @empid=i.Emp_ID from inserted i;
select @empname=i.Emp_Name from inserted i;
select @empsal=i.Emp_Sal from inserted i;
set @audit_action='Inserted Record -- After Insert Trigger.';
insert into Employee_Test_Audit
(Emp_ID,Emp_Name,Emp_Sal,Audit_Action,Audit_Timestamp)
values(@empid,@empname,@empsal,@audit_action,getdate());
PRINT 'AFTER INSERT trigger fired.'
GO
insert into Employee_Test values('Chris',1500);