⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 employeeoperateaction.java

📁 是Eclipse web开发从入门到精通的源码
💻 JAVA
字号:
package com.REP.action;

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

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.action.DynaActionForm;
import org.apache.struts.actions.DispatchAction;

import com.REP.IService.IEmployeeService;
import com.REP.excptions.AccountNotExistException;
import com.REP.excptions.OverDrawException;

public class EmployeeOperateAction extends DispatchAction {
    
   IEmployeeService employeeservice;
   //处理员工就餐刷卡请求
    public ActionForward employeeRepast(ActionMapping mapping,
            ActionForm form, HttpServletRequest request,
            HttpServletResponse response)  {
       /*
        *如果需要对员工刷卡的位置有具体的要求,比如只允许员工在餐厅的某台计算机上刷卡就餐,
        *就可以利用 request.getRemoteHost()方法获得用户使用计算机的ip地址,如果是正
        *确的ip地址则允许刷卡,否则禁止刷卡。读者可以自己添加这部分内容。
        */
        
        //获得员工页面输入内容,主要是就餐账户名称、消费金额
        DynaActionForm dform = (DynaActionForm)form;
        String repastCard =dform.getString("repastCard");
        String repastFee =dform.getString("repastFee");
        
        try {
            //对输入内容进行处理,完成刷卡动作
            employeeservice.repast(repastCard,repastFee);
            //获得账户余额
            String banlances =String.valueOf(employeeservice.searchBanlances(repastCard));
            //获得透支次数
            String overDrawNub = String.valueOf(employeeservice.searchOverDrawNub(repastCard));
           
            //将账户余额和透支次数存放在Request范围内,方便其他页面调用
            request.setAttribute("banlances",banlances);
            request.setAttribute("overDrawNub",overDrawNub);
            return mapping.findForward("RepastSuccess");
            
        } catch (AccountNotExistException e) {
            //建立ActionMessages对象
            ActionMessages errors = new ActionMessages();
            //将异常或错误信息存入ActionMessages对象errors中
            errors.add(ActionMessages.GLOBAL_MESSAGE,new ActionMessage("error.repast.accountNotExist"));
            //把ActionMessages对象存入到request对象中
            saveErrors(request,errors);
            //跳转到错误处理页面 
            return mapping.getInputForward();
        } catch (OverDrawException e) {
          //建立ActionMessages对象
            ActionMessages errors = new ActionMessages();
            //将异常或错误信息存入ActionMessages对象errors中
            errors.add(ActionMessages.GLOBAL_MESSAGE,new ActionMessage("error.repast.OverDraw"));
            //把ActionMessages对象存入到request对象中
            saveErrors(request,errors);
            //跳转到错误处理页面 
            return mapping.getInputForward();
        }
    }
    //处理员工余额查询请求
    public ActionForward banlancesSearch(ActionMapping mapping,
            ActionForm form, HttpServletRequest request,
            HttpServletResponse response)  {
        
        //从页面获得员工输入的就餐卡号
        DynaActionForm dform = (DynaActionForm)form;
        String repastCard =dform.getString("repastCard");
       
        String banlances;
        try {
            //查询余额 
            banlances = String.valueOf(employeeservice.searchBanlances(repastCard));
            String overDrawNub = String.valueOf(employeeservice.searchOverDrawNub(repastCard));
            request.setAttribute("banlances",banlances);
            request.setAttribute("overDrawNub",overDrawNub);
        } catch (AccountNotExistException e) {
            //建立ActionMessages对象
            ActionMessages errors = new ActionMessages();
            //将异常或错误信息存入ActionMessages对象errors中
            errors.add(ActionMessages.GLOBAL_MESSAGE,new ActionMessage("error.repast.accountNotExist"));
            //把ActionMessages对象存入到request对象中
            saveErrors(request,errors);
            //跳转到错误处理页面 
            return mapping.getInputForward();
        }
       
        
        return mapping.findForward("BanlancesSearch");
            
        
    }
    
//    public ActionForward goEmployeeRegist(ActionMapping mapping,
//            ActionForm form, HttpServletRequest request,
//            HttpServletResponse response) throws SQLException {
//        return mapping.findForward("EmployeeRegistAction");
//          
//    }
    
    public IEmployeeService getEmployeeservice() {
        return employeeservice;
    }
    public void setEmployeeservice(IEmployeeService employeeservice) {
        this.employeeservice = employeeservice;
    }
    
   
}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -