tôi đã sử dụng Quickbooks SDK bởi vì tôi đã phát triển một công cụ nhập khẩu đối với một người bạn và chúng tôi không có sự sang trọng của việc mua một thư viện của bên thứ 3.
Tôi bắt đầu phát triển nó như một dịch vụ web, nhưng tôi phải quay lại sau khi nhận ra điều đó, chúng tôi không chỉ cần triển khai Redbooks của Quickbooks SDK trên máy chủ mà còn cần cài đặt Quickbooks. Và thường xuyên hơn bao giờ hết, Quickbooks hiển thị một hộp thoại, mà trên một máy chủ là xấu.
Khi hộp thoại đó được mở, Quickbooks SDK sẽ từ chối mọi kết nối với nó.
Tôi đã kết thúc hoạt động như một ứng dụng C# Winform thuần túy. Từ đó, nó khá thẳng thắn.
Tại trung tâm của chương trình là một lớp phiên quickbook rằng xử lý phiên và thông điệp
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);
}
}
Sau đó, nó rất đơn giản là vấn đề của việc tạo ra một phiên, tạo một thông điệp và phụ truy vấn khác nhau .
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
}
}
Mã này cách xa bằng chứng đạn từ nhiều lỗ hổng của Quickbooks. Quickbooks SDK cũng khá chậm.Ví dụ, lấy danh sách nhà cung cấp mất khoảng 2 phút cho khoảng 1000 nhà cung cấp.
Nguồn
2011-08-16 20:11:24
Đối với dịch vụ cửa sổ, COM interop có vẻ như là giải pháp tốt nhất trong số đó. –
Mặc dù thực tế rằng nó có thể là một chút lộn xộn, có gì sai khi sử dụng COM? –
@JP, Chúng tôi sẽ gọi đó là yêu cầu kinh doanh – iamkrillin