public class NorthWindCustomer
{
   private object customerID;

   private string companyName;
   public string CompanyName
   {
      get { return companyName; }
      set { companyName = value; }
   }

   private string contactName;
   public string ContactName
   {
      get { return contactName; }
      set { contactName = value; }
   }

   private string contactTitle;
   public string ContactTitle
   {
      get { return contactTitle; }
      set { contactTitle = value; }
   }

   private string address;
   public string Address
   {
      get { return address; }
      set { address = value; }
   }

   private string city;
   public string City
   {
      get { return city; }
      set { city = value; }
   }

   private string region;
   public string Region
   {
      get { return region; }
      set { region = value; }
   }

   private string postalCode;
   public string PostalCode
   {
      get { return postalCode; }
      set { postalCode = value; }
   }

   private string country;
   public string Country
   {
      get { return country; }
      set { country = value; }
   }

   private string phone;
   public string Phone
   {
      get { return phone; }
      set { phone = value; }
   }

   private string fax;
   public string Fax
   {
      get { return fax; }
      set { fax = value; }
   }

   public bool Save()
   {
      return true;
   }

   // Domylny konstruktor.
   public NorthWindCustomer()
   {
      this.customerID = DBNull.Value;
      this.companyName = string.Empty;
      this.contactName = string.Empty;
      this.contactTitle = string.Empty;
      this.address = string.Empty;
      this.city = string.Empty;
      this.region = string.Empty;
      this.postalCode = string.Empty;
      this.country = string.Empty;
      this.phone = string.Empty;
      this.fax = string.Empty;
   }

   // Obiekt Business przedstawiajcy dane klienta z bazy danych Northwind.
   public NorthWindCustomer(string customerID)
   {
      string connectionString =
      "Data Source=Brahams;Initial Catalog=Northwind;Integrated Security=True";

      StringBuilder sb =
         new StringBuilder("Select CompanyName, ContactName, ContactTitle,");
      sb.Append(" Address, City, Region, PostalCode, Country, Phone, ");
      sb.Append(" Fax from Customers ");
      sb.Append(" where CustomerID = @customerID");

      // Tworzenie obiektu Connection, inicjalizacja
      // z cigiem znakowym poczenia.
      System.Data.SqlClient.SqlConnection connection =
         new System.Data.SqlClient.SqlConnection(connectionString);

      // Deklaracja obiektu Command dla polece SQL.
      System.Data.SqlClient.SqlCommand command =
         new System.Data.SqlClient.SqlCommand(sb.ToString(), connection);

      SqlParameter param =
         command.Parameters.AddWithValue("@customerID", customerID);
      param.DbType = DbType.String;
      param.Direction = ParameterDirection.Input;
      SqlDataReader dataReader = null;
      try
      {
         connection.Open();
         dataReader = command.ExecuteReader();
         if (dataReader != null && dataReader.Read())
         {
            this.companyName = dataReader["companyName"].ToString();
            this.contactName = dataReader["contactName"].ToString();
            this.contactTitle = dataReader["contactTitle"].ToString();
            this.address = dataReader["address"].ToString();
            this.city = dataReader["city"].ToString();
            this.region = dataReader["region"].ToString();
            this.postalCode = dataReader["postalCode"].ToString();
            this.country = dataReader["country"].ToString();
            this.phone = dataReader["phone"].ToString();
            this.fax = dataReader["fax"].ToString();
         }
         else
         {
            throw new ApplicationException(
               "Nie znaleziono danych klienta o identyfikatorze CustomerID" + customerID);
         }
      }
      finally
      {
         try
         {
            if (dataReader != null)
            {
               dataReader.Close();
            }
            connection.Close();
         }
         catch (SqlException)
         {
            // W tym miejscu obsugujemy wyjtek.
            throw;
         }
      }
   } // Koniec konstruktora.
} // Koniec klasy.
