git-svn-id: https://192.168.0.254/svn/Proyectos.AbetoDesign_FactuGES/trunk@2 93f398dd-4eb6-7a46-baf6-13f46f578da2
222 lines
5.9 KiB
ObjectPascal
222 lines
5.9 KiB
ObjectPascal
unit srvGestorDocumentos_Impl;
|
|
|
|
{----------------------------------------------------------------------------}
|
|
{ This unit was automatically generated by the RemObjects SDK after reading }
|
|
{ the RODL file associated with this project . }
|
|
{ }
|
|
{ This is where you are supposed to code the implementation of your objects. }
|
|
{----------------------------------------------------------------------------}
|
|
|
|
{$I Remobjects.inc}
|
|
|
|
interface
|
|
|
|
uses
|
|
{vcl:} Classes, SysUtils,
|
|
{RemObjects:} uROXMLIntf, uROClientIntf, uROTypes, uROServer, uROServerIntf, uROSessions,
|
|
{Required:} uRORemoteDataModule,
|
|
{Ancestor Implementation:} DataAbstractService_Impl,
|
|
{Used RODLs:} DataAbstract4_Intf,
|
|
{Generated:} FactuGES_Intf;
|
|
|
|
type
|
|
{ TsrvGestorDocumentos }
|
|
TsrvGestorDocumentos = class(TDataAbstractService, IsrvGestorDocumentos)
|
|
private
|
|
function DarRutaDocumentos: string;
|
|
|
|
protected
|
|
{ IsrvGestorDocumentos methods }
|
|
function DarListaFicheros(const Almacen: TRdxAlmacenes; const ID: Integer): StringArray;
|
|
function DescargarFichero(const Almacen: TRdxAlmacenes; const ID: Integer; const NombreFichero: String): Binary;
|
|
function SubirFichero(const Almacen: TRdxAlmacenes; const ID: Integer; const NombreFichero: String; const Fichero: Binary): Boolean;
|
|
function EliminarFichero(const Almacen: TRdxAlmacenes; const ID: Integer; const NombreFichero: String): Boolean;
|
|
function EliminarID(const Almacen: TRdxAlmacenes; const ID: Integer): Boolean;
|
|
end;
|
|
|
|
implementation
|
|
|
|
{$R *.dfm}
|
|
uses
|
|
{Generated:} FactuGES_Invk, srvConfiguracion_Impl, uSistemaFunc, Dialogs, Forms;
|
|
|
|
const
|
|
CTE_VALOR = 'RUTA_DOCUMENTOS';
|
|
CTE_DOCUMENTOS = 'DOCUMENTOS';
|
|
CTE_ALMACEN_PRESUPUESTOS = '\Presupuestos\';
|
|
|
|
|
|
procedure Create_srvGestorDocumentos(out anInstance : IUnknown);
|
|
begin
|
|
anInstance := TsrvGestorDocumentos.Create(nil);
|
|
end;
|
|
|
|
{
|
|
|
|
Sample call
|
|
|
|
You can try this function placing a ListBox and a button on a form and adding this code to the OnClick event of the button:
|
|
|
|
procedure TForm1.Button1Click(Sender: TObject);
|
|
var
|
|
list: TStringList;
|
|
begin
|
|
list := FindFile('C:\Delphi\*.pas');
|
|
ListBox1.Items.Assign(list);
|
|
list.Free;
|
|
end;
|
|
}
|
|
|
|
{ srvGestorDocumentos }
|
|
function TsrvGestorDocumentos.DarListaFicheros(const Almacen: TRdxAlmacenes; const ID: Integer): StringArray;
|
|
var
|
|
Ruta: String;
|
|
ListaFicheros: TStringList;
|
|
i: Integer;
|
|
|
|
begin
|
|
Result := NIL;
|
|
Ruta := DarRutaDocumentos;
|
|
try
|
|
case Almacen of
|
|
TRdxAlmacenes_Presupuestos:
|
|
begin
|
|
Ruta := Ruta + CTE_ALMACEN_PRESUPUESTOS + IntToStr(ID) + '\*.*';
|
|
ListaFicheros := FindFile(Ruta);
|
|
Result := StringArray.Create();
|
|
for i := 0 to ListaFicheros.Count - 1 do
|
|
Result.Add(ExtractFileName(ListaFicheros.Strings[i]));
|
|
end;
|
|
end;
|
|
|
|
finally
|
|
if Assigned(ListaFicheros) then
|
|
FreeAndNil(ListaFicheros);
|
|
end;
|
|
end;
|
|
|
|
function TsrvGestorDocumentos.DarRutaDocumentos: string;
|
|
var
|
|
AConfiguracionService : IsrvConfiguracion;
|
|
Intf : IInterface;
|
|
AClientID : TGUID;
|
|
begin
|
|
CreateGUID(AClientID);
|
|
try
|
|
GetClassFactory('srvConfiguracion').CreateInstance(AClientID, Intf);
|
|
AConfiguracionService := Intf as IsrvConfiguracion;
|
|
Result := AConfiguracionService.darValor(CTE_VALOR, (ExtractFilePath(Application.ExeName) + CTE_DOCUMENTOS));
|
|
finally
|
|
AConfiguracionService := Nil;
|
|
end;
|
|
end;
|
|
|
|
function TsrvGestorDocumentos.DescargarFichero(const Almacen: TRdxAlmacenes; const ID: Integer; const NombreFichero: String): Binary;
|
|
var
|
|
Ruta: String;
|
|
|
|
begin
|
|
Result := Binary.Create;
|
|
|
|
try
|
|
Ruta := DarRutaDocumentos;
|
|
case Almacen of
|
|
TRdxAlmacenes_Presupuestos:
|
|
begin
|
|
Ruta := Ruta + CTE_ALMACEN_PRESUPUESTOS + IntToStr(ID) + '\' + NombreFichero;
|
|
Result.LoadFromFile(Ruta);
|
|
end;
|
|
end;
|
|
finally
|
|
//
|
|
end;
|
|
end;
|
|
|
|
function TsrvGestorDocumentos.EliminarFichero(const Almacen: TRdxAlmacenes; const ID: Integer;
|
|
const NombreFichero: String): Boolean;
|
|
var
|
|
Ruta: String;
|
|
|
|
begin
|
|
Result := False;
|
|
|
|
try
|
|
Ruta := DarRutaDocumentos;
|
|
case Almacen of
|
|
TRdxAlmacenes_Presupuestos:
|
|
begin
|
|
Ruta := Ruta + CTE_ALMACEN_PRESUPUESTOS + IntToStr(ID) + '\' + NombreFichero;
|
|
if FileExists(Ruta) then
|
|
Result := SysUtils.DeleteFile(Ruta)
|
|
else
|
|
Result := True; //Ya ha sido borrado
|
|
end;
|
|
end;
|
|
finally
|
|
//
|
|
end;
|
|
end;
|
|
|
|
function TsrvGestorDocumentos.EliminarID(const Almacen: TRdxAlmacenes; const ID: Integer): Boolean;
|
|
var
|
|
Ruta: String;
|
|
|
|
begin
|
|
Result := False;
|
|
|
|
try
|
|
Ruta := DarRutaDocumentos;
|
|
case Almacen of
|
|
TRdxAlmacenes_Presupuestos:
|
|
begin
|
|
Ruta := Ruta + CTE_ALMACEN_PRESUPUESTOS + IntToStr(ID);
|
|
if DirectoryExists(Ruta) then
|
|
Deltree(Ruta, True);
|
|
Result := True;
|
|
end;
|
|
end;
|
|
finally
|
|
//
|
|
end;
|
|
end;
|
|
|
|
function TsrvGestorDocumentos.SubirFichero(const Almacen: TRdxAlmacenes; const ID: Integer; const NombreFichero: String;
|
|
const Fichero: Binary): Boolean;
|
|
var
|
|
Ruta: String;
|
|
|
|
begin
|
|
Result := False;
|
|
try
|
|
Ruta := DarRutaDocumentos;
|
|
if not DirectoryExists(Ruta) then
|
|
CreateDir(Ruta);
|
|
|
|
case Almacen of
|
|
TRdxAlmacenes_Presupuestos:
|
|
begin
|
|
Ruta := Ruta + CTE_ALMACEN_PRESUPUESTOS;
|
|
if not DirectoryExists(Ruta) then
|
|
CreateDir(Ruta);
|
|
|
|
Ruta := Ruta + IntToStr(ID);
|
|
if not DirectoryExists(Ruta) then
|
|
CreateDir(Ruta);
|
|
|
|
Ruta := Ruta + '\' + NombreFichero;
|
|
Fichero.SaveToFile(Ruta);
|
|
Result := True;
|
|
end;
|
|
end;
|
|
finally
|
|
//
|
|
end;
|
|
end;
|
|
|
|
initialization
|
|
TROClassFactory.Create('srvGestorDocumentos', Create_srvGestorDocumentos, TsrvGestorDocumentos_Invoker);
|
|
|
|
finalization
|
|
|
|
end.
|