2016-05-25 11 views
0

私の目標は非常に基本的です。営業担当者と価格レベルを含むすべての顧客の詳細を取得しようとします。クイックブックSDKの営業担当者と価格レベルで詳細な顧客リストを照会する方法

私はこのような新しい顧客クラスを作成します。

public class Customer 
{ 
    public string Name { get; set; } 
    public string FullName { get; set; } 
    public bool IsActive { get; set; } 
    public string SalesRep { get; set; } 
    public string PriceLevel { get; set; } 
} 

そして、私はプログラムを実行すると、これはメインのコード

https://gist.github.com/anonymous/3968904d2d0fc492ed176c40465313b6#file-gistfile1-txt

private void button1_Click(object sender, EventArgs e) 
    { 

     QBSessionManager sessionManager = null; 
     try 
     { 
      sessionManager = new QBSessionManager(); 
      IMsgSetRequest requestMsgSet = sessionManager.CreateMsgSetRequest("US", 13, 0); 
      requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue; 

      sessionManager.OpenConnection("", "Quickbooks SDK Demo Test"); 
      sessionManager.BeginSession("", ENOpenMode.omDontCare); 

      ICustomerQuery customerQueryRq = requestMsgSet.AppendCustomerQueryRq(); 

      customerQueryRq.ORCustomerListQuery.CustomerListFilter.ActiveStatus.SetValue(ENActiveStatus.asAll); 

      IMsgSetResponse responseMsgSet = sessionManager.DoRequests(requestMsgSet); 

      sessionManager.EndSession(); 
      sessionManager.CloseConnection(); 

      IResponse response = responseMsgSet.ResponseList.GetAt(0); 
      ICustomerRetList customerRetList = (ICustomerRetList)response.Detail; 


      List<Customer> customers = new List<Customer>(); 


      if (customerRetList != null) 
      { 
       for (int i = 0; i < customerRetList.Count; i++) 
       { 
        ICustomerRet customerRet = customerRetList.GetAt(i); 

        Customer customer = new Customer(); 
        { 
         customer.Name = customerRet.Name.GetValue(); 
         customer.FullName = customerRet.FullName.GetValue(); 
         customer.IsActive = customerRet.IsActive.GetValue(); 
         customer.PriceLevel = customerRet.PriceLevelRef.FullName.GetValue(); 
         customer.SalesRep = customerRet.SalesRepRef.FullName.GetValue(); 
        } 
        customers.Add(customer); 
       } 
      } 

      dataGridView1.DataSource = customers; 

     } 
     catch (Exception ex) 
     { 
      MessageBox.Show(ex.Message); 
     } 

     finally 
     { 
      sessionManager.EndSession(); 
      sessionManager.CloseConnection(); 
     } 
    } 

ですが、私はエラーだ: 「オブジェクトのインスタンスに設定されていないオブジェクト参照」を 私はSalesRepとPriceLevelに何か問題があることを知っています。これらはオブジェクト参照ですが、修正方法はわかりません。

助けてください。

おかげ

答えて

0

これらのフィールドは:

customer.PriceLevel = customerRet.PriceLevelRef.FullName.GetValue(); 
customer.SalesRep = customerRet.SalesRepRef.FullName.GetValue(); 

常に存在しません。すべてのお客様にSalesRepRefまたはPriceLevelRefが存在すると見なすことはできません。一部の顧客には営業担当者がいないか、カスタム価格レベルはありません。

したがって、これらの値がNULLではないことを確認するか、値を取得する前に何らかの方法で設定を解除してください。

+0

ありがとうございました。私はいくつかのIF文をSalesRepとSalesRepFullNameに追加することで修正しました – uniz

関連する問題