unit P3V_TypyUkolu;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, P3KvaFormQV, AdvUtil, Vcl.Menus,
  System.ImageList, Vcl.ImgList, System.Actions, Vcl.ActnList, KvaActionSource,
  Vcl.Grids, AdvObj, BaseGrid, AdvGrid, AdvGlowButton, Vcl.ExtCtrls, P3SysTxt,
  Vcl.StdCtrls, GradientLabel, AdvPanel, P3ObjPPC, P3Types, P3Global;

type
  TV_TypyUkolu = class(TKvaFormQV)
    procedure OQvyberDblClickCell(Sender: TObject; ARow, ACol: Integer);
    procedure OQvyberGetAlignment(Sender: TObject; ARow, ACol: Integer;
      var HAlign: TAlignment; var VAlign: TVAlignment);
    procedure OQvyberGetDisplText(Sender: TObject; ACol, ARow: Integer;
      var Value: string);
  private
    { Private declarations }
  public
    { Public declarations }
    TypyUkolu:TKvaTypUkoluList;
    VybTypUkolu:TKvaTypUkolu;
    procedure Vybrat; override;
    procedure NeVybrat; override;
    procedure InitGrid(which:smallint); override;
    procedure ReFillGrid(which:smallint;whichnot:smallint); override;
    procedure InitFirstGo; override;
    procedure InitForm(NewSectiom:TKvaTypeSection); override;
    constructor CreateNew(AOwner:TComponent; Dummy: Integer=0); override;
  end;

var
  V_TypyUkolu: TV_TypyUkolu;

implementation

{$R *.dfm}

constructor TV_TypyUkolu.CreateNew(AOwner: TComponent; Dummy: Integer);
begin
  inherited;
   ReadComponentResFile(GUnitsDir+'\P3V_TypyUkolu.dfm',self);
end;

procedure TV_TypyUkolu.InitFirstGo;
begin
   Constraints.MinHeight:= 300;
   Constraints.MinWidth:= 300;
   Constraints.MaxHeight:=GMaxHeight;
   Constraints.MaxWidth:=GMaxWidth;
  inherited;
   ACfiltrv.Visible:=false;
   ACallitems.Visible:=false;
   ACactitems.Visible:=false;
   ACInsert.Visible:=false;
   ACEdit.Visible:=false;
   ACDelete.Visible:=false;
   XEheadtext.Caption:=TxtCaption('5VyberUkolu');
   OQvyber.Visible:=true;
   OQvyber.RowCount:=2;
   OQvyber.FixedRows:=1;
   OQvyber.Options := OQvyber.Options + [goRowSelect];
   OQvyber.ColCount:=3;
   OQvyber.ColWidths[0]:=20;
   OQvyber.ColWidths[1]:=80;
   OQvyber.ColWidths[2]:=200;
   FirstGo:=false;
   FindGo(OQvyber);
end;

procedure TV_TypyUkolu.InitForm(NewSectiom: TKvaTypeSection);
begin
  inherited;
   SetWidthCol(SetFormular);
   InitGrid(0);
   ReFillGrid(0,0);
end;

procedure TV_TypyUkolu.InitGrid(which: smallint);
begin
  inherited;
   OQvyber.DefaultRowHeight:=12+((Lsf_Vybery*4)*FDefPixel);
   OQvyber.RowHeights[0]:=30+((Lsf_Vybery*4)*FDefPixel);
end;

procedure TV_TypyUkolu.NeVybrat;
begin
  inherited;
   VybTypUkolu:=nil;
end;

procedure TV_TypyUkolu.OQvyberDblClickCell(Sender: TObject; ARow,
  ACol: Integer);
begin
  inherited;
  if ARow>0 then
    ACsave.Execute;
end;

procedure TV_TypyUkolu.OQvyberGetAlignment(Sender: TObject; ARow, ACol: Integer;
  var HAlign: TAlignment; var VAlign: TVAlignment);
begin
  inherited;
  if ARow=0 then
   HAlign:=taCenter
  else
    case ACol of
      2,3: HAlign:=taLeftJustify;
      else HAlign:=taCenter;
    end;
end;

procedure TV_TypyUkolu.OQvyberGetDisplText(Sender: TObject; ACol, ARow: Integer;
  var Value: string);
begin
  inherited;
  if ARow>0 then
    begin
      var shTypyUkolu:=TypyUkolu.TypUkolu[ARow-1];
      if shTypyUkolu<>nil then
        case ACol of
        1:  Value:=shTypyUkolu.zkrtyp;
        2:  Value:=shTypyUkolu.naztyp;
        end;
    end;
end;

procedure TV_TypyUkolu.ReFillGrid(which, whichnot: smallint);
var
   NumRecords:integer;
   SomeRecord:boolean;
begin
  inherited;
   NumRecords:=0;
   SomeRecord:=false;
   if (TypyUkolu<>nil) then
   begin
      NumRecords:=TypyUkolu.NumRows;
      SomeRecord:=NumRecords>0;
      if (SomeRecord) then OQvyber.RowCount:=NumRecords+1
      else OQvyber.RowCount:=1;
   end else
   begin
      OQvyber.RowCount:=1;
   end;
   ACsave.Enabled:=SomeRecord;
   OQvyber.Invalidate;
end;

procedure TV_TypyUkolu.Vybrat;
begin
  inherited;
   if (TypyUkolu<>nil)and(TypyUkolu.NumRows>0) then
   VybTypUkolu:=TypyUkolu.TypUkolu[OQvyber.Row-1];
end;

end.
