ConfigDoc.pas 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. unit ConfigDoc;
  2. interface
  3. uses
  4. Classes, IniFiles, UtilMethods;
  5. type
  6. TConfigInfo = class
  7. private
  8. FIniFile: TIniFile;
  9. FUnits: TStrings;
  10. FStandardXmLib: string;
  11. FStandardGclLib: string;
  12. FOutputPath: string;
  13. FAuditPath: string;
  14. FCompanyName: string;
  15. FAutoSave: Boolean;
  16. FAutoSaveInterval: Integer;
  17. FOverRangeType: Integer;
  18. procedure LoadSectionOfUnitList;
  19. procedure LoadSectionOfStdFile;
  20. procedure LoadSectionOfPath;
  21. procedure LoadSectionOfOptions;
  22. procedure LoadIniFile;
  23. procedure SaveIniFile;
  24. procedure SaveSectionOfStdFile;
  25. procedure SaveSectionOfOptions;
  26. function GetStandardGclLib: string;
  27. function GetStandardXmLib: string;
  28. procedure SetStandardGclLib(const Value: string);
  29. procedure SetStandardXmLib(const Value: string);
  30. function GetOutputPath: string;
  31. function GetAuditPath: string;
  32. public
  33. constructor Create(const AIniFile: string);
  34. destructor Destroy; override;
  35. property Units: TStrings read FUnits;
  36. property StandardXmLib: string read GetStandardXmLib write SetStandardXmLib;
  37. property StandardGclLib: string read GetStandardGclLib write SetStandardGclLib;
  38. // Path
  39. property AuditPath: string read GetAuditPath;
  40. property OutputPath: string read GetOutputPath;
  41. // Options
  42. property CompanyName: string read FCompanyName write FCompanyName;
  43. property AutoSave: Boolean read FAutoSave write FAutoSave;
  44. property AutoSaveInterval: Integer read FAutoSaveInterval write FAutoSaveInterval;
  45. property OverRangeType: Integer read FOverRangeType write FOverRangeType;
  46. end;
  47. implementation
  48. { TConfigInfo }
  49. constructor TConfigInfo.Create(const AIniFile: string);
  50. begin
  51. FIniFile := TIniFile.Create(AIniFile);
  52. FUnits := TStringList.Create;
  53. LoadIniFile;
  54. end;
  55. destructor TConfigInfo.Destroy;
  56. begin
  57. SaveIniFile;
  58. FUnits.Free;
  59. FIniFile.Free;
  60. inherited;
  61. end;
  62. function TConfigInfo.GetAuditPath: string;
  63. begin
  64. Result := GetAppFilePath + FAuditPath;
  65. end;
  66. function TConfigInfo.GetOutputPath: string;
  67. begin
  68. Result := GetAppFilePath + FOutputPath;
  69. end;
  70. function TConfigInfo.GetStandardGclLib: string;
  71. begin
  72. Result := GetAppFilePath + '标准清单\工程量清单\' + FStandardGclLib;
  73. end;
  74. function TConfigInfo.GetStandardXmLib: string;
  75. begin
  76. Result := GetAppFilePath + '标准清单\项目节清单\' + FStandardXmLib;
  77. end;
  78. procedure TConfigInfo.LoadIniFile;
  79. begin
  80. LoadSectionOfUnitList;
  81. LoadSectionOfStdFile;
  82. LoadSectionOfPath;
  83. LoadSectionOfOptions;
  84. end;
  85. procedure TConfigInfo.LoadSectionOfOptions;
  86. begin
  87. FCompanyName := FIniFile.ReadString('Options', 'CompanyName', '');
  88. FAutoSave := FIniFile.ReadBool('Options', 'AutoSave', True);
  89. FAutoSaveInterval := FIniFile.ReadInteger('Options', 'AutoSaveInterval', 15);
  90. FOverRangeType := FIniFile.ReadInteger('Options', 'OverRangeType', 0);
  91. end;
  92. procedure TConfigInfo.LoadSectionOfPath;
  93. begin
  94. FOutputPath := FIniFile.ReadString('Paths', 'Output', '导出文件\');
  95. FAuditPath := FIniFile.ReadString('Paths', 'AuditPath', '上报批复文件\');
  96. end;
  97. procedure TConfigInfo.LoadSectionOfStdFile;
  98. begin
  99. FStandardXmLib := FIniFile.ReadString('StdFiles', 'XmLib', '');
  100. FStandardGclLib := FIniFile.ReadString('StdFiles', 'GclLib', '');
  101. end;
  102. procedure TConfigInfo.LoadSectionOfUnitList;
  103. var
  104. iIndex: Integer;
  105. begin
  106. if FIniFile.SectionExists('UnitList') then
  107. begin
  108. FIniFile.ReadSection('UnitList', FUnits);
  109. for iIndex := 0 to FUnits.Count - 1 do
  110. FUnits.Strings[iIndex] := FIniFile.ReadString('UnitList', FUnits.Strings[iIndex], '');
  111. end;
  112. end;
  113. procedure TConfigInfo.SaveIniFile;
  114. begin
  115. SaveSectionOfStdFile;
  116. SaveSectionOfOptions;
  117. end;
  118. procedure TConfigInfo.SaveSectionOfOptions;
  119. begin
  120. FIniFile.WriteString('Options', 'CompanyName', FCompanyName);
  121. FIniFile.WriteBool('Options', 'AutoSave', FAutoSave);
  122. FIniFile.WriteInteger('Options', 'AutoSaveInterval', FAutoSaveInterval);
  123. FIniFile.WriteInteger('Options', 'OverRangeType', FOverRangeType);
  124. end;
  125. procedure TConfigInfo.SaveSectionOfStdFile;
  126. begin
  127. FIniFile.WriteString('StdFiles', 'XmLib', FStandardXmLib);
  128. FIniFile.WriteString('StdFiles', 'GclLib', FStandardGclLib);
  129. end;
  130. procedure TConfigInfo.SetStandardGclLib(const Value: string);
  131. begin
  132. FStandardGclLib := Value;
  133. SaveIniFile;
  134. end;
  135. procedure TConfigInfo.SetStandardXmLib(const Value: string);
  136. begin
  137. FStandardXmLib := Value;
  138. SaveIniFile;
  139. end;
  140. end.