package idc.service.command;

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

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

import java.sql.*;

public class IdcKtCSInfoUpdateCmd implements IdcCmd{
	
	private IdcDAO dao = new IdcDAO();
	
	public void execute(HttpServletRequest request, HttpServletResponse response){
		
		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("kcs_last_date", request.getParameter("kcs_last_date"));
		setatt(request);
	}
	
	//kcs 정보 받아오기
	private void setatt(HttpServletRequest request)
	{
		
		String kcs_num = request.getParameter("kcs_num");
		
		Connection conn=null;
		PreparedStatement pstmt=null;
		ResultSet rs=null;
		try	
		{
			conn=dao.getConn();
			String sql="SELECT * FROM kcsdb WHERE kcs_num="+kcs_num+" ";			
			pstmt =conn.prepareStatement(sql);
			rs = pstmt.executeQuery();
			while(rs.next())
			{
				request.setAttribute("kcs_num", kcs_num);
				request.setAttribute("kcs_code", rs.getString("kcs_code"));
				request.setAttribute("kcs_ip", rs.getString("kcs_ip"));
				request.setAttribute("kcs_use_domain", rs.getString("kcs_use_domain"));
				request.setAttribute("kcs_connect_domain", rs.getString("kcs_connect_domain"));
				request.setAttribute("kcs_note", rs.getString("kcs_note"));
				request.setAttribute("service_admin", rs.getString("kcs_admin"));
			}
		}
		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();
			}
		}
	}
}
