package com.kingdee.eas.hr.emp.web.handler;

import java.sql.SQLException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.eas.framework.CoreBaseInfo;
import com.kingdee.eas.hr.emp.PersonContactMethodInfo;
import com.kingdee.eas.util.app.DbUtil;
import com.kingdee.jdbc.rowset.IRowSet;
import com.kingdee.shr.base.syssetting.context.SHRContext;
import com.kingdee.shr.base.syssetting.exception.SHRWebException;
import com.kingdee.shr.base.syssetting.exception.ShrWebBizException;

/**
 * 员工联系方式信息修改
 * @author issuser
 *
 */
public class PersonContactMethodEditHandlerEx extends
		PersonContactMethodEditHandler {

	@Override
	protected void beforeSave(HttpServletRequest request,
			HttpServletResponse response, CoreBaseInfo model)
			throws SHRWebException {
		Context ctx = SHRContext.getInstance().getContext();
    	PersonContactMethodInfo info = (PersonContactMethodInfo) model;
    	StringBuffer checkSql = new StringBuffer();
    	checkSql.append(" select fid from T_HR_PersonContactMethod where Upper(FEmail) = Upper('" + info.getEmail() + "')");
    	if(info.getId() != null){
    		checkSql.append(" and fid != '" + info.getId().toString() + "'");
    	}
    	
		try {
			IRowSet rs = DbUtil.executeQuery(ctx, checkSql.toString());
			if(rs.next()){
	    		throw new ShrWebBizException("The user mailbox already exists. Procedure !"); 
	    	}
		} catch (BOSException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		super.beforeSave(request, response, model);
	}
}
