git-svn-id: https://192.168.0.254/svn/Proyectos.Acana_FactuGES/trunk@4 3f40d355-893c-4141-8e64-b1d9be72e7e7
152 lines
4.3 KiB
ObjectPascal
152 lines
4.3 KiB
ObjectPascal
unit HacerCopiaSeguridad;
|
||
|
||
interface
|
||
|
||
uses
|
||
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
||
Dialogs, cxMemo, cxControls, cxContainer, cxEdit, cxTextEdit, cxMaskEdit,
|
||
cxButtonEdit, StdCtrls, RdxBotones, RdxBarras, ExtCtrls, RdxPaneles,
|
||
Configuracion, RdxShape, RdxFrame, IBServices, Entidades, cxProgressBar;
|
||
|
||
type
|
||
TfrHacerCopiaSeguridad = class(TRdxFrame)
|
||
Titulo: TRdxBarraSuperior;
|
||
brInferior: TRdxBarraInferior;
|
||
bCerrar: TRdxBoton;
|
||
ArchivoCopiaSeguridad: TcxButtonEdit;
|
||
Label3: TLabel;
|
||
bBackup: TRdxBoton;
|
||
eMensaje: TLabel;
|
||
pnlAtencion: TRdxShape;
|
||
Label1: TLabel;
|
||
Label2: TLabel;
|
||
SaveDialog1: TSaveDialog;
|
||
IBBackupService1: TIBBackupService;
|
||
cxProgressBar1: TcxProgressBar;
|
||
procedure ArchivoCopiaSeguridadPropertiesButtonClick(Sender: TObject;
|
||
AButtonIndex: Integer);
|
||
procedure bCerrarClick(Sender: TObject);
|
||
procedure bBackupClick(Sender: TObject);
|
||
procedure ArchivoCopiaSeguridadExit(Sender: TObject);
|
||
private
|
||
procedure HacerBackup;
|
||
protected
|
||
function CambiarEntidad(EntidadAnterior, Entidad : TRdxEntidad): Boolean; override;
|
||
public
|
||
constructor Create(AOwner : TComponent); override;
|
||
end;
|
||
|
||
var
|
||
frHacerCopiaSeguridad: TfrHacerCopiaSeguridad;
|
||
|
||
implementation
|
||
|
||
{$R *.dfm}
|
||
|
||
uses
|
||
DateUtils, Math, Mensajes, StrFunc, BaseDatos;
|
||
|
||
procedure TfrHacerCopiaSeguridad.ArchivoCopiaSeguridadPropertiesButtonClick(
|
||
Sender: TObject; AButtonIndex: Integer);
|
||
begin
|
||
SaveDialog1.FileName := ArchivoCopiaSeguridad.Text;
|
||
if SaveDialog1.Execute then
|
||
begin
|
||
ArchivoCopiaSeguridad.Text := SaveDialog1.FileName;
|
||
bBackup.SetFocus;
|
||
end;
|
||
end;
|
||
|
||
procedure TfrHacerCopiaSeguridad.bCerrarClick(Sender: TObject);
|
||
begin
|
||
CloseFrame;
|
||
end;
|
||
|
||
constructor TfrHacerCopiaSeguridad.Create(AOwner: TComponent);
|
||
var
|
||
Cadena : String;
|
||
begin
|
||
inherited;
|
||
Cadena := GetCurrentDir + '\factuges-%s';
|
||
Cadena := Format(Cadena, [FormatDateTime('yyyy-mm-dd', Date)]);
|
||
Cadena := Cadena + '.gbk';
|
||
ArchivoCopiaSeguridad.Text := Cadena;
|
||
end;
|
||
|
||
procedure TfrHacerCopiaSeguridad.bBackupClick(Sender: TObject);
|
||
begin
|
||
if EsCadenaVacia(ArchivoCopiaSeguridad.Text) then
|
||
begin
|
||
VerMensaje('Debe indicar una ruta con un nombre de archivo para poder hacer la copia de seguridad.');
|
||
ArchivoCopiaSeguridad.SetFocus;
|
||
Exit;
|
||
end;
|
||
|
||
{ if not DirectoryExists(ArchivoCopiaSeguridad.Text) then
|
||
begin
|
||
VerMensaje('Aseg<65>rese de que ha escrito correctamente la ruta del archivo');
|
||
ArchivoCopiaSeguridad.SetFocus;
|
||
Exit;
|
||
end;}
|
||
HacerBackup;
|
||
end;
|
||
|
||
procedure TfrHacerCopiaSeguridad.ArchivoCopiaSeguridadExit(
|
||
Sender: TObject);
|
||
begin
|
||
if not EsCadenaVacia(ArchivoCopiaSeguridad.Text) then
|
||
begin
|
||
if Pos('.gbk', ArchivoCopiaSeguridad.Text) = 0 then
|
||
ArchivoCopiaSeguridad.Text := ArchivoCopiaSeguridad.Text + '.gbk';
|
||
|
||
{ if ((FileExists(ArchivoCopiaSeguridad.Text)) and
|
||
(VerMensajePreguntaFmt('%s ya existe. <20>Desea reemplazarlo?',
|
||
[ArchivoCopiaSeguridad.Text]) <> IDOK)) then
|
||
exit;}
|
||
end;
|
||
end;
|
||
|
||
procedure TfrHacerCopiaSeguridad.HacerBackup;
|
||
begin
|
||
with IBBackupService1 do
|
||
begin
|
||
LoginPrompt := False;
|
||
Params.Add('user_name=sysdba');
|
||
Params.Add('password=masterkey');
|
||
DatabaseName := dmBaseDatos.RutaBD;
|
||
Protocol := TCP;
|
||
ServerName := dmBaseDatos.NombreServidor;
|
||
BackupFile.Clear;
|
||
BackupFile.Add(ArchivoCopiaSeguridad.Text);
|
||
try
|
||
Verbose := True;
|
||
Active := True;
|
||
ServiceStart;
|
||
eMensaje.Visible := True;
|
||
cxProgressBar1.Visible := True;
|
||
cxProgressBar1.Position := 0;
|
||
eMensaje.Caption := 'Espere, por favor...';
|
||
eMensaje.Update;
|
||
while not EOF do
|
||
begin
|
||
GetNextLine;
|
||
cxProgressBar1.Position := cxProgressBar1.Position + 1;
|
||
end;
|
||
cxProgressBar1.Position := cxProgressBar1.Properties.Max;
|
||
eMensaje.Caption := 'Copia de seguridad realizada correctamente.';
|
||
VerMensaje('Copia de seguridad realizada correctamente.');
|
||
finally
|
||
Active := False;
|
||
bCerrar.SetFocus;
|
||
end;
|
||
end;
|
||
end;
|
||
|
||
function TfrHacerCopiaSeguridad.CambiarEntidad(EntidadAnterior, Entidad: TRdxEntidad): Boolean;
|
||
begin
|
||
inherited CambiarEntidad(EntidadAnterior, Entidad);
|
||
ConfigurarFrame(Self, Self.Entidad);
|
||
end;
|
||
|
||
end.
|