Come ottenere un elenco di clienti, lavori e dipendenti utilizzando Quickbooks QBFC (SDK 8.0)

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

  •  19-09-2019
  •  | 
  •  

Domanda

Mi è stato affidato il doloroso compito di scrivere un'applicazione C# per sincronizzare le registrazioni degli orari dei dipendenti in un database separato con Quickbooks.Dato che sono nuovo nella programmazione QB, sto cercando di eseguire attività di base, come ottenere un elenco di clienti, quindi lavori per ciascun cliente, quindi dipendenti.Ho letto la documentazione dell'SDK, ma sono ancora un po' confuso sui dettagli perché gli esempi che sto trovando sono un po' troppo avanzati per me al momento :-P

Per semplificare le cose, vorrei chiedere uno snippet di codice che mi fornisca l'elenco dei clienti per cominciare.Ecco il codice che ho:

        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();

Qualcuno può inserire il "codice per ottenere l'elenco dei clienti qui" per me?Grazie mille in anticipo!

Vincitore

È stato utile?

Soluzione 2

Ok, sembra che io abbia trovato il pezzo mancante:

ICustomerQuery customers = customerSet.AppendCustomerQueryRq();

Ciò produce tutti i dati relativi a ciascun cliente, che è un passo avanti. L'analisi dell'XML per i clienti dovrebbe essere piuttosto semplice, ma l'analisi delle singole attività/posti di lavoro per ogni cliente sarà laborioso, perché non ci sono subnodi per ogni attività - in pratica ricevi ripetute blocchi di XML con tutte le informazioni di base del cliente (indirizzo di base, fatturazione Indirizzo, indirizzo di spedizione, ecc.), Quindi questa proprietà chiamata "fullname" che aggiunge un colon al nome del cliente, seguito dal titolo dell'attività (che a sua volta può essere seguito da un altro colon con un titolo di sottotitoli, ecc.). Mi chiedo se c'è qualcosa di intelligente che posso fare con la query di richiesta per ottenere una migliore risposta XML (ad esempio, specificare quali proprietà voglio restituire e forse imporre la creazione di subnodi per ogni attività per un determinato cliente) ... I commenti sono apprezzati.

Altri suggerimenti

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

Solo i campi specificati nell'elenco precedente verranno restituiti da QuickBooks - è molto importante utilizzare le stringhe corrette nel caso corretto - non verrà visualizzato alcun messaggio di errore se qualcosa non va.Non è possibile specificare sottocampi (ad esempio, Città all'interno di un blocco Indirizzo;è necessario ottenere l'intero blocco di indirizzi).Per i campi personalizzati, è inoltre necessario specificare l'ID Proprietario (utilizzare 0 per i campi personalizzati che non sono privati ​​per un'applicazione)

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

Aggiungendo ai vincitori, alla risposta di Chili e Hassan. Sono contento di essersi imbattuto in questa domanda mentre io stesso stavamo lottando con gli esempi di QBFC. Ecco un set completo di codice che potrebbe solo aiutare qualcuno lungo la strada. Se nel frattempo qualcuno potesse semplicemente indicarmi nella direzione di una documentazione utile ... sarebbe fantastico.

Ottenere i dati dei dipendenti su una stringa 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();
    }

Mettere la stringa XML in un elenco di oggetti 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;
    }

Funzione che restituisce un oggetto dipendente usando 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;
    }

Esempio di codice

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

Classe dei dipendenti

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

}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top