Friday, October 8, 2010

Jquery1



Friday, October 1, 2010

LINQ Coding

LINQ coding
-------------------------------
//from c in MurSapeliCovers
//join o in MurCompCustomers on new { cid = c.CustomerId, coid=c.CoverId} equals new
//{ cid = o.CustId, coid=o.CoverId} into g
//from o in g.DefaultIfEmpty()
//select new {Cover = c.Cover,
// compNumber = o == null ? 0 : o.CompNumber
// }


from p in MurCompApplications
join o in MurCompCustomers on p.CompNumber equals o.CompNumber
join c in MurSapeliCovers on new { cid = o.CustId, coid=o.CoverId} equals new
{ c.CustomerId = cid, CoverId=coid} into g
from c in g.DefaultIfEmpty()
select new {Cover = c.Cover,
compNumber = o == null ? 0 : o.CompNumber
}

from c in MurSapeliCovers
join o in ( from cu in MurCompCustomers join ca in MurCompApplications
on cu.CompNumber equals ca.CompNumber
select new { CustId = cu.CustId, CoverId = cu.CoverId, CompNumber=ca.CompNumber } )
on new { cid = c.CustomerId, coid=c.CoverId} equals new
{ cid = o.CustId, coid=o.CoverId} into g
from o in g.DefaultIfEmpty()
select new {Cover = c.Cover,
compNumber = o == null ? 0 : o.CompNumber
}


from p in MurCompApplications
join q in MurCompCustomers on p.CompNumber equals q.CompNumber
select new
{
coverid = q.CoverId, compNumber = p.CompNumber
}
///////////////////////////////////
from p in MurCompApplications
join q in MurCompCustomers on p.CompNumber equals q.CompNumber into g
from q in g.DefaultIfEmpty()
select new
{
coverid = q == null ? 0 : q.CoverId,
compNumber = p.CompNumber
}
///////////////////////////////////
from c in MurSapeliCovers
join o in MurCompCustomers on new { cid = c.CustomerId, coid=c.CoverId} equals new
{ cid = o.CustId, coid=o.CoverId} into g
from o in g.DefaultIfEmpty()
select new {Cover = c.Cover,
compNumber = o == null ? 0 : o.CompNumber
}
///////////////////////////////////

from c in MurSapeliCovers
join o in ( from cu in MurCompCustomers join ca in MurCompApplications
on cu.CompNumber equals ca.CompNumber
select new { CustId = cu.CustId, CoverId = cu.CoverId, CompNumber=ca.CompNumber } )
on new { cid = c.CustomerId, coid=c.CoverId} equals new
{ cid = o.CustId, coid=o.CoverId} into g
from o in g.DefaultIfEmpty()
select new {Cover = c.Cover,
compNumber = o == null ? 0 : o.CompNumber
}
from sapelicovers in TblCoverWithCustomerDetails
join compData in
(
from compCust in Comp_Customers
join compApp in Comp_Applications
on compCust.CompNumber equals compApp.Comp_CompNumber.CompNumber
where compApp.Active == true
&& compApp.Comp_TypeDetails.TypeId == 1
&& compApp.Comp_TypeDetails.Code == 1
select new
{
CompNumber = compCust.CompNumber,
CustId = compCust.CustId,
CoverId = compCust.CoverId,
IncidentDate = compApp.IncidentDate,
Active = compApp.Active,
CompTypeId = compApp.Comp_TypeDetails.TypeId,
CompTypeCode = compApp.Comp_TypeDetails.Code
}
)
on
new { coverno = sapelicovers.CoverNo , custid = sapelicovers.CustomerNo }
equals new { coverno = compData.CoverId , custid = compData.CustId }
into outer
from compData in outer.DefaultIfEmpty()
where sapelicovers.CustomerNo == 1
select new
{
Cover = sapelicovers.Cover,
InsuranceNumber = sapelicovers.InsuranceNo,
CompensationNumber = compData == null ? 0 : compData.CompNumber,
StatusCode = sapelicovers.CoverStatus,
EvaluationDate = compData.IncidentDate,
ExpiryReason = sapelicovers.ExpiryReason,
ValidFromDate = sapelicovers.CoverStartDate,
ValidToDate = sapelicovers.CoverEndDate,
SumInsured = sapelicovers.SumInsured,
Bonus = sapelicovers.BonusType,
Benificiary = sapelicovers.BeneficiaryCode
}

from sapelicover in TblCoverWithCustomerDetails
join o in
(
from p in Comp_Customers
join q in Comp_Applications
on p.CompNumber equals q.Comp_CompNumber.CompNumber
where q.Comp_TypeDetails.TypeId == 1
&& q.Comp_TypeDetails.Code == 1
&& p.CompNumber == 10005
&& q.Active == false
select new
{
coverid = p.CoverId,
CompNumber = p.CompNumber,
AddInfoReceivedDate = q.AddInfoReceivedDate,
AppReceivedDate = q.AppReceivedDate,
AddiInfo = q.Comments,
IncidentDate = q.IncidentDate,
CustId = p.CustId,
InsuranceNumber = p.InsuranceId
}
)
on new { coverid = sapelicover.CoverNo, custid = sapelicover.CustomerNo }
equals new { coverid = o.coverid, custid = o.CustId } into outer
from o in outer.DefaultIfEmpty()
where
sapelicover.Active == true
&& sapelicover.CustomerNo == 1
&& sapelicover.CoverNo == 1
select new
{
sapelicover, o
}














C# Expression
-------------
from p in Comp_Applications select p
from p in Comp_Applications select p.CompNumber
from p in Comp_Applications select new{p.RowId,p.CompNumber}
from p in Comp_Applications select new{Comp_Number=p.CompNumber}
from p in Comp_Applications select new{ rowid= p.RowId, comp_number= p.CompNumber}
from p in Comp_Applications where p.RowId > 10 select p
from p in Comp_Applications where p.CompNumber==10011 select p
from p in Comp_Applications where p.RowId > 10 && p.CompNumber==10011 select p
from p in Comp_Applications where p.RowId > 10 || p.CompNumber==10011 select p
from p in Comp_Applications orderby p.CreatedBy,p.CompNumber select p
from p in Comp_Applications group p by p.CreatedBy into g select new{ crea=g.Key}
from p in Comp_Applications group p by p.CreatedBy into g select new{ crea=g.Key, count=g.Count()}


var one = from p in Comp_Applications select p;
var two = from p in Comp_Applications select new{ rowid = p.RowId , compNumber = p.CompNumber };
one.Dump();
two.Dump();

from p in Comp_Applications
select new { p.CompNumber, CompeNumber = p.CompNumber > 10005 && p.CompNumber < 10008 ? 1 :
p.CompNumber > 10009 && p.CompNumber < 10020 ? 0:
p.CompNumber,
recDate = p.AppReceivedDate
}


outer join example:-
============================

create table MurCustomer
(
keyId int, customerName varchar(50)
)
create table MurOrder
(
keyId int, OrderNumber varchar(50)
)
insert into MurCustomer values(1,'xx');
insert into MurCustomer values(2,'yy');
insert into MurCustomer values(3,'zz');
insert into MurCustomer values(4,'aa');
insert into MurCustomer values(5,'bb');

insert into MurOrder values(1,'pppp');
insert into MurOrder values(1,'qqqq');
insert into MurOrder values(4,'rrrr');
insert into MurOrder values(5,'ssss');
insert into MurOrder values(5,'tttt');

select * from MurOrder;
select * from MurCustomer;


from c in MurCustomers
join o in MurOrders on c.KeyId equals o.KeyId into g
from o in g.DefaultIfEmpty()
select new {customerNameDisplay = c.CustomerName,
OrderNumber = o == null ? "(no orders)" : o.OrderNumber}


another example:-
===================
create table MurSapeliCover
(
CustomerId int, CoverId int, Cover varchar(50)
)
create table MurCompApplication
(
CompNumber int
)
create table MurCompCustomer
(
CompNumber int, CustId int, CoverId int
)

insert into MurSapeliCover values(1,1,'First cust 1st Cover');
insert into MurSapeliCover values(1,2,'First cust 2nd Cover');
insert into MurSapeliCover values(1,3,'First cust 3rd Cover');
insert into MurSapeliCover values(1,4,'First cust 4th Cover');

insert into MurSapeliCover values(2,1,'Second cust 1st Cover');
insert into MurSapeliCover values(2,5,'Second cust 2nd Cover');
insert into MurSapeliCover values(3,6,'Third cust 1st Cover');
insert into MurSapeliCover values(4,7,'Fourth cust 1st Cover');

insert into MurCompApplication values(1);
insert into MurCompApplication values(2);
insert into MurCompApplication values(3);

insert into MurCompCustomer values(1,1,1);
insert into MurCompCustomer values(2,1,2);
insert into MurCompCustomer values(3,2,1);


select * from MurSapeliCover;
select * from MurCompCustomer;
select * from MurCompApplication;

from c in MurSapeliCovers
join o in MurCompCustomers on new { cid = c.CustomerId, coid=c.CoverId} equals new
{ cid = o.CustId, coid=o.CoverId} into g
from o in g.DefaultIfEmpty()
select new {Cover = c.Cover,
compNumber = o == null ? 0 : o.CompNumber
}


from c in MurSapeliCovers
join o in ( from cu in MurCompCustomers join ca in MurCompApplications
on cu.CompNumber equals ca.CompNumber
select new { CustId = cu.CustId, CoverId = cu.CoverId, CompNumber=ca.CompNumber } )
on new { cid = c.CustomerId, coid=c.CoverId} equals new
{ cid = o.CustId, coid=o.CoverId} into g
from o in g.DefaultIfEmpty()
select new {Cover = c.Cover,
compNumber = o == null ? 0 : o.CompNumber
}

from p in Comp_Customers where p.CustId == 100
select new { p, p.CompNumber, p.CustId }


ClaimsCRUD.GetCustomerSapeliCovers(request);
*/

Sample LINQ Methods

public void SampleMethod()
{
DTOServices.Claims.Address FromAddress = new Sapeli.DTOServices.Claims.Address();
FromAddress.AddressKey = Guid.NewGuid();
FromAddress.City = "Bangalore";
FromAddress.Country = "India";
FromAddress.PAddress = "Mainroad, Marathahalli";
FromAddress.PostalCode = "560037";


DTOServices.Claims.Address ToAddress = new Sapeli.DTOServices.Claims.Address();

PropertyInfo[] propFrom = FromAddress.GetType().GetProperties();
PropertyInfo[] propTo = ToAddress.GetType().GetProperties();

foreach (PropertyInfo p in propFrom)
{
object value = p.GetValue(FromAddress, new object[] { });
//propTo.SetValue(value, 1);

}


//using (InsuranceEntities ctx = new InsuranceEntities())
//{
// var qry = from efcover in ctx.BeneficiaryItem.Include("Beneficiary").Include("Beneficiary.Cover").Include("BeneficiaryTable")
// where efcover.Beneficiary.Cover.ID == new Guid("") && (efcover.RowStatus == 600 || efcover.RowStatus == 900) &&
// efcover.Beneficiary.OrderInsuredIn == 1
// select efcover;

// var qry1 = from p in ctx.BeneficiaryItem.Include("Beneficiary")
// where p.Beneficiary.Cover.ID == new Guid("") select p;

//}

//using (SapeliPrintEntities ctx = new SapeliPrintEntities())
//{
// var qry = from p in ctx.CaseType.Include("Case")
// where p.Case
//}

//using (SapeliPrintEntities insurancePrint = new SapeliPrintEntities())
//{
// CaseType casetype;


//casetype = (from p in insurancePrint.CaseType.Include("Case")
// where p.ID == new Guid("F471F3AA-6804-4871-9B5F-88237234BF42")
// && p.Case.SelectMany( o => o.CaseCreated.Value.Day < 10)
// select p).FirstOrDefault();

//if (casetype != null)
//{
// //casetype.Case.Where(o => o.CaseCreated.Value.Day < 10);
// //casetype.Case.Load();

// //casetype.Case.Attach( casetype.Case.CreateSourceQuery().Where(o=> o.CaseCreated.Value.Day < 10 ));

// //casetype.CoverItem.Attach(cover.CoverItem.CreateSourceQuery().Where(o => o.RowStatus == 600));
//}


//var roles = from role in ctx.InsuranceRole.Include("InsuranceRoleItem")
// where role.RowStatus == 600 &&
// role.fk_Covers == coverid
// select role;

//foreach (InsuranceRole role in roles)
//{
// role.RowStatus = 900;
// foreach (InsuranceRoleItem item in role.InsuranceRoleItem.Where(o => o.RowStatus == 600))
// {
// item.RowStatus = 900;
// }
//}

//using (Sapeli_InvoiceEntities ctx = new Sapeli_InvoiceEntities())
//{
// IEnumerable invoices = ctx.CreateQuery(query).ToList().DefaultIfEmpty();
// return invoices.ToList();
//}

//var invoice = ctx.Invoice.Include("InvoiceAmount")
// .Where(i => i.InsuranceNo == insuranceNo)
// .Where(i => i.InvoiceStartDate < searchDate)
// .Where(i => i.InvoiceEndDate > searchDate).ToList().DefaultIfEmpty();


//var qry = insurancePrint.CaseType.Where(p => p.CaseCode != "");

//IEnumerable
//objCaseCollection = from p in insurancePrint.CaseType.Include("Case") //.Include("CaseType")
// select p;
//foreach (CaseType objCase in objCaseCollection)
//{

//}

//var qry1 = (from p in insurancePrint.CaseType select p).FirstOrDefault();
//qry1.Case.Load();
//foreach (CaseType obj in objCaseCollection)
//{

//}

//// IEnumerable results = ctx.CreateQuery ("SELECT * FROM [Sapeli_Invoice].[dbo].[Invoice]");

// var qry = from p in insurancePrint.CaseType select p;

// //IEnumerable objFilter = objCaseCollection.Where(p => p.CaseCode == "703");



// //IEnumerable
// //objCaseCollection = from p in insurancePrint.MasterInsurance.Include("InsuranceRole").Include("InsuranceRole.InsuranceRoleItem").Include("InsuranceRole.InsuranceRoleContactInfo")
// // select p;

// foreach (CaseType objCase in objCaseCollection)
//{

//}
//}
}

LINQ terminology

Lazy Loading (or) Deferred Loading
----------------------------------

Refer to : http://dotnetslackers.com/articles/csharp/Load-Lazy-in-LINQ-to-SQL.aspx

Lazy loading indicates the DAL’s ability to load only a portion of the object graph based on some rules. When you add this capability to your DAL, you have implemented the “Lazy Load” pattern (LL).

Lazy loading describes the behavior of an object that doesn’t hold all the data it needs. The object, though, does know how to retrieve missing data on demand. When you load an instance of, say, a Customer entity in a lazy loading model only essential data is loaded—for example, only personal information. Later, when some piece of code needs to go through orders associated with the customer, missing information is located and loaded.


How to disable lazy loading:
----------------------------

NorthwindDataContext ctx = new NorthwindDataContext();
ctx.DeferredLoadingEnabled = false;


Advantage of O/RM (object/relational mapper) tools :
-------------------------

O/RM tools are powerful instruments that save developers a lot of work and are becoming a necessary tool every day. However, you cannot blindly delegate tools the generation of the database code. Make sure you cross-check any T-SQL code and use the SQL profiler extensively during development. If you don’t like the database code being generated, change it. Sometimes you can do better by simply tweaking the O/RM configuration; sometimes you need to manually rewrite the T-SQL code.

Refer to : http://blogs.msdn.com/gblock/archive/2006/10/26/ten-advantages-of-an-orm.aspx


Ten advantages of an ORM (Object Relational Mapper) :
-----------------------------------------------------

1. Facilitates implementing the Domain Model pattern (Thanks Udi). This one reason supercedes all others. In short using this pattern means that you model entities based on real business concepts rather than based on your database structure. ORM tools provide this functionality through mapping between the logical business model and the physical storage model.

2. Huge reduction in code. ORM tools provide a host of services thereby allowing developers to focus on the business logic of the application rather than repetitive CRUD (Create Read Update Delete) logic.

3. Changes to the object model are made in one place. One you update your object definitions, the ORM will automatically use the updated structure for retrievals and updates. There are no SQL Update, Delete and Insert statements strewn throughout different layers of the application that need modification.

4. Rich query capability. ORM tools provide an object oriented query language. This allows application developers to focus on the object model and not to have to be concerned with the database structure or SQL semantics. The ORM tool itself will translate the query language into the appropriate syntax for the database.

5. Navigation. You can navigate object relationships transparently. Related objects are automatically loaded as needed. For example if you load a PO and you want to access it's Customer, you can simply access PO.Customer and the ORM will take care of loading the data for you without any effort on your part.

6. Data loads are completely configurable allowing you to load the data appropriate for each scenario. For example in one scenario you might want to load a list of POs without any of it's child / related objects, while in other scenarious you can specify to load a PO, with all it's child LineItems, etc.

7. Concurrency support. Support for multiple users updating the same data simultaneously.

8. Cache managment. Entities are cached in memory thereby reducing load on the database.

9. Transaction management and Isolation. All object changes occur scoped to a transaction. The entire transaction can either be committed or rolled back. Multiple transactions can be active in memory in the same time, and each transactions changes are isolated form on another.

10. Key Management. Identifiers and surrogate keys are automatically propogated and managed.


If your developing short lifespan applications then it really doesn't matter.

If you're developing long standing enterprise level applications there should be a separation of concerns. The business model should not be running CRUD operations. There should also be persistence ignorance which means loose coupling between ui/model and data access. Why? What happens when MS decides to come out with the next grand data access framework in 4-5 years and linq to sql becomes deprecated? You have to rewrite your most of your app just to use the new framework. If you google the underlined phrases you'll find a lot of information on these subjects.

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();
}