📄 movesortaction.java
字号:
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.hao2007.struts.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
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 org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMessage;
import com.hao2007.struts.form.MoveSortForm;
import com.hao2007.struts.db.DataStore;
import java.sql.ResultSet;
/**
* MyEclipse Struts
* Creation date: 08-27-2007
*
* XDoclet definition:
* @struts.action path="/moveSort" name="moveSortForm" input="/admin/moveSort.jsp" scope="request" validate="true"
* @struts.action-forward name="moveSortSuccess" path="/admin/moveSortSuccess.jsp"
* @struts.action-forward name="moveSortFail" path="/admin/moveSortFail.jsp"
*/
public class MoveSortAction extends Action {
/*
* Generated Methods
*/
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
MoveSortForm moveSortForm = (MoveSortForm) form;// TODO Auto-generated method stub
int sort_id1=Integer.parseInt(moveSortForm.getSort_id1());
int sort_id2=Integer.parseInt(moveSortForm.getSort_id2());
DataStore ds=DataStore.getInstance();
ds.beginTransaction();
ResultSet rs1=null;
try{
String sql1="select * from class where id='"+sort_id1+"'";
rs1=ds.read(sql1);
rs1.next();
}
catch(Exception e){
e.printStackTrace();
}
ds.commitTransaction();
ds.beginTransaction();
ResultSet rs2=null;
try{
String sql2="select * from class where id='"+sort_id2+"'";
rs2=ds.read(sql2);
rs2.next();
}catch(Exception e){
e.printStackTrace();
}
ds.commitTransaction();
ActionErrors errors=new ActionErrors();
//根目录不能移动,请选择其它类别
if(rs1.getInt("parent_id")==0){
errors.add("moveSort.error1", new ActionMessage("moveSort.error1_1"));
saveErrors(request,errors);
return (mapping.findForward("moveSortFail"));
}
//目标类别与原类别相同,不能移动
//rs2.getInt("parent_id")==rs1.getInt("parent_id")
if(sort_id1==sort_id2){
errors.add("moveSort.error2", new ActionMessage("moveSort.error2_2"));
saveErrors(request,errors);
return (mapping.findForward("moveSortFail"));
}
//不能移动到自已的父目录下
if(rs2.getString("sort_path")+rs1.getInt("parent_id")+","==rs1.getString("sort_path")){
errors.add("moveSort.error3", new ActionMessage("moveSort.error3_3"));
saveErrors(request,errors);
return (mapping.findForward("moveSortFail"));
}
//不能移动当前类别的子类别下
if(rs2.getString("sort_path").indexOf(rs1.getString("sort_path"))>=0){
errors.add("moveSort.error4", new ActionMessage("moveSort.error4_4"));
saveErrors(request,errors);
return (mapping.findForward("moveSortFail"));
}
//更新节点的路径
String newPath=rs2.getString("sort_path")+rs1.getString("id")+",";
String sql3="update class set sort_path=concat('"+newPath+"',Mid(sort_path,LENGTH('"+rs1.getString("sort_path")+"')+1)) where INSTR(sort_path,'"+rs1.getString("sort_path")+"')>0";
ds.execute(sql3);
//重新调整深度值
//ds.beginTransaction();
ResultSet rs3=null;
try{
String sql_select_depth="select * from class where INSTR(sort_path,',"+rs1.getInt("id")+",')>0 order by id asc";
rs3=ds.read(sql_select_depth);
while(rs3.next()){
//String depth_length[]=rs3.getString("sort_path").split(",");
String sql_depth="update class set sort_depth="+(rs3.getString("sort_path").split(",").length-1)+" where INSTR(sort_path,',"+rs1.getInt("id")+",')>0 order by id asc";
ds.execute(sql_depth);
};
}
catch(Exception e){
e.printStackTrace();
}
//ds.commitTransaction();
//更新操作节点的父节点
String sql4="update class set parent_id="+rs2.getInt("id")+" where id='"+rs1.getInt("id")+"'";
ds.execute(sql4);
//更新对应信息路径
String sql5="update news set sort_path=concat('"+newPath+"',Mid(sort_path,LENGTH('"+rs1.getString("sort_path")+"')+1)) where INSTR(sort_path,'"+rs1.getString("sort_path")+"')>0";
ds.execute(sql5);
return (mapping.findForward("moveSortSuccess"));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -