Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit View.Components.Grid001;
- interface
- uses
- Winapi.Windows,
- Winapi.Messages,
- System.SysUtils,
- System.Variants,
- System.Classes,
- Vcl.Graphics,
- Vcl.Controls,
- Vcl.Forms,
- Vcl.Dialogs,
- Data.DB,
- Vcl.Grids,
- Vcl.DBGrids,
- Vcl.ExtCtrls,
- MidasLib,
- View.Components.Interfaces,
- View.Components.Attributes.Interfaces,
- View.Services.ComponentsCount,
- View.Styles.States,
- View.Components.Attributes,
- Datasnap.DBClient, Datasnap.Provider;
- type
- TComponentGrid001 = class(TFrame, iComponents<TComponentGrid001>)
- Panel1: TPanel;
- DBGrid1: TDBGrid;
- ClientDataSet1: TClientDataSet;
- DataSource1: TDataSource;
- DataSetProvider1: TDataSetProvider;
- procedure DBGrid1TitleClick(Column: TColumn);
- private
- { Private declarations }
- FAttributes : iComponentAttributes<TComponentGrid001>;
- FContainer : TWinControl;
- FDataSource : TDataSource;
- public
- { Public declarations }
- constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
- function Component : TWinControl;
- function Attributes : iComponentAttributes<TComponentGrid001>;
- function LoadAttributes (aValue : String) : TComponentGrid001;
- function Container (aValue : TWinControl) : iComponents<TComponentGrid001>;
- function DataSource (aValue : TDataSource) : TComponentGrid001;
- function This : TComponentGrid001;
- end;
- implementation
- {$R *.dfm}
- { TComponentGrid001 }
- function TComponentGrid001.Attributes: iComponentAttributes<TComponentGrid001>;
- begin
- Result := FAttributes;
- end;
- function TComponentGrid001.Component: TWinControl;
- begin
- Result := Panel1;
- if Assigned(FContainer) then
- Panel1.Parent:=FContainer;
- Name:= 'Frame_'+IntToStr(TServiceComponentsCount.CountInc);
- Panel1.Align := alClient;
- Panel1.Color:= FAttributes.BackGround;
- DataSetProvider1.DataSet:=FDataSource.DataSet;
- ClientDataset1.ProviderName:=DataSetProvider1.Name;
- ClientDataset1.Active:=True;
- DataSource1.DataSet:=ClientDataset1;
- // DBGrid1.DataSource:=FDataSource;
- DBGrid1.DataSource:=DataSource1;
- end;
- function TComponentGrid001.Container(
- aValue: TWinControl): iComponents<TComponentGrid001>;
- begin
- Result := Self;
- FContainer := aValue;
- end;
- constructor TComponentGrid001.Create(AOwner: TComponent);
- begin
- inherited;
- FAttributes := TComponentAttributes<TComponentGrid001>.New(Self);
- FDataSource := TDataSource.Create(nil);
- end;
- function TComponentGrid001.DataSource(aValue: TDataSource): TComponentGrid001;
- begin
- Result := Self;
- FDataSource.DataSet := aValue.DataSet;
- end;
- procedure TComponentGrid001.DBGrid1TitleClick(Column: TColumn);
- var
- indexName : string;
- ordenacao : TIndexOptions;
- i : integer;
- begin
- //retirar a formatação de negrito de todas as coluunas
- for I := 0 to DBGrid1.Columns.Count -1 do
- begin
- DBGrid1.Columns[i].title.font.Style:=[];
- DBGrid1.Columns[i].title.font.Color:=clBlack;
- end;
- //congfigurar a ordenação
- if ClientDataSet1.IndexName = Column.FieldName + '_ASC' then
- begin
- indexName := Column.FieldName + '_DESC';
- ordenacao := [ixDescending];
- end
- else
- begin
- indexName := Column.FieldName + '_ASC';
- ordenacao := [];
- end;
- //adiciona a formatação no dataset, caso não exista
- if ClientDataset1.IndexDefs.IndexOf(indexName)<0 then
- ClientDataSet1.AddIndex(indexName, Column.FieldName, ordenacao);
- ClientDataSet1.IndexDefs.Update;
- //formata o título da coluna
- Column.title.font.Style:=[fsBold];
- Column.title.font.Color:=clRed;
- //atribui a ordenação selecionada
- ClientDataSet1.IndexName := indexName;
- end;
- destructor TComponentGrid001.Destroy;
- begin
- FDataSource.Free;
- inherited;
- end;
- function TComponentGrid001.LoadAttributes(aValue: String): TComponentGrid001;
- var
- FLoadAttributes : iComponentAttributes<TComponentGrid001>;
- begin
- Result := Self;
- FLoadAttributes := (StylesStates.GetStyle(aValue) as iComponentAttributes<TComponentGrid001>);
- FAttributes := FLoadAttributes.Clone;
- FAttributes.Parent(Self);
- end;
- function TComponentGrid001.This: TComponentGrid001;
- begin
- Result := Self;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement