/*
 * 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.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.MospConst;
import jp.mosp.common.utils.TimeUtil;
import jp.mosp.kintai.common.dto.CmWorkTypeDto;

/**
 * @author yoshida
 *
 */
public class WorkTypeMasterListVo extends MosPVo {
	
	private static final long	serialVersionUID	= -3051204572322360172L;
	
	// 定数
	/**
	 * 
	 */
	public static final int		SEARCH_OFF			= 0;
	/**
	 * 
	 */
	public static final int		SEARCH_ON			= 1;
	
	// パラメータ名
	/**
	 * 
	 */
	public static final String	PRM_TXT_SHIFT_CODE	= "txtShiftCode";
	/**
	 * 
	 */
	public static final String	PRM_TXT_SHIFT_NAME	= "txtShiftName";
	/**
	 * 
	 */
	public static final String	PRM_PLT_DELETE		= "pltDelete";
	
	// フィールド
	private String[]			aryShiftCode;
	private String[]			aryShiftName;
	private String[]			aryWorkTable;
	private String[]			aryDelete;
	private String				txtShiftCode;
	private String				txtShiftName;
	private String				pltDelete;
	
	// フィールド名及び制限
	/**
	 * 
	 */
	public String				NAM_SHIFT_CODE;
	/**
	 * 
	 */
	public String				NAM_SHIFT_NAME;
	/**
	 * 
	 */
	public String				NAM_WORKING_TABLE;
	/**
	 * 
	 */
	public String				NAM_DELETE;
	/**
	 * 
	 */
	public int					LEN_SHIFT_CODE;
	/**
	 * 
	 */
	public int					LEN_SHIFT_NAME;
	
	// ソートキー	
	/**
	 * 
	 */
	public final String			KEY_SHIFT_CODE		= "keyShiftCode";
	/**
	 * 
	 */
	public final String			KEY_SHIFT_NAME		= "keyShiftName";
	/**
	 * 
	 */
	public final String			KEY_DELETE			= "keyDelete";
	
	// モード(0：検索なし、1：検索あり)
	private int					searchmode;
	

	/**
	 * コンストラクタ
	 */
	public WorkTypeMasterListVo() {
		super();
		setViewPath(getClassName());
		txtShiftCode = "";
		txtShiftName = "";
		aryShiftCode = new String[0];
		aryShiftName = new String[0];
		aryWorkTable = new String[0];
		aryDelete = new String[0];
		setFormerKey(KEY_SHIFT_CODE);
	}
	
	@Override
	protected void setSubTitle() {
		subTitle = CommonConst.TTL_WORK_TYPE_MASTER;
		aryMenu = new String[][]{ { CMD_MENU_SYSTEM2, CommonConst.NAM_TO_MENU } };
	}
	
	@Override
	protected void setFieldsName() {
		NAM_SHIFT_CODE = CommonConst.NAM_COMMON_CODE;
		NAM_SHIFT_NAME = CommonConst.NAM_WORKING_TYPE;
		NAM_WORKING_TABLE = CommonConst.NAM_WORKING_TABLE_INFO;
		NAM_DELETE = CommonConst.NAM_DELETE_FLAG;
		LEN_SHIFT_CODE = 10;
		LEN_SHIFT_NAME = 50;
	}
	
	@Override
	public void setParams(HttpServletRequest request) {
		txtShiftCode = request.getParameter(PRM_TXT_SHIFT_CODE);
		txtShiftName = request.getParameter(PRM_TXT_SHIFT_NAME);
		pltDelete = request.getParameter(PRM_PLT_DELETE);
	}
	
	@Override
	public void setFields(List<?> listWorkingTable) {
		// リストの設定
		list = listWorkingTable;
		// データ総数の取得
		count = listWorkingTable.size();
		// 配列の初期化
		aryShiftCode = new String[count];
		aryShiftName = new String[count];
		aryWorkTable = new String[count];
		aryDelete = new String[count];
		// データの設定
		int i = 0;
		Iterator<?> it = listWorkingTable.iterator();
		while (it.hasNext()) {
			CmWorkTypeDto dto = (CmWorkTypeDto)it.next();
			aryShiftCode[i] = escapeHTML(dto.getShiftCode());
			aryShiftName[i] = escapeHTML(dto.getShiftName());
			aryWorkTable[i] = escapeHTML(convWorkTypeTimes(dto.getStartTime(), dto.getQuitTime()));
			if (dto.getDeleteFlag() == MospConst.DELETE_FLAG_OFF) {
				aryDelete[i] = escapeHTML(MospConst.DELETE_FLAG_OFF_NAME);
			} else if (dto.getDeleteFlag() == MospConst.DELETE_FLAG_ON) {
				aryDelete[i] = escapeHTML(MospConst.DELETE_FLAG_ON_NAME);
			}
			i++;
		}
	}
	
	/**
	 * 勤務形態時刻変換メソッド
	 * @param start 開始時刻
	 * @param quit 終了時刻
	 * @return	string	結合文字列
	 */
	private String convWorkTypeTimes(int start, int quit) {
		StringBuffer sb = new StringBuffer();
		// 出勤時刻
		sb.append(TimeUtil.convIntegerTimeToStringTime(start));
		sb.append(" ");
		sb.append(CommonConst.STR_SLASH_SEPARATOR);
		sb.append(" ");
		// 退勤時刻
		sb.append(TimeUtil.getJPStringTime(quit));
		return sb.toString();
	}
	
	// アクセサメソッド
	/**
	 * @return txtShiftCode
	 */
	public String getEscTxtShiftCode() {
		return escapeHTML(txtShiftCode);
	}
	
	/**
	 * @return txtShiftName
	 */
	public String getEscTxtShiftName() {
		return escapeHTML(txtShiftName);
	}
	
	/**
	 * @return aryShiftCode
	 */
	public String[] getAryShiftCode() {
		return aryShiftCode.clone();
	}
	
	/**
	 * @return aryShiftName
	 */
	public String[] getAryShiftName() {
		return aryShiftName.clone();
	}
	
	/**
	 * @return aryWorkTable
	 */
	public String[] getAryWorkTable() {
		return aryWorkTable.clone();
	}
	
	/**
	 * @return aryDelete
	 */
	public String[] getAryDelete() {
		return aryDelete.clone();
	}
	
	/**
	 * @return txtShiftCode
	 */
	public String getTxtShiftCode() {
		return txtShiftCode;
	}
	
	/**
	 * @return txtShiftName
	 */
	public String getTxtShiftName() {
		return txtShiftName;
	}
	
	/**
	 * @return pltDelete
	 */
	public String getPltDelete() {
		return pltDelete;
	}
	
	/**
	 * @return searchmode
	 */
	public int getSearchmode() {
		return searchmode;
	}
	
	/**
	 * @param txtShiftCode セットする txtShiftCode
	 */
	public void setTxtShiftCode(String txtShiftCode) {
		this.txtShiftCode = txtShiftCode;
	}
	
	/**
	 * @param txtShiftName セットする txtShiftName
	 */
	public void setTxtShiftName(String txtShiftName) {
		this.txtShiftName = txtShiftName;
	}
	
	/**
	 * @param pltDelete セットする pltDelete
	 */
	public void setPltDelete(String pltDelete) {
		this.pltDelete = pltDelete;
	}
	
	/**
	 * @param searchmode セットする searchmode
	 */
	public void setSearchmode(int searchmode) {
		this.searchmode = searchmode;
	}
	
	/**
	 * @param aryShiftCode セットする aryShiftCode
	 */
	public void setAryShiftCode(String[] aryShiftCode) {
		this.aryShiftCode = aryShiftCode.clone();
	}
	
	/**
	 * @param aryShiftName セットする aryShiftName
	 */
	public void setAryShiftName(String[] aryShiftName) {
		this.aryShiftName = aryShiftName.clone();
	}
	
	/**
	 * @param aryWorkTable セットする aryWorkTable
	 */
	public void setAryWorkTable(String[] aryWorkTable) {
		this.aryWorkTable = aryWorkTable.clone();
	}
	
	/**
	 * @param aryDelete セットする aryDelete
	 */
	public void setAryDelete(String[] aryDelete) {
		this.aryDelete = aryDelete.clone();
	}
	
}
