从 C# 代码与 Quickbook 集成的最佳方式是什么?

发布于 2024-11-30 01:36:07 字数 1432 浏览 0 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

痞味浪人 2024-12-07 01:36:07

我使用 Quickbooks SDK 是因为我正在为朋友开发一个导入工具,而我们没有能力购买第 3 方库。

我开始将其开发为 Web 服务,但在意识到我们不仅需要在服务器上部署 Quickbooks SDK 的可再发行版本,而且还需要安装 Quickbooks 本身后,我不得不退缩。 Quickbooks 通常会显示一个对话框,这在服务器上是很糟糕的。

只要该对话框打开,Quickbooks SDK 就会拒绝与其建立任何连接。

我最终将其作为纯 C# Winform 应用程序来完成。从那里开始,它就相当直截了当了。

该程序的核心是一个处理会话和消息的 Quickbook 会话类。

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);
    }
}

之后,创建会话、创建消息并附加不同的查询就很简单了。

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
    }
}

这段代码远非能够抵御 Quickbooks 的许多陷阱。 Quickbooks SDK 也相当慢。例如,检索大约 1000 个供应商的供应商列表大约需要 2 分钟。

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.

卸妝后依然美 2024-12-07 01:36:07

我决定使用上面未提及的另一个产品,称为“QuickBooks ADO.NET Data Provider”,它显然是由制作 QuickBooks 集成器产品的同一个人制作的。

我选择它的原因...

1) 它有一个远程访问组件
您安装远程服务器,然后可以从网络上的任何位置访问 QuickBooks 数据

2) 远程访问组件可以作为服务运行
Nuff 说

3) 为 QuickBooks 数据提供 SQL 风格的接口
4) 进行一些自动魔法缓存以加速数据访问

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

白馒头 2024-12-07 01:36:07

我在我参与的一个项目中使用了 nSoftware 的 QuickBooks 集成器。它比使用 QuickBooks SDK 容易得多,而且支持也很棒。该产品已经问世约 8 年了。

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

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/

懵少女 2024-12-07 01:36:07

虽然我确信在某些情况下它不起作用,但我的第一个攻击方向是在 Intuit 上找到的 Quickbooks SDK开发者中心

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文