unit ProjectPropertyDM; interface uses SysUtils, Classes, DBClient, Provider, DB, ADODB; type TProjPropertyDM = class(TDataModule) atProjProperty: TADOTable; dspProjProperty: TDataSetProvider; cdsProjProperty: TClientDataSet; cdsProjPropertyID: TIntegerField; cdsProjPropertyName: TWideStringField; cdsProjPropertyItemValue: TWideStringField; atProjData: TADOTable; dspProjData: TDataSetProvider; cdsProjData: TClientDataSet; cdsProjDataBuildProjectID: TIntegerField; cdsProjDataBuildProjectName: TWideStringField; cdsProjDataProjectLocation: TWideStringField; cdsProjDataBuildUnit: TWideStringField; cdsProjDataAuthorUnit: TWideStringField; cdsProjDataBidder: TWideStringField; cdsProjDataAuthor: TWideStringField; cdsProjDataAuthorCertificate: TWideStringField; cdsProjDataAuditor: TWideStringField; cdsProjDataAuditorCertificate: TWideStringField; cdsProjDataBudgetProjectName: TWideStringField; cdsProjDataEditRange: TWideStringField; cdsProjDataEditDate: TDateTimeField; cdsProjDataMachineBBFeeRate: TFloatField; cdsProjDataFZFeeRate: TFloatField; cdsProjDataIsCalcGYFeeRate: TBooleanField; cdsProjDataRoadLength: TFloatField; cdsProjDataAvgMaintMonth: TFloatField; cdsProjDataRoadClass: TIntegerField; cdsProjDataIsNew: TBooleanField; cdsProjDataLandForm: TIntegerField; cdsProjDataDJZG: TFloatField; cdsProjDataYJZG: TFloatField; cdsProjDataNightZG: TFloatField; cdsProjDataRaiseRateByYear: TFloatField; cdsProjDataRaiseYear: TFloatField; cdsProjDataBuildManageFeeFile: TIntegerField; private FConnection: TADOConnection; procedure SetConnection(const Value: TADOConnection); procedure SetActive(const Value: Boolean); function GetActive: Boolean; procedure CheckActive; procedure EditProperty(aProjType: Integer); procedure EditProjData; property Active: Boolean read GetActive write SetActive; public property Connection: TADOConnection read FConnection write SetConnection; procedure EditProjProperty(aProjType: Integer); procedure Save; function GetProjectType: Integer; end; implementation uses Math, ConstVarUnit; {$R *.dfm} { TProjPropertyDM } procedure TProjPropertyDM.CheckActive; begin if not Active then Active := True; end; procedure TProjPropertyDM.EditProjData; begin cdsProjData.First; while not cdsProjData.Eof do begin cdsProjData.Edit; cdsProjDataEditDate.Value := Now; cdsProjData.Post; cdsProjData.Next; end; end; procedure TProjPropertyDM.EditProjProperty(aProjType: Integer); begin CheckActive; EditProperty(aProjType); EditProjData; end; procedure TProjPropertyDM.EditProperty(aProjType: Integer); begin cdsProjProperty.First; while not cdsProjProperty.Eof do begin if cdsProjPropertyName.Value = sProjType then begin cdsProjProperty.Edit; cdsProjPropertyItemValue.Value := IntToStr(aProjType); cdsProjProperty.Post; Break; end; cdsProjProperty.Next; end; end; function TProjPropertyDM.GetActive: Boolean; begin Result := cdsProjProperty.Active and cdsProjData.Active; end; function TProjPropertyDM.GetProjectType: Integer; begin Result := -1; cdsProjProperty.First; while not cdsProjProperty.Eof do begin if cdsProjPropertyName.Value = sProjType then begin Result := StrToIntDef(cdsProjPropertyItemValue.Value, 1); Break; end; cdsProjProperty.Next; end; end; procedure TProjPropertyDM.Save; begin cdsProjProperty.ApplyUpdates(0); cdsProjData.ApplyUpdates(0); end; procedure TProjPropertyDM.SetActive(const Value: Boolean); begin cdsProjProperty.Active := Value; cdsProjData.Active := Value; end; procedure TProjPropertyDM.SetConnection(const Value: TADOConnection); begin FConnection := Value; if Assigned(FConnection) then begin atProjProperty.Connection := FConnection; atProjData.Connection := FConnection; { TODO : open cds } Active := True; end; end; end.