rpgGatherControl.pas 4.4 KB

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