package idc.cupon.command;

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

import java.sql.Date;
import java.util.ArrayList;

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

public class IdcCuponWriteForm2Cmd implements IdcCmd 
{
	IdcDAO dao;
	
	public IdcCuponWriteForm2Cmd() 
	{
		dao = new IdcDAO();
	}
	
	//쿠폰등록창 (2)
	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response)
	{
		//데이타 가져오기
		String[] getNum = request.getParameterValues("checkNum");
		String[] getDate = request.getParameterValues("endDay");
		ArrayList<IdcCuponDBDTO> list = (ArrayList<IdcCuponDBDTO>)request.getSession().getAttribute("IdcServiceList");
		ArrayList<IdcCuponDBDTO> dtoList = new ArrayList<IdcCuponDBDTO>();

		//세션데이터 지우기
		request.getSession().removeAttribute("IdcServiceList");
		
		//필요데이터만 뽑아내기
		int temp=0;
		if(getNum != null)
		{
			for(int i=0;i<getNum.length;i++)
			{
				temp =Integer.parseInt(getNum[i])-1;
				list.get(temp).setCupon_end_date(Date.valueOf(getDate[temp]));
				dtoList.add(list.get(temp));
			}
		}
		request.getSession().setAttribute("IdcServiceList", dtoList);
	}
}
