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

📄 aglocatecurrentdept.java.svn-base

📁 一个包含排班信息的模块 2.1. 最新排班 6 2.2. 所有排班 6 2.3. 日常排班统计 7 2.4. 排班管理 7 2.5. 班次配置 7 2.6. 部门人员配置 7
💻 SVN-BASE
字号:
/*
 名称:定位当前部门并打开当前部门代理
 作用:根据传入的部门名称,打开该部门文件夹
 @author yeshq
 @version 2007-10-22
 参数:
 sDeptName    部门名称

 返回值:
 Case 1:
 <Return>0</Return>
 Case 1:
 <Return>1</Return>
 <Content>
 <Item>
 <AreaName>部门文档UNID</AreaName>
 <DeptName>部门名称</DeptName>
 </Item>

 </Content>
 */
package com.fzet.cois.dividework.agents;

import lotus.domino.*;

import java.io.*;
import com.fzet.cois.common.scriptLib.*;

import lotus.domino.AgentBase;

public class AgLocateCurrentDept extends AgentBase {
    Session session = null;

    Database db = null;

    Database dbMain = null; // 配置中心数据库

    Document doc = null;

    int nCount = 0; // 计数器,用于为各个折叠式元素命名,所有的折叠式元素都以UNID命名

    View vwDept = null; // 部门取值视图

    StringBuffer sbResult = new StringBuffer(); // 返回值

    public void NotesMain() {

	AgentContext ac = null;
	PrintWriter pw = null;
	ErrHandle err = null;

	DocumentCollection dc = null;
	Document docDept = null;

	try {
	    session = getSession();
	    ac = session.getAgentContext();
	    db = ac.getCurrentDatabase();
	    doc = ac.getDocumentContext();
	    pw = getAgentOutput();
	    dbMain = Common.getMainDb(session);
	    err = new ErrHandle(session, 0, "", "agLocateCurrentDept.xml");
	    // 首先打开“部门取值视图”,如果打不开,后面的代码就无法执行,只好退出
	    vwDept = dbMain.getView("vwDeptByAllDept");
	    if (vwDept == null) {
		Common.returnXML(pw, "<root><Return>0</Return><Error>无法打开部门取值视图。</Error></root>");
		return;
	    }
	    // 提取查询参数
	    String sQuery = doc.getItemValueString("Query_String_Decoded");
	    String sDeptName = Common.parseParameter(sQuery, "DeptName");

	    // 如果部门名称为空,则返回错误信息
	    if (sDeptName == null || sDeptName.equals("") || sDeptName.equals("/")) {
		Common.returnXML(pw, "<root><Return>0</Return><Error>无效的部门名称。</Error></root>");
		return;
	    }
	    // 返回XML头
	    sbResult.append("<root><Return>1</Return><Content>");
	    // 先返回本部门的UNID
	    sbResult.append("<Item><AreaName>").append(findDeptUNID(sDeptName)).append("</AreaName>");
	    sbResult.append("<DeptName>").append(sDeptName).append("</DeptName></Item>");

	    // 返回上级部门的UNID
	    sbResult.append(addDeptUNID(sDeptName));
	    // 返回xml结束符
	    sbResult.append("</Content></root>");

	    Common.returnXML(pw, sbResult.toString());

	} catch (Exception e) {
	    err.record(false, 0, e.toString());
	    e.printStackTrace();
	    Common.returnXML(pw, "<root><Return>0</Return><Error>" + e.toString() + "</Error></root>");
	} finally {
	    try {

		if (docDept != null)
		    docDept.recycle();
		if (dc != null)
		    dc.recycle();
		if (vwDept != null)
		    vwDept.recycle();
		if (doc != null)
		    doc.recycle();
		if (db != null)
		    db.recycle();
		if (ac != null)
		    ac.recycle();
		if (session != null)
		    session.recycle();
	    } catch (Exception e) {
		e.printStackTrace();
	    }
	}
    }

    // 增加部门UNID和部门名函数
    // 参数说明:sDeptName|部门名称
    // 返回,正确:部门UNID和部门名XML;错误:空
    public String addDeptUNID(String sDeptName) {
	ErrHandle err = null; // 错误处理
	String sResult = null; // 函数返回值
	try {
	    err = new ErrHandle(session, 0, "", "AgLocateCurrentDept.addDeptUNID()");

	    // 调用“查找父部门”函数,返回值为一字符串
	    String sParentDeptName;
	    sParentDeptName = getParentDeptName(sDeptName);

	    sResult = "";
	    // 循环调用getParentDeptName得到上级部门名,如果没有上级部门,则返回空值
	    while (!sParentDeptName.equals("")) {
		sResult += "<Item><AreaName>" + findDeptUNID(sParentDeptName) + "</AreaName>";
		sResult += "<DeptName>" + sParentDeptName + "</DeptName></Item>";
		sParentDeptName = getParentDeptName(sParentDeptName);
	    }
	    return sResult;
	} catch (Exception e) {
	    err.record(true, 0, e.toString());
	    e.printStackTrace();
	    return ""; // 如果出错,返回空值
	}
    }

    // 查找部门UNID函数,根据传入的“部门名称”,查找其UNID
    public String findDeptUNID(String sDeptName) {
	ErrHandle err = null; // 错误处理
	String sResult = null; // 函数返回值	
	Document docDept = null;
	ViewEntryCollection vecDept = null;
	ViewEntry veDept = null;
	ViewEntry veTemp = null;
	try {
	    err = new ErrHandle(session, 0, "", "agCreateDeptTree.findSubDept()");
	    sResult = "";
	    // 以“部门名称”为关键字,在“部门管理视图”中查找部门文档UNID
	    vecDept = vwDept.getAllEntriesByKey(sDeptName, true);
	    veDept = vecDept.getFirstEntry();
	    if (veDept != null) {
		docDept = veDept.getDocument();
		sResult = docDept.getUniversalID();
		docDept.recycle();
	    }
	    return sResult;
	} catch (NotesException e) {
	    err.record(true, e.id, e.text);
	    e.printStackTrace();
	    return sResult;
	} catch (Exception e) {
	    e.printStackTrace();
	    return sResult;
	} finally {
	    try {
		// 最后释放dcDept,docDept对象所占用的资源
		if (docDept != null)
		    docDept.recycle();
		if (veTemp != null)
		    veTemp.recycle();
		if (veDept != null)
		    veDept.recycle();
		if (vecDept != null)
		    vecDept.recycle();
	    } catch (Exception e) {
		e.printStackTrace();
	    }
	}
    }

    // 获取当前部门的上级部门
    public String getParentDeptName(String sDeptName) {
	int nPos = sDeptName.indexOf("/");
	String sParentDeptName;
	if (nPos <= 0)
	    sParentDeptName = "";
	else
	    sParentDeptName = sDeptName.substring(nPos + 1, sDeptName.length());
	return sParentDeptName;
    }
}

⌨️ 快捷键说明

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