/*动态创建一棵组织机构树
**QEP_TreeViewOnExpand 结点展开之前访问数据库，获取该结点下的组织机构和用户。
**init() 初始化一棵组织机构树，获取最顶层组织机构信息，及无父结点的组织机构。
*/
function DBOrgInsTreeinit()
{
  new Query("Query1");
  Query1.MaxRows=-1;
  Query1.DataObject='test3';
  Query1.MaxRows=-1;
  Query1.Open();
  Query1.AutoControl = false;
  new TreeView("TreeView1");
  TreeView1.SelectImage='../jcl/image/openfoldericon.gif';;
  TreeView1.Image='../jcl/image/foldericon.gif';
  TreeView1.Items.Clear();
  for(var i=0;i<Query1.RecordCount;i++){
	n1 = new TreeNode();
    n1.Text.innerHTML=Query1.Fields.Field["NAME"].Value;
	n1.NAME = Query1.Fields.Field["NAME"].Value;
	n1.DEPTID = Query1.Fields.Field["DEPTID"].Value;
    TreeView1.Items.AddChild(n1);
	Query1.Next();
  }
  TreeView1.OnExpand=DBOrgInsTree_TreeViewOnExpand;
  TreeView1.Expanded = true;
 }
 
 
function DBOrgInsTree_TreeViewOnExpand(sender,node){
  new Query("Query1");
  Query1.MaxRows=-1;
  Query1.DataObject='test2';
  Query1.Params.Clear();
  var id = node.DEPTID;
  Query1.Params.Add(new Param('PARENTDEPT',id,'String'));
  Query1.MaxRows=-1;
  Query1.Open();
  Query1.AutoControl = false;
  node.Items.Clear();
  for(var i=0;i<Query1.RecordCount;i++){
	n1 = new TreeNode();
    n1.Text.innerHTML=Query1.Fields.Field["NAME"].Value;
	n1.DEPTID = Query1.Fields.Field["DEPTID"].Value;
	node.Items.AddChild(n1);
	Query1.Next();
  }
  Query1.AutoControl = true;
  new Query("Query2");
  Query2.MaxRows=-1;
  Query2.DataObject = 'test';
  Query2.Params.Clear();
  var id = node.DEPTID;
  Query2.Params.Add(new Param('DEPTID',id,'String'));
  Query2.MaxRows=-1;
  Query2.Open();
  Query2.AutoControl = false;
    for(var i=0;i<Query2.RecordCount;i++){
	n2 = new TreeNode();
    n2.Text.innerHTML=Query2.Fields.Field["NAME"].Value;
	n2.NAME = Query2.Fields.Field["NAME"].Value;
	node.Items.AddChild(n2);
	Query2.Next();
  }
  return node.NAME;
}
