может ли кто-нибудь показать мне простой пример добавления клиента в quickbooks на vb.net

Я пытаюсь написать программу VB.net WPF, которая добавит клиенту пользовательские заметки. Intuit заставляет меня ходить по кругу своими примерами кода, которые не конвертируются из C# в VB.net.

Может ли кто-нибудь показать мне очень простой пример, который показывает добавление только имени клиента? Оставьте любую проверку ошибок и т. д., я могу понять это. Я просто не знаю, как написать подключение к quickbooks и отправить запрос. Может быть, простая форма с текстовым полем и кнопкой, позволяющая поместить имя в текстовое поле и нажать кнопку, чтобы добавить имя клиента.


person user2574474    schedule 11.07.2013    source источник


Ответы (2)


Меня уже давно раздражают плохие примеры кода из Intuit для SDK Quickbooks. Сказав это, я все еще использую их; после исправления кода они весьма полезны.

Вам также необходимо добавить ссылку на Intuit Quickbooks SDK QBFC7Lib; В зависимости от версии он может немного отличаться.

Вот что вам нужно сделать, чтобы сделать код полезным (используйте «Правка» > «Быстрая замена»):

  1. Замените // на ' (комментарии)
  2. Удалить все ; (точки с запятой)
  3. Замените == на =
  4. Замените For j = 0 на For j as Integer = 0
  5. Замените responseList.GetAt(i) на responseList.GetAt(j)
  6. Удалить завершающий . (точка)
  7. Замените Integerfor на Integer (следующая строка) for
  8. Замените DataExtRet на DataExtRet. (только когда выдает ошибку)
  9. Проверьте наличие других ошибок
  10. Удаляйте то, что вам не нужно

Когда вы запускаете его в первый раз, вам нужно открыть Quickbooks и быть готовым предоставить разрешения от Quickbooks. Вот пример с исправленными ошибками.

Imports QBFC7Lib

Module QBSample

Public Class Customer

    Public Sub DoCustomerAdd()
        Dim sessionBegun As Boolean
        sessionBegun = False
        Dim connectionOpen As Boolean
        connectionOpen = False
        Dim sessionManager As QBSessionManager
        sessionManager = Nothing

        Try

            'Create the session Manager object
            sessionManager = New QBSessionManager

            'Create the message set request object to hold our request
            Dim requestMsgSet As IMsgSetRequest
            requestMsgSet = sessionManager.CreateMsgSetRequest("US", 7, 0)
            requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue

            BuildCustomerAddRq(requestMsgSet)

            'Connect to QuickBooks and begin a session
            sessionManager.OpenConnection("", "Your application")
            connectionOpen = True
            sessionManager.BeginSession("", ENOpenMode.omDontCare)
            sessionBegun = True

            'Send the request and get the response from QuickBooks
            Dim responseMsgSet As IMsgSetResponse
            responseMsgSet = sessionManager.DoRequests(requestMsgSet)

            'End the session and close the connection to QuickBooks
            sessionManager.EndSession()
            sessionBegun = False
            sessionManager.CloseConnection()
            connectionOpen = False

            WalkCustomerAddRs(responseMsgSet)
        Catch e As Exception
            MessageBox.Show(e.Message, "Error")
            If (sessionBegun) Then
                sessionManager.EndSession()
            End If
            If (connectionOpen) Then
                sessionManager.CloseConnection()
            End If
        End Try
    End Sub
    Private Sub BuildCustomerAddRq(ByVal requestMsgSet As IMsgSetRequest)
        Dim CustomerAddRq As ICustomerAdd
        CustomerAddRq = requestMsgSet.AppendCustomerAddRq()
        'Set field value for Name
        CustomerAddRq.Name.SetValue("Test Customer 2")
        'Set field value for IsActive
        CustomerAddRq.IsActive.SetValue(True)
        'Set field value for CompanyName
        CustomerAddRq.CompanyName.SetValue("ab")
        'Set field value for Salutation
        CustomerAddRq.Salutation.SetValue("ab")
        'Set field value for FirstName
        CustomerAddRq.FirstName.SetValue("ab")
        'Set field value for MiddleName
        CustomerAddRq.MiddleName.SetValue("ab")
        'Set field value for LastName
        CustomerAddRq.LastName.SetValue("ab")
        'Set field value for Addr1
        CustomerAddRq.BillAddress.Addr1.SetValue("ab")
        'Set field value for Addr2
        CustomerAddRq.BillAddress.Addr2.SetValue("ab")
        'Set field value for Addr3
        CustomerAddRq.BillAddress.Addr3.SetValue("ab")
        'Set field value for Addr4
        CustomerAddRq.BillAddress.Addr4.SetValue("ab")
        'Set field value for Phone
        CustomerAddRq.Phone.SetValue("ab")
        'Set field value for AltPhone
        CustomerAddRq.AltPhone.SetValue("ab")
        'Set field value for Fax
        CustomerAddRq.Fax.SetValue("ab")
        'Set field value for Email
        CustomerAddRq.Email.SetValue("ab")
        'Set field value for Contact
        CustomerAddRq.Contact.SetValue("ab")
        'Set field value for AltContact
        CustomerAddRq.AltContact.SetValue("ab")

        'May create more than one of these if needed
        CustomerAddRq.IncludeRetElementList.Add("Name")
        CustomerAddRq.IncludeRetElementList.Add("ListID")

    End Sub

    Private Sub WalkCustomerAddRs(ByVal responseMsgSet As IMsgSetResponse)
        If (responseMsgSet Is Nothing) Then
            Exit Sub
        End If

        Dim responseList As IResponseList
        responseList = responseMsgSet.ResponseList
        If (responseList Is Nothing) Then
            Exit Sub
        End If

        'if we sent only one request, there is only one response, we'll walk the list for this sample
        For j As Integer = 0 To responseList.Count - 1
            Dim response As IResponse
            response = responseList.GetAt(j)
            'check the status code of the response, 0=ok, >0 is warning
            If (response.StatusCode >= 0) Then
                'the request-specific response is in the details, make sure we have some
                If (Not response.Detail Is Nothing) Then
                    'make sure the response is the type we're expecting
                    Dim responseType As ENResponseType
                    responseType = CType(response.Type.GetValue(), ENResponseType)
                    If (responseType = ENResponseType.rtCustomerAddRs) Then
                        ''upcast to more specific type here, this is safe because we checked with response.Type check above
                        Dim CustomerRet As ICustomerRet
                        CustomerRet = CType(response.Detail, ICustomerRet)
                        WalkCustomerRet(CustomerRet)
                    End If
                End If
            End If
        Next j
    End Sub

    Private Sub WalkCustomerRet(ByVal CustomerRet As ICustomerRet)
        If (CustomerRet Is Nothing) Then
            Exit Sub
        End If

        'Go through all the elements of ICustomerRet
        'Get value of ListID
        Dim ListID1 As String
        ListID1 = CustomerRet.ListID.GetValue()
        'Get value of Name
        Dim Name5 As String
        Name5 = CustomerRet.Name.GetValue()

    End Sub

End Class

End Module

Еще одна проблема, с которой я часто сталкиваюсь, — это переход кода из «ретлиста» в «ретист». Обычно это происходит с запросами, например. ПолучитьПлатежныйЗапрос. Это не проблема с DoCustomerAdd. Я упоминаю его здесь только для справки, когда вы конвертируете другие методы.

Код от OSR:

Public Sub WalkReceivePaymentRet(ByVal ReceivePaymentRet As IReceivePaymentRetList)
    If (ReceivePaymentRet Is Nothing) Then
        Exit Sub
    End If

Исправьте это так:

Public Sub WalkReceivePaymentRet(ByVal ReceivePaymentRetList As IReceivePaymentRetList)

    For a As Integer = 0 To ReceivePaymentRetList.Count - 1
        Dim ReceivePaymentRet As IReceivePaymentRet

        ReceivePaymentRet = ReceivePaymentRetList.GetAt(a)

        If (ReceivePaymentRet Is Nothing) Then
            Exit Sub
        End If
person D_Bester    schedule 12.07.2013
comment
Вот если бы Intuit могла просто добавить исправленный код к своим образцам, это было бы здорово. - person D_Bester; 12.07.2013
comment
Вот ссылка на онлайн-справочник Intuit SDK для Quickbooks: developer- static.intuit.com/qbSDK-current/Common/newOSR/ - person D_Bester; 26.08.2013

Обязательно добавьте «AddCu» в Quickbooks, выполнив следующие действия:

QB-> Edit -> Preferences-> Integrated Applications-> Company Preferences

Разрешить доступ: ✓ | Имя приложения: AddCu

Импорт Interop.QBFC13

Public Sub AddCu()
    ' Create a QBSessionManager object:
    Dim SessionManager As QBSessionManager
    SessionManager = New QBSessionManager

    ' Create an IMsgSetRequest object (the parameters specify US QuickBooks and the 6.0 spec):
    Dim CustomerSet As IMsgSetRequest
    CustomerSet = SessionManager.CreateMsgSetRequest("US", 6, 0)

    ' Create an ICustomerAdd object:
    Dim customer As ICustomerAdd

    customer = CustomerSet.AppendCustomerAddRq

    ' Set the ICustomerAdd object's field values:
    customer.Name.SetValue("Joey Hamham")

    customer.Phone.SetValue("315-253-2642")

    customer.Email.SetValue("bla@gmail")

    ' The request message set for this example is complete
    ' Open a connection:
    SessionManager.OpenConnection("App", "AddCu")
    ' Begin a session:
    SessionManager.BeginSession("", ENOpenMode.omDontCare)

    ' Create a IMsgSetResponse object:
    Dim Resp As IMsgSetResponse

    ' Call DoRequests, passing the IMsgSetRequest object that was populated with a 
    Resp = SessionManager.DoRequests(CustomerSet)

    ' Display the unprocessed QBXML in the response in a message box:
    MsgBox(Resp.ToXMLString)

    ' End the session:
    SessionManager.EndSession()
    ' Close the connection:
    SessionManager.CloseConnection()
    ' Clear the QBSessionManager
    SessionManager = Nothing
End Sub
person Chance Gristy    schedule 09.08.2018