⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 websitedirmanager.java

📁 一个目前正在上线运行的JSP企业网站系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
      {
        strSQL += " Order by " + strOrderBy + " desc";
      }
      else
      {
        strSQL += " Order by " + strOrderBy + "";
      }
    }
    else
    {
      strSQL += " Order by OrderNumber";
    }

    Vector vt = SQLManager.GetResultSet(strSQL);
    return vt;
  }

  /**
   * 获取指定ID目录下子目录个数
   * @param iSystemDirectoryID  目录ID
   * @return 指定ID目录下子目录个数
   */
  public static int getSubSystemDirectoryCount(int iSystemDirectoryID)
  {
    int iReturnValue = 0;
    String strSQL = "select Count(*) from " + TableName +
      " where Station=((select Station from " + TableName + " where ID=" +
      iSystemDirectoryID + ")+'" + iSystemDirectoryID + "_')";
    Vector 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 = "select ID from " + TableName +
      " where Station like ((select Station from " + TableName +
      " where ID=" + iSystemDirectoryID + ")+'" + iSystemDirectoryID + "_%')";
    Vector 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)
      {
      }
    }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -