📄 personfilebean.java
字号:
sql =
"delete from zz_grwjb where zgbh= '"
+ strPersonID
+ "' and wjbh="
+ strFileID;
return deleteRecord(sql);
}
//格式化文件名
public String formatFileName(String str, int nLen, int nLine) {
String strFileName = "";
String strT = "";
if (ds.byteLength(str) > (nLen * nLine)) {
return (ds.strByteCopy(str, (nLen * nLine))) + "...";
} else {
return str;
}
/*
for (int i = 0; i < nLine; i++) {
int n = ds.byteLength(str);
if (n < nLen) {
strFileName += str;
break;
}
strT = ds.strByteCopy(str, nLen);
strFileName += strT;
if (i < nLine - 1)
strFileName += "<BR>";
else
strFileName += "...";
str = str.substring(strT.length());
}
*/
}
//根据文件扩展名取得相应的图标名
public String getFileIMG(String strExtName)
{
strExtName = ds.toString(strExtName);
strExtName = strExtName.toUpperCase();
//返回默认的文件图标
if (strExtName.equals(""))
return "file.gif";
if (strExtName.equals("DIR"))
return "folder.gif";
String sql = "";
sql =
"select WJLX,TBWJM from ZZ_GRWJB_WJTB where WJLX='"
+ strExtName
+ "'";
ResultSet rs = db.QuerySQL(sql);
Statement stmt = null;
String strName = "file.gif";
try{
if (rs.next()) {
strName = ds.toString(rs.getString("TBWJM"));
}
}catch(Exception e){System.out.println("getFileIMG()运行时出错:"+e);}
finally{
if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("关闭记录集rs时出错"+e);}
if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("关闭声明时statement出错"+e);}
}
return strName;
}
//删除文件夹及其子文件(夹)
public int delTree()
{
int nErr = 0;
DefaultMutableTreeNode root = buildTree(Integer.toString(nFileID));
//以先序方式删除文件夹树
for (Enumeration e = root.preorderEnumeration();
e.hasMoreElements();
) {
DefaultMutableTreeNode node =
(DefaultMutableTreeNode) e.nextElement();
Hashtable hs = (Hashtable) (node.getUserObject());
String strFileID = (String) hs.get("WJBH");
int nErr_Temp = delSubFile(strFileID);
if (nErr_Temp > 0)
nErr = nErr_Temp;
}
return nErr;
}
//将服务器上的文件更名成上传时的文件名,
//放入downcache文件夹中以备下载,并返回改变后的文件名路径
public String getDownloadFilePrepared(){
String targetfile = "";
//检查根路径
try{
String strRootPath = strFileStorePath;
strRootPath = ds.toString(strRootPath);
if (strRootPath.equals(""))
return null;
//取得文件存贮在服务器上路径
String strFileName = getFilePath();
//取得文件的原名
String strCacheFileName = getFileTrueName();
//打开服务器中的文件
java.io.File myFile = new java.io.File(strRootPath + strFileName);
//取得Cache路径
String strCacheFilePath = strDownCachePath;
java.io.File toFile =
new java.io.File(strCacheFilePath + strCacheFileName);
if (myFile.exists()) {
//拷贝文件
DealFile df = new DealFile();
df.connFIS(strRootPath + strFileName);
df.connFOS(strCacheFilePath + strCacheFileName);
df.movefile_BufferedByteStream();
df.closeFIS();
df.closeFOS();
}
targetfile = (strCacheFilePath + strCacheFileName);
}catch(Exception e){System.out.println("getDownloadFilePrepared()运行时出错:"+e);}
return targetfile;
}
//返回文件下载路径(库中的路径)
private String getFilePath(){
String sql = "";
sql =
"select WJLJ from zz_grwjb where zgbh= '"
+ strPersonID
+ "' and wjbh="
+ nFileID;
ResultSet rs = db.QuerySQL(sql);
Statement stmt = null;
String strPath = "";
try{
if(rs.next())
strPath = ds.toString(rs.getString("WJLJ"));
}catch(Exception e){System.out.println("getFilePath()运行时出错:"+e);}
finally{
if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("关闭记录集rs时出错"+e);}
if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("关闭声明时statement出错"+e);}
}
return strPath;
}
//返回文件原名-上传时的名字(数据库中的名字)
public String getFileTrueName() {
String sql = "";
sql =
"select WJMC from zz_grwjb where zgbh= '"
+ strPersonID
+ "' and wjbh="
+ nFileID;
ResultSet rs = db.QuerySQL(sql);
String strName ="";
Statement stmt = null;
try{
if(rs.next())
strName = ds.toString(rs.getString("WJMC"));
}catch(Exception e){System.out.println("getFileTrueName()运行时出错:"+e);}
finally{
if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("关闭记录集rs时出错"+e);}
if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("关闭声明时statement出错"+e);}
}
return strName;
}
//取得上传文件保存的别名
public String getNewStoreFileName(String strFN) {
SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmssSSSZ");
String strdt = df.format(new java.util.Date());
strFN = ds.toString(strFN);
String strExt = ds.toString(strPersonID);
strExt.replace('.', '_');
String strNewFileName = ds.toString(strdt + strFN + "." + strExt);
strNewFileName = strNewFileName + "." + "HG$";
//System.out.println(strNewFileName);
return strNewFileName;
}
// 取得职工唯一编号
public String getPersonID() {
return strPersonID;
}
//取得当前文件夹的子文件
public Vector getSubData(){
Vector vt = new Vector();
String sql = "";
sql =
"select ZGBH,WJBH,WJMC,WJDX,WJLJ,WJLB,FMLBH,WJKZM from ZZ_grwjb "
+ " where zgbh='"
+ strPersonID
+ "'"
+ " and WJFBH="
+ nParentID
+ " order by WJLB,WJMC";
ResultSet rs = selectRecord(sql);
Statement stmt = null;
try{
ResultSetMetaData rsmd = rs.getMetaData();
int cols = rsmd.getColumnCount();
while (rs.next()) {
Hashtable ht = new Hashtable();
for (int i = 1; i <= cols; i++) {
String field = ds.toString(rsmd.getColumnName(i));
String value = ds.toString(rs.getString(i));
ht.put(field, value);
}
vt.add(ht);
}
}catch(Exception e){System.out.println("getSubData()运行时出错:"+e);}
finally{
if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("关闭记录集rs时出错"+e);}
if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("关闭声明时statement出错"+e);}
}
return vt;
}
//检查新文件名的合法性--是否在当前根下面有重名
public boolean isSameName(String strName){
DefaultMutableTreeNode root = build1LevTree();
DefaultMutableTreeNode node;
if (root.getChildCount() != 0) {
for (int i = 0; i < root.getChildCount(); i++) {
node = (DefaultMutableTreeNode) root.getChildAt(i);
String str =
(String) ((Hashtable) node.getUserObject()).get("WJMC");
if (str.equals(strName)) {
return true;
}
} //end for i;
} //end if;
return false;
}
//取得DownCachePath
public String getDownCachePath() {
return strDownCachePath;
}
//取得FileStorePath
public String getFileStorePath() {
return strFileStorePath;
}
//为文件改名(不能改扩展名)
public int renameFile(String strNewName){
String sql =
"update ZZ_GRWJB set WJMC='"
+ strNewName
+ "'"
+ " where ZGBH='"
+ strPersonID
+ "' and WJBH="
+ nFileID;
return db.ExecuteSQL(sql);
}
// 设置文件唯一编号
public void setFileID(int nNum) {
nFileID = nNum;
}
public int getFileID() {
return this.nNum;
}
public void setstrFileID(String strNum) {
nFileID = Integer.parseInt(strNum);
}
public String getstrFileID() {
return this.strNum;
}
//设置父文件编号
public void setParentID(int nNum) {
nParentID = nNum;
}
public void setParentID(String strNum) {
nParentID = Integer.parseInt(strNum);
}
// 设置职工唯一编号
public void setPersonID(String str) {
strPersonID = str;
}
public int mvFileToFolder(String str){
if (nFileID == Integer.parseInt(str))
return -1;
String sql =
"update ZZ_GRWJB set FMLBH="
+ str
+ " where ZGBH='"
+ strPersonID
+ "' and WJBH="
+ nFileID;
return db.ExecuteSQL(sql);
}
public DefaultMutableTreeNode buildFolderTree() {
String sql =
" Select WJBH,WJMC from ZZ_GRWJB "
+ " Where FMLBH = -1"
+ " and ZGBH='"
+ strPersonID
+ "'"
+ " order by WJBH ";
ResultSet rs = db.QuerySQL(sql);
Statement stmt = null;
DefaultMutableTreeNode root = null;
try{
ResultSetMetaData rsmd = rs.getMetaData();
// 结果集为空时返回
if (!(rs.next())) {
//System.err.println("数据表错误:根为空。");
return null;
}
int cols = rsmd.getColumnCount();
Hashtable hash = new Hashtable();
hash.clear();
for (int i = 1; i <= cols; i++) {
String field = ds.toString(rsmd.getColumnName(i));
String value = ds.toString(rs.getString(i));
hash.put(field, value);
}
root = new DefaultMutableTreeNode(hash);
buildSubFolderTree(root);
}catch(Exception e){System.out.println("buildFolderTree()运行时出错:"+e);}
finally{
if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("关闭记录集rs时出错"+e);}
if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("关闭声明时statement出错"+e);}
}
return root;
}
private void buildSubFolderTree(DefaultMutableTreeNode rootNode)
{
String sql = "";
String strParentNo = "";
DefaultMutableTreeNode root = rootNode;
DefaultMutableTreeNode treeNode;
//选出rootNode的子节点
strParentNo =
(String) ((Hashtable) rootNode.getUserObject()).get("WJBH");
sql =
" Select WJBH,WJMC from ZZ_GRWJB "
+ " Where FMLBH="
+ strParentNo
+ " and ZGBH='"
+ strPersonID
+ "'"
+ " and WJLB='D' order by WJBH ";
ResultSet rs = db.QuerySQL(sql);
Statement stmt = null;
try{
ResultSetMetaData rsmd = rs.getMetaData();
int cols = rsmd.getColumnCount();
while (rs.next()) {
Hashtable hash = new Hashtable();
for (int i = 1; i <= cols; i++) {
String field = ds.toString(rsmd.getColumnName(i));
String value = ds.toString(rs.getString(i));
hash.put(field, value);
}
treeNode = new DefaultMutableTreeNode(hash);
root.add(treeNode);
buildSubFolderTree(treeNode);
}
}catch(Exception e){System.out.println("buildSubFolderTree()运行时出错:"+e);}
finally{
if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("关闭记录集rs时出错"+e);}
if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("关闭声明时statement出错"+e);}
}
}
public int getUsedSpace(String PersonID) {
int usedspace=0;
ResultSet rs = null;
Statement stmt = null;
try {
String sql =
"select SUM(WJDX) from ZZ_GRWJB where ZGBH='"
+ PersonID
+ "'";rs = db.QuerySQL(sql);
if (rs.next())usedspace = rs.getInt(1);
} catch (SQLException e) {}
finally{
if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("关闭记录集rs时出错"+e);}
if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("关闭声明时statement出错"+e);}
}
return usedspace;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -