/*
 * 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.payroll.common.vo;

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

import javax.servlet.http.HttpServletRequest;

import jp.mosp.payroll.base.PayrollConst;
import jp.mosp.payroll.base.PayrollVo;
import jp.mosp.payroll.dto.MImportDto;

public class ImportMasterListVo extends PayrollVo {
	
	private static final long	serialVersionUID	= -3093345238424415014L;
	
	// 定数
	public static final int		SEARCH_OFF			= 0;
	public static final int		SEARCH_ON			= 1;
	
	// パラメータ名
	public static final String	PRM_TXT_I_CODE		= "txtICode";
	public static final String	PRM_TXT_I_NAME		= "txtIName";
	public static final String	PRM_PLT_I_TABLE		= "pltITable";
	
	// フィールド
	private String[]			aryImportCmd;
	private String[]			aryICode;
	private String[]			aryIName;
	private String[]			aryITable;
	private String				txtICode;
	private String				txtIName;
	private String				pltITable;
	
	// プルダウンリスト
	public String[][]			aryPltITable;
	
	// ソートキー
	public final String			KEY_I_CODE			= "keyICode";
	public final String			KEY_I_NAME			= "keyIName";
	public final String			KEY_I_TABLE			= "keyITable";
	
	// モード(0：検索なし、1：検索あり)
	private int					searchmode;
	

	/**
	 * コンストラクタ
	 */
	public ImportMasterListVo() {
		super();
		txtICode = "";
		txtIName = "";
		pltITable = "";
		aryImportCmd = new String[0];
		aryICode = new String[0];
		aryIName = new String[0];
		aryITable = new String[0];
		setFormerKey(KEY_I_CODE);
	}
	
	/**
	 * サブタイトルを設定する。
	 */
	@Override
	protected void setSubTitle() {
		super.setSubTitle();
		subTitle = getName("P_PAYMENT") + getName("P_IMPORT");
		addAryMenu("P1001", getName("P_PAYMENT") + getName("P_CALCULATE") + getName("C_MENU") + getName("C_TO"));
	}
	
	/**
	 * パラメータ設定
	 * @param request リクエスト
	 */
	public void setParams(HttpServletRequest request) {
		txtICode = request.getParameter(PRM_TXT_I_CODE);
		txtIName = request.getParameter(PRM_TXT_I_NAME);
		pltITable = request.getParameter(PRM_PLT_I_TABLE);
	}
	
	/**
	 * フィールド設定
	 * @param listImport インポートリスト
	 */
	public void setFields(List listImport) {
		// リストの設定
		list = listImport;
		// データ総数の取得
		count = listImport.size();
		// 配列の初期化
		aryImportCmd = new String[count];
		aryICode = new String[count];
		aryIName = new String[count];
		aryITable = new String[count];
		// データの設定
		int i = 0;
		Iterator it = listImport.iterator();
		while (it.hasNext()) {
			MImportDto dto = (MImportDto)it.next();
			if (dto.getITable().equals(PayrollConst.CODE_IMPORT_TABLE_PI_PAYMENT)) {
				aryImportCmd[i] = "P9040"; /* 給与データインポート */
			} else if (dto.getITable().equals(PayrollConst.CODE_IMPORT_TABLE_M_SYUKKINBO)) {
				aryImportCmd[i] = "P9050"; /* 勤怠データインポート */
			} else if (dto.getITable().equals(PayrollConst.CODE_IMPORT_TABLCT_TIMECARD)) {
				aryImportCmd[i] = "P9060"; /* タイムカードデータインポート */
			}
			aryICode[i] = escapeHTML(dto.getICode());
			aryIName[i] = escapeHTML(dto.getIName());
			aryITable[i] = escapeHTML(getCodeName(dto.getITable(), aryPltITable));
			i++;
		}
	}
	
	/**
	 * JavaScript設定
	 * @param cls 情報取得クラス
	 * @throws IllegalAccessException
	 */
	@Override
	public String getDirectJs(Class cls) throws IllegalAccessException {
		StringBuffer sb = new StringBuffer();
		sb.append(super.getDirectJs(cls));
		return sb.toString();
	}
	
	// アクセサメソッド
	public String[] getAryImportCmd() {
		return aryImportCmd.clone();
	}
	
	public String[] getEscAryICode() {
		return aryICode.clone();
	}
	
	public String[] getEscAryIName() {
		return aryIName.clone();
	}
	
	public String[] getEscAryITable() {
		return aryITable.clone();
	}
	
	public String getTxtICode() {
		return txtICode;
	}
	
	public String getTxtIName() {
		return txtIName;
	}
	
	public String getPltITable() {
		return pltITable;
	}
	
	public String getEscTxtICode() {
		return escapeHTML(txtICode);
	}
	
	public String getEscTxtIName() {
		return escapeHTML(txtIName);
	}
	
	public String getEscPltITable() {
		return escapeHTML(pltITable);
	}
	
	public void setSearchmode(int searchmode) {
		this.searchmode = searchmode;
	}
	
	public int getSearchmode() {
		return searchmode;
	}
	
}
