rpgGatherControl.pas 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. unit rpgGatherControl;
  2. interface
  3. uses
  4. Classes, rpgGatherData, ADODB, ReportManager;
  5. type
  6. TrpgGatherControl = class
  7. private
  8. // 当前打开项目,根据其筛选项目
  9. FProjectID: Integer;
  10. // 当前汇总的报表 -- 主要用于读取报表中的附加信息
  11. FTemplate: TTemplateNode;
  12. FHistroyProjs: TList;
  13. // 选择的汇总项目
  14. FSelectProjs: TList;
  15. // 汇总数据
  16. FGatherData: TrpgGatherData;
  17. function SelectProject: Boolean;
  18. function SameSelect: Boolean;
  19. procedure RefreshGather;
  20. public
  21. constructor Create(AProjectID: Integer);
  22. destructor Destroy; override;
  23. function RefreshConnection(ATemplate: TTemplateNode): TADOConnection;
  24. end;
  25. implementation
  26. uses
  27. ZhAPI, GatherProjInfo, ProjGather, ProjGatherSelectFrm, Globals, Forms,
  28. Controls;
  29. { TrpgGatherControl }
  30. constructor TrpgGatherControl.Create(AProjectID: Integer);
  31. begin
  32. FProjectID := AProjectID;
  33. FHistroyProjs := TList.Create;
  34. FSelectProjs := TList.Create;
  35. FGatherData := TrpgGatherData.Create;
  36. end;
  37. destructor TrpgGatherControl.Destroy;
  38. begin
  39. FGatherData.Free;
  40. FSelectProjs.Free;
  41. ClearObjects(FHistroyProjs);
  42. FHistroyProjs.Free;
  43. inherited;
  44. end;
  45. function TrpgGatherControl.RefreshConnection(ATemplate: TTemplateNode): TADOConnection;
  46. begin
  47. FTemplate := ATemplate;
  48. if SelectProject then
  49. begin
  50. if not SameSelect then
  51. RefreshGather
  52. else if Assigned(ATemplate.InteractInfo) then
  53. FGatherData.UpdateDataBase(ATemplate.InteractInfo.SpecialProjGatherTypes);
  54. end;
  55. Result := FGatherData.Connection;
  56. end;
  57. procedure TrpgGatherControl.RefreshGather;
  58. var
  59. Gather: TProjGather;
  60. begin
  61. Screen.Cursor := crHourGlass;
  62. Gather := TProjGather.Create(FGatherData.WriteGatherData,
  63. ReportConfig.XmjCompare, ReportConfig.GclCompare);
  64. try
  65. if Assigned(FTemplate.InteractInfo) then
  66. Gather.Gather(FSelectProjs, FTemplate.InteractInfo.SpecialProjGatherTypes)
  67. else
  68. Gather.Gather(FSelectProjs, nil);
  69. FGatherData.LoadRelaData(FProjectID);
  70. ClearObjects(FHistroyProjs);
  71. FHistroyProjs.Assign(FSelectProjs);
  72. finally
  73. Gather.Free;
  74. Screen.Cursor := crDefault;
  75. end;
  76. end;
  77. function TrpgGatherControl.SameSelect: Boolean;
  78. function IncludeProj(AList: TList; AProj: TGatherProjInfo): Boolean;
  79. var
  80. i: Integer;
  81. vProj: TGatherProjInfo;
  82. begin
  83. Result := False;
  84. for i := 0 to AList.Count - 1 do
  85. begin
  86. vProj := TGatherProjInfo(AList.Items[i]);
  87. if (AProj.ProjectID = vProj.ProjectID) and (AProj.ProjType = vProj.ProjType) then
  88. begin
  89. Result := True;
  90. Break;
  91. end;
  92. end;
  93. end;
  94. function IncludeList(ALarge, ASmall: TList): Boolean;
  95. var
  96. iSmall: Integer;
  97. begin
  98. Result := True;
  99. for iSmall := 0 to ASmall.Count - 1 do
  100. begin
  101. if not IncludeProj(ALarge, TGatherProjInfo(ASmall.Items[iSmall])) then
  102. begin
  103. Result := False;
  104. Break;
  105. end;
  106. end;
  107. end;
  108. begin
  109. if FHistroyProjs.Count = FSelectProjs.Count then
  110. Result := IncludeList(FHistroyProjs, FSelectProjs) and IncludeList(FSelectProjs, FHistroyProjs)
  111. else
  112. Result := False;
  113. end;
  114. function TrpgGatherControl.SelectProject: Boolean;
  115. begin
  116. if FTemplate.IsExtra then
  117. Result := SelectGatherProject(FProjectID, FHistroyProjs, FSelectProjs, FTemplate.InteractInfo.SpecialProjGatherTypes)
  118. else
  119. Result := SelectGatherProject(FProjectID, FHistroyProjs, FSelectProjs);
  120. end;
  121. end.