unit OtherMeasureFme;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, JimPages, XPMenu, ComCtrls, ToolWin, ExtCtrls, sdGridDBA, ZJGrid,
  ProjectData;

type
  TOtherMeasureFrame = class(TFrame)
    pnlRelaXmjType: TPanel;
    tbToolsButton: TToolBar;
    tobtnPhase: TToolButton;
    tobtnOnce: TToolButton;
    xpm: TXPMenu;
    pnlOtherMeasure: TPanel;
    jpsOtherMeasure: TJimPages;
    jpsOtherMeasurePhase: TJimPage;
    jpsOtherMeasureOnce: TJimPage;
    zgPhase: TZJGrid;
    zgOnce: TZJGrid;
    saOnce: TsdGridDBA;
    saPhase: TsdGridDBA;
    procedure tobtnPhaseClick(Sender: TObject);
    procedure zgPhaseKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure zgPhaseCellGetColor(Sender: TObject; ACoord: TPoint;
      var AColor: TColor);
  private
    FProjectData: TProjectData;
    { Private declarations }
  public
    constructor Create(AProjectData: TProjectData);
    destructor Destroy; override;

    procedure ResetViewControl;
  end;

implementation

uses
  OtherMeasurePhaseDm, sdDB, ConditionalDefines;

{$R *.dfm}

constructor TOtherMeasureFrame.Create(AProjectData: TProjectData);
begin
  inherited Create(nil);
  FProjectData := AProjectData;
  saPhase.DataView := FProjectData.OtherMeasurePhaseData.sdvPhase;
  saOnce.DataView := FProjectData.OtherMeasureOnceData.sdvOnce;
  if not _IsDebugView then
    zgPhase.OnKeyDown := nil;
end;

destructor TOtherMeasureFrame.Destroy;
begin
  inherited;
end;

procedure TOtherMeasureFrame.ResetViewControl;
begin
  saPhase.Columns.ColumnByName('CurTotalPrice').ReadOnly := TProjectData(FProjectData).StageDataReadOnly;
  if TProjectData(FProjectData).AllowInsert then
    saPhase.Options := [aoAllowInsert, aoAllowEdit, aoAllowDelete, aoAutoInsert, aoAllowUpMove, aoAllowDownMove]
  else
    saPhase.Options := [];
end;

procedure TOtherMeasureFrame.tobtnPhaseClick(Sender: TObject);
begin
  jpsOtherMeasure.ActivePageIndex := TToolButton(Sender).Tag;
  tobtnPhase.Down := tobtnPhase.Tag = TToolButton(Sender).Tag;
  tobtnOnce.Down := tobtnOnce.Tag = TToolButton(Sender).Tag;
end;

procedure TOtherMeasureFrame.zgPhaseKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if (ssCtrl in Shift) and (ssShift in Shift) and (ssAlt in Shift)
      and (Key in [68, 100]) then // 'd', 'D'
  begin
    with FProjectData.OtherMeasurePhaseData do
      FilterDeletedRec := not FilterDeletedRec;
  end;
end;

procedure TOtherMeasureFrame.zgPhaseCellGetColor(Sender: TObject;
  ACoord: TPoint; var AColor: TColor);
var
  Rec: TsdDataRecord;
begin
  Rec := saPhase.DataView.Records[ACoord.Y-1];
  if Assigned(Rec) and Rec.ValueByName('Deleted').AsBoolean then
    AColor := $00D5D5D5
  else
    AColor := clWindow;
end;

end.
