unit PhaseProperty;

interface

uses
  ProjectProperty, ADODB, Variants, SysUtils;

type
  TPhaseProperties = class
  private
    FPropertyInqurity: TPropertyInquiry;
    FFinalAudit: Boolean;
    FAuditCount: Integer;
    FPayablePrice: Double;

    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;

    procedure CreateInqurity(AConnection: TADOConnection);
    procedure LoadBaseProperties;

    procedure SetFinalAudit(const Value: Boolean);
    procedure SetAuditCount(const Value: Integer);
    function GetZJJLType: Integer;
    procedure SetZJJLType(const Value: Integer);
    procedure SetZjjlVersion(const Value: Integer);
    function GetZjjlVersion: Integer;
    function GetZJJLPreText: string;
    procedure SetZJJLPreText(const Value: string);
  public
    constructor Create(AConnection: TADOConnection);
    destructor Destroy; override;

    procedure Open;
    procedure Save;

    property AuditCount: Integer read FAuditCount write SetAuditCount;
    property FinalAudit: Boolean read FFinalAudit write SetFinalAudit;

    property ZJJLType: Integer read GetZJJLType write SetZJJLType;
    property ZJJLPreText: string read GetZJJLPreText write SetZJJLPreText;
    property ZjjlVersion: Integer read GetZjjlVersion write SetZjjlVersion;
  end;

implementation

{ TPhaseProperties }

constructor TPhaseProperties.Create(AConnection: TADOConnection);
begin
  CreateInqurity(AConnection);
end;

procedure TPhaseProperties.CreateInqurity(AConnection: TADOConnection);
begin
  FPropertyInqurity := TPropertyInquiry.Create(AConnection);
  FPropertyInqurity.TableName := 'PhaseProperty';
end;

destructor TPhaseProperties.Destroy;
begin
  FPropertyInqurity.Free;
  inherited;
end;

function TPhaseProperties.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 TPhaseProperties.GetFloatPropertyDef(const AName: string;
  ADef: Double): Double;
var
  sValue: Variant;
begin
  sValue := GetStrPropertyDef(AName, FloatToStr(ADef));
  Result := StrToFloatDef(sValue, ADef);
end;

function TPhaseProperties.GetIntPropertyDef(const AName: string;
  ADef: Integer): Integer;
var
  sValue: Variant;
begin
  sValue := GetStrPropertyDef(AName, IntToStr(ADef));
  Result := StrToIntDef(sValue, ADef);
end;

function TPhaseProperties.GetStrPropertyDef(const AName,
  ADef: string): string;
var
  vProperty: Variant;
begin
  vProperty := FPropertyInqurity.Value[AName];
  Result := VarToStrDef(vProperty, ADef);
end;

function TPhaseProperties.GetZJJLPreText: string;
begin
  Result := GetStrPropertyDef('ZJJLPreText', '');
end;

function TPhaseProperties.GetZJJLType: Integer;
begin
  Result := GetIntPropertyDef('ZJJLType', 0);
end;

function TPhaseProperties.GetZjjlVersion: Integer;
begin
  Result := GetIntPropertyDef('ZjjlVersion', 0);
end;

procedure TPhaseProperties.LoadBaseProperties;
begin
  FFinalAudit := GetBoolPropertyDef('FinalAudit', False);
  FAuditCount := GetIntPropertyDef('AuditCount', 0);
end;

procedure TPhaseProperties.Open;
begin
  LoadBaseProperties;
end;

procedure TPhaseProperties.Save;
begin

end;

procedure TPhaseProperties.SetAuditCount(const Value: Integer);
begin
  FAuditCount := Value;
  FPropertyInqurity.Value['AuditCount'] := FAuditCount;
end;

procedure TPhaseProperties.SetFinalAudit(const Value: Boolean);
begin
  FFinalAudit := Value;
  FPropertyInqurity.Value['FinalAudit'] := FFinalAudit;
end;

procedure TPhaseProperties.SetZJJLPreText(const Value: string);
begin
  FPropertyInqurity.Value['ZJJLPreText'] := Value;
end;

procedure TPhaseProperties.SetZJJLType(const Value: Integer);
begin
  FPropertyInqurity.Value['ZJJLType'] := Value;
end;

procedure TPhaseProperties.SetZjjlVersion(const Value: Integer);
begin
  FPropertyInqurity.Value['ZjjlVersion'] := Value;
end;

end.
