unit BranchService; interface uses SysUtils, StrUtils, Classes, RealICQContacterTreeView, BaseService, ComCtrls, RealICQModel; type TBranchService = class(TBaseService) private FServers: TStringList; FSelfUnit: TStringList; FOnGettedSelfUnitEvent: TNotifyEvent; FOnGettedBranchsEvent: TNotifyEvent; procedure OnGettedSelfUnit(AData: TObject); procedure ClearSelfUnit; procedure UpdateOrAddTreeView(ABranchs: TStringList; ATreeView: TRealICQContacterTreeView); procedure GetUsersCount(ABranchInfo: TRealICQBranchInfo; var OnlineCount, TotalCount: Integer); constructor Create; public destructor Destroy; override; class function GetBranchService: TBranchService; procedure Init; procedure Uninstall; function GetBranchs(AServerID: string): TStringList; overload; function GetBranchs: TStringList; overload; function GetSelfUnit: TStringList; function RequestBranchs(AServerID: string): TStringList; overload; function RequestBranchs(AServerID, AParentBranch: string): TStringList; overload; function RequestBranchs: TStringList; overload; function RequestSelfUnit: TStringList; property OnGettedBranchsEvent: TNotifyEvent read FOnGettedBranchsEvent write FOnGettedBranchsEvent; property OnGettedSelfUnitEvent: TNotifyEvent read FOnGettedSelfUnitEvent write FOnGettedSelfUnitEvent; end; implementation uses UsersService, MainFrm; var ABranchService: TBranchService; { TBranchService } function TBranchService.GetBranchs(AServerID: string): TStringList; begin end; procedure TBranchService.ClearSelfUnit; var obj: TObject; begin while FSelfUnit.Count <> 0 do begin obj := FSelfUnit.Objects[0]; FSelfUnit.Delete(0); FreeAndNil(obj); end; end; constructor TBranchService.Create; begin inherited Create; FSelfUnit := TStringList.Create; end; destructor TBranchService.Destroy; begin ClearSelfUnit; FreeAndNil(FSelfUnit); inherited; end; function TBranchService.GetBranchs: TStringList; begin end; class function TBranchService.GetBranchService: TBranchService; begin if ABranchService = nil then ABranchService := TBranchService.Create; Result := ABranchService; end; function TBranchService.GetSelfUnit: TStringList; begin end; procedure TBranchService.OnGettedSelfUnit(AData: TObject); var ABranchs: TStringList; iLoop: Integer; ATreeView: TRealICQContacterTreeView; begin if AData = nil then Exit; ABranchs := AData as TStringList; ClearSelfUnit; for iLoop := 0 to ABranchs.Count - 1 do FSelfUnit.AddObject(ABranchs[iLoop], (ABranchs.Objects[iLoop] as TRealICQBranchInfo).Clone); ATreeView := GetTreeView(LVMyContacters); if ATreeView <> nil then UpdateOrAddTreeView(FSelfUnit, ATreeView); TUsersService.GetUsersService.RequestCompany(MainForm.RealICQClient); TUsersService.GetUsersService.RequestFriends(MainForm.RealICQClient); end; function TBranchService.RequestBranchs(AServerID: string): TStringList; begin end; function TBranchService.RequestBranchs: TStringList; begin end; function TBranchService.RequestBranchs(AServerID, AParentBranch: string): TStringList; begin end; function TBranchService.RequestSelfUnit: TStringList; begin MainForm.RealICQClient.SendGetBranchList; end; //-----计算某个部门的总上线人数和总用户数----------------------------------- procedure TBranchService.GetUsersCount(ABranchInfo: TRealICQBranchInfo; var OnlineCount, TotalCount: Integer); var iLoop:Integer; TmpBranchInfo: TRealICQBranchInfo; begin OnlineCount := OnlineCount + ABranchInfo.OnlineEmployee; TotalCount := TotalCount + ABranchInfo.EmployeeCount; for iLoop:= 0 to FSelfUnit.Count - 1 do begin TmpBranchInfo := FSelfUnit.Objects[iLoop] as TRealICQBranchInfo; if TmpBranchInfo.ParentID = ABranchInfo.ID then GetUsersCount(TmpBranchInfo, OnlineCount, TotalCount); end; end; procedure TBranchService.Init; begin Uninstall; MainForm.RealICQClient.OnGettedBranchs := OnGettedSelfUnit; MainForm.RealICQClient.SendGetBranchList; end; procedure TBranchService.Uninstall; begin MainForm.RealICQClient.OnGettedBranchs := nil; ClearStringList(FSelfUnit); end; procedure TBranchService.UpdateOrAddTreeView(ABranchs: TStringList; ATreeView: TRealICQContacterTreeView); var iLoop: Integer; OnlineEmployee,EmployeeCount:Integer; BranchInfo: TRealICQBranchInfo; Branch: TRealICQBranch; ParentNode:TTreeNode; begin // ATreeView.OnHeadImageMouseEnter := NodeOnHeadImageMouseEnter; // ATreeView.OnHeadImageMouseLeave := NodeOnHeadImageMouseLeave; ATreeView.AdjustPosition :=False; ATreeView.HideSystemScrollBar; ATreeView.BeginUpdate; try {$region '添加部门'} for iLoop := 0 to FSelfUnit.Count - 1 do begin BranchInfo := FSelfUnit.Objects[iLoop] as TRealICQBranchInfo; if (ATreeView.BranchItems.IndexOf(BranchInfo.ID)) >= 0 then Continue; OnlineEmployee:=0; EmployeeCount:=0; GetUsersCount(BranchInfo, OnlineEmployee, EmployeeCount); Branch := TRealICQBranch.Create(BranchInfo.BranchName); Branch.BranchID := BranchInfo.ID; Branch.ParentID := BranchInfo.ParentID; Branch.IsGetUserList:=False; Branch.OnlineEmployee:=OnlineEmployee; Branch.EmployeeCount:=EmployeeCount; ATreeView.AddBranch(Branch); end; ATreeView.ReAlignBranchs; {$endregion} finally ATreeView.EndUpdate; end; end; initialization finalization if ABranchService <> nil then FreeAndNil(ABranchService); end.