/*
 * MosP - Mind Open Source Project    http://www.mosp.jp/
 * Copyright (C) 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.kintai.report.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.utils.StringUtil;
import jp.mosp.kintai.report.dto.MExportDto;

public class ExportCardVo extends MosPVo {
	
	private static final long	serialVersionUID	= -1964891218805898322L;
	
	// 定数
	public static final int		SEARCH_OFF			= 0;
	public static final int		SEARCH_ON			= 1;
	
	// パラメーター名
	public static final String	PRM_PLT_YEAR		= "pltYear";
	public static final String	PRM_PLT_MONTH		= "pltMonth";
	public static final String	PRM_TXT_E_NAME		= "txtEName";
	public static final String	PRM_TXT_E_FILE		= "txtEFile";
	
	// フィールド
	private String				pltYear;
	private String				pltMonth;
	
	private String[]			aryEName;
	private String[]			aryEFile;
	/*						
	 *  	2009/02/20	m.yoshida	エラー対応
	 */
	private String[]			aryENameKey;
	private String				txtEName;
	private String				txtEFile;
	
	// プルダウンリスト
	public String[][]			aryPltYear;
	public String[][]			aryPltMonth;
	
	// フィールド名及び制限
	public String				NAM_E_NAME;
	public String				NAM_E_FILE;
	public String				NAM_KINTAI_INFO;
	public String				NAM_PLT_YEAR;
	public String				NAM_PLT_MONTH;
	public int					LEN_E_NAME;
	
	// ソートキー
	public final String			KEY_E_NAME			= "keyEName";
	
	// モード(0：検索なし、1：検索あり)
	private int					searchmode;
	

	/**
	 * コンストラクタ
	 */
	public ExportCardVo() {
		super();
		setViewPath(getClassName());
		pltYear = "";
		pltMonth = "";
		aryEName = new String[0];
		aryEFile = new String[0];
		setFormerKey(KEY_E_NAME);
		/*						
		 *  	2009/02/20	m.yoshida	エラー対応
		 */
		aryENameKey = new String[0];
	}
	
	@Override
	protected void setSubTitle() {
		subTitle = CommonConst.TTL_EXPORT_MASTER;
		aryMenu = new String[][]{ { CMD_MENU_PAYROLL, CommonConst.NAM_TO_MENU } };
	}
	
	@Override
	protected void setFieldsName() {
		NAM_E_NAME = CommonConst.NAM_COMMON_MEISYO;
		NAM_E_FILE = CommonConst.NAM_TABLE;
		NAM_KINTAI_INFO = CommonConst.NAM_TARGET_MONTH;
		NAM_PLT_YEAR = CommonConst.NAM_YEAR;
		NAM_PLT_MONTH = CommonConst.NAM_MONTH;
		LEN_E_NAME = 10;
	}
	
	@Override
	public void setParams(HttpServletRequest request) {
		pltYear = request.getParameter(PRM_PLT_YEAR);
		pltMonth = request.getParameter(PRM_PLT_MONTH);
	}
	
	/**
	 * フィールド設定
	 * @param exportList エクスポートマスタリスト
	 */
	public void setFields(List<?> exportList) {
		//リストの設定
		list = exportList;
		//データ総数の取得
		count = exportList.size();
		//配列の初期化
		aryEName = new String[count];
		aryEFile = new String[count];
		/*						
		 *  	2009/02/20	m.yoshida	エラー対応
		 */
		aryENameKey = new String[count];
		//データの設定
		int i = 0;
		Iterator<?> it = exportList.iterator();
		while (it.hasNext()) {
			MExportDto dto = (MExportDto)it.next();
			String ename = "";
			String[] divName = StringUtil.divideByComma(dto.getEName());
			if (divName.length == 1) {
				ename = dto.getEName();
			} else {
				ename = divName[1];
			}
			aryEName[i] = escapeHTML(ename);
			aryEFile[i] = escapeHTML(dto.getEFile());
			aryENameKey[i] = escapeHTML(dto.getEName());
			i++;
		}
	}
	
	@Override
	public String getDirectJs(Class<?> cls, Object obj) throws IllegalAccessException {
		StringBuffer sb = new StringBuffer();
		sb.append(super.getDirectJs(cls, obj));
		return sb.toString();
	}
	
	// アクセサメッソド
	public String[] getEscAryEName() {
		return aryEName.clone();
	}
	
	public String[] getEscAryEFile() {
		return aryEFile.clone();
	}
	
	/*						
	 *  	2009/02/20	m.yoshida	エラー対応
	 */
	public String[] getEscAryENameKey() {
		return aryENameKey.clone();
	}
	
	public String getPltYear() {
		return pltYear;
	}
	
	public String getPltMonth() {
		return pltMonth;
	}
	
	public String getEscTxtEName() {
		return escapeHTML(txtEName);
	}
	
	public String getTxtEName() {
		return txtEName;
	}
	
	public String getTxtEFile() {
		return txtEFile;
	}
	
	public void setPltYear(String pltYear) {
		this.pltYear = pltYear;
	}
	
	public void setPltMonth(String pltMonth) {
		this.pltMonth = pltMonth;
	}
	
	public String getEscPltYear() {
		return escapeHTML(pltYear);
	}
	
	public String getEscPltMonth() {
		return escapeHTML(pltMonth);
	}
	
	public void setTxtEName(String ename) {
		txtEName = ename;
	}
	
	public void setTxtEFile(String efile) {
		txtEFile = efile;
	}
	
	public void setSearchmode(int searchmode) {
		this.searchmode = searchmode;
	}
	
	public int getSearchmode() {
		return searchmode;
	}
	
}
