Thursday, September 30, 2010

C Programs 1

program 11:
#include
#include
void main()
{
int a,b;

clrscr();

a = 10; b = 20;
printf("Addition is : %d",a+b);

printf("%s\n","any key is ok for me, Press");
getch();
}


Program 12 :
#include
#include
void main()
{
int first, second;
int add_result;
int multi_result;
int div_result;
int subtract_result;

clrscr();
printf("%s","Enter First Value : "); scanf("%d",&first);
printf("%s","Enter Second Value : "); scanf("%d",&second);

add_result = first + second;
multi_result = first * second;
div_result = first / second;
subtract_result = first - second;

printf("First Value : %d\n",first);
printf("Second Value : %d\n",second);

printf("%s\n","---------------------------------");
printf("Addition result : %d\n",add_result);
printf("Division result : %d\n",div_result);
printf("Subtract result : %d\n",subtract_result);
printf("Multiplication result : %d\n",multi_result);
printf("%s\n","---------------------------------");

printf("%s\n","any key is ok for me, Press");
getch();
}


Program 13 :
#include
#include
void main()
{
int EmpNo = 121;
float Salary = 25000;

clrscr();

printf("%s","Values entered by you are : ");
printf("Employee Number : %d\n",EmpNo);
printf("Salary : %f\n",Salary);

printf("%s\n","any key is ok for me, Press");
getch();
}

Program 14 :
#include
#include
void main()
{
int EmpNo;
float Salary;

clrscr();

printf("%s\n","Enter the following details : ");
printf("%s","Employee Number : "); scanf("%d\n",&EmpNo);
printf("%s","Salary : "); scanf("%f\n",&Salary);

printf("%s","Values entered by you are : ");
printf("%s","Employee Number : "); printf("%d\n",EmpNo);
printf("%s","Salary : "); printf("%f\n",Salary);

printf("%s\n","any key is ok for me, Press");
getch();
}


Program 15 :
#include
#include
void main()
{
int AdmissionNo = 1234;
char[20] StudentName = "Swathi";
int Maths, Physics, Chemistry;
int TotalMarks;

Maths = 87; Physics = 95; Chemistry = 92;
TotalMarks = Maths + Physics + Chemistry;

clrscr();

printf("%s\n","-----------------------------------------------");
printf("%s\n","SRI Y.N.COLLEGE, NARSAPUR, WG DT.");
printf("%s\n","-----------------------------------------------");
printf("Student Admission Number : %s\n",AdmissionNo);
printf("Student Name : %s\n",StudentName);
printf("Maths : %d\n",Maths);
printf("Physics : %d\n",Physics);
printf("Chemistry : %d\n",chemistry);
printf("Total : %d\n",TotalMarks);
printf("%s","-----------------------------------------------");

printf("%s\n","Press any key to back to the application");
getch();
}

Program 16 :
#include
#include
void main()
{
int AdmissionNo;
char[20] StudentName = "Swathi";
int Maths, Physics, Chemistry;
int TotalMarks;
float Percentage;

clrscr();

printf("%s","Enter Student Admission Number "); scanf("%d",&AdmissionNo);
printf("%s","Enter Maths Marks : "); scanf("%d",&Maths);
printf("%s","Enter Physics Marks : "); scanf("%d",&Physics);
printf("%s","Enter Chemistry Marks : "); scanf("%d",&Chemistry);

TotalMarks = Maths + Physics + Chemistry;
Percentage = TotalMarks / 3;

printf("%s\n","-----------------------------------------------");
printf("%s\n","SRI Y.N.COLLEGE, NARSAPUR, WG DT.");
printf("%s\n","-----------------------------------------------");
printf("Student Admission Number : %s\n",AdmissionNo);
printf("Student Name : %s\n",StudentName);
printf("Maths : %d\n",Maths);
printf("Physics : %d\n",Physics);
printf("Chemistry : %d\n",chemistry);
printf("Total : %d\n",TotalMarks);
printf("Percent : %f\n",Percentage);
printf("%s","-----------------------------------------------");

printf("%s\n","Press any key to back to the application");
getch();
}


Program 17 :
#include
#include
void main()
{
int EmpNo;
char[20] EmpName = "Swathi";
float Basic;
float DA;
float HRA;
float SplAllow;
float IncomeTax;
float NetSalary

clrscr();

printf("%s\n","Enter the following details : ");
printf("%s","Employee Number : "); scanf("%d\n",&EmpNo);
printf("%s","Basic Salary : "); scanf("%f\n",&Basic);

DA = Basic * 0.01;
HRA = Basic * 0.01;
SplAllow = Basic * 0.02;
IncomeTax = Basic * 0.05;

NetSalary = (Basic + DA + HRA + SplAllow) - IncomeTax;

printf("%s","-----------------------------------------------");
printf("%s","Values entered by you are : ");
printf("%s","-----------------------------------------------");
printf("%s","Employee Number : "); printf("%d\n",EmpNo);
printf("%s","Employee Name : "); printf("%s\n",EmpName);
printf("%s","Basic Salary : "); printf("%f\n",Basic);
printf("%s","DA : "); printf("%f\n",DA);
printf("%s","HRA : "); printf("%f\n",HRA);
printf("%s","Special Allow : "); printf("%f\n",SplAllow);
printf("%s","Income Tax : "); printf("%f\n",IncomeTax);
printf("%s","-----------------------------------------------");
printf("%s","Net Salary : "); printf("%f\n",NetSalary);
printf("%s","-----------------------------------------------");

printf("%s\n","Press any key to back to the application");
getch();
}



Program 18 :
#include
#include
void main()
{
int radius;

clrscr();

printf("%s","Enter circle radius: "); scanf("%d",&radius);

// perimeter formula is 2 * pi * radius
printf("%s","circle perimeter: "); printf("%d\n",2 * 3.14 * radius);

// area formula is pi * radius * radius
printf("%s","circle Area : "); printf("%d\n", 3.14 * radius * radius);

printf("%s\n","any key is ok for me, Press");
getch();
}

Program 19 :
#include
#include
void main()
{
int radius;
int area, perimeter;
float PI = 3.14; // this is called as a constant value.

clrscr();

printf("%s","Enter circle radius: "); scanf("%d",&radius);

perimeter = 2 * PI * radius;
area = PI * radius * radius

printf("%s","circle perimeter : "); printf("%d\n",perimeter);
printf("%s","circle Area : "); printf("%d\n", area);

printf("%s\n","any key is ok for me, Press");
getch();
}


Program 20 :
#include
#include
void main()
{
int maths;

clrscr();

printf("%s","Enter Mathematics Marks : "); scanf("%d",&maths);

if( maths >= 35)
{
printf("%s\n","Student passed in maths exam")
}
else
{
printf("%s\n","Student failed !!")
}

printf("%s\n","any key is ok for me, Press");
getch();
}

Program 21 :
#include
#include
void main()
{
int percentage;

clrscr();

printf("%s","Enter marks percentage : "); scanf("%d",&percentage);

if( percentage >= 60)
{
printf("%s","Student got first class, He is excellent");
}
else if( percentage >= 50)
{
printf("%s","Student got second class, He is good");
}
else if( percentage >= 35)
{
printf("%s","Student just pass the exam, He is ok");
}
else if( percentage < 35)
{
printf("%s","Student failed the exam, Better luck next time");
}


printf("%s\n","any key is ok for me, Press");
getch();
}

Wednesday, September 29, 2010

C Programs

Program 1 :
#include
#include
void main()
{
printf("%s\n","Hello How are you? ");
printf("%s\n","Welcome to c programming language. ");
printf("%s\n","Write good programs in c");
getch();
}


Program 2 :
#include
#include
void main()
{
printf("%s\n\n\n\n\n","Swathi");
printf("%s\n\n\n\n","Murali");
getch();
// these are single line comment lines


/*
these are multiple line comment lines.
here you can write any matter.
any number of lines can be written like this.
*/
}

Program 3 :
#include
#include
void main()
{
// Comment : \n means next line
// \t means 8 characters(tab)

printf("%s\t%s\n","Swathi","Murali");
printf("%s\t%s\n\n","Sreedhar","KrishnaVeni");
printf("%s\t\t\t\t%s\t%s\n","Sreevathsa","Koundinya","Jitamanyu");
getch();
}


Program 4 :
#include
#include
void main()
{
printf("%s\n","Swathi");
printf("%s\n","");
printf("%s\n","");
printf("%s\n","");
printf("%s\n","");
printf("%s\n","");
printf("%s\n","");
printf("%s\n","");
printf("%s\n","");
printf("%s\n","");
printf("%s\n","");
printf("%s\n","");
printf("%s\n","");
printf("%s\n","");
printf("%s\n","");
printf("%s\n","Murali");
printf("%s\n","Press any key to continue ...");
getch();
}


Program 5 :
#include
#include
void main()
{
// Program 4 and 5 give same output.
printf("%s\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n","Swathi");
printf("%s\n","Murali");
printf("%s\n","Press any key to continue ...");
getch();
}


Program 6 :
#include
#include
void main()
{
printf("%s\n","Swathi,...........................");
printf("%s\n"," ");
printf("%s\n"," ");
printf("%s\n"," ");
printf("%s\n"," I LOVE YOU ");
printf("%s\n"," ");
printf("%s\n"," ");
printf("%s\n"," ");
printf("%s\n"," ");
printf("%s\n"," Murali");

printf("%s\n","Press any key to continue ...");
getch();
}


Program 7 :
#include
#include
void main()
{
int a;
int b = 12;
int EmpNo = 152;
int empno = 256; // int type variable accepts value from zero(0) to 32767.
// negative value are not accepted.

printf("%s\n","the following values are assigned to variables.");

printf("%d",a);
printf("%d",b);
printf("%d",EmpNo);
printf("%d",empno);

printf("%s\n","any key is ok for me, Press");
getch();
}


Program 8 :
#include
#include
void main()
{
int a; int b = 12; int EmpNo = 152; int empno = 256;
printf("%s\n","the following values are assigned to variables.");

printf("%d",a); printf("%d",b); printf("%d",EmpNo); printf("%d",empno);

printf("%s\n","any key is ok for me, Press");
getch();
}


Program 9 :
#include
#include
void main()
{
int a;
int b = 12;
int EmpNo = 152;
int empno = 256;

Empno = 255;
b = 20;

printf("%s\n","the following values are assigned to variables.");

printf("%d\n",a); printf("\n\n\n\n%d\n",b); printf("\n\n\n%d",EmpNo);
printf("\t\n\t%d",empno);

printf("%s\n","any key is ok for me, Press");
getch();
}


Program 10 :
#include
#include
void main()
{
int EmpNo = 152;
int Salary = 25000;

printf("%s\n","---------------------------------------");
printf("%s\n"," Value Labs, Hyderabad");
printf("%s\n"," a CMMi Level 4 software company");
printf("%s\n","---------------------------------------");
printf("%s","Employee Number : "); printf("%d\n",EmpNo);
printf("%s","Salary : ");
printf("%d\n",Salary);
printf("%s\n","---------------------------------------");

printf("%s\n","any key is ok for me, Press");
getch();
}

Tuesday, September 28, 2010

CRUD operations using LINQ

CRUD operations using LINQ
---------------------------
private void Create()
{
NorthwindDataContext db = new NorthwindDataContext();
var products = from p in db.Products where p.CategoryId == 2 select p;

var products = from p in db.Products where p.Category.CategoryName == "Candles"
orderby p.ProductId descending
select new { p.ProductId, p.ProductName, p.Category.CategoryName, Price = p.UnitPrice };

}
here
1) Category table is linked with Product table.
2) Price = .... is called shaping.

private void Insert()
{
NorthwindDataContext db = new NorthwindDataContext();
Product p1 = new Product { CategoryId=1, ProductName='xyz', unitprice=1.23m }; // object initializer
db.Products.InsertOnSubmit(p1);
db.SubmitChanges();

}

private void Update()
{
NorthwindDataContext db = new NorthwindDataContext();
Product p1 = db.Products.First( p => p.ProductName.StartsWith("scott"));
p1.UnitPrice += 1.10m;
db.SubmitChanges();
}

private void Delete()
{
NorthwindDataContext db = new NorthwindDataContext();
Product p1 = db.Products.Single( p => p.ProductName.StartsWith("scott"));
db.Products.DeleteOnSubmit(p1);
db.SubmitChanges();
}

Edmx vs Dbml

Entity framework (EF)
LINQ to SQL (L2S)

Edmx vs Dbml
--------------------
Shouldn't be any difference since they both generate classes that you would expose to the client via RIA services.

RIA - Rich Internet Applications

---------------------------------------------------------------------------------
Category...............LINQ to SQL.............Entity Framework
---------------------------------------------------------------------------------
1.Model................domain model............conceptual data model

2.Databases Supported..as the name indicates:..only variety of databases
SQL server

3.Data Sources.........tables only.............tables, replication, reporting Services,BI and etc

4.Complexity...........simple to use...........complex to use

5.Development Time.....rapid development.......slower development but more capabilities

6.Mapping..............class to single table...class to multiple tables

7.Inheritance..........hard to apply...........simple to apply

8.File Types...........dbml files only.........edmx files after compilation generate 3 xml files to represent the schema: csdl, msl and ssdl
----------------------------------------------------------------------------------------------------
Currently LINQ to SQL has better performance. The ADO.NET team work on the performance issues of entity framework. They posted that when the framework will be released with SP1 of visual studio the performance issue will be better.

When you want to build a data layer there are many choices (and EF and LINQ2SQL are among them). Microsoft recommend the use of EF because they are going to make LINQ2SQL legacy in the future.



There is a big difference between LINQ to SQL and LINQ.
--------------------------------------------------------
LINQ is Language Integrated Query

DataSet : LINQ to DataSet
XML: LINQ to XML
In Memory Objects: LINQ to Objects
ADO.NET Data Services (Astoria) Client: LINQ to Data Services
LINQ to Relational Databases:
LINQ to SQL –
Entity Framework (LINQ to Entities)
There are many other people in the company and broader community working on LINQ solutions to other data sources. We are also excited to see LINQ being applied to many cool new problems beyond the typical data access scenario.

Monday, September 27, 2010

nHibernate fundamentals

1) nHibernate it is a OR/M tool. Hibernate is very popular for Java programmers. Same thing is now available to .NET developers too.

2) ISession class is a unit of work (transactions)

3) ISession is like a ADO.NET dataset

4) session.Add()
Session.Delete()
Session.Flush()

5) ISessionFactory to build a session class.

6) Configuration Class. IsessionFactory uses configuration class to build it.
ISessionFactory sessionFactory = new
Configuration().Configure().buildSessionFactory()

7) In summary.
Configuration Class -> Session Factory -> Session

8) there are two important xsd files exist.
nHibernate-configuration.xsd
nHibernate-mapping.xsd

9) copy the above two files into the below folder inorder to get the intellisense in the web.config file.
c:\program files\microsoft visual studio 9.0\xml\schemas

10) create a DTO library project and create DTO classes for each table

11) create a mapping file. ex:- Customer.hbm.xml this convension is optional. but recommended

12)











Note: 1) column="xyz" is optional.
2) .hbm.xml file has a property.
"Build action" - embedded resources
"copy to output directory"
13)
creat a data access layer project and reference to the following dll's
1) nHibernate.dll
2) log4net.dll
3) isi.collections.dll
4) castle.dynamicProxy.dll

14)

public DataTransfer.Customer GetCustomerById(int customerid)
{
NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration();
config.Configure();
NHibernate.ISessionFactory sessionFactory = config.BuildSessionFactory();
NHibernate.ISession session = sessionFactory.OpenSession();
return (DataTransfer.Customer)session.Get(typeof(DataTransfer.Customer), customerId);
}

15)

return session.Get(customerId);

16)

public DataTransfer.Customer GetCustomerById(int customerid)
{
ISessionFactory sessionFactory = (new Configuration()).configure().BuildSessionFactory();
ISession session = sessionFactory.OpenSession();
return session.Get(customerId);
}

17)

creat a test project. and add a configuration file.
filename is hibernate.cfg.xml



nHibernate.connection.DriverconnectionProvider


false
nHibernate.Dialect.MsSql2005Dialect





18)
SQL statement is shown.
parameterized sql is a protection against SQL injection problem.
SQL injection problem is taken care.
execution plan is maintained due to parameterized sql.
speedy response. SQL Server execution caching techniques.

19) Query choices

1) HQL - hibernate query language
2) Criteria API
3) QBE
4) T-SQL / PL-SQL

20) Object oriented SQL. instead of referring to tables, columns we refer to objects, properties.

select c.Firstname from Customer c.

21)

public IList GetCustomersByFirstname(string firstname)
{
ISession session = GetSession();
return session.CreateQuery("select from Customer c where c.Firstname='" + firstname + "'").List();

return session.CreateQuery("select from customer c where c.Firstname = :fn")
.SetString("fn",firstname)
.List();
}

22)

public IList GetCustomersByFirstnameLastname(string firstname, string lastname)
{
ISession session = GetSession();

return session.CreateQuery("select from customer c where c.Firstname = :fn and c.Lastname = :ln")
.SetString("fn",firstname)
.SetString("ln",lastname)
.List();
}

23)

public IList GetCustomersWithIdGreaterThan(int CustomerId)
{
ISession session = GetSession();

return session.CreateQuery("select from customer c where c.CustomerId > :cid")
.SetInt32("cid",customerid)
.List();
}


24)

public IList CRIT_GetCustomersByFirstname(string firstname)
{
ISession session = GetSession();

return session.CreateCriteria(typeof(Customer))
.Add(new NHibernate.Expression.EqExpression("Firstname",firstname))
.List();
}


25)

public IList CRIT_GetCustomersByFirstnameLastname(string firstname, string lastname)
{
ISession session = GetSession();

return session.CreateCriteria(typeof(Customer))
.Add(new NHibernate.Expression.EqExpression("Firstname",firstname))
.Add(new NHibernate.Expression.EqExpression("Lastname",lastname))
.List();
}

26)

public IList CRIT_GetCustomersWithIdGreaterThan(int CustomerId)
{
ISession session = GetSession();

return session.CreateCriteria(typeof(Customer))
.Add(new NHibernate.Expression.GtExpression("CustomerId",customerid))
.List();
}