建立一个树形组织机构的简单实现
建立一个树形组织机构的简单实现
如需Notes数据库,请联系:yangfanhaohai@msn.com
(1)建立表单:员工|FormEmp
域:
员工姓名:EmpName
所属机构:UnitName 机构名称格式:集团公司/北京分公司/昌平办事处
(2)建立视图: 树型结构|ViewTree
列:
机构:分类列:@ReplaceSubstring ( UnitName ; "/" ; "\\" )
姓名:EmpName
(3)建立代理:Org
A、声明
B、Initialize 事件
C、函数:FormatEntry
D、函数:FormatHtml
E、函数:PrintCss
F、函数:PrintJs
--------------------------------------------------------
Dim session As NotesSession
Dim db As NotesDatabase
Dim note As NotesDocument
Dim ViewTree As NotesView
-------------------------------------------------------
Sub Initialize
Set session = New NotesSession
Set db = session.CurrentDatabase
Set note = session.DocumentContext
Set ViewTree = db.GetView ( "ViewTree" )
Print ""
Call PrintCss()
Call PrintJs()
Dim Nav As NotesViewNavigator
Set Nav = ViewTree.CreateViewNav()
Dim Entry As NotesViewEntry
Set Entry = Nav.GetFirst
While Not Entry Is Nothing
Call FormatEntry(Entry,1)
Set Entry = nav.GetNextSibling(Entry)
Wend
End Sub
--------------------------------------------------------------------------------
Function FormatEntry(Entry As NotesViewEntry,display As Integer) As String
%REM
参数说明: display:样式表控制,是否显示
%ENDREM
On Error Goto errhandle
Dim StrTemp As String
Dim StrValue As String
Dim StrImg As String
Dim HtmlAttr As String
Dim Style As String
If display = 1 Then
Style = "display:block;"
Else
Style = "display:none;"
End If
If Entry.ChildCount > 0 Then
StrImg = "<img src=plus.gif align=middle class=Category>"
'StrValue = Cstr(Entry.ColumnValues(Entry.IndentLevel))
StrValue = Entry.ColumnValues(0)
HtmlAttr = "id=" + StrValue + " class=Category"
StrTemp = StrImg + FormatHtml( StrValue,"span",HtmlAttr )
Dim Nav As NotesViewNavigator
Dim EntryChild As NotesViewEntry
'Set Nav = ViewPerson.CreateViewNavFromChildren(Entry)
Set Nav = ViewTree.CreateViewNavFromDescendants(Entry)
Set EntryChild = Nav.GetFirst
Print "<ul class=Collapse style=" + Style + ">" + StrTemp
While Not EntryChild Is Nothing
Call FormatEntry(EntryChild,0)
Set EntryChild = Nav.GetNextSibling(EntryChild)
Wend
Print "</ul>"
Else
StrImg = "<img src=Person.gif align=middle class=imgPerson>"
'StrTemp = Cstr(Entry.ColumnValues(Ubound(Entry.ColumnValues)))
StrTemp = Cstr(Entry.ColumnValues(1))
HtmlAttr = "id=" + StrTemp + " class=Person"
StrTemp = StrImg + FormatHtml( StrTemp,"span",HtmlAttr)
Print FormatHtml(StrTemp,"ul","class=Collapse style=" + Style)
End If
Exit Function
errhandle:
Print Cstr(Erl) + ":" + Cstr(Err) + ":" + Error
Exit Function
End Function
------------------------------------------------------------------------------------
Function FormatHtml(Param As String,HtmlElement As String,Attr As String) As String
REM 封装数据为Html格式
REM 说明:Param:要格式化的数据;HtmlElement:格式符(TD,TR,Table等);Attr:属性(Colspan=3等);
FormatHtml = "<" + HtmlElement + " " + Attr + ">" + Param + "</" + HtmlElement + ">"
End Function
-------------------------------------------------------------------------------------
Sub PrintCss()
Print|
<style>
UL {
/*border : 1px solid red;*/
margin-left : 20px;
margin-bottom : 0;
margin-top : 2px;
}
Body {
font-size : 78%;
margin : 0;
}
img {
margin-right : 8px;
margin-left : 0;
}
.category {
font-weight : bold;
cursor : hand;
}
.Person {
cursor : hand;
}
</style>
|
End Sub
------------------------------------------------------------------------------
Sub PrintJS()
Print |
<script language = javascript>
function onClickBody() {
var src = event.srcElement;
if ( src.className == "Person" ) {
SetSelectPerson(src.id);
}
if ( src.className == "Category" ) {
var srcUL = src.parentElement;
if ( srcUL.className != "Collapse" ) {
var srcChildren = srcUL.children;
for ( var i = 0 ; i < srcChildren.length ; i ++ ) {
if ( srcChildren[i].tagName == "UL" ) {
srcChildren[i].style.display ="none";
}
}
var srcImg = srcUL.getElementsByTagName("IMG");
srcImg[0].src = "plus.gif";
srcUL.className = "Collapse";
} else {
var srcChildren = srcUL.children;
for ( var i = 0 ; i < srcChildren.length ; i ++ ) {
if ( srcChildren[i].tagName == "UL" )
srcChildren[i].style.display ="block";
}
var srcImg = srcUL.getElementsByTagName("IMG");
srcImg[0].src = "minus.gif";
srcUL.className = "Expand";
}
}
}
function SetSelectPerson(person) {
var Item = window.parent.document.all.item("SelectPerson");
var tmpPersons = GetList(Item);
var flag = false;
for ( var j = 0 ; j < tmpPersons.length ; j++ ){
var tmpPerson = tmpPersons[j];
if (person == tmpPerson) {
flag = true;
break;
}
}
if ( !flag ) {
if ( parent.document.all.item("IsSingle").value != "1" ){
Item.options[Item.options.length] = new Option(person,person);
} else {
Item.options[0] = new Option(person,person);
}
}
}
function GetList(Item) {
var fldList = Item;
var selects = new Array();
for ( var i = 0; i < fldList.options.length; i++ ) {
selects.push(fldList.options[i].value);
}
return selects;
}
</script>
<Body onClick = "onClickBody()"; >
|
End Sub
(4)测试:
建立两条记录:
张三: 集团公司/北京分公司/昌平办事处
李四:集团公司/上海分公司
在浏览器下输入: /WebDbName/tree.nsf/org?OpenAgent