如何使用Quickbooks QBFC(8.0 SDK)获取客户,工作和雇主的列表

时间:2009-07-23 19:08:43

标签: quickbooks qbfc

我被编写了一个痛苦的任务,即编写一个C#应用程序,将员工时间条目与Quickbooks同步到一个单独的数据库中。由于我是QB编程的新手,我正在尝试执行基本任务,例如获取客户列表,然后是每个客户的工作,然后是员工。我一直在阅读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();

任何人都可以填写“代码来获取客户名单”吗?非常感谢你提前!

维克多

3 个答案:

答案 0 :(得分:8)

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

答案 1 :(得分:7)

好吧,好像我找到了丢失的部分:

ICustomerQuery customers = customerSet.AppendCustomerQueryRq();

这会产生与每个客户相关的所有数据,这是向前迈出的一步。为客户解析XML应该非常简单,但解析每个客户的单个任务/作业将是费力的,因为每个任务都没有子节点 - 基本上你会得到重复的XML块和所有基本的客户信息(地址,计费)地址,送货地址等),然后这个名为“FullName”的属性将冒号附加到客户名称,然后是任务标题(其本身可以跟随另一个带有子任务标题的冒号等)。我想知道我是否可以使用请求查询来获得更好的xml响应(例如,指定我想要返回的属性,并且可能强制为给定客户的每个任务创建子节点)......评论表示赞赏。

答案 2 :(得分:0)

在Victors,Chili和Hassan的回答之外。我本人在努力解决QBFC的示例时很高兴在这个问题上迷迷糊糊。 这是一整套代码,可能会帮助别人。如果在此期间有人可以指出一些有用文档的方向……那太好了。

  

将Employee数据获取为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返回Employee对象的函数

    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; }
    }

}