rpgGatherControl.pas 2.6 KB

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