unit ProjectProperty; interface uses Classes, SysUtils, Variants, DB, ADODB, ZhAPI, CalcDecimal; type TPropertyInquiry = class private FInquriyQuery: TADOQuery; FConnection: TADOConnection; FTableName: string; FSql: string; function GetValue(const AName: string): Variant; procedure SetValue(const AName: string; const Value: Variant); function GetNewID: Integer; procedure ExecuteSql(AIsSelect: Boolean = True); function CheckPropertyExist(const AName: string): Boolean; public constructor Create(AConnection: TADOConnection); destructor Destroy; override; property TableName: string read FTableName write FTableName; property Value[const AName: string]: Variant read GetValue write SetValue; default; end; TProjProperties = class private FProjectData: TObject; FPropertyInqurity: TPropertyInquiry; FShowPriceChange: Boolean; FPhaseCount: Integer; FLockedLedgerData: Boolean; FStartedSubsist: Double; FContractPrice: Double; FMaterialSubsist: Double; FBLegal: string; FDealName: string; FDealIndex: string; FCLegal: string; FCDate: string; FBName: string; FProjectName: string; FBDate: string; FCName: string; FSDate: string; FSName: string; FSLegal: string; FLoadLength: Double; FLaneCount: Integer; FLoadLevel: Integer; FEndPeg: string; FStartPeg: string; FShowBGLCode: Boolean; FZJJLPreText: string; FUnlockInfoPassword: string; FPhaseIndex: Integer; FShowDesignQuantity: Boolean; FDealType: string; FShowAlias: Boolean; FDecimalManager: TDecimalManager; FTotalPriceDigit: Integer; FTotalPriceFormat: string; FQuantityDigit: Integer; FQuantityFormat: string; FPriceDigit: Integer; FPriceFormat: string; FUpdateFlag: Integer; FPriceMarginStartPhaseID: Integer; function GetBoolPropertyDef(const AName: string; ADef: Boolean): Boolean; function GetIntPropertyDef(const AName: string; ADef: Integer): Integer; function GetStrPropertyDef(const AName, ADef: string): string; function GetFloatPropertyDef(const AName: string; ADef: Double): Double; function GetDisplayFormat(ADigit: Integer): string; procedure LoadBaseProperties; procedure LoadViewProperties; procedure LoadDealInfo; procedure LoadTechParameters; procedure LoadCalcParameters; procedure SaveDealInfo; procedure SaveTechParameters; procedure SaveCalcParameters; procedure SetShowPriceChange(const Value: Boolean); procedure SetPhaseCount(const Value: Integer); procedure SetLockedLedgerData(const Value: Boolean); function GetFinalAuditCount: Integer; procedure SetFinalAuditCount(const Value: Integer); function GetAuditStatus: Integer; procedure SetAuditStatus(const Value: Integer); function GetAuditStatusStr: string; procedure SetContractPrice(const Value: Double); procedure SetMaterialSubsist(const Value: Double); procedure SetStartedSubsist(const Value: Double); function GetAuditCompany: string; procedure SetAuditCompany(const Value: string); procedure SetShowBGLCode(const Value: Boolean); procedure SetZJJLPreText(const Value: string); procedure SetUnlockInfoPassword(const Value: string); procedure SetPhaseIndex(const Value: Integer); procedure SetShowDesignQuantity(const Value: Boolean); procedure SetShowAlias(const Value: Boolean); procedure SetQuantityDigit(const Value: Integer); procedure SetTotalPriceDigit(const Value: Integer); procedure SetUpdateFlag(const Value: Integer); public constructor Create(AProjectData: TObject); destructor Destroy; override; procedure Open(AConnection: TADOConnection); procedure Save; {Submit-Audit-Reply} // 共计终审计量期数 property FinalAuditCount: Integer read GetFinalAuditCount write SetFinalAuditCount; // 当前审核状态 property AuditStatus: Integer read GetAuditStatus write SetAuditStatus; property AuditStatusStr: string read GetAuditStatusStr; property AuditCompany: string read GetAuditCompany write SetAuditCompany; {合同信息} // 建设项目名称 property ProjectName: string read FProjectName write FProjectName; // 合同名称 property DealName: string read FDealName write FDealName; // 合同编号 property DealIndex: string read FDealIndex write FDealIndex; // 合同类别 property DealType: string read FDealType write FDealType; // 建设单位 // 名称 property BName: string read FBName write FBName; // 法人代表 property BLegal: string read FBLegal write FBLegal; // 签订日期 property BDate: string read FBDate write FBDate; // 施工单位 // 名称 property CName: string read FCName write FCName; // 法人代表 property CLegal: string read FCLegal write FCLegal; // 签订日期 property CDate: string read FCDate write FCDate; // 监理单位 // 名称 property SName: string read FSName write FSName; // 法人代表 property SLegal: string read FSLegal write FSLegal; // 签订日期 property SDate: string read FSDate write FSDate; {技术参数} // 公路等级 property LoadLevel: Integer read FLoadLevel write FLoadLevel; // 起点桩号 property StartPeg: string read FStartPeg write FStartPeg; // 终点桩号 property EndPeg: string read FEndPeg write FEndPeg; // 长度 property LoadLength: Double read FLoadLength write FLoadLength; // 车道数 property LaneCount: Integer read FLaneCount write FLaneCount; {合同支付} property ContractPrice: Double read FContractPrice write SetContractPrice; property MaterialSubsist: Double read FMaterialSubsist write SetMaterialSubsist; property StartedSubsisit: Double read FStartedSubsist write SetStartedSubsist; {密码} // 解锁台账编辑节点密码 property UnlockInfoPassword: string read FUnlockInfoPassword write SetUnlockInfoPassword; {小数位数} property DecimalManager: TDecimalManager read FDecimalManager; // 数量 property QuantityDigit: Integer read FQuantityDigit write SetQuantityDigit; property QuantityFormat: string read FQuantityFormat; // 金额 property TotalPriceDigit: Integer read FTotalPriceDigit write SetTotalPriceDigit; property TotalPriceFormat: string read FTotalPriceFormat; // 单价 property PriceDigit: Integer read FPriceDigit; property PriceFormat: string read FPriceFormat; {升级标记} property UpdateFlag: Integer read FUpdateFlag write SetUpdateFlag; {Base} // 计量期数 property PhaseIndex: Integer read FPhaseIndex write SetPhaseIndex; property PhaseCount: Integer read FPhaseCount write SetPhaseCount; property ZJJLPreText: string read FZJJLPreText write SetZJJLPreText; {View} // Can Modify In ProjectPropertiesFrm property ShowPriceChange: Boolean read FShowPriceChange write SetShowPriceChange; property ShowBGLCode: Boolean read FShowBGLCode write SetShowBGLCode; property ShowDesignQuantity: Boolean read FShowDesignQuantity write SetShowDesignQuantity; property ShowAlias: Boolean read FShowAlias write SetShowAlias; end; implementation { TPropertyInquiry } function TPropertyInquiry.CheckPropertyExist(const AName: string): Boolean; begin Result := False; FSql := Format('Select * From %s Where Name = ''%s''', [TableName, UpperCase(AName)]); ExecuteSql; Result := FInquriyQuery.RecordCount > 0; FInquriyQuery.Close; end; constructor TPropertyInquiry.Create(AConnection: TADOConnection); begin FConnection := AConnection; FInquriyQuery := TADOQuery.Create(nil); FInquriyQuery.Connection := FConnection; end; destructor TPropertyInquiry.Destroy; begin FInquriyQuery.Free; inherited; end; procedure TPropertyInquiry.ExecuteSql(AIsSelect: Boolean); begin FInquriyQuery.Close; FInquriyQuery.SQL.Clear; FInquriyQuery.SQL.Add(FSql); if AIsSelect then FInquriyQuery.Open else FInquriyQuery.ExecSQL; end; function TPropertyInquiry.GetNewID: Integer; begin FSql := Format('Select Max(ID) As MaxID From %s', [TableName]); ExecuteSql; if FInquriyQuery.RecordCount > 0 then Result := FInquriyQuery.FieldByName('MaxID').AsInteger + 1 else Result := 0; FInquriyQuery.Close; end; function TPropertyInquiry.GetValue(const AName: string): Variant; begin FSql := Format('Select * From %s Where Name = ''%s''', [TableName, UpperCase(AName)]); ExecuteSql; if FInquriyQuery.RecordCount > 0 then Result := FInquriyQuery.FieldByName('PropValue').AsVariant else Result := Null; FInquriyQuery.Close; end; procedure TPropertyInquiry.SetValue(const AName: string; const Value: Variant); function GetUpdateSql: string; begin if VarIsNull(Value) then Result := Format('Delete From %s Where Name = ''%s''', [TableName, UpperCase(AName)]) else begin if CheckPropertyExist(AName) then Result := Format('Update %s Set PropValue = ''%s'' Where Name = ''%s''', [TableName, VarToStr(Value), UpperCase(AName)]) else Result := Format('Insert Into %s (ID, Name, PropValue) Values (%d, ''%s'', ''%s'')', [TableName, GetNewID, UpperCase(AName), VarToStr(Value)]); end; end; begin FSql := GetUpdateSql; ExecuteSql(False); FInquriyQuery.Close; end; { TProjProperties } constructor TProjProperties.Create(AProjectData: TObject); begin FProjectData := AProjectData; FDecimalManager := TDecimalManager.Create(AProjectData); end; destructor TProjProperties.Destroy; begin FPropertyInqurity.Free; FDecimalManager.Free; inherited; end; function TProjProperties.GetAuditCompany: string; begin Result := GetStrPropertyDef('AuditCompany', ''); end; function TProjProperties.GetAuditStatus: Integer; begin Result := GetIntPropertyDef('AuditStatus', -1); end; function TProjProperties.GetAuditStatusStr: string; begin case AuditStatus of -1: if PhaseCount = 0 then Result := '原报' else Result := '批复'; 0: Result := '原报'; else Result := Format('%d 审', [AuditStatus]); end; end; function TProjProperties.GetBoolPropertyDef(const AName: string; ADef: Boolean): Boolean; var vProperty: Variant; begin vProperty := FPropertyInqurity.Value[AName]; if VarIsNull(vProperty) then Result := ADef else Result := Boolean(vProperty); end; function TProjProperties.GetDisplayFormat(ADigit: Integer): string; begin case ADigit of 0: Result := '#'; 1: Result := '#.#'; 2: Result := '#.##'; 3: Result := '#.###'; 4: Result := '#.####'; 5: Result := '#.#####'; 6: Result := '#.######'; 7: Result := '#.#######'; 8: Result := '#.########'; 9: Result := '#.#########'; else Result := '#.##########'; end; end; function TProjProperties.GetFinalAuditCount: Integer; begin Result := GetIntPropertyDef('FinalAuditCount', 0); end; function TProjProperties.GetFloatPropertyDef(const AName: string; ADef: Double): Double; var sValue: Variant; begin sValue := GetStrPropertyDef(AName, FloatToStr(ADef)); Result := StrToFloatDef(sValue, ADef); end; function TProjProperties.GetIntPropertyDef(const AName: string; ADef: Integer): Integer; var sValue: Variant; begin sValue := GetStrPropertyDef(AName, IntToStr(ADef)); Result := StrToIntDef(sValue, ADef); end; function TProjProperties.GetStrPropertyDef(const AName, ADef: string): string; var vProperty: Variant; begin vProperty := FPropertyInqurity.Value[AName]; Result := VarToStrDef(vProperty, ADef); end; procedure TProjProperties.LoadBaseProperties; begin FPhaseCount := GetIntPropertyDef('PhaseCount', 0); FLockedLedgerData := GetBoolPropertyDef('LockedLedgerData', False); FContractPrice := GetFloatPropertyDef('ContractPrice', 0); FStartedSubsist := GetFloatPropertyDef('StartedSubsist', 0); FMaterialSubsist := GetFloatPropertyDef('MaterialSubsist', 0); FZJJLPreText := GetStrPropertyDef('ZJJLPreText', ''); end; procedure TProjProperties.LoadCalcParameters; begin FQuantityDigit := GetIntPropertyDef('QuantityDigit', 3); FQuantityFormat := GetDisplayFormat(FQuantityDigit); FTotalPriceDigit := GetIntPropertyDef('TotalPriceDigit', 0); FTotalPriceFormat := GetDisplayFormat(FTotalPriceDigit); FPriceDigit := 2; FPriceFormat := GetDisplayFormat(FPriceDigit); with FDecimalManager.Common do begin Quantity.Digit := GetIntPropertyDef('QuantityDigit', 3); TotalPrice.Digit := GetIntPropertyDef('TotalPriceDigit', 0); Price.Digit := 2; end; with FDecimalManager do begin Compile.Quantity.Digit := GetIntPropertyDef('QuantityDigit1', Common.Quantity.Digit); Compile.TotalPrice.Digit := GetIntPropertyDef('TotalPriceDigit1', Common.TotalPrice.Digit); Compile.Price.Digit := 2; end; with FDecimalManager do begin PriceMargin.Quantity.Digit := Common.Quantity.Digit; PriceMargin.TotalPrice.Digit := Common.TotalPrice.Digit; PriceMargin.Price.Digit := 3;//GetIntPropertyDef('PM_PriceDigit', Common.Price.Digit); end; end; procedure TProjProperties.LoadDealInfo; begin FProjectName := GetStrPropertyDef('ProjectName', ''); FDealName := GetStrPropertyDef('DealName', ''); FDealIndex := GetStrPropertyDef('DealIndex', ''); FDealType := GetStrPropertyDef('DealType', ''); FBName := GetStrPropertyDef('BName', ''); FBLegal := GetStrPropertyDef('BLegal', ''); FBDate := GetStrPropertyDef('BDate', ''); FCName := GetStrPropertyDef('CName', ''); FCLegal := GetStrPropertyDef('CLegal', ''); FCDate := GetStrPropertyDef('CDate', ''); FSName := GetStrPropertyDef('SName', ''); FSLegal := GetStrPropertyDef('SLegal', ''); FSDate := GetStrPropertyDef('SDate', ''); end; procedure TProjProperties.LoadTechParameters; begin FLoadLevel := GetIntPropertyDef('LoadLevel', 0); FStartPeg := GetStrPropertyDef('StartPeg', ''); FEndPeg := GetStrPropertyDef('EndPeg', ''); FLoadLength := GetFloatPropertyDef('LoadLength', 0); FLaneCount := GetIntPropertyDef('LaneCount', 0); end; procedure TProjProperties.LoadViewProperties; begin FShowPriceChange := GetBoolPropertyDef('ShowPriceChange', False); FShowBGLCode := GetBoolPropertyDef('ShowBGLCode', True); FShowDesignQuantity := GetBoolPropertyDef('ShowDesignQuantity', False); FShowAlias := GetBoolPropertyDef('ShowAlias', False); end; procedure TProjProperties.Open(AConnection: TADOConnection); begin FPropertyInqurity := TPropertyInquiry.Create(AConnection); FPropertyInqurity.TableName := 'ProjProperties'; LoadBaseProperties; LoadViewProperties; LoadDealInfo; LoadTechParameters; LoadCalcParameters; FUnlockInfoPassword := GetStrPropertyDef('UnlockInfoPassword', ''); FUpdateFlag := GetIntPropertyDef('UpdateFlag', 0); end; procedure TProjProperties.Save; begin SaveDealInfo; SaveTechParameters; SaveCalcParameters; end; procedure TProjProperties.SaveCalcParameters; begin with FDecimalManager do begin {FPropertyInqurity.Value['QuantityDigit'] := Common.Quantity.Digit; FPropertyInqurity.Value['TotalPriceDigit'] := Common.TotalPrice.Digit; FPropertyInqurity.Value['QuantityDigit1'] := Compile.Quantity.Digit; FPropertyInqurity.Value['TotalPriceDigit1'] := Compile.TotalPrice.Digit;} //FPropertyInqurity.Value['PM_PriceDigit'] := PriceMargin.Price.Digit; end; end; procedure TProjProperties.SaveDealInfo; begin FPropertyInqurity.Value['ProjectName'] := FProjectName; FPropertyInqurity.Value['DealName'] := FDealName; FPropertyInqurity.Value['DealIndex'] := FDealIndex; FPropertyInqurity.Value['DealType'] := FDealType; FPropertyInqurity.Value['BName'] := FBName; FPropertyInqurity.Value['BLegal'] := FBLegal; FPropertyInqurity.Value['BDate'] := FBDate; FPropertyInqurity.Value['CName'] := FCName; FPropertyInqurity.Value['CLegal'] := FCLegal; FPropertyInqurity.Value['CDate'] := FCDate; FPropertyInqurity.Value['SName'] := FSName; FPropertyInqurity.Value['SLegal'] := FSLegal; FPropertyInqurity.Value['SDate'] := FSDate; end; procedure TProjProperties.SaveTechParameters; begin FPropertyInqurity.Value['LoadLevel'] := FLoadLevel; FPropertyInqurity.Value['StartPeg'] := FStartPeg; FPropertyInqurity.Value['EndPeg'] := FEndPeg; FPropertyInqurity.Value['LoadLength'] := FLoadLength; FPropertyInqurity.Value['LaneCount'] := FLaneCount; end; procedure TProjProperties.SetAuditCompany(const Value: string); begin FPropertyInqurity.Value['AuditCompany'] := Value; end; procedure TProjProperties.SetAuditStatus(const Value: Integer); begin FPropertyInqurity.Value['AuditStatus'] := Value; end; procedure TProjProperties.SetContractPrice(const Value: Double); begin FContractPrice := Value; FPropertyInqurity.Value['ContractPrice'] := Value; end; procedure TProjProperties.SetFinalAuditCount(const Value: Integer); begin FPropertyInqurity.Value['FinalAuditCount'] := Value; end; procedure TProjProperties.SetLockedLedgerData(const Value: Boolean); begin FLockedLedgerData := Value; FPropertyInqurity.Value['LockedLedgerData'] := Value; end; procedure TProjProperties.SetMaterialSubsist(const Value: Double); begin FMaterialSubsist := Value; FPropertyInqurity.Value['MaterialSubsist'] := Value; end; procedure TProjProperties.SetPhaseCount(const Value: Integer); begin FPhaseCount := Value; FPropertyInqurity.Value['PhaseCount'] := Value; end; procedure TProjProperties.SetPhaseIndex(const Value: Integer); begin FPhaseIndex := Value; FPropertyInqurity.Value['PhaseIndex'] := Value; end; procedure TProjProperties.SetQuantityDigit(const Value: Integer); begin FQuantityDigit := Value; FPropertyInqurity.Value['QuantityDigit'] := Value; FQuantityFormat := GetDisplayFormat(FQuantityDigit); end; procedure TProjProperties.SetShowAlias(const Value: Boolean); begin FShowAlias := Value; FPropertyInqurity.Value['ShowAlias'] := Value; end; procedure TProjProperties.SetShowBGLCode(const Value: Boolean); begin FShowBGLCode := Value; FPropertyInqurity.Value['ShowBGLCode'] := Value; end; procedure TProjProperties.SetShowDesignQuantity(const Value: Boolean); begin FShowDesignQuantity := Value; FPropertyInqurity.Value['ShowDesignQuantity'] := Value; end; procedure TProjProperties.SetShowPriceChange(const Value: Boolean); begin FShowPriceChange := Value; FPropertyInqurity.Value['ShowPriceChange'] := Value; end; procedure TProjProperties.SetStartedSubsist(const Value: Double); begin FStartedSubsist := Value; FPropertyInqurity.Value['StartedSubsist'] := Value; end; procedure TProjProperties.SetTotalPriceDigit(const Value: Integer); begin FTotalPriceDigit := Value; FPropertyInqurity.Value['TotalPriceDigit'] := Value; FTotalPriceFormat := GetDisplayFormat(FTotalPriceDigit); end; procedure TProjProperties.SetUnlockInfoPassword(const Value: string); begin FUnlockInfoPassword := Value; FPropertyInqurity.Value['UnlockInfoPassword'] := Value; end; procedure TProjProperties.SetUpdateFlag(const Value: Integer); begin FUpdateFlag := Value; FPropertyInqurity.Value['UpdateFlag'] := Value; end; procedure TProjProperties.SetZJJLPreText(const Value: string); begin FZJJLPreText := Value; FPropertyInqurity.Value['ZJJLPreText'] := Value; end; end.