제목 : [3] DB Layer : Database Abstract Class : DataProvider.cs
    
    
        
            
                | 글번호: |  | 301 | 
            
                | 작성자: |  | 레드플러스 | 
            
                | 작성일: |  | 2008/07/16 오전 10:45:00 | 
            
            
                | 조회수: |  | 6610 | 
            
        
     
 
    
	
	
    
	using System;
using System.Configuration;
using System.Data;
namespace RedPlus.Modules.Memo
{
    /// <summary>
    /// 1. 공급자를 결정 : SQL Server, Access, Oracle
    /// 2. 각각의 클래스에게 멤버 상속 : 추상 클래스
    /// </summary>
    public abstract class DataProvider
    {
        #region 디자인 패턴에 따른 공급자 결정 코드 블록(공식)
        //[1] 필드 : 인스턴스화된 개체에 대한 싱글톤 참조
        private static DataProvider objDataProvider = null;
        //[2] 정적 생성자 : DataProvider.멤버 접근시 호출
        static DataProvider()
        {
            CreateProvider();
        }
        //[3] 정적 메서드 : Web.config에 따른 서로 다른 공급자 호출
        private static void CreateProvider()
        {
            //[a] 네임스페이스명
            string strNamespace = "RedPlus.Modules.Memo.";
            //[b] Type 클래스의 개체 생성
            Type objType;
            //[c] Web.config 파일에 따라서 동적으로 클래스명 지정 : 네임스페이스명 추가
            objType = Type.GetType(strNamespace + ConfigurationManager.AppSettings["DataProvider"].ToString(), true);
            //[d] Activator.CreateInstance()로 동적으로 개체 생성
            objDataProvider = (DataProvider)Activator.CreateInstance(objType);
        }
        //[4] 정적 메서드
        public static DataProvider Instance()
        {
            return objDataProvider;
        }
        #endregion
        // 입력용 추상 메서드
        public abstract void AddMemo(string Name, string Email, string Title, string PostIP);
        // 출력용 추상 메서드
        public abstract IDataReader GetMemos(int Page);
        // 카운트 계산용 추상 메서드
        public abstract int GetTotalMemo();
        // 검색용 추상 메서드
        public abstract IDataReader FindMemos(string SearchField, string SearchQuery);
        // 검색 카운트 계산용 추상 메서드
        public abstract int GetTotalFindMemo(string SearchField, string SearchQuery);
        // 검색 리스트에 대한 추상 메서드
        public abstract IDataReader GetFindMemos(int intPage, string strSearchField, string strSearchQuery);
    }
}