/**
 * @(#)file    SYSRightCommon.java
 * @(#)author  DaeJin Lee
 * @(#)version 1.0
 * @(#)date    2003-07-23
 * @(#)since   JDK1.3.1
 *
 * Copyright (c) 2002-2003 www.hwenc.com, Inc.
 * All rights reserved.
 * This software is the proprietary information of hwenc, Inc.
 */
package kr.co.udapsoft.ebid.buyer.sycs.security.biz;

import kr.co.hsnc.common.base.WAFLogger;
import kr.co.hsnc.common.sql.RowSet;
import kr.co.hsnc.common.sql.RowSetImpl;
import kr.co.hsnc.common.sql.search.Search;
import kr.co.hsnc.common.sql.search.SearchImpl;
import com.udapsoft.waf.common.ui.HTMLMaker; 


/**
 * 권한 관리 공통 모듈
 * 
 * @author DaeJin Lee
 */
public class SYSRightCommon {

    private static String ACCT_TABLE     = "PUB0120T";

    private static String R_TABLE        = "PUB0340T";
    private static String R_LIST_TABLE   = "PUB0350T";

    private static String PGM_TABLE      = "PUB0320T";
    private static String PGM_GR_TABLE   = "PUB0310T";
    private static String PGM_LIST_TABLE = "PUB0300T";
    private static String PGM_SYS_TABLE  = "PUB0390T";

    /**
     * 시스템 코드 SELECT Html tag 리턴
	 * @param selectedValue
	 * @return
	 */
	public String getSystemSelectTag(String selectedValue) {

        return getSystemSelectTag(selectedValue, null);
    }

    /**
     * 시스템 코드 SELECT Html tag 리턴
	 * @param selectedValue
	 * @return
	 */
	public String getSystemSelectTag(String selectedValue, String style) {

        RowSet rowSet = getSystemRowSet();

        return HTMLMaker.getSelectTag(rowSet, "SYSTEM_ID", "NAME", "system_id", style, "<OPTION value=''>-- 전체 --</OPTION>", selectedValue, 7);
    }
    public String getSystemSelectTagCombo(String selectedValue, String style) {

        RowSet rowSet = getSystemRowSetCombo();

        return HTMLMaker.getSelectTagText4Sheet(rowSet);
    }
    public String getSystemSelectTagCode(String selectedValue, String style) {

        RowSet rowSet = getSystemRowSetCombo();
        
        return HTMLMaker.getSelectTagValue4Sheet( rowSet);
    }

    /**
     * 검색을 위한 시스템 목록 리턴
     * @return
     */
    public RowSet getSystemRowSet() {
        
        Search search = new SearchImpl();
        RowSet sysRowSet = null;
        String sqlstr = "";
        try {

            sqlstr = " SELECT   SYSTEM_ID, SYSTEM_CODE, NAME \n"
                   + " FROM     " + PGM_SYS_TABLE + "        \n"
                   + " ORDER BY SEQ                          \n";
            search.setStatement(sqlstr);
            sysRowSet = search.execute();
        }
        catch(Exception e) {

            WAFLogger.error(this.getClass().getName() + " --> getSystemRowSet() : " + e.getMessage());
            WAFLogger.error("SQL : " + search.getStatement());
            WAFLogger.error(e);
            return null;
        }
        finally {

            if( sysRowSet == null ) sysRowSet = new RowSetImpl();
            return sysRowSet;
        }
    }
     public RowSet getSystemRowSetCombo() {
        
        Search search = new SearchImpl();
        RowSet sysRowSet = null;
        String sqlstr = "";
        
        /*IBSheet에 들어갈 code 값도 변환을 해야 explore 표현 된다. 
         * ex) COMBO_CODE ==> "1@OUT"         
         */
        try {

            sqlstr = " SELECT  NAME, CONCAT(CONCAT(SYSTEM_ID,'@'),SYSTEM_CODE) AS COMBO_CODE, SYSTEM_ID, SYSTEM_CODE \n"
                   + " FROM     " + PGM_SYS_TABLE + "        \n"
                   + " ORDER BY SEQ                          \n";
            search.setStatement(sqlstr);
            sysRowSet = search.execute();
        }
        catch(Exception e) {

            WAFLogger.error(this.getClass().getName() + " --> getSystemRowSet() : " + e.getMessage());
            WAFLogger.error("SQL : " + search.getStatement());
            WAFLogger.error(e);
            return null;
        }
        finally {

            if( sysRowSet == null ) sysRowSet = new RowSetImpl();
            return sysRowSet;
        }
    }

}
