ProjectPropertyUnit.pas 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. unit ProjectPropertyUnit;
  2. interface
  3. uses
  4. ADODB,
  5. ScFileArchiver,
  6. SysUtils;
  7. type
  8. TProjectProperty = class
  9. private
  10. FBuildProjectName: string;
  11. FBudgetProjectName: string;
  12. { 标段类型 }
  13. FProjectType : string;
  14. { 编制范围 }
  15. FWeaveRange : string;
  16. { 建设单位 }
  17. FBuildUnit : string;
  18. { 工程地点 }
  19. FProjectSite : string;
  20. { 编制日期 }
  21. FWeaveDate : string;
  22. { 编制人 }
  23. FWeavePerson : string;
  24. { 编制人证号 }
  25. FWeaveCode : string;
  26. { 复核人 }
  27. FCheckPerson : string;
  28. { 复核人证号 }
  29. FCheckCode : string;
  30. { 投标人 }
  31. FTenderPerson : string;
  32. { 数据文件号 }
  33. FDataFileCode : string;
  34. { 公路等级 }
  35. FRoadLevel : string;
  36. { 起点桩号 }
  37. FFirstPeg : string;
  38. { 终点桩号 }
  39. FLastPeg : string;
  40. { 路线长度 }
  41. FRouteLength : string;
  42. { 路线宽度 }
  43. FRouteWidth : string;
  44. FExpressMode : Integer;
  45. FQuery : TADOQuery;
  46. FDoQuery : TADOQuery;
  47. FConnection : TADOConnection;
  48. FArchiver : TScProjectFileArchiver;
  49. function OpenArcFile(const aFilePath: string): Boolean;
  50. procedure ExecuteSql(aQuery: TADOQuery; const aSql: string);
  51. procedure OpenSql(aQuery: TADOQuery; const aSql: string);
  52. { Access Tables }
  53. procedure WriteProjectData;
  54. procedure WriteProjProperty;
  55. procedure WriteProjFloatProperty;
  56. procedure ReadProjectData;
  57. procedure ReadProjProperty;
  58. procedure ReadProjFloatProperty;
  59. { projproperty }
  60. function GetMaxProjPropertyID: Integer;
  61. function CheckProjProperty(const aName: string): Boolean;
  62. procedure WriteProperty(var aMaxID: Integer; const aTableName, aName, aItemValue: string);
  63. procedure UpdateProjProperty(const aTableName, aName, aItemValue: string);
  64. procedure InsertProjProperty(aID: Integer; const aTableName, aName, aItemValue: string);
  65. procedure SetBuildUnit(const Value: string);
  66. procedure SetCheckCode(const Value: string);
  67. procedure SetCheckPerson(const Value: string);
  68. procedure SetDataFileCode(const Value: string);
  69. procedure SetFirstPeg(const Value: string);
  70. procedure SetLastPeg(const Value: string);
  71. procedure SetProjectSite(const Value: string);
  72. procedure SetProjectType(const Value: string);
  73. procedure SetRoadLevel(const Value: string);
  74. procedure SetRouteLength(const Value: string);
  75. procedure SetRouteWidth(const Value: string);
  76. procedure SetTenderPerson(const Value: string);
  77. procedure SetWeaveCode(const Value: string);
  78. procedure SetWeaveDate(const Value: string);
  79. procedure SetWeavePerson(const Value: string);
  80. procedure SetWeaveRange(const Value: string);
  81. procedure SetConnection(const Value: TADOConnection);
  82. procedure SetExpressMode(const Value: Integer);
  83. public
  84. constructor Create;
  85. destructor Destroy; override;
  86. procedure CloseArcFile;
  87. procedure SaveProperty;
  88. procedure InitProjectProperty;
  89. // project has not opened yet
  90. procedure GetProjectProperty(const aFilePath: string); overload;
  91. // project has opened
  92. procedure GetProjectProperty; overload;
  93. property Connection: TADOConnection read FConnection write SetConnection;
  94. property BuildProjectName: string read FBuildProjectName write FBuildProjectName;
  95. property BudgetProjectName: string read FBudgetProjectName write FBudgetProjectName;
  96. { 标段类型 }
  97. property ProjectType: string read FProjectType write SetProjectType;
  98. { 编制范围 }
  99. property WeaveRange: string read FWeaveRange write SetWeaveRange;
  100. { 建设单位 }
  101. property BuildUnit: string read FBuildUnit write SetBuildUnit;
  102. { 工程地点 }
  103. property ProjectSite: string read FProjectSite write SetProjectSite;
  104. { 编制日期 }
  105. property WeaveDate: string read FWeaveDate write SetWeaveDate;
  106. { 编制人 }
  107. property WeavePerson: string read FWeavePerson write SetWeavePerson;
  108. { 编制人证号 }
  109. property WeaveCode: string read FWeaveCode write SetWeaveCode;
  110. { 复核人 }
  111. property CheckPerson: string read FCheckPerson write SetCheckPerson;
  112. { 复核人证号 }
  113. property CheckCode: string read FCheckCode write SetCheckCode;
  114. { 投标人 }
  115. property TenderPerson: string read FTenderPerson write SetTenderPerson;
  116. { 数据文件号 }
  117. property DataFileCode: string read FDataFileCode write SetDataFileCode;
  118. { 公路等级 }
  119. property RoadLevel: string read FRoadLevel write SetRoadLevel;
  120. { 起点桩号 }
  121. property FirstPeg: string read FFirstPeg write SetFirstPeg;
  122. { 终点桩号 }
  123. property LastPeg: string read FLastPeg write SetLastPeg;
  124. { 路线长度 }
  125. property RouteLength: string read FRouteLength write SetRouteLength;
  126. { 路线宽度 }
  127. property RouteWidth: string read FRouteWidth write SetRouteWidth;
  128. property ExpressMode: Integer read FExpressMode write SetExpressMode;
  129. end;
  130. implementation
  131. uses DB;
  132. { TProjectProperty }
  133. function TProjectProperty.CheckProjProperty(
  134. const aName: string): Boolean;
  135. var
  136. sSql: string;
  137. begin
  138. sSql := Format('Select * From ProjProperty Where Name = ''%s''', [aName]);
  139. OpenSql(FDoQuery, sSql);
  140. Result := FDoQuery.RecordCount > 0;
  141. end;
  142. procedure TProjectProperty.CloseArcFile;
  143. begin
  144. if FArchiver.IsOpened then
  145. FArchiver.CloseFile;
  146. end;
  147. constructor TProjectProperty.Create;
  148. begin
  149. FQuery := TADOQuery.Create(nil);
  150. FDoQuery := TADOQuery.Create(nil);
  151. FArchiver := TScProjectFileArchiver.Create;
  152. end;
  153. destructor TProjectProperty.Destroy;
  154. begin
  155. CloseArcFile;
  156. FQuery.Free;
  157. FDoQuery.Free;
  158. FArchiver.Free;
  159. inherited;
  160. end;
  161. procedure TProjectProperty.ExecuteSql(aQuery: TADOQuery; const aSql: string);
  162. begin
  163. with aQuery do
  164. begin
  165. SQL.Clear;
  166. SQL.Add(aSql);
  167. ExecSQL;
  168. end;
  169. end;
  170. function TProjectProperty.GetMaxProjPropertyID: Integer;
  171. var
  172. sSql: string;
  173. begin
  174. sSql := 'Select Max(ID) as ID From ProjProperty';
  175. OpenSql(FDoQuery, sSql);
  176. Result := FDoQuery.FieldByName('ID').AsInteger + 1;
  177. end;
  178. procedure TProjectProperty.GetProjectProperty;
  179. begin
  180. InitProjectProperty;
  181. ReadProjectData;
  182. ReadProjProperty;
  183. ReadProjFloatProperty;
  184. end;
  185. procedure TProjectProperty.GetProjectProperty(const aFilePath: string);
  186. begin
  187. CloseArcFile;
  188. if not OpenArcFile(aFilePath) then Exit;
  189. FConnection := FArchiver.Connection;
  190. FQuery.Connection := FConnection;
  191. FDoQuery.Connection := FConnection;
  192. GetProjectProperty;
  193. end;
  194. procedure TProjectProperty.InitProjectProperty;
  195. begin
  196. FBudgetProjectName := '';
  197. FProjectType := '';
  198. FWeaveRange := '';
  199. FBuildUnit := '';
  200. FProjectSite := '';
  201. FWeaveDate := '';
  202. FWeavePerson := '';
  203. FWeaveCode := '';
  204. FCheckPerson := '';
  205. FCheckCode := '';
  206. FTenderPerson := '';
  207. FDataFileCode := '';
  208. FRoadLevel := '';
  209. FFirstPeg := '';
  210. FLastPeg := '';
  211. FRouteLength := '';
  212. FRouteWidth := '';
  213. FExpressMode := 1;
  214. end;
  215. procedure TProjectProperty.InsertProjProperty(aID: Integer;
  216. const aTableName, aName, aItemValue: string);
  217. var
  218. sSql: string;
  219. begin
  220. sSql := Format('Insert Into %s (ID, Name, ItemValue) Values (%d, ''%s'', ''%s'')',
  221. [aTableName, aID, aName, aItemValue]);
  222. ExecuteSql(FDoQuery, sSql);
  223. end;
  224. function TProjectProperty.OpenArcFile(const aFilePath: string): Boolean;
  225. begin
  226. FArchiver.FileName := aFilePath;
  227. Result := FArchiver.OpenFile;
  228. end;
  229. procedure TProjectProperty.OpenSql(aQuery: TADOQuery; const aSql: string);
  230. begin
  231. with aQuery do
  232. begin
  233. SQL.Clear;
  234. SQL.Add(aSql);
  235. Open;
  236. end;
  237. end;
  238. procedure TProjectProperty.ReadProjectData;
  239. begin
  240. OpenSql(FQuery, 'Select * From ProjData');
  241. with FQuery do
  242. begin
  243. FBuildProjectName := FieldByName('BuildProjectName').AsString;
  244. FBudgetProjectName := FieldByName('BudgetProjectName').AsString;
  245. FWeaveRange := FieldByName('EditRange').AsString;
  246. FBuildUnit := FieldByName('BuildUnit').AsString;
  247. FProjectSite := FieldByName('ProjectLocation').AsString;
  248. FWeaveDate := FieldByName('EditDate').AsString;
  249. FWeavePerson := FieldByName('Author').AsString;
  250. FWeaveCode := FieldByName('AuthorCertificate').AsString;
  251. FCheckPerson := FieldByName('Auditor').AsString;
  252. FCheckCode := FieldByName('AuditorCertificate').AsString;
  253. FTenderPerson := FieldByName('Bidder').AsString;
  254. end;
  255. end;
  256. procedure TProjectProperty.ReadProjFloatProperty;
  257. begin
  258. OpenSql(FQuery, 'Select * From ProjFloatProperty Where Name = ''ROADLENGTH''');
  259. if FQuery.RecordCount > 0 then
  260. FRouteLength := FQuery.FieldByName('ItemValue').AsString;
  261. end;
  262. procedure TProjectProperty.ReadProjProperty;
  263. begin
  264. OpenSql(FQuery, 'Select * From ProjProperty');
  265. with FQuery do
  266. begin
  267. First;
  268. while not Eof do
  269. begin
  270. if FieldByName('Name').AsString = 'PROJTYPE' then
  271. begin
  272. if FieldByName('ItemValue').AsString = '5' then
  273. FProjectType := '三级清单预算'
  274. else
  275. FProjectType := '';
  276. // FProjectType := '旧版本';
  277. end
  278. else if FieldByName('Name').AsString = 'DATAFILENO' then
  279. FDataFileCode := FieldByName('ItemValue').AsString
  280. else if FieldByName('Name').AsString = 'ROADLEVEL' then
  281. FRoadLevel := FieldByName('ItemValue').AsString
  282. else if FieldByName('Name').AsString = 'STARTCODE' then
  283. FFirstPeg := FieldByName('ItemValue').AsString
  284. else if FieldByName('Name').AsString = 'ENDCODE' then
  285. FLastPeg := FieldByName('ItemValue').AsString
  286. else if FieldByName('Name').AsString = 'ROADWIDTH' then
  287. FRouteWidth := FieldByName('ItemValue').AsString
  288. else if FieldByName('Name').AsString = 'ExpressMode' then
  289. FExpressMode := FieldByName('ItemValue').AsInteger;
  290. Next;
  291. end;
  292. end;
  293. end;
  294. procedure TProjectProperty.SaveProperty;
  295. begin
  296. if FConnection = nil then Exit;
  297. WriteProjectData;
  298. WriteProjProperty;
  299. WriteProjFloatProperty;
  300. if FArchiver.IsOpened then
  301. FArchiver.Save;
  302. end;
  303. procedure TProjectProperty.SetBuildUnit(const Value: string);
  304. begin
  305. FBuildUnit := Value;
  306. end;
  307. procedure TProjectProperty.SetCheckCode(const Value: string);
  308. begin
  309. FCheckCode := Value;
  310. end;
  311. procedure TProjectProperty.SetCheckPerson(const Value: string);
  312. begin
  313. FCheckPerson := Value;
  314. end;
  315. procedure TProjectProperty.SetConnection(const Value: TADOConnection);
  316. begin
  317. FConnection := Value;
  318. FQuery.Connection := FConnection;
  319. FDoQuery.Connection := FConnection;
  320. end;
  321. procedure TProjectProperty.SetDataFileCode(const Value: string);
  322. begin
  323. FDataFileCode := Value;
  324. end;
  325. procedure TProjectProperty.SetExpressMode(const Value: Integer);
  326. begin
  327. FExpressMode := Value;
  328. end;
  329. procedure TProjectProperty.SetFirstPeg(const Value: string);
  330. begin
  331. FFirstPeg := Value;
  332. end;
  333. procedure TProjectProperty.SetLastPeg(const Value: string);
  334. begin
  335. FLastPeg := Value;
  336. end;
  337. procedure TProjectProperty.SetProjectSite(const Value: string);
  338. begin
  339. FProjectSite := Value;
  340. end;
  341. procedure TProjectProperty.SetProjectType(const Value: string);
  342. begin
  343. FProjectType := Value;
  344. // WriteProjProperty;
  345. end;
  346. procedure TProjectProperty.SetRoadLevel(const Value: string);
  347. begin
  348. FRoadLevel := Value;
  349. // WriteProjProperty;
  350. end;
  351. procedure TProjectProperty.SetRouteLength(const Value: string);
  352. begin
  353. FRouteLength := Value;
  354. // WriteProjFloatProperty;
  355. end;
  356. procedure TProjectProperty.SetRouteWidth(const Value: string);
  357. begin
  358. FRouteWidth := Value;
  359. // WriteProjProperty;
  360. end;
  361. procedure TProjectProperty.SetTenderPerson(const Value: string);
  362. begin
  363. FTenderPerson := Value;
  364. end;
  365. procedure TProjectProperty.SetWeaveCode(const Value: string);
  366. begin
  367. FWeaveCode := Value;
  368. // WriteProjectData;
  369. end;
  370. procedure TProjectProperty.SetWeaveDate(const Value: string);
  371. begin
  372. FWeaveDate := Value;
  373. // WriteProjectData;
  374. end;
  375. procedure TProjectProperty.SetWeavePerson(const Value: string);
  376. begin
  377. FWeavePerson := Value;
  378. // WriteProjectData;
  379. end;
  380. procedure TProjectProperty.SetWeaveRange(const Value: string);
  381. begin
  382. FWeaveRange := Value;
  383. // WriteProjectData;
  384. end;
  385. procedure TProjectProperty.UpdateProjProperty(const aTableName, aName,
  386. aItemValue: string);
  387. var
  388. sSql: string;
  389. begin
  390. sSql := Format('Update %s Set ItemValue = ''%s'' Where Name = ''%s''',
  391. [aTableName, aItemValue, aName]);
  392. ExecuteSql(FDoQuery, sSql);
  393. end;
  394. procedure TProjectProperty.WriteProjectData;
  395. var
  396. sSql: string;
  397. begin
  398. sSql := Format('Update ProjData Set ' +
  399. 'BuildProjectName = ''%s'', ' +
  400. 'BudgetProjectName = ''%s'', ' +
  401. 'EditRange = ''%s'', ' +
  402. 'BuildUnit = ''%s'', ' +
  403. 'ProjectLocation = ''%s'', ' +
  404. 'EditDate = ''%s'', ' +
  405. 'Author = ''%s'', ' +
  406. 'AuthorCertificate = ''%s'', ' +
  407. 'Auditor = ''%s'', ' +
  408. 'AuditorCertificate = ''%s'', ' +
  409. 'Bidder = ''%s''',
  410. [FBuildProjectName, FBudgetProjectName, FWeaveRange,
  411. FBuildUnit, FProjectSite,
  412. FWeaveDate, FWeavePerson, FWeaveCode,
  413. FCheckPerson, FCheckCode, FTenderPerson]);
  414. if not Assigned(FQuery.Connection) then
  415. FQuery.Connection := FConnection;
  416. ExecuteSql(FQuery, sSql);
  417. end;
  418. procedure TProjectProperty.WriteProjFloatProperty;
  419. var
  420. sSql: string;
  421. begin
  422. sSql := Format('Update ProjFloatProperty Set ItemValue = %0.3f Where Name = ''ROADLENGTH''',
  423. [StrToFloatDef(FRouteLength, 0)]);
  424. ExecuteSql(FQuery, sSql);
  425. end;
  426. procedure TProjectProperty.WriteProjProperty;
  427. var
  428. iMaxID: Integer;
  429. sSql: string;
  430. sProjType: string;
  431. begin
  432. iMaxID := GetMaxProjPropertyID;
  433. if SameText(FProjectType, '三级清单预算') then
  434. sProjType := '5'
  435. else
  436. sProjType := '6';
  437. WriteProperty(iMaxID, 'ProjProperty', 'PROJTYPE', sProjType);
  438. WriteProperty(iMaxID, 'ProjProperty', 'DATAFILENO', FDataFileCode);
  439. WriteProperty(iMaxID, 'ProjProperty', 'ROADLEVEL', FRoadLevel);
  440. WriteProperty(iMaxID, 'ProjProperty', 'STARTCODE', FFirstPeg);
  441. WriteProperty(iMaxID, 'ProjProperty', 'ENDCODE', FLastPeg);
  442. WriteProperty(iMaxID, 'ProjProperty', 'ROADWIDTH', FRouteWidth);
  443. WriteProperty(iMaxID, 'ProjProperty', 'ExpressMode', IntToStr(FExpressMode));
  444. end;
  445. procedure TProjectProperty.WriteProperty(var aMaxID: Integer;
  446. const aTableName, aName, aItemValue: string);
  447. begin
  448. if CheckProjProperty(aName) then
  449. begin
  450. UpdateProjProperty(aTableName, aName, aItemValue);
  451. end
  452. else
  453. begin
  454. InsertProjProperty(aMaxID, aTableName, aName, aItemValue);
  455. Inc(aMaxID);
  456. end;
  457. end;
  458. end.