ConfigDoc.pas 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. FExcelWithMis: Boolean;
  19. FIsLog: Boolean;
  20. FBatchInsertFrmHeight: Integer;
  21. FBatchInsertFrmWidth: Integer;
  22. FOverRangePercent: Integer;
  23. procedure LoadSectionOfCustomize;
  24. procedure LoadSectionOfUnitList;
  25. procedure LoadSectionOfStdFile;
  26. procedure LoadSectionOfPath;
  27. procedure LoadSectionOfOptions;
  28. procedure LoadIniFile;
  29. procedure SaveIniFile;
  30. procedure SaveSectionOfStdFile;
  31. procedure SaveSectionOfOptions;
  32. procedure SaveSectionOfCustomize;
  33. function GetStandardGclLib: string;
  34. function GetStandardXmLib: string;
  35. procedure SetStandardGclLib(const Value: string);
  36. procedure SetStandardXmLib(const Value: string);
  37. function GetOutputPath: string;
  38. function GetAuditPath: string;
  39. public
  40. constructor Create(const AIniFile: string);
  41. destructor Destroy; override;
  42. property Units: TStrings read FUnits;
  43. property StandardXmLib: string read GetStandardXmLib write SetStandardXmLib;
  44. property StandardGclLib: string read GetStandardGclLib write SetStandardGclLib;
  45. property IsLog: Boolean read FIsLog;
  46. // Path
  47. property AuditPath: string read GetAuditPath;
  48. property OutputPath: string read GetOutputPath;
  49. // Options
  50. property CompanyName: string read FCompanyName write FCompanyName;
  51. property AutoSave: Boolean read FAutoSave write FAutoSave;
  52. property AutoSaveInterval: Integer read FAutoSaveInterval write FAutoSaveInterval;
  53. property OverRangeType: Integer read FOverRangeType write FOverRangeType;
  54. property OverRangePercent: Integer read FOverRangePercent write FOverRangePercent;
  55. property ExcelWithMis: Boolean read FExcelWithMis write FExcelWithMis;
  56. // Customize
  57. property BatchInsertFrmHeight: Integer read FBatchInsertFrmHeight write FBatchInsertFrmHeight;
  58. property BatchInsertFrmWidth: Integer read FBatchInsertFrmWidth write FBatchInsertFrmWidth;
  59. end;
  60. implementation
  61. { TConfigInfo }
  62. constructor TConfigInfo.Create(const AIniFile: string);
  63. begin
  64. FIniFile := TIniFile.Create(AIniFile);
  65. FUnits := TStringList.Create;
  66. LoadIniFile;
  67. end;
  68. destructor TConfigInfo.Destroy;
  69. begin
  70. SaveIniFile;
  71. FUnits.Free;
  72. FIniFile.Free;
  73. inherited;
  74. end;
  75. function TConfigInfo.GetAuditPath: string;
  76. begin
  77. Result := GetAppFilePath + FAuditPath;
  78. end;
  79. function TConfigInfo.GetOutputPath: string;
  80. begin
  81. Result := GetAppFilePath + FOutputPath;
  82. end;
  83. function TConfigInfo.GetStandardGclLib: string;
  84. begin
  85. Result := GetAppFilePath + '标准清单\工程量清单\' + FStandardGclLib;
  86. end;
  87. function TConfigInfo.GetStandardXmLib: string;
  88. begin
  89. Result := GetAppFilePath + '标准清单\项目节清单\' + FStandardXmLib;
  90. end;
  91. procedure TConfigInfo.LoadIniFile;
  92. begin
  93. LoadSectionOfUnitList;
  94. LoadSectionOfStdFile;
  95. LoadSectionOfPath;
  96. LoadSectionOfOptions;
  97. LoadSectionOfCustomize;
  98. FIsLog := FIniFile.ReadBool('Other', 'IsLog', True);
  99. end;
  100. procedure TConfigInfo.LoadSectionOfCustomize;
  101. begin
  102. FBatchInsertFrmHeight := FIniFile.ReadInteger('Customize', 'BatchInsertFrmHeight', 382);
  103. FBatchInsertFrmWidth := FIniFile.ReadInteger('Customize', 'BatchInsertFrmWidth', 779);
  104. end;
  105. procedure TConfigInfo.LoadSectionOfOptions;
  106. begin
  107. FCompanyName := FIniFile.ReadString('Options', 'CompanyName', '');
  108. FAutoSave := FIniFile.ReadBool('Options', 'AutoSave', True);
  109. FAutoSaveInterval := FIniFile.ReadInteger('Options', 'AutoSaveInterval', 15);
  110. FOverRangeType := FIniFile.ReadInteger('Options', 'OverRangeType', 0);
  111. FOverRangePercent := FIniFile.ReadInteger('Options', 'OverRangePercent', 100);
  112. FExcelWithMis := FIniFile.ReadBool('Options', 'ExcelWithMis', False);
  113. end;
  114. procedure TConfigInfo.LoadSectionOfPath;
  115. begin
  116. FOutputPath := FIniFile.ReadString('Paths', 'Output', '导出文件\');
  117. FAuditPath := FIniFile.ReadString('Paths', 'AuditPath', '上报批复文件\');
  118. end;
  119. procedure TConfigInfo.LoadSectionOfStdFile;
  120. begin
  121. FStandardXmLib := FIniFile.ReadString('StdFiles', 'XmLib', '');
  122. FStandardGclLib := FIniFile.ReadString('StdFiles', 'GclLib', '');
  123. end;
  124. procedure TConfigInfo.LoadSectionOfUnitList;
  125. var
  126. iIndex: Integer;
  127. begin
  128. if FIniFile.SectionExists('UnitList') then
  129. begin
  130. FIniFile.ReadSection('UnitList', FUnits);
  131. for iIndex := 0 to FUnits.Count - 1 do
  132. FUnits.Strings[iIndex] := FIniFile.ReadString('UnitList', FUnits.Strings[iIndex], '');
  133. end;
  134. end;
  135. procedure TConfigInfo.SaveIniFile;
  136. begin
  137. SaveSectionOfStdFile;
  138. SaveSectionOfOptions;
  139. SaveSectionOfCustomize;
  140. end;
  141. procedure TConfigInfo.SaveSectionOfCustomize;
  142. begin
  143. FIniFile.WriteInteger('Customize', 'BatchInsertFrmHeight', FBatchInsertFrmHeight);
  144. FIniFile.WriteInteger('Customize', 'BatchInsertFrmWidth', FBatchInsertFrmWidth);
  145. end;
  146. procedure TConfigInfo.SaveSectionOfOptions;
  147. begin
  148. FIniFile.WriteString('Options', 'CompanyName', FCompanyName);
  149. FIniFile.WriteBool('Options', 'AutoSave', FAutoSave);
  150. FIniFile.WriteInteger('Options', 'AutoSaveInterval', FAutoSaveInterval);
  151. FIniFile.WriteInteger('Options', 'OverRangeType', FOverRangeType);
  152. FIniFile.WriteInteger('Options', 'OverRangePercent', FOverRangePercent);
  153. FIniFile.WriteBool('Options', 'ExcelWithMis', FExcelWithMis);
  154. end;
  155. procedure TConfigInfo.SaveSectionOfStdFile;
  156. begin
  157. FIniFile.WriteString('StdFiles', 'XmLib', FStandardXmLib);
  158. FIniFile.WriteString('StdFiles', 'GclLib', FStandardGclLib);
  159. end;
  160. procedure TConfigInfo.SetStandardGclLib(const Value: string);
  161. begin
  162. FStandardGclLib := Value;
  163. SaveIniFile;
  164. end;
  165. procedure TConfigInfo.SetStandardXmLib(const Value: string);
  166. begin
  167. FStandardXmLib := Value;
  168. SaveIniFile;
  169. end;
  170. end.