What is the best way to integrate with quickbooks from C# code? [closed]

≯℡__Kan透↙ 提交于 2019-11-30 09:34:52

I used the Quickbooks SDK because I was developing a import tool for a friend and we didn't have the luxury of buying a 3rd party library.

I started developing it as a web service, but I had to fall back after realizing that, not only does we need to deploy the redistribuable of the Quickbooks SDK on the server, but we also needed Quickbooks itself to be installed. And more often than never, Quickbooks displayed a dialog, which on a server is bad.

As long as that dialog was open, Quickbooks SDK would refuse any connection to it.

I ended up doing it as a pure C# Winform application. From there, its rather strait-forward.

At the heart of the program was a quickbook session class that handled the session and the message

public static class Quickbooks
{
    public static QuickbookSession CreateSession()
    {
        return new QuickbookSession();
    }
}

public class QuickbookSession : IDisposable
{
    /// <summary>
    /// Initializes a new instance of the <see cref="QuickbookSession"/> class.
    /// </summary>
    internal QuickbookSession()
    {
        this.SessionManager = new QBSessionManager();

        this.SessionManager.OpenConnection2(
            ConfigurationManager.AppSettings["QuickbooksApplicationId"],
            ConfigurationManager.AppSettings["QuickbooksApplicationName"],
            Utils.GetEnumValue<ENConnectionType>(ConfigurationManager.AppSettings["QuickbooksConnectionType"]));

        var file = Quickbook.QuickbookDatabaseFilePath;
        if (string.IsNullOrEmpty(file))
        {
            file = ConfigurationManager.AppSettings["QuickbooksDatabaseLocalPath"];
        }

        this.SessionManager.BeginSession(file, Utils.GetEnumValue<ENOpenMode>(ConfigurationManager.AppSettings["QuickbooksSessionOpenMode"]));
    }

    /// <summary>
    /// Gets the Quickbook session manager that is owning this message.
    /// </summary>
    public QBSessionManager SessionManager { get; private set; }

    public QuickbookMessage CreateMessage()
    {
        return new QuickbookMessage(this.SessionManager);
    }

    public void Dispose()
    {
        Dispose(true);
        GC.SuppressFinalize(this);
    }

    protected virtual void Dispose(bool disposing)
    {
        if (disposing)
        {
            // get rid of managed resources
        }

        this.SessionManager.EndSession();
        this.SessionManager.CloseConnection();

        System.Runtime.InteropServices.Marshal.ReleaseComObject(this.SessionManager);
    }
}

After that, it was simple a matter of creating a session, creating a message and appending the different query.

using(var session = Quickbooks.CreateSession())
{
    // Check if the job already exist
    using (var message = session.CreateMessage())
    {
        var jobQuery = message.AppendCustomerQueryRq();
        jobQuery.ORCustomerListQuery.CustomerListFilter.ORNameFilter.NameFilter.Name.SetValue("something");
        jobQuery.ORCustomerListQuery.CustomerListFilter.ORNameFilter.NameFilter.MatchCriterion.SetValue(ENMatchCriterion.mcContains);

        var result = message.Send();

        // do stuff here with the result
    }
}

This code is far from being bullet proof from the many pitfall of Quickbooks. The Quickbooks SDK is also rather slow. For example, retrieving the list of supplier takes about 2 minutes for about 1000 suppliers.

I have decided to go with another product not mentioned above called "QuickBooks ADO.NET Data Provider" it is apparently made by the same folks who make the QuickBooks integrator product

The reasons I chose it...

1) It has a remote access component
You install the remote server, and you can access your QuickBooks data from anywhere on your network

2) The remote access component can run as a service
Nuff said

3) Provides a SQL style interface to the QuickBooks data
4) Does some auto magic caching to speed up the data access

I used the QuickBooks integrator from nSoftware on a project that I was on. It is way easier than using the QuickBooks SDK and the support is great. That product has been around for around 8 years.

http://www.nsoftware.com/ibiz/quickbooks/

While I am sure there are some cases in which it will not work, my first direction of attack would be the Quickbooks SDK found at the Intuit developer center.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!