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

/**
 * @author yoshida
 *
 */
public class AttendanceRouteListVo extends MosPVo {
	
	private static final long	serialVersionUID	= 7562923266126590833L;
	
	// 定数
	/**
	 * 
	 */
	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_ROUTE_CODE	= "txtRouteCode";
	/**
	 * 
	 */
	public static final String	PRM_PLT_OFFICE		= "pltOffice";
	/**
	 * 
	 */
	public static final String	PRM_PLT_SECTION		= "pltSection";
	
	// フィールド
	/**
	 * 
	 */
	public String[][]			aryAttendanceRoute;
	
	private String				txtKCode;
	private String				txtKName;
	private String				txtRouteCode;
	private String				pltOffice;
	private String				pltSection;
	
	// フィールド名及び制限
	/**
	 * 
	 */
	public String				NAM_K_CODE;
	/**
	 * 
	 */
	public String				NAM_K_NAME;
	/**
	 * 
	 */
	public String				NAM_ROUTE_CODE;
	/**
	 * 
	 */
	public String				NAM_OFFICE;
	/**
	 * 
	 */
	public String				NAM_SECTION;
	/**
	 * 
	 */
	public String				NAM_CODE;
	/**
	 * 
	 */
	public String				NAM_LAYER1;
	/**
	 * 
	 */
	public String				NAM_LAST_LAYER;
	/**
	 * 
	 */
	public int					LEN_CODE;
	/**
	 * 
	 */
	public int					LEN_NAME;
	
	// ソートキー
	/**
	 * 
	 */
	public final String			KEY_SECTION			= "keySectionCode";
	/**
	 * 
	 */
	public final String			KEY_K_CODE			= "keyKCode";
	/**
	 * 
	 */
	public final String			KEY_OFFICE			= "keyOffice";
	
	// モード(0：検索なし、1：検索あり)
	private int					searchmode;
	
	// プルダウン
	/**
	 * 
	 */
	public String[][]			aryPltOffice;
	/**
	 * 
	 */
	public String[][]			aryPltSection;
	/**
	 * 
	 */
	public String[][]			aryPltUser;
	/**
	 * 
	 */
	public String[][]			aryPltUnit;
	

	/**
	 * コンストラクタ
	 */
	public AttendanceRouteListVo() {
		super();
		setViewPath(getClassName());
		txtKCode = "";
		txtKName = "";
		txtRouteCode = "";
		pltOffice = "";
		pltSection = "";
		aryAttendanceRoute = new String[0][0];
		setFormerKey(KEY_SECTION);
	}
	
	@Override
	protected void setSubTitle() {
		subTitle = CommonConst.TTL_APPROVAL_ATTENDANCE;
		aryMenu = new String[][]{ { CMD_MENU_SYSTEM2, CommonConst.NAM_TO_MENU }, MosPMenuConst.getMenuApproval(), };
	}
	
	@Override
	protected void setFieldsName() {
		NAM_K_CODE = CommonConst.NAM_K_CODE;
		NAM_K_NAME = CommonConst.NAM_K_NAME;
		NAM_ROUTE_CODE = CommonConst.NAM_APPROVAL_ROUTE + CommonConst.NAM_COMMON_CODE;
		NAM_OFFICE = CommonConst.NAM_OFFICE;
		NAM_SECTION = CommonConst.NAM_STATION;
		NAM_CODE = CommonConst.NAM_COMMON_CODE;
		NAM_LAYER1 = CommonConst.NAM_1ST_APPROVED;
		NAM_LAST_LAYER = CommonConst.NAM_2ND_APPROVED;
		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);
		txtRouteCode = request.getParameter(PRM_TXT_ROUTE_CODE);
		pltOffice = request.getParameter(PRM_PLT_OFFICE);
		pltSection = request.getParameter(PRM_PLT_SECTION);
	}
	
	@Override
	public void setFields(List<?> listAttendanceRoute) {
		// リストの設定
		list = listAttendanceRoute;
		// データ総数の取得
		count = listAttendanceRoute.size();
		// 配列の初期化
		aryAttendanceRoute = new String[count][6];
		// データの設定
		int i = 0;
		Iterator<?> it = listAttendanceRoute.iterator();
		while (it.hasNext()) {
			AttendanceRouteDto dto = (AttendanceRouteDto)it.next();
			aryAttendanceRoute[i][0] = String.valueOf(dto.getRouteId());
			aryAttendanceRoute[i][1] = escapeHTML(getCodeName(dto.getSCode(), aryPltSection));
			aryAttendanceRoute[i][2] = escapeHTML(getCodeName(dto.getKCode(), aryPltUser));
			aryAttendanceRoute[i][3] = escapeHTML(getCodeName(dto.getLayer1(), aryPltUnit));
			aryAttendanceRoute[i][4] = escapeHTML(getCodeName(dto.getLastLayer(), aryPltUnit));
			aryAttendanceRoute[i][5] = escapeHTML(getCodeName(dto.getJCode(), aryPltOffice));
			i++;
		}
	}
	
	// アクセサメソッド
	public String[][] getEscAryAttendanceRoute() {
		return aryAttendanceRoute.clone();
	}
	
	public String getTxtKCode() {
		return txtKCode;
	}
	
	public String getTxtKName() {
		return txtKName;
	}
	
	public String getTxtRouteCode() {
		return txtRouteCode;
	}
	
	public String getPltOffice() {
		return pltOffice;
	}
	
	public String getPltSection() {
		return pltSection;
	}
	
	public String getEscTxtKCode() {
		return escapeHTML(txtKCode);
	}
	
	public String getEscTxtKName() {
		return escapeHTML(txtKName);
	}
	
	public String getEscTxtRouteCode() {
		return escapeHTML(txtRouteCode);
	}
	
	public void setSearchmode(int searchmode) {
		this.searchmode = searchmode;
	}
	
	/**
	 * @return
	 */
	public int getSearchmode() {
		return searchmode;
	}
	
}
