Programmer:Simple program to test connection to AutoCount Accounting

From AutoCount Resource Center

Version Applicable

AutoCount Accounting 1.8.30.136 and higher

Introduction

In order to connect to one of the account book in AutoCount Accounting, there are few steps to start with.
To understand each of the steps, a program is written to test the result of each step.
STEP 1. Create DBSetting STEP 2. Call (Create) SubProjectStartup STEP 3. Login to AutoCount Accounting
Download Sample Project (Visual Studio 2015)

Sample project to test connection to AutoCount Accounting.



DBSetting

DBSetting is one of the most frequently used class in AutoCount Accounting, whether it is plug-in or integrating system.
Even when writing scripting for report script or application script, you may find the object of DBSetting is provided.
DBSetting is required by all transactions and documents when accessing to database server.
Moreover, it provides methods such as GetDataTable(...), ExecuteScalar(...), ExecuteNonQuery(...) and more for programmer to easily access to currently connected account book.
During its creation, two pieces of information is important, they are the server name and database name.
Namespace: BCE.Data

Create DBSetting with AutoCount default configuration

DBSetting object can be created with new operator, or via SubProjectStartupWithLogin method.
Below example code shows the DBSetting is created with new operator.

BCE.Data.DBSetting dbSetting = new BCE.Data.DBSetting(DBServerType.SQL2000, serverName, dbName);


Create DBSetting while specifying SQL Server sa password

BCE.Data.DBSetting dbSetting = new BCE.Data.DBSetting(DBServerType.SQL2000, serverName, "sa", "mYsApAsSwOrD", dbName);
  • sa login password can be omitted when the password is using AutoCount default sa login password.
  • Specify the sa password only when sa password has been changed.


Success of created DBSetting does not justify whether the provided information connecting to SQL Server is correct.
DBSetting merely store the information that is essential to connect SQL Server.



SubProjectStartupWithLogin

  • When using SubProjectStartupWithLogin it does the following tasks:
    1. Return DBSetting upon success login. Whereas, return null when user clicks cancel.
    2. Initiate AutoCount Accounting system
    3. Login to AutoCount Accounting


BCE.Data.DBSetting dbSetting = BCE.AutoCount.MainEntry.Startup.Default.SubProjectStartupWithLogin("", "");

//dbSetting is null when user did not login by pressing 'Cancel'
if (dbSetting != null)
{
    //Do something after DBSetting, SubProjectStartup, and Login to AutoCount Accounting are all successful
}
else
{
    //Exit, prompt message or throw error
}
  • Requires two values to specify where AutoCount Accounting Database Info are stored;
  • To let AutoCount Accounting use default path, set the two values to empty string.
When calling SubProjectStartupWithLogin, it prompts login form for user to input.
Upon successful login, it returns DBSetting, initialized AutoCount Accounting system and Login to AutoCount Accounting.
If user cancel login, the return value of DBSetting is null.


SubProjectStartup

When call SubProjectStartup, DBSetting object must be created before SubProjectStartup can be used.
It does not return any result. It throws exception, when error is encountered.

SubProjectStartup is to initialize AutoCount Accounting system, while it also perform below two important tasks:-

  1. Whether to load plug-in
    Some plug-in may contain script that calculate the subtotal which may require to be loaded.
  2. Load account book Licensing
    License Code or Dongle


Four overloading methods of SubProjectStartup

//Does not load Plug-In
//Load license control by license code
void BCE.AutoCount.MainEntry.Startup.Default.SubProjectStartup(DBSetting dbSetting);


//Programmer define whether plug-in will be loaded
//Load license control by license code
void BCE.AutoCount.MainEntry.Startup.Default.SubProjectStartup(DBSetting dbSetting, BCE.AutoCount.MainEntry.StartupPlugInOption loadPlugInOption);


//Programmer define whether plug-in will be loaded
//Programmer define which type of license control to be loaded, either License Code or Dongle
void BCE.AutoCount.MainEntry.Startup.Default.SubProjectStartup(DBSetting dbSetting, BCE.AutoCount.MainEntry.StartupPlugInOption loadPlugInOption,
    BCE.AutoCount.MainEntry.StartupLicenseControlType slcType);


//Programmer define whether plug-in will be loaded
//Programmer define which type of license control to be loaded, either License Code or Dongle
//and define the IP and Port of USB server for Dongle License
void BCE.AutoCount.MainEntry.Startup.Default.SubProjectStartup(DBSetting dbSetting, BCE.AutoCount.MainEntry.StartupPlugInOption loadPlugInOption,
    BCE.AutoCount.MainEntry.StartupLicenseControlType slcType, string dgServerName, int dgServerPort);
  • There are 4 overloading methods when calling SubProjectStartup (Reference of version 1.8.30.186)
    • Prior to version 1.8.30.186, SubProjectStatup does not include the parameter of StartupPlugInOption;
    • StartupPlugInOption allows programmer to set whether to load plug-in, when AutoCount Accounting is initialized.
  • Dongle server name is the IP address of the computer where USB Key Server (windows service) is installed.
  • The dongle's default server port is 9560.
    • Port setting can be found in, Tools | Options -> General | Miscellaneous -> USB Key Setting
    • Default value is used when port is not defined in SubProjectStartup.


For inter-billing and integration, if StartupPlugInOption.LoadStandardPlugIn is not stated in SubProjectStartup, the target account book will not load plug-in that has/have installed.


Error: InvalidLCPFileException

Invalid LCP File Exception is common error when calling SubProjectStartup or SubProjectStartupWithLogin when loading from a standalone program or web application.

Exception Namespace: BCE.LCP.InvalidLCPDecryptFileException

Solution

Include LCP files together with your exe or dll which is calling SubProjectStartup.

  • To let Visual Studio copy these files to output folder for debugging, follow steps below:
  1. Find these files in AutoCount Accounting folder.
    • LCPDecrypt.wdl
    • LCPDecrypt2.exe
    • LCPDecrypt2.wdl
    • LCPDecryptApp.exe
  2. Add these files to your Project as existing items.
    • Set Build Action = none (empty)
    • Copy to Output = Copy if newer
So that these files will be copied to project output folder.
Refer to Invalid LCPDecryptFileException was unhandled


Login to AutoCount Accounting

In order to create transaction and document, Login to AutoCount Accounting is required.

bool loginSuccess = BCE.AutoCount.Authentication.UserAuthentication.GetOrCreate(dbset).Login(userID, password);

if (loginSuccess)
{
    //Do something
}
else
{
    //Exit, prompt message or throw error
}


See Also


Go to menu

Go to top
Resources For AutoCount Software Developers