Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit LeopardGerenciador.BaseClass.InjectableBaseclass.InjectableBaseClassModel;
- interface
- uses
- System.Classes,
- System.SysUtils,
- System.VarUtils,
- System.Variants,
- // Vcl
- vcl.Dialogs,
- Vcl.Graphics,
- Vcl.ExtCtrls,
- Vcl.Forms,
- Vcl.StdCtrls,
- Vcl.Consts,
- Vcl.Controls,
- Data.DB,
- // Leopard
- LeopardDriverDataset,
- FireDAC.Phys.Intf,FireDAC.Stan.Option, FireDAC.Stan.Intf, FireDAC.Comp.Client,
- Dialog.Rai.Model;
- Type TAlertEvent = procedure of object;
- type TRefresData = procedure( RecCount: Integer ) of object;
- type TRefresData<T> = procedure( Result: T ) of object;
- type TInjectableBaseClassModel = class
- type TResponseClass = class
- DataL: TArray<TLeopardDriverDataset>;
- Data: TArray<TDataSet>;
- end;
- type TParametrosClass = class
- private
- FDescricao: string;
- FCodeBar: string;
- FNroLancamento: integer;
- FDataFinal: TDate;
- FDataInicial: TDate;
- FSituacaodavenda: String;
- FNumeroPDV: String;
- procedure SetCodeBar(const Value: string);
- procedure SetDataFinal(const Value: TDate);
- procedure SetDataInicial(const Value: TDate);
- procedure SetDescricao(const Value: string);
- procedure SetNroLancamento(const Value: integer);
- procedure SetNumeroPDV(const Value: String);
- procedure SetSituacaodavenda(const Value: String);
- published
- property Descricao: string read FDescricao write SetDescricao;
- property DataInicial: TDate read FDataInicial write SetDataInicial;
- property DataFinal: TDate read FDataFinal write SetDataFinal;
- property CodeBar: string read FCodeBar write SetCodeBar;
- property NroLancamento: integer read FNroLancamento write SetNroLancamento;
- property NumeroPDV: String read FNumeroPDV write SetNumeroPDV;
- property Situacaodavenda: String read FSituacaodavenda write SetSituacaodavenda;
- end;
- (*Eventos para a classe Base*)
- type TEventsClass = class
- private
- FOnRefreshDataEvent: TRefresData;
- procedure SetOnRefreshDataEvent(const Value: TRefresData);
- published
- property OnRefreshDataEvent: TRefresData read FOnRefreshDataEvent write SetOnRefreshDataEvent;
- end;
- (*Base classe para eventos do Firedac TFDEventAlert*)
- type TPostEventFB = class
- private
- FEventAlertFD: TFDEventAlerter;
- FAlertEvent: TAlertEvent;
- procedure SetEventAlertFD(const Value: TFDEventAlerter);
- procedure SetAlertEvent(const Value: TAlertEvent);
- procedure EventAlert(ASender: TFDCustomEventAlerter;
- const AEventName: String; const AArgument: Variant);
- public
- procedure AfterConstruction; override;
- procedure BeforeDestruction; override;
- property EventAlertFD: TFDEventAlerter read FEventAlertFD write SetEventAlertFD;
- property AlertEvent: TAlertEvent read FAlertEvent write SetAlertEvent;
- end;
- private
- FResponse: TResponseClass;
- FParametros: TParametrosClass;
- FEventos: TEventsClass;
- FUsePostEvent: Boolean;
- FConnection: TFDCustomConnection;
- FNameEvent: string;
- FPostEventFB: TPostEventFB;
- procedure SetEventos(const Value: TEventsClass);
- procedure SetParametros(const Value: TParametrosClass);
- procedure SetResponse(const Value: TResponseClass);
- procedure setFUsePostEvent(const Value: Boolean);
- procedure SetConnection(const Value: TFDCustomConnection);
- procedure SetNameEvent(const Value: string);
- procedure SetPostEventFB(const Value: TPostEventFB);
- public
- procedure AfterConstruction; override;
- procedure BeforeDestruction; override;
- property PostEventFB: TPostEventFB read FPostEventFB write SetPostEventFB;
- property Response:TResponseClass read FResponse write SetResponse;
- property Parametros: TParametrosClass read FParametros write SetParametros;
- property Eventos: TEventsClass read FEventos write SetEventos;
- property UsePostEvent: Boolean read FUsePostEvent write setFUsePostEvent;
- property NameEvent: string read FNameEvent write SetNameEvent;
- property Connection: TFDCustomConnection read FConnection write SetConnection;
- end;
- implementation
- { TInjectableBaseClassModel }
- procedure TInjectableBaseClassModel.AfterConstruction;
- begin
- inherited AfterConstruction;
- FResponse := TResponseClass.Create;
- FParametros := TParametrosClass.Create;
- FEventos := TEventsClass.Create;
- FPostEventFB:= TPostEventFB.Create;
- end;
- procedure TInjectableBaseClassModel.BeforeDestruction;
- begin
- inherited BeforeDestruction;
- FreeAndNil( FResponse );
- FreeAndNil( FParametros );
- FreeAndNil( FEventos );
- FreeAndNil( FPostEventFB );
- end;
- procedure TInjectableBaseClassModel.SetConnection(const Value: TFDCustomConnection);
- begin
- FConnection := Value;
- FPostEventFB.EventAlertFD.Connection := Value;
- end;
- procedure TInjectableBaseClassModel.SetEventos(const Value: TEventsClass);
- begin
- FEventos := Value;
- end;
- procedure TInjectableBaseClassModel.setFUsePostEvent(const Value: Boolean);
- begin
- FUsePostEvent := Value;
- if FNameEvent <> EmptyStr then
- begin
- if FConnection <> nil then
- FPostEventFB.EventAlertFD.Active := Value
- else
- raise Exception.Create('Para usar o Post_Event é necessário informar uma conexão do tipo Firedac');
- end else
- raise Exception.Create('Primeiro informe o nome do post_Event');
- end;
- procedure TInjectableBaseClassModel.SetNameEvent(const Value: string);
- begin
- FNameEvent := Value;
- if UsePostEvent then
- FPostEventFB.EventAlertFD.Names.Add(Value);
- end;
- procedure TInjectableBaseClassModel.SetParametros(const Value: TParametrosClass);
- begin
- FParametros := Value;
- end;
- procedure TInjectableBaseClassModel.SetPostEventFB(const Value: TPostEventFB);
- begin
- FPostEventFB := Value;
- end;
- procedure TInjectableBaseClassModel.SetResponse(const Value: TResponseClass);
- begin
- FResponse := Value;
- end;
- { TInjectableBaseClassModel.TParametrosClass }
- procedure TInjectableBaseClassModel.TParametrosClass.SetCodeBar(const Value: string);
- begin
- FCodeBar := Value;
- end;
- procedure TInjectableBaseClassModel.TParametrosClass.SetDataFinal(const Value: TDate);
- begin
- FDataFinal := Value;
- end;
- procedure TInjectableBaseClassModel.TParametrosClass.SetDataInicial(const Value: TDate);
- begin
- FDataInicial := Value;
- end;
- procedure TInjectableBaseClassModel.TParametrosClass.SetDescricao(const Value: string);
- begin
- FDescricao := Value;
- end;
- procedure TInjectableBaseClassModel.TParametrosClass.SetNroLancamento(const Value: integer);
- begin
- FNroLancamento := Value;
- end;
- procedure TInjectableBaseClassModel.TParametrosClass.SetNumeroPDV(const Value: String);
- begin
- FNumeroPDV := Value;
- end;
- procedure TInjectableBaseClassModel.TParametrosClass.SetSituacaodavenda(const Value: String);
- begin
- FSituacaodavenda := Value;
- end;
- { TInjectableBaseClassModel.TPostEventFB }
- procedure TInjectableBaseClassModel.TPostEventFB.AfterConstruction;
- begin
- inherited AfterConstruction;
- EventAlertFD := TFDEventAlerter.Create(nil);
- EventAlertFD.OnAlert := EventAlert;
- end;
- procedure TInjectableBaseClassModel.TPostEventFB.BeforeDestruction;
- begin
- inherited AfterConstruction;
- FreeAndNil( FEventAlertFD );
- end;
- procedure TInjectableBaseClassModel.TPostEventFB.EventAlert(ASender: TFDCustomEventAlerter; const AEventName: String;
- const AArgument: Variant);
- begin
- if Assigned(FAlertEvent) then
- FAlertEvent;
- end;
- procedure TInjectableBaseClassModel.TPostEventFB.SetAlertEvent(const Value: TAlertEvent);
- begin
- FAlertEvent := Value;
- end;
- procedure TInjectableBaseClassModel.TPostEventFB.SetEventAlertFD(const Value: TFDEventAlerter);
- begin
- FEventAlertFD := Value;
- end;
- { TInjectableBaseClassModel.TEventsClass }
- procedure TInjectableBaseClassModel.TEventsClass.SetOnRefreshDataEvent(const Value: TRefresData);
- begin
- FOnRefreshDataEvent := Value;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement