/*
 * MosP - Mind Open Source Project         http://www.mosp.jp/
 * Copyright (C) 1987-2009 MIND Co., Ltd.  http://www.e-mind.co.jp/
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package jp.mosp.system.vo;

import java.util.Iterator;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import jp.mosp.common.CommonConst;
import jp.mosp.common.MosPVo;
import jp.mosp.common.common.MospException;

import jp.mosp.system.dto.MCodeDto;

public class YukyuInformationCardVo extends MosPVo {	

	private static final long serialVersionUID = 8784848856294588759L;

	//URL、JSファイル、CSSファイル
	private static final String RETURN_URL = "/jsp/system/yukyuInformationCard.jsp";
	private static final String EXTRA_JS   = "/pub/system/js/yukyuInformationCard.js";
	private static final String EXTRA_CSS  = "/pub/system/css/yukyuInformationCard.css";

	//画面サブタイトル
	public final String SUB_TITLE = CommonConst.TTL_PAID_HOLIDAY_MASTER;
	//画面で使う名称
	public final String SUB_TITLE1 = CommonConst.NAM_CARRIED_FORWARD + CommonConst.NAM_PROCESS + CommonConst.NAM_SET_UP;
	public final String SUB_TITLE2 = CommonConst.NAM_PAID_HOLIDAY + CommonConst.NAM_SUPPLY + CommonConst.NAM_CONDITION;

	//定数
	public static final int MODE_UPDATE = 1;

	//パラメーター名
	public static final String PRM_PLT_CF_MONTH	= "pltCFMonth";
	public static final String PRM_TXT_CF_DAYS 	= "txtCFDays";
	public static final String PRM_PLT_CF_KBN		= "pltCFKbn";

	public static final String PRM_TXT_STANDARD 	= "txtStandard";
	public static final String PRM_TXT_DAYS 		= "txtDays";
	public static final String PRM_TXT_INFO		= "txtInfo";

	//フィールド
	private String  	pltCFMonth		;	
	private String 		txtCFDays		;	
	private String  	pltCFKbn		;	
	private String[]  	aryTxtStandard	;
	private String[]  	aryTxtDays		;
	private String[]  	aryTxtInfo		;

	//プルダウンリスト
	public String[][] aryPltCFKbn;
	public String[][] aryPltCFMonth;

	//モード(1：更新)
	private int mode;

	//フィールド名及び制限
	public static final String NAM_CF_MONTH	= CommonConst.NAM_CARRIED_FORWARD + CommonConst.NAM_PROCESS + CommonConst.NAM_MONTH;
	public static final String NAM_CF_DAYS 	= CommonConst.NAM_CARRIED_FORWARD + CommonConst.NAM_NUMBER_OF_DAYS;
	public static final String NAM_CF_KBN 	= CommonConst.NAM_CARRIED_FORWARD + CommonConst.NAM_COMMON_TYPE;
	public static final String NAM_STANDARD	= CommonConst.NAM_SUPPLY + CommonConst.NAM_CONDITION;
	public static final String NAM_DAYS 		= CommonConst.NAM_SUPPLY + CommonConst.NAM_NUMBER_OF_DAYS;
	public static final String NAM_INFO 		= CommonConst.NAM_EXPLANATION;

	public static final int LEN_CF_MONTH		= 2;
	public static final int LEN_CF_DAYS 		= 2;
	public static final int LEN_STANDARD		= 2;
	public static final int LEN_DAYS 			= 2;
	public static final int LEN_INFO 			= 7;

	/**
	 * コンストラクタ
	 */
	public YukyuInformationCardVo(){
		super();
		mode = 0;
		setExtraCss	(EXTRA_CSS);
		addExtraJs	(EXTRA_JS);
		setRetUrl	(RETURN_URL);
		pltCFMonth	= "";
		txtCFDays		= "";
		pltCFKbn			= "";
		aryTxtStandard	= new String[0];
		aryTxtDays		= new String[0];
		aryTxtInfo		= new String[0];
	}

	/**
	 * 初期値設定
	 */	
	public void setDefaultValues(){
		aryTxtStandard = new String[20];
		for (int i = 0; i < aryTxtStandard.length; i++) {
			aryTxtStandard[i] = "";
		}
		aryTxtDays = new String[20];
		for (int i = 0; i < aryTxtDays.length; i++) {
			aryTxtDays[i] = "";
		}
		aryTxtInfo = new String[20];
		for (int i = 0; i < aryTxtInfo.length; i++) {
			aryTxtInfo[i] = "";
		}
	}

	/**
	 * パラメータ設定
	 */
	public void setParams(HttpServletRequest request){
		pltCFMonth		= request.getParameter(PRM_PLT_CF_MONTH);
		txtCFDays 		= request.getParameter(PRM_TXT_CF_DAYS);
		pltCFKbn 		= request.getParameter(PRM_PLT_CF_KBN);
		aryTxtStandard	= request.getParameterValues(PRM_TXT_STANDARD);
		aryTxtDays 		= request.getParameterValues(PRM_TXT_DAYS);
		aryTxtInfo 		= request.getParameterValues(PRM_TXT_INFO);
	}

	/**
	 * フィールド設定
	 * @param listYukyuInfo 有休情報リスト
	 */
	public void setFields(List listYukyuInfo) throws MospException{
		//リストの設定
		list = listYukyuInfo;
		// データ総数の取得
		count = 20;
		// 配列の初期化
		aryTxtStandard	= new String[count];
		aryTxtDays		= new String[count];
		aryTxtInfo		= new String[count];
		for (int i = 0; i < 20 ; i++) {
			aryTxtStandard[i] = "";
			aryTxtDays[i] = "";
			aryTxtInfo[i] = "";
		}
		//データの設定		
		int i = 0;
		Iterator it = listYukyuInfo.iterator();
		while (it.hasNext()){
			MCodeDto dto = (MCodeDto)it.next();
			aryTxtStandard[i]	= escapeHTML(dto.getTCode());
			aryTxtDays[i] 		= escapeHTML(dto.getTChange());
			aryTxtInfo[i] 		= escapeHTML(dto.getTName());
			i++;
		}
	}

	/**
	 * フィールド設定(DTOに対するVO情報のセット)
	 * @param dto 設定対象DTO
	 */
	public void setDtoFieldsCFMonth(MCodeDto dto) {
		dto.setTCode(CommonConst.NAM_CARRIED_FORWARD + CommonConst.NAM_MONTH);
		dto.setTChange(pltCFMonth);
	}

	/**
	 * フィールド設定(DTOに対するVO情報のセット)
	 * @param dto 設定対象DTO
	 */
	public void setDtoFieldsCFDay(MCodeDto dto) {
		dto.setTCode(CommonConst.NAM_CARRIED_FORWARD + CommonConst.NAM_NUMBER_OF_DAYS);
		dto.setTChange(txtCFDays);
	}

	/**
	 * フィールド設定(DTOに対するVO情報のセット)
	 * @param dto 設定対象DTO
	 */
	public void setDtoFieldsCFDivision(MCodeDto dto) {
		dto.setTCode(CommonConst.NAM_CARRIED_FORWARD + CommonConst.NAM_COMMON_TYPE);
		dto.setTName(CommonConst.TNM_CARRY_OVER);
		dto.setTChange(pltCFKbn);
	}

	/**
	 * フィールド設定(DTOに対するVO情報のセット)
	 * @param dto 設定対象DTO
	 */
	public void setDtoFields(List<MCodeDto> listCode) {
		for (int i = 0; i < aryTxtStandard.length; i++) {
			MCodeDto dto = new MCodeDto();
			dto.setTId(CommonConst.NAM_PAID_HOLIDAY + CommonConst.NAM_SUPPLY);
			if (!aryTxtStandard[i].equals("") && aryTxtStandard[i].length() < 2) {
				aryTxtStandard[i] = "0" + aryTxtStandard[i] ;
			}
			dto.setTCode(aryTxtStandard[i]);
			dto.setTName(aryTxtInfo[i]);
			dto.setTChange(aryTxtDays[i]);
			listCode.add(dto);
		}
	}

	/**
	 * フィールドの妥当性確認（有給休暇処理）
	 * @throws MospException
	 */
	public void validate() throws MospException {
		//妥当性確認開始時処理
		startValidation();
		//必須確認
		checkRequired(txtCFDays		, NAM_CF_DAYS	, PRM_TXT_CF_DAYS	);
		checkRequired(pltCFKbn		, NAM_CF_KBN	, PRM_PLT_CF_KBN	);
		//文字列長確認
		checkLength(txtCFDays	, LEN_CF_DAYS	, NAM_CF_DAYS	, PRM_TXT_CF_DAYS	);
		//文字列タイプ確認(半角数字)
		checkNumber(txtCFDays	, NAM_CF_DAYS	, PRM_TXT_CF_DAYS);
		for (int i = 0; i < aryTxtStandard.length; i++) {
			if (!aryTxtStandard[i].equals("")) {
				//文字列タイプ確認(半角数字)
				checkNumber(aryTxtStandard[i], 		NAM_STANDARD,					i, 	PRM_TXT_STANDARD);
				checkLength(aryTxtStandard[i], 		LEN_STANDARD,	NAM_STANDARD,	i, 	PRM_TXT_STANDARD);
			} else {
				if (!aryTxtDays[i].equals("")) {
					//必須確認
					checkRequired(aryTxtStandard[i],NAM_STANDARD, 					i, 	PRM_TXT_STANDARD);
					checkRequired(aryTxtInfo[i], 	NAM_INFO, 						i, 	PRM_TXT_INFO);
					//文字列タイプ確認(半角数字)
					checkNumber(aryTxtStandard[i], 	NAM_STANDARD, 					i, 	PRM_TXT_STANDARD);
					checkNumber(aryTxtDays[i], 		NAM_DAYS,  						i,	PRM_TXT_DAYS);
					//文字列長確認
					checkLength(aryTxtStandard[i], 	LEN_STANDARD,	NAM_STANDARD,	i,  PRM_TXT_STANDARD);
					checkLength(aryTxtDays[i], 		LEN_DAYS, 		NAM_DAYS, 	 	i,	PRM_TXT_DAYS);
					checkLength(aryTxtInfo[i], 		LEN_INFO, 		NAM_INFO, 	 	i,	PRM_TXT_INFO);
				}
				if (!aryTxtInfo[i].equals("")) {
					//必須確認
					checkRequired(aryTxtStandard[i],NAM_STANDARD, 					i, 	PRM_TXT_STANDARD);
					checkRequired(aryTxtDays[i], 	NAM_DAYS, 						i,	PRM_TXT_DAYS);
					//文字列タイプ確認(半角数字)
					checkNumber(aryTxtStandard[i], 	NAM_STANDARD,  					i,	PRM_TXT_STANDARD);
					checkNumber(aryTxtDays[i], 		NAM_DAYS, 						i, 	PRM_TXT_DAYS);
					//文字列長確認
					checkLength(aryTxtStandard[i], 	LEN_STANDARD,  	NAM_STANDARD, 	i,	PRM_TXT_STANDARD);
					checkLength(aryTxtDays[i], 		LEN_DAYS,  		NAM_DAYS, 		i,	PRM_TXT_DAYS);
					checkLength(aryTxtInfo[i], 		LEN_INFO,  		NAM_INFO, 		i,	PRM_TXT_INFO);
				}
			}
		}		// 妥当性確認終了時処理
		endValidation();
	}

	/**
	 * JavaScript設定
	 * @param cls 情報取得クラス
	 * @throws IllegalAccessException
	 */
	@Override
	public String  getDirectJs(Class cls) throws IllegalAccessException{
		StringBuffer sb = new StringBuffer();
		sb.append(super.getDirectJs(cls));
		sb.append("var MODE = ");
		sb.append(mode);
		sb.append(";");
		return sb.toString();		
	}

	//アクセサメソッド
	public String[] getEscAryTxtStandard()	{ return aryTxtStandard.clone()	; }
	public String[] getEscAryTxtDays()		{ return aryTxtDays.clone()		; }
	public String[] getEscAryTxtInfo()		{ return aryTxtInfo.clone()		; }

	public String getPltCFMonth()	{ return pltCFMonth	; }
	public String getTxtCFDays() 	{ return txtCFDays	; }
	public String getPltCFKbn()		{ return pltCFKbn	; }

	public String getEscPltCFMonth() 	{ return escapeHTML(pltCFMonth)	; }
	public String getEscTxtCFDays()		{ return escapeHTML(txtCFDays)	; }
	public String getEscPltCFKbn()		{ return escapeHTML(pltCFKbn)	; }

	public void setPltCFMonth		(String pltCFMonth	){ this.pltCFMonth 	= pltCFMonth	; }
	public void setTxtCFDays		(String txtCFDays	){ this.txtCFDays 	= txtCFDays		; }
	public void setPltCFKbn		(String pltCFKbn	){ this.pltCFKbn 	= pltCFKbn		; }

	public void setMode(int mode) { this.mode = mode; }
	public int getMode() { return mode; }

}
