Advertisement
filhotecmail

Abstract Factory 2

Sep 9th, 2017
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 6.12 KB | None | 0 0
  1. {*******************************************************}
  2. {                                                       }
  3. {       FrentePDV                                       }
  4. {                                                       }
  5. {       Copyright (C) 2017 Leopard report               }
  6. {   C:\Leopard\Pdv\CentralDeConfiguracao\SourceProj\    }
  7. {- CentraldeConfiguracao  1.0.0.244                     }
  8. {                     08/09/2017 16:39:20               }
  9. { Devenvolvedor: Carlos Alberto Dias da Silva Filho     }
  10. {*******************************************************}
  11.  
  12. unit CentralConfigFactory;
  13.  
  14. interface
  15.  
  16.  uses Vcl.Forms,FrmConfigSat,  SatModelEngine,Dialogs,JvExComCtrls, JvComCtrls, JvDialogs,Types,Windows,
  17.       JvComponentBase, JvComputerInfoEx, FrmMiscelanias, Sistema.Model,FireDAC.Phys.FBDef, FireDAC.UI.Intf, FireDAC.VCLUI.Wait, FireDAC.Comp.UI,
  18.   FireDAC.Stan.Intf, FireDAC.Phys, FireDAC.Phys.IBBase, FireDAC.Phys.FB, FireDAC.Stan.Option, FireDAC.Stan.Param,
  19.   FireDAC.Stan.Error, FireDAC.DatS, FireDAC.Phys.Intf, FireDAC.DApt.Intf, FireDAC.Stan.Async, FireDAC.DApt,
  20.   FireDAC.Stan.Def, FireDAC.Stan.Pool, Data.DB, FireDAC.Comp.Client, FireDAC.Comp.DataSet,System.SysUtils,System.Generics.Collections;
  21.  
  22. type
  23.   ICentral = interface
  24.   ['{21BC9C81-9302-4029-B46B-25E28070463F}']
  25.     function CreateConfigSatForm:TForm;
  26.     function CreateFrmMisc: TForm;
  27.     function CreateSat:TObject;
  28.     function CarregaDllSat: String;
  29.     function RetornaNomedoComputador:string;
  30.     function CriaInformacoesCpu: TJvComputerInfoEx;
  31.     function CriaConfigSistemas: TObject;
  32.     procedure LimpaMemoriaResidual;
  33.     procedure CreateConexaoBaseDados;
  34.   end;
  35.  
  36.   IAbstractCentral = interface
  37.   ['{3530B3E6-14C0-4C9E-B5F6-C76B28229A5D}']
  38.     function CreateIAbstractProduct: ICentral;
  39.   end;
  40.  
  41.   TCentralFactory = class(TInterfacedObject, ICentral)
  42.   private
  43.  
  44.   published
  45.     function CreateConfigSatForm:TForm;
  46.     function CreateFrmMisc: TForm;
  47.     function CreateSat:TObject;
  48.     function CarregaDllSat: String;
  49.     function RetornaNomedoComputador:string;
  50.     function CriaInformacoesCpu: TJvComputerInfoEx;
  51.     function CriaConfigSistemas: TObject;
  52.     procedure LimpaMemoriaResidual;
  53.     procedure CreateConexaoBaseDados;
  54.  
  55.   end;
  56.  
  57.   TConcreteCentral = class(TInterfacedObject, IAbstractCentral)
  58.   public
  59.     function CreateIAbstractProduct: ICentral;
  60.   end;
  61.  
  62.  type TGlobals = class
  63.    FrmConfigSatParam: TTfrmConfigSat;
  64.    CentralFactory: TConcreteCentral;
  65.    Central:  TCentralFactory;
  66.    Sat: TSatTableDaoModel;
  67.    FInfoCpu: TJvComputerInfoEx;
  68.    FrmMisc: TTfrmMiscelanias;
  69.    SistemaConfig: TSistema;
  70.    FConnectionPdv: TFDConnection;
  71.  End;
  72.  
  73.   type Obj = class Function Global: TObjectList<TGlobals>;
  74.   end;
  75.  
  76.     var  FrmConfigSatParam: TTfrmConfigSat;
  77.    CentralFactory: TConcreteCentral;
  78.    Central:  TCentralFactory;
  79.    Sat: TSatTableDaoModel;
  80.    FInfoCpu: TJvComputerInfoEx;
  81.    FrmMisc: TTfrmMiscelanias;
  82.    SistemaConfig: TSistema;
  83.    FConnectionPdv: TFDConnection;
  84. implementation
  85.  
  86.  
  87. uses
  88.   FuncoesLibraryClass;
  89. { TCentralFactory }
  90.  
  91. function TCentralFactory.CarregaDllSat: String;
  92.  var  aopen: TJvOpenDialog;
  93. begin
  94.  
  95.       aopen:= TJvOpenDialog.Create(nil);
  96.   try
  97.    if aopen.Execute then
  98.    Result:=  aopen.FileName;
  99.   finally
  100.     aopen.DisposeOf;
  101.   end;
  102. end;
  103.  
  104. procedure TCentralFactory.CreateConexaoBaseDados;
  105. begin
  106.  
  107.   CarregaWait('Preparando Carregamento dos dados',200);
  108.   FConnectionPdv:= TFDConnection.Create(Nil);
  109.   FConnectionPdv.Params.Clear;
  110.    CarregaWait('Tentando se conectar ao banco de dados',200);
  111.   FConnectionPdv.DriverName := 'FB';
  112.   FConnectionPdv.Params.Values['Server'] :=   '127.0.0.1';
  113.   FConnectionPdv.Params.Values['Database'] := 'C:\Leopard\PDV\PDV.FDB';
  114.   FConnectionPdv.Params.Values['User_Name'] := 'SYSDBA';
  115.   FConnectionPdv.Params.Values['Password'] := '1234';
  116.   FConnectionPdv.Params.Values['Port'] := '3050';
  117.   FConnectionPdv.Params.Values['DriveId'] := 'FB';
  118.   FConnectionPdv.LoginPrompt:= False;
  119.   CarregaWait('Tentando se conectar ao banco de dados',200);
  120.   try
  121.     try
  122.     FConnectionPdv.Connected:= True;
  123.     finally
  124.       CarregaWait('Conexao criada com sucesso!',200);
  125.     end;
  126.   except
  127.    on E: Exception do begin
  128.       raise Exception.Create('Não consegui conectar a base de dados do PDV, por favor revise as configurações ou'
  129.       +' verifique se o Arquivo PDV.FDB se encontra na pasta.');
  130.    end;
  131.   end;
  132.   end;
  133.  
  134. function TCentralFactory.CreateConfigSatForm: TForm;
  135. begin
  136.    CarregaWait('Carregando e criando dados do SAT',200);
  137.    FrmConfigSatParam:= TTfrmConfigSat.Create(Application);
  138.    Result:= FrmConfigSatParam;
  139.    FrmConfigSatParam.ShowModal;
  140. end;
  141.  
  142. function TCentralFactory.CreateFrmMisc: TForm;
  143. begin
  144.   CarregaWait('Carregando as Configurações da aplicação',500);
  145.   FrmMisc:= TTfrmMiscelanias.Create(Application);
  146.   Result := FrmMisc;
  147.   FrmMisc.ShowModal;
  148. end;
  149.  
  150. function TCentralFactory.CreateSat: TObject;
  151. begin
  152.     Sat:= TSatTableDaoModel.Create;
  153.     Result:= Sat;
  154. end;
  155.  
  156. function TCentralFactory.CriaConfigSistemas: TObject;
  157. begin
  158.    SistemaConfig:= TSistema.Create;
  159.    result:= SistemaConfig;
  160. end;
  161.  
  162. function TCentralFactory.CriaInformacoesCpu: TJvComputerInfoEx;
  163. begin
  164.  
  165.   Result:= TJvComputerInfoEx.Create(Nil);
  166.   FInfoCpu:= Result;
  167. end;
  168.  
  169. procedure TCentralFactory.LimpaMemoriaResidual;
  170. var
  171. MainHandle : THandle;
  172. begin
  173. try
  174. MainHandle := OpenProcess(PROCESS_ALL_ACCESS, false, GetCurrentProcessID) ;
  175. SetProcessWorkingSetSize(MainHandle, $FFFFFFFF, $FFFFFFFF) ;
  176. CloseHandle(MainHandle) ;
  177. except
  178. end;
  179. Application.ProcessMessages;
  180. end;
  181.  
  182. function TCentralFactory.RetornaNomedoComputador: string;
  183. var ipbuffer : string;
  184.       nsize : dword;
  185. begin
  186.    nsize := 255;
  187.    SetLength(ipbuffer,nsize);
  188.    if GetComputerName(pchar(ipbuffer),nsize) then
  189.       result := ipbuffer;
  190. end;
  191.  
  192. { TConcreteCentral }
  193.  
  194. function TConcreteCentral.CreateIAbstractProduct: ICentral;
  195. begin
  196.   Result := TCentralFactory.Create();
  197.  
  198. end;
  199.  
  200. { Obj }
  201.  
  202. function Obj.Global: TObjectList<TGlobals>;
  203.  var Objeto: TObjectList<TGlobals>; I: Integer;
  204. begin
  205.  
  206.  Objeto:= TObjectList<TGlobals>.Create();
  207.  result:= Objeto;
  208. end;
  209.  
  210. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement