Venice
C++ example
 
The following topics are available:
the actual example
Remark: This example doesn't contain any business logic, it is just meant to show the possibilities and syntax of the SDK.
 
Example
 
// CppClient.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "CppClient.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif

#include <atlbase.h>
#include <ATLComTime.h>

#import "Venice\Bin\ClSdk.dll"

using namespace std;
using namespace ClSdk;

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
    OleInitialize (NULL);

    try
    {
        // These are not 'real' pointers, but 'smart' pointers, looking as pointers but acting as objects, so do not use 'delete'!
        IVenicePtr   pVenice;
        IDossierPtr  pDossier;
        ICustmPtr    pCustm;
        IYearPtr     pYear;
        IBalanPtr    pBalan;
        ISalesPtr    pSales;
        eAccessMode  eAM;
        VARIANT      vPer0, vPer1, vPer2, vPer3, vPer4, vRem;
        double       dValue;
        CString      strStreet, strCity, strPostal, strValue;
        long         lSysNum;

        // Create the Venice object interface
        pVenice.CreateInstance(__uuidof(ClSdk::Venice));

        // Is option 'Access Management' installed?
        eAM = pVenice->GetAccessMode ();

        // Logon into Venice, allowing user interface - script written for version 13.30_
        if (eAM == amSecure)
            pVenice->LogonSecure ("13.30_", "MyApplication", lngNld, true, "ClSdkUser", "ClSdkPassword");
        else
            pVenice->Logon ("13.30_", "MyApplication", lngNld, true, "SDK", "ClSdkUser", "Software engineer");

        // Get some Venice properties
        printf ("Venice user: %s\nWindows user: %s", (LPCSTR)pVenice->vUserName, (LPCSTR)pVenice->vWindowsUser);

        // Create DossierContext, use the default filing cabinet 'Data' and the dossier 'MyCompany'
        pDossier = pVenice->CreateDossierContext("", "MyCompany");

        // Get some Dossier properties
        printf ("\nFull path name: %s\nLast financial year: %d", (LPCSTR)pDossier->vPath, (short)pDossier->vLastYear);

        // Create YearContext - 0 = last year
        pYear = pDossier->CreateYearContext (0);

        // Create a customer object - CanChange = true
        pCustm = pDossier->CreateCustm (true);

        // Seek a customer in Brugge
        if (pCustm->SeekByPostal (smEqual, "8000"))
        {
            // Show customer found
            pCustm->View ();

            // Get some Customer properties
            strStreet = pCustm->pStreet;
            strPostal = pCustm->pPostalCode;
            strCity   = pCustm->pCity;

            // Change some Customer properties
            pCustm->pStreet     = "SDK Street";
            pCustm->pPostalCode = 1234;
            pCustm->pCity       = "SDK Town";

            // And update the Customer Card
            pCustm->Update (umFullReport);

            // Show the result
            pCustm->View ();

            // Restore original values with alternative way of setting a property
            pCustm->SetFieldVal (cusfStreet, (LPCSTR)strStreet);
            pCustm->SetFieldVal (cusfPostalCode, (LPCSTR)strPostal);
            pCustm->SetFieldVal (cusfCity, (LPCSTR)strCity);

            // And update the Customer Card again
            pCustm->Update (umFullReport);

            // Verify if the update succeeded, using the string version of GetField
            if (strPostal != (LPCSTR)pCustm->GetFieldStr (cusfPostalCode))
                printf ("\nUpdate failed!");
        }
        else
            printf ("\nNo customer found in Brugge.");

        // Now select a Customer using the browse list
        lSysNum = pCustm->Browse (false);

        // lSysNum != 0 means a customer was selected in the browse
        if (lSysNum != 0)
        {
            // Seek the selected record
            if (pCustm->SeekBySysNum (smEqual, lSysNum))
            {
                // and update it in a dialog
                pCustm->Update (umDialog);

                // Get the balance of the current Customer
                dValue = pCustm->GetBalance (0);

                // If a balance was returned, get the expired amounts
                if (dValue != 0.0)
                {
                    dValue = pCustm->GetExpired (0, &vPer0, &vPer1, &vPer2, &vPer3, &vPer4, &vRem);

                    // If there are open documents in period 2 or higher, show the documents
                    if (vPer2.dblVal + vPer3.dblVal + vPer4.dblVal != 0.0)
                    {
                        lSysNum = pCustm->BrowseDocuments ((long)pCustm->pNumber);

                        // lSysNum != 0 means a document was selected
                        if (lSysNum != 0)
                        {
                            // Create Sales Object - CanChange = false
                            pSales = pYear->CreateSales (false);

                            // Seek the selected document
                            if (pSales->SeekBySysNum (smEqual, lSysNum))
                                pSales->View ();        // and show it
                        }
                    }
                }
            }
        }

        // pSales is no longer needed
        pSales = NULL;

        // We are interested in the turnover, so create a Balance object - CanChange = false
        pBalan = pYear->CreateBalan (false);

        // Get the balance for all accounts starting with '70' for the complete financial year
        dValue = pBalan->GetBalance ("70*", 0);

        // Show the result
        printf ("\nTotal turnover: %0.2lf", dValue);

        // pBalan is no longer needed
        pBalan = NULL;
        
        // Get the last Customer in the file - the parameter is redundant
        if (pCustm->SeekBySysNum (smLast, 0))
        {
            // Remember system number of last Customer
            lSysNum = (long)pCustm->pSysNum;

            // Import some new Customers
            pCustm->ImportDialog ();

            // Enumerate the newly imported Customers
            if (pCustm->SeekBySysNum (smGreater, lSysNum))
            {
                strValue = "";
                // Until not EOF
                while (pCustm->GetDBStatus () == 0)
                {
                    strValue += (CString)pCustm->pName.bstrVal + "\n";

                    // Seek the next customer (with a greater system number)
                    pCustm->GetNext ();
                } 
                printf ("\n%s", strValue);
            }
        }

        // Done, delete the customer
        // pCustm->Delete (dmFullReport);

        // No need to destroy the remaining objects, they are destroyed automatically when going out of scope
    }

    catch (_com_error CE)
    {
        printf ("\nError while executing application.\nReason: %s\nSource: %s", (LPCSTR)CE.Description (), (LPCSTR)CE.Source ()); 
    }

    // All objects must be out of scope (or destroyed) before calling OleUninitialize ()!
    OleUninitialize ();
}