/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package com.yuntong.action;

import java.util.Calendar;
import java.util.Date;

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

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.yuntong.action.actionform.Y_insertUserInfoForm;
import com.yuntong.encrypt.MD5;
import com.yuntong.hibernate.database.dao.TCarTypeDAO;
import com.yuntong.service.Y_IUserManagerService;

/** 
 * MyEclipse Struts
 * Creation date: 04-11-2007
 * 填加或修改用户信息
 * XDoclet definition:
 * @struts.action path="/y_addUserInfo" name="y_insertUserInfoForm" input="/Y_CZY_1.jsp" scope="request" validate="true"
 */
public class Y_addUserInfoAction extends Action {
	private static final Log log = LogFactory.getLog(TCarTypeDAO.class);
	private Y_IUserManagerService userManagerService;
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		Y_insertUserInfoForm y_insertUserInfoForm = (Y_insertUserInfoForm) form;
		//得到提交信息
		//用户编号
		String strUserID=y_insertUserInfoForm.getUserId();
		int userID=0;
		int userLoginNum=0;
		Date loginDate=new Date();
		Date userDate=new Date();
		if(strUserID!=""){
			userID=Integer.parseInt(strUserID);
			userLoginNum=y_insertUserInfoForm.getUserLoginNum();
			//分解时间条件		
			String temp[]=y_insertUserInfoForm.getUserLoginDate().split("-");		
			int y=Integer.parseInt(temp[0]);
			int m=Integer.parseInt(temp[1]);
			
			int d=Integer.parseInt(temp[2].substring(0, 2));
			//格式化为Date类型
			Calendar calendar=Calendar.getInstance();
			calendar.clear();
			calendar.set(y, m-1, d);
			//得到时间
			loginDate=calendar.getTime();
			
			//分解时间条件		
			String temp2[]=y_insertUserInfoForm.getUserDate().split("-");		
			int y2=Integer.parseInt(temp2[0]);
			int m2=Integer.parseInt(temp2[1]);
			
			int d2=Integer.parseInt(temp2[2].substring(0, 2));
			//格式化为Date类型			
			calendar.clear();
			calendar.set(y2, m2-1, d2);
			//得到时间
			userDate=calendar.getTime();
			log.info(temp[0]);
		}
		//用户名
		String userName=y_insertUserInfoForm.getUserName();
		log.info("用户名："+y_insertUserInfoForm.getUserName());
		//所属公司(编号)
		int filiale=y_insertUserInfoForm.getFiliale();
		log.info("公司编号"+filiale);
		//所属部门(编号)
		int department=y_insertUserInfoForm.getDepartment();
		//用户权限(编号)		
		int userRole=y_insertUserInfoForm.getUserRole();
		log.info("权限编号"+userRole);
		//真实姓名
		String userTrueName=y_insertUserInfoForm.getUserTrueName();
		//联系电话
		String userPhone=y_insertUserInfoForm.getUserPhone();
		//身份证号码
		String userCardId=y_insertUserInfoForm.getUserCardId();
		//登陆密码
		String userPwd1=y_insertUserInfoForm.getUserPwd1();
		//密码确认
		String userPwd2=MD5.MD5Encrypt(y_insertUserInfoForm.getUserPwd2());
		//填加或修改用户信息
		userManagerService.addUserInfo(userID, userName, filiale, department, userRole, userTrueName, userPhone, userCardId, userPwd2,userLoginNum,loginDate,userDate);
		HttpSession session=request.getSession();
		if(strUserID==""){
			session.setAttribute("Y_tishi", "填加成功");
		}else{
			session.setAttribute("Y_tishi", "修改成功");
		}
		
		return mapping.findForward("go");
	}
	public Y_IUserManagerService getUserManagerService() {
		return userManagerService;
	}
	public void setUserManagerService(Y_IUserManagerService userManagerService) {
		this.userManagerService = userManagerService;
	}
}