rpgGatherControl.pas 4.5 KB

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