?? functionaction.java
字號:
/**
* Created by Struts Assistant.
* Date: 08.12.2005 Time: 09:33:24
*/
package com.tairun.component.popedom.webapp.action;
import org.apache.struts.action.*;
import org.apache.struts.actions.MappingDispatchAction;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.tairun.component.popedom.dao.FunctionDAO;
import com.tairun.component.popedom.dao.DAOFactory;
import com.tairun.component.popedom.dao.RoleDAO;
import com.tairun.component.popedom.dao.PrivilegeDAO;
import com.tairun.component.popedom.model.Function;
import com.tairun.component.popedom.model.Role;
import com.tairun.component.popedom.model.Privilege;
import com.tairun.component.popedom.webapp.form.FunctionForm;
import com.tairun.component.popedom.webapp.form.FunListTreeForm;
import java.util.List;
import java.util.Vector;
import java.util.Iterator;
public class FunctionAction extends MappingDispatchAction {
public ActionForward create(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
FunctionDAO functionDAO = DAOFactory.createFunctionDAO();
FunctionForm functionForm = (FunctionForm)form;
if(functionDAO.isexist(functionForm.getFunctionID(),functionForm.getFunctionname())){
return mapping.findForward("create_function_faile");
}
else{
Function function = new Function();
String str = functionDAO.getmaxID(functionForm.getFunctionID());
function.setFunctionID(str);
function.setFunctionname(functionForm.getFunctionname());
function.setDiscription(functionForm.getDiscription());
functionDAO.create(function);
request.setAttribute("funID",functionForm.getFunctionID());
function = functionDAO.getdetailby_funID(functionForm.getFunctionID());
request.setAttribute("fun",function);
RoleDAO roleDAO = DAOFactory.createRoleDAO();
PrivilegeDAO privilegeDAO = DAOFactory.createPrivilegeDAO();
List listrole = roleDAO.getlist();
for(Iterator it = listrole.iterator();it.hasNext();){
Role role = (Role)it.next();
Privilege privilege = new Privilege();
privilege.setFunctionID(str);
privilege.setRoleID(role.getRoleID());
privilege.setPrivatestatus("0000");
privilegeDAO.create(privilege);
}
return mapping.getInputForward();
}
}
public ActionForward createFirstfun(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
FunctionDAO functionDAO = DAOFactory.createFunctionDAO();
FunctionForm functionForm = (FunctionForm)form;
if(functionDAO.isexist("",functionForm.getFunctionname())){
return mapping.findForward("create_function_faile");
}
else{
Function function = new Function();
String str = functionDAO.getmaxID();
function.setFunctionID(str);
function.setFunctionname(functionForm.getFunctionname());
function.setDiscription(functionForm.getDiscription());
functionDAO.create(function);
RoleDAO roleDAO = DAOFactory.createRoleDAO();
PrivilegeDAO privilegeDAO = DAOFactory.createPrivilegeDAO();
List listrole = roleDAO.getlist();
for(Iterator it = listrole.iterator();it.hasNext();){
Role role = (Role)it.next();
Privilege privilege = new Privilege();
privilege.setFunctionID(str);
privilege.setRoleID(role.getRoleID());
privilege.setPrivatestatus("0000");
privilegeDAO.create(privilege);
}
return mapping.getInputForward();
}
}
public ActionForward update(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
FunctionDAO functionDAO = DAOFactory.createFunctionDAO();
FunctionForm functionForm = (FunctionForm)form;
String str = request.getParameter("functionID");
if(functionDAO.isexist_update(str,functionForm.getFunctionname())){
return mapping.findForward("updata_function_faile");
}
else{
Function function = new Function();
function.setFunction(functionForm.getFunction());
function.setFunctionname(functionForm.getFunctionname());
function.setDiscription(functionForm.getDiscription());
functionDAO.update(function);
String str1= new String();
if(str.length()==2){
str1 = str;
}
else if(str.length()==4){
str1 = str.substring(0,2);
}
else{
str1 = str.substring(0,4);
}
request.setAttribute("fatherID",str1);
function = functionDAO.getdetailby_funID(str1);
request.setAttribute("fun",function);
return mapping.getInputForward();
}
}
public ActionForward delete(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
FunctionDAO functionDAO = DAOFactory.createFunctionDAO();
String[] delfunID = request.getParameterValues("fun");
Function function1 = functionDAO.getdetail(Long.parseLong(delfunID[0]));
String str = function1.getFunctionID();
for(int i=0;i<delfunID.length;i++){
Function function = new Function();
function.setFunction(Long.parseLong(delfunID[i]));
functionDAO.delete(function);
}
if(str.length()==4){
request.setAttribute("fatherID",str.substring(0,2));
Function function = functionDAO.getdetailby_funID(str.substring(0,2));
request.setAttribute("fun",function);
}
else if(str.length()==6){
request.setAttribute("fatherID",str.substring(0,4));
Function function = functionDAO.getdetailby_funID(str.substring(0,4));
request.setAttribute("fun",function);
}
else{
request.setAttribute("fatherID",str);
}
return mapping.getInputForward();
}
public ActionForward display(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
FunctionDAO functionDAO = DAOFactory.createFunctionDAO();
FunctionForm functionForm = (FunctionForm)form;
Function function = functionDAO.getdetail(Long.parseLong(request.getParameter("function")));
functionForm.setFunction(function.getFunction());
functionForm.setFunctionID(function.getFunctionID());
functionForm.setFunctionname(function.getFunctionname());
functionForm.setDiscription(function.getDiscription());
return mapping.getInputForward();
}
public ActionForward list(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
FunctionDAO functionDAO = DAOFactory.createFunctionDAO();
FunctionForm functionForm = (FunctionForm)form;
List results = functionDAO.getlist();
functionForm.setResults(results);
return mapping.getInputForward();
}
public ActionForward funID_list(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
FunctionDAO functionDAO = DAOFactory.createFunctionDAO();
FunctionForm functionForm = (FunctionForm)form;
List results = functionDAO.getfunID_list();
functionForm.setResults(results);
return mapping.getInputForward();
}
public ActionForward firstall_list(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
FunctionDAO functionDAO = DAOFactory.createFunctionDAO();
FunctionForm functionForm = (FunctionForm)form;
List results = functionDAO.getfirstall_list();
functionForm.setResults(results);
return mapping.getInputForward();
}
public ActionForward second_list(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
FunctionDAO functionDAO = DAOFactory.createFunctionDAO();
FunctionForm functionForm = (FunctionForm)form;
List results = functionDAO.getsecond_list(request.getParameter("functionID"));
functionForm.setResults(results);
return mapping.getInputForward();
}
public ActionForward listForTree(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
FunctionDAO functionDAO = DAOFactory.createFunctionDAO();
FunListTreeForm funListTreeForm = (FunListTreeForm)form;
List list = functionDAO.getfirstall_list();
List results = new Vector();
for(Iterator it = list.iterator();it.hasNext();){
Function fun = (Function)it.next();
List list1 = functionDAO.getsecond_list(fun.getFunctionID());
List results1 = new Vector();
for(Iterator it1 = list1.iterator();it1.hasNext();){
Function fun1 = (Function)it1.next();
fun1.setList(functionDAO.getsecond_list(fun1.getFunctionID()));
results1.add(fun1);
}
fun.setList(results1);
results.add(fun);
}
funListTreeForm.setResults(results);
return mapping.getInputForward();
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -