/**
 * @(#)file    InitCombo.java
 * @(#)author  chj
 * @(#)version 1.0
 * @(#)date    2014-06-24
 * @(#)since   JDK 1.6.2
 *
 * Copyright (c) www.udapsoft.co.kr, Inc.
 */
package com.udapsoft.waf.common.ui;

import kr.co.hsnc.common.base.WAFLogger;
import kr.co.hsnc.common.sql.RowSet;
import kr.co.hsnc.common.sql.search.Search;
import kr.co.hsnc.common.sql.search.SearchImpl;
import kr.co.hsnc.common.sql.util.RowSetUtility;
import kr.co.hsnc.common.util.ValueObject;

public class InitCombo { 
	
	private String code;		// 코드컬럼명 		ex) '1|2|3'
	private String codeName;	// 코드값컬럼명 	ex) '사업자 |개인|기타'
	


	/* IBSheet의 Combo 데이타 채우기
	 * 
	 * @param 	rowSet		combo data 컬럼을 구성할 로우셋
	 * @param	code		code컬럼 이름   
	 * @param	codeName	value컬럼 이름
	 */   
	public void makeComboData(RowSet rowSet, String codeColName, String valueColName) {
		makeComboData(rowSet, codeColName, valueColName, "", "");
	}
	
	public void makeComboData(RowSet rowSet, String codeColName, String valueColName, String defaultCode, String defaultCodeName) {
		Search search = new SearchImpl();
        RowSet listRowSet = null;
        
        String temp1="";
		String temp2="";
		
        try {
    	    // DataCombo의 자료 만들기
    	    ValueObject row = null;	    
    		for(int i=0; i < rowSet.size(); i++){
    			row = RowSetUtility.getValueObject(rowSet.getRow(i));
    			
    			if(i == 0){
    			    if( ! ( defaultCode.equals("") && defaultCodeName.equals("") ) ){
    			    	temp1 += defaultCode + "|";
    			    	temp2 += defaultCodeName + "|";
    			    }
    			    
    				temp1 += row.get(valueColName);		
    			    temp2 += row.get(codeColName);
    			}else{
    			    temp1 = temp1 + "|" + row.get(valueColName);
    				temp2 = temp2 + "|" + row.get(codeColName);
    			}
    	    }
    		
        }
        catch(Exception e) {
            
            WAFLogger.error(this.getClass().getName() + " --> makeComboData() : " + e.getMessage());
            WAFLogger.error("SQL : " + search.getStatement());
            WAFLogger.error(e);
        }
        finally {
        	this.code = temp1;
        	this.codeName = temp2;
        }
    }
	
	public String getCode() {
		return this.code;
	}
	
	public String getCodeName(){
		return this.codeName;
	}
	
}
