如何使用QBFC13和C#获取一个月的所有发票并将其全部保存为PDF?

如何使用QBFC13和C#获取一个月的所有发票并将其全部保存为PDF?,c#,pdf,quickbooks,qbxml,qbfc,C#,Pdf,Quickbooks,Qbxml,Qbfc,我正在制作一个应用程序,获取一个月的所有发票,然后将每个发票保存为PDF格式,我从未使用QuickBooks开发过,所以我对它知之甚少。有人能给我一些源代码来做这个或类似的事情吗?我发现了几个链接,我认为它们为我指明了正确的方向,但我不是100%确定: 我正在使用C#.NET和QBFC13Lib 编辑: 我使用此代码从链接问题获取所有发票 bool sessionBegun = false; bool connectionOpen = false; QBSe

我正在制作一个应用程序,获取一个月的所有发票,然后将每个发票保存为PDF格式,我从未使用QuickBooks开发过,所以我对它知之甚少。有人能给我一些源代码来做这个或类似的事情吗?我发现了几个链接,我认为它们为我指明了正确的方向,但我不是100%确定:

我正在使用C#.NET和QBFC13Lib

编辑:

我使用此代码从链接问题获取所有发票

bool sessionBegun = false;
        bool connectionOpen = false;
        QBSessionManager sessionManager = null;

        try
        {
            //Create the session Manager object
            sessionManager = new QBSessionManager();

            //Create the message set request object to hold our request
            IMsgSetRequest requestMsgSet = sessionManager.CreateMsgSetRequest("US", 13, 0);
            requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;

            //Connect to QuickBooks and begin a session
            sessionManager.OpenConnection("", "GenerateInvoicePDFs");
            connectionOpen = true;
            sessionManager.BeginSession("", ENOpenMode.omDontCare);
            sessionBegun = true;

            IInvoiceQuery invoiceQueryRq = requestMsgSet.AppendInvoiceQueryRq();

            invoiceQueryRq.IncludeLineItems.SetValue(true);

            //Send the request and get the response from QuickBooks
            IMsgSetResponse responseMsgSet = sessionManager.DoRequests(requestMsgSet);
            IResponse response = responseMsgSet.ResponseList.GetAt(0);
            IInvoiceRetList invoiceRetList = (IInvoiceRetList)response.Detail;

            var invoices = new List<Invoice>();

            if (invoiceRetList != null)
            {
                for (int i = 0; i < invoiceRetList.Count; i++)
                {
                    IInvoiceRet invoiceRet = invoiceRetList.GetAt(i);

                    var invoice = new Invoice
                    {
                        QuickBooksID = invoiceRet.TxnID.GetValue(),
                        EditSequence = invoiceRet.EditSequence.GetValue()
                    };
                }
            }
        }
        catch
        {

        }
bool sessionbegined=false;
bool connectionOpen=false;
QBSessionManager会话管理器=null;
尝试
{
//创建会话管理器对象
sessionManager=newqbsessionmanager();
//创建消息集请求对象以保存我们的请求
IMsgSetRequest requestMsgSet=sessionManager.CreateMsgSetRequest(“US”,13,0);
requestMsgSet.Attributes.OnError=ENRqOnError.roeContinue;
//连接到QuickBooks并开始会话
OpenConnection(“,“GenerateInvoicePDFs”);
connectionOpen=true;
sessionManager.BeginSession(“,ENOpenMode.omDontCare);
sessionbegined=true;
IInvoiceQuery invoiceQueryRq=requestMsgSet.AppendInvoiceQueryRq();
invoiceQueryRq.IncludeLineItems.SetValue(true);
//发送请求并从QuickBooks获取响应
IMsgSetResponse responsemssgset=sessionManager.DoRequests(requestMsgSet);
IResponse response=responsemsgsset.ResponseList.GetAt(0);
IInvoiceRetList invoiceRetList=(IInvoiceRetList)response.Detail;
var发票=新列表();
if(invoiceletlist!=null)
{
for(int i=0;i

我收到一个错误,说明发票不是一种类型。

SDK在查询对象上提供过滤器,使您能够查询数据子集。您可以根据交易日期筛选发票:

// get all invoices for the month of august 2016
invoiceQueryRq.ORInvoiceQuery.InvoiceFilter.ORDateRangeFilter.TxnDateRangeFilter.ORTxnDateRangeFilter.TxnDateFilter.FromTxnDate.SetValue(new DateTime(2016, 8, 1));
invoiceQueryRq.ORInvoiceQuery.InvoiceFilter.ORDateRangeFilter.TxnDateRangeFilter.ORTxnDateRangeFilter.TxnDateFilter.ToTxnDate.SetValue(new DateTime(2016, 8, 31));
或者,您可以查询在给定日期范围内已修改的发票:

// all invoices modified in the month of August 2016
invoiceQueryRq.ORInvoiceQuery.InvoiceFilter.ORDateRangeFilter.ModifiedDateRangeFilter.FromModifiedDate.SetValue(new DateTime(2016, 8, 1));
invoiceQueryRq.ORInvoiceQuery.InvoiceFilter.ORDateRangeFilter.ModifiedDateRangeFilter.ToModifiedDate.SetValue(new DateTime(2016, 8, 31));
在您正在使用的代码中,当您调用BeginSession时,第一个参数为空。虽然这是通过获取当前打开的公司文件来实现的,但建议明确提供要查询的公司文件的文件路径

请确保在完成查询后进行清理:

if (requestMsgSet != null)
{
    Marshal.FinalReleaseComObject(requestMsgSet);
}
if (invoiceQueryRq != null)
{
    Marshal.FinalReleaseComObject(invoiceQueryRq);
}
sessionMgr.EndSession();
sessionMgr.CloseConnection();
在任何情况下,我建议您阅读SDK开发人员指南,以了解您的代码实际上在做什么

更新:


回答问题的第二部分。

分享代码和您目前面临的问题。我们将帮助您解决特定问题,而不是一般概念。抱歉,“发票不是类型”是一个编译错误。您看到此错误是因为尚未定义类“Invoice”。如果您是软件开发新手,这将解释如何在C#中定义类。@Naveen我对软件开发并不陌生,但我认为这种类型在QBFC13Lib中。这对您非常有帮助。您知道如何将发票保存为PDF吗?SDK只允许您从公司文件中提取数据。另存为PDF必须在您正在开发的应用程序中实现。您想将单个发票保存为PDF还是将发票列表保存为单个PDF?如果必须将每张发票保存为PDF格式,您是否有可用的模板?我想将单个发票保存为PDF格式,但我没有可用的模板。但是,QuickBooks已经具有将发票保存为PDF格式的功能,我希望PDF格式相同。您在回答中链接的问题已存在4年,由于这些问题,我不确定信息是否准确:在任何情况下,我都可以使用QuickBooks制作的PDF作为模板。@JakeFarley您所指的链接是针对QuickBooks Online的-QuickBooks的在线版本。我假设您正在使用QuickBooks Desktop,因为QBFC13是QuickBooks Desktop的SDK。@JakeFarley QuickBooks Desktop允许您保存PDF,但QuickBooks Desktop的SDK仅允许您从公司文件中提取数据。您正在开发的应用程序可以根据SDK提供的数据生成PDF。