根据我的研究,基本上有 3 个选项。
1:使用COM
2:使用网络服务和网络连接器
3:使用第 3 方组件(而且似乎有很多)
这些选项中的每一个都给我带来了问题:
1:有人告诉我我不能使用 COM
2:这个解决方案对我来说似乎很虚伪,因为我需要从 Windows 服务进行集成
3:其中一些解决方案相当昂贵。
我看来我将不得不走第 3 方路线,并且在我的脑海中有两个领先者:
1: QODBC (http://www.qodbc.com/usa.html)
2:AccessBooks (http://www.synergration.com/AccessBooksUpdater/default.aspx)
亲爱的读者,我的问题如下:
1:您会使用哪种解决方案(com、网络服务、哪个第 3 方)?
2:为什么选择它而不是其他选项?
3:还有其他我错过的选择吗?
我使用 Quickbooks SDK 是因为我正在为 friend 开发导入工具,而我们没有购买第 3 方库的奢侈。
我开始将它开发为 Web 服务,但在意识到我们不仅需要在服务器上部署 Quickbooks SDK 的可再发行组件之后,我不得不退缩,还需要安装 Quickbooks 本身。 Quickbooks 经常显示一个对话框,这在服务器上是错误的。
只要该对话框处于打开状态,Quickbooks SDK 就会拒绝与其建立任何连接。
我最终将它作为一个纯 C# Winform 应用程序来做。从那里开始,它相当直截了当。
程序的核心是一个处理 session 和消息的 quickbook session 类
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);
}
}
之后,只需创建 session 、创建消息并附加不同的查询即可。
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 分钟。