|
发表于 2010-8-25 14:57:40
|
显示全部楼层
单元的代码:
unit SelectPerson;
interface
uses
Business.System, Business.Forms, Business.Model.Org, Business.Model, Business.Data;
type
TSelectPerson = class(TForm)
OrgTreeView: TOrgTreeView;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
BitBtn4: TBitBtn;
BitBtn5: TBitBtn;
BitBtn6: TBitBtn;
OrgListView: TOrgListView;
EditSearch: TEdit;
btnSearch: TSpeedButton;
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
procedure BitBtn4Click(Sender: TObject);
procedure BizFormCreate(Sender: TObject);
procedure btnSearchClick(Sender: TObject);
procedure EditSearchKeyPress(Sender: TObject; var Key: Char);
procedure BizFormShow(Sender: TObject);
private
{private declarations}
lDeptID: string;
procedure setDeptID(value: string);
function GetIDResultList: TStringList;
function GetNameResultList: TStringList;
procedure SetIDResultList(Value: TStringList);
public
{public declarations}
constructor Create(aDeptID:string); overload;
property DeptID:string read lDeptID write setDeptID;
property IDResultList: TStringList read GetIDResultList write SetIDResultList;
property NameResultList: TStringList read GetNameResultList;
end;
implementation
procedure TSelectPerson.setDeptID(value: string);
var
lUrl: TBizUrl;
begin
// lUrl:= TBizUrl.Create;
try
if value <> lDeptID then
begin
lDeptID:= Value;
lUrl:= OrgSys.OrgSystem.GetURL(DeptID,'','');
OrgTreeView.StartWithNodes.Clear;
OrgTreeView.AddStartWith(lUrl.URL);
OrgTreeView.ReloadTree;
end;
finally
// lUrl.Free;
end;
end;
constructor TSelectPerson.Create(aDeptID:string);
begin
inherited create(Context);
DeptID:= aDeptID;
end;
procedure TSelectPerson.BitBtn1Click(Sender: TObject);
var
lExpr: string;
begin
OrgListView.BizURLs.Clear;
lExpr:='OrgKey('''+ DeptID + ''','''','''')';
lExpr:= 'OrgChildren(' + lExpr + ',OrgCondition(''*.psm'','''',''''),true)';
OrgSys.OrgSystem.GetBizURLsByOrgExpr(lExpr,OrgListView.BizURLs);
end;
procedure TSelectPerson.BitBtn2Click(Sender: TObject);
var
lOrgUnit: TOrgUnit;
lExpr: string;
sl: TStrings;
lBizUrl: TBizUrl;
i:integer;
begin
if OrgTreeView.SelectionCount = 0 then Exit;
sl:= TStringList.Create;
lBizUrl:= TBizUrl.Create;
try
sl.Clear;
lBizUrl.URL:= TOrgNode(OrgTreeView.SelectedNode).ObjectID;
lOrgUnit:= OrgSys.OrgSystem.GetUnit(lBizUrl);
case TBizObjectKind(lOrgUnit.OrgKind) of
TBizObjectKind.boOrgan: //华大电子
begin
lExpr:= 'OrgChildren(OrgSelect(OrgCondition(''*.OGN'', isplayName=''' + lOrgUnit.DisplayName +''','''')),OrgCondition(''*.PSM'','''',''''),True,False)';;
OrgSys.OrgSystem.GetBizURLsByOrgExpr(lExpr,sl);
end;
TBizObjectKind.boDept: //选中部门
begin
lExpr:='OrgKey('''+ lOrgUnit.ID + ''','''','''')';
lExpr:= 'OrgChildren(' + lExpr + ',OrgCondition(''*.psm'','''',''''),true)';
OrgSys.OrgSystem.GetBizURLsByOrgExpr(lExpr,sl);
end;
TBizObjectKind.boPositionMember: //选中岗位
begin
lExpr:='OrgKey('''+ lOrgUnit.Parent.ID +''','''+ lOrgUnit.ID + ''','''')';
lExpr:= 'OrgChildren(' + lExpr + ',OrgCondition(''*.psm'','''',''''),true)';
OrgSys.OrgSystem.GetBizURLsByOrgExpr(lExpr,sl);
end;
TBizObjectKind.boPersonMember: //选中人员
begin
sl.Add(TOrgNode(OrgTreeView.SelectedNode).ObjectID);
end;
end; //case
for i:=0 to sl.Count-1 do
begin
if OrgListView.BizURLs.IndexOf(sl.Strings)< 0 then
OrgListView.BizURLs.Add(sl.Strings);
end;
finally
sl.Free;
lBizUrl.Free;
end;
end;
procedure TSelectPerson.BitBtn3Click(Sender: TObject);
begin
OrgListView.BizURLs.Clear;
end;
procedure TSelectPerson.BitBtn4Click(Sender: TObject);
begin
// JsDialogs.ShowMsg(OrgListView.SelectedNode.BizURL.URL,'');
if OrgListView.SelCount=0 then Exit;
OrgListView.BizURLs.Delete(OrgListView.BizURLs.IndexOf(OrgListView.SelectedNode.BizURL.URL));
end;
function TSelectPerson.GetIDResultList: TStringList;
var
i: integer;
lOrgUnit: TOrgUnit;
lBizUrl: TBizUrl;
begin
result:= TStringList.Create;
result.Clear;
if OrgListView.BizURLs.Count = 0 then Exit;
lBizUrl:= TBizUrl.Create;
try
for i:=0 to OrgListView.BizURLs.Count - 1 do
begin
lBizUrl.URL:= OrgListView.BizURLs.Strings;
lOrgUnit:= OrgSys.OrgSystem.GetUnit(lBizUrl);
result.Add(lOrgUnit.ID);
end;
finally
lBizUrl.Free;
end;
end;
function TSelectPerson.GetNameResultList: TStringList;
var
i: integer;
lOrgUnit: TOrgUnit;
lBizUrl: TBizUrl;
begin
result:= TStringList.Create;
result.Clear;
if OrgListView.BizURLs.Count = 0 then Exit;
lBizUrl:= TBizUrl.Create;
try
for i:=0 to OrgListView.BizURLs.Count - 1 do
begin
lBizUrl.URL:= OrgListView.BizURLs.Strings;
lOrgUnit:= OrgSys.OrgSystem.GetUnit(lBizUrl);
result.Add(lOrgUnit.DisplayName);
end;
finally
lBizUrl.Free;
end;
end;
procedure TSelectPerson.SetIDResultList(Value: TStringList);
var
i: integer;
PersonList: TStrings;
s: string;
const
// lExpr = 'OrgChildren(OrgKey('''', '''', ''%s'') , OrgCondition(''*.psm'', '''', ''''), True, False)';
lExpr = 'OrgCondition(''%s.psm'', '''', '''')';
begin
// JsDialogs.ShowMsg(value.Text,'设置值');
PersonList:= TStringList.Create;
try
OrgListView.BizURLs.Clear;
for i:=0 to Value.Count-1 do
begin
s:= SysUtils.Format(lExpr,[Value.Strings]);
PersonList.Clear;
OrgSys.OrgSystem.GetBizURLsByOrgExpr(s,PersonList);
if PersonList.Count > 0 then
OrgListView.BizURLs.Add(PersonList.Strings[0]);
end;
finally
PersonList.Free;
end;
end;
procedure TSelectPerson.BizFormCreate(Sender: TObject);
begin
OrgTreeView.StartWithNodes.Clear;
OrgTreeView.AddStartWith('Org:\ROOT\HED.ogn');
OrgTreeView.ReloadTree;
OrgTreeView.Items[0].Expand(False);
end;
procedure TSelectPerson.btnSearchClick(Sender: TObject);
var
// i: integer;
PersonList: TStrings;
s: string;
const
lExpr = 'OrgCondition(''%s.psm'', '''', '''')';
begin
if SysUtils.Trim(EditSearch.Text) = '' then
begin
BizFormCreate(nil);
end
else
begin
PersonList:= TStringList.Create;
try
s:= SysUtils.Format(lExpr,[EditSearch.text]);
PersonList.Clear;
OrgSys.OrgSystem.GetBizURLsByOrgExpr(s,PersonList);
if PersonList.Count > 0 then
begin
OrgTreeView.StartWithNodes.Clear;
OrgTreeView.AddStartWith(PersonList.Strings[0]);
OrgTreeView.ReloadTree;
OrgTreeView.Items[0].Expand(False);
end
else
begin
OrgTreeView.Clear;
end;
finally
PersonList.Free;
end;
end;
end;
procedure TSelectPerson.EditSearchKeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
BtnSearch.Click;
end;
procedure TSelectPerson.BizFormShow(Sender: TObject);
begin
if IDResultList.Count>0 then
SetIDResultList(IDResultList);
end;
end. |
|