📄 employeecontroller.java
字号:
package com.pet.controller;
import java.text.DateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
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.actions.DispatchAction;
import com.pet.actionform.EmployeeForm;
import com.pet.pojo.Clinique;
import com.pet.pojo.Employee;
import com.pet.proxy.EmployeeProxy;
import com.pet.toolkit.Pagination;
import com.pet.toolkit.Tool;
public class EmployeeController extends DispatchAction {
private EmployeeProxy employeeProxy;
public EmployeeProxy getEmployeeProxy() {
return employeeProxy;
}
public void setEmployeeProxy(EmployeeProxy employeeProxy) {
this.employeeProxy = employeeProxy;
}
public ActionForward login(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
EmployeeForm ef=(EmployeeForm)form;
String employeeCode=ef.getEmployeeCode();
String passWord=ef.getPassWord();
Employee employee=employeeProxy.login(employeeCode, passWord);
int i=Tool.LoginOrFailure(employeeCode, passWord, employee);
if(i==0){
request.setAttribute("Error", "该帐号不存在或帐号错误,请重新输入!");
return mapping.findForward("failure");
}else if(i==1){
request.getSession().setAttribute("employee", employee);
System.out.println(employee.getClinique().getCliniqueCode());
return mapping.findForward("success");
}else {
request.setAttribute("Error", "密码错误,请重新输入!");
return mapping.findForward("failure");
}
}
public ActionForward Query(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
String[] conditions=request.getParameterValues("query");
String pages=request.getParameter("pages");
Map<String, String> map=new HashMap<String, String>();
String query="";
if(conditions!=null){
int j=0;
int len=Tool.GetStringArrayLength(conditions);
query="&";
for(int i=0;i<conditions.length;i++){
String temp=conditions[i];
j++;
if(!"".equals(temp)){
String[] value=temp.split("@");
map.put(value[1], value[2]);
query+="query="+temp;
if(j<len)
query+="&";
}
}
System.out.println("j=:"+j+"----conditions=:"+conditions.length);
}
System.out.println("query:"+query);
int pageSize=7;
long totalResults=employeeProxy.searchResults(map);
Pagination page=new Pagination(pageSize,totalResults);
if(pages!=null)
page.setCurrentPage(Integer.parseInt(pages));
List<Employee> employeeList=employeeProxy.searchByCondition(map, page);
request.setAttribute("employeeList", employeeList);
System.out.println(employeeList.size());
request.setAttribute("page", page);
request.setAttribute("query", query);
return mapping.findForward("QUERY");
}
public ActionForward Add(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
EmployeeForm ef=(EmployeeForm)form;
Employee emp=(Employee)request.getSession().getAttribute("employee");
Clinique clinique=emp.getClinique();
Employee employee=new Employee(clinique, ef.getEmployeeCode(),
ef.getEmployeeName(), ef.getPassWord(), ef.getEmployeeAddr(),
ef.getEmployeeTelephone(), DateFormat.getDateInstance().parse(ef.getEmployeeBirth()),
ef.getEmployeeSex(),ef.getInsuranceNo(), ef.getEmployeePosition(), ef.getSalaryYear(),
null);
employeeProxy.Save(employee);
request.setAttribute("msg", "添加员工成功◎!若需要,可继续添加员工!");
return mapping.findForward("add");
}
public ActionForward edit(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception{
String employeeId=request.getParameter("chkItem");
Employee employee=employeeProxy.searchOne(Integer.valueOf(employeeId));
request.setAttribute("emp", employee);
return mapping.findForward("EDIT");
}
public ActionForward searchMaxKey(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception{
String cid=request.getParameter("cid");
long maxPkey=employeeProxy.searchPrimaryKey(cid);
Employee emp=(Employee)request.getSession().getAttribute("employee");
Clinique clinique=emp.getClinique();
String eCode=clinique.getCliniqueCode().substring(0, 5)+String.valueOf(cid)+"00"+String.valueOf(maxPkey+1);
request.setAttribute("employeeCode", eCode);
return mapping.findForward("add");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -