/* 
    ETRI IntraPMS Project
    전자결재 DBManager

    
*/

import com.etri.groupware.*;
import com.etri.groupware.eda.*;


import java.sql.*;
import java.util.*;


public class PandaSoftEDADBManager implements EDADBManagerInterface {
	
	static DBConnectionManager connectionManager = null ;
	int servletInits = 0 ;
	
	int SUCCESS = EDAResultStatus.SUCCESS ;
	int FAILURE = EDAResultStatus.FAILURE ;

/*----------------------------------------------------------------- */
/**
 [메소드이름]: init<br>
 [기능]: PandaSoftEDADBManager를 생성한다.<br>
 [파라미터]: 없음 <br>
 [호출자] : EDAController <br>
 */
/*--------------------------------------------------------------- */		
        public void init(){
        	connectionManager = DBConnectionManager.getInstance();
        }

/*----------------------------------------------------------------- */
/**
 [메소드이름]: deleteListsDB<br>
 [기능]: 지정 사원에 저장되어 있는 문서를 삭제한다.<br>
 [파라미터]: String docID,String listID, String personID<br>
 [호출자] : EDAController<br>
 */
/*--------------------------------------------------------------- */
	public EDAResultStatus deleteListsDB( String docID , String listID , String personID ){
		System.out.println("deleteListsDB 함수 실행");
	
		Connection con = null;
		Statement stmt = null;
		try{
			 con = connectionManager.getConnection("access");
			stmt = con.createStatement();
			
			String iSQL = " delete from EDAlist where docID = \'" + docID +
				      "\' AND personID = \'" + personID + 
				      "\' AND listID = \'" + listID + "\'";
			
			System.out.println( iSQL + "준비");
			stmt.executeUpdate( iSQL );
			System.out.println( iSQL + "실행");

			return ( new EDAResultStatus( SUCCESS ) );
		}
		catch ( Exception e) {
			System.out.println( e.toString () ) ;
			return ( new EDAResultStatus( FAILURE ,
			 e.toString()));
		}
		finally {
			try{
				if( stmt != null ) {
					stmt.close (); 
				}
			}
			catch( SQLException sqle ) {
				while( sqle != null) {
					System.out.println( "SQLState : " + sqle.getSQLState() );
					System.out.println( "Message : " + sqle.getMessage() );
					System.out.println( "Error code : " + sqle.getErrorCode() );
					sqle = sqle.getNextException() ;
					System.out.println( " ");
				};
				connectionManager.freeConnection ("access", con ) ;
			}
			connectionManager.freeConnection ("access", con ) ;
		}
	}	

/*----------------------------------------------------------------- */
/**
 [메소드이름]: deliverApprovalDocumentDB<br>
 [기능]: 문서 결재 후 결재 문서를 다음 결재자에게 넘겨주는 함수이다.<br>
 [파라미터]: ApprovalDocument document , Connection con<br>
 [호출자] : this<br>
 */
/*--------------------------------------------------------------- */		
	public EDAResultStatus deliverApprovalDocumentDB( ApprovalDocument document , Connection con){
		if( con == null ){
			
			 con = connectionManager.getConnection("access");
		}
		Statement stmt = null;		
		try{
			System.out.println("deliverApprovalDocumentDB 실행 시작");
			stmt = con.createStatement();
			document.setcurrentPerson();
			System.out.println(document.getendDay());
			///////////////////////////////////
			//문서가 결재 완료가 되었을 경우
			if(!(document.getendDay().equals( "00/00/00" ))){
				//문서에 완결 상태 기록
				System.out.println("문서에 완결 상태 기록");
				document.setconditionCode( ApprovalCourse.APPROVAL );
				String iSQL = " UPDATE EDAdocument " +
					      " set conditionCode = \'" + document.getconditionCode() + 
					      "\' where docID = \'" + document.getdocID() + "\'";
				
				System.out.println( iSQL + "준비");
				stmt.executeUpdate( iSQL );
				System.out.println( iSQL + "실행");
				
				//결재자들에게 전달하던 Tuple삭제	
				iSQL = " delete from EDAlist where docID = \'" + document.getdocID() +
				       "\' AND personID = \'" + document.getcurrentPerson() + 
				       "\' AND listID = \'" + Lists.INGBOX + "\'";
			
				System.out.println( iSQL + "준비");
				stmt.executeUpdate( iSQL );
				System.out.println( iSQL + "실행");

				//상신자의 문서 List를 완료함으로 이동	
				System.out.println("상신자의 문서 List를 완료함으로 이동");
				iSQL = " UPDATE EDAlist " +
				       " set listID = \'" + Lists.COMPLETEBOX +
				       "\' , visited = \'NO " +
				       "\' WHERE docID = \'" + document.getdocID() +
				       "\' AND listID = \'" + Lists.SUBMITBOX + "\'";
				
				System.out.println( iSQL + "준비");
				stmt.executeUpdate( iSQL );
				System.out.println( iSQL + "실행");
				
				//문서를 공용 문서함에 저장
				System.out.println("문서를 공용 문서함에 저장");
				
				iSQL = " Insert into EDAlist( docID , personID , listID , visited ) values (\'" + 
			 		 document.getdocID() + "\',\'" + Lists.PUBLICUSER + "\',\'" +
			 		 Lists.PUBLICBOX  + "\',\'NO\')" ;
			 
				System.out.println( iSQL + "준비");
				stmt.executeUpdate( iSQL ) ;
				System.out.println( iSQL + "실행");

				//통보자들의 통보함에 List추가	
				System.out.println("통보자들의 통보함에 List추가");	
				if( document.getcurrentPerson().equals( document.getapprovalCourse( document.sizeOfApprovalCourse() -1 ).getpersonID() ) ){
					return (new EDAResultStatus(SUCCESS) );
				}
				else {	
					ApprovalCourse[] course = document.getapprovalCourse();
					int currentPosition ;
					for( currentPosition = 1 ; currentPosition < document.sizeOfApprovalCourse() ; currentPosition ++ )
						if( course[currentPosition].gettype() == ApprovalCourse.SUBMITINFORM )
							break;
					for( ; currentPosition < document.sizeOfApprovalCourse() ; currentPosition ++ ){
						
						iSQL = " Insert into EDAlist( docID , personID , listID , visited ) values (\'" + 
			 			       document.getdocID() + "\',\'" + course[currentPosition].getpersonID() + "\',\'" +
			 			       Lists.INFORMBOX + "\',\'NO\')" ;
			 
						System.out.println( iSQL + "준비");
						stmt.executeUpdate( iSQL ) ;
						System.out.println( iSQL + "실행");
						 
						course[currentPosition].setconditionCode( ApprovalCourse.APPROVAL );
						course[currentPosition].setworkDate( document.getendDay() );
						iSQL = " UPDATE EDApath " + 
						       " SET conditionCode = \'" + ApprovalCourse.APPROVAL +
						       "\', workDate = \'" + document.getendDay() +
						       "\' WHERE docID = \'" + document.getdocID() +
						       "\' AND personID =\'" + course[currentPosition].getpersonID() +
						       "\' AND sequence = " + currentPosition ;
						document.setapprovalCourse ( currentPosition , course[ currentPosition] );
						
						System.out.println( iSQL + "준비");
						stmt.executeUpdate( iSQL );
						System.out.println( iSQL + "실행");
					}		
					return (new EDAResultStatus( SUCCESS ) );
				}
			}
			//////////////////////////////
			// 결재 경로 중간에 위치한 사람일 경우
			else {
				String iSQL = " UPDATE EDAlist " +
					      " SET personID = \'" + document.getcurrentPerson() +
					      "\', visited=\'NO"+
					      "\' WHERE docID = \'" + document.getdocID() +
					      "\' AND listID = \'" + Lists.INGBOX + "\'";
					      
				System.out.println( iSQL +"준비");	 
				stmt.executeUpdate( iSQL );
				System.out.println( iSQL +"실행");
				
				return (new EDAResultStatus( SUCCESS ) );
			}
		}
		catch(Exception e){
			return (new EDAResultStatus(FAILURE,
			 e.toString()));
		}
		finally{
			try{
				if( stmt != null ) 
					stmt.close (); 
			}
			catch(SQLException sqle){
				while( sqle!=null){
					System.out.println("SQLState :"+sqle.getSQLState());
					System.out.println("Message :"+sqle.getMessage());
					System.out.println("Error code :"+sqle.getErrorCode());
					sqle = sqle.getNextException();
					System.out.println("");
				};
				connectionManager.freeConnection ("access", con ) ;
			}
			connectionManager.freeConnection ("access", con ) ;
		}
	}

/*----------------------------------------------------------------- */
/**
 [메소드이름]: deliverReturnDocumentDB<br>
 [기능]: 문서 반려 후 결재 문서를 상신자에게 돌려주는 함수이다.<br>
 [파라미터]: ApprovalDocument document , Connection con<br>
 [호출자] : this<br>
 */
/*--------------------------------------------------------------- */	
	public EDAResultStatus deliverReturnDocumentDB( ApprovalDocument document, Connection con ){
		if( con == null ){
			
			 con = connectionManager.getConnection("access");
		}
		System.out.println( "deliverReturnDocumentDB 실행");
		Statement stmt = null;		
		try{
			stmt = con.createStatement();
			/////////////////////////////////////////
			//상신자의 상신함에서 반려함으로 이동
			String iSQL = " UPDATE EDAlist " +
				      " SET listID = \'" + Lists.REJECTBOX  +
				      "\', visited = \'NO" +
				      "\' WHERE docID = \'" + document.getdocID() +
				      "\' AND listID = \'" + Lists.SUBMITBOX + "\'";		

			System.out.println( iSQL + "준비");
			stmt.executeUpdate( iSQL );
			System.out.println( iSQL + "실행");

			//////////////////////
			//결재용 문서를 삭제	
			iSQL = " delete from EDAlist where docID = \'" + document.getdocID() +
			       "\' AND personID = \'" + document.getcurrentPerson() + 
			       "\' AND listID = \'" + Lists.INGBOX + "\'";
			
			System.out.println( iSQL + "준비");
			stmt.executeUpdate( iSQL );
			System.out.println( iSQL + "실행");

			return (new EDAResultStatus ( SUCCESS ));
		}catch(Exception e1){

			return (new EDAResultStatus(FAILURE,
			 e1.toString()));
		}
		finally{
			try{
				if( stmt != null )
					stmt.close();
			}
			catch(SQLException sqle){
				while( sqle!=null){
					System.out.println("SQLState :"+sqle.getSQLState());
					System.out.println("Message :"+sqle.getMessage());
					System.out.println("Error code :"+sqle.getErrorCode());
					sqle = sqle.getNextException();
					System.out.println("");
				};
				connectionManager.freeConnection ("access", con ) ;
			}
			connectionManager.freeConnection ("access", con ) ;
		}
	}
	
/*----------------------------------------------------------------- */
/**
 [메소드이름]: getCurrentDate<br>
 [기능]: 현재의 시스템 날자를 얻는 함수이다.<br>
 [파라미터]: 없음<br>
 [호출자] : this<br>
 */
/*--------------------------------------------------------------- */	
	private String getCurrentDate(){
		Calendar current = Calendar.getInstance();
		String initYear = String.valueOf( current.get(Calendar.YEAR));
		String initMonth = String.valueOf((current.get(Calendar.MONTH) +1 ));
		String initDays = String.valueOf(current.get( Calendar.DAY_OF_MONTH ));
		initMonth = (initMonth.length()==1)?("0"+ initMonth):initMonth;
		initDays = (initDays.length()==1)?("0"+initDays):initDays;
		initDays = initYear + "-" + initMonth + "-" + initDays ;
		return initDays;
	}

/*----------------------------------------------------------------- */
/**
 [메소드이름]: getDocumentDB<br>
 [기능]: 시스템에 저장되어 있는 문서를 가져온다.<br>
 [파라미터]: String docID , String personID , String listID<br>
 [호출자] : EDAController<br>
 */
/*--------------------------------------------------------------- */
	public ApprovalDocument getDocumentDB( String docID , String personID , String listID ) throws Exception {
		System.out.println("getDocumentDB 함수시작");
	
		Connection con = null;
		Statement stmt = null;
		ApprovalDocument result = null;
		try {
			 con = connectionManager.getConnection("access");
			stmt = con.createStatement();
			////////////////////////////
			//Document 내용을 얻는 부분
			String iSQL = " SELECT * FROM EDAdocument " +
				      " WHERE docID = \'" + docID + "\'";
			
			System.out.println( iSQL + "준비");
			ResultSet rs = stmt.executeQuery( iSQL );		
			System.out.println( iSQL + "실행");
			
			rs.next();
			result = new ApprovalDocument ( rs.getString("docID") ,
			 rs.getString("initDay") , rs.getString("initPersonID") ,
			 rs.getString("conditionCode") , rs.getString("title"),
			 rs.getString("description") );
			/////////////////////////
			//결재 경로를 얻는 부분
			iSQL = " SELECT * " +
			       " FROM EDApath " +
			       " WHERE docID = \'" + docID + "\'" +
			       " ORDER BY sequence ";
			
			System.out.println( iSQL + "준비");
			rs = stmt.executeQuery( iSQL );
			System.out.println( iSQL + "실행");
			
			while( rs.next() ){
				result.addapprovalCourse ( new ApprovalCourse (
				 rs.getString("docID"), rs.getString("personID"),
				 rs.getInt("sequence"), rs.getString("conditionCode"),
				 rs.getString("description"), rs.getInt("type"),
				 rs.getString("workDate") ) );
			}
			/////////////////////////
			//첨부 파일을 얻는 부분
			iSQL = " SELECT * " +
		       	       " FROM EDAfileaccess " +
		       	       " WHERE docID = \'" + docID + "\'" ;
		
			System.out.println(iSQL + "준비");
			rs = stmt.executeQuery( iSQL );
			System.out.println(iSQL + "실행");
			
			while( rs.next() ){
				result.addattatchFile( new AttatchFile (
				 rs.getString("fileName"), rs.getString("docID"),
				 rs.getString("filePath"), rs.getInt("fileSize") ) );
			}
			///////////////////////////////////////
			//해당 문서를 읽었음을 기록하는부분
			iSQL = " UPDATE EDAlist " +
			       " SET visited = \'YES\' "+
			       " WHERE docID = \'" + docID +
			       "\' AND personID = \'" + personID +
			       "\' AND listID = \'" + listID + "\'";
				
			System.out.println( iSQL + "준비");
			stmt.executeUpdate ( iSQL );
			System.out.println( iSQL + "실행");
			
			return result;
		}
		catch ( SQLException e) {
			String message = null;
			while( e != null){
				message = message + "SQLState : " + e.getSQLState() + 
				 "Message : " + e.getMessage() + " Error code :" +
				 e.getErrorCode() ;
				 e = e.getNextException();
			}
			throw new Exception( message );			
		}
		finally {
			try{
				if( stmt != null ) 
					stmt.close (); 
			}
			catch( SQLException sqle ) {
				while( sqle != null) {
					System.out.println( "SQLState : " + sqle.getSQLState() );
					System.out.println( "Message : " + sqle.getMessage() );
					System.out.println( "Error code : " + sqle.getErrorCode() );
					sqle = sqle.getNextException() ;
					System.out.println( " ");
				};
				connectionManager.freeConnection ("access", con ) ;
			}
			connectionManager.freeConnection ("access", con ) ;
		}
	}

/*----------------------------------------------------------------- */
/**
 [메소드이름]: getDocumentListsDB<br>
 [기능]: 지정사원의 문서함을 가져온다.<br>
 [파라미터]: String personID , String listID<br>
 [호출자] : EDADController<br>
 */
/*--------------------------------------------------------------- */
	public ApprovalDocument[] getDocumentListsDB( String personID , String listID ) throws Exception{

		System.out.println("getDocumentListsDB 함수 시작");
		Connection con	= null;
		Statement stmt = null;
		ApprovalDocument[] result = null;
		List resultList = new ArrayList();
		try {
			 con = connectionManager.getConnection("access");
			stmt = con.createStatement();
			
			/////////////////////////
			//Option을 가져오는 부분
			EDAOption option = new EDAOption();
	 		boolean notHasValue = true ;

			String iSQL = " SELECT * " +
				      " FROM EDAOption " +
	 			      " WHERE personID = \'" + personID + "\'" ;
	 				
			System.out.println( iSQL + "준비");
			ResultSet rs = stmt.executeQuery( iSQL );
			System.out.println( iSQL + "실행");
			
			while( rs.next() ){
				option = new EDAOption (  rs.getString( "ingBoxSort" ) , rs.getString( "ingSortMethod" ),
				 rs.getString( "completeBoxSort" ) , rs.getString( "completeSortMethod" ) ,
				 rs.getString( "rejectBoxSort" ) , rs.getString( "rejectSortMethod" ) , 
				 rs.getString( "publicBoxSort" ) , rs.getString( "publicSortMethod" ),
				 rs.getString( "defaultPath" ) , rs.getInt( "numOfItem" ) );
				notHasValue = false ;
				System.out.println("DB에 Option이 있음");
				
			}
			if ( notHasValue ){
				//Option이 저장되어 있지 않을 경우 System에서 Default로 Option설정
				option = new EDAOption ( "initDay" , "DESC" , "initDay" , "DESC" , "initDay" , "DESC", "initDay" , "DESC" , 5 );
 				iSQL = " INSERT INTO EDAOption VALUES ( \'" + personID + 
 				       "\', \'" + option.getingBoxSort() + "\', \'" + option.getingSortMethod() +
	 			       "\', \'" + option.getcompleteBoxSort() + "\', \'" + option.getcompleteSortMethod() +
	 			       "\', \'" + option.getrejectBoxSort() + "\' , \'" + option.getrejectSortMethod() +
	 			       "\', \'" + option.getpublicBoxSort() + "\' , \'" + option.getpublicSortMethod() + 
	 			       "\', null , " + option.getnumOfItem() + ")" ;

				System.out.println( iSQL + "준비");
				stmt.executeUpdate( iSQL );
				System.out.println( iSQL + "실행");
			}
			//////////////////////////////////////
			//문서함의 문서List를 가져오는 부분
			
			//공용 문서함의 경우			
			if( listID.equals(Lists.PUBLICBOX)){
				iSQL = " SELECT * FROM EDAlist,EDAdocument " +
		 		       " WHERE personID = \'" + Lists.PUBLICUSER + "\' AND "+
				       " listID = \'" + listID + "\' AND " +
			       	       " EDAlist.docID = EDAdocument.docID ";
			}else{
			//일반 문서함일 경우
			iSQL = " SELECT * FROM EDAlist,EDAdocument " +
			       " WHERE personID = \'" + personID + "\' AND "+
			       " listID = \'" + listID + "\' AND " +
			       " EDAlist.docID = EDAdocument.docID ";
			}
			// Option을 SQL에 적용하는 부분
			if( listID.equals( Lists.INGBOX ) )
				iSQL = iSQL + " ORDER BY " + option.getingBoxSort() + " " + option.getingSortMethod();
			else if( listID.equals( Lists.COMPLETEBOX ) )
				iSQL = iSQL + " ORDER BY " + option.getcompleteBoxSort() + " " + option.getcompleteSortMethod();
			else if( listID.equals( Lists.REJECTBOX ) )
				iSQL = iSQL + " ORDER BY " + option.getrejectBoxSort() + " " + option.getrejectSortMethod();
			else if( listID.equals( Lists.PUBLICBOX ) )
				iSQL = iSQL + " ORDER BY " + option.getpublicBoxSort() + " " + option.getpublicSortMethod();
			else
				iSQL = iSQL + " ORDER BY initDay DESC ";
			System.out.println( iSQL + "준비");
			rs = stmt.executeQuery( iSQL );
			System.out.println( iSQL + "실행");
			
			List docIDs = new ArrayList();
			
			while( rs.next() ){
				docIDs.add ( rs.getString("docID"));
			}
			
			Iterator docIDIterator = docIDs.iterator();

			while( docIDIterator.hasNext() ){
				String docID = (String)docIDIterator.next();	
				/////////////////////////
				//문서 내용을 얻는 부분
				iSQL = " SELECT * FROM EDAdocument " +
				       " WHERE docID = \'" + docID + "\'";
			
				System.out.println( iSQL + "준비");
				rs = stmt.executeQuery( iSQL );		
				System.out.println( iSQL + "실행");
			
				rs.next();
				ApprovalDocument document = new ApprovalDocument ( rs.getString("docID") ,
			 	 rs.getString("initDay") , rs.getString("initPersonID") ,
			 	 rs.getString("conditionCode") , rs.getString("title"),
			 	 rs.getString("description") );
				/////////////////////////
				//결재 경로를 얻는 부분
				iSQL = " SELECT * " +
			       	       " FROM EDApath " +
			       	       " WHERE docID = \'" + docID + "\'" +
			       	       " ORDER BY sequence ";
			
				System.out.println( iSQL + "준비");
				rs = stmt.executeQuery( iSQL );
				System.out.println( iSQL + "실행");
			
				while( rs.next() ){
					document.addapprovalCourse ( new ApprovalCourse (
				 	 rs.getString("docID"), rs.getString("personID"),
				 	 rs.getInt("sequence"), rs.getString("conditionCode"),
				 	 rs.getString("description"), rs.getInt("type"),
				 	 rs.getString("workDate") ) );
				}

				resultList.add( document );
			}
			result = new ApprovalDocument[ resultList.size()];
			for( int i= 0 ; i < resultList.size() ; i++ )
				result[i] = (ApprovalDocument)resultList.get(i);

			return result;

		}
		catch ( SQLException e) {
			String message = null;
			while( e != null){
				message = message + "SQLState : " + e.getSQLState() + 
				 "Message : " + e.getMessage() + " Error code :" +
				 e.getErrorCode() ;
				 e = e.getNextException();
			}
			throw new Exception( message );			
		}
		finally {
			try{
				if( stmt != null ) 
					stmt.close (); 
			}
			catch( SQLException sqle ) {
				while( sqle != null) {
					System.out.println( "SQLState : " + sqle.getSQLState() );
					System.out.println( "Message : " + sqle.getMessage() );
					System.out.println( "Error code : " + sqle.getErrorCode() );
					sqle = sqle.getNextException() ;
					System.out.println( " ");
				};
				connectionManager.freeConnection ("access", con ) ;
			}
			connectionManager.freeConnection ("access", con ) ;
		}
	}

/*----------------------------------------------------------------- */
/**
 [메소드이름]: getStartPanelDB<br>
 [기능]: 초기 메뉴에서 보여줄 문서를 가져온다.<br>
 [파라미터]: String personID <br>
 [호출자] : EDAController<br>
 */
/*--------------------------------------------------------------- */
	public ApprovalDocument[] getStartPanelDB( String personID ) throws Exception{

		System.out.println("getStartPanelDB 함수 시작");
		Connection con = null;
		Statement stmt = null;
		ApprovalDocument[] result = null;
		List resultList = new ArrayList();
		try{
			 con = connectionManager.getConnection("access");
			stmt = con.createStatement();
			////////////////////////////////////////////
			//자신이 결재해야할 문서List를 가져오는 부분			
			String iSQL = " SELECT * FROM EDAlist,EDAdocument " +
				      " WHERE personID = \'" + personID + "\' AND " +
				      " listID = \'" + Lists.INGBOX + "\' AND " + 
				      " EDAdocument.docID = EDAlist.docID " +
				      " ORDER BY initDay DESC ";

 			System.out.println("자신의 문서함을 검색하는" + iSQL + " 실행 준비");
 			ResultSet rs = stmt.executeQuery( iSQL );
 			System.out.println("자신의 문서함을 검색하는" + iSQL + " 실행 완료");
 			List docIDs = new ArrayList();

 			while( rs.next() ){
 				docIDs.add( new Lists( rs.getString("listID") , rs.getString("docID"), rs.getString("personID") ) );
 				System.out.println("문서 저장");
 			}
			////////////////////////////////////////////////////////
			//자신의 완결,반려함에 새로 올라온 문서List를  검색
			iSQL = " SELECT * FROM EDAlist,EDAdocument " +
 			       " WHERE personID =\'" + personID + "\'AND " +
 			       " ( listID = \'" + Lists.COMPLETEBOX +
 			       "\' OR listID = \'" + Lists.REJECTBOX + "\' ) " +
 			       " AND visited=\'NO\' AND " +
 			       " EDAlist.docID = EDAdocument.docID " +
 			       " ORDER BY listID , initDay DESC ";

 			System.out.println("자신의 문서함을 검색하는" + iSQL + " 실행 준비");
 			rs = stmt.executeQuery( iSQL );
 			System.out.println("자신의 문서함을 검색하는" + iSQL + " 실행 완료");
 			
 			while( rs.next() ){
 				docIDs.add( new Lists( rs.getString("listID") , rs.getString("docID"), rs.getString("personID") ) );
 				System.out.println("문서 저장");
 			}
 			 
 			Iterator docIDIterator = docIDs.iterator();
 			
 			while( docIDIterator.hasNext() ){
 				Lists list = ( Lists )docIDIterator.next();
 				String docID = list.getdocID();
 				System.out.println( list.getdocID() + "문서를 가져올 준비");
 				//문서 내용을 얻는 부분
 				iSQL = " SELECT * FROM EDAdocument " +
				       " WHERE docID = \'" + docID + "\'";
			
				System.out.println( iSQL + "준비");
				rs = stmt.executeQuery( iSQL );		
				System.out.println( iSQL + "실행");
			
				rs.next();
				ApprovalDocument document = new ApprovalDocument ( rs.getString("docID") ,
			 	 rs.getString("initDay") , rs.getString("initPersonID") ,
			 	 rs.getString("conditionCode") , rs.getString("title"),
			 	 rs.getString("description") );
				//결재 경로를 얻는 부분
				iSQL = " SELECT * " +
			       	       " FROM EDApath " +
			               " WHERE docID = \'" + docID + "\'" +
			               " ORDER BY sequence ";
			
				System.out.println( iSQL + "준비");
				rs = stmt.executeQuery( iSQL );
				System.out.println( iSQL + "실행");
			
				while( rs.next() ){
					document.addapprovalCourse ( new ApprovalCourse (
				 	 rs.getString("docID"), rs.getString("personID"),
				 	 rs.getInt("sequence"), rs.getString("conditionCode"),
				 	 rs.getString("description"), rs.getInt("type"),
				 	 rs.getString("workDate") ) );
				}

 				document.setlistID( list.getlistID() );
 				resultList.add( document );
 				
 			}
 			result = new ApprovalDocument[ resultList.size() ];
 			for( int i = 0 ; i < resultList.size() ; i++ )
 				result[i] = ( ApprovalDocument) resultList.get(i);
 				
 			return result;
 		}
 		catch( SQLException e ){
 			String message = null;
 			while( e != null ){
 				message = message + " SQLState : " + e.getSQLState() +
 				 "Message: " + e.getMessage() + " Error code:" + e.getErrorCode() ;
 				e = e.getNextException();
 			}
 			throw new Exception( message );
 		}
 		finally{
 			try{
 				if( stmt!= null )
 					stmt.close();
 			}
 			catch( SQLException sqle ){
 				while( sqle != null ){
 					System.out.println("SQLState : " + sqle.getSQLState());
 					System.out.println("Message : " + sqle.getMessage());
 					System.out.println("Error code : " + sqle.getErrorCode());
 					sqle = sqle.getNextException();
 					System.out.println("");
 				};
 				connectionManager.freeConnection ("access", con ) ;
 			}
 			connectionManager.freeConnection ("access", con ) ;
 		}
 	}
 			
/*----------------------------------------------------------------- */
/**
 [메소드이름]: obtainApprovalDB<br>
 [기능]: 지정 문서를 결재한다.<br>
 [파라미터]: ApprovalDocument document , String personID , String description , Connection con<br>
 [호출자] : this<br>
 */
/*--------------------------------------------------------------- */		
	public EDAResultStatus obtainApprovalDB( ApprovalDocument document , 
	 String personID , String description , Connection con){
		if( con == null ){

			 con = connectionManager.getConnection("access");
		}
		Statement stmt = null;
		try {
			System.out.println( "obtainApprovalDB 시작");
			stmt = con.createStatement();
			
			document.setcurrentPerson();
			System.out.println("obtainApprovalDB.현 결재 위치 " + document.getcurrentPosition() );
			
			ApprovalCourse course = ( ApprovalCourse ) document.getapprovalCourse ( document.getcurrentPosition() );
			System.out.println("결재 경로에서 가져온 course person"+ course.getpersonID() );
			
			course.setconditionCode( ApprovalCourse.APPROVAL );
			course.setdescription( description );
			course.setworkDate( getCurrentDate() );
			document.setapprovalCourse( course.getsequence() , course );
			System.out.println( " argument로 온 결재자"  + personID );
			System.out.println( " 문서에 저장된 현 결재자"+ document.getcurrentPerson());
			if( personID.equals( document.getcurrentPerson()) ){			
				String iSQL = " UPDATE EDApath " +
					      " SET workDate = \'" + getCurrentDate() +
					      "\' , conditionCode = \'" + ApprovalCourse.APPROVAL +
					      "\' , description = \'" + description + 
					      "\' WHERE docID =\'" + document.getdocID() +
					      "\' AND personID =\'" + course.getpersonID() +
					      "\' AND sequence =" + course.getsequence();
				
				System.out.println( iSQL+"준비" );		
				stmt.executeUpdate( iSQL );
				System.out.println( iSQL + "실행");
				
				return (new EDAResultStatus( SUCCESS ) );
			}
			else
				return ( new EDAResultStatus( FAILURE ,
				 "지정하신 사원은 현재의 결재권자가 아닙니다."));
		}
		catch(Exception e){
			return (new EDAResultStatus(FAILURE,
			 e.toString()));
		}
		finally{
			try{
				if( stmt != null ) 
					stmt.close (); 
			}
			catch(SQLException sqle){
				while( sqle!=null){
					System.out.println("SQLState :"+sqle.getSQLState());
					System.out.println("Message :"+sqle.getMessage());
					System.out.println("Error code :"+sqle.getErrorCode());
					sqle = sqle.getNextException();
					System.out.println("");
				};
				connectionManager.freeConnection ("access", con ) ;
			}
			connectionManager.freeConnection ("access", con ) ;
		}
	}

/*----------------------------------------------------------------- */
/**
 [메소드이름]: returnApprovalDB<br>
 [기능]: 지정 문서를 반려한다.<br>
 [파라미터]: ApprovalDocument document , String personID , String description , Connection con<br>
 [호출자] : this<br>
 */
/*--------------------------------------------------------------- */
	public EDAResultStatus returnApprovalDB( ApprovalDocument document , 
	 String personID , String description , Connection con){
		if( con == null ){
		
			 con = connectionManager.getConnection("access");
		}
		System.out.println( "returnApprovalDB 함수 시작");
		Statement stmt = null;
		try {
			stmt = con.createStatement();
			
			document.setcurrentPerson();
			
			ApprovalCourse course = ( ApprovalCourse ) document.getapprovalCourse ( document.getcurrentPosition() );
			System.out.println("결재 경로에서 가져온 course person"+ course.getpersonID() );
			
			course.setconditionCode( ApprovalCourse.REJECT );
			course.setdescription( description );
			course.setworkDate( getCurrentDate());
			document.setapprovalCourse( course.getsequence() , course );

			System.out.println( " argument로 온 결재자"  + personID );
			System.out.println( " 문서에 저장된 현 결재자"+ document.getcurrentPerson());			
			if( personID.equals( document.getcurrentPerson() ) ){			
				//////////////////////////
				//결재 경로에 반려 입력
				String iSQL = " UPDATE EDApath " +
					      " SET workDate = \'" + getCurrentDate() +
					      "\' , conditionCode = \'" + ApprovalCourse.REJECT +
					      "\' , description = \'" + description + 
					      "\' WHERE docID =\'" + document.getdocID() +
					      "\' AND personID =\'" + course.getpersonID() +
					      "\' AND sequence =" + course.getsequence();
				
				System.out.println( iSQL + "준비");			
				stmt.executeUpdate( iSQL );
				System.out.println( iSQL + "실행");
				///////////////////
				//문서에 반려 기재				
				document.setconditionCode ( ApprovalCourse.REJECT );
				
				iSQL = " UPDATE EDAdocument " +
				       " SET conditionCode = \'" + ApprovalCourse.REJECT +
				       "\' WHERE docID = \'" + document.getdocID() + "\'" ;
				
				System.out.println( iSQL + "준비");
				stmt.executeUpdate( iSQL );
				System.out.println( iSQL + "실행");
				
				return (new EDAResultStatus( SUCCESS ) );
			}
			else
				return ( new EDAResultStatus( FAILURE ,
				 "지정하신 사원은 현재의 결재권자가 아닙니다."));
		}
		catch(Exception e){
			return (new EDAResultStatus(FAILURE,
			 e.toString()));
		}
		finally{
			try{
				if( stmt != null ) 
					stmt.close (); 
			}
			catch(SQLException sqle){
				while( sqle!=null){
					System.out.println("SQLState :"+sqle.getSQLState());
					System.out.println("Message :"+sqle.getMessage());
					System.out.println("Error code :"+sqle.getErrorCode());
					sqle = sqle.getNextException();
					System.out.println("");
				};
				connectionManager.freeConnection ("access", con ) ;
			}
			connectionManager.freeConnection ("access", con ) ;
		}
	}

/*----------------------------------------------------------------- */
/**
 [메소드이름]: processAbortApprovalDB<br>
 [기능]: 지정 문서의 상신을 취소한다.<br>
 [파라미터]: ApprovalDocument document , String personID<br>
 [호출자] : EDAController<br>
 */
/*--------------------------------------------------------------- */
	public EDAResultStatus processAbortApprovalDB( ApprovalDocument document , String personID ) {

		Connection con=null;
		Statement stmt=null;
		System.out.println("processAbortApprovalDB 함수 시작");
		document.setcurrentPerson();
		
		try{
			 con = connectionManager.getConnection("access");
			
			stmt = con.createStatement();
			
			con.setAutoCommit(false);
			
			if( !(personID.equals( document.getapprovalCourse(0).getpersonID())))
				return (new EDAResultStatus ( FAILURE,
				 "상신 취소는 작성자 만이 수행할 수 있습니다. "));
			//////////////////////////////////////////////	 
			//상신자의 결재 경로에 상신취소를 기록한다.
			ApprovalCourse course = ( ApprovalCourse ) document.getapprovalCourse ( 0 );
			
			course.setconditionCode( ApprovalCourse.ABORT );

			course.setworkDate( getCurrentDate());
			
			document.setapprovalCourse( 0 , course );

			String iSQL = " UPDATE EDApath " +
				      " SET conditionCode =\'" + ApprovalCourse.ABORT +
				      "\' , workDate =\'" + getCurrentDate() +
				      "\' WHERE docID =\'" + document.getdocID() +
				      "\' AND sequence = 0 AND personID =\'" + personID + "\'";
			
			System.out.println( iSQL + "준비");
			stmt.executeUpdate( iSQL );
			System.out.println( iSQL + "실행");
			
			/////////////////////////////////////////////
			//결재 문서에 문서가 상신취소 됐음을 기록			
			document.setconditionCode ( ApprovalCourse.ABORT );

			iSQL = " UPDATE EDAdocument " +
			       " SET conditionCode =\'" + document.getconditionCode() +
			       "\' WHERE docID =\'" + document.getdocID() + "\'";			 
			
			System.out.println( iSQL + "준비");
			stmt.executeUpdate( iSQL );
			System.out.println( iSQL + "실행");
			
			/////////////////////////////////////////////////
			//결재를 위해 결재자의 결재함에 있는 List삭제
			iSQL = " delete from EDAlist where docID = \'" + document.getdocID() +
			              "\' AND personID = \'" + document.getcurrentPerson() + 
			              "\' AND listID = \'" + Lists.INGBOX + "\'";
			
			System.out.println( iSQL + "준비");
			stmt.executeUpdate( iSQL );
			System.out.println( iSQL + "실행");

			////////////////////////////////////////////////
			//상신자의 결재 문서 List를 상신 취소로 수정
			iSQL = " UPDATE EDAlist " +
			       " SET listID = \'" + Lists.ABORTBOX +
			       "\' , visited=\'NO" +
			       "\' WHERE docID =\'" + document.getdocID() +
			       "\' AND listID =\'" + Lists.SUBMITBOX + "\'";
			
			System.out.println( iSQL + "준비");
			stmt.executeUpdate( iSQL );
			System.out.println( iSQL + "실행");
			
			con.commit();
			return (new EDAResultStatus( SUCCESS ) );
		}catch(Exception e1){
			try{
				con.rollback();
			}
			catch(SQLException e2){
				String message=null;
				while(e2!=null){
					message= message + "SQLState:"+
					 e2.getSQLState() + "Message:"+
					 e2.getMessage() + "Error code:"+
					 e2.getErrorCode();
					 e2.getNextException();
				}
				return (new EDAResultStatus(FAILURE,
				 e1.toString()+
				 "RollBack에 실패했습니다."+
				 message ) );
			}
			return (new EDAResultStatus(FAILURE,
			 e1.toString()));
		}
		finally{
			try{
				con.setAutoCommit(true);
			}
			catch(SQLException sqle){
				while( sqle!=null){
					System.out.println("SQLState :"+sqle.getSQLState());
					System.out.println("Message :"+sqle.getMessage());
					System.out.println("Error code :"+sqle.getErrorCode());
					sqle = sqle.getNextException();
					System.out.println("");
				};
				connectionManager.freeConnection ("access", con ) ;
			}
			connectionManager.freeConnection ("access", con ) ;
		}
	}

/*----------------------------------------------------------------- */
/**
 [메소드이름]: processObtainApprovalDB<br>
 [기능]: 지정 문서를 결재한다.<br>
 [파라미터]: ApprovalDocument document , String personID , String description<br>
 [호출자] : EDAController<br>
 */
/*--------------------------------------------------------------- */
	public EDAResultStatus processObtainApprovalDB( ApprovalDocument document, 
	 String personID , String description ){

		Connection con = null;
		System.out.println("processObtainApprovalDB 함수 시작");
		try{
			 con = connectionManager.getConnection("access");
			con.setAutoCommit(false);
			
			////////////////////////////////////////////
			//결재 기록을 위해 obtainApprovalDB를 호출
			EDAResultStatus result = obtainApprovalDB( document, personID , description , con );

			if( result.getResultStatus() == FAILURE )
				throw new Exception( result.getReason() );
			
			////////////////////////////////////////////////////////////////////////////////
			//결재 문서를 다음 결재자에게 전달하기 위한 deliverApprovalDocumentDB 호출
			result = deliverApprovalDocumentDB ( document, con );
			
			if( result.getResultStatus() == FAILURE )
				throw new Exception ( result.getReason() );

			con.commit();
			return ( new EDAResultStatus( SUCCESS ));
				
		}
		catch(Exception e1){
			try{
				con.rollback();
			}
			catch(Exception e2){
				return (new EDAResultStatus(FAILURE,
				 "RollBack에 실패했습니다."+
				 e2.toString()));
			}
			return (new EDAResultStatus(FAILURE,
			 e1.toString()));
		}
		finally{
			try{
				con.setAutoCommit(true);
			}
			catch(SQLException sqle){
				while( sqle!=null){
					System.out.println("SQLState :"+sqle.getSQLState());
					System.out.println("Message :"+sqle.getMessage());
					System.out.println("Error code :"+sqle.getErrorCode());
					sqle = sqle.getNextException();
					System.out.println("");
				};
				connectionManager.freeConnection ("access", con ) ;
			}
			connectionManager.freeConnection ("access", con ) ;
		}
	}
		
		
/*----------------------------------------------------------------- */
/**
 [메소드이름]: processRaiseApprovalDB<br>
 [기능]: 새로운 문서를 상신한다.<br>
 [파라미터]: ApprovalDocument document<br>
 [호출자] : EDAController<br>
 */
/*--------------------------------------------------------------- */
	public EDAResultStatus processRaiseApprovalDB( ApprovalDocument document ){
		//결재경로가 옳바른지 확인
		if( ( document.sizeOfApprovalCourse() < 2 ) || 
		    ( document.getapprovalCourse(1).gettype() == ApprovalCourse.SUBMITINFORM ))
			return ( new EDAResultStatus ( FAILURE ,
			 "결재자가 지정되어 있지 않습니다. 결재자를 지정하세요."));
		System.out.println("processRaiseApprovalDB 함수 시작");

		Connection con = null;
		Statement stmt = null;
		try{
			 con = connectionManager.getConnection("access");
			con.setAutoCommit(false);
			stmt = con.createStatement();
			///////////////////////
			//문서 번호 얻는 부분
			String iSQL = " SELECT MAX(docCount) AS DOCNUMBER " +
			       " FROM EDAdocument " +
			       " WHERE docID LIKE \'" + document.getdocID() + "%\' ";
			
			System.out.println( iSQL + "준비");
			ResultSet rs=stmt.executeQuery( iSQL );
			System.out.println( iSQL + "실행");
			
			rs.next();
			int docCount = rs.getInt( "DOCNUMBER" );
			if( rs.wasNull() ){
				document.setdocID( document.getdocID() + "-" + 1 );
				docCount = 1;
			}
			else
				document.setdocID( document.getdocID() + "-" + ( ++docCount ) );
				
			/////////////////
			//문서 내용 저장
			iSQL = " Insert into EDAdocument( docID,initDay,initPersonID,"+
			"conditionCode,title,comment,docCount) values (\'" +
			 document.getdocID() + "\',\'" + document.getinitDay() +
			 "\',\'" + document.getinitPersonID() + "\',\'" +
			 document.getconditionCode() + "\',\'" + document.gettitle() +
			 "\',\'" + document.getcomment() + "\'," + docCount + ")";

			System.out.println( iSQL + "준비");
			stmt.executeUpdate( iSQL );
			System.out.println( iSQL + "실행");
			
			/////////////////
			//결재 경로 저장
			for( int i=0 ; i<document.sizeOfApprovalCourse(); i++ ) { 
				ApprovalCourse course = document.getapprovalCourse( i );
				course.setdocID( document.getdocID() );
				document.setapprovalCourse( i , course );
				iSQL = " INSERT INTO EDApath(docID,personID,sequence,"+
				"conditionCode,description,type) values (\'" +
				 course.getdocID() + "\',\'" + course.getpersonID() + 
				 "\'," + course.getsequence() + ",\'" + 
				 course.getconditionCode() + "\',\'" +
				 course.getdescription() + "\'," + course.gettype() + ")";
				System.out.println( iSQL +"준비");	
				stmt.executeUpdate( iSQL );
				System.out.println( iSQL + "실행");
			}
			/////////////////
			//FileAccess 저장
			if( document.sizeOfAttatchFile() > 0){
				for( int i=0 ; i< document.sizeOfAttatchFile() ; i++ ){
					AttatchFile file = document.getattatchFile( i );
					file.setdocID( document.getdocID() );
					document.setattatchFile( i , file );
					iSQL = " INSERT INTO EDAfileaccess(docID,fileName,"+
					 "filePath,fileSize) values (\'" + 
					 file.getdocID() + "\',\'" + file.getfileName() +
					 "\',\'" + file.getfilePath() + "\'," +
					 file.getfileSize()  + ")" ;
					System.out.println( iSQL + "준비" );
					stmt.executeUpdate( iSQL ) ;
					System.out.println( iSQL + "실행" );
				}
			}	
			/////////////////////////////////////////////////////
			// 상신자의 상신함과 결재자의 결재함에 Lists 저장	
			iSQL = " Insert into EDAlist( docID , personID , listID , visited ) values (\'" + 
			 	 document.getdocID() + "\',\'" + 
			 	 document.getapprovalCourse(0).getpersonID() + "\',\'" +
			 	 Lists.SUBMITBOX + "\',\'NO\')" ;
			 	 
			System.out.println( iSQL + "준비");
			stmt.executeUpdate( iSQL );
			System.out.println( iSQL + "실행");
			
			iSQL = " Insert into EDAlist( docID , personID , listID , visited ) values (\'" + 
			 	 document.getdocID() + "\',\'" +
			 	 document.getapprovalCourse(1).getpersonID() + "\',\'" +
			 	 Lists.INGBOX  + "\',\'NO\')" ;
			 
			System.out.println( iSQL + "준비");
			stmt.executeUpdate( iSQL ) ;
			System.out.println( iSQL + "실행");
 
			con.commit();
			return (new EDAResultStatus( SUCCESS) );
			
		}
		catch( Exception e){
			try{
				con.rollback();
			}
			catch( Exception e2 ){
				return (new EDAResultStatus ( FAILURE ,
				 " 오류가 발생했으며" +
				 "(Message : " + e.toString() +
				 ") rollback에도 실패했습니다.Message :" +
				 e2.toString() ) );
			}
			return (new EDAResultStatus ( FAILURE ,
			 " 오류가 발생했습니다." +
			 "Message : " + e.toString() ) );
		}
		finally {
			try{
				con.setAutoCommit(true);
				if( stmt !=null ){
					stmt.close();
					
				}
			}
			catch( SQLException sqle){
				while( sqle != null){
					System.out.println("SQLState : " + sqle.getSQLState() );
					System.out.println("Message : " + sqle.getMessage() );
					System.out.println("Error code : " + sqle.getErrorCode() );
					sqle= sqle.getNextException();
					System.out.println(" ");
				};
				connectionManager.freeConnection ("access", con ) ;
			}
			connectionManager.freeConnection ("access", con ) ;
		}
	}
	
/*----------------------------------------------------------------- */
/**
 [메소드이름]: processReturnApprovalDB<br>
 [기능]: 지정 문서를 반려한다.<br>
 [파라미터]: ApprovalDocument document , String personID , String description<br>
 [호출자] : EDAController<br>
 */
/*--------------------------------------------------------------- */		
	public EDAResultStatus processReturnApprovalDB( ApprovalDocument document, 
	 String personID , String description ){
		Connection con = null;
		System.out.println("processReturnApprovalDB 함수 시작");
		try{
			 con = connectionManager.getConnection("access");
			con.setAutoCommit(false);
			///////////////////////////////////////////////
			//반려 기록을 위해 returnApprovalDB 함수 호출
			EDAResultStatus result = returnApprovalDB( document, personID , description , con );
			if( result.getResultStatus() == FAILURE )
				throw new Exception( result.getReason() );
			
			////////////////////////////////////////////////////////////////////////////
			//결재 문서를 상신자에게 돌려주기 위해 deliverReturnDocumentDB 함수 호출	
			result = deliverReturnDocumentDB ( document, con );
			if( result.getResultStatus() == FAILURE )
				throw new Exception ( result.getReason() );

			con.commit();
			return ( new EDAResultStatus( SUCCESS ));
				
		}
		catch(Exception e1){
			try{
				con.rollback();
			}
			catch(Exception e2){
				return (new EDAResultStatus(FAILURE,
				 "RollBack에 실패했습니다."+
				 e2.toString()));
			}
			return (new EDAResultStatus(FAILURE,
			 e1.toString()));
		}
		finally{
			try{
				con.setAutoCommit(true);
			}
			catch(SQLException sqle){
				while( sqle!=null){
					System.out.println("SQLState :"+sqle.getSQLState());
					System.out.println("Message :"+sqle.getMessage());
					System.out.println("Error code :"+sqle.getErrorCode());
					sqle = sqle.getNextException();
					System.out.println("");
				};
				connectionManager.freeConnection ("access", con ) ;
			}
			connectionManager.freeConnection ("access", con ) ;
		}
	}

/*----------------------------------------------------------------- */
/**
 [메소드이름]: saveApprovalCourseDB<br>
 [기능]: 결재 경로를 저장한다.<br>
 [파라미터]: String personID , String courseName , ApprovalCourse[] course<br>
 [호출자] : EDAController<br>
 */
/*--------------------------------------------------------------- */
	public EDAResultStatus saveApprovalCourseDB ( String personID , String courseName , ApprovalCourse[] course ){

		System.out.println( "saveApprovalCourseDB 함수 시작");
	 	Connection con = null;
	 	Statement stmt = null;
	 	try{
	 		 con = connectionManager.getConnection("access");
	 		stmt = con.createStatement();
	 		System.out.println("커넥션으로부터 스테이트먼트를 얻어냈습니다.");
	 		String courseString = "";
	 		for( int i=0 ; i< course.length ; i++ ){
	 			courseString = courseString + course[i].getpersonID() + ",";
	 			if( course[i].gettype() == ApprovalCourse.SUBMITAPPROVAL )
	 				courseString = courseString + "결재;";
	 			else if( course[i].gettype() == ApprovalCourse.SUBMITINFORM )
	 				courseString = courseString + "통보;";
	 		}
	 		
	 		System.out.println("현재 전달된 결재 경로 : "+ courseString );
	 		

			boolean inDB = false;
			String iSQL = " SELECT courseName" +
	 		              " FROM EDAstorepath " +
			              " WHERE owner = \'" + personID + "\' "+
			              " ORDER BY courseName ";
	
			System.out.println( iSQL + "준비");
			ResultSet rs=stmt.executeQuery( iSQL );
			System.out.println( iSQL + "실행");
			
			List courseList = new ArrayList();
			while(rs.next() ){
				courseList.add ( Integer.toString(rs.getInt("courseName") ) );
				inDB = true ;
			}
			
			if( inDB ){
			 	for( int i = 0 ; i < courseList.size() ; i++ ) {
			 		 		
			 		ApprovalCourse[] courseInDB;
	 				List temp = new ArrayList();
	 				int courseNumber = Integer.parseInt( (String) courseList.get(i) );
	 				
					iSQL = " SELECT * " +
				      	       " FROM EDAstorepath " +
	 			      	       " WHERE owner= \'" + personID +
	 			      	       "\' AND courseName =" + courseNumber + 
	 			      	       " ORDER BY sequence " ;
	 				
					System.out.println( iSQL + "준비");
					rs = stmt.executeQuery( iSQL );
					System.out.println( iSQL + "실행");
			
					while( rs.next() ){
						temp.add( new ApprovalCourse ( null , rs.getString( "personID" ),
				 		rs.getInt( "sequence" ), null , rs.getInt( "type") ) );
					}
					courseInDB = new ApprovalCourse[ temp.size() ];
					for ( int j = 0 ; j < temp.size() ; j ++ ){
						courseInDB[j] = (ApprovalCourse) temp.get(j);
					}
 		
			 		String 	courseInDBString = "";
			 		for( int k = 0 ; k < courseInDB.length ; k++ ){
			 			courseInDBString = courseInDBString + courseInDB[k].getpersonID() + ",";
	 					if( courseInDB[k].gettype() == ApprovalCourse.SUBMITAPPROVAL )
	 						courseInDBString = courseInDBString + "결재;";
	 					else if( course[k].gettype() == ApprovalCourse.SUBMITINFORM )
	 						courseInDBString = courseInDBString + "통보;";
	 				}
	 				if( courseInDBString.equals( courseString ) )
	 					return (new EDAResultStatus (SUCCESS ) );
	 			}
	 		}
			int nextNumber = 0;
			if( inDB == false )
				nextNumber = 1;
			else
				nextNumber = Integer.parseInt((String)courseList.get( (courseList.size() -1) )) + 1;
			
			System.out.println("nextNumber : " + nextNumber );
			
			for ( int i = 0 ; i < course.length ; i++ ){
	 			iSQL = " INSERT INTO EDAStorepath VALUES ( \'" +
	 				      personID + "\', " + nextNumber + ", \'"+
	 				      course[i].getpersonID() + "\', "+ course[i].getsequence()+
	 				      ", " + course[i].gettype() + ")";
			
				System.out.println( iSQL + "준비");
				stmt.executeUpdate( iSQL );
				System.out.println( iSQL + "실행");
			}

			return ( new EDAResultStatus( SUCCESS) );
	 	}
	 	catch(Exception e) {
			return ( new EDAResultStatus( FAILURE , e.toString() ) ); 
	 	}
	 	finally{
	 		try{
	 			if( stmt != null )
	 				stmt.close();
	 		}
	 		catch( SQLException sqle ){
	 			while(sqle != null){
	 				System.out.println("SQLState : " + sqle.getSQLState() );
	 				System.out.println("Message : " + sqle.getMessage() );
	 				System.out.println("Error code : " + sqle.getErrorCode() );
	 				sqle = sqle.getNextException();
	 				System.out.println(" ");
	 			};
	 			connectionManager.freeConnection ("access", con ) ;
	 		}
	 		connectionManager.freeConnection ("access", con ) ;
	 	}
	}


/*----------------------------------------------------------------- */
/**
 [메소드이름]: saveEDAOptionDB<br>
 [기능]: 문서함 관리를 위한 Option을 설정한다.<br>
 [파라미터]: String personID , EDAOption optionClass<br>
 [호출자] : EDAController<br>
 */
/*--------------------------------------------------------------- */	
	public EDAResultStatus saveEDAOptionDB ( String personID , EDAOption optionClass ){

		System.out.println( "saveApprovalCourseDB 함수 시작");
	 	Connection con = null;
	 	Statement stmt = null;
	 	boolean newOption = false;
	 	try{
	 		 con = connectionManager.getConnection("access");
	 		System.out.println("이미 커넥션 풀이 연결되어 있어서 다시 연결하지 않습니다.");
	 		stmt = con.createStatement();
	 		System.out.println("커넥션으로부터 스테이트먼트를 얻어냈습니다.");

			String iSQL = " SELECT COUNT(*) AS length " +
			       	      " FROM EDAOption " +
			       	      " WHERE personID = \'" + personID + "\' ";
	
			System.out.println( iSQL + "준비");
			ResultSet rs=stmt.executeQuery( iSQL );
			System.out.println( iSQL + "실행");
	
			rs.next();
			int temp = rs.getInt("length");
			if( rs.wasNull() ){
				System.out.println("newOption을 True로 설정함");
				newOption = true;
			}
			if( newOption )
 				iSQL = " INSERT INTO EDAOption VALUES ( \'" + personID + 
 				       "\', \'" + optionClass.getingBoxSort() + "\', \'" + optionClass.getingSortMethod() +
	 			       "\', \'" + optionClass.getcompleteBoxSort() + "\', \'" + optionClass.getcompleteSortMethod() +
	 			       "\', \'" + optionClass.getrejectBoxSort() + "\' , \'" + optionClass.getrejectSortMethod() +
	 			       "\', \'" + optionClass.getpublicBoxSort() + "\' , \'" + optionClass.getpublicSortMethod() + 
	 			       "\', \'" + optionClass.getdefaultPath() + "\' , " + optionClass.getnumOfItem() + ")" ;
	 		else
 				iSQL = " UPDATE EDAOption SET "  +
 				       " ingBoxSort = \'" + optionClass.getingBoxSort() + "\', ingSortMethod =\'" + optionClass.getingSortMethod() +
	 			       "\', completeBoxSort =\'" + optionClass.getcompleteBoxSort() + "\', completeSortMethod = \'" + optionClass.getcompleteSortMethod() +
	 			       "\', rejectBoxSort =\'" + optionClass.getrejectBoxSort() + "\' , rejectSortMethod =\'" + optionClass.getrejectSortMethod() +
	 			       "\', publicBoxSort =\'" + optionClass.getpublicBoxSort() + "\' , publicSortMethod =\'" + optionClass.getpublicSortMethod() + 
	 			       "\', defaultPath =\'" + optionClass.getdefaultPath() + "\' , numOfItem = " + optionClass.getnumOfItem() + 
	 			       " WHERE personID = \'" + personID + "\' " ;	 			
			System.out.println( iSQL + "준비");
			stmt.executeUpdate( iSQL );
			System.out.println( iSQL + "실행");
			

			return ( new EDAResultStatus( SUCCESS) );
	 	}
	 	catch(Exception e) {
			return ( new EDAResultStatus( FAILURE , e.toString() ) ); 
	 	}
	 	finally{
	 		try{
	 			if( stmt != null )
	 				stmt.close();
	 		}
	 		catch( SQLException sqle ){
	 			while(sqle != null){
	 				System.out.println("SQLState : " + sqle.getSQLState() );
	 				System.out.println("Message : " + sqle.getMessage() );
	 				System.out.println("Error code : " + sqle.getErrorCode() );
	 				sqle = sqle.getNextException();
	 				System.out.println(" ");
	 			};
	 			connectionManager.freeConnection ("access", con ) ;
	 		}
	 		connectionManager.freeConnection ("access", con ) ;
	 	}
	}

/*----------------------------------------------------------------- */
/**
 [메소드이름]: loadApprovalCourseDB<br>
 [기능]: 해당 이름을 가지는 결재 경로를 가져온다.<br>
 [파라미터]: String personID , String courseName <br>
 [호출자] : EDAController<br>
 */
/*--------------------------------------------------------------- */
	public ApprovalCourse[] loadApprovalCourseDB ( String personID , String courseName ) throws Exception{
		System.out.println( "loadApprovalCourseDB 함수 시작");

		Connection con = null;
	 	Statement stmt = null;
	 	ApprovalCourse[] result;
	 	List course = new ArrayList();
	 	int courseNumber = Integer.parseInt( courseName );
	 	try{
			 con = connectionManager.getConnection("access"); 		
	 		stmt = con.createStatement();
	 		System.out.println("커넥션으로부터 스테이트먼트를 얻어냈습니다.");

			String iSQL = " SELECT * " +
				      " FROM EDAstorepath " +
	 			      " WHERE owner= \'" + personID +
	 			      "\' AND courseName =" + courseNumber + 
	 			      " ORDER BY sequence " ;
	 				
			System.out.println( iSQL + "준비");
			ResultSet rs = stmt.executeQuery( iSQL );
			System.out.println( iSQL + "실행");
			
			while( rs.next() ){
				course.add( new ApprovalCourse ( null , rs.getString( "personID" ),
				 rs.getInt( "sequence" ), null , rs.getInt( "type") ) );
			}
			result = new ApprovalCourse[ course.size() ];
			for ( int i = 0 ; i < course.size() ; i ++ ){
				result[i] = (ApprovalCourse) course.get(i);
			}
			return result;
	 	}
		catch(SQLException e){
			String message="";
 			while(e != null){
	 			message = message + "State  : " + e.getSQLState() ;
	 			message = message + "Message : " + e.getMessage() ;
	 			message = message + "Error code : " + e.getErrorCode() ;
	 			e = e.getNextException();
	 		};
			
			throw new Exception(message );
		}

	 	finally{
	 		try{
	 			if( stmt != null )
	 				stmt.close();
	 		}
	 		catch( SQLException sqle ){
	 			while(sqle != null){
	 				System.out.println("SQLState : " + sqle.getSQLState() );
	 				System.out.println("Message : " + sqle.getMessage() );
	 				System.out.println("Error code : " + sqle.getErrorCode() );
	 				sqle = sqle.getNextException();
	 				System.out.println(" ");
	 			};
	 			connectionManager.freeConnection ("access", con ) ;
	 		}
	 		connectionManager.freeConnection ("access", con ) ;
	 	}
	}

/*----------------------------------------------------------------- */
/**
 [메소드이름]: loadEDAOptionDB<br>
 [기능]: 지정 사원의 Option을 가져온다.<br>
 [파라미터]: String personID <br>
 [호출자] : EDAController<br>
 */
/*--------------------------------------------------------------- */		
	public EDAOption loadEDAOptionDB ( String personID ) throws Exception{
		System.out.println( "loadEDAOption 함수 시작");

		Connection con = null;
		Statement stmt = null;
		EDAOption result = new EDAOption();
	 	boolean notHasValue = true ;
		try {
			 con = connectionManager.getConnection("access");
			stmt = con.createStatement();

	 		System.out.println("커넥션으로부터 스테이트먼트를 얻어냈습니다.");

			String iSQL = " SELECT * " +
				      " FROM EDAOption " +
	 			      " WHERE personID = \'" + personID + "\'" ;
	 				
			System.out.println( iSQL + "준비");
			ResultSet rs = stmt.executeQuery( iSQL );
			System.out.println( iSQL + "실행");
			

			while( rs.next() ){
				result = new EDAOption (  rs.getString( "ingBoxSort" ) , rs.getString( "ingSortMethod" ),
				 rs.getString( "completeBoxSort" ) , rs.getString( "completeSortMethod" ) ,
				 rs.getString( "rejectBoxSort" ) , rs.getString( "rejectSortMethod" ) , 
				 rs.getString( "publicBoxSort" ) , rs.getString( "publicSortMethod" ),
				 rs.getString( "defaultPath" ) , rs.getInt( "numOfItem" ) );
				notHasValue = false ;
				System.out.println("DB에 Option이 있음");
				
			}
			if ( notHasValue ){
				result = new EDAOption ( "initDay" , "DESC" , "initDay" , "DESC" , "initDay" , "DESC", "initDay" , "DESC" , 5 );
 				iSQL = " INSERT INTO EDAOption VALUES ( \'" + personID + 
 				       "\', \'" + result.getingBoxSort() + "\', \'" + result.getingSortMethod() +
	 			       "\', \'" + result.getcompleteBoxSort() + "\', \'" + result.getcompleteSortMethod() +
	 			       "\', \'" + result.getrejectBoxSort() + "\' , \'" + result.getrejectSortMethod() +
	 			       "\', \'" + result.getpublicBoxSort() + "\' , \'" + result.getpublicSortMethod() + 
	 			       "\', null , " + result.getnumOfItem() + ")" ;

				System.out.println( iSQL + "준비");
				stmt.executeUpdate( iSQL );
				System.out.println( iSQL + "실행");
			}
			return result;				
	 	}
	 	catch(Exception e) {
			throw e; 
	 	}
	 	finally{
	 		try{
	 			if( stmt != null )
	 				stmt.close();
	 		}
	 		catch( SQLException sqle ){
	 			while(sqle != null){
	 				System.out.println("SQLState : " + sqle.getSQLState() );
	 				System.out.println("Message : " + sqle.getMessage() );
	 				System.out.println("Error code : " + sqle.getErrorCode() );
	 				sqle = sqle.getNextException();
	 				System.out.println(" ");
	 			};
	 			connectionManager.freeConnection ("access", con ) ;
	 		}
	 		connectionManager.freeConnection ("access", con ) ;
	 	}
	}


/*----------------------------------------------------------------- */
/**
 [메소드이름]: listApprovalCourseDB<br>
 [기능]: 해당 사원이 저장한 모든 결재 경로를 가져온다.<br>
 [파라미터]: String personID <br>
 [호출자] : EDAController<br>
 */
/*--------------------------------------------------------------- */
	public Map listApprovalCourseDB ( String personID ) throws Exception {

		System.out.println( "listApprovalCourseDB 함수 시작");
	 	Connection con = null;
	 	Statement stmt = null;
	 	Map result = new HashMap();
	 	List courseName = new ArrayList();
	 	try{
	 		 con = connectionManager.getConnection("access");
	 		System.out.println("이미 커넥션 풀이 연결되어 있어서 다시 연결하지 않습니다.");
	 		stmt = con.createStatement();
	 		System.out.println("커넥션으로부터 스테이트먼트를 얻어냈습니다.");

			String iSQL = " SELECT courseName " +
				      " FROM EDAstorepath " +
	 			      " WHERE owner= \'" + personID + "\'";
	 				
			System.out.println( iSQL + "준비");
			ResultSet rs = stmt.executeQuery( iSQL );
			System.out.println( iSQL + "실행");
			
			while( rs.next() ){
				courseName.add( Integer.toString(rs.getInt( "courseName" ) ) );
			}
			
			for( int i = 0 ; i < courseName.size() ; i++ ) {
	 			ApprovalCourse[] course;
	 			List temp= new ArrayList();
	 			int courseNumber = Integer.parseInt( (String)courseName.get(i) );
	 		
				iSQL = " SELECT * " +
				       " FROM EDAstorepath " +
	 			       " WHERE owner= \'" + personID +
	 			       "\' AND courseName =" + courseNumber + 
	 			       " ORDER BY sequence " ;
	 				
				System.out.println( iSQL + "준비");
				rs = stmt.executeQuery( iSQL );
				System.out.println( iSQL + "실행");
			
				while( rs.next() ){
					temp.add( new ApprovalCourse ( null , rs.getString( "personID" ),
				 	 rs.getInt( "sequence" ), null , rs.getInt( "type") ) );
				}
				course = new ApprovalCourse[ temp.size() ];
				for ( int j = 0 ; j < temp.size() ; j ++ ){
					course[j] = (ApprovalCourse) temp.get(j);
				}
				
				List courseList = new ArrayList();
				for( int j = 0 ; j < course.length ; j++ ) 
					courseList.add( course[j] );
				result.put ( (String) courseName.get(i) , courseList );
			}
			
			return result;

		}
		catch(SQLException e){
			String message="";
 			while(e != null){
	 			message = message + "State  : " + e.getSQLState() ;
	 			message = message + "Message : " + e.getMessage() ;
	 			message = message + "Error code : " + e.getErrorCode() ;
	 			e = e.getNextException();
	 		};
			
			throw new Exception(message );
		}

		catch(Exception e){
			throw e;
		}

	 	finally{
	 		try{
	 			if( stmt != null )
	 				stmt.close();
	 		}
	 		catch( SQLException sqle ){
	 			while(sqle != null){
	 				System.out.println("SQLState : " + sqle.getSQLState() );
	 				System.out.println("Message : " + sqle.getMessage() );
	 				System.out.println("Error code : " + sqle.getErrorCode() );
	 				sqle = sqle.getNextException();
	 				System.out.println(" ");
	 			};
	 			connectionManager.freeConnection ("access", con ) ;
	 		}
	 		connectionManager.freeConnection ("access", con ) ;
	 	}
	}
	
/*----------------------------------------------------------------- */
/**
 [메소드이름]: deleteApprovalCourseDB<br>
 [기능]: 지정 결재 경로를 삭제한다.<br>
 [파라미터]: String personID , String courseName , ApprovalCourse[] course<br>
 [호출자] : EDAController<br>
 */
/*--------------------------------------------------------------- */
	public EDAResultStatus deleteApprovalCourseDB ( String personID , String courseName , ApprovalCourse[] course){

		System.out.println( "deleteApprovalCourseDB 함수 시작");
	 	Connection con = null;
	 	Statement stmt = null;
	 	int courseNumber = 0;
	 	try{
	 		 con = connectionManager.getConnection("access");
	 		System.out.println("이미 커넥션 풀이 연결되어 있어서 다시 연결하지 않습니다.");
	 		stmt = con.createStatement();
	 		System.out.println("커넥션으로부터 스테이트먼트를 얻어냈습니다.");

	 		String courseString = "";
	 		for( int i=0 ; i< course.length ; i++ ){
	 			courseString = courseString + course[i].getpersonID() + ",";
	 			if( course[i].gettype() == ApprovalCourse.SUBMITAPPROVAL )
	 				courseString = courseString + "결재;";
	 			else if( course[i].gettype() == ApprovalCourse.SUBMITINFORM )
	 				courseString = courseString + "통보;";
	 		}
	 		
	 		System.out.println("현재 전달된 결재 경로 : "+ courseString );
	 		
	 		stmt = con.createStatement();
	 		System.out.println("커넥션으로부터 스테이트먼트를 얻어냈습니다.");

			String iSQL = " SELECT courseName" +
	 		              " FROM EDAstorepath " +
			              " WHERE owner = \'" + personID + "\' "+
			              " ORDER BY courseName ";
	
			System.out.println( iSQL + "준비");
			ResultSet rs=stmt.executeQuery( iSQL );
			System.out.println( iSQL + "실행");
			
			List courseList = new ArrayList();
			while(rs.next() ){
				courseList.add ( Integer.toString(rs.getInt("courseName") ) );
			}
			
		 	for( int i = 0 ; i < courseList.size() ; i++ ) {
		 			 		
			 	ApprovalCourse[] courseInDB;
	 			List temp = new ArrayList();
	 			int courseInt = Integer.parseInt( (String) courseList.get(i) );
	 			
				iSQL = " SELECT * " +
				       " FROM EDAstorepath " +
	 			       " WHERE owner= \'" + personID +
	 			       "\' AND courseName =" + courseInt + 
	 			       " ORDER BY sequence " ;
	 				
				System.out.println( iSQL + "준비");
				rs = stmt.executeQuery( iSQL );
				System.out.println( iSQL + "실행");
			
				while( rs.next() ){
					temp.add( new ApprovalCourse ( null , rs.getString( "personID" ),
					 rs.getInt( "sequence" ), null , rs.getInt( "type") ) );
				}
				courseInDB = new ApprovalCourse[ temp.size() ];
				for ( int j = 0 ; j < temp.size() ; j ++ ){
					courseInDB[j] = (ApprovalCourse) temp.get(j);
				}
		 		
		 		String 	courseInDBString = "";
			 	for( int j = 0 ; j < courseInDB.length ; j++ ){
			 		courseInDBString = courseInDBString + courseInDB[j].getpersonID() + ",";
	 				if( courseInDB[j].gettype() == ApprovalCourse.SUBMITAPPROVAL )
	 					courseInDBString = courseInDBString + "결재;";
	 				else if( course[j].gettype() == ApprovalCourse.SUBMITINFORM )
	 					courseInDBString = courseInDBString + "통보;";
	 				if( courseInDBString.equals( courseString ) )
	 					courseNumber = Integer.parseInt((String)courseList.get(i));
	 			}
	 		}
			if( courseNumber > 0 ){
				iSQL = " DELETE FROM EDAStorepath " +
	 		 	       " WHERE owner = \'" + personID +
	 			       "\' AND courseName = " + courseNumber ; 
	 			
				System.out.println( iSQL + "준비");
				stmt.executeUpdate( iSQL );
				System.out.println( iSQL + "실행");
			}

			return ( new EDAResultStatus( SUCCESS ) );
	 	}
	 	catch(Exception e) {
			return ( new EDAResultStatus( FAILURE , e.toString() ) ); 
	 	}
	 	finally{
	 		try{
	 			if( stmt != null )
	 				stmt.close();
	 		}
	 		catch( SQLException sqle ){
	 			while(sqle != null){
	 				System.out.println("SQLState : " + sqle.getSQLState() );
	 				System.out.println("Message : " + sqle.getMessage() );
	 				System.out.println("Error code : " + sqle.getErrorCode() );
	 				sqle = sqle.getNextException();
	 				System.out.println(" ");
	 			};
	 			connectionManager.freeConnection ("access", con ) ;
	 		}
	 		connectionManager.freeConnection ("access", con ) ;
	 	}
	}
		
/*----------------------------------------------------------------- */
/**
 [메소드이름]: searchDocumentListsDB<br>
 [기능]: 문서를 검색한다.<br>
 [파라미터]: SearchCondition searchClass<br>
 [호출자] : EDAController<br>
 */
/*--------------------------------------------------------------- */	
	public ApprovalDocument[] searchDocumentListsDB( SearchCondition searchClass ) throws Exception{

		System.out.println( "searchDocumentListsDB 함수 시작");	 	
	 	Connection con = null;
	 	Statement stmt = null;
	 	boolean condStart = false;
	 	boolean andSearch = searchClass.getandSearch();
	 	List docIDs = new ArrayList();
	 	List resultList = new ArrayList();
	 	ApprovalDocument[] result ;
	 	try{
	 		 con = connectionManager.getConnection("access");
	 		System.out.println("이미 커넥션 풀이 연결되어 있어서 다시 연결하지 않습니다.");
	 		stmt = con.createStatement();
	 		System.out.println("커넥션으로부터 스테이트먼트를 얻어냈습니다.");
			//EDAOption 을 가져오는 함수
			EDAOption option = new EDAOption();
		 	boolean notHasValue = true ;
			
			String iSQL = " SELECT * " +
				      " FROM EDAOption " +
	 			      " WHERE personID = \'" + searchClass.getowner() + "\'" ;
	 				
			System.out.println( iSQL + "준비");
			ResultSet rs = stmt.executeQuery( iSQL );
			System.out.println( iSQL + "실행");

			while( rs.next() ){
				option = new EDAOption (  rs.getString( "ingBoxSort" ) , rs.getString( "ingSortMethod" ),
				 rs.getString( "completeBoxSort" ) , rs.getString( "completeSortMethod" ) ,
				 rs.getString( "rejectBoxSort" ) , rs.getString( "rejectSortMethod" ) , 
				 rs.getString( "publicBoxSort" ) , rs.getString( "publicSortMethod" ),
				 rs.getString( "defaultPath" ) , rs.getInt( "numOfItem" ) );
				notHasValue = false ;
				System.out.println("DB에 Option이 있음");
			}
			if ( notHasValue ){
				option = new EDAOption ( "initDay" , "DESC" , "initDay" , "DESC" , "initDay" , "DESC", "initDay" , "DESC" , 5 );
 				iSQL = " INSERT INTO EDAOption VALUES ( \'" + searchClass.getowner() + 
 				       "\', \'" + option.getingBoxSort() + "\', \'" + option.getingSortMethod() +
	 			       "\', \'" + option.getcompleteBoxSort() + "\', \'" + option.getcompleteSortMethod() +
	 			       "\', \'" + option.getrejectBoxSort() + "\' , \'" + option.getrejectSortMethod() +
	 			       "\', \'" + option.getpublicBoxSort() + "\' , \'" + option.getpublicSortMethod() + 
	 			       "\', null , " + option.getnumOfItem() + ")" ;

				System.out.println( iSQL + "준비");
				stmt.executeUpdate( iSQL );
				System.out.println( iSQL + "실행");
			}
			//문서함 가져오는 함수
			if( searchClass.getlistID().equals(Lists.PUBLICBOX ) )
		 		iSQL = " SELECT * FROM EDAdocument,EDAlist " +
		 		       " WHERE (personID = \'" + Lists.PUBLICUSER + 
		 		       "\' AND listID = \'" + searchClass.getlistID() +
		 		       "\' AND EDAlist.docID = EDAdocument.docID )" +
		 		       " AND ( ";
			else		
		 		iSQL = " SELECT * FROM EDAdocument,EDAlist " +
		 		       " WHERE (personID = \'" + searchClass.getowner() + 
				       "\' AND listID = \'" + searchClass.getlistID() +
		 		       "\' AND EDAlist.docID = EDAdocument.docID )" +
		 		       " AND ( ";
			
			if( searchClass.getdocIDFlag()){
	 			iSQL = iSQL + " EDAlist.docID LIKE \'" + searchClass.getdocID() + "%\' ";
	 			condStart = true;
	 		}
	 		if( searchClass.getpersonFlag() ){
	  			if(condStart){
	 				if( andSearch )
	 					iSQL = iSQL + " AND ";
	 				else
	 					iSQL = iSQL + " OR ";
	 				if ( searchClass.getinitPerson().indexOf('(') != -1 )
		 				iSQL = iSQL + " initPersonID = \'" +
		 				 searchClass.getinitPerson() + "\' ";
		 			else
		 				iSQL = iSQL + " initPersonID LIKE \'" +
		 				 searchClass.getinitPerson() + "%\' ";
	 			}
	 			else{

	 				if ( searchClass.getinitPerson().indexOf('(') != -1 )
		 				iSQL = iSQL + " initPersonID = \'" +
		 				 searchClass.getinitPerson() + "\' ";
		 			else
		 				iSQL = iSQL + " initPersonID LIKE \'" +
		 				 searchClass.getinitPerson() + "%\' ";
	 				condStart = true;
	 			}
	 		}
	 		if( searchClass.gettitleFlag()){
	 			if( condStart ){
	 				if( andSearch )
	 					iSQL = iSQL + " AND ";
	 				else
	 					iSQL = iSQL + " OR ";
	 				iSQL = iSQL + " title LIKE \'%" +
	 				 searchClass.gettitle() + "%\' ";
	 			}
	 			else{
	 				iSQL = iSQL + " title LIKE \'%" +
	 				 searchClass.gettitle() + "%\' ";
	 				condStart = true;
	 			}
	 		}
	 		if( searchClass.getcommFlag() ){
	 			if( condStart ){
	 				if( andSearch )
	 					iSQL = iSQL + " AND ";
	 				else
	 					iSQL = iSQL + " OR ";
	 				iSQL = iSQL + " comment LIKE \'%" +
	 				 searchClass.getcomment() + "%\' ";
	 			}
	 			else{
	 				iSQL = iSQL + " comment LIKE \'%" +
	 				 searchClass.getcomment() + "%\' ";
	 				condStart = true;
	 			}
	 		}
	 		if( searchClass.getdayFlag() ){ 
	 			if( condStart ){
	 				if( andSearch )
	 					iSQL = iSQL + " AND ";
	 				else
	 					iSQL = iSQL + " OR ";
	 				iSQL = iSQL + " (initDay >= \'" +
	 				 searchClass.getstartDay() + "\' AND initDay < \'" +
	 				 searchClass.getendDay() + "\')";	 			
	 			}
	 			else{
	 				iSQL = iSQL + " (initDay >= \'" +
	 				 searchClass.getstartDay() + "\' AND initDay < \'" +
	 				 searchClass.getendDay() + "\')";
	 			}
	 		}
	 		String listID = searchClass.getlistID();
			if( listID.equals( Lists.INGBOX ) )
				iSQL = iSQL + ") ORDER BY " + option.getingBoxSort() + " " + option.getingSortMethod();
			else if( listID.equals( Lists.COMPLETEBOX ) )
				iSQL = iSQL + ") ORDER BY " + option.getcompleteBoxSort() + " " + option.getcompleteSortMethod();
			else if( listID.equals( Lists.REJECTBOX ) )
				iSQL = iSQL + ") ORDER BY " + option.getrejectBoxSort() + " " + option.getrejectSortMethod();
			else if( listID.equals( Lists.PUBLICBOX ) )
				iSQL = iSQL + ") ORDER BY " + option.getpublicBoxSort() + " " + option.getpublicSortMethod();
			else
				iSQL = iSQL + ") ORDER BY initDay DESC ";
 		
	 		
	 		System.out.println(iSQL + "준비");//debug
	 		rs = stmt.executeQuery( iSQL );
	 		System.out.println(iSQL + "완료");//debug
	 		
	 		while( rs.next() ){
				if( !(searchClass.getpersonFlag() ) )
	 				docIDs.add( rs.getString("docID") );
	 			else if( searchClass.getinitPerson().indexOf('(') != -1 )
	 				docIDs.add( rs.getString("docID") );
	 			else {
	 				StringTokenizer st = new StringTokenizer ( rs.getString("initPersonID") , "(" );
	 				String personName = st.nextToken();
	 				if( searchClass.getinitPerson().equals( personName ) )
	 					docIDs.add( rs.getString("docID") );
	 			}
	 		}
			
			Iterator docIDIterator = docIDs.iterator();

			while( docIDIterator.hasNext() ){
				String docID = (String)docIDIterator.next();	
						
				iSQL = " SELECT * FROM EDAdocument " +
				       " WHERE docID = \'" + docID + "\'";
			
				System.out.println( iSQL + "준비");
				rs = stmt.executeQuery( iSQL );		
				System.out.println( iSQL + "실행");
			
				rs.next();
				ApprovalDocument document = new ApprovalDocument ( rs.getString("docID") ,
				 		rs.getString("initDay") , rs.getString("initPersonID") ,
			 			rs.getString("conditionCode") , rs.getString("title"),
			 			rs.getString("description") );
			
				iSQL = " SELECT * " +
				       " FROM EDApath " +
				       " WHERE docID = \'" + docID + "\'" +
				       " ORDER BY sequence ";
			
				System.out.println( iSQL + "준비");
				rs = stmt.executeQuery( iSQL );
				System.out.println( iSQL + "실행");
			
				while( rs.next() ){
					document.addapprovalCourse ( new ApprovalCourse (
				 	 rs.getString("docID"), rs.getString("personID"),
				 	 rs.getInt("sequence"), rs.getString("conditionCode"),
				 	 rs.getString("description"), rs.getInt("type"),
				 	 rs.getString("workDate") ) );
				}

				resultList.add( document );
			}
			result = new ApprovalDocument[ resultList.size() ];
			for( int i= 0 ; i < resultList.size() ; i++ )
				result[i] = (ApprovalDocument) resultList.get(i);

			return result;
	 	}
	 	catch(Exception e) {
			throw e; 
	 	}
	 	finally{
	 		try{
	 			if( stmt != null )
	 				stmt.close();
	 		}
	 		catch( SQLException sqle ){
	 			while(sqle != null){
	 				System.out.println("SQLState : " + sqle.getSQLState() );
	 				System.out.println("Message : " + sqle.getMessage() );
	 				System.out.println("Error code : " + sqle.getErrorCode() );
	 				sqle = sqle.getNextException();
	 				System.out.println(" ");
	 			};
	 			connectionManager.freeConnection ("access", con ) ;
	 		}
	 		connectionManager.freeConnection ("access", con ) ;
	 	}
	}
}