unit phDataEd;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, Grids, RXGrids, ActnList, ComCtrls, ToolWin;

type
  TfmPhDataEd = class(TForm)
    gdPhData: TRxDrawGrid;
    CoolBar1: TCoolBar;
    ToolBar1: TToolBar;
    ToolButton1: TToolButton;
    ActionList1: TActionList;
    actOpenFile: TAction;
    ToolButton2: TToolButton;
    actSaveFile: TAction;
    actGraph: TAction;
    ToolButton3: TToolButton;
    procedure gdPhDataDrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    procedure FormCreate(Sender: TObject);
    procedure gdPhDataGetEditText(Sender: TObject; ACol, ARow: Integer;
      var Value: String);
    procedure gdPhDataSetEditText(Sender: TObject; ACol, ARow: Integer;
      const Value: String);
    procedure actOpenFileExecute(Sender: TObject);
    procedure actSaveFileExecute(Sender: TObject);
    procedure actGraphExecute(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fmPhDataEd: TfmPhDataEd;

implementation

uses Data, FormHolder, GraphBaseSt, phDataGr;

{$R *.DFM}

procedure TfmPhDataEd.gdPhDataDrawCell(Sender: TObject; ACol,
  ARow: Integer; Rect: TRect; State: TGridDrawState);
begin
   with Sender as TRxDrawGrid do
   case ARow of
     0     : case ACol of
               0    : DrawStr(Rect,'Α/Α',taCenter);
               else   DrawStr(Rect,shortMonthNames[ACol],taCenter);
             end;
     else    case ACol of
               0    : DrawStr(Rect,Format('%0.2d:00-%0.2d:00',[Arow-1,Arow]),taCenter);
               else   DrawStr(rect,Format('%0.3f',[phFactors[ACol,ARow]]),taCenter);
             end
   end;
end;

procedure TfmPhDataEd.FormCreate(Sender: TObject);
begin
  gdPhData.ColWidths[0] := 2 * gdPhData.ColWidths[1];
end;

procedure TfmPhDataEd.gdPhDataGetEditText(Sender: TObject; ACol,
  ARow: Integer; var Value: String);
begin
  Value := Format('%0.3f',[phFactors[ACol,ARow]]);;
end;

procedure TfmPhDataEd.gdPhDataSetEditText(Sender: TObject; ACol,
  ARow: Integer; const Value: String);
begin
  phFactors[ACol,ARow] := StrToFloat(Value);
end;

procedure TfmPhDataEd.actOpenFileExecute(Sender: TObject);
begin
  with TOpenDialog.Create(Self) do
  try
    DefaultExt  := 'pph';
    Filter      := 'Φωτοβολταϊκά Δεδομένα|*.pph';
    FilterIndex := 1;
    if Execute then
    begin
      phFactors.LoadFromFile(FileName);
      gdphData.Refresh;
    end;
  finally
    Free;
  end;
end;

procedure TfmPhDataEd.actSaveFileExecute(Sender: TObject);
begin
  with TSaveDialog.Create(Self) do
  try
    DefaultExt  := 'pph';
    Filter      := 'Φωτοβολταϊκά Δεδομένα|*.pph';
    FilterIndex := 1;
    if Execute then
    begin
      phFactors.SaveToFile(FileName);
      gdphData.Refresh;
    end;
  finally
    Free;
  end;
end;

procedure TfmPhDataEd.actGraphExecute(Sender: TObject);
begin
  HoldFormClass(fmHolder.pnlHolder,fmHolder.Panel1,true,false,TFmPhDataGr);
end;

end.
