rpgGatherControl.pas 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. CopyTables(sTempFile, 'DealBills');
  63. finally
  64. if FileExists(sTempFile) then
  65. DeleteFile(sTempFile);
  66. end;
  67. end;
  68. function TrpgGatherControl.RefreshConnection(ATemplate: TTemplateNode): TADOConnection;
  69. begin
  70. FTemplate := ATemplate;
  71. if SelectProject then
  72. begin
  73. if not SameSelect then
  74. RefreshGather
  75. else if Assigned(ATemplate.InteractInfo) then
  76. FGatherData.UpdateDataBase(ATemplate.InteractInfo.SpecialProjGatherTypes);
  77. end;
  78. Result := FGatherData.Connection;
  79. end;
  80. procedure TrpgGatherControl.RefreshGather;
  81. var
  82. Gather: TProjGather;
  83. begin
  84. Screen.Cursor := crHourGlass;
  85. Gather := TProjGather.Create(FGatherData.WriteGatherData,
  86. ReportConfig.XmjCompare, ReportConfig.GclCompare);
  87. try
  88. if Assigned(FTemplate.InteractInfo) then
  89. Gather.Gather(FSelectProjs, FTemplate.InteractInfo.SpecialProjGatherTypes)
  90. else
  91. Gather.Gather(FSelectProjs, nil);
  92. FGatherData.LoadRelaData(FProjectData.ProjectID);
  93. ClearObjects(FHistroyProjs);
  94. FHistroyProjs.Assign(FSelectProjs);
  95. finally
  96. Gather.Free;
  97. Screen.Cursor := crDefault;
  98. end;
  99. end;
  100. function TrpgGatherControl.SameSelect: Boolean;
  101. function IncludeProj(AList: TList; AProj: TGatherProjInfo): Boolean;
  102. var
  103. i: Integer;
  104. vProj: TGatherProjInfo;
  105. begin
  106. Result := False;
  107. for i := 0 to AList.Count - 1 do
  108. begin
  109. vProj := TGatherProjInfo(AList.Items[i]);
  110. if (AProj.ProjectID = vProj.ProjectID) and (AProj.ProjType = vProj.ProjType) then
  111. begin
  112. Result := True;
  113. Break;
  114. end;
  115. end;
  116. end;
  117. function IncludeList(ALarge, ASmall: TList): Boolean;
  118. var
  119. iSmall: Integer;
  120. begin
  121. Result := True;
  122. for iSmall := 0 to ASmall.Count - 1 do
  123. begin
  124. if not IncludeProj(ALarge, TGatherProjInfo(ASmall.Items[iSmall])) then
  125. begin
  126. Result := False;
  127. Break;
  128. end;
  129. end;
  130. end;
  131. begin
  132. if FHistroyProjs.Count = FSelectProjs.Count then
  133. Result := IncludeList(FHistroyProjs, FSelectProjs) and IncludeList(FSelectProjs, FHistroyProjs)
  134. else
  135. Result := False;
  136. end;
  137. function TrpgGatherControl.SelectProject: Boolean;
  138. begin
  139. if FTemplate.IsExtra then
  140. Result := SelectGatherProject(FProjectData.ProjectID, FSelectProjs, FTemplate.InteractInfo.SpecialProjGatherTypes)
  141. else
  142. Result := SelectGatherProject(FProjectData.ProjectID, FSelectProjs);
  143. end;
  144. procedure TrpgGatherControl.CopyTables(const AFileName,
  145. ATableName: string);
  146. const
  147. sCopySql = 'Select * Into %s' +
  148. ' From %s In ''%s''';
  149. var
  150. vQuery: TADOQuery;
  151. begin
  152. vQuery := TADOQuery.Create(nil);
  153. try
  154. vQuery.Connection := FGatherData.Connection;
  155. vQuery.SQL.Clear;
  156. vQuery.SQL.Add(Format(sCopySql, [ATableName, ATableName, AFileName]));
  157. vQuery.ExecSQL;
  158. finally
  159. vQuery.Free;
  160. end;
  161. end;
  162. end.