| |
| /* -------------------------------------------------------------------------------- |
| * |
| * Programma di esempio per il calcolo delle scadenze 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 esempio e' compilato come applicazione Windows 32bit, in quanto utilizza |
| * librerie, tra cui la SppServ.dll, che sono esplicitamente di tipo Win32. |
| * |
| * 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. |
| * |
| -------------------------------------------------------------------------------- */ |
| using System; |
| using System.IO; |
| using System.Collections.Generic; |
| using System.Text; |
| using System.Runtime.InteropServices; |
| |
| namespace SppServTest3 |
| { |
| class Program |
| { |
| //costante booleana che, se settata a true, abilita l'uso di Start v.3 |
| const bool STARTSUITE = false; |
| const string MY_LIBRARY_NAME = "sppserv.dll"; |
| const int SPPSRV_SUCCESS = 0; |
| |
| static bool IsSppServInit = false; |
| |
| [DllImport("user32.dll", SetLastError = false)] |
| static extern IntPtr GetDesktopWindow(); |
| |
| // prototipi delle funzioni della sppserv.dll |
| [DllImport(MY_LIBRARY_NAME, SetLastError = true)] |
| private static extern int SPPSRVVersion(); |
| [DllImport(MY_LIBRARY_NAME, SetLastError = true)] |
| private static extern int SPPSRVInit(IntPtr mainwnd); |
| [DllImport(MY_LIBRARY_NAME, SetLastError = true)] |
| private static extern int SPPSRVExit(); |
| [DllImport(MY_LIBRARY_NAME, SetLastError = true)] |
| private static extern int SPPSRVComuniConnect([MarshalAs(UnmanagedType.LPStr)] |
| StringBuilder comuniconnectstring); |
| [DllImport(MY_LIBRARY_NAME, SetLastError = true)] |
| private static extern int SPPSRVDittaConnect([MarshalAs(UnmanagedType.LPStr)] |
| StringBuilder dittaconnectstring); |
| [DllImport(MY_LIBRARY_NAME, SetLastError = true)] |
| private static extern int SPPSRVSetEsercizio([MarshalAs(UnmanagedType.LPStr)] |
| StringBuilder esercizio); |
| [DllImport(MY_LIBRARY_NAME, SetLastError = true)] |
| private static extern int SPPSRVSetEuro(bool IsEuro); |
| [DllImport(MY_LIBRARY_NAME, SetLastError = true)] |
| private static extern int SPPSRVSetUtente([MarshalAs(UnmanagedType.LPStr)] |
| StringBuilder utente); |
| [DllImport(MY_LIBRARY_NAME, SetLastError = true)] |
| private static extern int SPPSRVSetTodayDate([MarshalAs(UnmanagedType.LPStr)] |
| StringBuilder todaydate); |
| [DllImport("sppserv.dll", SetLastError = true)] |
| private static extern int SPPSRVCalcolaScadenze([MarshalAs(UnmanagedType.LPStr)] |
| StringBuilder szTipoPagamento, |
| [MarshalAs(UnmanagedType.Bool)] bool bValuta, |
| double dImporto, |
| [MarshalAs(UnmanagedType.LPStr)] StringBuilder szDataFattura, |
| [MarshalAs(UnmanagedType.LPStr)] StringBuilder szDataDecorrenza, |
| [MarshalAs(UnmanagedType.LPStr)] StringBuilder szGiornoParticolare, |
| [MarshalAs(UnmanagedType.LPStr)] StringBuilder szMeseSalto1, |
| [MarshalAs(UnmanagedType.LPStr)] StringBuilder szMeseSalto2, |
| [MarshalAs(UnmanagedType.LPStr)] StringBuilder szGiornoSpostamento); |
| [DllImport("sppserv.dll", SetLastError = true)] |
| private static extern int SPPSRVReadScadenza(int NumeroScadenza, ref double Importo, |
| [MarshalAs(UnmanagedType.LPStr)] StringBuilder Data, |
| [MarshalAs(UnmanagedType.LPStr)] StringBuilder Tipo); |
| |
| static void Main(string[] args) |
| { |
| int rc = 0; |
| StringBuilder MovcoNum = new StringBuilder(16); |
| |
| Console.Clear(); |
| Console.WriteLine("Test sviluppo scadenze..."); |
| System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly(); |
| string msgfilepath = assembly.CodeBase; |
| if (msgfilepath.IndexOf("file:///") >= 0) |
| msgfilepath = msgfilepath.Substring(8, msgfilepath.Length - 8); |
| msgfilepath = System.IO.Path.GetDirectoryName(msgfilepath); |
| //Verifica della presenza della SppServ.dll e delle sue dipendenze |
| if (!File.Exists(msgfilepath + "\\sppserv.dll")) |
| Console.WriteLine("Libreria SppServ.dll non trovata"); |
| else if (!File.Exists(msgfilepath + "\\xnmba423.dll")) |
| Console.WriteLine("Libreria xnmba423.dll non trovata"); |
| else if (!File.Exists(msgfilepath + "\\Sx32w.dll")) |
| Console.WriteLine("Libreria Sx32w.dll non trovata"); |
| else if (!File.Exists(msgfilepath + "\\hasp_windows_90347.dll")) |
| Console.WriteLine("Libreria Hasp_Windows_90347.dll non trovata"); |
| else if (!File.Exists(msgfilepath + "\\sppmsg.ita")) |
| Console.WriteLine("File dei messaggi SppMsg.ita non trovato"); |
| else |
| { |
| // inizializzazione della DLL |
| try |
| { |
| if ((rc = SPPSRVInit(GetDesktopWindow())) != SPPSRV_SUCCESS) |
| { |
| Console.WriteLine("Inizializzazione SppServ.dll fallita." + |
| " SPPSRVInit ha tornato: " + |
| rc.ToString()); |
| goto FINE; |
| } |
| else |
| { |
| IsSppServInit = true; |
| // numero di versione della dll |
| int sppver = SPPSRVVersion(); |
| Console.WriteLine("Inizializzazione SppServ.dll eseguita con successo." + |
| " Versione libreria (valore di ritorno di SPPSRVVersion): " + |
| sppver.ToString()); |
| } |
| } |
| catch (Exception ex) |
| { |
| Console.WriteLine("Errore generico inizializzazione SppServ.dll: " + ex.Message); |
| goto FINE; |
| } |
| // connessione al database dei dati comuni e dei dati ditta |
| if (STARTSUITE) |
| { |
| // versione per SIGLA StartSuite (archivi dui tipo DBF) |
| rc = SPPSRVComuniConnect(new StringBuilder("C:\\SIGLAPP\\PROVGEN")); |
| Console.WriteLine("SPPSRVComuniConnect ha tornato: " + rc.ToString()); |
| if (rc != SPPSRV_SUCCESS) goto FINE; |
| rc = SPPSRVDittaConnect(new StringBuilder("C:\\SIGLAPP\\PROVDIT")); |
| Console.WriteLine("SPPSRVDittaConnect ha tornato: " + rc.ToString()); |
| if (rc != SPPSRV_SUCCESS) goto FINE; |
| } |
| else |
| { |
| // versione per SIGLA (accesso ai dati via ODBC) |
| rc = SPPSRVComuniConnect(new StringBuilder("DSN=SPPGEN;UID=sigla;PWD=sigla")); |
| Console.WriteLine("SPPSRVComuniConnect ha tornato: " + rc.ToString()); |
| if (rc != SPPSRV_SUCCESS) goto FINE; |
| rc = SPPSRVDittaConnect(new StringBuilder("DSN=SPPDIT;UID=sigla;PWD=sigla")); |
| Console.WriteLine("SPPSRVDittaConnect ha tornato: " + rc.ToString()); |
| if (rc != SPPSRV_SUCCESS) goto FINE; |
| } |
| // impostazione dell'esercizio di lavoro |
| rc = SPPSRVSetEsercizio(new StringBuilder("2012")); |
| Console.WriteLine("SPPSRVSetEsercizio ha tornato: " + rc.ToString()); |
| // impostazione dell'utente |
| rc = SPPSRVSetUtente(new StringBuilder("SIGLA ")); |
| Console.WriteLine("SPPSRVSetUtente ha tornato: " + rc.ToString()); |
| // impostazione della data |
| rc = SPPSRVSetTodayDate(new StringBuilder("20121113")); |
| Console.WriteLine("SPPSRVSetTodayDate ha tornato: " + rc.ToString()); |
| // impostazione dell'euro come valuta di lavoro |
| rc = SPPSRVSetEuro(true); |
| Console.WriteLine("SPPSrvSetEuro ha tornato: " + rc.ToString()); |
| // calcolo delle scadenze |
| Console.WriteLine("Calcolo della scadenza..."); |
| // parametri |
| string DataFattura = "20121113"; |
| string DataDecPag = "20121130"; |
| string GGPart = ""; |
| string MSalto1 = ""; |
| string MSalto2 = ""; |
| string GGSalto = ""; |
| double TRata = 1000.0; |
| bool IsValuta = false; |
| string TipoPag = "RB02"; |
| rc = SPPSRVCalcolaScadenze(new StringBuilder(TipoPag), IsValuta, TRata, |
| new StringBuilder(DataFattura), new StringBuilder(DataDecPag), |
| new StringBuilder(GGPart), new StringBuilder(MSalto1), |
| new StringBuilder(MSalto2), new StringBuilder(GGSalto)); |
| Console.WriteLine("SPPSRVCalcolaScadenze ha tornato: " + rc.ToString()); |
| |
| // lettura delle scadenze |
| int numscad = rc; |
| double importo = 0; |
| StringBuilder data = new StringBuilder(8); |
| StringBuilder tipo = new StringBuilder(4); |
| if (numscad > 0) |
| { |
| // int DLLCALL SPPSRVReadScadenza(int nscad,double *importo,LPSTR data,LPSTR tipo); |
| for (int j = 1; j <= numscad; j++) |
| { |
| rc = SPPSRVReadScadenza(j, ref importo, data, tipo); |
| if( rc == 0) |
| Console.WriteLine(j.ToString() + ") Data: " + data.ToString().Substring(6, 2) + |
| "/" + data.ToString().Substring(4, 2) + "/" + |
| data.ToString().Substring(0, 4) + " Importo: " |
| + importo.ToString()); |
| else |
| Console.WriteLine(j.ToString() + ") SPPSRVReadScadenza ha tornato: " + rc.ToString()); |
| } |
| } |
| } |
| FINE: |
| // resetta la DLL |
| if (IsSppServInit) |
| { |
| if ((rc = SPPSRVExit()) == SPPSRV_SUCCESS) |
| Console.WriteLine("Deinizializzazione SppServ.dll eseguita con successo"); |
| Console.WriteLine("SPPSRVExit ha tornato: " + rc.ToString()); |
| } |
| Console.WriteLine("... premere <INVIO> per terminare..."); |
| Console.ReadKey(); |
| } |
| } |
| } |