QuickBooks QBFC(8.0 SDK)を使用して顧客、ジョブ、および雇用者のリストを取得する方法

StackOverflow https://stackoverflow.com/questions/1173859

  •  19-09-2019
  •  | 
  •  

質問

QuickBooksを使用して別のデータベースで従業員の時間エントリを同期するために、C#アプリケーションを作成するという苦痛なタスクが与えられました。私はQBプログラミングの真新しいので、顧客のリストを取得したり、各顧客のジョブ、従業員の仕事を取得するなど、基本的なタスクをPeFormしようとしています。私はSDKのドキュメントを読んでいますが、私が見つけている例は現時点では少し前進しすぎているので、まだ詳細については少しあいまいです:P

物事をシンプルに保つために、スターターの顧客のリストを提供するコードスニペットをお願いしたいと思います。これが私が持っているコードです:

        QBSessionManager SessionManager = new QBSessionManager();
        IMsgSetRequest customerSet = SessionManager.CreateMsgSetRequest("US", 8, 0);

        //          
        // Code to get list of customers here.
        //

        SessionManager.OpenConnection2("", "New App", ENConnectionType.ctLocalQBD);
        SessionManager.BeginSession(string.Empty, ENOpenMode.omDontCare);
        IMsgSetResponse Resp = SessionManager.DoRequests(customerSet);
        MessageBox.Show(Resp.ToXMLString());
        SessionManager.EndSession();
        SessionManager.CloseConnection();

誰かが私のために「顧客のリストをここに取得するためのコード」に記入できますか?事前にどうもありがとうございました!

ビクター

役に立ちましたか?

解決 2

わかりました、私は欠けている作品を見つけたようです:

ICustomerQuery customers = customerSet.AppendCustomerQueryRq();

これにより、各顧客に関連するすべてのデータが生成されます。これは一歩前進します。顧客のXMLを解析することは非常に簡単ですが、各タスクにサブノードがないため、各顧客の個々のタスク/ジョブを解析することは面倒です - 基本的に、すべての基本的な顧客情報でXMLのチャンクを繰り返します(アドレス、請求書、請求住所、配送先住所など)、次に、「FullName」と呼ばれるこの1つのプロパティは、顧客名にコロンを追加し、その後にタスクタイトルが続きます(それ自体がサブタスクタイトルなどの別のコロンが続くことができます)。より良いXML応答を取得するためにリクエストクエリでできることがあるのではないかと思っています(たとえば、返されるプロパティを指定し、特定の顧客の各タスクのサブノードの作成を実施するかもしれません)...コメントを感謝します。

他のヒント

customers.IncludeRetElementList.Add("IsActive");
customers.IncludeRetElementList.Add("ListID");
customers.IncludeRetElementList.Add("EditSequence");
customers.IncludeRetElementList.Add("Name");
customers.IncludeRetElementList.Add("ParentRef");

上記のリストで指定されたフィールドのみがQuickBooksから返されます - 正しいケースで正しい文字列を使用することが非常に重要です - 何かが間違っている場合、エラーメッセージは生じません。サブフィールドを指定することはできません(たとえば、アドレスブロック内の都市。アドレスブロック全体を取得する必要があります)。カスタムフィールドの場合、OwnerIDを指定する必要があります(アプリケーションのプライベートではないカスタムフィールドに0を使用)

customers.IncludeRetElementList.Add("DataExtRet"); //will return non-private and/or private data extension fields depending on the OwnerIDList, below
customers.OwnerIDList.Add("0"); // required for non-private data extn fields
customers.OwnerIDList.Add("Your Appln GUID"); // Use this to get private data extns for the Appln identified by the GUID

勝利者、チリ、ハッサンの答えに加えます。私自身がQBFCの例に苦労していたので、この質問につまずいてくれてうれしいです。これは、将来の誰かを助けるかもしれない完全なコードのセットです。その間に誰かが私を有用な文書の方向に向けて指し示すことができれば...それは素晴らしいことです。

従業員のデータをXML文字列に取得します

    public static string EmployeeListXML()
    {
        QBSessionManager SessionManager = new QBSessionManager();
        IMsgSetRequest msgSetReq = SessionManager.CreateMsgSetRequest("US", 8, 0);
        IEmployeeQuery employee = msgSetReq.AppendEmployeeQueryRq();
        employee.IncludeRetElementList.Add("IsActive");
        employee.IncludeRetElementList.Add("ListID");
        employee.IncludeRetElementList.Add("EditSequence");
        employee.IncludeRetElementList.Add("FirstName");
        employee.IncludeRetElementList.Add("LastName");
        employee.IncludeRetElementList.Add("SSN");
        //employee.IncludeRetElementList.Add("ParentRef");
        //employee.IncludeRetElementList.Add("DataExtRet"); //will return non-private and/or private data extension fields depending on the OwnerIDList, below
        employee.OwnerIDList.Add("0"); // required for non-private data extn fields
        //customers.OwnerIDList.Add("Your Appln GUID"); // Use this to get private data extns for the Appln identified by the GUID
        SessionManager.OpenConnection2("", Application.ProductName, ENConnectionType.ctLocalQBD);
        //SessionManager.BeginSession(string.Empty, ENOpenMode.omDontCare);
        SessionManager.BeginSession(frmMain.QBFileName, ENOpenMode.omDontCare); // I have the filename on frmMain
        IMsgSetResponse Resp = SessionManager.DoRequests(msgSetReq);
        SessionManager.EndSession();
        SessionManager.CloseConnection();
        //MessageBox.Show(Resp.ToXMLString());
        return Resp.ToXMLString();
    }

XML文字列をEmplpoyeeオブジェクトのリストに入れます

    public static List<Employee> EmployeeXMLtoList()
    {
        string sXML = EmployeeListXML();

        List<Employee> lstEmp = new List<Employee>();
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.LoadXml(sXML);
        XmlNodeList parentNode = xmlDoc.GetElementsByTagName("EmployeeRet");
        foreach (XmlNode childNode in parentNode)
        {
            Employee oEmp = new Employee();
            oEmp.ListID = childNode.SelectSingleNode("ListID").InnerText;
            oEmp.EditSequence = childNode.SelectSingleNode("EditSequence").InnerText;
            oEmp.Active = childNode.SelectSingleNode("IsActive").InnerText;
            oEmp.FirstName = childNode.SelectSingleNode("FirstName").InnerText;
            oEmp.LastName = childNode.SelectSingleNode("LastName").InnerText;
            oEmp.SSN = childNode.SelectSingleNode("SSN").InnerText;
            lstEmp.Add(oEmp);
        }
        return lstEmp;
    }

LINQを使用して従業員オブジェクトを返す機能

    public static Employee GetEmployeeObject(string sSSN)
    {
        Employee oReturn = null;
        List<Employee> lstEmployee = EmployeeXMLtoList();

        IEnumerable<Employee> lstEmps = from oEmp in lstEmployee
                                        where oEmp.SSN == sSSN
                                        select oEmp;

        foreach (var oEmp in lstEmps)
        {
            oReturn = oEmp;
        }
        return oReturn;
    }

コードの例

 Employee oEmployee = QB.GetEmployeeObject("112-35-8560");

従業員クラス

public class Employee
{
    private string sEmployeeID;
    private string sSSN;
    private string sLastName;
    private string sFirstName;
    private string sAddress1;
    private string sAddress2;
    private string sCity;
    private string sState;
    private string sZipCode;
    private string sGender;
    private string sEthnicity;
    private DateTime dDOB;
    private string sMaritalStatus;
    private int iDependants;
    private string sUScitizen;
    private decimal iPayRate;
    private string sPhone;
    private DateTime dHireDate;
    private string sEmail;

    public Employee() { }

    public string EmployeeID
    {
        get { return sEmployeeID; }
        set { sEmployeeID = value; }
    }

    public string ListID
    {
        get; set;
    }

    public string EditSequence
    {
        get;  set;
    }

    public string Active
    {
        get; set;
    }


    public string SSN
    {
        get { return sSSN; }
        set { sSSN = value; }
    }

    public string LastName
    {
        get { return sLastName; }
        set { sLastName = value; }
    }

    public string FirstName
    {
        get { return sFirstName; }
        set { sFirstName = value; }
    }

    public string FullName
    {
        get { return FirstName + " " + LastName; }
        set { }
    }

    public string Address1
    {
        get { return sAddress1; }
        set { sAddress1 = value; }
    }

    public string Address2
    {
        get { return sAddress2; }
        set { sAddress2 = value; }
    }

    public string State
    {
        get { return sState; }
        set { sState = value; }
    }
    public string City
    {
        get { return sCity; }
        set { sCity = value; }
    }
    public string ZipCode
    {
        get { return sZipCode; }
        set { sZipCode = value; }
    }
    public string Gender
    {
        get { return sGender; }
        set { sGender = value; }
    }

    public string Ethnicity
    {
        get { return sEthnicity; }
        set { sEthnicity = value; }
    }

    public DateTime DOB
    {
        get { return dDOB; }
        set { dDOB = value; }
    }
    public string MaritalStatus
    {
        get { return sMaritalStatus; }
        set { sMaritalStatus = value; }
    }
    public int Dependants
    {
        get { return iDependants; }
        set { iDependants = value; }
    }
    public string UScitizen
    {
        get { return sUScitizen; }
        set { sUScitizen = value; }
    }

    public decimal PayRate
    {
        get { return iPayRate; }
        set { iPayRate = value; }
    }
    public DateTime HireDate
    {
        get { return dHireDate; }
        set { dHireDate = value; }
    }
    public string Phone
    {
        get { return sPhone; }
        set { sPhone = value; }
    }
    public string Email
    {
        get { return sEmail; }
        set { sEmail = value; }
    }

}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top