📄 aginitviewcount.java.svn-base
字号:
package com.fzet.cois.dividework.agents;
import java.util.Vector;
import com.fzet.cois.common.scriptLib.ErrHandle;
import lotus.domino.AgentBase;
import lotus.domino.AgentContext;
import lotus.domino.Database;
import lotus.domino.Document;
import lotus.domino.NotesException;
import lotus.domino.Session;
import lotus.domino.View;
import lotus.domino.ViewColumn;
import lotus.domino.ViewEntry;
import lotus.domino.ViewEntryCollection;
public class AgInitViewCount extends AgentBase {
public void NotesMain() {
Session session = null;
AgentContext ac = null;
Database db = null;
Document doc = null;
ErrHandle err = null;
View vwTarget = null;
ViewEntryCollection vecTarget = null;
ViewEntryCollection vecTemp = null;
ViewEntry veTarget = null;
ViewEntry veTemp = null;
ViewColumn vcColumn = null;
try {
session = getSession();
ac = session.getAgentContext();
db = ac.getCurrentDatabase();
doc = ac.getDocumentContext();
err = new ErrHandle(session,0,"","agInitViewCount");
//读取参数
String sViewName = doc.getItemValueString("ViewName");
String sSort = doc.getItemValueString("Sort");
String sStart = doc.getItemValueString("Start");
String sPageSize = doc.getItemValueString("Count");
String sIsManager = doc.getItemValueString("IsManager");
//参数有效性验证
if (sViewName == null || sViewName.equals("")) return;
if (sStart == null || sStart.equals("")) sStart = "1";
if (sPageSize == null || sPageSize.equals("")) sPageSize = "20";
if (sIsManager == null) sIsManager = "0";
//暂时不用,del by yeshq, 2006-12-26
//if (sIsManager.equals("1")) sViewName = sViewName + "_Mgr";
//定义变更
int nTotalCount = 0;
int nStart = Integer.parseInt(sStart);
int nPageSize = Integer.parseInt(sPageSize);
int nEnd = nStart + nPageSize;
int nStartColumn = -1;
StringBuffer sbResult = new StringBuffer();
Vector vColumnValues = new Vector();
Vector vColumns = new Vector();
//==========================读取视图信息,组合成显示列表======================
//打开“视图”,得到视图的文档数量
vwTarget = db.getView(sViewName);
if (vwTarget != null) {
if(sSort == null || sSort.equals("")) { //非分类视图
vecTarget = vwTarget.getAllEntries();
}else{
//当sSort不为空时,部门人员配置视图采用vwDetpUsers xinjf 2008-1-15
if(sViewName.equals("vwDeptUsersSeq")){
vwTarget = db.getView("vwDeptUsers");
}
//增加sort有多个值的处理,by yeshq, 2008/1/7
String[] aSort = sSort.split(",");
vecTarget = vwTarget.getAllEntriesByKey(aSort[0].trim(),true);
for (int j = 1; j < aSort.length; j++) {
//vecTarget = vwTarget.getAllEntriesByKey(sSort,true);
vecTemp = vwTarget.getAllEntriesByKey(aSort[j].trim(),true);
veTarget = vecTemp.getFirstEntry();
while(veTarget!=null){
vecTarget.addEntry(veTarget);
veTemp = veTarget;
veTarget = vecTemp.getNextEntry(veTarget);
veTemp.recycle();
}
}
//add end
}
nTotalCount = vecTarget.getCount();
//开始输出
vColumns = vwTarget.getColumns();
for (int i=0 ; i < vColumns.size() ; i++) {
vcColumn = (ViewColumn)vColumns.elementAt(i);
if (!vcColumn.isHidden()) {
if (nStartColumn == -1) nStartColumn = i;
sbResult.append(vcColumn.getTitle());
}
vcColumn.recycle();
}
if (nEnd > nTotalCount+1) nEnd = nTotalCount+1;
for (int i=nStart ; i < nEnd ; i++) {
veTarget = vecTarget.getNthEntry(i);
vColumnValues = veTarget.getColumnValues();
for (int j=nStartColumn ; j < vColumnValues.size(); j++) {
String sColumnValue = (String)vColumnValues.elementAt(j);
sbResult.append(sColumnValue);
}
veTemp = veTarget;
veTarget = vecTarget.getNextEntry(veTarget);
veTemp.recycle();
}
}
//将结果分布到多个BODY域中,以免域超长
int nPos = 1;
int nBody_Start = 0;
int nBody_End = nBody_Start + 10000;
int nLength = sbResult.length();
while (nBody_Start < nLength) {
if (nBody_End > nLength) nBody_End = nLength;
doc.replaceItemValue("Body" + Integer.toString(nPos),sbResult.substring(nBody_Start,nBody_End).toString());
nBody_Start += 10000;
nBody_End += 10000;
nPos += 1;
}
//=========================视图列表生成完毕==================================
//=========================计算视图的“总条目数”“总页数”“当前页码”=============
int nPageCount = nTotalCount / nPageSize;
nPos = nTotalCount % nPageSize;
if (nPos > 0) nPageCount += 1;
if (nPageCount == 0) nPageCount = 1;
int nCurPage = nStart / nPageSize;
nPos = nStart % nPageSize;
if (nPos > 1) {
nCurPage += 2;
}else{
nCurPage += 1;
}
doc.replaceItemValue("TotalCount",Integer.toString(nTotalCount));
doc.replaceItemValue("PageCount",Integer.toString(nPageCount));
doc.replaceItemValue("CurPage",Integer.toString(nCurPage));
//=========================计算完毕,接下来生成翻页的组合框=========================
String sListBoxValue = null;
sListBoxValue = "<select onchange=\"fnGotoPage(this.value);\">";
for (int i=1 ; i <= nPageCount ; i++) {
if (i == nCurPage) {
sListBoxValue += "<option value=\"" + Integer.toString(i) + "\" selected>" + Integer.toString(i) + "</option>";
}else{
sListBoxValue += "<option value=\"" + Integer.toString(i) + "\">" + Integer.toString(i) + "</option>";
}
}
sListBoxValue += "</select>";
//将结果分布到多个ListBoxValue域中,以免域超长
nPos = 1;
nBody_Start = 0;
nBody_End = nBody_Start + 10000;
nLength = sListBoxValue.length();
while (nBody_Start < nLength) {
if (nBody_End > nLength) nBody_End = nLength;
doc.replaceItemValue("ListBoxValue" + Integer.toString(nPos),sListBoxValue.substring(nBody_Start,nBody_End).toString());
nBody_Start += 10000;
nBody_End += 10000;
nPos += 1;
}
//=============完成所有操作=================================
} catch(NotesException e) {
err.record(true,e.id,e.text);
e.printStackTrace();
} catch(Exception e) {
e.printStackTrace();
} finally {
try {
if (vcColumn != null) vcColumn.recycle();
if (veTemp != null ) veTemp.recycle();
if (veTarget != null) veTarget.recycle();
if (vecTarget != null) vecTarget.recycle();
if (vwTarget != null) vwTarget.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();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -