rpgGatherControl.pas 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. unit rpgGatherControl;
  2. interface
  3. uses
  4. Classes, rpgGatherData, ADODB, ReportManager, ProjectData;
  5. type
  6. TrpgGatherControl = class
  7. private
  8. // 当前打开项目,根据其筛选项目
  9. FProjectData: TProjectData;
  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 CopyTables(const AFileName, ATableName: string);
  20. procedure CopyRelaData;
  21. procedure RefreshGather;
  22. public
  23. constructor Create(AProjectData: TProjectData);
  24. destructor Destroy; override;
  25. function RefreshConnection(ATemplate: TTemplateNode): TADOConnection;
  26. end;
  27. implementation
  28. uses
  29. ZhAPI, GatherProjInfo, ProjGather, ProjGatherSelectFrm, Globals, Forms,
  30. Controls, UtilMethods, SysUtils;
  31. { TrpgGatherControl }
  32. constructor TrpgGatherControl.Create(AProjectData: TProjectData);
  33. begin
  34. FProjectData := AProjectData;
  35. FHistroyProjs := TList.Create;
  36. FSelectProjs := TList.Create;
  37. FGatherData := TrpgGatherData.Create;
  38. CopyRelaData;
  39. end;
  40. destructor TrpgGatherControl.Destroy;
  41. begin
  42. FGatherData.Free;
  43. FSelectProjs.Free;
  44. ClearObjects(FHistroyProjs);
  45. FHistroyProjs.Free;
  46. inherited;
  47. end;
  48. procedure TrpgGatherControl.CopyRelaData;
  49. var
  50. sTempFile: string;
  51. begin
  52. sTempFile := GetTempFileName;
  53. try
  54. FProjectData.SaveTempDataBaseFile(sTempFile);
  55. CopyTables(sTempFile, 'ProjProperties');
  56. finally
  57. if FileExists(sTempFile) then
  58. DeleteFile(sTempFile);
  59. end;
  60. end;
  61. function TrpgGatherControl.RefreshConnection(ATemplate: TTemplateNode): TADOConnection;
  62. begin
  63. FTemplate := ATemplate;
  64. if SelectProject then
  65. begin
  66. if not SameSelect then
  67. RefreshGather
  68. else if Assigned(ATemplate.InteractInfo) then
  69. FGatherData.UpdateDataBase(ATemplate.InteractInfo.SpecialProjGatherTypes);
  70. end;
  71. Result := FGatherData.Connection;
  72. end;
  73. procedure TrpgGatherControl.RefreshGather;
  74. var
  75. Gather: TProjGather;
  76. begin
  77. Screen.Cursor := crHourGlass;
  78. Gather := TProjGather.Create(FGatherData.WriteGatherData,
  79. ReportConfig.XmjCompare, ReportConfig.GclCompare);
  80. try
  81. if Assigned(FTemplate.InteractInfo) then
  82. Gather.Gather(FSelectProjs, FTemplate.InteractInfo.SpecialProjGatherTypes)
  83. else
  84. Gather.Gather(FSelectProjs, nil);
  85. FGatherData.LoadRelaData(FProjectData.ProjectID);
  86. ClearObjects(FHistroyProjs);
  87. FHistroyProjs.Assign(FSelectProjs);
  88. finally
  89. Gather.Free;
  90. Screen.Cursor := crDefault;
  91. end;
  92. end;
  93. function TrpgGatherControl.SameSelect: Boolean;
  94. function IncludeProj(AList: TList; AProj: TGatherProjInfo): Boolean;
  95. var
  96. i: Integer;
  97. vProj: TGatherProjInfo;
  98. begin
  99. Result := False;
  100. for i := 0 to AList.Count - 1 do
  101. begin
  102. vProj := TGatherProjInfo(AList.Items[i]);
  103. if (AProj.ProjectID = vProj.ProjectID) and (AProj.ProjType = vProj.ProjType) then
  104. begin
  105. Result := True;
  106. Break;
  107. end;
  108. end;
  109. end;
  110. function IncludeList(ALarge, ASmall: TList): Boolean;
  111. var
  112. iSmall: Integer;
  113. begin
  114. Result := True;
  115. for iSmall := 0 to ASmall.Count - 1 do
  116. begin
  117. if not IncludeProj(ALarge, TGatherProjInfo(ASmall.Items[iSmall])) then
  118. begin
  119. Result := False;
  120. Break;
  121. end;
  122. end;
  123. end;
  124. begin
  125. if FHistroyProjs.Count = FSelectProjs.Count then
  126. Result := IncludeList(FHistroyProjs, FSelectProjs) and IncludeList(FSelectProjs, FHistroyProjs)
  127. else
  128. Result := False;
  129. end;
  130. function TrpgGatherControl.SelectProject: Boolean;
  131. begin
  132. if FTemplate.IsExtra then
  133. Result := SelectGatherProject(FProjectData.ProjectID, FHistroyProjs, FSelectProjs, FTemplate.InteractInfo.SpecialProjGatherTypes)
  134. else
  135. Result := SelectGatherProject(FProjectData.ProjectID, FHistroyProjs, FSelectProjs);
  136. end;
  137. procedure TrpgGatherControl.CopyTables(const AFileName,
  138. ATableName: string);
  139. const
  140. sCopySql = 'Select * Into %s' +
  141. ' From %s In ''%s''';
  142. var
  143. vQuery: TADOQuery;
  144. begin
  145. vQuery := TADOQuery.Create(nil);
  146. try
  147. vQuery.Connection := FGatherData.Connection;
  148. vQuery.SQL.Clear;
  149. vQuery.SQL.Add(Format(sCopySql, [ATableName, ATableName, AFileName]));
  150. vQuery.ExecSQL;
  151. finally
  152. vQuery.Free;
  153. end;
  154. end;
  155. end.