package idc.main.command;

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;

import idc.model.*;

public class IdcIndexCmd implements IdcCmd{

	IdcDAO dao = new IdcDAO();
	
	public void execute(HttpServletRequest request, HttpServletResponse response){
		ArrayList<IdcHaveListDBDTO> list=null;
		
		list = idcClientAllServerList();
		request.setAttribute("IdcHaveList", list);
		
	}
	
	//보유현황 페이지 읽어오기
	public ArrayList<IdcHaveListDBDTO> idcClientAllServerList()
	{
		ArrayList<IdcHaveListDBDTO> names=new ArrayList<IdcHaveListDBDTO>();
		
		Connection conn=null;
		PreparedStatement pstmt=null;
		ResultSet rs = null;
		
		try 
		{
			conn = dao.getConn();
			String sql = "SELECT * FROM havelist ";
			pstmt = conn.prepareStatement(sql);
						
			rs = pstmt.executeQuery();
			
			while(rs.next())
			{
				IdcHaveListDBDTO dto = new IdcHaveListDBDTO();
				dto.setClient_name(rs.getString("client_name"));
				dto.setDefence_c(rs.getInt("defence_c"));
				dto.setDefence_t(rs.getInt("defence_t"));
				dto.setNormal_c(rs.getInt("normal_c"));
				dto.setNormal_t(rs.getInt("normal_t"));
				dto.setSolo_c(rs.getInt("solo_c"));
				dto.setSolo_t(rs.getInt("solo_t"));
				dto.setSub_c(rs.getInt("substitution_c"));
				dto.setSub_t(rs.getInt("substitution_t"));
				dto.setTest_c(rs.getInt("test_c"));
				dto.setTest_t(rs.getInt("test_t"));
				dto.setTest_total(rs.getInt("test_total"));
				dto.setTotal_c(rs.getInt("total_c"));
				dto.setTotal_t(rs.getInt("total_t"));
				dto.setTotal_total(rs.getInt("total_total"));
				dto.setSoloLine_c(rs.getInt("soloLine_c"));
				dto.setSoloLine_t(rs.getInt("soloLine_t"));
				names.add(dto);
			}
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		finally
		{
			try 
			{
				if(conn!=null) conn.close();
				if(pstmt!=null) pstmt.close();
				if(rs!=null) rs.close();				
			} 
			catch (SQLException e) 
			{
				e.printStackTrace();
			}
		}
		return names;
	}	

}
