无法使用QBFC向Quickbooks添加重复的客户

时间:2014-06-20 17:57:59

标签: c# quickbooks qbfc

我有以下代码:

public void addCustomer()
        {
            bool sessionBegun = false;
            bool connectionOpen = false;
            QBSessionManager sessionManager = null;

            try
            {
                //Create sessions manager object
                sessionManager = new QBSessionManager();

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

                //Connect to quickbooks and begin a session
                sessionManager.OpenConnection("", "CSW QB Interface");
                connectionOpen = true;
                sessionManager.BeginSession(@"C:\Users\Public\Documents\Intuit\QuickBooks\Company Files\Super Legit Industries.qbw", ENOpenMode.omDontCare);
                sessionBegun = true;

                ICustomerAdd customerAddRq = requestMsgSet.AppendCustomerAddRq();
                customerAddRq.Name.SetValue("Test Customer 1");

                //Send the request and get the response from quickbooks
                IMsgSetResponse responseMsgSet = sessionManager.DoRequests(requestMsgSet);
                IResponse response = responseMsgSet.ResponseList.GetAt(0);
                ICustomerRet customerRet = (ICustomerRet)response.Detail;

                //Console.WriteLine(response.Detail.ToString());
                custID = customerRet.ListID.GetValue();

            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                //End the session and close the connection to quickbooks
                if(sessionBegun)
                {
                    sessionManager.EndSession();
                }
                if(connectionOpen)
                {
                    sessionManager.CloseConnection();
                }
            }
        }

我的问题是,可能存在这样的情况,即两个人具有相同的名称并需要输入快速书,但如果我不止一次运行此代码(尝试添加"测试客户1"不止一次),第二次我在线上抛出错误:

custID = customerRet.ListID.GetValue();

话说:

Object reference not set to an instance of an object

有没有办法在没有抛出异常的情况下使用QBFC将重复的客户添加到QB中?

1 个答案:

答案 0 :(得分:1)

  

我的问题是,可能存在两个人姓名相同且需要输入快速书的情况,

QuickBooks本身不支持拥有两个同名客户。

您遇到的不是QBFC,SDK或其他任何限制 - 这就是QuickBooks的工作原理。你不能有重复。