示例#1
0
        public static bool Connect(string companyname)
        {
            bool result = true;

            try
            {
                application = new Application();
                application.Connect();
                foreach (Sage.Accounting.Company company in application.Companies)
                {
                    if (company.Name == companyname)
                    {
                        application.ActiveCompany = company;
                    }
                }

                result = application.ActiveCompany == null ? false : true;
            }
            catch (Exception ex)
            {
                // TODO - LOGGING
                result = false;
            }
            return(result);
        }
        private void Connect()
        {
            if (_app == null)
            {
                _app = new Sage.Accounting.Application();
                _app.Connect();
            }

            if (_company == null)
            {
                _company           = _app.Companies[0];
                _app.ActiveCompany = _company;
            }
        }
        private static void Connect()
        {
            // Declare the Application object used to connect.
            Sage.Accounting.Application application = null;

            try
            {
                application = new Sage.Accounting.Application();

                // Use the Connect method (no parameters required)
                application.Connect();

                // IMPORTANT: select the company (database) - a connection will not be made
                // unless this line is included.
                // In this example an indexer is used to select the company. This
                // is fine if there is only one company. If there are multiple companies a more
                // appropriate solution would be to iterate the collection checking the Name property.
                application.ActiveCompany = application.Companies[0];

                System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();

                stringBuilder.Append("Successfully logged on to " + application.ActiveCompany.Name);

                System.Diagnostics.Debug.WriteLine(stringBuilder.ToString());
            }
            // The Connect method may throw the following exceptions:
            // Ex9990Exception - User already logged in.
            // Ex9991Exception - Maximum number of users logged in.
            catch (System.Exception exception)
            {
                System.Diagnostics.Debug.WriteLine(exception.Message);
            }
            finally
            {
                if (application != null)
                {
                    // Disconnect from the application
                    application.Disconnect();
                }
            }
        }