
package kr.co.kihyun.tree;

import java.sql.ResultSet;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
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;
import kr.co.kihyun.text.html.ServletUtil;

public class DeptDelete extends DBManager
{
	public DeptDelete(HttpServletRequest req,HttpServletResponse res)
	{
		PrintWriter out=null;
		try
		{
			res.setContentType("text/html;charset=UTF-8");
			out = res.getWriter();
    	if(!HttpSSOLogin.isLogin(req)) 
			{
				String connURL = "location='/totsys/login/login.jsp';";
				out.println(ServletUtil.getJavaScript(connURL));
				return;
			}
			String deptId=MString.checkNull(req.getParameter("id"),"null");
			if(deptId.equals("null")) deptId=null; 
      if(deptId!=null && !deptId.equals("ROOT"))
      {
			  String sql="UPDATE MOUMI_DEPT SET SEL_TYPE='N' WHERE ID='"+deptId+"'";
			  execUpdate(sql);
      }
			out.println(ServletUtil.alert(MoumiConfig.getMessageBundle().getString("moumi.message.popup.coporationChange")));
			out.println(ServletUtil.redirect("/totsys/sysadm/dept/empty.jsp?reload=yes"));
		//44.적절하지 않은 예외처리(광범위예외클래스)_CWE-754 Add by YOUNGJUN,CHO
                } catch (IOException ioex) {
                    ioex.printStackTrace();
                    out.println(ServletUtil.alert(MoumiConfig.getMessageBundle().getString("moumi.message.popup.notCoporationChangeAdmin")));
                    out.println(ServletUtil.redirect("/totsys/sysadm/dept/empty.jsp?reload=no"));
                } catch (SQLException sqlex) {
                    sqlex.printStackTrace();
                    out.println(ServletUtil.alert(MoumiConfig.getMessageBundle().getString("moumi.message.popup.notCoporationChangeAdmin")));
                    out.println(ServletUtil.redirect("/totsys/sysadm/dept/empty.jsp?reload=no"));
                    //++++++++++++++++++++++++++++++++++++++++++++++++
                } 
		catch (Exception e) 
		{
			e.printStackTrace();
			out.println(ServletUtil.alert(MoumiConfig.getMessageBundle().getString("moumi.message.popup.notCoporationChangeAdmin")));
			out.println(ServletUtil.redirect("/totsys/sysadm/dept/empty.jsp?reload=no"));
		} 
		finally { execClose(); }
	}
}
