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; FShowReportShading: Boolean; FReportShading: string; FBaseline: string; FDeadline: string; FDealPayAloneDigit: Boolean; FReportShowState: Boolean; FReportShowStateWithoutReply: Boolean; FReportShowStateText: string; FDealPhase: string; 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 LoadDateTime; 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); procedure SetReportShading(const Value: string); procedure SetShowReportShading(const Value: Boolean); procedure SetBaseline(const Value: string); procedure SetDeadline(const Value: string); procedure SetDealPayAloneDigit(const Value: Boolean); procedure SetReportShowState(const Value: Boolean); procedure SetReportShowStateText(const Value: string); procedure SetReportShowStateWithoutReply(const Value: Boolean); public constructor Create(AProjectData: TObject); destructor Destroy; override; procedure Open(AConnection: TADOConnection); procedure Save; procedure Reload; {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 DealPhase: string read FDealPhase write FDealPhase; {合同支付} 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 DealPayAloneDigit: Boolean read FDealPayAloneDigit write SetDealPayAloneDigit; 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 Baseline: string read FBaseline write SetBaseline; // 结束时间 property Deadline: string read FDeadline write SetDeadline; {升级标记} 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; property ShowReportShading: Boolean read FShowReportShading write SetShowReportShading; property ReportShading: string read FReportShading write SetReportShading; property ReportShowState: Boolean read FReportShowState write SetReportShowState; property ReportShowStateText: string read FReportShowStateText write SetReportShowStateText; property ReportShowStateWithoutReply: Boolean read FReportShowStateWithoutReply write SetReportShowStateWithoutReply; 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 := '0'; 1: Result := '0.#'; 2: Result := '0.##'; 3: Result := '0.###'; 4: Result := '0.####'; 5: Result := '0.#####'; 6: Result := '0.######'; 7: Result := '0.#######'; 8: Result := '0.########'; 9: Result := '0.#########'; else Result := '0.##########'; 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 FDealPayAloneDigit := GetBoolPropertyDef('DealPayAloneDigit', False); 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; with FDecimalManager do begin DealPay.TotalPrice.Digit := GetIntPropertyDef('DealPayTPDigit', Common.TotalPrice.Digit); if FDealPayAloneDigit then DealPay.RelaCalcDecimal := nil else DealPay.RelaCalcDecimal := Common; end; end; procedure TProjProperties.LoadDateTime; begin FBaseline := GetStrPropertyDef('Baseline', ''); FDeadline := GetStrPropertyDef('Deadline', ''); 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); FDealPhase := GetStrPropertyDef('DealPhase', ''); end; procedure TProjProperties.LoadViewProperties; begin FShowPriceChange := GetBoolPropertyDef('ShowPriceChange', False); FShowBGLCode := GetBoolPropertyDef('ShowBGLCode', True); FShowDesignQuantity := GetBoolPropertyDef('ShowDesignQuantity', False); FShowAlias := GetBoolPropertyDef('ShowAlias', False); FShowReportShading := GetBoolPropertyDef('ShowReportShading', False); FReportShading := GetStrPropertyDef('ReportShading', ''); FReportShowState := GetBoolPropertyDef('ReportShowState', True); FReportShowStateText := GetStrPropertyDef('ReportShowStateText', '标段未批复'); FReportShowStateWithoutReply := GetBoolPropertyDef('ReportShowStateWithoutReply', True); end; procedure TProjProperties.Open(AConnection: TADOConnection); begin FPropertyInqurity := TPropertyInquiry.Create(AConnection); FPropertyInqurity.TableName := 'ProjProperties'; LoadBaseProperties; LoadViewProperties; LoadDealInfo; LoadTechParameters; LoadCalcParameters; LoadDateTime; FUnlockInfoPassword := GetStrPropertyDef('UnlockInfoPassword', ''); FUpdateFlag := GetIntPropertyDef('UpdateFlag', 0); end; procedure TProjProperties.Reload; begin LoadBaseProperties; LoadViewProperties; LoadDealInfo; LoadTechParameters; LoadCalcParameters; FUnlockInfoPassword := GetStrPropertyDef('UnlockInfoPassword', ''); end; procedure TProjProperties.Save; begin SaveDealInfo; SaveTechParameters; SaveCalcParameters; // 无意义,不可删除,Sql最后一句不执行,写多一句,以保证完整执行 FPropertyInqurity.Value['Complete'] := True; end; procedure TProjProperties.SaveCalcParameters; begin if FPhaseCount > 0 then Exit; FPropertyInqurity.Value['DealPayAloneDigit'] := FDealPayAloneDigit; 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; FPropertyInqurity.Value['DealPayTPDigit'] := DealPay.TotalPrice.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; FPropertyInqurity.Value['DealPhase'] := FDealPhase; 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.SetBaseline(const Value: string); begin FBaseline := Value; FPropertyInqurity.Value['Baseline'] := Value; end; procedure TProjProperties.SetContractPrice(const Value: Double); begin FContractPrice := Value; FPropertyInqurity.Value['ContractPrice'] := Value; end; procedure TProjProperties.SetDeadline(const Value: string); begin FDeadline := Value; FPropertyInqurity.Value['Deadline'] := Value; end; procedure TProjProperties.SetDealPayAloneDigit(const Value: Boolean); begin FDealPayAloneDigit := Value; if Value then DecimalManager.DealPay.RelaCalcDecimal := nil else DecimalManager.DealPay.RelaCalcDecimal := DecimalManager.Common; 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.SetReportShading(const Value: string); begin FReportShading := Value; FPropertyInqurity.Value['ReportShading'] := Value; end; procedure TProjProperties.SetReportShowState(const Value: Boolean); begin FReportShowState := Value; FPropertyInqurity.Value['ReportShowState'] := Value; end; procedure TProjProperties.SetReportShowStateText(const Value: string); begin FReportShowStateText := Value; FPropertyInqurity.Value['ReportShowStateText'] := Value; end; procedure TProjProperties.SetReportShowStateWithoutReply( const Value: Boolean); begin FReportShowStateWithoutReply := Value; FPropertyInqurity.Value['ReportShowStateWithoutReply'] := Value; 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.SetShowReportShading(const Value: Boolean); begin FShowReportShading := Value; FPropertyInqurity.Value['ShowReportShading'] := 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.