/*************************************************************************************************
	프로그램명		: DeptView.java
	프로그램설명	    : 부서 상세 정보
	작성자				: 조 용 준
	작성일				: 04.07.02
	변경일				:	
**************************************************************************************************/
package kr.co.kihyun.beans.totsys.sysadm.dept;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import kr.co.kihyun.db.DBManager;
import kr.co.kihyun.db.SQLMessage;

/*
 * @Deprecated
 * use kr.co.kihyun.beans.entity Package and Moumi.getEntityManager() method
 */
@Deprecated
public class DeptView extends DBManager{
	private static final Logger LOG = LoggerFactory.getLogger(DeptView.class);
	ResultSet rs = null;

	int id = 0;
	String name = "";
	String addr = "";
	String phone = "";
	String passcode = "";
	String recoImg = "";
	String upperDept = "";
	boolean selType = false;
	int priority = -1;
	String location = "";
        String organ="";

	public void executeQuery(String id){
		String sql = "";

		try{
			sql ="select name, addr, phone, passcode, reco_img, upper_dept,  organ,  sel_type, priority, location from moumi_dept where id=?";
			rs = execQuery(sql,id);
			if(rs.next()){
				name = rs.getString(1);
				addr = rs.getString(2);
				phone = rs.getString(3);
				passcode = rs.getString(4);
				recoImg = rs.getString(5);
				upperDept = rs.getString(6);				
				organ = rs.getString(7);
				selType = rs.getBoolean(8);
				priority = rs.getInt(9);
				location = rs.getString(10);

			}
		}catch(SQLException sqlEx){
			name = "NONAME";
			LOG.error("\nSQLState - {}\nMySQL Error Code - {}\nmessage - {}\nsql - {}",
					new Object[] {sqlEx.getSQLState(), sqlEx.getErrorCode(), sqlEx.getMessage(), sql});
                        sqlEx.printStackTrace();
		}catch(Exception ex){
			name = "NONAME";
			ex.printStackTrace();
		}finally{
			close(rs);
			execClose();
		}
	}
	
	public String getUpperDeptName()
	{
		String sql = "select name from moumi_dept where id='"+upperDept+"'";
               
		String upperName = "";
		
		try{

			rs = execQuery(sql);
			
			if(rs.next()){
				upperName = rs.getString(1);
                               
			}
			
			return upperName;
		}catch(SQLException sqlEx){
			LOG.error("\nSQLState - {}\nMySQL Error Code - {}\nmessage - {}\nsql - {}",
					new Object[] {sqlEx.getSQLState(), sqlEx.getErrorCode(), sqlEx.getMessage(), sql});
                        sqlEx.printStackTrace();
			return "NOUPPERNAME";
		}catch(Exception ex){
			ex.printStackTrace();
			return "NOUPPERNAME";
		}finally{
			close(rs);
			execClose();
		}
	}



	/***** 각각의 필드값 얻는 메소드 *******/
	public int getID(){ return id; }
	public String getName(){ return name; }
	public String getAddr(){ return addr; }
	public String getPhone(){ return phone; }
	public String getPasscode(){ return passcode; }
	public String getRecoImg(){ return recoImg; }
	public String getOrgan(){ return organ; }
	public String getUpperDeptID(){ return upperDept; }
	public boolean getSelType(){ return selType; }
	public int getPriority(){ return priority; }
	public String getLocation() {return location;}
        public String getUpperDept() {return upperDept;}
}
