📄 workplandb.java
字号:
ps = null; } } } catch (SQLException e) { logger.error("load: " + e.getMessage()); } finally { if (rs != null) { try { rs.close(); } catch (SQLException e) {} rs = null; } if (conn!=null) { conn.close(); conn = null; } } } public Attachment getAttachment(int attId) { Iterator ir = attachments.iterator(); while (ir.hasNext()) { Attachment at = (Attachment)ir.next(); if (at.getId()==attId) return at; } return null; } public boolean delAttachment(int attachId) { Attachment att = new Attachment(attachId); if (att==null) return false; boolean re = att.del(); WorkPlanCache rc = new WorkPlanCache(this); primaryKey.setValue(new Integer(id)); rc.refreshSave(primaryKey); return re; } public boolean save() { return false; } public boolean save(FileUpload fu) throws ErrMsgException { Conn conn = new Conn(connname); boolean re = false; try { PreparedStatement ps = conn.prepareStatement(QUERY_SAVE); ps.setString(1, title); ps.setString(2, content); ps.setString(3, DateUtil.format(beginDate, "yyyy-MM-dd HH:mm:ss")); ps.setString(4, DateUtil.format(endDate, "yyyy-MM-dd HH:mm:ss")); ps.setInt(5, typeId); ps.setString(6, remark); ps.setString(7, principal); ps.setInt(8, id); re = conn.executePreUpdate()==1?true:false; if (re) { WorkPlanCache rc = new WorkPlanCache(this); primaryKey.setValue(new Integer(id)); rc.refreshSave(primaryKey); if (ps!=null) { ps.close(); ps = null; } String sql = "delete from work_plan_user where workPlanId=?"; ps = conn.prepareStatement(sql); ps.setInt(1, id); conn.executePreUpdate(); sql = "delete from work_plan_dept where workPlanId=?"; ps = conn.prepareStatement(sql); ps.setInt(1, id); conn.executePreUpdate(); if (ps!=null) { ps.close(); ps = null; } if (users!=null) { int len = users.length; sql = "insert work_plan_user (workPlanId, userName) values (?,?)"; ps = conn.prepareStatement(sql); for (int i=0; i<len; i++) { ps.clearParameters(); ps.setInt(1, id); ps.setString(2, users[i]); conn.executePreUpdate(); } } if (ps!=null) { ps.close(); ps = null; } if (depts!=null) { int len = depts.length; sql = "insert work_plan_dept (workPlanId, deptCode) values (?,?)"; ps = conn.prepareStatement(sql); for (int i=0; i<len; i++) { ps.clearParameters(); ps.setInt(1, id); ps.setString(2, depts[i]); conn.executePreUpdate(); } } if (fu.getRet() == fu.RET_SUCCESS) { Calendar cal = Calendar.getInstance(); String year = "" + (cal.get(cal.YEAR)); String month = "" + (cal.get(cal.MONTH) + 1); com.redmoon.oa.Config cfg = new com.redmoon.oa.Config(); String vpath = cfg.get("file_workplan") + "/" + year + "/" + month + "/"; String filepath = Global.getRealPath() + vpath; fu.setSavePath(filepath); fu.writeFile(true); Vector v = fu.getFiles(); FileInfo fi = null; Iterator ir = v.iterator(); while (ir.hasNext()) { fi = (FileInfo) ir.next(); Attachment att = new Attachment(); att.setFullPath(filepath + fi.getDiskName()); att.setWorkPlanId(id); att.setName(fi.getName()); att.setDiskName(fi.getDiskName()); att.setVisualPath(vpath); re = att.create(); } } } } catch (SQLException e) { logger.error("save: " + e.getMessage()); } finally { if (conn != null) { conn.close(); conn = null; } } return re; } public ListResult listResult(String listsql, int curPage, int pageSize) throws ErrMsgException { int total = 0; ResultSet rs = null; Vector result = new Vector(); ListResult lr = new ListResult(); lr.setTotal(total); lr.setResult(result); Conn conn = new Conn(connname); try { String countsql = SQLFilter.getCountSql(listsql); rs = conn.executeQuery(countsql); if (rs != null && rs.next()) { total = rs.getInt(1); } if (rs != null) { rs.close(); rs = null; } if (total != 0) conn.setMaxRows(curPage * pageSize); rs = conn.executeQuery(listsql); if (rs == null) { return lr; } else { rs.setFetchSize(pageSize); int absoluteLocation = pageSize * (curPage - 1) + 1; if (rs.absolute(absoluteLocation) == false) { return lr; } do { WorkPlanDb wpd = getWorkPlanDb(rs.getInt(1)); result.addElement(wpd); } while (rs.next()); } } catch (SQLException e) { logger.error("listResult:" + e.getMessage()); throw new ErrMsgException("数据库出错!"); } finally { if (rs != null) { try { rs.close(); } catch (Exception e) {} rs = null; } if (conn != null) { conn.close(); conn = null; } } lr.setResult(result); lr.setTotal(total); return lr; } public Vector list(String sql) { ResultSet rs = null; Conn conn = new Conn(connname); Vector result = new Vector(); try { rs = conn.executeQuery(sql); if (rs == null) { return null; } else { while (rs.next()) { result.addElement(getWorkPlanDb(rs.getInt(1))); } } } catch (SQLException e) { logger.error("list:" + e.getMessage()); } finally { if (conn != null) { conn.close(); conn = null; } } return result; } public void setTitle(String title) { this.title = title; } public void setContent(String content) { this.content = content; } public void setBeginDate(java.util.Date beginDate) { this.beginDate = beginDate; } public void setEndDate(java.util.Date endDate) { this.endDate = endDate; } public void setTypeId(int typeId) { this.typeId = typeId; } public void setRemark(String remark) { this.remark = remark; } public void setPrincipal(String principal) { this.principal = principal; } public String[] getUsers() { return users; } public String[] getDepts() { return depts; } public Vector getAttachments() { return attachments; } public String getAuthor() { return author; } public void setUsers(String[] users) { this.users = users; } public void setDepts(String[] depts) { this.depts = depts; } public void setAttachments(Vector attachments) { this.attachments = attachments; } public void setAuthor(String author) { this.author = author; } private String title; private String content; private java.util.Date beginDate; private java.util.Date endDate; private int typeId; private String remark; private String principal; private String[] users; private String[] depts; private Vector attachments; private String author;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -