Initiate UserSession and DBSetting

Revision as of 04:46, 10 March 2023 by DanielY (talk | contribs)

Initiate UserSession and Connect to AutoCount Accounting 2.1

There are 3 methods to establish connection to AutoCount Accounting 2.1.

  1. Unattended connection without loading UI components
  2. Unattended connection that load UI components (needs UI components)
  3. User login to establish connection (needs UI components)
UI Components require System.Windows.Forms and DevExpress winForm components. 
  UserSession must only initiate once in the application.

Do not create more than one instance in a running application. As it may consume system resource and has an impact on your application performance.
After obtained the object of UserSession, pass it as parameter in constructor or method.


Unattended Connection without loading UI components

Nuget package: AutoCount2.Accounting

This MainEntry is commonly used for integration, or when no user login is required to access and initiate AutoCount Accounting, and it does not load UI components.

internal UserSession InitiateUserSessionUnattended(string serverName, string dbName, string userLogin, string userPasswd)
{
    AutoCount.MainEntry.Startup startup = new AutoCount.MainEntry.Startup();
    AutoCount.Data.DBSetting dbSetting = new AutoCount.Dadta.DBSetting(
                                          DBServerType.SQL2000, serverName, dbName);
    AutoCount.Authentication.UserSession userSession = new 
                                         AutoCount.Authentication.UserSession(dbSetting);
            
    if (userSession.Login(userLogin, userPasswd))
    {
        //2nd parameter is to load plug-in when value is true.
        //set 2nd parameter to false if do not want to load plug-in.
        startup.SubProjectStartup(userSession, true);
    }
    return userSession;
}


Unattended connection that load UI components

Nuget package: AutoCount2.Accounting.UI

This MainEntry.UIStartup is similar to the MainEntry.Startup, except that it loads UI components. When MainEntry.UIStartup is used, AutoCount images and DevExpress are required.

internal UserSession InitiateUserSessionUnattendedWithUI(string serverName, string dbName, string userLogin, string userPasswd)
{
    AutoCount.MainEntry.UIStartup startup = new AutoCount.MainEntry.UIStartup();
    AutoCount.Data.DBSetting dbSetting = new AutoCount.Dadta.DBSetting(
                                          DBServerType.SQL2000, serverName, dbName);
    AutoCount.Authentication.UserSession userSession = new 
                                         AutoCount.Authentication.UserSession(dbSetting);
            
    if (userSession.Login(userLogin, userPasswd))
    {
        //2nd parameter is to load plug-in when value is true.
        //set 2nd parameter to false if do not want to load plug-in.
        startup.SubProjectStartup(userSession, true);
    }
    return userSession;
}

User login to establish connection (needs UI components)

Nuget package: AutoCount2.MainEntry

This MainEntry opens the AutoCount Accounting user login form, and with successful login, it returns the object of the UserSession.
If user clicked [Cancel], the object of UserSession is null.

internal AutoCount.Authentication.UserSession InitiateUserSessionWithLogin()
{
    return AutoCount.MainEntry.MainStartup.Default.SubProjectStartupWithLogin("", "");
}

Go to menu

  Go to top
  Resources For AutoCount Software Developers