git-svn-id: https://192.168.0.254/svn/Proyectos.Tecsitel_FactuGES2/trunk@540 0c75b7a4-871f-7646-8a2f-f78d34cc349f
111 lines
3.8 KiB
ObjectPascal
111 lines
3.8 KiB
ObjectPascal
unit uGestorDocumentosController;
|
|
|
|
interface
|
|
|
|
uses
|
|
Classes, uROTypes, uControllerBase, uDataModuleGestorDocumentos;
|
|
|
|
type
|
|
IGestorDocumentosController = interface(IControllerBase)
|
|
['{75EC4D1B-A7A2-4C81-B2DA-8688240D6EC2}']
|
|
function DarListaDocumentos(const ID: Integer): TStringList;
|
|
function DescargarFichero(const ID:Integer; const NombreFichero: String; const DestinoFichero: String): Boolean;
|
|
function SubirFichero(const ID:Integer; const NombreFichero: String; const Fichero: Binary): Boolean;
|
|
procedure SincronizarDocumentos(const ID: Integer; FListaDocumentos: TStringList; Directorio: String);
|
|
function EliminarDirectorio(const ID: Integer): Boolean;
|
|
end;
|
|
|
|
TGestorDocumentosController = class(TControllerBase, IGestorDocumentosController)
|
|
protected
|
|
FDataModule : IDataModuleGestorDocumentos;
|
|
|
|
//Estos son los tres métodos a sobre escribir si se desea heredar toda la logica de
|
|
//este controller
|
|
procedure AsignarDataModule; virtual;
|
|
|
|
public
|
|
constructor Create; override;
|
|
destructor Destroy; override;
|
|
|
|
function DarListaDocumentos(const ID: Integer): TStringList;
|
|
function DescargarFichero(const ID:Integer; const NombreFichero: String; const DestinoFichero: String): Boolean;
|
|
function SubirFichero(const ID:Integer; const NombreFichero: String; const Fichero: Binary): Boolean;
|
|
procedure SincronizarDocumentos(const ID: Integer; FListaDocumentos: TStringList; Directorio: String);
|
|
function EliminarDirectorio(const ID: Integer): Boolean;
|
|
end;
|
|
|
|
implementation
|
|
{ TGestorDocumentosController }
|
|
|
|
uses SysUtils, Dialogs;
|
|
|
|
procedure TGestorDocumentosController.AsignarDataModule;
|
|
begin
|
|
FDataModule := TDataModuleGestorDocumentos.Create(Nil);
|
|
end;
|
|
|
|
constructor TGestorDocumentosController.Create;
|
|
begin
|
|
inherited;
|
|
AsignarDataModule;
|
|
end;
|
|
|
|
function TGestorDocumentosController.DarListaDocumentos(
|
|
const ID: Integer): TStringList;
|
|
begin
|
|
Result := FDataModule.DarListaDocumentos(ID);
|
|
end;
|
|
|
|
function TGestorDocumentosController.DescargarFichero(const ID: Integer;
|
|
const NombreFichero, DestinoFichero: String): Boolean;
|
|
begin
|
|
Result := FDataModule.DescargarFichero(ID, NombreFichero, DestinoFichero);
|
|
end;
|
|
|
|
destructor TGestorDocumentosController.Destroy;
|
|
begin
|
|
FDataModule := Nil;
|
|
inherited;
|
|
end;
|
|
|
|
function TGestorDocumentosController.EliminarDirectorio(const ID: Integer): Boolean;
|
|
begin
|
|
Result := FDataModule.EliminarID(ID);
|
|
end;
|
|
|
|
procedure TGestorDocumentosController.SincronizarDocumentos(const ID: Integer;
|
|
FListaDocumentos: TStringList; Directorio: String);
|
|
var
|
|
ListaDocumentosServidor: TStringList;
|
|
ANombreFichero: String;
|
|
AFichero: Binary;
|
|
i, j: Integer;
|
|
begin
|
|
//Eliminamos todos los documentos del servidor que ya no existan en el cliente.
|
|
ListaDocumentosServidor := DarListaDocumentos(ID);
|
|
for i:= 0 to ListaDocumentosServidor.Count - 1 do
|
|
if not FListaDocumentos.Find(ListaDocumentosServidor.Strings[i], j) then
|
|
if not FDataModule.EliminarFichero(ID, ListaDocumentosServidor.Strings[i]) then
|
|
showmessage('Error al borrar fichero' + ListaDocumentosServidor.Strings[i]);
|
|
|
|
//Subimos todos los ficheros que halla al servidor (de momento no se miran fechas)
|
|
for i := 0 to FListaDocumentos.Count - 1 do
|
|
begin
|
|
ANombreFichero := Directorio + FListaDocumentos.Strings[i];
|
|
if FileExists(ANombreFichero) then
|
|
begin
|
|
AFichero := Binary.Create;
|
|
AFichero.LoadFromFile(ANombreFichero);
|
|
SubirFichero(ID, ExtractFileName(ANombreFichero), AFichero);
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
function TGestorDocumentosController.SubirFichero(const ID: Integer;
|
|
const NombreFichero: String; const Fichero: Binary): Boolean;
|
|
begin
|
|
Result := FDataModule.SubirFichero(ID, NombreFichero, Fichero);
|
|
end;
|
|
|
|
end.
|