package idc.service.command;

import idc.model.IdcCmd;
import idc.model.IdcDAO;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class IdcCSInfoUpdateCmd implements IdcCmd{
	private IdcDAO dao = new IdcDAO();
	public void execute(HttpServletRequest request, HttpServletResponse response){		
		setatt(request);
	}
	
	private void setatt(HttpServletRequest request){
		
		String vpc_num = request.getParameter("vpc_num");
		request.setAttribute("service_line", request.getParameter("service_line"));
		request.setAttribute("client_name", request.getParameter("client_name"));
		request.setAttribute("service_ip", request.getParameter("service_ip"));
		request.setAttribute("server_code", request.getParameter("server_code"));
		request.setAttribute("vpc_last_date", request.getParameter("vpc_last_date"));
		
		Connection conn=null;
		PreparedStatement pstmt=null;
		ResultSet rs=null;
		try	
		{
			conn=dao.getConn();
			String sql="SELECT * FROM vpcdb WHERE vpc_num="+vpc_num+" ";
			pstmt =conn.prepareStatement(sql);
			rs = pstmt.executeQuery();
			while(rs.next())
			{
				request.setAttribute("vpc_num", rs.getString("vpc_num"));
				request.setAttribute("vpc_code", rs.getString("vpc_code"));
				request.setAttribute("vpc_csip", rs.getString("vpc_csip"));
				request.setAttribute("vpc_connect_domain", rs.getString("vpc_connect_domain"));
				request.setAttribute("vpc_connect_domain_dn", rs.getString("vpc_connect_domain_dn"));
				request.setAttribute("vpc_connect_domain_my", rs.getString("vpc_connect_domain_my"));
				request.setAttribute("vpc_connect_domain_etc", rs.getString("vpc_connect_domain_etc"));
				request.setAttribute("vpc_fireWall", rs.getString("vpc_fireWall"));
				request.setAttribute("vpc_note", rs.getString("vpc_note"));
			}
		}
		catch (Exception e) 
		{
			System.out.println("IdcCSInfoUpdateCmd 에서의 exception");
			e.printStackTrace();
		}
		finally
		{
			try 
			{
				if(conn!=null) conn.close();
				if(pstmt!=null)pstmt.close();
				if(rs!=null)rs.close();
			}
			catch (SQLException e) 
			{
				System.out.println("IdcCSInfoUpdateCmd 에서의 sqlexception");
				e.printStackTrace();
			}
		}
	}

}
