package idc;

import idc.client.command.IdcClientDBListCmd;
import idc.deposit.command.IdcDepositBillPaperCmd;
import idc.deposit.command.IdcDepositFormCmd;
import idc.deposit.command.IdcDepositListCmd;
import idc.deposit.command.IdcDepositListExcelCmd;
import idc.deposit.command.IdcDepositModifyCmd;
import idc.deposit.command.IdcDepositNonPaymentListCmd;
import idc.deposit.command.IdcDepositNonPaymentListExcelCmd;
import idc.deposit.command.IdcDepositWriteCmd;
import idc.deposit.command.IdcDetailListCmd;
import idc.deposit.command.IdcPaymentListFormCmd;
import idc.deposit.command.IdcReSendBillPaperFormCmd;
import idc.deposit.command.IdcReSendMailListFormCmd;
import idc.deposit.command.IdcWeeklyNonpaymentCmd;
import idc.deposit.command.IdcWeeklyNonpaymentModifyCmd;
import idc.model.IdcCmd;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * Servlet implementation class IdcClientFrontController
 */
@WebServlet("*.dep")
public class IdcDepositFrontController extends HttpServlet {
	private static final long serialVersionUID = 1L;
    private static final String DEPOSIT_PATH="/jsp/deposit/";
    /**
     * @see HttpServlet#HttpServlet()
     */
    public IdcDepositFrontController() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request,response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{
		response.setDateHeader("Expires", 0);
		response.setHeader("Cache-Control","no-Cache");
		response.setHeader("Cache-Control","no-store");
		response.setContentType("charset='utf-8'");

		request.setCharacterEncoding("UTF-8");
		
		String requestURI = request.getRequestURI();
		String contextPath = request.getContextPath();
		String cmdURI = requestURI.substring(contextPath.length());
		IdcCmd cmd = null;
		String viewPage = "LayoutPage.jsp";
		
		Object obj=request.getSession().getAttribute("member");
		if(obj!=null)
		{
			System.out.println(cmdURI);
	//		입금등록 창
			if(cmdURI.equals("/IdcDepositForm.dep"))
			{
				cmd = new IdcDepositFormCmd();
				cmd.execute(request,response);
				request.setAttribute("TargetFile", DEPOSIT_PATH+"IdcDepositForm.jsp");
			}
			//입금등록
			if(cmdURI.equals("/IdcDepositWrite.dep"))
			{
				cmd = new IdcDepositWriteCmd();
				cmd.execute(request, response);
				viewPage="IdcDepositList.dep";
			}
			//입금리스트
			if(cmdURI.equals("/IdcDepositList.dep"))
			{
				cmd = new IdcDepositListCmd();
				cmd.execute(request,response);
				request.setAttribute("TargetFile", DEPOSIT_PATH+"IdcDepositList.jsp");
			}
			//입금리스트
			if(cmdURI.equals("/IdcDepositListMK.dep"))
			{
				cmd = new IdcDepositListCmd();
				cmd.execute(request,response);
				request.setAttribute("TargetFile", DEPOSIT_PATH+"IdcDepositListMK.jsp");
			}			
	//		입금리스트 수정 
			if(cmdURI.equals("/IdcDepositModify.dep"))
			{
				cmd = new IdcDepositModifyCmd();
				cmd.execute(request,response);
				viewPage="IdcDepositList.dep";
			}
			//미납리스트
			if(cmdURI.equals("/IdcDepositNonPaymentList.dep"))
			{
				cmd = new IdcDepositNonPaymentListCmd();
				cmd.execute(request,response);
				request.setAttribute("TargetFile", DEPOSIT_PATH+"IdcDepositNonPaymentList.jsp");
			}
			//NEW 미납리스트
			if(cmdURI.equals("/IdcDepositNonPaymentListMK.dep"))
			{
				cmd = new IdcDepositNonPaymentListCmd();
				cmd.execute(request,response);
				request.setAttribute("TargetFile", DEPOSIT_PATH+"IdcDepositNonPaymentListMK.jsp");
			}			
			//청구서 페이지
			if(cmdURI.equals("/IdcDepositBillPaper.dep"))
			{
				cmd = new IdcDepositBillPaperCmd();
				cmd.execute(request,response);
				request.setAttribute("TargetFile", DEPOSIT_PATH+"IdcDepositBillPaperForm.jsp");
			}
			//청구서 발송 리스트
			if(cmdURI.equals("/IdcReSendMailList.dep"))
			{
				cmd = new IdcReSendMailListFormCmd();
				cmd.execute(request,response);
				request.setAttribute("TargetFile", DEPOSIT_PATH+"IdcReSendMailListForm.jsp");
			}
			//청구서 재발송
			if(cmdURI.equals("/IdcReSendBillPaperForm.dep"))
			{
				cmd = new IdcReSendBillPaperFormCmd();
				cmd.execute(request,response);
				request.setAttribute("TargetFile", DEPOSIT_PATH+"IdcReSendBillPaperForm.jsp");
			}
			//테스트용 기본페이지.
			if(cmdURI.equals("/DefaultPage.main"))
			{
				cmd = new IdcClientDBListCmd(true);
				cmd.execute(request,response);
				request.setAttribute("TargetFile", DEPOSIT_PATH+"IdcClientDBList.jsp");
			}
	//		결제 내역페이지
			if(cmdURI.equals("/IdcPaymentList.dep"))
			{
				cmd = new IdcPaymentListFormCmd();
				cmd.execute(request,response);
				request.setAttribute("TargetFile", DEPOSIT_PATH+"IdcPaymentListForm.jsp");
			}
			
			//주간 및 월간 미납리스트 뿌려주기
			if(cmdURI.equals("/IdcWeeklyNonpayment.dep")){
				cmd = new IdcWeeklyNonpaymentCmd();
				cmd.execute(request, response);
				request.setAttribute("TargetFile", DEPOSIT_PATH+"IdcWeeklyNonpayment.jsp");
			}
			//주간 및 월간 미납리스트 비고 수정하기
			if(cmdURI.equals("/IdcWeeklyNonpaymentModify.dep")){
				System.out.println("주간 및 월간 미납리스트 비고 수정하기");
				cmd = new IdcWeeklyNonpaymentModifyCmd();
				cmd.execute(request, response);				
				viewPage="IdcWeeklyNonpayment.dep";
			}
			//15일간 내역 리스트 뿌려주기
			if(cmdURI.equals("/IdcDetailList.dep")){
				cmd = new IdcDetailListCmd();
				cmd.execute(request, response);
				request.setAttribute("TargetFile", DEPOSIT_PATH+"IdcDetailList.jsp");
			}
			//미납리스트 엑셀 페이지
			if(cmdURI.equals("/IdcDepositNonPaymentListExcel.dep"))
			{
				cmd = new IdcDepositNonPaymentListExcelCmd();
				cmd.execute(request,response);
				request.setAttribute("TargetFile", DEPOSIT_PATH+"IdcDepositNonPaymentListExcel.jsp");
			}
			//입금리스트
			if(cmdURI.equals("/IdcDepositListExcel.dep"))
			{
				cmd = new IdcDepositListExcelCmd();
				cmd.execute(request,response);
				request.setAttribute("TargetFile", DEPOSIT_PATH+"IdcDepositListExcel.jsp");
			}
		}
		else
		{
			request.setAttribute("TargetFile", "jsp/main/IdcLoginForm.jsp");
		}
		RequestDispatcher dis = request.getRequestDispatcher(viewPage);
		dis.forward(request, response);
	}
}

