/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.lqc.epai.web.action;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.actions.DispatchAction;
import com.lqc.epai.web.actionform.T_UserFormForm;
import com.lqc.epai.Ibiz.T_goods_Ibiz;
import com.lqc.epai.Ibiz.T_user_Ibiz;
import com.lqc.epai.com.Paging;
import com.lqc.epai.entity.Goods;
import com.lqc.epai.entity.T_userEn;
import com.lqc.epai.impbiz.T_goods_impbiz;
import com.lqc.epai.impbiz.T_user_impbiz;
/**
* MyEclipse Struts
* Creation date: 09-18-2008
*
* XDoclet definition:
* @struts.action path="/t_User_DispatchAction" name="t_UserFormForm" scope="request" validate="true"
* @struts.action-forward name="userConfig" path="/userInfo.jsp"
*/
public class T_User_DispatchActionAction extends DispatchAction {
/*
* Generated Methods
*/
private HttpSession usersession = null;
// 实体类对象
private T_userEn userEn = null;
private List<Goods> T_goods_list = null;
// 业务层对象
private T_user_Ibiz userbiz = null;
private T_goods_Ibiz goodsbiz = null;
// 分页实体类
Paging paging_en = null;
/**
* 检查用户是否合法
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward CheckUser(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
T_UserFormForm t_UserFormForm = (T_UserFormForm) form;
try
{
T_userEn user_en = t_UserFormForm.getT_userEn();
userEn = userbiz.CheckUser(user_en.getUserName(), user_en.getUserPassword());
if(userEn!=null)
{
CreateSession(request, response);
return mapping.findForward("userConfig");
}
else
{
ActionMessages errors = new ActionMessages();
errors.add("error1",new ActionMessage("error.validate.error1"));
super.saveErrors(request, errors);
//response.sendRedirect("index.jsp");
return mapping.findForward("index");
}
}catch(Exception ex)
{
ex.printStackTrace();
System.out.println("action-检查用户出错了!");
return mapping.findForward("error");
}
}
/**
* 注册
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward Enrol(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
T_UserFormForm t_UserFormForm = (T_UserFormForm) form;
ActionMessages errors = new ActionMessages();
try
{
T_userEn user_en = t_UserFormForm.getT_userEn();
T_userEn userEn = userbiz.CheckUser(user_en.getUserName(), user_en.getUserPassword());
// 判断该用户是否存在
if(userEn==null)
{
// 存在注册用户
if(userbiz.Enrol(user_en))
{
errors.add("errorC",new ActionMessage("error.validate.enrolC"));
super.saveErrors(request, errors);
}
}else
{
// 提示该用户已存在
errors.add("errorY",new ActionMessage("error.validate.enrolY"));
super.saveErrors(request, errors);
// response.sendRedirect(request.getContextPath()+"/Enrol.jsp");
}
return mapping.findForward("enrol");
}catch(Exception ex)
{
ex.printStackTrace();
System.out.println("action-检查用户出错了!");
return mapping.findForward("error");
}
}
/***
* 是否同意
* @param mapping
* @param form
* @param request
* @param response
* @return
*/
public ActionForward confirm(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
{
try
{
if(request.getParameter("isnot").equals("1"))
{
ClearSession(request);
// 创建分页对象【第一个参数为:每页行数;第二个参数为:查询该表名;】
paging_en = new Paging("SELECT COUNT(tb_good) FROM Goods tb_good");
/**
* 查询所有商品信息
*/
T_goods_list = goodsbiz.getGoodsList(paging_en);
request.setAttribute("goods_list", T_goods_list);
/**
* 查看用户详细信息
*/
T_userEn user_en = (T_userEn)request.getSession().getAttribute("userinfo");
request.setAttribute("userEn", user_en);
// 设置分页实体类
request.setAttribute("pag_En", paging_en);
return mapping.findForward("index");
}
else
{
return mapping.findForward("index");
}
}catch(Exception ex)
{
ex.printStackTrace();
System.out.println("action: 是否同出错!");
return mapping.findForward("error");
}
}
/**
* 创建session
*/
public void CreateSession(HttpServletRequest request, HttpServletResponse response)
{
usersession = request.getSession();
if(usersession.getAttribute("userinfo")==null)
{
usersession.setAttribute("userinfo", userEn);
}
}
/**
* 清空session
* @param request
*/
public void ClearSession(HttpServletRequest request)
{
if(request.getSession().getAttribute("good_id")!=null)
{
request.getSession().setAttribute("good_id", null);
}
}
/**
* 注入方法
* @param userbiz
*/
public void setUserbiz(T_user_Ibiz userbiz) {
this.userbiz = userbiz;
}
public void setGoodsbiz(T_goods_Ibiz goodsbiz) {
this.goodsbiz = goodsbiz;
}
}