userdesktopsetupdb.java
来自「一个用java编写的功能强大的OA系统」· Java 代码 · 共 422 行
JAVA
422 行
package com.redmoon.oa.person;import java.sql.*;import cn.js.fan.base.*;import cn.js.fan.db.*;import cn.js.fan.util.*;import com.redmoon.oa.db.*;import com.redmoon.oa.ui.DesktopMgr;import com.cloudwebsoft.framework.db.JdbcTemplate;import java.util.Iterator;public class UserDesktopSetupDb extends ObjectDb { public UserDesktopSetupDb() { init(); } public UserDesktopSetupDb(int id) { init(); this.id = id; load(); } public void initDB() { tableName = "user_desktop_setup"; primaryKey = new PrimaryKey("ID", PrimaryKey.TYPE_INT); objectCache = new UserDesktopSetupCache(this); this.isInitFromConfigDB = false; QUERY_CREATE = "insert into " + tableName + " (USER_NAME, TITLE, COUNT, WIN_LEFT, WIN_TOP, WIN_WIDTH, WIN_HEIGHT, MODULE_CODE, MODULE_ITEM, ID, ZINDEX) values (?,?,?,?,?,?,?,?,?,?,?)"; QUERY_SAVE = "update " + tableName + " set TITLE=?, COUNT=?, WIN_LEFT=?, WIN_TOP=?, WIN_WIDTH=?, WIN_HEIGHT=?, MODULE_CODE=?, MODULE_ITEM=?, ZINDEX=?, WIN_MIN=? where ID=?"; QUERY_LOAD = "select USER_NAME, TITLE, COUNT, WIN_LEFT, WIN_TOP, WIN_WIDTH, WIN_HEIGHT, MODULE_CODE, MODULE_ITEM, ZINDEX, WIN_MIN from " + tableName + " where ID=?"; QUERY_DEL = "delete from " + tableName + " where ID=?"; QUERY_LIST = "select ID from " + tableName; } public ObjectDb getObjectRaw(PrimaryKey pk) { return new UserDesktopSetupDb(pk.getIntValue()); } public UserDesktopSetupDb getUserDesktopSetupDb(int id) { return (UserDesktopSetupDb) getObjectDb(new Integer(id)); } public void delDesktopOfUser(String userName) { JdbcTemplate jt = new JdbcTemplate(new com.cloudwebsoft.framework.db.Connection(cn.js.fan.web.Global.defaultDB)); String sql = "delete from user_desktop_setup where USER_NAME=?"; try { jt.executeUpdate(sql, new Object[] {userName}); } catch (Exception e) { logger.error("deleteDesktopOfUser:" + e.getMessage()); } } public void initDesktopOfUser(String userName) { delDesktopOfUser(userName); JdbcTemplate jt = new JdbcTemplate(new com.cloudwebsoft.framework.db.Connection(cn.js.fan.web.Global.defaultDB)); int id = (int)SequenceManager.nextID(SequenceManager.OA_USER_DESKTOP_SETUP); try { String sql = "INSERT INTO user_desktop_setup(ID, USER_NAME, TITLE, COUNT, WIN_LEFT,"; sql += "WIN_TOP, WIN_WIDTH, WIN_HEIGHT, MODULE_CODE,"; sql += "MODULE_ITEM, IS_SYSTEM, MORE_PAGE, IS_LOCKED,"; sql += "ZINDEX, WIN_MIN) VALUES "; sql += "(" + id + ", " + StrUtil.sqlstr(userName) + ",'公共通知 ',10, 430, 0, 371, 246, 'fileark','notice',0, NULL, '',1, 0)"; jt.addBatch(sql); id = (int)SequenceManager.nextID(SequenceManager.OA_USER_DESKTOP_SETUP); sql = "INSERT INTO user_desktop_setup(ID, USER_NAME, TITLE, COUNT, WIN_LEFT,"; sql += "WIN_TOP, WIN_WIDTH, WIN_HEIGHT, MODULE_CODE,"; sql += "MODULE_ITEM, IS_SYSTEM, MORE_PAGE, IS_LOCKED,"; sql += "ZINDEX, WIN_MIN) VALUES "; sql += "(" + id + ", " + StrUtil.sqlstr(userName) + ",'待办工作流 ',20, 6, 0, 418, 244, 'flow','',0, NULL,'',1, 0)"; jt.addBatch(sql); id = (int)SequenceManager.nextID(SequenceManager.OA_USER_DESKTOP_SETUP); sql = "INSERT INTO user_desktop_setup(ID, USER_NAME, TITLE, COUNT, WIN_LEFT,"; sql += "WIN_TOP, WIN_WIDTH, WIN_HEIGHT, MODULE_CODE,"; sql += "MODULE_ITEM, IS_SYSTEM, MORE_PAGE, IS_LOCKED,"; sql += "ZINDEX, WIN_MIN) VALUES "; sql += "(" + id + ", " + StrUtil.sqlstr(userName) + ",'任务督办 ',10, 8, 512, 418, 265, 'task','',0, NULL, '',1, 0)"; jt.addBatch(sql); id = (int)SequenceManager.nextID(SequenceManager.OA_USER_DESKTOP_SETUP); sql = "INSERT INTO user_desktop_setup(ID, USER_NAME, TITLE, COUNT, WIN_LEFT,"; sql += "WIN_TOP, WIN_WIDTH, WIN_HEIGHT, MODULE_CODE,"; sql += "MODULE_ITEM, IS_SYSTEM, MORE_PAGE, IS_LOCKED,"; sql += "ZINDEX, WIN_MIN) VALUES "; sql += "(" + id + "," + StrUtil.sqlstr(userName) + ",'短消息 ',10, 7, 255, 418, 248, 'msg','',0, NULL, '',1, 0)"; jt.addBatch(sql); id = (int)SequenceManager.nextID(SequenceManager.OA_USER_DESKTOP_SETUP); sql = "INSERT INTO user_desktop_setup(ID, USER_NAME, TITLE, COUNT, WIN_LEFT,"; sql += "WIN_TOP, WIN_WIDTH, WIN_HEIGHT, MODULE_CODE,"; sql += "MODULE_ITEM, IS_SYSTEM, MORE_PAGE, IS_LOCKED,"; sql += "ZINDEX, WIN_MIN) VALUES "; sql += "(" + id + ", " + StrUtil.sqlstr(userName) + ",'论坛新贴 ',10, 431, 514, 371, 260, 'forum','',0, NULL, '',1, 0)"; jt.addBatch(sql); id = (int)SequenceManager.nextID(SequenceManager.OA_USER_DESKTOP_SETUP); sql = "INSERT INTO user_desktop_setup(ID, USER_NAME, TITLE, COUNT, WIN_LEFT,"; sql += "WIN_TOP, WIN_WIDTH, WIN_HEIGHT, MODULE_CODE,"; sql += "MODULE_ITEM, IS_SYSTEM, MORE_PAGE, IS_LOCKED,"; sql += "ZINDEX, WIN_MIN) VALUES "; sql += "(" + id + ", " + StrUtil.sqlstr(userName) + ",'日程安排 ',10, 431, 254, 371, 253, 'plan','',0, NULL, '',1, 0)"; jt.addBatch(sql); jt.executeBatch(); UserDesktopSetupCache udsc = new UserDesktopSetupCache(this); udsc.refreshList(); } catch (SQLException e) { logger.error("initDesktopOfUser:" + e.getMessage()); } } public void setUserName(String userName) { this.userName = userName; } public void setTitle(String title) { this.title = title; } public void setCount(int count) { this.count = count; } public void setLeft(int left) { this.left = left; } public void setTop(int top) { this.top = top; } public void setWidth(int width) { this.width = width; } public void setHeight(int height) { this.height = height; } public void setModuleCode(String moduleCode) { this.moduleCode = moduleCode; } public void setModuleItem(String moduleItem) { this.moduleItem = moduleItem; } public void setId(int id) { this.id = id; } public void setZIndex(int zIndex) { this.zIndex = zIndex; } public void setWinMin(boolean winMin) { this.winMin = winMin; } public String getUserName() { return userName; } public String getTitle() { return title; } public int getCount() { return count; } public int getLeft() { return left; } public int getTop() { return top; } public int getWidth() { return width; } public int getHeight() { return height; } public String getModuleCode() { return moduleCode; } public String getModuleItem() { return moduleItem; } public int getId() { return id; } public int getZIndex() { return zIndex; } public boolean isWinMin() { return winMin; } public int getMaxZIndexOfUser(String userName) { ResultSet rs = null; String sql = "select max(zIndex) from " + tableName + " where USER_NAME=?"; Conn conn = new Conn(connname); try { PreparedStatement pstmt = conn.prepareStatement(sql); pstmt.setString(1, userName); rs = conn.executePreQuery(); if (rs != null) { if (rs.next()) { int m = rs.getInt(1); return m; } } } catch (SQLException e) { logger.error("load:" + e.getMessage()); } finally { if (conn != null) { conn.close(); conn = null; } } return 1; } public void copyToAllOtherUsersDesktop(String userName) { UserDb ud = new UserDb(); Iterator ir = ud.list().iterator(); while (ir.hasNext()) { ud = (UserDb)ir.next(); if (!ud.getName().equals(userName)) { int zIndex = getMaxZIndexOfUser(ud.getName()); UserDesktopSetupDb uds = new UserDesktopSetupDb(); uds.setUserName(ud.getName()); uds.setTitle(title); uds.setCount(count); uds.setLeft(left); uds.setTop(top); uds.setWidth(width); uds.setHeight(height); uds.setModuleCode(moduleCode); uds.setModuleItem(moduleItem); uds.setZIndex(zIndex); uds.create(); } } } public boolean create() { zIndex = getMaxZIndexOfUser(userName) + 1; Conn conn = new Conn(connname); boolean re = false; try { id = (int)SequenceManager.nextID(SequenceManager.OA_USER_DESKTOP_SETUP); PreparedStatement pstmt = conn.prepareStatement(QUERY_CREATE); pstmt.setString(1, userName); pstmt.setString(2, title); DesktopMgr dm = new DesktopMgr(); com.redmoon.oa.ui.DesktopUnit du = dm.getDesktopUnit(moduleCode); if (du.getType().equals(du.TYPE_DOCUMENT)) count = 500; pstmt.setInt(3, count); pstmt.setInt(4, left); pstmt.setInt(5, top); pstmt.setInt(6, width); pstmt.setInt(7, height); pstmt.setString(8, moduleCode); pstmt.setString(9, moduleItem); pstmt.setInt(10, id); pstmt.setInt(11, zIndex); re = conn.executePreUpdate()==1?true:false; if (re) { UserDesktopSetupCache rc = new UserDesktopSetupCache(this); rc.refreshCreate(); } } catch (SQLException e) { logger.error("create:" + e.getMessage()); } finally { if (conn != null) { conn.close(); conn = null; } } return re; } public boolean save() { Conn conn = new Conn(connname); boolean re = false; try { PreparedStatement pstmt = conn.prepareStatement(QUERY_SAVE); pstmt.setString(1, title); pstmt.setInt(2, count); pstmt.setInt(3, left); pstmt.setInt(4, top); pstmt.setInt(5, width); pstmt.setInt(6, height); pstmt.setString(7, moduleCode); pstmt.setString(8, moduleItem); pstmt.setInt(9, zIndex); pstmt.setInt(10, winMin?1:0); pstmt.setInt(11, id); re = conn.executePreUpdate()==1?true:false; if (re) { UserDesktopSetupCache rc = new UserDesktopSetupCache(this); primaryKey.setValue(new Integer(id)); rc.refreshSave(primaryKey); return true; } } catch (SQLException e) { logger.error("save:" + e.getMessage()); } finally { if (conn != null) { conn.close(); conn = null; } } return re; } public void load() { Conn conn = new Conn(connname); ResultSet rs = null; try { PreparedStatement pstmt = conn.prepareStatement(QUERY_LOAD); pstmt.setInt(1, id); rs = conn.executePreQuery(); if (rs != null) { if (rs.next()) { userName = StrUtil.getNullStr(rs.getString(1)); title = StrUtil.getNullStr(rs.getString(2)); count = rs.getInt(3); left = rs.getInt(4); top = rs.getInt(5); width = rs.getInt(6); height = rs.getInt(7); moduleCode = rs.getString(8); moduleItem = StrUtil.getNullString(rs.getString(9)); zIndex = rs.getInt(10); winMin = rs.getInt(11)==1; loaded = true; primaryKey.setValue(new Integer(id)); } } } catch (SQLException e) { logger.error("load:" + e.getMessage()); } finally { if (conn != null) { conn.close(); conn = null; } } } public boolean del() { Conn conn = new Conn(connname); boolean re = false; try { PreparedStatement pstmt = conn.prepareStatement(QUERY_DEL); pstmt.setInt(1, id); re = conn.executePreUpdate()==1?true:false; if (re) { re = conn.executePreUpdate() >= 0 ? true : false; UserDesktopSetupCache rc = new UserDesktopSetupCache(this); rc.refreshDel(primaryKey); return true; } } catch (SQLException e) { logger.error("del:" + e.getMessage()); } finally { if (conn != null) { conn.close(); conn = null; } } return re; } private String userName; private String title; private int count = 10; private int left = 0; private int top = 0; private int width = 200; private int height = 100; private String moduleCode; private String moduleItem; private int id; private int zIndex = 100; private boolean winMin = false;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?