📄 nseermoduletreedb.java
字号:
}else{
file.mkdirs();//生成文件夹
file1.mkdirs();
fileb.mkdirs();
}
}
return finished_tag;
}
public String getFileId(String tableName,String[] chief_array,String parent_id,int step_length){//生成II级或之后的编号
String file_ID="";
String temp="";
for(int i=0;i<step_length;i++){
temp+="0";
}
temp="1"+temp;
try{
String sqla = "select "+chief_array[0]+","+chief_array[4]+" from "+tableName+" where "+chief_array[1]+"='"+parent_id+"' order by "+chief_array[0]+" desc";
ResultSet rs =db.executeQuery(sqla);
if(rs.next()){
String str=rs.getString(chief_array[4]);
int in1=0;
String str2=str.substring(str.length()-step_length);
in1=Integer.parseInt(temp)+Integer.parseInt(str2)+1;
file_ID=str.substring(0,str.length()-step_length)+(in1+"").substring(1);
}else{
sqla = "select "+chief_array[4]+" from "+tableName+" where "+chief_array[0]+"='"+parent_id+"'";
rs =db.executeQuery(sqla);
if(rs.next()){
file_ID=rs.getString(chief_array[4])+((Integer.parseInt(temp)+1)+"").substring(1);//生成编号
}
}
db.close();
}catch(Exception ex){
ex.printStackTrace();
}
return file_ID;
}
public void deleteTemp(String id,String[] chief_array,String tableName){
try{
/******为操作erp_update_d表做准备**********/
java.util.Date now = new java.util.Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String time=formatter.format(now);
Double c_ver=0.00;
String sql_update="select ver from erp_update_t order by ver desc";
ResultSet rs_update=db.executeQuery(sql_update);
if(rs_update.next()){c_ver=rs_update.getDouble("ver");}
/****************/
List rsList = (List)new java.util.ArrayList();
String sql1 = "select "+chief_array[0]+" from "+tableName+" where "+chief_array[1]+"='"+id+"' and reserved_tag!='1'";
try{
ResultSet rs=db.executeQuery(sql1);
while(rs.next()){
rsList.add(rs.getString(chief_array[0]));
}
}catch(Exception ex){
ex.printStackTrace();
}
Iterator ite=rsList.iterator();
while(ite.hasNext()){
String pid=(String)ite.next();
deleteTemp(pid,chief_array,tableName);
String sql2 = "delete from "+tableName+" where "+chief_array[0]+"='"+pid+"' and reserved_tag!='1'";
try{
/*******删除erp_update_d表中的记录******/
sql_update="select id from "+tableName+" where "+chief_array[0]+"='"+pid+"' and reserved_tag!='1'";
rs_update=db.executeQuery(sql_update);
if(rs_update.next()){
sql_update="delete from erp_update_d where t_name='"+tableName+"' and row_id='"+rs_update.getString("id")+"'";
db.executeUpdate(sql_update);
}
/***********************************/
db.executeUpdate(sql2);
}catch(Exception ex){
ex.printStackTrace();
}
}
try{
String pid="";
String sql4="select "+chief_array[1]+" from "+tableName+" where "+chief_array[0]+"='"+id+"' and reserved_tag!='1'";
ResultSet rs4=db.executeQuery(sql4);
if(rs4.next()){
pid=rs4.getString(chief_array[1]);
}
String sql31 = "select * from "+tableName+" where "+chief_array[0]+"='"+id+"' and reserved_tag!='1'";
ResultSet rs41=db.executeQuery(sql31);
if(rs41.next()){
if(rs41.getString("hreflink").equals("")){
delAllFile(path+rs41.getString("file_path"));//删除文件
}else{
File file = new File(path+rs41.getString("file_path")+rs41.getString("hreflink"));
file.delete();//删除单个文件
}
}
String sql3 = "delete from "+tableName+" where "+chief_array[0]+"='"+id+"' and reserved_tag!='1'";
/*******删除erp_update_d表中的记录******/
sql_update="select id from "+tableName+" where "+chief_array[0]+"='"+id+"' and reserved_tag!='1'";
rs_update=db.executeQuery(sql_update);
if(rs_update.next()){
sql_update="delete from erp_update_d where t_name='"+tableName+"' and row_id='"+rs_update.getString("id")+"'";
db.executeUpdate(sql_update);
}
/***********************************/
db.executeUpdate(sql3);
sql4="select id from "+tableName+" where "+chief_array[1]+"='"+pid+"' and reserved_tag!='1'";
rs4=db.executeQuery(sql4);
if(!rs4.next()){
sql3 = "update "+tableName+" set "+chief_array[3]+"='0' where "+chief_array[0]+"='"+pid+"' and reserved_tag!='1'";
db.executeUpdate(sql3);
/*****更新erp_update_d表条记录********/
sql_update="select id from "+tableName+" where "+chief_array[0]+"='"+pid+"' and "+chief_array[3]+"='0' and reserved_tag!='1' order by id desc";
rs_update=db.executeQuery(sql_update);
if(rs_update.next()){
String row_id=rs_update.getString("id");
sql_update="select * from erp_update_d where t_name='"+tableName+"' and row_id='"+row_id+"'";
rs_update=db.executeQuery(sql_update);
if(rs_update.next()){
String[] cols_name=rs_update.getString("cols_name").split("㊣");
String[] cols_value=rs_update.getString("cols_value").split("㊣");
String cols_temp="";
int a=0;
for(int i=0;i<cols_name.length;i++){
if(cols_name[i].equals(chief_array[3])){
cols_value[i]="0";
a++;
}
cols_temp+="㊣"+cols_value[i];
}
if(a>0){
sql_update="update erp_update_d set cols_value='"+cols_temp.substring(1)+"' where t_name='"+tableName+"' and row_id='"+row_id+"'";
}else{
sql_update="update erp_update_d set cols_name='"+rs_update.getString("cols_name")+"㊣"+chief_array[3]+"',cols_value='"+cols_temp.substring(1)+"㊣1' where t_name='"+tableName+"' and row_id='"+row_id+"'";
}
db.executeUpdate(sql_update);
}
}
/*****************************************/
}
}catch(Exception ex){
ex.printStackTrace();
}
}catch(Exception ex){
ex.printStackTrace();
}
}
public String deleteNodeInf(String id,String[] chief_array,String tableName){
String finished_tag="";
try{
deleteTemp(id,chief_array,tableName);
db.close();
finished_tag="200";
}catch(Exception ex){ex.printStackTrace();}
return finished_tag;
}
public String[] getSingleNodeInf(String category_id,String tableName,String[] field_array,String[] chief_array){//根据传入的节点id,表名,列名,以list形式返回所有子节点信息
String[] data_array=new String[field_array.length];
String column_group="";
for(int i=0;i<field_array.length;i++){
column_group+=","+field_array[i];
}
String sql="select "+column_group.substring(1)+" from "+tableName+" where "+chief_array[0]+"='"+category_id+"' and reserved_tag!='1'";
try{
ResultSet rs =db.executeQuery(sql);
if(rs.next()){
for(int i=0;i<field_array.length;i++){
if(field_array[i].equals("file_id")){data_array[i]=rs.getString(field_array[i]);}
else{data_array[i]=rs.getString(field_array[i]);}
}
}
db.close();
}catch(Exception ex){
ex.printStackTrace();
}
return data_array;
}
public String changeNodeInf(String tableName,String category_id,String file_id,String file_id_hidden,String file_name,String[] chief_array,int step_length){//此方法起修改节点作用/
String node_name="";
try{
/*
if(file_id.equals(file_id_hidden)||file_id.substring(0,file_id.length()-step_length).equals(file_id_hidden.substring(0,file_id_hidden.length()-step_length))){//如果编号没有修改.
String sql = "update "+tableName+" set "+chief_array[2]+"='"+n.E(file_id+" "+file_name)+"',"+chief_array[4]+"='"+n.E(file_id)+"',"+chief_array[5]+"='"+n.E(file_name)+"' where "+chief_array[0]+"='"+category_id+"'";
db.executeUpdate(sql);
}else{//如果编号修改.
String parent_ID=file_id.substring(0,file_id.length()-step_length);
String sqla="select "+chief_array[0]+" from "+tableName+" where "+chief_array[4]+"='"+parent_ID+"'";
ResultSet rs=db.executeQuery(sqla);
if(rs.next()){
node_name=rs.getString(chief_array[0]);
}
String sql = "update "+tableName+" set "+chief_array[2]+"='"+file_id+" "+file_name+"',"+chief_array[1]+"='"+node_name+"',"+chief_array[4]+"='"+file_id+"',"+chief_array[5]+"='"+file_name+"' where "+chief_array[0]+"='"+category_id+"'";
db.executeUpdate(sql);
sql="update "+tableName+" set "+chief_array[3]+"='1' where "+chief_array[0]+"='"+node_name+"'";
db.executeUpdate(sql);
String pid1="";
sqla="select "+chief_array[0]+" from "+tableName+" where "+chief_array[4]+"='"+file_id_hidden.substring(0,file_id_hidden.length()-step_length)+"'";
rs=db.executeQuery(sqla);
if(rs.next()){
pid1=rs.getString(chief_array[0]);
sqla="select id from "+tableName+" where "+chief_array[1]+"='"+pid1+"'";
rs=db.executeQuery(sqla);
if(!rs.next()){
sql="update "+tableName+" set "+chief_array[3]+"='0' where "+chief_array[4]+"='"+file_id_hidden.substring(0,file_id_hidden.length()-step_length)+"'";
db.executeUpdate(sql);
}
}
}*/
db.close();
}catch(Exception ex){
ex.printStackTrace();
}
return node_name;
}
public static void delAllFile(String filePath) {// 删除文件
try {
File file = new File(filePath);
File[] fileList = file.listFiles();
String dirPath = null;
if (fileList != null) {
for (int i = 0; i < fileList.length; i++) {
if (fileList[i].isFile()) {
fileList[i].delete();
}
if (fileList[i].isDirectory()) {
dirPath = fileList[i].getPath();
delAllFile(dirPath);
}
}
file.delete();
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -