C Additional Functionality

From Sage Evolution SDK | Documentation Portal
Jump to: navigation, search

The following are some useful functionalities in the SDK

The following example shows how validation can be done on a Evolution username and password.

bool valid = Agent.Authenticate(AgentName.Text, Password.Text);
MessageBox.Show(valid.ToString());

Any transaction can be processed using a evolution user as follows

DatabaseContext.CurrentAgent = new Agent("User2");

On a online branch accounting database a specific branch can be specified as follows.

DatabaseContext.SetBranchContext(1);

User defined fields can be updated as follows

SalesOrder SO = new SalesOrder("SO00023");//Specify the order number to process
SO.UserFields["ucIITestSO"] = "this is a user field";

User fields can also be used to update existing fields where properties don't exist like on a Customer

Customer cust = new Customer();
cust.Code = "Test1";
cust.Description = "test1";
cust.UserFields["BFOpenType"] = 1;//The existing field will be case sensitive bfopentype wont work
cust.Save();

The following List method displays a list of unprocessed Sales Orders the ListArchived method will display processed orders that are now invoices

dataGridView1.DataSource = SalesOrder.List(" Account = 'Cash'");

PriceLists can be displayed per customers

DataTable PriceList = SellingPrice.ListByStockItemID(1002);

How do I integrate with 2 or more Evolution databases?

Whenever calling the DatabaseContext.CreateConnection method, the active connection is closed and the new connection will be used for all following operations.

Take note of the following:

When switching the connection, the active transaction (if any) will be rolled back. Any records existing in memory, belonging to the previous connection are now invalid and not be relied on It is advised to perform all multi-database posting in database sequence; i.e. instead of switching between databases to and fro, rather sort your source transactions by target database and switch databases as seldom as possible.

Will the SDK check for and prevent duplicate transactions from being processed?

No. The SDK will not prevent duplicate transactions from being processed. This allows for flexibility on what defines a duplicate transaction, but also means that you will have to avoid duplications yourself. The preferred method of doing this when importing transactions from an external database is to flag transactions in the foreign database after processing them in Evolution. Alternatively, use the following function as a guide:

private bool isTransactionPosted(CustomerTransaction transaction)
        {
            string criteria = string.Format(@"Reference = '{0}' and Id = '{1}' and AccountLink = {2}", 
                transaction.Reference, transaction.ModID.ToString(), transaction.AccountID);
            return CustomerTransaction.Find(criteria) != -1;
            // ..or just raise an exception
        }

When should I use BeginTran(), CommitTran(), and RollbackTran() for managing database transactions?

In early versions of the SDK, the you were required to manage a database transaction for each and every operation. Recent versions of the SDK removed this requirement by implicitly creating a transaction scope if a transaction is not already in session.

There as still some cases in which you may want to manually control the database transaction. This technique will mostly be used to process a large number of accounting transactions and rolling back the entire session if a single accounting transaction fails. In such a case, you would manually call BeginTran and start looping through transaction posting. You should ensure that this takes place within a try-catch block and that you call RollbackTran as soon as an exception is caught. CommitTran would normally be the final step in your try block. It is also advisable to call StartNewBatch after posting each accounting transaction to separate each into its own audit batch.

try
{
    BeginTran();
    [loop]
    {
        [post transaction]
        StartNewBatch();
    }
    CommitTran();
}
catch
{
    RollbackTran()
}

There might be other cases in which it is desirable to group transactions into a single batch. In those cases, StartNewBatch should not be called. When posting GL transactions, you are still required to manage the transaction scope since multiple GL transactions are required for a balanced batch.

Can I generate or print an Evolution document/report using the SDK?

No. The Evolution printing component is specific to its development platform and not available in the SDK. You will have to generate any documents for printing in your project. Print groups can also be created and documents linked together for later batch printing from inside Evolution.