Advertisement
filhotecmail

BkpThread

Feb 5th, 2018
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 4.17 KB | None | 0 0
  1. unit BkpModel;
  2.  
  3. interface
  4.  
  5. uses Classes,SysUtils,System.Generics.Collections,windows,Forms;
  6.  
  7. type TServiceProgressEvent = procedure (ASender: TObject; const AMessage: String) of object;
  8.  
  9.  type
  10.   TBkpservicesthread = class(TThread)
  11.  
  12. private
  13.  
  14.  
  15.  protected
  16.   procedure Execute(const User, password, Host, Banco, LocalBkp,Formato,output: string); overload;
  17.   procedure CmdPromptcommand(const User, password, Host, Banco, LocalBkp,Formato,output: string);
  18.   procedure BackupDossier;
  19.  
  20.   public
  21.  
  22. end;
  23.  
  24.  type TbkpServicesOptions = class
  25.  
  26.    private
  27.     FCaminhoBkp: string;
  28.     FPageSize: LongWord;
  29.     FPageBuffers: LongWord;
  30.  
  31.    {Private declaration}
  32.    protected
  33.    {Protected declaration}
  34.    public
  35.    {Public declaration declaration}
  36.    property CaminhoBkp: string read FCaminhoBkp write FCaminhoBkp;
  37.    property PageSize: LongWord read FPageSize write FPageSize default 0;
  38.    property PageBuffers: LongWord read FPageBuffers write FPageBuffers default 0;
  39.      constructor Create; (*Metodos do Constructor*)
  40.      destructor Destroy; override;
  41.  
  42.    published
  43.    {Protected declaration}
  44.    end;
  45.  
  46.  
  47.  
  48.  type TBkpServices = class( TComponent )
  49.  
  50.       private
  51.     FDatabase: String;
  52.     FEUAPassword: String;
  53.     FEUAUserName: String;
  54.     FEUAPort: String;
  55.      FTBkpservicesthread: TBkpservicesthread;
  56.     FTbkpServicesOptions: TbkpServicesOptions;
  57.     FOnProgress: TServiceProgressEvent;
  58.     FTstringList: TstringList;
  59.     FHost: string;
  60.     FCaminhoBkp: string;
  61.         {Private declaration}
  62.       protected
  63.       {Protected declaration}
  64.       public
  65.     constructor Create(AOwner: TComponent); override;
  66.       {Public declaration declaration}
  67.       property Database: String read FDatabase    write FDatabase;
  68.       property UserName: String read FEUAUserName write FEUAUserName;
  69.       property Password: String read FEUAPassword write FEUAPassword;
  70.       property Port: String     read FEUAPort     write FEUAPort;
  71.       property Host: string read FHost write FHost;
  72.       property CaminhoBkp: string read FCaminhoBkp write FCaminhoBkp;
  73.       property RetornoGbk: TstringList read FTstringList write FTstringList;
  74.       property Options: TbkpServicesOptions read FTbkpServicesOptions write FTbkpServicesOptions;
  75.       property OnProgress: TServiceProgressEvent read FOnProgress write FOnProgress;
  76.       procedure ExecuteBackup;
  77.  
  78.         destructor Destroy; override;
  79.     procedure AfterConstruction; override;
  80.     procedure BeforeDestruction; override;
  81.  
  82.       published
  83.       {Protected declaration}
  84.       end;
  85.  
  86. { TBkpServices }
  87.  
  88.  
  89. implementation
  90.  
  91. procedure TBkpServices.AfterConstruction;
  92. begin
  93.   inherited AfterConstruction;
  94.  
  95. end;
  96.  
  97. procedure TBkpServices.BeforeDestruction;
  98. begin
  99.   inherited BeforeDestruction;
  100.  
  101. end;
  102.  
  103.  
  104. constructor TBkpServices.Create(AOwner: TComponent);
  105. begin
  106.   inherited Create(aowner);
  107.   FTbkpServicesOptions:= TbkpServicesOptions.Create;
  108. end;
  109.  
  110. destructor TBkpServices.Destroy;
  111. begin
  112.  
  113.   inherited;
  114. end;
  115.  
  116. procedure TBkpServices.ExecuteBackup;
  117. begin
  118.   FTBkpservicesthread := TBkpservicesthread.Create;
  119.   FTBkpservicesthread.CmdPromptcommand(FEUAUserName,FEUAPassword,FHost,FDatabase,FCaminhoBkp,'.Fkb',ExtractFilePath(Application.ExeName));
  120.  
  121. end;
  122.  
  123. { TbkpServicesOptions }
  124.  
  125. constructor TbkpServicesOptions.Create;
  126. begin
  127.  
  128. end;
  129.  
  130. destructor TbkpServicesOptions.Destroy;
  131. begin
  132.  
  133.   inherited;
  134. end;
  135.  
  136. { TBkpservicesthread }
  137.  
  138. procedure TBkpservicesthread.BackupDossier;
  139. begin
  140.  
  141. end;
  142.  
  143. procedure TBkpservicesthread.CmdPromptcommand(const User, password, Host, Banco, LocalBkp,Formato,output: string);
  144.  var T: TstringBuilder;
  145. begin
  146.     T:= TStringBuilder.Create;
  147.     T.Append('cmd /c gbak ')
  148.     .Append( '-user ')
  149.     .Append(user)
  150.     .Append(' -pas ')
  151.     .Append(password)
  152.     .Append(Host)
  153.     .Append(':')
  154.     .Append(Banco)
  155.     .Append(LocalBkp)
  156.     .Append('.'+Formato)
  157.     .Append('>')
  158.     .Append(output)
  159.     .Append(',0');
  160.      WinExec(PAnsiChar(T.ToString),SW_HIDE);
  161. end;
  162.  
  163. procedure TBkpservicesthread.Execute(const User, password, Host, Banco, LocalBkp, Formato, output: string);
  164. begin
  165.  inherited Execute;
  166.  CmdPromptcommand(User, password, Host, Banco, LocalBkp, Formato, output);
  167. end;
  168.  
  169. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement