SystemDirectoryManager.java
资源名称:OA.rar [点击查看]
上传用户:mingda
上传日期:2017-06-20
资源大小:27691k
文件大小:12k
源码类别:
OA系统
开发平台:
Java
- package com.gforce.gfoa;
- /**
- * <p>Title: 吉力科技办公自动化系统</p>
- * <p>Description: 吉力科技办公自动化系统</p>
- * <p>Copyright: 版权所有 2003 (c) 西安吉力科技发展有限公司 Copyright (c) 2003 GForce Sceince & Technology</p>
- * <p>Company: 西安吉力科技发展有限公司 (GForce Sceince & Technology)</p>
- * @author 马登军
- * @version 1.0
- */
- import com.gforce.currency.*;
- import com.gforce.currency.database.*;
- import java.sql.*;
- import java.util.*;
- public class SystemDirectoryManager
- extends RecordManager {
- public SystemDirectoryManager() {
- }
- protected final static String TableName = "SystemDirectory"; //定义声明本类操作表名称为“UserInfo”
- protected final static String IDFieldName = "ID"; //定义声明主键或者可以确定唯一记录的字段名称为“ID”,必须为自增整型
- protected final static String[] NumericFieldsName = {"LevelNumber","ChildrenAcount","OrderNumber","IsLink","IsShow"}; //声明数值型字段名称
- protected final static String[] StringFieldsName = {
- "Name", "Station","OpenedICO","CloseedICO","LinkUrl","Target","Content"}; //声明字符型字段名称
- protected final static String[] DatetimeFieldsName = {}; //声明日期时间型字段名称
- protected final static String[] TextFieldsName = {}; //声明大字符串型字段名称
- /**
- * 根据字段名称获取插入数据时表单元素名称
- * @param strFieldName 字段名称
- * @return 表单素名称
- */
- protected String InsertParament(String strFieldName) {
- return "" + strFieldName + ""; //可以根据需要加前缀、后缀
- }
- /**
- * 根据字段名称获取修改数据时表单元素名称
- * @param strFieldName 字段名称
- * @return 表单素名称
- */
- protected String UpdateParament(String strFieldName) {
- return "" + strFieldName + ""; //可以根据需要加前缀、后缀
- }
- /**
- * 获取本类操作表名称
- * @return 表名称
- */
- public String getTableName() { //获取本类操作表名称
- return TableName;
- }
- protected String getIDFieldName() { //获取主键或者可以确定唯一记录的字段名称
- return IDFieldName;
- }
- protected String[] getNumericFieldsName() { //获取数值型字段名称
- return NumericFieldsName;
- }
- protected String[] getStringFieldsName() { //获取字符型字段名称
- return StringFieldsName;
- }
- protected String[] getDatetimeFieldsName() { //获取日期时间型字段名称
- return DatetimeFieldsName;
- }
- protected String[] getTextFieldsName() { //获取大字符串型字段名称
- return TextFieldsName;
- }
- /**
- * 获取所有记录的向量集
- * @return 所有记录的向量集
- */
- public Vector getSysDirData(String strHasRightPages)
- {
- Vector vc = new Vector();
- strHasRightPages = "'" + strHasRightPages.replaceAll(",","','") + "'";
- vc = SQLManager.GetResultSet("select ID,Name,Station,LevelNumber,ChildrenAcount,OrderNumber,OpenedICO,CloseedICO,LinkUrl,Target,IsLink,Content,IsShow from " + getTableName() + " where LinkUrl='' or LinkUrl is null or LinkUrl in (" + strHasRightPages + ") order by OrderNumber");
- return vc;
- }
- /**
- * 获取所有记录的向量集
- * @return 所有记录的向量集
- */
- public static Vector getSystemDirectoryData()
- {
- Vector vc = new Vector();
- vc = SQLManager.GetResultSet("select * from " + TableName + " ORDER BY OrderNumber ");
- return vc;
- }
- /**
- * 获取指定ID的数据集
- * @param intID 要检索的ID
- * @return 指定ID的数据集
- */
- public static Vector getRecordByID(int intID)
- {
- Vector vc = new Vector();
- vc = SQLManager.GetResultSet("select * from " + TableName + " WHERE ID = " + intID);
- return vc;
- }
- /**
- * 获取指定ID目录下子目录个数
- * @param iSystemDirectoryID 目录ID
- * @return 指定ID目录下子目录个数
- */
- public static int getSubSystemDirectoryCount(int iSystemDirectoryID)
- {
- int iReturnValue = 0;
- String strSQL;
- Vector vc = new Vector();
- if (iSystemDirectoryID == 0)
- {
- strSQL = "select count(*) from " + TableName + " Where Station = '_0_'";
- }
- else
- {
- strSQL = "select Count(*) from " + TableName + " where Station=((select Station from " + TableName +
- " where ID=" + iSystemDirectoryID + ")+'" + iSystemDirectoryID + "_')";
- }
- vc = SQLManager.GetResultSet(strSQL);
- iReturnValue = Integer.parseInt( ( (Vector) vc.get(0)).get(0).toString());
- return iReturnValue;
- }
- /**
- * 获取所有子目录ID组成的字符串
- * @param iSystemDirectoryID 系统目录ID
- * @return 子目录ID组成的字符串
- */
- public static String getSubSystemDirectoryIDs(int iSystemDirectoryID)
- {
- String strReturnValue = "";
- String strSQL;
- Vector vc = new Vector();
- if (iSystemDirectoryID == 0)
- {
- strSQL = "select ID from " + TableName + "";
- }
- else
- {
- strSQL = "select ID from " + TableName + " where Station like ((select Station from " + TableName +
- " where ID=" + iSystemDirectoryID + ")+'" + iSystemDirectoryID + "_%')";
- }
- vc = SQLManager.GetResultSet(strSQL);
- for(int i=0;i<vc.size();i++)
- {
- strReturnValue += ","+ ((Vector) vc.get(i)).get(0).toString();
- }
- if(strReturnValue.length()>1)
- {
- return strReturnValue.substring(1);
- }
- else
- {
- return "";
- }
- }
- /**
- * 更新指定ID目录的子目录个数
- * @param iSystemDirectoryID 目录ID
- */
- public void updateSubSystemDirectoryCount(int iSystemDirectoryID)
- {
- SQLManager.ExcuteSQL("Update " + TableName + " set ChildrenAcount=" + getSubSystemDirectoryCount(iSystemDirectoryID) +
- " where ID=" + iSystemDirectoryID);
- }
- public void updateSubSystemDirectoryData(int iSystemDirectoryID,String strNewStation,String strOldStation,int iLevelChange)
- {
- String strUpdateSQL = "Update " + TableName + " set LevelNumber=LevelNumber + " + iLevelChange + ",Station = Replace(Station,'" + strOldStation + "','" + strNewStation+ "') where Station like '" + strOldStation + iSystemDirectoryID + "_"+"%'";
- SQLManager.ExcuteSQL(strUpdateSQL);
- }
- /**
- * 新增目录记录
- * @param m_request 包含新目录记录的Request请求
- * @return 新目录的ID(大于等于1)或者错误代码(小于1)
- */
- public int InsertRecord(Request m_request)
- {
- int iReturnValue = super.InsertRecord(m_request);
- int iSystemDirectoryID = m_request.GetInt("SystemDirectoryID");
- updateSubSystemDirectoryCount(iSystemDirectoryID);
- return iReturnValue;
- }
- /**
- * 修改目录记录
- * @param m_request 包含目录记录的Request请求
- * @return 目录的ID(大于等于1)或者错误代码(小于1)
- */
- public int UpdateRecord(Request m_request)
- {
- int iID = m_request.GetInt("ID");
- int iNewLevelNumber = m_request.GetInt("LevelNumber");
- String strNewStation = m_request.GetString("Station");
- Vector vc = SQLManager.GetResultSet("select Station,LevelNumber from " + TableName + " where ID=" + iID);
- String strOldStation = ( (Vector) vc.get(0)).get(0).toString();
- int iOldLevelNumber = Integer.parseInt(( (Vector) vc.get(0)).get(1).toString());
- String strStation = strOldStation.substring(0, strOldStation.length() - 1);
- int iOldSystemDirectoryID = Integer.parseInt(strStation.substring(strStation.lastIndexOf("_")+1));
- int iNewSystemDirectoryID = m_request.GetInt("SystemDirectoryID");
- int iReturnValue = 0;
- if (iOldSystemDirectoryID != iNewSystemDirectoryID)
- {
- SQLManager.ExcuteSQL("Update " + TableName + " set OrderNumber=OrderNumber-1 where OrderNumber>(select OrderNumber from " + TableName + " where ID=" + iID +") and Station=((select Station from " + TableName + " where ID=" + iID +")+'')");
- iReturnValue = super.UpdateRecord(m_request);
- updateSubSystemDirectoryCount(iNewSystemDirectoryID);
- updateSubSystemDirectoryCount(iOldSystemDirectoryID);
- updateSubSystemDirectoryData(iID,strNewStation,strOldStation,iNewLevelNumber-iOldLevelNumber);
- setSysDirOrderNumber(iID,10000);
- reOrderSysDir(strOldStation);
- reOrderSysDir(strNewStation);
- }
- else
- {
- iReturnValue = super.UpdateRecord(m_request);
- reOrderSysDir(strNewStation);
- }
- return iReturnValue;
- }
- /**
- * 删除指定ID目录
- * @param iID 目录ID
- * @return 错误代码(小于1)
- */
- public int DeleteByID(int iID)
- {
- SQLManager.ExcuteSQL("Update " + TableName + " set OrderNumber=OrderNumber-1 where OrderNumber>(select OrderNumber from " + TableName + " where ID=" + iID +") and Station=((select Station from " + TableName + " where ID=" + iID +")+'')");
- int iReturnValue = super.DeleteByID(iID);
- updateSubSystemDirectoryCount(iID);
- return iReturnValue;
- }
- /**
- * 按照指定方向移动指定系统目录
- * @param iSysDirID int 指定系统目录的ID
- * @param strDirect String 指定移动方向
- * @return int 错误代码
- */
- public static int moveSysDir(int iSysDirID,String strDirect)
- {
- int iErrCode=1;
- Vector vt=getRecordByID(iSysDirID);
- if(vt.size()==1)
- {
- if(strDirect.equalsIgnoreCase("Top"))
- {
- setSysDirOrderNumber(iSysDirID,-10000);
- }
- else if(strDirect.equalsIgnoreCase("Bottom"))
- {
- setSysDirOrderNumber(iSysDirID,10000);
- }
- else if(strDirect.equalsIgnoreCase("Up"))
- {
- SQLManager.ExcuteSQL("Update " + TableName + " set OrderNumber=OrderNumber-1 where ID=" + iSysDirID +"");
- SQLManager.ExcuteSQL("Update " + TableName + " set OrderNumber=OrderNumber+1 where ID in (Select ID from " + TableName + " where Station=(Select Station from " + TableName + " where ID=" + iSysDirID +") and OrderNumber=(Select OrderNumber from " + TableName + " where ID=" + iSysDirID +") and ID<>" + iSysDirID + ")");
- }
- else if(strDirect.equalsIgnoreCase("Down"))
- {
- SQLManager.ExcuteSQL("Update " + TableName + " set OrderNumber=OrderNumber+1 where ID=" + iSysDirID +"");
- SQLManager.ExcuteSQL("Update " + TableName + " set OrderNumber=OrderNumber-1 where ID in (Select ID from " + TableName + " where Station=(Select Station from " + TableName + " where ID=" + iSysDirID +") and OrderNumber=(Select OrderNumber from " + TableName + " where ID=" + iSysDirID +") and ID<>" + iSysDirID + ")");
- }
- reOrderSysDir(( (Vector) vt.get(0)).get(2).toString());
- }
- else
- {
- iErrCode=-3;
- }
- return iErrCode;
- }
- /**
- * 修改指定系统目录的排序编号
- * @param iSysDirID int 指定系统目录ID
- * @param iOrderNumber int 新的排序编号
- */
- private static void setSysDirOrderNumber(int iSysDirID,int iOrderNumber)
- {
- SQLManager.ExcuteSQL("Update " + TableName + " set OrderNumber=" + iOrderNumber + " where ID=" + iSysDirID + "");
- }
- /**
- * 重新排序指定位置的系统目录
- * @param strStation String
- */
- private static void reOrderSysDir(String strStation)
- {
- if(strStation==null || strStation.trim().length()==0)
- {
- strStation="_0_";
- }
- Vector vt=SQLManager.GetResultSet("Select * from " + TableName + " where Station='" + strStation + "' order by OrderNumber");
- for(int i=0;i<vt.size();i++)
- {
- try
- {
- int iID = 0;
- iID=Integer.parseInt(( (Vector) vt.get(i)).get(0).toString());
- setSysDirOrderNumber(iID,i+1);
- }
- catch(Exception err)
- {
- }
- }
- }
- }