2012년 2월 10일 금요일
최소화(Minimize)Security.cs

using System;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;

/// <summary>
/// Security 클래스 : 보안 관련 클래스
/// </summary>
public class Security
{
 /// <summary>
 /// Encrypt() 메서드 : 문자열 암호화
 /// </summary>
 /// <param name="cleanString">암호화시킬 문자열</param>
 /// <returns>암호화된 문자열</returns>
 public static string Encrypt(string cleanString)
 {
  Byte[] clearBytes =
   new UnicodeEncoding().GetBytes(cleanString);
  Byte[] hashedBytes =
   ((HashAlgorithm) CryptoConfig.CreateFromName("MD5")).ComputeHash(clearBytes);
  
  return BitConverter.ToString(hashedBytes);
 }
}

최소화(Minimize)CustomersDB.cs

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// 고객 상세 정보
/// Customers 테이블과 일대일로 매치되는 클래스
/// </summary>
public class CustomerDetails
{
    public string CustomerName { get; set; } // prop 코드 조각
 public string Phone1 { get; set; }
 public string Phone2 { get; set; }
 public string Phone3 { get; set; }
 public string Mobile1 { get; set; }
 public string Mobile2 { get; set; }
 public string Mobile3 { get; set; }
 public string Zip { get; set; }
 public string Address { get; set; }
 public string AddressDetail { get; set; }
 public string Ssn1 { get; set; }
 public string Ssn2 { get; set; }
 public string EmailAddress { get; set; }
 public int MemberDivision { get; set; }
 //
 public string UserID { get; set; }
 public string Password { get; set; }
 public string BirthYear { get; set; }
 public string BirthMonth { get; set; }
 public string BirthDay { get; set; }
 public string BirthStatus { get; set; }
 public int Gender { get; set; }
 public string Job { get; set; }
 public int Wedding { get; set; }
 public string Hobby { get; set; }
 public string Homepage { get; set; }
 public string Intro { get; set; }
 public int Mailing { get; set; }
 public int VisitCount { get; set; }
 public DateTime LastVisit { get; set; }
 public int Mileage { get; set; }
 public DateTime JoinDate { get; set; }
}
 
/// <summary>
/// 고객 관리
/// </summary>
public class CustomersDB
{
    /// <summary>
    /// 고객 상세 정보 반환 메서드
    /// </summary>
    /// <param name="customerID">고객번호</param>
    /// <returns>모든 고객정보 리스트</returns>
 public CustomerDetails GetCustomerDetails(string customerID)
 {
  SqlConnection objCon =
   new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
  objCon.Open();

  SqlCommand objCmd = new SqlCommand("CustomerDetail", objCon);
  objCmd.CommandType = CommandType.StoredProcedure;

  SqlParameter parameterCustomerID = new SqlParameter("@CustomerID", SqlDbType.Int, 4);
  parameterCustomerID.Value = Int32.Parse(customerID);
  objCmd.Parameters.Add(parameterCustomerID);

  SqlDataReader objDr = objCmd.ExecuteReader(CommandBehavior.CloseConnection);

  CustomerDetails customerDetails = new CustomerDetails();

  while(objDr.Read())
  {
   customerDetails.CustomerName = objDr.GetString(0);
   customerDetails.Phone1 = objDr.GetString(1);
   customerDetails.Phone2 = objDr.GetString(2);
   customerDetails.Phone3 = objDr.GetString(3);
   customerDetails.Mobile1 = objDr.GetString(4);
   customerDetails.Mobile2 = objDr.GetString(5);
   customerDetails.Mobile3 = objDr.GetString(6);
   customerDetails.Zip = objDr.GetString(7);
   customerDetails.Address = objDr.GetString(8);
   customerDetails.AddressDetail = objDr.GetString(9);
   customerDetails.Ssn1 = objDr.GetString(10);
   customerDetails.Ssn2 = objDr.GetString(11);
   customerDetails.EmailAddress = objDr.GetString(12);
   customerDetails.MemberDivision = objDr.GetInt32(13);
   //
   customerDetails.UserID = objDr.GetString(14);
   customerDetails.Password = objDr.GetString(15);
   customerDetails.BirthYear = objDr.GetString(16);
   customerDetails.BirthMonth = objDr.GetString(17);
   customerDetails.BirthDay = objDr.GetString(18);
   customerDetails.BirthStatus = objDr.GetString(19);
   customerDetails.Gender = objDr.GetInt32(20);
   customerDetails.Job = objDr.GetString(21);
   customerDetails.Wedding = objDr.GetInt32(22);
   customerDetails.Hobby = objDr.GetString(23);
   customerDetails.Homepage = objDr.GetString(24);
   customerDetails.Intro = objDr.GetString(25);
   customerDetails.Mailing = objDr.GetInt32(26);
   customerDetails.VisitCount = objDr.GetInt32(27);
   customerDetails.LastVisit = objDr.GetDateTime(28);
   customerDetails.Mileage = objDr.GetInt32(29);
   customerDetails.JoinDate = objDr.GetDateTime(30);
  }
  objDr.Close();

  return customerDetails;
 }

    /// <summary>
    /// 회원 가입 : Customers + Membership
    /// Register.aspx에서 사용
    /// </summary>
    /// <param name="customerDetails">고객 정보 클래스</param>
    /// <returns>고객번호</returns>
 public string AddCustomer(CustomerDetails customerDetails)
 {
  SqlConnection objCon =
   new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
  SqlCommand objCmd = new SqlCommand("CustomerAdd", objCon);

  objCmd.CommandType = CommandType.StoredProcedure;

  // 파라미터 추가
  SqlParameter [] parameters =
  {
   new SqlParameter("@CustomerName",SqlDbType.VarChar, 25),
   new SqlParameter("@Phone1",SqlDbType.VarChar, 4),
   new SqlParameter("@Phone2",SqlDbType.VarChar, 25),
   new SqlParameter("@Phone3",SqlDbType.VarChar, 25),
   new SqlParameter("@Mobile1",SqlDbType.VarChar, 25),
   new SqlParameter("@Mobile2",SqlDbType.VarChar, 25),
   new SqlParameter("@Mobile3",SqlDbType.VarChar, 25),
   new SqlParameter("@EmailAddress",SqlDbType.VarChar, 25),
   new SqlParameter("@MemberDivision",SqlDbType.Int),
   //
   new SqlParameter("@UserID",SqlDbType.VarChar, 25),
   new SqlParameter("@Password",SqlDbType.VarChar, 100),
   new SqlParameter("@Zip",SqlDbType.VarChar, 25),
   new SqlParameter("@Address",SqlDbType.VarChar, 100),
   new SqlParameter("@AddressDetail",SqlDbType.VarChar, 100),
   new SqlParameter("@Ssn1",SqlDbType.VarChar, 6),
   new SqlParameter("@Ssn2",SqlDbType.VarChar, 7),
   new SqlParameter("@BirthYear",SqlDbType.VarChar, 4),
   new SqlParameter("@BirthMonth", SqlDbType.VarChar, 4),
   new SqlParameter("@BirthDay", SqlDbType.VarChar, 4),
   new SqlParameter("@BirthStatus", SqlDbType.VarChar, 2),
   new SqlParameter("@Gender", SqlDbType.Int),
   new SqlParameter("@Job",SqlDbType.VarChar, 25),
   new SqlParameter("@Wedding",SqlDbType.Int),
   new SqlParameter("@Hobby",SqlDbType.VarChar, 100),
   new SqlParameter("@Homepage",SqlDbType.VarChar, 100),
   new SqlParameter("@Intro", SqlDbType.VarChar, 400),
   new SqlParameter("@Mailing", SqlDbType.Int),
   new SqlParameter("@Mileage", SqlDbType.Int),
   new SqlParameter("@CustomerID", SqlDbType.Int, 4)
  };   
  parameters[0].Value = customerDetails.CustomerName;
  parameters[1].Value = customerDetails.Phone1;
  parameters[2].Value = customerDetails.Phone2;
  parameters[3].Value = customerDetails.Phone3;
  parameters[4].Value = customerDetails.Mobile1;
  parameters[5].Value = customerDetails.Mobile2;
  parameters[6].Value = customerDetails.Mobile3;
  parameters[7].Value = customerDetails.EmailAddress;
  parameters[8].Value = 1;
  //
  parameters[9].Value = customerDetails.UserID;
  parameters[10].Value = customerDetails.Password;
  parameters[11].Value = customerDetails.Zip;
  parameters[12].Value = customerDetails.Address;
  parameters[13].Value = customerDetails.AddressDetail;
  parameters[14].Value = customerDetails.Ssn1;
  parameters[15].Value = customerDetails.Ssn2;
  parameters[16].Value = customerDetails.BirthYear;
  parameters[17].Value = customerDetails.BirthMonth;
  parameters[18].Value = customerDetails.BirthDay;
  parameters[19].Value = customerDetails.BirthStatus;
  parameters[20].Value = customerDetails.Gender;
  parameters[21].Value = customerDetails.Job;
  parameters[22].Value = customerDetails.Wedding;
  parameters[23].Value = customerDetails.Hobby;
  parameters[24].Value = customerDetails.Homepage;
  parameters[25].Value = customerDetails.Intro;
  parameters[26].Value = customerDetails.Mailing;
  parameters[27].Value = customerDetails.Mileage;
  parameters[28].Direction = ParameterDirection.Output;

  for(int i = 0;i < parameters.Length;i++)
  {
   objCmd.Parameters.Add(parameters[i]);//파라미터 추가  
  }

  try
  {
   objCon.Open();
   objCmd.ExecuteNonQuery();
   objCon.Close();

   // 저장 프로시저의 Output 파라미터로 부터 값 반환
   int customerId = (int)parameters[25].Value;

   return customerId.ToString();
  }
  catch
  {
   return String.Empty;
  }
 }

    /// <summary>
    /// 회원 로그인
    /// Login.aspx에서 사용
    /// </summary>
    /// <param name="userId">아이디</param>
    /// <param name="password">암호</param>
    /// <returns>정상적으로 로그인하면 고객번호, 그렇지 않으면 null</returns>
 public string Login(string userId, string password)
 {
  SqlConnection objCon =
   new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
  
  SqlCommand objCmd = new SqlCommand("CustomerLogin", objCon);
  objCmd.CommandType = CommandType.StoredProcedure;

  SqlParameter parameterUserID =
   new SqlParameter("@UserID", SqlDbType.NVarChar, 50);
  parameterUserID.Value = userId;
  objCmd.Parameters.Add(parameterUserID);

  SqlParameter parameterPassword =
   new SqlParameter("@Password", SqlDbType.NVarChar, 50);
  parameterPassword.Value = password;
  objCmd.Parameters.Add(parameterPassword);

  SqlParameter parameterCustomerID =
   new SqlParameter("@CustomerID", SqlDbType.Int, 4);
  parameterCustomerID.Direction = ParameterDirection.Output;
  objCmd.Parameters.Add(parameterCustomerID);

  objCon.Open();
  objCmd.ExecuteNonQuery();
  objCon.Close();

  int customerId = (int)(parameterCustomerID.Value);

  if (customerId == 0)
  {
   return null;
  }
  else
  {
   return customerId.ToString();
  }
 }
 
    /// <summary>
    /// CheckOut.aspx에서 사용
    /// 비회원 고객 정보 저장 : Customers
    /// </summary>
    /// <param name="customerDetails">고객 정보 클래스</param>
    /// <returns>고객번호</returns>
 public string AddNonCustomer(CustomerDetails customerDetails)
 {
  // 커넥션
  SqlConnection objCon =
   new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

  // 커멘드
  SqlCommand objCmd = new SqlCommand("NonCustomerAdd", objCon);
  objCmd.CommandType = CommandType.StoredProcedure;

  // 파라미터 추가
  SqlParameter [] parameters =
  {
   new SqlParameter("@CustomerName",SqlDbType.VarChar, 25),
   new SqlParameter("@Phone1",SqlDbType.VarChar, 4),
   new SqlParameter("@Phone2",SqlDbType.VarChar, 25),
   new SqlParameter("@Phone3",SqlDbType.VarChar, 25),
   new SqlParameter("@Mobile1",SqlDbType.VarChar, 25),
   new SqlParameter("@Mobile2",SqlDbType.VarChar, 25),
   new SqlParameter("@Mobile3",SqlDbType.VarChar, 25),
   new SqlParameter("@Zip",SqlDbType.VarChar, 25),
   new SqlParameter("@Address",SqlDbType.VarChar, 100),
   new SqlParameter("@AddressDetail",SqlDbType.VarChar, 100),
   new SqlParameter("@Ssn1",SqlDbType.VarChar, 6),
   new SqlParameter("@Ssn2",SqlDbType.VarChar, 7),
   new SqlParameter("@EmailAddress",SqlDbType.VarChar, 25),
   new SqlParameter("@MemberDivision",SqlDbType.Int),
   new SqlParameter("@CustomerID", SqlDbType.Int)
  };   

  parameters[0].Value = customerDetails.CustomerName;
  parameters[1].Value = customerDetails.Phone1;
  parameters[2].Value = customerDetails.Phone2;
  parameters[3].Value = customerDetails.Phone3;
  parameters[4].Value = customerDetails.Mobile1;
  parameters[5].Value = customerDetails.Mobile2;
  parameters[6].Value = customerDetails.Mobile3;
  parameters[7].Value = customerDetails.Zip;
  parameters[8].Value = customerDetails.Address;
  parameters[9].Value = customerDetails.AddressDetail;
  parameters[10].Value = customerDetails.Ssn1;
  parameters[11].Value = customerDetails.Ssn2;
  parameters[12].Value = customerDetails.EmailAddress;
  parameters[13].Value = 0;//비회원
  parameters[14].Direction = ParameterDirection.Output;

  for(int i = 0;i < parameters.Length;i++)
  {
   objCmd.Parameters.Add(parameters[i]);//파라미터 추가  
  }

  try
  {
   objCon.Open();
   objCmd.ExecuteNonQuery();
   objCon.Close();

   int customerId = (int)parameters[14].Value;

   return customerId.ToString();
  }
  catch
  {
   return String.Empty;
  }
 } 
}

최소화(Minimize)CategoriesDB.cs

using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Microsoft.Practices.EnterpriseLibrary.Data; //

/// <summary>
/// 카테고리 관리 클래스
/// </summary>
public class CategoriesDB
{
    // 카테고리 추가 : CategoryAdd.ascx에서 사용
    public void AddCategory(string categoryName)
    {
        DatabaseFactory.CreateDatabase(
            "ConnectionString").ExecuteNonQuery(
                CommandType.Text,
                    "Insert Into Categories(CategoryName) "
                        + " Values('" + categoryName + "')");
    }
    // 카테고리 반환 : CategoryList.ascx에서 사용
    public DataSet GetCategories()
    {
        return DatabaseFactory.CreateDatabase(
            "ConnectionString").ExecuteDataSet(
                CommandType.Text,
                "Select CategoryID, CategoryName From Categories "
                    + " Order By CategoryID Desc");
    }
}

최소화(Minimize)ProductsDB.cs

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;

/// <summary>
/// 상품의 필드를 구성하는 상품 상세 클래스
/// </summary>
public class ProductDetails
{
    public int ProductID { get; set; }
    public int CategoryID { get; set; }

 //public string  ModelNumber; // public 필드 : X
    public string ModelNumber { get; set; }

    // 상품명
    private string _ModelName;
    public string ModelName
    {
        get { return _ModelName; }
        set { this._ModelName = value; }
    }

    // 제조회사 속성
    public string Company { get; set; }
    public int OriginPrice { get; set; }
    public int SellPrice { get; set; }
    public string EventName { get; set; }
    public string ProductImage { get; set; }
    public string Explain { get; set; }
    public string Description { get; set; }
    public string Encoding { get; set; }
    public int ProductCount { get; set; }
    public DateTime RegistDate { get; set; }
    public int Mileage { get; set; }
    public int Absence { get; set; }
}

public class ProductsDB
{
    /// <summary>
    /// 상품 등록
    /// ProductAdd.aspx에서 사용
    /// </summary>
    /// <param name="product">상품상세 개체</param>
    /// <returns>현재 입력된 상품의 상품번호</returns>
    public int AddProduct(ProductDetails product)
    {
        // Database 클래스의 인스턴스 생성
        Database db = DatabaseFactory.CreateDatabase("ConnectionString");
        // DbCommand 클래스의 인스턴스 생성
        DbCommand dbCommand = db.GetStoredProcCommand("ProductsAdd");
        // 파라미터 추가 : Input/Output
        db.AddInParameter(dbCommand, "CategoryID", DbType.Int32, product.CategoryID);
        db.AddInParameter(dbCommand, "ModelNumber", DbType.String, product.ModelNumber);
        db.AddInParameter(dbCommand, "ModelName", DbType.String, product.ModelName);
        db.AddInParameter(dbCommand, "Company", DbType.String, product.Company);
        db.AddInParameter(dbCommand, "OriginPrice", DbType.Int32, product.OriginPrice);
        db.AddInParameter(dbCommand, "SellPrice", DbType.Int32, product.SellPrice);
        db.AddInParameter(dbCommand, "EventName", DbType.String, product.EventName);
        db.AddInParameter(dbCommand, "ProductImage", DbType.String, product.ProductImage);
        db.AddInParameter(dbCommand, "Explain", DbType.Int32, product.Explain);
        db.AddInParameter(dbCommand, "Description", DbType.String, product.Description);
        db.AddInParameter(dbCommand, "Encoding", DbType.String, product.Encoding);
        db.AddInParameter(dbCommand, "ProductCount", DbType.Int32, product.ProductCount);
        db.AddInParameter(dbCommand, "Mileage", DbType.Int32, product.Mileage);
        db.AddInParameter(dbCommand, "Absence", DbType.Int32, product.Absence);
        db.AddOutParameter(dbCommand, "ProductID", DbType.Int32, 8);
        // 실행
        db.ExecuteNonQuery(dbCommand);
        return Convert.ToInt32(db.GetParameterValue(dbCommand, "ProductID"));
    }

    /// <summary>
    /// 전체 카테고리 리스트
    /// CategoryList.ascx에서 사용
    /// </summary>
    /// <returns>카테고리 리스트</returns>
 public SqlDataReader GetProductCategories()
 {
        #region ADO.NET 클래스 사용
        //SqlConnection objCon =
        //    new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        //objCon.Open();

        //SqlCommand objCmd = new SqlCommand("ProductCategoryList", objCon);
        //objCmd.CommandType = CommandType.StoredProcedure;

        //SqlDataReader result = objCmd.ExecuteReader(CommandBehavior.CloseConnection);

        //return result;
        #endregion
        return (SqlDataReader)DatabaseFactory.CreateDatabase("ConnectionString").ExecuteReader(CommandType.StoredProcedure, "ProductCategoryList");
 }

 /// <summary>
 /// 카테고리에 따른 상품 리스트
 /// ProductsList.aspx에서 사용
 /// </summary>
 /// <param name="intCategoryID">카테고리 번호</param>
 /// <returns>카테고리에 따른 상품 리스트(데이터리더)</returns>
 public SqlDataReader GetProducts(int intCategoryID)
 {
        #region ADO.NET 클래스 사용
        //SqlConnection objCon = new SqlConnection(
        //    ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        //objCon.Open();

        //SqlCommand objCmd = new SqlCommand("ProductsByCategory", objCon);
        //objCmd.CommandType = CommandType.StoredProcedure;

        //SqlParameter parameterCategoryID = new SqlParameter("@CategoryID", SqlDbType.Int, 4);
        //parameterCategoryID.Value = intCategoryID;
        //objCmd.Parameters.Add(parameterCategoryID);

        //SqlDataReader result =
        //    objCmd.ExecuteReader(CommandBehavior.CloseConnection);

        //return result;
        #endregion
        return (SqlDataReader)DatabaseFactory.CreateDatabase("ConnectionString").ExecuteReader("ProductsByCategory", intCategoryID);
 }

 /// <summary>
 /// 상품 상세 정보 반환
 /// ProductDetails.aspx에서 사용
 /// </summary>
 /// <param name="intProductID">상품 번호</param>
 /// <returns>ProductDetails 형식의 데이터</returns>
 public ProductDetails GetProductDetails(int intProductID)
 {
        #region ADO.NET 클래스 사용
        //// 커넥션
        //SqlConnection objCon =
        //    new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

        //// 커멘드
        //SqlCommand objCmd = new SqlCommand("ProductDetail", objCon);
        //objCmd.CommandType = CommandType.StoredProcedure;

        //// 파라미터 추가
        //SqlParameter parameterProductID =
        //    new SqlParameter("@ProductID", SqlDbType.Int, 4);
        //parameterProductID.Value = intProductID;
        //objCmd.Parameters.Add(parameterProductID);

        //SqlParameter parameterOriginPrice =
        //    new SqlParameter("@OriginPrice", SqlDbType.Int, 8);
        //parameterOriginPrice.Direction = ParameterDirection.Output;
        //objCmd.Parameters.Add(parameterOriginPrice);

        //SqlParameter parameterSellPrice =
        //    new SqlParameter("@SellPrice", SqlDbType.Int, 8);
        //parameterSellPrice.Direction = ParameterDirection.Output;
        //objCmd.Parameters.Add(parameterSellPrice);

        //SqlParameter parameterModelNumber =
        //    new SqlParameter("@ModelNumber", SqlDbType.NVarChar, 50);
        //parameterModelNumber.Direction = ParameterDirection.Output;
        //objCmd.Parameters.Add(parameterModelNumber);

        //SqlParameter parameterModelName =
        //    new SqlParameter("@ModelName", SqlDbType.NVarChar, 50);
        //parameterModelName.Direction = ParameterDirection.Output;
        //objCmd.Parameters.Add(parameterModelName);

        //SqlParameter parameterCompany =
        //    new SqlParameter("@Company", SqlDbType.NVarChar, 50);
        //parameterCompany.Direction = ParameterDirection.Output;
        //objCmd.Parameters.Add(parameterCompany);

        //SqlParameter parameterProductImage =
        //    new SqlParameter("@ProductImage", SqlDbType.NVarChar, 50);
        //parameterProductImage.Direction = ParameterDirection.Output;
        //objCmd.Parameters.Add(parameterProductImage);

        //SqlParameter parameterDescription =
        //    new SqlParameter("@Description", SqlDbType.NVarChar, 4000);
        //parameterDescription.Direction = ParameterDirection.Output;
        //objCmd.Parameters.Add(parameterDescription);

        //SqlParameter parameterProductCount =
        //    new SqlParameter("@ProductCount", SqlDbType.Int, 8);
        //parameterProductCount.Direction = ParameterDirection.Output;
        //objCmd.Parameters.Add(parameterProductCount);
  
        //objCon.Open();
        //objCmd.ExecuteNonQuery();
        //objCon.Close();

        //// ProductDetails 형식변수에 저장
        //ProductDetails myProductDetails = new ProductDetails();

        //myProductDetails.ModelNumber = (string)parameterModelNumber.Value;
        //myProductDetails.ModelName = (string)parameterModelName.Value;
        //myProductDetails.Company = (string)parameterCompany.Value;
        //myProductDetails.OriginPrice = (int)parameterOriginPrice.Value;
        //myProductDetails.SellPrice = (int)parameterSellPrice.Value;
        //myProductDetails.ProductImage = ((string)parameterProductImage.Value).Trim();
        //myProductDetails.Description = Convert.ToString(parameterDescription.Value);
        //myProductDetails.ProductCount = (int)parameterProductCount.Value;

        //return myProductDetails; 
        #endregion
        // Database 클래스의 인스턴스 생성
        Database db = DatabaseFactory.CreateDatabase("ConnectionString");
        // DbCommand 클래스의 인스턴스 생성
        DbCommand dbCommand = db.GetStoredProcCommand("ProductDetail");
        // 파라미터 추가 : Input/Output
        db.AddInParameter(dbCommand, "ProductID", DbType.Int32, intProductID);
        db.AddOutParameter(dbCommand, "OriginPrice", DbType.Int32, 8);
        db.AddOutParameter(dbCommand, "SellPrice", DbType.Int32, 8);
        db.AddOutParameter(dbCommand, "ModelNumber", DbType.String, 50);
        db.AddOutParameter(dbCommand, "ModelName", DbType.String, 50);
        db.AddOutParameter(dbCommand, "Company", DbType.String, 50);
        db.AddOutParameter(dbCommand, "ProductImage", DbType.String, 50);
        db.AddOutParameter(dbCommand, "Description", DbType.String, 4000);
        db.AddOutParameter(dbCommand, "ProductCount", DbType.Int32, 8);
        // 실행
        db.ExecuteNonQuery(dbCommand);
        // ProductDetails 형식변수에 저장
        ProductDetails myProductDetails = new ProductDetails();
        myProductDetails.ModelNumber = db.GetParameterValue(dbCommand, "ModelNumber").ToString();
        myProductDetails.ModelName = db.GetParameterValue(dbCommand, "ModelName").ToString();    
        myProductDetails.Company = db.GetParameterValue(dbCommand, "Company").ToString();
        myProductDetails.OriginPrice = Convert.ToInt32(db.GetParameterValue(dbCommand, "OriginPrice"));
        myProductDetails.SellPrice = Convert.ToInt32(db.GetParameterValue(dbCommand, "SellPrice"));
        myProductDetails.ProductImage = db.GetParameterValue(dbCommand, "ProductImage").ToString();
        myProductDetails.Description = db.GetParameterValue(dbCommand, "Description").ToString();
        myProductDetails.ProductCount =
            Convert.ToInt32(db.GetParameterValue(dbCommand, "ProductCount"));
        return myProductDetails; 
    }

    /// <summary>
    /// 이미 구매한 제품과 같이 구매한 상품리스트를 반환
    /// AlsoBought.ascx에서 사용
    /// </summary>
    /// <param name="intProductID">상품번호</param>
    /// <returns>연관 상품 리스트</returns>
 public SqlDataReader GetProductsAlsoPurchased(int intProductID)
 {
        #region ADO.NET 클래스 사용
        //SqlConnection objCon = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        //objCon.Open();

        //SqlCommand objCmd = new SqlCommand("CustomerAlsoBought", objCon);
        //objCmd.CommandType = CommandType.StoredProcedure;

        //SqlParameter parameterProductID = new SqlParameter("@ProductID", SqlDbType.Int, 4);
        //parameterProductID.Value = intProductID;
        //objCmd.Parameters.Add(parameterProductID);

        //SqlDataReader result = objCmd.ExecuteReader(CommandBehavior.CloseConnection);

        //return result;
        #endregion
        return (SqlDataReader)DatabaseFactory.CreateDatabase("ConnectionString").ExecuteReader("CustomerAlsoBought", intProductID);
 }

    /// <summary>
    /// 지난 일주일동안 가장 인기있었던 제품리스트
    /// PopularItems.ascx에서 사용
    /// </summary>
    /// <returns>상품 리스트</returns>
 public SqlDataReader GetMostPopularProductsOfWeek()
 {
        #region ADO.NET 클래스 사용
        //SqlConnection objCon = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        //SqlCommand objCmd = new SqlCommand("ProductsMostPopular", objCon);

        //objCmd.CommandType = CommandType.StoredProcedure;

        //objCon.Open();
        //SqlDataReader result = objCmd.ExecuteReader(CommandBehavior.CloseConnection);

        //return result;
        #endregion
        return (SqlDataReader)DatabaseFactory.CreateDatabase("ConnectionString"
            ).ExecuteReader(CommandType.StoredProcedure, "ProductsMostPopular");
 }

 /// <summary>
 /// 상품 검색 결과 : 넘겨져 온 검색어에 따른 상품리스트
 /// SearchResults.aspx에서 사용
 /// </summary>
 /// <param name="searchString">검색할 상품명</param>
 /// <returns>상품 검색 결과 리스트</returns>
 public SqlDataReader SearchProductDescriptions(string searchString)
 {
        #region ADO.NET 클래스 사용
        //// 커넥션
        //SqlConnection objCon =
        //    new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

        //// 커멘드
        //SqlCommand objCmd = new SqlCommand("ProductSearch", objCon);
        //objCmd.CommandType = CommandType.StoredProcedure;

        //// 파라미터
        //SqlParameter parameterSearch = new SqlParameter("@Search", SqlDbType.NVarChar, 255);
        //parameterSearch.Value = searchString;
        //objCmd.Parameters.Add(parameterSearch);

        //// 명령 실행
        //objCon.Open();
        //SqlDataReader result = objCmd.ExecuteReader(CommandBehavior.CloseConnection);

        //// 데이터리더 개체 반환
        //return result;
        #endregion
        return (SqlDataReader)DatabaseFactory.CreateDatabase("ConnectionString").ExecuteReader("ProductSearch", searchString);
 }
}

최소화(Minimize)ReviewsDB.cs

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;

public class ReviewsDB
{
    /// <summary>
    /// 리뷰(상품평) 리스트 
    /// ReviewList.ascx에서 사용
    /// </summary>
    /// <param name="productID">상품번호</param>
    /// <returns>쿼리스트링으로 넘겨온 상품번호에 해당하는 리뷰 리스트 반환</returns>
 public SqlDataReader GetReviews(int productID)
 {
        #region ADO.NET 클래스 사용
        //SqlConnection objCon = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        //objCon.Open();

        //SqlCommand objCmd = new SqlCommand("ReviewsList", objCon);
        //objCmd.CommandType = CommandType.StoredProcedure;

        //SqlParameter parameterProductID = new SqlParameter("@ProductID", SqlDbType.Int, 4);
        //parameterProductID.Value = productID;
        //objCmd.Parameters.Add(parameterProductID);

        //SqlDataReader result = objCmd.ExecuteReader(CommandBehavior.CloseConnection);

        //return result;
        #endregion
        return (SqlDataReader)DatabaseFactory.CreateDatabase("ConnectionString"
            ).ExecuteReader("ReviewsList", productID);
 }

    /// <summary>
    /// 리뷰 저장
    /// ReviewList.ascx에서 사용
    /// </summary>
    /// <param name="productID">상품번호</param>
    /// <param name="customerName">작성자</param>
    /// <param name="customerEmail">이메일</param>
    /// <param name="rating">점수(1~5)</param>
    /// <param name="comments">코멘트 내용</param>
 public void AddReview(int productID, string customerName, string customerEmail, int rating, string comments)
 {
        #region ADO.NET 클래스 사용
        //SqlConnection objCon = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

        //SqlCommand objCmd = new SqlCommand("ReviewsAdd", objCon);
        //objCmd.CommandType = CommandType.StoredProcedure;

        //SqlParameter parameterProductID =
        //    new SqlParameter("@ProductID", SqlDbType.Int, 4);
        //parameterProductID.Value = productID;
        //objCmd.Parameters.Add(parameterProductID);

        //SqlParameter parameterCustomerName =
        //    new SqlParameter("@CustomerName", SqlDbType.NVarChar, 50);
        //parameterCustomerName.Value = customerName;
        //objCmd.Parameters.Add(parameterCustomerName);

        //SqlParameter parameterEmail =
        //    new SqlParameter("@CustomerEmail", SqlDbType.NVarChar, 50);
        //parameterEmail.Value = customerEmail;
        //objCmd.Parameters.Add(parameterEmail);

        //SqlParameter parameterRating =
        //    new SqlParameter("@Rating", SqlDbType.Int, 4);
        //parameterRating.Value = rating;
        //objCmd.Parameters.Add(parameterRating);

        //SqlParameter parameterComments =
        //    new SqlParameter("@Comments", SqlDbType.NVarChar, 3850);
        //parameterComments.Value = comments;
        //objCmd.Parameters.Add(parameterComments);

        //SqlParameter parameterReviewID =
        //    new SqlParameter("@ReviewID", SqlDbType.Int, 4);
        //parameterReviewID.Direction = ParameterDirection.Output;
        //objCmd.Parameters.Add(parameterReviewID);

        //objCon.Open();
        //objCmd.ExecuteNonQuery();
        //objCon.Close();
        #endregion
        // Database 클래스의 인스턴스 생성
        Database db = DatabaseFactory.CreateDatabase("ConnectionString");
        // DbCommand 클래스의 인스턴스 생성
        DbCommand dbCommand = db.GetStoredProcCommand("ReviewsAdd");
        // 파라미터 추가 : Input/Output
        db.AddInParameter(dbCommand, "ProductID", DbType.Int32, productID);
        db.AddInParameter(dbCommand, "CustomerName", DbType.String, customerName);
        db.AddInParameter(dbCommand, "CustomerEmail", DbType.String, customerEmail);
        db.AddInParameter(dbCommand, "Rating", DbType.Int32, rating);
        db.AddInParameter(dbCommand, "Comments", DbType.String, comments);
        db.AddOutParameter(dbCommand, "ReviewID", DbType.Int32, 8);
        // 실행
        db.ExecuteNonQuery(dbCommand);
        // 반환
        // return Convert.ToInt32(db.GetParameterValue(dbCommand, "ReViewID"));
 }
}

최소화(Minimize)ShoppingCartDB.cs

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;

public class ShoppingCartDB
{
 /// <summary>
 /// 현재 접속자에게 고유한 키값을 반환
    /// AddToCart.aspx에서 사용
 /// </summary>
 /// <returns>고유한 문자열(인증값(CustomerID/UserID), 랜덤값(GUID))</returns>
 public string GetShoppingCartId()
 {
  // HttpContext 개체 생성
  System.Web.HttpContext context = System.Web.HttpContext.Current;

  // 인증된 사용자
  if (!String.IsNullOrEmpty(context.User.Identity.Name))
  {
   return context.User.Identity.Name; // 인증된 사용자명을 입력
  }

  // 인증되지 않은 사용자이지만, 쿠키값이 있다면,
  if (context.Request.Cookies["Shopping_CartID"] != null)
  {
   return context.Request.Cookies["Shopping_CartID"].Value;
  }
  else
  {
   // 랜덤함 GUID 값 생성
   Guid tempCartId = Guid.NewGuid();

   // 쿠키에 tempCartId 값 저장
   context.Response.Cookies["Shopping_CartID"].Value = tempCartId.ToString();

   // tempCartId 반환
   return tempCartId.ToString();
  }
 }

 /// <summary>
 /// 장바구니 담기
    /// AddToCart.aspx에서 사용
    /// </summary>
 /// <param name="cartID">누가</param>
 /// <param name="productID">어떤 제품</param>
 /// <param name="quantity">수량</param>
 public void AddItem(string cartID, int productID, int quantity)
 {
        #region ADO.NET 클래스 사용
        //SqlConnection objCon = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

        //SqlCommand objCmd = new SqlCommand("ShoppingCartAddItem", objCon);
        //objCmd.CommandType = CommandType.StoredProcedure;

        //SqlParameter parameterCartID = new SqlParameter("@CartID", SqlDbType.NVarChar, 50);
        //parameterCartID.Value = cartID;
        //objCmd.Parameters.Add(parameterCartID);

        //SqlParameter parameterProductID = new SqlParameter("@ProductID", SqlDbType.Int, 4);
        //parameterProductID.Value = productID;
        //objCmd.Parameters.Add(parameterProductID);

        //SqlParameter parameterQuantity = new SqlParameter("@Quantity", SqlDbType.Int, 4);
        //parameterQuantity.Value = quantity;
        //objCmd.Parameters.Add(parameterQuantity);

        //objCon.Open();
        //objCmd.ExecuteNonQuery();
        //objCon.Close();
        #endregion
        DatabaseFactory.CreateDatabase(
            "ConnectionString").ExecuteNonQuery("ShoppingCartAddItem"
                , cartID, productID, quantity);
 }

 /// <summary>
 /// 현재 접속자의 장바구니에 들어있는 상품 개수
    /// ShoppingCart.aspx에서 사용
    /// </summary>
 /// <param name="cartID">현재접속자(회원/비회원)</param>
 /// <returns>상품 개수</returns>
 public int GetItemCount(string cartID)
 {
        #region ADO.NET 클래스 사용
        //SqlConnection objCon = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
       
        //SqlCommand objCmd = new SqlCommand("ShoppingCartItemCount", objCon);
        //objCmd.CommandType = CommandType.StoredProcedure;

        //SqlParameter parameterCartID = new SqlParameter("@CartID", SqlDbType.NVarChar, 50);
        //parameterCartID.Value = cartID;
        //objCmd.Parameters.Add(parameterCartID);

        //SqlParameter parameterItemCount = new SqlParameter("@ItemCount", SqlDbType.Int, 4);
        //parameterItemCount.Direction = ParameterDirection.Output;
        //objCmd.Parameters.Add(parameterItemCount);

        //objCon.Open();
        //objCmd.ExecuteNonQuery();
        //objCon.Close();

        //// 항목 수 반환
        //return ((int)parameterItemCount.Value);
        #endregion
        // Database 클래스의 인스턴스 생성
        Database db = DatabaseFactory.CreateDatabase("ConnectionString");
        // DbCommand 클래스의 인스턴스 생성
        DbCommand dbCommand = db.GetStoredProcCommand("ShoppingCartItemCount");
        // 파라미터 추가 : Input/Output
        db.AddInParameter(dbCommand, "CartID", DbType.String, cartID);
        db.AddOutParameter(dbCommand, "ItemCount", DbType.Int32, 8);
        // 실행
        db.ExecuteNonQuery(dbCommand);
        // 반환
        return Convert.ToInt32(db.GetParameterValue(dbCommand, "ItemCount"));
 }

 /// <summary>
 /// 현재 접속자의 장바구니 리스트
    /// ShoppingCart.aspx에서 사용
    /// </summary>
 /// <param name="cartID">현재접속자</param>
 /// <returns>데이터리더 개체</returns>
 public SqlDataReader GetItems(string cartID)
 {
        #region ADO.NET 클래스 사용
        //SqlConnection objCon = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        //objCon.Open();

        //SqlCommand objCmd = new SqlCommand("ShoppingCartList", objCon);
        //objCmd.CommandType = CommandType.StoredProcedure;

        //SqlParameter parameterCartID = new SqlParameter("@CartID", SqlDbType.NVarChar, 50);
        //parameterCartID.Value = cartID;
        //objCmd.Parameters.Add(parameterCartID);

        //SqlDataReader result = objCmd.ExecuteReader(CommandBehavior.CloseConnection);

        //return result;
        #endregion
        return (SqlDataReader)DatabaseFactory.CreateDatabase(
            "ConnectionString").ExecuteReader("ShoppingCartList", cartID);
 }

 /// <summary>
 /// 장바구니 수정
    /// ShoppingCart.aspx에서 사용 
    /// </summary>
 /// <param name="cartID">현재접속자</param>
 /// <param name="productID">현재상품</param>
 /// <param name="quantity">수량</param>
 public void UpdateItem(string cartID, int productID, int quantity)
 {
  if (quantity < 0)
  {
   throw new Exception("수량은 0이상이어야 합니다.");
  }

        #region ADO.NET 클래스 사용
        //SqlConnection objCon = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

        //SqlCommand objCmd = new SqlCommand("ShoppingCartUpdate", objCon);
        //objCmd.CommandType = CommandType.StoredProcedure;

        //SqlParameter parameterCartID = new SqlParameter("@CartID", SqlDbType.NVarChar, 50);
        //parameterCartID.Value = cartID;
        //objCmd.Parameters.Add(parameterCartID);

        //SqlParameter parameterProductID = new SqlParameter("@ProductID", SqlDbType.Int, 4);
        //parameterProductID.Value = productID;
        //objCmd.Parameters.Add(parameterProductID);

        //SqlParameter parameterQuantity = new SqlParameter("@Quantity", SqlDbType.Int, 4);
        //parameterQuantity.Value = quantity;
        //objCmd.Parameters.Add(parameterQuantity);

        //objCon.Open();
        //objCmd.ExecuteNonQuery();
        //objCon.Close();
        #endregion
        DatabaseFactory.CreateDatabase("ConnectionString").ExecuteNonQuery(
            "ShoppingCartUpdate", cartID, productID, quantity);
 }

 /// <summary>
 /// 선택한 상품 지우기
    /// ShoppingCart.aspx에서 사용
    /// </summary>
 /// <param name="cartID">현재 접속자</param>
 /// <param name="productID">상품번호</param>
 public void RemoveItem(string cartID, int productID)
 {
        #region ADO.NET 클래스 사용
        //SqlConnection objCon = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

        //SqlCommand objCmd = new SqlCommand("ShoppingCartRemoveItem", objCon);
        //objCmd.CommandType = CommandType.StoredProcedure;

        //SqlParameter parameterCartID = new SqlParameter("@CartID", SqlDbType.NVarChar, 50);
        //parameterCartID.Value = cartID;
        //objCmd.Parameters.Add(parameterCartID);

        //SqlParameter parameterProductID = new SqlParameter("@ProductID", SqlDbType.Int, 4);
        //parameterProductID.Value = productID;
        //objCmd.Parameters.Add(parameterProductID);

        //objCon.Open();
        //objCmd.ExecuteNonQuery();
        //objCon.Close();
        #endregion
        DatabaseFactory.CreateDatabase("ConnectionString").ExecuteNonQuery(
            "ShoppingCartRemoveItem", cartID, productID);
 }

 /// <summary>
 /// 현재 장바구니의 총 금액
    /// ShoppingCart.aspx에서 사용
    /// </summary>
 /// <param name="cartID">현재접속자</param>
 /// <returns>장바구니에 담긴 상품의 가격 총 합계</returns>
 public int GetTotal(string cartID)
 {
        #region ADO.NET 클래스 사용
        //SqlConnection objCon =
        //    new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

        //SqlCommand objCmd = new SqlCommand("ShoppingCartTotal", objCon);
        //objCmd.CommandType = CommandType.StoredProcedure;

        //SqlParameter parameterCartID = new SqlParameter("@CartID", SqlDbType.NVarChar, 50);
        //parameterCartID.Value = cartID;
        //objCmd.Parameters.Add(parameterCartID);

        //SqlParameter parameterTotalCost = new SqlParameter("@TotalCost", SqlDbType.Int, 8);
        //parameterTotalCost.Direction = ParameterDirection.Output;
        //objCmd.Parameters.Add(parameterTotalCost);

        //objCon.Open();
        //objCmd.ExecuteNonQuery();
        //objCon.Close();

        //// Total 값 반환
        //if (parameterTotalCost.Value.ToString() != "")
        //{
        //    return (int)parameterTotalCost.Value;
        //}
        //else
        //{
        //    return 0;
        //}
        #endregion
        // Database 클래스의 인스턴스 생성
        Database db = DatabaseFactory.CreateDatabase("ConnectionString");
        // DbCommand 클래스의 인스턴스 생성
        DbCommand dbCommand = db.GetStoredProcCommand("ShoppingCartTotal");
        // 파라미터 추가 : Input/Output
        db.AddInParameter(dbCommand, "CartID", DbType.String, cartID);
        db.AddOutParameter(dbCommand, "TotalCost", DbType.Int32, 8);
        // 실행
        db.ExecuteNonQuery(dbCommand);
        // 반환
        return Convert.ToInt32(db.GetParameterValue(dbCommand, "TotalCost"));
 }

 /// <summary>
 /// 장바구니 담고나서 로그인할 때 장바구니 테이블 업데이트
    /// ShoppingCart.aspx에서 사용
    /// </summary>
 /// <param name="oldCartId">고유한 문자열/로그인하기 전에 받은 세션ID</param>
 /// <param name="newCartId">회원 아이디</param>
 public void MigrateCart(string oldCartId, string newCartId)
 {
        #region ADO.NET 클래스 사용
        //SqlConnection objCon = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        //SqlCommand objCmd = new SqlCommand("ShoppingCartMigrate", objCon);

        //objCmd.CommandType = CommandType.StoredProcedure;

        //SqlParameter cart1 = new SqlParameter("@OriginalCartId ", SqlDbType.NVarChar, 50);
        //cart1.Value = oldCartId;
        //objCmd.Parameters.Add(cart1);

        //SqlParameter cart2 = new SqlParameter("@NewCartId ", SqlDbType.NVarChar, 50);
        //cart2.Value = newCartId;
        //objCmd.Parameters.Add(cart2);

        //objCon.Open();
        //objCmd.ExecuteNonQuery();
        //objCon.Close();
        #endregion
        DatabaseFactory.CreateDatabase("ConnectionString").ExecuteNonQuery(
            "ShoppingCartMigrate", oldCartId, newCartId);
 }

 /// <summary>
 /// 현재 접속자의 장바구니 전체 비우기
    /// ShoppingCart.aspx에서 사용
    /// </summary>
 /// <param name="cartID">현재 접속자</param>
 public void EmptyCart(string cartID)
 {
        #region ADO.NET 클래스 사용
        //SqlConnection objCon = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

        //SqlCommand objCmd = new SqlCommand("ShoppingCartEmpty", objCon);
        //objCmd.CommandType = CommandType.StoredProcedure;

        //SqlParameter cartid = new SqlParameter("@CartID", SqlDbType.NVarChar, 50);
        //cartid.Value = cartID;
        //objCmd.Parameters.Add(cartid);

        //objCon.Open();
        //objCmd.ExecuteNonQuery();
        //objCon.Close();
        #endregion
        #region Enterprise Library
     DatabaseFactory.CreateDatabase("ConnectionString").ExecuteNonQuery(
            "ShoppingCartEmpty", cartID);
     #endregion 
    }
}

최소화(Minimize)OrdersDB.cs

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// 주문 상세 정보 제공 클래스
/// Orders테이블과 일대일로 매치되는 클래스
/// </summary>
public class OrderDetails
{
 //public string CustomerID; //[1] public한 필드 : 권장하지 않음
    //private string _CustomerID; //[2] private한 필드 + public한 속성
    //public string CustomerID
    //{
    //    get { return _CustomerID; }
    //    set { _CustomerID = value; }
    //}
    public string CustomerID { get; set; } //[3] .NET 3.X 버전 이상에서의 속성
    public DateTime OrderDate { get; set; }
    public DateTime ShipDate { get; set; }
    public int TotalPrice { get; set; }
 public string OrderStatus { get; set; }
 public string Payment { get; set; }
 public int PaymentPrice { get; set; }
 public string PaymentInfo { get; set; }
 public DateTime PaymentEndDate { get; set; }
 public int DeliveryInfo { get; set; }
 public string DeliveryStatus { get; set; }
 public DateTime DeliveryEndDate { get; set; }
 public string OrderIP { get; set; }
 public string Password { get; set; }
 //
 public string CartID { get; set; }
 //
 public string Message { get; set; }
 //
 public string CustomerName { get; set; }
 public string TelePhone { get; set; }
 public string MobilePhone { get; set; }
 public string ZipCode { get; set; }
 public string Address { get; set; }
 public string AddressDetail { get; set; }
 //
 public DataSet OrderItems { get; set; } // 주문 항목
}

/// <summary>
/// 주문 처리 클래스
/// </summary>
public class OrdersDB
{
    /// <summary>
    /// 주문 처리 완료 : orders 테이블에 데이터 저장
    /// CheckOut.aspx에서 사용 : 주문 실행
    /// </summary>
    /// <param name="orderDetails">주문테이블 정보</param>
    /// <returns>주문번호(고유번호)</returns>
 public int PlaceOrder(OrderDetails orderDetails)
 {
  // 커넥션
  SqlConnection objCon =
   new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

  // 커멘드
  SqlCommand objCmd = new SqlCommand("OrdersAdd", objCon);
  // 커멘드 타입
  objCmd.CommandType = CommandType.StoredProcedure;

  // 고객코드
  SqlParameter parameterCustomerID =
   new SqlParameter("@CustomerID", SqlDbType.Int, 4);
  parameterCustomerID.Value = orderDetails.CustomerID;
  objCmd.Parameters.Add(parameterCustomerID);
  // 주문일자
  SqlParameter parameterOrderDate =
   new SqlParameter("@OrderDate", SqlDbType.DateTime, 8);
  parameterOrderDate.Value = DateTime.Now;
  objCmd.Parameters.Add(parameterOrderDate);
  // 배송일자
  SqlParameter parameterShipDate =
   new SqlParameter("@ShipDate", SqlDbType.DateTime, 8);
  parameterShipDate.Value = CalculateShippingDate();
  objCmd.Parameters.Add(parameterShipDate);
  // 주문총금액
  SqlParameter parameterTotalPrice =
   new SqlParameter("@TotalPrice", SqlDbType.Int, 4);
  parameterTotalPrice.Value = orderDetails.TotalPrice;
  objCmd.Parameters.Add(parameterTotalPrice);
  // 주문상태
  SqlParameter parameterOrderStatus =
   new SqlParameter("@OrderStatus", SqlDbType.VarChar, 20);
  parameterOrderStatus.Value = orderDetails.OrderStatus;
  objCmd.Parameters.Add(parameterOrderStatus);
  // 결제방법
  SqlParameter parameterPayment =
   new SqlParameter("@Payment", SqlDbType.VarChar, 20);
  parameterPayment.Value = orderDetails.Payment;
  objCmd.Parameters.Add(parameterPayment);
  // 결제금액
  SqlParameter parameterPaymentPrice =
   new SqlParameter("@PaymentPrice", SqlDbType.Int, 4);
  parameterPaymentPrice.Value = orderDetails.PaymentPrice;
  objCmd.Parameters.Add(parameterPaymentPrice);
  // 결제상태
  SqlParameter parameterPaymentInfo =
   new SqlParameter("@PaymentInfo", SqlDbType.VarChar, 20);
  parameterPaymentInfo.Value = orderDetails.PaymentInfo;
  objCmd.Parameters.Add(parameterPaymentInfo);
  // 결제완료일
  SqlParameter parameterPaymentEndDate =
   new SqlParameter("@PaymentEndDate", SqlDbType.DateTime, 8);
  parameterPaymentEndDate.Value = DateTime.Now;//orderDetails.PaymentEndDate;//관리자 계산
  objCmd.Parameters.Add(parameterPaymentEndDate);
  // 배송지구분
  SqlParameter parameterDeliveryInfo =
   new SqlParameter("@DeliveryInfo", SqlDbType.Int, 4);
  parameterDeliveryInfo.Value = orderDetails.DeliveryInfo;
  objCmd.Parameters.Add(parameterDeliveryInfo);
  // 배송상태
  SqlParameter parameterDeliveryStatus =
   new SqlParameter("@DeliveryStatus", SqlDbType.VarChar, 20);
  parameterDeliveryStatus.Value = orderDetails.DeliveryStatus;
  objCmd.Parameters.Add(parameterDeliveryStatus);
  // 거래완료일자
  SqlParameter parameterDeliveryEndDate =
   new SqlParameter("@DeliveryEndDate", SqlDbType.DateTime, 8);
  parameterDeliveryEndDate.Value = DateTime.Now;//orderDetails.DeliveryEndDate;//관리자 계산
  objCmd.Parameters.Add(parameterDeliveryEndDate);
  // 주문자아이피주소
  SqlParameter parameterOrderIP =
   new SqlParameter("@OrderIP", SqlDbType.VarChar, 15);
  parameterOrderIP.Value = orderDetails.OrderIP;
  objCmd.Parameters.Add(parameterOrderIP);
  // 주문비밀번호
  SqlParameter parameterPassword =
   new SqlParameter("@Password", SqlDbType.VarChar, 20);
  parameterPassword.Value = orderDetails.Password;
  objCmd.Parameters.Add(parameterPassword);
  // 쇼핑카트 번호
  SqlParameter parameterCartID =
   new SqlParameter("@CartID", SqlDbType.VarChar, 50);
  parameterCartID.Value = orderDetails.CartID;
  objCmd.Parameters.Add(parameterCartID);
  // 남길 메모
  SqlParameter parameterMessage =
   new SqlParameter("@Message", SqlDbType.VarChar, 50);
  parameterMessage.Value = orderDetails.Message;
  objCmd.Parameters.Add(parameterMessage);
  // 배송자 이름
  SqlParameter parameterCustomerName =
   new SqlParameter("@CustomerName", SqlDbType.VarChar, 50);
  parameterCustomerName.Value = orderDetails.CustomerName;
  objCmd.Parameters.Add(parameterCustomerName);
  // 배송지 전화번호
  SqlParameter parameterTelePhone =
   new SqlParameter("@TelePhone", SqlDbType.VarChar, 20);
  parameterTelePhone.Value = orderDetails.TelePhone;
  objCmd.Parameters.Add(parameterTelePhone);
  // 배송지 휴대폰번호
  SqlParameter parameterMobilePhone =
   new SqlParameter("@MobilePhone", SqlDbType.VarChar, 20);
  parameterMobilePhone.Value = orderDetails.MobilePhone;
  objCmd.Parameters.Add(parameterMobilePhone);
  // 배송지 우편번호
  SqlParameter parameterZipCode =
   new SqlParameter("@ZipCode", SqlDbType.VarChar, 7);
  parameterZipCode.Value = orderDetails.ZipCode;
  objCmd.Parameters.Add(parameterZipCode);
  // 배송지 주소
  SqlParameter parameterAddress =
   new SqlParameter("@Address", SqlDbType.VarChar, 100);
  parameterAddress.Value = orderDetails.Address;
  objCmd.Parameters.Add(parameterAddress);
  // 배송지 상세주소
  SqlParameter parameterAddressDetail =
   new SqlParameter("@AddressDetail", SqlDbType.VarChar, 50);
  parameterAddressDetail.Value = orderDetails.AddressDetail;
  objCmd.Parameters.Add(parameterAddressDetail);
  // 주문번호 : 반환값
  SqlParameter parameterOrderID =
   new SqlParameter("@OrderID", SqlDbType.Int, 4);
  parameterOrderID.Direction = ParameterDirection.Output;
  objCmd.Parameters.Add(parameterOrderID);
  // 커넥션 오픈 및 명령 실행
  objCon.Open();
  objCmd.ExecuteNonQuery();
  objCon.Close();

  // 주문번호(OrderID) 반환
  return (int)parameterOrderID.Value;
 }

    /// <summary>
    /// 오늘 날짜를 기준으로 오늘, 내일, 모레 날짜를 반환
    /// CheckOut.aspx에서 사용 : 랜덤하게 배송일 계산 후 반환
    /// </summary>
    /// <returns>배송 예정일</returns>
 public DateTime CalculateShippingDate()
 {
  Random x = new Random();
  double myrandom = (double)x.Next(0,3);
  return DateTime.Now.AddDays(myrandom);//오늘 제외시 +1
 } 

    /// <summary>
    /// 고객번호에 따른 주문 리스트
    /// OrderList.aspx에서 사용 : 회원용
    /// </summary>
    /// <param name="customerID">고객번호/인증번호</param>
    /// <returns>주문 리스트</returns>
 public SqlDataReader GetCustomerOrders(string customerID)
 {
  // 커넥션
  SqlConnection objCon =
   new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
  
  // 커멘드
  SqlCommand objCmd = new SqlCommand("OrdersList", objCon);
  objCmd.CommandType = CommandType.StoredProcedure;

  // 파라미터
  SqlParameter parameterCustomerid = new SqlParameter("@CustomerID", SqlDbType.Int, 4);
  parameterCustomerid.Value = Int32.Parse(customerID);
  objCmd.Parameters.Add(parameterCustomerid);

  // 실행
  objCon.Open();
  SqlDataReader result = objCmd.ExecuteReader(CommandBehavior.CloseConnection);

  // 결과 데이터셋 리턴
  return result;
 } 

    /// <summary>
    /// 주문번호/암호가 맞을 때 비회원용 주문 리스트
    /// OrderList.aspx에서 사용 : 비회원용
    /// </summary>
    /// <param name="orderID">주문시 주문번호</param>
    /// <param name="password">주문시 비밀번호</param>
    /// <returns>주문 리스트</returns>
 public SqlDataReader GetNonCustomerOrders(string orderID, string password)
 {
  // 커넥션
  SqlConnection objCon =
   new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
  
  // 커멘드
  SqlCommand objCmd = new SqlCommand("OrdersListNonCustomer", objCon);
  objCmd.CommandType = CommandType.StoredProcedure;

  // 파라미터
  SqlParameter parameterOrderID = new SqlParameter("@OrderID", SqlDbType.Int, 4);
  parameterOrderID.Value = Int32.Parse(orderID);
  objCmd.Parameters.Add(parameterOrderID);

  SqlParameter parameterPassword = new SqlParameter("@Password", SqlDbType.VarChar, 20);
  parameterPassword.Value = password;
  objCmd.Parameters.Add(parameterPassword);

  // 실행
  objCon.Open();
  SqlDataReader result = objCmd.ExecuteReader(CommandBehavior.CloseConnection);

  // 결과 데이터셋 리턴
  return result;
 } 

    /// <summary>
    /// 주문에 따른 주문 상세 내역
    /// OrderDetails.aspx에서 사용
    /// </summary>
    /// <param name="orderID">주문번호</param>
    /// <returns>주문 상세 내역 리스트</returns>
 public OrderDetails GetOrderDetails(int orderID)
 {
  // 커넥션
  SqlConnection objCon =
   new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

  // 커멘드
  SqlDataAdapter objCmd = new SqlDataAdapter("OrdersDetail", objCon);
  objCmd.SelectCommand.CommandType = CommandType.StoredProcedure;

  // 파라미터
  SqlParameter parameterOrderID = new SqlParameter("@OrderID", SqlDbType.Int, 4);
  parameterOrderID.Value = orderID;
  objCmd.SelectCommand.Parameters.Add(parameterOrderID);

  SqlParameter parameterOrderDate = new SqlParameter("@OrderDate", SqlDbType.DateTime, 8);
  parameterOrderDate.Direction = ParameterDirection.Output;
  objCmd.SelectCommand.Parameters.Add(parameterOrderDate);

  SqlParameter parameterShipDate = new SqlParameter("@ShipDate", SqlDbType.DateTime, 8);
  parameterShipDate.Direction = ParameterDirection.Output;
  objCmd.SelectCommand.Parameters.Add(parameterShipDate);

  SqlParameter parameterTotalPrice = new SqlParameter("@TotalPrice", SqlDbType.Int, 8);
  parameterTotalPrice.Direction = ParameterDirection.Output;
  objCmd.SelectCommand.Parameters.Add(parameterTotalPrice);

  // 채우기
  DataSet myDataSet = new DataSet();
  objCmd.Fill(myDataSet, "OrderItems");
         
  if (parameterShipDate.Value != DBNull.Value)
  {           
   OrderDetails myOrderDetails = new OrderDetails();

   myOrderDetails.OrderDate = (DateTime)parameterOrderDate.Value;
   myOrderDetails.ShipDate = (DateTime)parameterShipDate.Value;
   myOrderDetails.TotalPrice = (int)parameterTotalPrice.Value;
   myOrderDetails.OrderItems = myDataSet;

   // 데이터셋 반환
   return myOrderDetails;
  }
  else
   return null;
 }
}

Copyright 2000-2011 by DotNetKorea all right reserved.   사용약관  개인정보취급방침