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

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

import javax.servlet.http.HttpServletRequest;

import jp.mosp.common.CommonConst;
import jp.mosp.common.MosPMenuConst;
import jp.mosp.common.MosPVo;
import jp.mosp.common.utils.DateUtil;
import jp.mosp.workflow.dto.AmUnitDto;

/**
 * @author yoshida
 *
 */
public class ApprovalUnitListVo extends MosPVo {
	
	private static final long	serialVersionUID	= 4781254088593017966L;
	
	// 定数
	public static final int		SEARCH_OFF			= 0;
	public static final int		SEARCH_ON			= 1;
	
	// パラメータ名
	public static final String	PRM_TXT_K_CODE		= "txtKCode";
	public static final String	PRM_TXT_K_NAME		= "txtKName";
	public static final String	PRM_TXT_UNIT_CODE	= "txtUnitCode";
	
	// フィールド
	public String[][]			aryUnit;
	public String[][]			aryPltUser;
	
	private String				txtKCode;
	private String				txtKName;
	private String				txtUnitCode;
	
	// フィールド名及び制限
	public String				NAM_K_CODE;
	public String				NAM_K_NAME;
	public String				NAM_UNIT_CODE;
	public String				NAM_MAIN;
	public String				NAM_AGENT;
	public String				NAM_START_DATE;
	public int					LEN_CODE;
	public int					LEN_NAME;
	
	// ソートキー
	public final String			KEY_UNIT_CODE		= "keyUnitCode";
	public final String			KEY_MAIN			= "keyMain";
	public final String			KEY_AGENT			= "keyAgent";
	public final String			KEY_START_DATE		= "keyStartDate";
	
	// モード(0：検索なし、1：検索あり)
	private int					searchmode;
	

	/**
	 * コンストラクタ
	 */
	public ApprovalUnitListVo() {
		super();
		setViewPath(getClassName());
		txtKCode = "";
		txtKName = "";
		txtUnitCode = "";
		aryUnit = new String[0][0];
		setFormerKey(KEY_UNIT_CODE);
	}
	
	@Override
	protected void setSubTitle() {
		subTitle = CommonConst.TTL_APPROVAL_UNIT;
		createAryMenu(CMD_MENU_SYSTEM2, MosPMenuConst.getMenuApproval());
	}
	
	@Override
	protected void setFieldsName() {
		NAM_K_CODE = CommonConst.NAM_K_CODE;
		NAM_K_NAME = CommonConst.NAM_K_NAME;
		NAM_UNIT_CODE = CommonConst.NAM_COMMON_CODE;
		NAM_MAIN = CommonConst.NAM_APPROVED + CommonConst.NAM_PERSON;
		NAM_AGENT = CommonConst.NAM_AGENT;
		NAM_START_DATE = CommonConst.NAM_START_DATE;
		LEN_CODE = CommonConst.LEN_K_CODE;
		LEN_NAME = CommonConst.LEN_K_NAME;
	}
	
	@Override
	public void setParams(HttpServletRequest request) {
		txtKCode = request.getParameter(PRM_TXT_K_CODE);
		txtKName = request.getParameter(PRM_TXT_K_NAME);
		txtUnitCode = request.getParameter(PRM_TXT_UNIT_CODE);
	}
	
	@Override
	public void setFields(List<?> listUnit) {
		// リストの設定
		list = listUnit;
		// データ総数の取得
		count = listUnit.size();
		// 配列の初期化
		aryUnit = new String[count][5];
		// データの設定
		int i = 0;
		Iterator<?> it = listUnit.iterator();
		while (it.hasNext()) {
			AmUnitDto dto = (AmUnitDto)it.next();
			aryUnit[i][0] = escapeHTML(dto.getUnitCode());
			aryUnit[i][1] = escapeHTML(getCodeName(dto.getMain(), aryPltUser));
			aryUnit[i][2] = escapeHTML(getCodeName(dto.getAgent(), aryPltUser));
			aryUnit[i][3] = escapeHTML(DateUtil.convDateToFormatDateJP(dto.getStartDate()));
			aryUnit[i][4] = escapeHTML(DateUtil.convDateFormattedByHyphen(dto.getStartDate()));
			i++;
		}
	}
	
	// アクセサメソッド
	public String[][] getEscAryUnit() {
		return aryUnit.clone();
	}
	
	public String getTxtKCode() {
		return txtKCode;
	}
	
	public String getTxtKName() {
		return txtKName;
	}
	
	public String getTxtUnitCode() {
		return txtUnitCode;
	}
	
	public String getEscTxtKCode() {
		return escapeHTML(txtKCode);
	}
	
	public String getEscTxtKName() {
		return escapeHTML(txtKName);
	}
	
	public String getEscTxtUnitCode() {
		return escapeHTML(txtUnitCode);
	}
	
	public void setSearchmode(int searchmode) {
		this.searchmode = searchmode;
	}
	
	/**
	 * @return
	 */
	public int getSearchmode() {
		return searchmode;
	}
	
}
