BranchService.pas 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. unit BranchService;
  2. interface
  3. uses
  4. SysUtils, StrUtils, Classes, RealICQContacterTreeView, BaseService, ComCtrls,
  5. RealICQModel;
  6. type
  7. TBranchService = class(TBaseService)
  8. private
  9. FServers: TStringList;
  10. FSelfUnit: TStringList;
  11. FOnGettedSelfUnitEvent: TNotifyEvent;
  12. FOnGettedBranchsEvent: TNotifyEvent;
  13. procedure OnGettedSelfUnit(AData: TObject);
  14. procedure ClearSelfUnit;
  15. procedure UpdateOrAddTreeView(ABranchs: TStringList;
  16. ATreeView: TRealICQContacterTreeView);
  17. procedure GetUsersCount(ABranchInfo: TRealICQBranchInfo; var OnlineCount,
  18. TotalCount: Integer);
  19. constructor Create;
  20. public
  21. destructor Destroy; override;
  22. class function GetBranchService: TBranchService;
  23. procedure Init;
  24. procedure Uninstall;
  25. function GetBranchs(AServerID: string): TStringList; overload;
  26. function GetBranchs: TStringList; overload;
  27. function GetSelfUnit: TStringList;
  28. function RequestBranchs(AServerID: string): TStringList; overload;
  29. function RequestBranchs(AServerID, AParentBranch: string): TStringList; overload;
  30. function RequestBranchs: TStringList; overload;
  31. function RequestSelfUnit: TStringList;
  32. property OnGettedBranchsEvent: TNotifyEvent read FOnGettedBranchsEvent write FOnGettedBranchsEvent;
  33. property OnGettedSelfUnitEvent: TNotifyEvent read FOnGettedSelfUnitEvent write FOnGettedSelfUnitEvent;
  34. end;
  35. implementation
  36. uses
  37. UsersService, MainFrm;
  38. var
  39. ABranchService: TBranchService;
  40. { TBranchService }
  41. function TBranchService.GetBranchs(AServerID: string): TStringList;
  42. begin
  43. end;
  44. procedure TBranchService.ClearSelfUnit;
  45. var
  46. obj: TObject;
  47. begin
  48. while FSelfUnit.Count <> 0 do
  49. begin
  50. obj := FSelfUnit.Objects[0];
  51. FSelfUnit.Delete(0);
  52. FreeAndNil(obj);
  53. end;
  54. end;
  55. constructor TBranchService.Create;
  56. begin
  57. inherited Create;
  58. FSelfUnit := TStringList.Create;
  59. end;
  60. destructor TBranchService.Destroy;
  61. begin
  62. ClearSelfUnit;
  63. FreeAndNil(FSelfUnit);
  64. inherited;
  65. end;
  66. function TBranchService.GetBranchs: TStringList;
  67. begin
  68. end;
  69. class function TBranchService.GetBranchService: TBranchService;
  70. begin
  71. if ABranchService = nil then
  72. ABranchService := TBranchService.Create;
  73. Result := ABranchService;
  74. end;
  75. function TBranchService.GetSelfUnit: TStringList;
  76. begin
  77. end;
  78. procedure TBranchService.OnGettedSelfUnit(AData: TObject);
  79. var
  80. ABranchs: TStringList;
  81. iLoop: Integer;
  82. ATreeView: TRealICQContacterTreeView;
  83. begin
  84. if AData = nil then
  85. Exit;
  86. ABranchs := AData as TStringList;
  87. ClearSelfUnit;
  88. for iLoop := 0 to ABranchs.Count - 1 do
  89. FSelfUnit.AddObject(ABranchs[iLoop], (ABranchs.Objects[iLoop] as TRealICQBranchInfo).Clone);
  90. ATreeView := GetTreeView(LVMyContacters);
  91. if ATreeView <> nil then
  92. UpdateOrAddTreeView(FSelfUnit, ATreeView);
  93. TUsersService.GetUsersService.RequestCompany(MainForm.RealICQClient);
  94. TUsersService.GetUsersService.RequestFriends(MainForm.RealICQClient);
  95. end;
  96. function TBranchService.RequestBranchs(AServerID: string): TStringList;
  97. begin
  98. end;
  99. function TBranchService.RequestBranchs: TStringList;
  100. begin
  101. end;
  102. function TBranchService.RequestBranchs(AServerID,
  103. AParentBranch: string): TStringList;
  104. begin
  105. end;
  106. function TBranchService.RequestSelfUnit: TStringList;
  107. begin
  108. MainForm.RealICQClient.SendGetBranchList;
  109. end;
  110. //-----计算某个部门的总上线人数和总用户数-----------------------------------
  111. procedure TBranchService.GetUsersCount(ABranchInfo: TRealICQBranchInfo;
  112. var OnlineCount, TotalCount: Integer);
  113. var
  114. iLoop:Integer;
  115. TmpBranchInfo: TRealICQBranchInfo;
  116. begin
  117. OnlineCount := OnlineCount + ABranchInfo.OnlineEmployee;
  118. TotalCount := TotalCount + ABranchInfo.EmployeeCount;
  119. for iLoop:= 0 to FSelfUnit.Count - 1 do
  120. begin
  121. TmpBranchInfo := FSelfUnit.Objects[iLoop] as TRealICQBranchInfo;
  122. if TmpBranchInfo.ParentID = ABranchInfo.ID then
  123. GetUsersCount(TmpBranchInfo, OnlineCount, TotalCount);
  124. end;
  125. end;
  126. procedure TBranchService.Init;
  127. begin
  128. Uninstall;
  129. MainForm.RealICQClient.OnGettedBranchs := OnGettedSelfUnit;
  130. MainForm.RealICQClient.SendGetBranchList;
  131. end;
  132. procedure TBranchService.Uninstall;
  133. begin
  134. MainForm.RealICQClient.OnGettedBranchs := nil;
  135. ClearStringList(FSelfUnit);
  136. end;
  137. procedure TBranchService.UpdateOrAddTreeView(ABranchs: TStringList;
  138. ATreeView: TRealICQContacterTreeView);
  139. var
  140. iLoop: Integer;
  141. OnlineEmployee,EmployeeCount:Integer;
  142. BranchInfo: TRealICQBranchInfo;
  143. Branch: TRealICQBranch;
  144. ParentNode:TTreeNode;
  145. begin
  146. // ATreeView.OnHeadImageMouseEnter := NodeOnHeadImageMouseEnter;
  147. // ATreeView.OnHeadImageMouseLeave := NodeOnHeadImageMouseLeave;
  148. ATreeView.AdjustPosition :=False;
  149. ATreeView.HideSystemScrollBar;
  150. ATreeView.BeginUpdate;
  151. try
  152. {$region '添加部门'}
  153. for iLoop := 0 to FSelfUnit.Count - 1 do
  154. begin
  155. BranchInfo := FSelfUnit.Objects[iLoop] as TRealICQBranchInfo;
  156. if (ATreeView.BranchItems.IndexOf(BranchInfo.ID)) >= 0 then Continue;
  157. OnlineEmployee:=0;
  158. EmployeeCount:=0;
  159. GetUsersCount(BranchInfo, OnlineEmployee, EmployeeCount);
  160. Branch := TRealICQBranch.Create(BranchInfo.BranchName);
  161. Branch.BranchID := BranchInfo.ID;
  162. Branch.ParentID := BranchInfo.ParentID;
  163. Branch.IsGetUserList:=False;
  164. Branch.OnlineEmployee:=OnlineEmployee;
  165. Branch.EmployeeCount:=EmployeeCount;
  166. ATreeView.AddBranch(Branch);
  167. end;
  168. ATreeView.ReAlignBranchs;
  169. {$endregion}
  170. finally
  171. ATreeView.EndUpdate;
  172. end;
  173. end;
  174. initialization
  175. finalization
  176. if ABranchService <> nil then
  177. FreeAndNil(ABranchService);
  178. end.