package idc.line.command;

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

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

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

public class IdcLineModifyFormCmd implements IdcCmd 
{
	IdcDAO dao;
	public IdcLineModifyFormCmd() 
	{
		dao = new IdcDAO();
	}
	
	//라인 수정 페이지.
	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response) 
	{
		String lineNum = request.getParameter("lineNum");
		
		IdcLineDBDTO dto=idcLineModifyFormCmd(Integer.parseInt(lineNum));
		
		request.setAttribute("LineDB", dto);
	}
	
	private IdcLineDBDTO idcLineModifyFormCmd(int lineNum)
	{
		IdcLineDBDTO dto = new IdcLineDBDTO();
		
		Connection conn=null;
		PreparedStatement pstmt=null;
		ResultSet rs=null;
		try	
		{
			conn=dao.getConn();
			String sql="SELECT * FROM linedb WHERE line_Num = ?";
			pstmt =conn.prepareStatement(sql);
			pstmt.setInt(1, lineNum);
			rs = pstmt.executeQuery();
			
			if(rs.next())
			{
				dto.setLine_num(lineNum);
				dto.setLine_able(rs.getString("line_able"));
				dto.setLine_before_allocatingday(rs.getDate("line_before_allocatingday"));
				dto.setLine_before_endday(rs.getDate("line_before_endday"));
				dto.setLine_before_mainip(rs.getString("line_before_mainip"));
				dto.setLine_before_subip1(rs.getString("line_before_subip1"));
				dto.setLine_before_subip2(rs.getString("line_before_subip2"));
				dto.setLine_before_subip3(rs.getString("line_before_subip3"));
				dto.setLine_before_user(rs.getString("line_before_user"));
				dto.setLine_block(rs.getString("line_block"));
				dto.setLine_block_endday(rs.getDate("line_block_endday"));
				dto.setLine_block_note(rs.getString("line_block_note"));
				dto.setLine_case(rs.getString("line_case"));
				dto.setLine_client_name(rs.getString("line_client_name"));
				dto.setLine_code(rs.getString("line_code"));
				dto.setLine_gateway(rs.getString("line_gateway"));
				dto.setLine_haveip(rs.getString("line_haveip"));
				dto.setLine_id(rs.getString("line_id"));
				dto.setLine_IP(rs.getString("line_IP"));
				dto.setLine_mainip(rs.getString("line_mainip"));
				dto.setLine_name(rs.getString("line_name"));
				dto.setLine_note(rs.getString("line_note"));
				dto.setLine_pass(rs.getString("line_pass"));
				dto.setLine_phone(rs.getString("line_phone"));
				dto.setLine_reason(rs.getString("line_reason"));
				dto.setLine_subip1(rs.getString("line_subip1"));
				dto.setLine_subip2(rs.getString("line_subip2"));
				dto.setLine_subip3(rs.getString("line_subip3"));
				dto.setLine_subnet(rs.getString("line_subnet"));
				dto.setLine_user_allocatingday(rs.getDate("line_user_allocatingday"));
				dto.setLine_user_endday(rs.getDate("line_user_endday"));
				
			}
		}
		catch (Exception e) 
		{
			System.out.println("idcLineModifyFormCmd 에서의 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("idcLineModifyFormCmd 에서의 sqlexception");
				e.printStackTrace();
			}
		}
		
		return dto;
	}
}
