Advertisement
filhotecmail

LotePesquisa.Fornecedores

Oct 14th, 2017
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 5.99 KB | None | 0 0
  1. unit LotePesquisa.Fornecedores;
  2.  
  3. interface
  4.  
  5. uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
  6.   Vcl.Controls,Forms,Dialogs,DB,
  7.   FireDAC.Stan.Intf, FireDAC.Stan.Option,
  8.   FireDAC.Stan.Error,FireDAC.UI.Intf, FireDAC.Phys.Intf, FireDAC.Stan.Def, FireDAC.Stan.Pool,
  9.   FireDAC.Stan.Async, FireDAC.Phys,FireDAC.Phys.FB, FireDAC.Phys.FBDef, FireDAC.VCLUI.Wait, FireDAC.Comp.Client;
  10.  
  11.  
  12.  
  13.  type ILotePesquisaFornecedor = Interface
  14.       ['{09ED3C04-3CD8-418D-B2CD-C1E07DA04EFB}']
  15.       Procedure AddConnection(aConnection: TFDconnection);
  16.       Procedure Conect;
  17.       Function ReturnTable: TFDquery;
  18.       Procedure Pesquisa(aDescricaoForn,aCnpj: string);
  19.  End;
  20.  
  21.  type TLotePesquisaFornecedor = Class(TInterfacedObject,ILotePesquisaFornecedor )
  22.  
  23.     private
  24.     {Private declaration}
  25.     var LoteFornTable: TFDquery;
  26.     Function Asql: String;
  27.     Procedure Pesquisa(aDescricaoForn,aCnpj: string);
  28.     Var Connectionserver: TFDConnection;
  29.     Procedure AddConnection(aConnection: TFDconnection);
  30.     Procedure Conect;
  31.     Function ReturnTable: TFDquery;
  32.     protected
  33.     {Protected declaration}
  34.     public
  35.     {Public declaration declaration}
  36.     Function NewILotePesquisaFornecedor: ILotePesquisaFornecedor;
  37.  
  38.       constructor Create; (*Metodos do Constructor*)
  39.       destructor Destroy; override;
  40.  
  41.     published
  42.     {Protected declaration}
  43.     end;
  44.  
  45.  
  46.  {$IFDEF RTL230_UP}
  47.   [ComponentPlatformsAttribute(pidWin32 or pidWin64)]
  48.  {$ENDIF RTL230_UP}
  49.  
  50.  type TBeforeChabgeRecord = procedure of object;
  51.  
  52.  type TLotePesquisaForn = class(TComponent)
  53.       private
  54.     FConexao: TFDConnection;
  55.     LoteForn: ILotePesquisaFornecedor;
  56.     FBeforeChangeRecord: TBeforeChabgeRecord;
  57.     procedure setConexao(const Value: TFDConnection);
  58.     function GetTableFornecedor: TFDquery;
  59.     function GetConnect: TObject;
  60.     function GetBeforeChangeRecord: TNotifyEvent;
  61.     procedure SetBeforeChangeRecord(const Value: TNotifyEvent);
  62.  
  63.       {Private declaration}
  64.       protected
  65.       {Protected declaration}
  66.       public
  67.       {Public declaration declaration}
  68.       Procedure AfterConstruction; Override;
  69.       Procedure BeforeDestruction; Override;
  70.     constructor Create(AOwner: TComponent); override;
  71.     Destructor Destroy; override;
  72.  
  73.       published
  74.       {Protected declaration}
  75.       property Conexao: TFDConnection read FConexao write setConexao;
  76.       property TableFornecedor: TFDquery read GetTableFornecedor;
  77.       property ConnecttoTable: TObject read GetConnect;
  78.       Procedure Pesquisar(aDescrField,aCnpjField: string);
  79.       property BeforeChangeRecord: TBeforeChabgeRecord read FBeforeChangeRecord write FBeforeChangeRecord;
  80.       Procedure BeforeChangeRecordEvent();
  81.       Procedure BeforeScroll(Dataset: TDataset);
  82.       procedure register;
  83.       end;
  84.  
  85. implementation
  86. { TLotePesquisaForn }
  87. uses Lote.FrmPesquisaFornecedores;
  88.  
  89. procedure TLotePesquisaForn.AfterConstruction;
  90. begin
  91.   inherited AfterConstruction;
  92.  
  93. end;
  94.  
  95. procedure TLotePesquisaForn.BeforeChangeRecordEvent;
  96. begin
  97.   if Assigned(FBeforeChangeRecord) then
  98.      FBeforeChangeRecord();
  99. end;
  100.  
  101. procedure TLotePesquisaForn.BeforeDestruction;
  102. begin
  103.   inherited BeforeDestruction;
  104.   FrmLotePesquisaFornecedor.Close;
  105.   FrmLotePesquisaFornecedor.DisposeOf;
  106. end;
  107.  
  108. procedure TLotePesquisaForn.BeforeScroll(Dataset: TDataset);
  109. begin
  110.    BeforeChangeRecordEvent;
  111. end;
  112.  
  113. constructor TLotePesquisaForn.Create(AOwner: TComponent);
  114. begin
  115.   inherited create( AOwner );
  116.   LoteForn:= TLotePesquisaFornecedor.Create;
  117.  
  118. end;
  119.  
  120. destructor TLotePesquisaForn.Destroy;
  121. begin
  122.  
  123.   inherited;
  124. end;
  125.  
  126.  
  127. function TLotePesquisaForn.GetBeforeChangeRecord: TNotifyEvent;
  128. begin
  129.  
  130. end;
  131.  
  132. function TLotePesquisaForn.GetConnect: TObject;
  133. begin
  134.   LoteForn.Conect;
  135.   FrmLotePesquisaFornecedor:= TFrmLotePesquisaFornecedor.create(Application);
  136.   FrmLotePesquisaFornecedor.DsLoteForn.DataSet := LoteForn.ReturnTable;
  137.   FrmLotePesquisaFornecedor.showModal;
  138.  
  139. end;
  140.  
  141. function TLotePesquisaForn.GetTableFornecedor: TFDquery;
  142. begin
  143.   Result:= LoteForn.ReturnTable;
  144.   Result.BeforeScroll:= Self.BeforeScroll;
  145.  
  146. end;
  147.  
  148.  
  149. procedure TLotePesquisaForn.Pesquisar(aDescrField, aCnpjField: string);
  150. begin
  151.   LoteForn.Pesquisa(aDescrField,aCnpjField);
  152. end;
  153.  
  154. procedure TLotePesquisaForn.register;
  155. begin
  156.  RegisterComponents('Leopard',[TLotePesquisaForn]);
  157.  
  158. end;
  159.  
  160. procedure TLotePesquisaForn.SetBeforeChangeRecord(const Value: TNotifyEvent);
  161. begin
  162.  
  163. end;
  164.  
  165. procedure TLotePesquisaForn.setConexao(const Value: TFDConnection);
  166. begin
  167.    FConexao := Value;
  168.    LoteForn.AddConnection(FConexao);
  169. end;
  170.  
  171. { TLotePesquisaFornecedor }
  172.  
  173. procedure TLotePesquisaFornecedor.AddConnection(aConnection: TFDconnection);
  174. begin
  175.  self.Connectionserver:= aConnection;
  176. end;
  177.  
  178. function TLotePesquisaFornecedor.Asql: String;
  179. begin
  180.  Result:= ' select ID, DATA, HORA, USUARIO, NOMERAZAO, FANTASIAAPELIDO, CNPJ, IE, IM, SUFRAMA, LOGADOURO, NUMERO, COMPLEMENTO, '+
  181.  ' BAIRRO, MUNICIPIO, ESTADO, UF, PAIS, CEP, TELEFONE, FAX, CELULAR, REPRESCOMERCIAL, EMAIL, WEBSITE, SIT, '+
  182.  ' CATEGORIA, OBS, IBGE_CODUF, IBGE_CODMUNI, IBGE_CODPAIS, IBGE_PAISISO3, FUNDACAO '+
  183.  ' from CAD_FORNECEDOR ';
  184.  
  185. end;
  186.  
  187. procedure TLotePesquisaFornecedor.Conect;
  188. begin
  189.   LoteFornTable := TFDquery.Create(Nil);
  190.   LoteFornTable.Connection := Connectionserver;
  191.   LoteFornTable.SQL.Text := Asql;
  192.   LoteFornTable.Open();
  193.  
  194. end;
  195.  
  196. constructor TLotePesquisaFornecedor.Create;
  197. begin
  198.  
  199. end;
  200.  
  201. destructor TLotePesquisaFornecedor.Destroy;
  202. begin
  203.  
  204.   inherited;
  205. end;
  206.  
  207. function TLotePesquisaFornecedor.NewILotePesquisaFornecedor: ILotePesquisaFornecedor;
  208. begin
  209.   Result:= TLotePesquisaFornecedor.Create;
  210. end;
  211.  
  212. procedure TLotePesquisaFornecedor.Pesquisa(aDescricaoForn, aCnpj: string);
  213. begin
  214.    LoteFornTable.Filtered:= False;
  215.    LoteFornTable.Filter := 'Upper (NOMERAZAO) Like' + quotedStr(Ansiuppercase('%'+aDescricaoForn+'%'));
  216.    LoteFornTable.Filtered:= True;
  217.  
  218. end;
  219.  
  220. function TLotePesquisaFornecedor.ReturnTable: TFDquery;
  221. begin
  222.  Result:= LoteFornTable;
  223. end;
  224.  
  225. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement