Advertisement
filhotecmail

InjectableBaseClassModel

Feb 27th, 2020
621
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 8.01 KB | None | 0 0
  1. unit LeopardGerenciador.BaseClass.InjectableBaseclass.InjectableBaseClassModel;
  2.  
  3. interface
  4.  
  5.   uses
  6.     System.Classes,
  7.     System.SysUtils,
  8.     System.VarUtils,
  9.     System.Variants,
  10.     // Vcl
  11.     vcl.Dialogs,
  12.     Vcl.Graphics,
  13.     Vcl.ExtCtrls,
  14.     Vcl.Forms,
  15.     Vcl.StdCtrls,
  16.     Vcl.Consts,
  17.     Vcl.Controls,
  18.     Data.DB,
  19.    // Leopard
  20.     LeopardDriverDataset,
  21.     FireDAC.Phys.Intf,FireDAC.Stan.Option, FireDAC.Stan.Intf, FireDAC.Comp.Client,
  22.     Dialog.Rai.Model;
  23.  
  24.   Type TAlertEvent = procedure of object;
  25.   type TRefresData = procedure( RecCount: Integer ) of object;
  26.   type TRefresData<T> = procedure( Result: T ) of object;
  27.   type TInjectableBaseClassModel = class
  28.  
  29.     type TResponseClass = class
  30.      DataL: TArray<TLeopardDriverDataset>;
  31.      Data: TArray<TDataSet>;
  32.     end;
  33.  
  34.     type TParametrosClass = class
  35.       private
  36.         FDescricao: string;
  37.         FCodeBar: string;
  38.         FNroLancamento: integer;
  39.         FDataFinal: TDate;
  40.         FDataInicial: TDate;
  41.         FSituacaodavenda: String;
  42.         FNumeroPDV: String;
  43.         procedure SetCodeBar(const Value: string);
  44.         procedure SetDataFinal(const Value: TDate);
  45.         procedure SetDataInicial(const Value: TDate);
  46.         procedure SetDescricao(const Value: string);
  47.         procedure SetNroLancamento(const Value: integer);
  48.         procedure SetNumeroPDV(const Value: String);
  49.         procedure SetSituacaodavenda(const Value: String);
  50.       published
  51.  
  52.      property Descricao: string read FDescricao write SetDescricao;
  53.      property DataInicial: TDate read FDataInicial write SetDataInicial;
  54.      property DataFinal: TDate read FDataFinal write SetDataFinal;
  55.      property CodeBar: string read FCodeBar write SetCodeBar;
  56.      property NroLancamento: integer read FNroLancamento write SetNroLancamento;
  57.      property NumeroPDV: String read FNumeroPDV write SetNumeroPDV;
  58.      property Situacaodavenda: String read FSituacaodavenda write SetSituacaodavenda;
  59.  
  60.     end;
  61.     (*Eventos para a classe Base*)
  62.  
  63.     type TEventsClass = class
  64.       private
  65.         FOnRefreshDataEvent: TRefresData;
  66.         procedure SetOnRefreshDataEvent(const Value: TRefresData);
  67.       published
  68.       property OnRefreshDataEvent: TRefresData read FOnRefreshDataEvent write SetOnRefreshDataEvent;
  69.  
  70.     end;
  71.     (*Base classe para eventos do Firedac TFDEventAlert*)
  72.  
  73.     type TPostEventFB = class
  74.       private
  75.         FEventAlertFD: TFDEventAlerter;
  76.         FAlertEvent: TAlertEvent;
  77.         procedure SetEventAlertFD(const Value: TFDEventAlerter);
  78.         procedure SetAlertEvent(const Value: TAlertEvent);
  79.          procedure EventAlert(ASender: TFDCustomEventAlerter;
  80.          const AEventName: String; const AArgument: Variant);
  81.  
  82.       public
  83.         procedure AfterConstruction; override;
  84.         procedure BeforeDestruction; override;
  85.         property EventAlertFD: TFDEventAlerter read FEventAlertFD write SetEventAlertFD;
  86.         property AlertEvent: TAlertEvent read FAlertEvent write SetAlertEvent;
  87.     end;
  88.  
  89.   private
  90.     FResponse: TResponseClass;
  91.     FParametros: TParametrosClass;
  92.     FEventos: TEventsClass;
  93.     FUsePostEvent: Boolean;
  94.     FConnection: TFDCustomConnection;
  95.     FNameEvent: string;
  96.     FPostEventFB: TPostEventFB;
  97.     procedure SetEventos(const Value: TEventsClass);
  98.     procedure SetParametros(const Value: TParametrosClass);
  99.     procedure SetResponse(const Value: TResponseClass);
  100.     procedure setFUsePostEvent(const Value: Boolean);
  101.     procedure SetConnection(const Value: TFDCustomConnection);
  102.     procedure SetNameEvent(const Value: string);
  103.     procedure SetPostEventFB(const Value: TPostEventFB);
  104.  
  105.   public
  106.     procedure AfterConstruction; override;
  107.     procedure BeforeDestruction; override;
  108.     property PostEventFB: TPostEventFB read FPostEventFB write SetPostEventFB;
  109.     property Response:TResponseClass read FResponse write SetResponse;
  110.     property Parametros: TParametrosClass read FParametros write SetParametros;
  111.     property Eventos: TEventsClass read FEventos write SetEventos;
  112.     property UsePostEvent: Boolean read FUsePostEvent write setFUsePostEvent;
  113.     property NameEvent: string read FNameEvent write SetNameEvent;
  114.     property Connection: TFDCustomConnection read FConnection write SetConnection;
  115.  
  116.   end;
  117.  
  118. implementation
  119.  
  120. { TInjectableBaseClassModel }
  121.  
  122. procedure TInjectableBaseClassModel.AfterConstruction;
  123. begin
  124.   inherited AfterConstruction;
  125.   FResponse   := TResponseClass.Create;
  126.   FParametros := TParametrosClass.Create;
  127.   FEventos    := TEventsClass.Create;
  128.   FPostEventFB:= TPostEventFB.Create;
  129. end;
  130.  
  131. procedure TInjectableBaseClassModel.BeforeDestruction;
  132. begin
  133.   inherited BeforeDestruction;
  134.   FreeAndNil( FResponse );
  135.   FreeAndNil( FParametros );
  136.   FreeAndNil( FEventos );
  137.   FreeAndNil( FPostEventFB );
  138. end;
  139.  
  140. procedure TInjectableBaseClassModel.SetConnection(const Value: TFDCustomConnection);
  141. begin
  142.   FConnection := Value;
  143.   FPostEventFB.EventAlertFD.Connection := Value;
  144. end;
  145.  
  146. procedure TInjectableBaseClassModel.SetEventos(const Value: TEventsClass);
  147. begin
  148.   FEventos := Value;
  149. end;
  150.  
  151. procedure TInjectableBaseClassModel.setFUsePostEvent(const Value: Boolean);
  152. begin
  153.  FUsePostEvent := Value;
  154.   if FNameEvent <> EmptyStr then
  155.   begin
  156.    if FConnection <> nil then
  157.        FPostEventFB.EventAlertFD.Active := Value
  158.        else
  159.        raise Exception.Create('Para usar o Post_Event é necessário informar uma conexão do tipo Firedac');
  160.   end else
  161.   raise Exception.Create('Primeiro informe o nome do post_Event');
  162.  
  163. end;
  164.  
  165. procedure TInjectableBaseClassModel.SetNameEvent(const Value: string);
  166. begin
  167.   FNameEvent := Value;
  168.   if UsePostEvent then
  169.    FPostEventFB.EventAlertFD.Names.Add(Value);
  170. end;
  171.  
  172. procedure TInjectableBaseClassModel.SetParametros(const Value: TParametrosClass);
  173. begin
  174.   FParametros := Value;
  175. end;
  176.  
  177. procedure TInjectableBaseClassModel.SetPostEventFB(const Value: TPostEventFB);
  178. begin
  179.   FPostEventFB := Value;
  180. end;
  181.  
  182. procedure TInjectableBaseClassModel.SetResponse(const Value: TResponseClass);
  183. begin
  184.   FResponse := Value;
  185. end;
  186.  
  187. { TInjectableBaseClassModel.TParametrosClass }
  188.  
  189. procedure TInjectableBaseClassModel.TParametrosClass.SetCodeBar(const Value: string);
  190. begin
  191.   FCodeBar := Value;
  192. end;
  193.  
  194. procedure TInjectableBaseClassModel.TParametrosClass.SetDataFinal(const Value: TDate);
  195. begin
  196.   FDataFinal := Value;
  197. end;
  198.  
  199. procedure TInjectableBaseClassModel.TParametrosClass.SetDataInicial(const Value: TDate);
  200. begin
  201.   FDataInicial := Value;
  202. end;
  203.  
  204. procedure TInjectableBaseClassModel.TParametrosClass.SetDescricao(const Value: string);
  205. begin
  206.   FDescricao := Value;
  207. end;
  208.  
  209. procedure TInjectableBaseClassModel.TParametrosClass.SetNroLancamento(const Value: integer);
  210. begin
  211.   FNroLancamento := Value;
  212. end;
  213.  
  214. procedure TInjectableBaseClassModel.TParametrosClass.SetNumeroPDV(const Value: String);
  215. begin
  216.   FNumeroPDV := Value;
  217. end;
  218.  
  219. procedure TInjectableBaseClassModel.TParametrosClass.SetSituacaodavenda(const Value: String);
  220. begin
  221.   FSituacaodavenda := Value;
  222. end;
  223.  
  224. { TInjectableBaseClassModel.TPostEventFB }
  225.  
  226. procedure TInjectableBaseClassModel.TPostEventFB.AfterConstruction;
  227. begin
  228.   inherited AfterConstruction;
  229.   EventAlertFD := TFDEventAlerter.Create(nil);
  230.   EventAlertFD.OnAlert := EventAlert;
  231. end;
  232.  
  233. procedure TInjectableBaseClassModel.TPostEventFB.BeforeDestruction;
  234. begin
  235.   inherited AfterConstruction;
  236.   FreeAndNil( FEventAlertFD );
  237. end;
  238.  
  239. procedure TInjectableBaseClassModel.TPostEventFB.EventAlert(ASender: TFDCustomEventAlerter; const AEventName: String;
  240.   const AArgument: Variant);
  241. begin
  242.  if Assigned(FAlertEvent) then
  243.    FAlertEvent;
  244. end;
  245.  
  246. procedure TInjectableBaseClassModel.TPostEventFB.SetAlertEvent(const Value: TAlertEvent);
  247. begin
  248.   FAlertEvent := Value;
  249. end;
  250.  
  251. procedure TInjectableBaseClassModel.TPostEventFB.SetEventAlertFD(const Value: TFDEventAlerter);
  252. begin
  253.   FEventAlertFD := Value;
  254. end;
  255.  
  256. { TInjectableBaseClassModel.TEventsClass }
  257.  
  258. procedure TInjectableBaseClassModel.TEventsClass.SetOnRefreshDataEvent(const Value: TRefresData);
  259. begin
  260.    FOnRefreshDataEvent := Value;
  261. end;
  262.  
  263. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement