package kr.co.kihyun.tree;

import java.sql.ResultSet;
import java.sql.SQLException;
//import java.io.IOException;
//import java.io.PrintWriter;
//import javax.servlet.ServletException;
//import javax.servlet.http.HttpServlet;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import kr.co.kihyun.lang.Encoder;
//import kr.co.kihyun.lang.MInteger;
//import kr.co.kihyun.lang.MLong;
//import kr.co.kihyun.moumi.MoumiConfig;
import kr.co.kihyun.db.DBManager;
import kr.co.kihyun.lang.MString;
//import kr.co.kihyun.beans.user.HttpSSOLogin;

public class GroupCount extends DBManager {

    public String getCount(String id, String name) {
        ResultSet rs = null;
        String tmp = name;
      //2014.09.22 Update by KWON,HAN : 부서사용여부(Y:폐교) 추가
      //String sql="select count(*) from moumi_user_dept where part_id='"+id+"'";
        String sql  = "";
                
        sql  = "SELECT COUNT(a.part_id) AS part_id_count    \n";
        sql += "  FROM moumi_user_dept a    \n";
        sql += "     , moumi_dept      dt    \n";
        sql += " WHERE a.part_id = '" + id + "'  \n";
        sql += "   AND a.id = dt.id    \n";
        sql += "   AND dt.is_out = 'N' AND dt.sel_type='Y'    \n";

        try {
            rs = execQuery(sql);
            if (rs.next()) {
                tmp += "(" + MString.checkNull(rs.getString(1), "0") + ")";
            }
        //44.적절하지 않은 예외처리(광범위예외클래스)_CWE-754 Add by YOUNGJUN,CHO
        } catch (SQLException sqlex) {
            tmp = "(?)";
            sqlex.printStackTrace();
        //++++++++++++++++++++++++++++++++++++++++++++++++
        } catch (Exception ex) {
            tmp = "(?)";
            //System.out.println("error exception3:" + ex);
            ex.printStackTrace();
        } finally {
            if (rs != null) {
                close(rs);
            }
            execClose();
            return tmp;
        }
    }
}
