📄 deptview.java
字号:
package com.redmoon.oa.dept;import cn.js.fan.util.StrUtil;import java.util.Vector;import javax.servlet.jsp.JspWriter;import java.util.Iterator;import org.apache.log4j.Logger;import cn.js.fan.module.cms.UprightLineNode;import cn.js.fan.util.ErrMsgException;import com.redmoon.oa.Config;import com.redmoon.oa.person.UserSetupDb;import javax.servlet.http.HttpServletRequest;import com.redmoon.oa.pvg.Privilege;import com.redmoon.oa.person.UserDb;public class DeptView { Logger logger = Logger.getLogger(DeptView.class.getName()); DeptDb rootLeaf; Vector UprightLineNodes = new Vector(); public DeptView(DeptDb rootLeaf) { this.rootLeaf = rootLeaf; } public void list(JspWriter out) throws Exception { ListTree(out, rootLeaf, true); } void ListTree(JspWriter out, DeptDb leaf, boolean isLastChild) throws Exception { ShowLeaf(out, leaf, isLastChild); DeptMgr dm = new DeptMgr(); Vector children = dm.getChildren(leaf.getCode()); int size = children.size(); if (size == 0) return; int i = 0; if (size > 0) out.print("<table id='childoftable" + leaf.getCode() + "' cellspacing=0 cellpadding=0 width='100%' align=center><tr><td>"); Iterator ri = children.iterator(); while (ri.hasNext()) { i++; DeptDb childlf = (DeptDb) ri.next(); boolean isLastChild1 = true; if (size != i) isLastChild1 = false; ListTree(out, childlf, isLastChild1); } if (size > 0) out.print("</td></tr></table>"); } void ShowLeaf(JspWriter out, DeptDb leaf, boolean isLastChild) throws Exception { String code = leaf.getCode(); String name = leaf.getName(); int layer = leaf.getLayer(); String description = leaf.getDescription(); if (!isLastChild) { DeptDb brotherleaf = leaf.getBrother("down"); if (brotherleaf != null) { Vector r = new Vector(); leaf.getAllChild(r, leaf); int count = r.size(); if (count>0) { UprightLineNode uln = new UprightLineNode(layer, count); UprightLineNodes.addElement(uln); } } } int childcount = leaf.getChildCount(); String tableid = "table" + leaf.getCode(); out.println("<table id=" + tableid + " name=" + tableid + " class='tbg1' cellspacing=0 cellpadding=0 width='100%' align=center onMouseOver=\"this.className='tbg1sel'\" onMouseOut=\"this.className='tbg1'\" border=0>"); out.println(" <tbody><tr>"); out.println(" <td width='85%' height='13' align=left nowrap>"); for (int k = rootLeaf.getLayer(); k <= layer - 1; k++) { boolean isShowed = false; Iterator ir = UprightLineNodes.iterator(); while (ir.hasNext()) { UprightLineNode node = (UprightLineNode) ir.next(); if (node.getLayer() == k) { node.show(out, "images/i_plus-2.gif"); if (node.getCount() == 0) { UprightLineNodes.remove(node); } isShowed = true; break; } } if (!isShowed) out.println("<img src='' width=20 height=1>"); } if (leaf.getCode().equals(rootLeaf.getCode())) { out.println("<img onClick=\"ShowChild(this, '" + tableid + "')\" src='images/i_puls-root.gif' align='absmiddle'><img src='images/folder_01.gif' align='absmiddle'>"); } else { if (isLastChild) { if (childcount > 0) out.println("<img onClick=\"ShowChild(this, '" + tableid + "')\" src='images/i_plus2-2.gif' align='absmiddle'><img src='images/folder_01.gif' align='absmiddle'>"); else out.println("<img src='images/i_plus-2-3.gif' align='absmiddle'><img src='images/folder_01.gif' align='absmiddle'>"); } else { if (childcount > 0) out.println("<img onClick=\"ShowChild(this, '" + tableid + "')\" src='images/i_plus2-1.gif' align='absmiddle'><img src='images/folder_01.gif' align='absmiddle'>"); else out.println("<img src='images/i_plus-2-2.gif' align='absmiddle'><img src='images/folder_01.gif' align='absmiddle'>"); } } if (leaf.getType() == 2) { out.print("<a target=_parent href='dept_user.jsp?deptCode=" + StrUtil.UrlEncode(code) + "'>" + name + "</a>"); } else if (leaf.getType() == 1) out.print( "<a target=_parent href='dept_user.jsp?deptCode=" + StrUtil.UrlEncode(code) + "'>" + name + "</a>"); else if (leaf.getType() == 0) { out.print(name); } out.print(" </td><td width='15%' align=right nowrap>"); if (!leaf.getCode().equals("root")) { out.print( "<a target=dirbottomFrame href='dept_bottom.jsp?parent_code=" + StrUtil.UrlEncode(code, "utf-8") + "&parent_name=" + StrUtil.UrlEncode(name, "utf-8") + "&op=AddChild'>添子部门</a> "); out.print( "<a target='dirbottomFrame' href='dept_bottom.jsp?op=modify&code=" + StrUtil.UrlEncode(code, "utf-8") + "&name=" + StrUtil.UrlEncode(name, "utf-8") + "&description=" + StrUtil.UrlEncode(description, "utf-8") + "'>修改</a> "); out.print( "<a target=_self href=# onClick=\"if (window.confirm('您确定要删除" + name + "吗?')) window.location.href='dept_top.jsp?op=del&root_code=" + StrUtil.UrlEncode(rootLeaf.getCode()) + "&delcode=" + StrUtil.UrlEncode(code, "utf-8") + "'\">删除</a> "); out.print("<a href='dept_top.jsp?op=move&direction=up&code=" + StrUtil.UrlEncode(code, "utf-8") + "'>上移</a> "); out.print("<a href='dept_top.jsp?op=move&direction=down&code=" + StrUtil.UrlEncode(code, "utf-8") + "'>下移</a> "); } out.println(" </td></tr></tbody></table>"); } void ShowDeptAsOption(JspWriter out, DeptDb leaf, int rootlayer) throws Exception { String code = leaf.getCode(); String name = leaf.getName(); int layer = leaf.getLayer(); String blank = ""; int d = layer-rootlayer; for (int i=0; i<d; i++) { blank += " "; } if (leaf.getChildCount()>0) { out.print("<option value='" + code + "'>" + blank + "╋ " + name + "</option>"); } else { out.print("<option value=\"" + code + "\">" + blank + "├『" + name + "』</option>"); } } public String getDeptAsOption(DeptDb leaf, int rootlayer) { String outStr = ""; String code = leaf.getCode(); String name = leaf.getName(); int layer = leaf.getLayer(); String blank = ""; int d = layer-rootlayer; for (int i=0; i<d; i++) { blank += " "; } if (leaf.getChildCount()>0) { outStr += "<option value='" + code + "'>" + blank + "╋ " + name + "</option>"; } else { outStr += "<option value=\"" + code + "\">" + blank + "├『" + name + "』</option>"; } return outStr; } public String getDeptNameAsOptionValue(DeptDb leaf, int rootlayer) { String outStr = ""; String code = leaf.getCode(); String name = leaf.getName(); int layer = leaf.getLayer(); String blank = ""; int d = layer-rootlayer; for (int i=0; i<d; i++) { blank += " "; } if (leaf.getChildCount()>0) { outStr += "<option value='" + name + "'>" + blank + "╋ " + name + "</option>"; } else { outStr += "<option value=\"" + name + "\">" + blank + "├『" + name + "』</option>"; } return outStr; } public void ShowDeptAsOptions(JspWriter out, DeptDb leaf, int rootlayer) throws Exception { ShowDeptAsOption(out, leaf, rootlayer); DeptMgr dm = new DeptMgr(); Vector children = dm.getChildren(leaf.getCode()); int size = children.size(); if (size == 0) return; int i = 0; Iterator ri = children.iterator(); while (ri.hasNext()) { DeptDb childlf = (DeptDb) ri.next(); ShowDeptAsOptions(out, childlf, rootlayer); } } public StringBuffer getDeptAsOptions(StringBuffer outStr, DeptDb leaf, int rootlayer) throws ErrMsgException { outStr.append(getDeptAsOption(leaf, rootlayer)); DeptMgr dm = new DeptMgr(); Vector children = dm.getChildren(leaf.getCode()); int size = children.size(); if (size == 0) return outStr; Iterator ri = children.iterator(); while (ri.hasNext()) { DeptDb childlf = (DeptDb) ri.next(); getDeptAsOptions(outStr, childlf, rootlayer); } return outStr; } public StringBuffer getDeptNameAsOptions(StringBuffer outStr, DeptDb leaf, int rootlayer) throws ErrMsgException { outStr.append(getDeptNameAsOptionValue(leaf, rootlayer)); DeptMgr dm = new DeptMgr(); Vector children = dm.getChildren(leaf.getCode()); int size = children.size(); if (size == 0) return outStr; int i = 0; Iterator ri = children.iterator(); while (ri.hasNext()) { DeptDb childlf = (DeptDb) ri.next(); getDeptNameAsOptions(outStr, childlf, rootlayer); } return outStr; } public void ListSimple(HttpServletRequest request, JspWriter out, String target, String link, String tableClass, String tableClassMouseOn) throws Exception { Privilege privilege = new Privilege(); UserSetupDb usd = new UserSetupDb(); usd = usd.getUserSetupDb(privilege.getUser(request)); String strDepts = usd.getMessageToDept(); String[] depts = StrUtil.split(strDepts, ","); ListTreeSimple(depts, out, rootLeaf, true, target, link, tableClass, tableClassMouseOn); } void ListTreeSimple(String[] depts, JspWriter out, DeptDb leaf, boolean isLastChild, String target, String link, String tableClass, String tableClassMouseOn) throws Exception { ShowLeafSimple(depts, out, leaf, isLastChild, target, link, tableClass, tableClassMouseOn); DeptMgr dir = new DeptMgr(); Vector children = dir.getChildren(leaf.getCode()); int size = children.size(); if (size == 0) return; int i = 0; if (size > 0) out.print("<table id='childoftable" + leaf.getCode() + "' cellspacing=0 cellpadding=0 width='100%' align=center><tr><td>"); Iterator ri = children.iterator(); while (ri.hasNext()) { i++; DeptDb childlf = (DeptDb) ri.next(); boolean isLastChild1 = true; if (size != i) isLastChild1 = false; ListTreeSimple(depts, out, childlf, isLastChild1, target, link, tableClass, tableClassMouseOn); } if (size > 0) out.print("</td></tr></table>"); } void ShowLeafSimple(String[] depts, JspWriter out, DeptDb leaf, boolean isLastChild, String target, String link, String tableClass, String tableClassMouseOn) throws Exception { String code = leaf.getCode(); String name = leaf.getName(); int layer = leaf.getLayer(); if (!isLastChild) { DeptDb brotherleaf = leaf.getBrother("down"); if (brotherleaf != null) { Vector r = new Vector(); leaf.getAllChild(r, leaf); int count = r.size(); if (count>0) { UprightLineNode uln = new UprightLineNode(layer, count);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -