【问题标题】:How to get list of customers, jobs, and employeers using Quickbooks QBFC (8.0 SDK)如何使用 Quickbooks QBFC (8.0 SDK) 获取客户、工作和员工列表
【发布时间】:2009-07-23 19:08:43
【问题描述】:

我被赋予了编写 C# 应用程序以将单独数据库中的员工时间条目与 Quickbooks 同步的艰巨任务。由于我是 QB 编程的新手,我正在尝试执行基本任务,例如获取客户列表,然后为每个客户提供工作,然后是员工。我一直在阅读 SDK 文档,但我对细节仍然有些模糊,因为目前我找到的示例对我来说有点太高级了:-P

为了简单起见,我想请求一个代码 sn-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();

谁能帮我填写“此处获取客户列表的代码”?非常感谢您!

维克多

【问题讨论】:

    标签: quickbooks qbfc


    【解决方案1】:
    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 用于指定 IncludeRetElementList 时顽固的 DataExtRet 的提示。
    • 我很想看到一个完整的 QBFC 示例,该示例是基于 SSN 查找员工的查询
    【解决方案2】:

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

    ICustomerQuery customers = customerSet.AppendCustomerQueryRq();
    

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

    【讨论】:

    • 是的,您可以指定要从查询中返回的元素以限制通信量。您可以使用查询创建,但是,您必须在单独的步骤中执行此操作(如果我理解正确的话)。我熟悉 XML,而不是 SDK 方法,所以我不能给你确切的细节。
    • 我需要所有客户详细信息,例如全名、地址、城市、州、邮政编码等,以便使用哪种类型的请求。我使用了“CustomerQueryRq”这种类型的请求。我无法获取所有客户详细信息。
    【解决方案3】:

    添加到 Victors、Chili 和 Hassan 的答案。很高兴偶然发现这个问题,因为我自己正在努力解决 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 字符串放入员工对象列表中

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-11
      • 1970-01-01
      相关资源
      最近更新 更多