Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit CentralConfigFactory;
- interface
- uses Vcl.Forms,FrmConfigSat, SatModelEngine,Dialogs,JvExComCtrls, JvComCtrls, JvDialogs,Types,Windows,
- JvComponentBase, JvComputerInfoEx, FrmMiscelanias, Sistema.Model,FireDAC.Phys.FBDef, FireDAC.UI.Intf, FireDAC.VCLUI.Wait, FireDAC.Comp.UI,
- FireDAC.Stan.Intf, FireDAC.Phys, FireDAC.Phys.IBBase, FireDAC.Phys.FB, FireDAC.Stan.Option, FireDAC.Stan.Param,
- FireDAC.Stan.Error, FireDAC.DatS, FireDAC.Phys.Intf, FireDAC.DApt.Intf, FireDAC.Stan.Async, FireDAC.DApt, FuncoesLibraryClass,
- FireDAC.Stan.Def, FireDAC.Stan.Pool, Data.DB, FireDAC.Comp.Client, FireDAC.Comp.DataSet,System.SysUtils,System.Generics.Collections;
- type
- ICentral = interface
- ['{21BC9C81-9302-4029-B46B-25E28070463F}']
- function CreateConfigSatForm:TForm;
- function CreateFrmMisc: TForm;
- function CreateSat:TObject;
- function CarregaDllSat: String;
- function RetornaNomedoComputador:string;
- function CriaInformacoesCpu: TJvComputerInfoEx;
- function CriaConfigSistemas: TObject;
- procedure LimpaMemoriaResidual;
- procedure CreateConexaoBaseDados;
- end;
- IAbstractCentral = interface
- ['{3530B3E6-14C0-4C9E-B5F6-C76B28229A5D}']
- function CreateIAbstractProduct: ICentral;
- end;
- TCentralFactory = class(TInterfacedObject, ICentral)
- private
- published
- function CreateConfigSatForm:TForm;
- function CreateFrmMisc: TForm;
- function CreateSat:TObject;
- function CarregaDllSat: String;
- function RetornaNomedoComputador:string;
- function CriaInformacoesCpu: TJvComputerInfoEx;
- function CriaConfigSistemas: TObject;
- procedure LimpaMemoriaResidual;
- procedure CreateConexaoBaseDados;
- function CriaObjetoEmail:TObject;
- end;
- TConcreteCentral = class(TInterfacedObject, IAbstractCentral)
- public
- function CreateIAbstractProduct: ICentral;
- end;
- type TLib = Class sealed
- procedure FormataCamposDataset(aDataset: TDataSet; aMascara: string);
- procedure Wait(Msg:String;time:Integer);
- End;
- type TGlobalForm = Class sealed
- FrmConfigSatParam: TTfrmConfigSat;
- FrmMisc: TTfrmMiscelanias;
- end;
- type TGlobals = class sealed
- CentralFactory: TConcreteCentral;
- Central: TCentralFactory;
- Sat: TSatTableDaoModel;
- FInfoCpu: TJvComputerInfoEx;
- SistemaConfig: TSistema;
- FConnectionPdv: TFDConnection;
- EmailClass: TConfigEmail;
- end;
- type tipos = (aClasses,aForms,aTlibrary);
- type Lista = class
- class function RetornaLista(arecord:tipos ):TObject;
- class function destroilista: Boolean;
- /// <summary> Retorna os Objetos de classes </summary>
- class var Objeto : TGlobals;
- /// <summary> Retorna os Objetos TForm </summary>
- class var ObjetoForm : TGlobalForm;
- class var Biblioteca : TLib;
- class constructor Create;
- class destructor destroy;
- end;
- var List: Lista;
- implementation
- { TCentralFactory }
- function TCentralFactory.CarregaDllSat: String;
- var aopen: TJvOpenDialog;
- begin
- aopen:= TJvOpenDialog.Create(nil);
- try
- if aopen.Execute then
- Result:= aopen.FileName;
- finally
- aopen.DisposeOf;
- end;
- end;
- procedure TCentralFactory.CreateConexaoBaseDados;
- begin
- CarregaWait('Preparando Carregamento dos dados',200);
- Lista.Objeto.FConnectionPdv:= TFDConnection.Create(Nil);
- List.objeto.FConnectionPdv.Params.Clear;
- CarregaWait('Tentando se conectar ao banco de dados',200);
- List.objeto.FConnectionPdv.DriverName := 'FB';
- List.objeto.FConnectionPdv.Params.Values['Server'] := '127.0.0.1';
- List.objeto.FConnectionPdv.Params.Values['Database'] := 'C:\Leopard\PDV\PDV.FDB';
- List.objeto.FConnectionPdv.Params.Values['User_Name'] := 'SYSDBA';
- List.objeto.FConnectionPdv.Params.Values['Password'] := '1234';
- List.objeto.FConnectionPdv.Params.Values['Port'] := '3050';
- List.objeto.FConnectionPdv.Params.Values['DriveId'] := 'FB';
- List.objeto.FConnectionPdv.LoginPrompt:= False;
- CarregaWait('Tentando se conectar ao banco de dados',200);
- try
- try
- List.objeto.FConnectionPdv.Connected:= True;
- finally
- CarregaWait('Conexao criada com sucesso!',200);
- end;
- except
- on E: Exception do begin
- raise Exception.Create('Não consegui conectar a base de dados do PDV, por favor revise as configurações ou'
- +' verifique se o Arquivo PDV.FDB se encontra na pasta.');
- end;
- end;
- end;
- function TCentralFactory.CreateConfigSatForm: TForm;
- begin
- CarregaWait('Carregando e criando dados do SAT',200);
- List.ObjetoForm.FrmConfigSatParam:= TTfrmConfigSat.Create(Application);
- Result:= List.ObjetoForm.FrmConfigSatParam;
- List.ObjetoForm.FrmConfigSatParam.ShowModal;
- end;
- function TCentralFactory.CreateFrmMisc: TForm;
- begin
- CarregaWait('Carregando as Configurações da aplicação',500);
- List.ObjetoForm.FrmMisc:= TTfrmMiscelanias.Create(Application);
- Result := List.ObjetoForm.FrmMisc;
- List.ObjetoForm.FrmMisc.ShowModal;
- end;
- function TCentralFactory.CreateSat: TObject;
- begin
- List.objeto.Sat:= TSatTableDaoModel.Create;
- Result:= List.objeto.Sat;
- end;
- function TCentralFactory.CriaConfigSistemas: TObject;
- begin
- List.objeto.SistemaConfig:= TSistema.Create;
- result:= List.objeto.SistemaConfig;
- end;
- function TCentralFactory.CriaInformacoesCpu: TJvComputerInfoEx;
- begin
- Result:= TJvComputerInfoEx.Create(Nil);
- List.objeto.FInfoCpu:= Result;
- end;
- function TCentralFactory.CriaObjetoEmail: TObject;
- begin
- Lista.Objeto.EmailClass:= TConfigEmail.Create;
- Result:= Lista.Objeto.EmailClass;
- end;
- procedure TCentralFactory.LimpaMemoriaResidual;
- var
- MainHandle : THandle;
- begin
- try
- MainHandle := OpenProcess(PROCESS_ALL_ACCESS, false, GetCurrentProcessID) ;
- SetProcessWorkingSetSize(MainHandle, $FFFFFFFF, $FFFFFFFF) ;
- CloseHandle(MainHandle) ;
- except
- end;
- Application.ProcessMessages;
- end;
- function TCentralFactory.RetornaNomedoComputador: string;
- var ipbuffer : string;
- nsize : dword;
- begin
- nsize := 255;
- SetLength(ipbuffer,nsize);
- if GetComputerName(pchar(ipbuffer),nsize) then
- result := ipbuffer;
- end;
- { TConcreteCentral }
- function TConcreteCentral.CreateIAbstractProduct: ICentral;
- begin
- Result := TCentralFactory.Create();
- end;
- {Lista}
- class constructor Lista.Create;
- begin
- inherited;
- RetornaLista(aclasses);
- RetornaLista(aForms);
- RetornaLista(aTlibrary);
- end;
- class function Lista.destroilista: Boolean;
- begin
- result := False;
- if Lista.Objeto <> nil then begin
- Lista.Objeto.DisposeOf;
- end;
- if Lista.ObjetoForm <> nil then begin
- Lista.ObjetoForm.DisposeOf;
- end;
- if Lista.Biblioteca <> nil then begin
- Lista.Biblioteca.DisposeOf;
- end;
- end;
- class destructor Lista.destroy;
- begin
- Lista.destroilista;
- end;
- class function Lista.RetornaLista(arecord: tipos): TObject;
- begin
- case arecord of
- aClasses: begin
- Objeto := TGlobals.Create;
- end;
- aForms: begin
- ObjetoForm := TGlobalForm.Create;
- end;
- aTlibrary : begin
- Biblioteca := TLib.Create;
- end;
- end;
- end;
- { TLib }
- procedure TLib.wait(Msg: String; time: Integer);
- begin
- CarregaWait(Msg,time);
- end;
- procedure TLib.FormataCamposDataset(aDataset: TDataSet; aMascara: string);
- begin
- FormataCamposFields(aDataset,aMascara);
- end;
- initialization
- CarregaWait('Objetos carregados com êxito',500);
- List := Lista.create;
- finalization
- CarregaWait('Descarregando Objetos',500);
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement