|
(* -------------------------------------------------------------------------------- |
* |
* Programma di esempio per la registrazione di una fattura di vendita utilizzando |
* le funzioni della libreria SPPSERV.DLL. |
* Prima di utilizzare questo esempio è necessario modificare alcune informazioni |
* in modo da adattare il codice alla base dati utilizzata. |
* In questo esempio l'esercizio di lavoro e' considerato corrispondente all'anno |
* solare in corso e le date impostate per default a quella attuale. |
* |
* QUESTO SORGENTE E' FORNITO A TITOLO DI ESEMPIO COME DIMOSTRAZIONE DELL'UTILIZZO |
* DELLA LIBRERIA SPPSERV.DLL. NESSUNA GARANZIA, NE' IMPLICITA NE' ESPLICITA, E' |
* PREVISTA PER QUALSIASI UTILIZZO DIVERSO DA QUELLO INDICATO. |
* |
-------------------------------------------------------------------------------- *) |
program SppServTest2; |
|
{$APPTYPE CONSOLE} |
|
uses |
Windows, StdCtrls, ExtCtrls, SysUtils; |
|
const |
MY_LIBRARY_NAME = 'sppserv.dll'; |
SPPSRV_SUCCESS = 0; |
|
var |
// prototipi delle funzioni della sppserv.dll |
SPPSRVVersion : function() : integer stdcall; |
SPPSRVInit : function(mainwnd : HWND) : integer stdcall; |
SPPSRVExit : function() : integer stdcall; |
SPPSRVComuniConnect : function(comuniconnectstring : pChar) : integer stdcall; |
SPPSRVDittaConnect : function(dittaconnectstring : pChar) : integer stdcall; |
SPPSRVSetEsercizio : function(esercizio : pChar) : integer stdcall; |
SPPSRVSetEuro : function(IsEuro : boolean) : integer stdcall; |
SPPSRVSetUtente : function(utente : pChar) : integer stdcall; |
SPPSRVSetTodayDate : function(todaydate : pChar) : integer stdcall; |
SPPSRVActivateTransaction : function() : integer stdcall; |
SPPSRVGetNum : function(code : pChar) : integer stdcall; |
SPPSRVInitMovcoTransaction : function() : integer stdcall; |
SPPSRVEndMovcoTransaction : function() : integer stdcall; |
SPPSRVSetMovcoField : function(fldname : pChar; value : pChar) : integer stdcall; |
SPPSRVAppendMovcoRecord : function() : integer stdcall; |
SPPSRVCheckMovcoRecord : function() : integer stdcall; |
SPPSRVGetMovcoField : function(fldname : pChar; value : pChar; |
valuelen : integer) : integer stdcall; |
|
dll : THandle; |
IsError, rc, nprot : integer; |
numeroprot, numerodoc : string; |
MovcoNum : array[0..15] of char; |
|
label |
END_OF_TEST, FINE; |
|
procedure ReportError(Msg : string); |
var |
lpMsgBuf : pAnsiChar; |
ErrorCode : DWORD; |
begin |
GetMem(lpMsgBuf, 512); |
ErrorCode := GetLastError(); |
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM or FORMAT_MESSAGE_ARGUMENT_ARRAY, |
nil, ErrorCode, LANG_NEUTRAL, lpMsgBuf, 512, nil); |
WriteLn(Msg + ': errore ' + IntToStr(ErrorCode) + ' (' + lpMsgBuf + ')'); |
FreeMem(lpMsgBuf); |
end; |
|
procedure SetMovcoField(fldname : string; value : string); |
var |
rc : integer; |
begin |
rc := SPPSRVSetMovcoField(pChar(fldname), pChar(value)); |
if (rc <> SPPSRV_SUCCESS) then |
WriteLn('SPPSRVSetMovcoField (' + fldname + ') ha tornato: ' + IntToStr(rc)); |
end; |
|
begin |
WriteLn('Inizio test ' + MY_LIBRARY_NAME); |
WriteLn('---------------------------------------------------'); |
WriteLn('Caricamento DLL e estrazione funzioni...'); |
dll := LoadLibrary(MY_LIBRARY_NAME); |
if (dll > 0) then |
WriteLn(MY_LIBRARY_NAME + ' caricata con successo') |
else begin |
WriteLn('**********************************************'); |
WriteLn('ERRORE: LoadLibrary("' + MY_LIBRARY_NAME + '") fallita!'); |
ReportError('Dettagli'); |
WriteLn('**********************************************'); |
goto END_OF_TEST; |
end; |
// estrazione delle funzioni esportate dalla dll |
IsError := 0; |
@SPPSRVInit := GetProcAddress(dll, 'SPPSRVInit'); |
if (Assigned(SPPSRVInit)) then |
WriteLn('SPPSRVInit caricata con successo') |
else begin |
WriteLn('**************************************************************'); |
WriteLn('ERRORE: GetProcAddress(dll, "SPPSRVInit") fallita!'); |
WriteLn('**************************************************************'); |
IsError := 1; |
end; |
@SPPSRVVersion := GetProcAddress(dll, 'SPPSRVVersion'); |
if (Assigned(SPPSRVVersion)) then |
WriteLn('SPPSRVVersion caricata con successo') |
else begin |
WriteLn('**************************************************************'); |
WriteLn('ERRORE: GetProcAddress(dll, "SPPSRVVersion") fallita!'); |
WriteLn('**************************************************************'); |
IsError := 1; |
end; |
@SPPSRVExit := GetProcAddress(dll, 'SPPSRVExit'); |
if (Assigned(SPPSRVExit)) then |
WriteLn('SPPSRVExit caricata con successo') |
else begin |
WriteLn('**************************************************************'); |
WriteLn('ERRORE: GetProcAddress(dll, "SPPSRVExit") fallita!'); |
WriteLn('**************************************************************'); |
IsError := 1; |
end; |
@SPPSRVComuniConnect := GetProcAddress(dll, 'SPPSRVComuniConnect'); |
if (Assigned(SPPSRVComuniConnect)) then |
WriteLn('SPPSRVComuniConnect caricata con successo') |
else begin |
WriteLn('**************************************************************'); |
WriteLn('ERRORE: GetProcAddress(dll, "SPPSRVComuniConnect") fallita!'); |
WriteLn('**************************************************************'); |
IsError := 1; |
end; |
@SPPSRVDittaConnect := GetProcAddress(dll, 'SPPSRVDittaConnect'); |
if (Assigned(SPPSRVDittaConnect)) then |
WriteLn('SPPSRVDittaConnect caricata con successo') |
else begin |
WriteLn('**************************************************************'); |
WriteLn('ERRORE: GetProcAddress(dll, "SPPSRVDittaConnect") fallita!'); |
WriteLn('**************************************************************'); |
IsError := 1; |
end; |
@SPPSRVSetEsercizio := GetProcAddress(dll, 'SPPSRVSetEsercizio'); |
if (Assigned(SPPSRVSetEsercizio)) then |
WriteLn('SPPSRVSetEsercizio caricata con successo') |
else begin |
WriteLn('**************************************************************'); |
WriteLn('ERRORE: GetProcAddress(dll, "SPPSRVSetEsercizio") fallita!'); |
WriteLn('**************************************************************'); |
IsError := 1; |
end; |
@SPPSRVSetUtente := GetProcAddress(dll, 'SPPSRVSetUtente'); |
if (Assigned(SPPSRVSetUtente)) then |
WriteLn('SPPSRVSetUtente caricata con successo') |
else begin |
WriteLn('**************************************************************'); |
WriteLn('ERRORE: GetProcAddress(dll,\"" << "SPPSRVSetUtente" << "\") fallita!'); |
WriteLn('**************************************************************'); |
IsError := 1; |
end; |
@SPPSRVSetTodayDate := GetProcAddress(dll, 'SPPSRVSetTodayDate'); |
if (Assigned(SPPSRVSetTodayDate)) then |
WriteLn('SPPSRVSetTodayDate caricata con successo') |
else begin |
WriteLn('**************************************************************'); |
WriteLn('ERRORE: GetProcAddress(dll,\"" << "SPPSRVSetTodayDate" << "\") fallita!'); |
WriteLn('**************************************************************'); |
IsError := 1; |
end; |
@SPPSRVSetEuro := GetProcAddress(dll, 'SPPSRVSetEuro'); |
if (Assigned(SPPSRVSetEuro)) then |
WriteLn('SPPSRVSetEuro caricata con successo') |
else begin |
WriteLn('**************************************************************'); |
WriteLn('ERRORE: GetProcAddress(dll, "SPPSRVSetEuro") fallita!'); |
WriteLn('**************************************************************'); |
IsError := 1; |
end; |
{$ifndef STARTSUITE} |
@SPPSRVActivateTransaction := GetProcAddress(dll, 'SPPSRVActivateTransaction'); |
if (Assigned(SPPSRVActivateTransaction)) then |
WriteLn('SPPSRVActivateTransaction caricata con successo') |
else begin |
WriteLn('**************************************************************'); |
WriteLn('ERRORE: GetProcAddress(dll, "SPPSRVActivateTransaction") fallita!'); |
WriteLn('**************************************************************'); |
IsError := 1; |
end; |
{$endif} |
@SPPSRVGetNum := GetProcAddress(dll, 'SPPSRVGetNum'); |
if (Assigned(SPPSRVGetNum)) then |
WriteLn('SPPSRVGetNum caricata con successo') |
else begin |
WriteLn('**************************************************************'); |
WriteLn('ERRORE: GetProcAddress(dll, "SPPSRVGetNum") fallita!'); |
WriteLn('**************************************************************'); |
IsError := 1; |
end; |
@SPPSRVInitMovcoTransaction := GetProcAddress(dll, 'SPPSRVInitMovcoTransaction'); |
if (Assigned(SPPSRVInitMovcoTransaction)) then |
WriteLn('SPPSRVInitMovcoTransaction caricata con successo') |
else begin |
WriteLn('**************************************************************'); |
WriteLn('ERRORE: GetProcAddress(dll, "SPPSRVInitMovcoTransaction") fallita!'); |
WriteLn('**************************************************************'); |
IsError := 1; |
end; |
@SPPSRVEndMovcoTransaction := GetProcAddress(dll, 'SPPSRVEndMovcoTransaction'); |
if (Assigned(SPPSRVEndMovcoTransaction)) then |
WriteLn('SPPSRVEndMovcoTransaction caricata con successo') |
else begin |
WriteLn('**************************************************************'); |
WriteLn('ERRORE: GetProcAddress(dll, "SPPSRVEndMovcoTransaction") fallita!'); |
WriteLn('**************************************************************'); |
IsError := 1; |
end; |
@SPPSRVSetMovcoField := GetProcAddress(dll, 'SPPSRVSetMovcoField'); |
if (Assigned(SPPSRVSetMovcoField)) then |
WriteLn('SPPSRVSetMovcoField caricata con successo') |
else begin |
WriteLn('**************************************************************'); |
WriteLn('ERRORE: GetProcAddress(dll, "SPPSRVSetMovcoField") fallita!'); |
WriteLn('**************************************************************'); |
IsError := 1; |
end; |
@SPPSRVCheckMovcoRecord := GetProcAddress(dll, 'SPPSRVCheckMovcoRecord'); |
if (Assigned(SPPSRVCheckMovcoRecord)) then |
WriteLn('SPPSRVCheckMovcoRecord caricata con successo') |
else begin |
WriteLn('**************************************************************'); |
WriteLn('ERRORE: GetProcAddress(dll, "SPPSRVCheckMovcoRecord") fallita!'); |
WriteLn('**************************************************************'); |
IsError := 1; |
end; |
@SPPSRVAppendMovcoRecord := GetProcAddress(dll, 'SPPSRVAppendMovcoRecord'); |
if (Assigned(SPPSRVAppendMovcoRecord)) then |
WriteLn('SPPSRVAppendMovcoRecord caricata con successo') |
else begin |
WriteLn('**************************************************************'); |
WriteLn('ERRORE: GetProcAddress(dll, "SPPSRVAppendMovcoRecord") fallita!'); |
WriteLn('**************************************************************'); |
IsError := 1; |
end; |
@SPPSRVGetMovcoField := GetProcAddress(dll, 'SPPSRVGetMovcoField'); |
if (Assigned(SPPSRVGetMovcoField)) then |
WriteLn('SPPSRVGetMovcoField caricata con successo') |
else begin |
WriteLn('**************************************************************'); |
WriteLn('ERRORE: GetProcAddress(dll, "SPPSRVGetMovcoField") fallita!'); |
WriteLn('**************************************************************'); |
IsError := 1; |
end; |
if (IsError = 1) then goto END_OF_TEST; |
|
WriteLn('Test inserimento scrittura cassa a banca...'); |
|
(* |
* §: ESEMPIO di registrazione di una scrittura in partita doppia |
*) |
|
// inizializzazione della DLL |
rc := SPPSRVInit(GetDesktopWindow()); |
WriteLn('SPPSRVInit ha tornato: ' + IntToStr(rc)); |
if (rc <> SPPSRV_SUCCESS) then goto END_OF_TEST; |
// numero di versione della dll |
rc := SPPSRVVersion(); |
WriteLn('SPPSRVVersion ha tornato: ' + IntToStr(rc)); |
// connessione al database dei dati comuni e dei dati ditta |
{$ifdef STARTSUITE} |
// versione per SIGLA StartSuite (archivi dui tipo DBF) |
rc := SPPSRVComuniConnect('C:\SIGLAPP\PROVGEN'); |
WriteLn('SPPSRVComuniConnect ha tornato: ' + IntToStr(rc)); |
if (rc <> SPPSRV_SUCCESS) then goto FINE; |
rc := SPPSRVDittaConnect('C:\SIGLAPP\PROVDIT'); |
WriteLn('SPPSRVDittaConnect ha tornato: ' + IntToStr(rc)); |
if (rc <> SPPSRV_SUCCESS) then goto FINE; |
{$else} |
// versione per SIGLA (accesso ai dati via ODBC) |
rc := SPPSRVComuniConnect('DSN=SPPGEN;UID=sigla;PWD=sigla'); |
WriteLn('SPPSRVComuniConnect ha tornato: ' + IntToStr(rc)); |
if (rc <> SPPSRV_SUCCESS) then goto FINE; |
rc := SPPSRVDittaConnect('DSN=SPPDIT;UID=sigla;PWD=sigla'); |
WriteLn('SPPSRVDittaConnect ha tornato: ' + IntToStr(rc)); |
if (rc <> SPPSRV_SUCCESS) then goto FINE; |
rc := SPPSRVActivateTransaction(); |
WriteLn('SPPSRVActivateTransaction ha tornato: ' + IntToStr(rc)); |
{$endif} |
// impostazione dell'esercizio di lavoro |
rc := SPPSRVSetEsercizio('2012'); |
WriteLn('SPPSRVSetEsercizio ha tornato: ' + IntToStr(rc)); |
// impostazione dell'utente |
rc := SPPSRVSetUtente('SIGLA '); |
WriteLn('SPPSRVSetUtente ha tornato: ' + IntToStr(rc)); |
// impostazione della data |
rc := SPPSRVSetTodayDate('20120412'); |
WriteLn('SPPSRVSetTodayDate ha tornato: ' + IntToStr(rc)); |
// impostazione dell'euro come valuta di lavoro |
rc := SPPSRVSetEuro(TRUE); |
WriteLn('SPPSrvSetEuro ha tornato: ' + IntToStr(rc)); |
// inizializzazione della transazione |
rc := SPPSRVInitMovcoTransaction(); |
WriteLn('SPPSRVInitMovcoTransaction ha tornato: ' + IntToStr(rc)); |
if (rc = SPPSRV_SUCCESS) then begin |
// solo dopo l'inizializzazione può essere letto il valore del campo NUMERO |
// della tabella MOVCO (sarà automaticamente utilizzato anche per MOVIVA) |
rc := SPPSRVGetMovcoField('NUMERO', MovcoNum, Length(MovcoNum)); |
WriteLn('SPPSRVGetMovcoField NUMERO ha tornato: ' + IntToStr(rc)); |
end; |
// registrazione del primo record di MOVCO |
WriteLn('Registrazione del record sulla cassa...'); |
SetMovcoField('DATAREG', '20120412'); |
SetMovcoField('ESEREGISTR', '2012'); |
SetMovcoField('DATACOMPET', '20120412'); |
SetMovcoField('DTCOMPCONT', '20120412'); |
SetMovcoField('ESECOMPET', '2012'); |
SetMovcoField('SOTTOCONTO', 'CASSA '); |
SetMovcoField('CONTROPART','1270108003'); |
SetMovcoField('C_F', 'A'); |
SetMovcoField('SEGNO', 'D'); |
// imposta la causale contabile |
SetMovcoField('CAUSALE', 'PGF'); |
SetMovcoField('EIMPORTO','100.00'); |
// imposta il campo CASO a "prima nota non iva" |
SetMovcoField('CASO', '4'); |
// controllo e inserimento del record |
rc := SPPSRVCheckMovcoRecord(); |
WriteLn('SPPSRVCheckMovcoRecord ha tornato: ' + IntToStr(rc)); |
rc := SPPSRVAppendMovcoRecord(); |
WriteLn('SPPSRVAppendMovcoRecord ha tornato: ' + IntToStr(rc)); |
// registrazione del secondo record di MOVCO |
// (i campi impostati non vengono resettati da SPPSRVAppendNovcoRecord) |
WriteLn('Registrazione del record sulla banca...'); |
SetMovcoField('SOTTOCONTO','1270108003'); |
SetMovcoField('CONTROPART','CASSA '); |
SetMovcoField('SEGNO', 'A'); |
SetMovcoField('EIMPORTO', '100.00'); |
// controllo e inserimento del record |
rc := SPPSRVCheckMovcoRecord(); |
WriteLn('SPPSRVCheckMovcoRecord ha tornato: ' + IntToStr(rc)); |
rc := SPPSRVAppendMovcoRecord(); |
WriteLn('SPPSRVAppendMovcoRecord ha tornato: ' + IntToStr(rc)); |
|
// termine della transazione |
rc := SPPSRVEndMovcoTransaction(); |
WriteLn('SPPSRVEndMovcoTransaction ha tornato: ' + IntToStr(rc)); |
WriteLn('Registrazione eseguita MOVCO.NUMERO = "' + StrPas(MovcoNum) + '"'); |
|
FINE: |
// resetta la DLL |
rc := SPPSRVExit(); |
WriteLn('SPPSRVExit ha tornato: ' + IntToStr(rc)); |
|
END_OF_TEST: |
if (dll > 0 ) then FreeLibrary(dll); |
WriteLn('---------------------------------------------------'); |
WriteLn('Fine test ' + MY_LIBRARY_NAME); |
|
WriteLn('... premere <INVIO> per terminare...'); |
ReadLn; |
end. |