
using System;

using System.Data;

using System.Configuration;

using System.Data.SqlClient;

using System.Collections.Generic;

namespace ReportViewerLib

{

public class Customer

{

public string strCustomerID;

public string strCompanyName;

public string strContactName;

public string strCountry;

public string CustomerID

{

get

{

return strCustomerID;

}

set

{

strCustomerID = value;

}

}

public string CompanyName

{

get

{

return strCompanyName;

}

set

{

strCompanyName= value;

}

}

public string ContactName

{

get

{

return strContactName;

}

set

{

strContactName= value;

}

}

public string Country

{

get

{

return strCountry;

}

set

{

strCountry= value;

}

}

public static List<Customer> GetCustomersForCountry

( string country)

{

SqlConnection cnn= new SqlConnection(

ConfigurationManager.ConnectionStrings

[ "NorthwindConnectionString"].ConnectionString);

SqlCommand cmd= new SqlCommand();

cmd.Connection=cnn;

cmd.CommandText="select

CustomerID,CompanyName,ContactName,Country

from customers where country=@country";

SqlParameter p= new SqlParameter

( "@country",country);

cmd.Parameters.Add(p);

cnn.Open();

SqlDataReader reader = cmd.ExecuteReader();

List<Customer> list = new List<Customer>();

while (reader.Read())

{

Customer c = new Customer();

c.CustomerID = reader.GetString(0);

c.CompanyName = reader.GetString(1);

c.ContactName = reader.GetString(2);

c.Country = reader.GetString(3);

list.Add(c);

}

cnn.Close();

return list;

}

public static List<Customer> GetAllCustomers()

{

SqlConnection cnn = new SqlConnection(

ConfigurationManager.ConnectionStrings

[ "NorthwindConnectionString"].ConnectionString);

SqlCommand cmd = new SqlCommand();

cmd.Connection = cnn;

cmd.CommandText = "select

CustomerID,CompanyName,ContactName,Country from

customers";

cnn.Open();

SqlDataReader reader = cmd.ExecuteReader();

List<Customer> list = new List<Customer>();

while (reader.Read())

{

Customer c = new Customer();

c.CustomerID = reader.GetString(0);

c.CompanyName = reader.GetString(1);

c.ContactName = reader.GetString(2);

c.Country = reader.GetString(3);

list.Add(c);

}

cnn.Close();

return list;

}

}

}