示例#1
0
        public IResponse DbGetResponseSet(ref QBSessionManager sessionManager, IMsgSetRequest requestMsgSet)
        {
            //Send the request and get the response from QuickBooks
            IMsgSetResponse responseMsgSet = sessionManager.DoRequests(requestMsgSet);

            return(responseMsgSet.ResponseList.GetAt(0));
        }
        private T ProcessQueryAsXML <T>(IMsgSetResponse queryResponse, string root)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(T));
            var           result     = default(T);

            try
            {
                if (_debug)
                {
                    using (FileStream fs = new FileStream(@"C:\Users\Computron\Documents\xml_response.xml", FileMode.OpenOrCreate))
                    {
                        byte[] info = new UTF8Encoding(true).GetBytes(queryResponse.ToXMLString());
                        fs.Write(info, 0, info.Length);
                    }
                }

                using (XmlReader reader = XmlReader.Create(new StringReader(queryResponse.ToXMLString())))
                {
                    reader.MoveToContent();
                    reader.ReadToDescendant(root);
                    result = (T)serializer.Deserialize(reader);
                }
            }
            catch (Exception ex)
            {
                throw new QuickBooksClientException(ex.ToString());
            }

            return(result);
        }
示例#3
0
        /// <summary>
        /// Method for handling different versions of QuickBooks.
        /// </summary>
        private double QBFCLatestVersion()
        {
            // Use oldest version to ensure that this application work with any QuickBooks (US)
            IMsgSetRequest msgset = SessionManager.CreateMsgSetRequest("US", 1, 0);

            msgset.AppendHostQueryRq();
            IMsgSetResponse QueryResponse = SessionManager.DoRequests(msgset);
            //Console.WriteLine("Host query = " + msgset.ToXMLString());

            // The response list contains only one response,
            // which corresponds to our single HostQuery request.
            IResponse response = QueryResponse.ResponseList.GetAt(0);

            // Please refer to QBFC Developers Guide for details on why
            // "as" clause was used to link this derived class to its base class.
            IHostRet  HostResponse      = response.Detail as IHostRet;
            IBSTRList supportedVersions = HostResponse.SupportedQBXMLVersionList as IBSTRList;

            double LastVers = 0;

            for (var i = 0; i <= supportedVersions.Count - 1; i++)
            {
                string svers = null;
                svers = supportedVersions.GetAt(i);
                var vers = Convert.ToDouble(svers);
                if (vers > LastVers)
                {
                    LastVers = vers;
                }
            }
            return(LastVers);
        }
        private void modifyCustomer(ICustomerRet QBCustomer)
        {
            Console.WriteLine(QBCustomer.Name.GetValue() + ": " + QBCustomer.Email.GetValue());

            IMsgSetRequest requestMsgSet = _MySessionManager.CreateMsgSetRequest("US", 13, 0);

            ICustomerMod Query = requestMsgSet.AppendCustomerModRq();

            Query.ListID.SetValue(QBCustomer.ListID.GetValue());
            Query.EditSequence.SetValue(QBCustomer.EditSequence.GetValue());
            Query.Email.SetValue("");

            IMsgSetResponse responseMsgSet = _MySessionManager.DoRequests(requestMsgSet);

            //IResponseList rsList = responseMsgSet.ResponseList;
            //IResponse response = rsList.GetAt(0);

            //ICustomerRet QBCustomer = (ICustomerRet)response.Detail;

            //if (QBCustomer == null)
            //{
            //    throw new Exception("Sorry, sales order not found.");
            //}

            //string CustomerName = QBCustomer.Name.GetValue().ToString();
            ////string email = QBCustomer.Email.GetValue();

            //Console.WriteLine(CustomerName);
        }
示例#5
0
        public IResponse QueryCustomerList()
        {
            // Add the request to the message set request object
            ICustomerQuery CustQ = requestMsgSet.AppendCustomerQueryRq();

            // Optionally, you can put filter on it.
            CustQ.ORCustomerListQuery.CustomerListFilter.MaxReturned.SetValue(5);

            // Do the request and get the response message set object
            IMsgSetResponse responseSet = SessionManager.DoRequests(requestMsgSet);

            // Uncomment the following to view and save the request and response XML
            //string requestXML = requestSet.ToXMLString();
            //Console.WriteLine(requestXML);
            //string responseXML = responseSet.ToXMLString();
            //Console.WriteLine(responseXML);

            IResponse response = responseSet.ResponseList.GetAt(0);

            //int statusCode = response.StatusCode;
            //string statusMessage = response.StatusMessage;
            //string statusSeverity = response.StatusSeverity;
            //Console.WriteLine("Status:\nCode = " + statusCode + "\nMessage = " + statusMessage + "\nSeverity = " + statusSeverity);

            return(response);
        }
/*        private IMsgSetRequest buildItemQueryRq(string[] includeRetElement, string fullName)
 *      {
 *          IMsgSetRequest requestMsgSet = sessionManager.getMsgSetRequest();
 *          requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;
 *          IItemQuery itemQuery = requestMsgSet.AppendItemQueryRq();
 *          if (fullName != null)
 *          {
 *              itemQuery.ORListQuery.FullNameList.Add(fullName);
 *          }
 *          for (int x = 0; x < includeRetElement.Length; x++)
 *          {
 *              itemQuery.IncludeRetElementList.Add(includeRetElement[x]);
 *          }
 *          return requestMsgSet;
 *      }
 *
 *      private IMsgSetRequest buildTermsQueryRq()
 *      {
 *          IMsgSetRequest requestMsgSet = sessionManager.getMsgSetRequest();
 *          requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;
 *          ITermsQuery termsQuery = requestMsgSet.AppendTermsQueryRq();
 *          termsQuery.IncludeRetElementList.Add("Name");
 *          return requestMsgSet;
 *      }
 *
 *      private IMsgSetRequest buildSalesTaxCodeQueryRq()
 *      {
 *          IMsgSetRequest requestMsgSet = sessionManager.getMsgSetRequest();
 *          requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;
 *          ISalesTaxCodeQuery salesTaxCodeQuery = requestMsgSet.AppendSalesTaxCodeQueryRq();
 *          salesTaxCodeQuery.IncludeRetElementList.Add("Name");
 *          return requestMsgSet;
 *      }
 *
 *      private IMsgSetRequest buildCustomerMsgQueryRq(string[] includeRetElement, string fullName)
 *      {
 *          IMsgSetRequest requestMsgSet = sessionManager.getMsgSetRequest();
 *          requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;
 *          ICustomerMsgQuery custMsgQuery = requestMsgSet.AppendCustomerMsgQueryRq();
 *          if (fullName != null)
 *          {
 *              custMsgQuery.ORListQuery.FullNameList.Add(fullName);
 *          }
 *          for (int x = 0; x < includeRetElement.Length; x++)
 *          {
 *              custMsgQuery.IncludeRetElementList.Add(includeRetElement[x]);
 *          }
 *          return requestMsgSet;
 *      }
 *
 *      private IMsgSetRequest buildCurrencyQueryRq(string fullName)
 *      {
 *          IMsgSetRequest requestMsgSet = sessionManager.getMsgSetRequest();
 *          requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;
 *          ICurrencyQuery currQuery = requestMsgSet.AppendCurrencyQueryRq();
 *          if (fullName != null)
 *          {
 *              currQuery.ORListQuery.FullNameList.Add(fullName);
 *          }
 *          return requestMsgSet;
 *      }
 *
 *      private IMsgSetRequest buildInvoiceAddRq()
 *      {
 *          if (!validateInput()) return null;
 *          IMsgSetRequest requestMsgSet = sessionManager.getMsgSetRequest();
 *          requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;
 *          IInvoiceAdd invAdd = requestMsgSet.AppendInvoiceAddRq();
 *
 *          // CustomerRef -> FullName
 *          if (comboBox_Customer.Text != "")
 *          {
 *              invAdd.CustomerRef.FullName.SetValue(comboBox_Customer.Text);
 *          }
 *
 *          // TxnDate
 *          DateTime DT_TxnDate = System.DateTime.Today;
 *          if (dateTimePicker1.Text != "")
 *          {
 *              DT_TxnDate = Convert.ToDateTime(dateTimePicker1.Text);
 *              invAdd.TxnDate.SetValue(DT_TxnDate);
 *          }
 *
 *          // RefNumber
 *          if (textBox_RefNumber.Text != "")
 *          {
 *              invAdd.RefNumber.SetValue(textBox_RefNumber.Text);
 *          }
 *
 *          // BillAddress
 *          if (label_BillTo.Text != "")
 *          {
 *              string[] BillAddress = label_BillTo.Text.Split('\n');
 *              invAdd.BillAddress.Addr1.SetValue(BillAddress[0]);
 *              invAdd.BillAddress.Addr2.SetValue(BillAddress[1]);
 *              invAdd.BillAddress.Addr3.SetValue(BillAddress[2]);
 *              invAdd.BillAddress.City.SetValue(BillAddress[3]);
 *              invAdd.BillAddress.State.SetValue(BillAddress[4]);
 *              invAdd.BillAddress.PostalCode.SetValue(BillAddress[5]);
 *          }
 *
 *          // TermsRef -> FullName
 *          bool termsAvailable = false;
 *          if (comboBox_Terms.Text != "")
 *          {
 *              termsAvailable = true;
 *              invAdd.TermsRef.FullName.SetValue(comboBox_Terms.Text);
 *          }
 *
 *          // DueDate
 *          if (termsAvailable)
 *          {
 *              DateTime DT_DueDate = System.DateTime.Today;
 *              double dueInDays = getDueInDays();
 *              DT_DueDate = DT_TxnDate.AddDays(dueInDays);
 *              invAdd.DueDate.SetValue(DT_DueDate);
 *          }
 *
 *          // CustomerMsgRef -> FullName
 *          if (comboBox_CustomerMessage.Text != "")
 *          {
 *              invAdd.CustomerMsgRef.FullName.SetValue(comboBox_CustomerMessage.Text);
 *          }
 *
 *          // ExchangeRate
 *          if (textBox_ExchangeRate.Text != "")
 *          {
 *              float exRate = (float)System.Convert.ToSingle(textBox_ExchangeRate.Text);
 *              invAdd.ExchangeRate.SetValue(exRate);
 *          }
 *
 *          //Line Items
 *          for (int x = 1; x < 6; x++)
 *          {
 *              string[] lineItem = getLineItem(x);
 *              if (lineItem[0] == "")
 *              {
 *                  break;
 *              }
 *              IORInvoiceLineAdd invLineAdd = invAdd.ORInvoiceLineAddList.Append();
 *              if (lineItem[0] != "")
 *              {
 *                  invLineAdd.InvoiceLineAdd.ItemRef.FullName.SetValue(lineItem[0]);
 *              }
 *              if (lineItem[1] != "")
 *              {
 *                  invLineAdd.InvoiceLineAdd.Desc.SetValue(lineItem[1]);
 *              }
 *              if (lineItem[2] != "")
 *              {
 *                  invLineAdd.InvoiceLineAdd.Quantity.SetValue(Convert.ToDouble(lineItem[2]));
 *              }
 *              if (lineItem[3] != "")
 *              {
 *                  invLineAdd.InvoiceLineAdd.ORRatePriceLevel.Rate.SetValue(Convert.ToDouble(lineItem[3]));
 *              }
 *              if (lineItem[4] != "")
 *              {
 *                  invLineAdd.InvoiceLineAdd.Amount.SetValue(Convert.ToDouble(lineItem[4]));
 *              }
 *          }
 *          return requestMsgSet;
 *      }
 *
 *      // RESPONSE PARSING
 *      private string[] parsePreferencesQueryRs(IMsgSetResponse responseMsgSet, int count)
 *      {
 *          string[] retVal = new string[count];
 *          IResponse response = responseMsgSet.ResponseList.GetAt(0);
 *          int statusCode = response.StatusCode;
 *          string statusMessage = response.StatusMessage;
 *          string statusSeverity = response.StatusSeverity;
 *          //MessageBox.Show("statusCode = " + statusCode + "\nstatusMessage = " + statusMessage + "\nstatusSeverity = " + statusSeverity);
 *          if (statusCode == 0)
 *          {
 *              IPreferencesRet prefRet = response.Detail as IPreferencesRet;
 *              if (prefRet.MultiCurrencyPreferences != null)
 *              {
 *                  retVal[0] = Convert.ToString(prefRet.MultiCurrencyPreferences.IsMultiCurrencyOn.GetValue());
 *                  retVal[1] = prefRet.MultiCurrencyPreferences.HomeCurrencyRef.FullName.GetValue();
 *              }
 *          }
 *          return retVal;
 *      }
 */
        private int getCount(string request)
        {
            IMsgSetResponse responseMsgSet = processRequestFromQB(buildDataCountQuery(request));
            int             count          = parseRsForCount(responseMsgSet);

            return(count);
        }
        private List <Customer> parseCustomerQueryRs2(IMsgSetResponse responseMsgSet, int count)
        {
            List <Customer> customers = new List <Customer>();
            IResponse       response  = responseMsgSet.ResponseList.GetAt(0);

            int statusCode = response.StatusCode;

            if (statusCode == 0)
            {
                ICustomerRetList custRetList = response.Detail as ICustomerRetList;
                for (int i = 0; i < count; i++)
                {
                    if (custRetList.GetAt(i).FullName != null)
                    {
                        customers.Add(new Customer {
                            Name = custRetList.GetAt(i).FullName.GetValue().ToString(),
                            //Address = custRetList.GetAt(i).BillAddress.Addr1.GetValue().ToString(),
                            //City = custRetList.GetAt(i).BillAddress.City.GetValue().ToString(),
                            //State = custRetList.GetAt(i).BillAddress.State.GetValue().ToString(),
                            //Zip = custRetList.GetAt(i).BillAddress.PostalCode.GetValue().ToString()
                        });
                    }
                }
            }
            return(customers);
        }
示例#8
0
        public void OpenQB()
        {
            QBSessionManager sessionManager = null;

            try
            {
                sessionManager = new QBSessionManager();
                IMsgSetRequest requestMsgSet = sessionManager.CreateMsgSetRequest("CA", 13, 0);
                requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;

                sessionManager.OpenConnection("QBAPI", "Quickbooks SDK Demo Test");
                string qbFile = ConfigurationSettings.AppSettings["companyfile"].ToString();
                Console.WriteLine(qbFile);
                sessionManager.BeginSession(
                    qbFile, ENOpenMode.omMultiUser);

                ICustomerQuery customerQueryRq = requestMsgSet.AppendCustomerQueryRq();
                customerQueryRq.ORCustomerListQuery.CustomerListFilter.ActiveStatus.SetValue(ENActiveStatus.asAll);


                IMsgSetResponse responseMsgSet = sessionManager.DoRequests(requestMsgSet);

                sessionManager.EndSession();
                sessionManager.CloseConnection();
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message);
                sessionManager.EndSession();
                sessionManager.CloseConnection();
            }
        }
        private IORItemRet QueryItem(QBSessionManager session, string itemFullName)
        {
            // query for the customer information

            IMsgSetRequest requestMsgSet = getLatestMsgSetRequest(session);

            requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;

            IItemQuery pItemQuery = requestMsgSet.AppendItemQueryRq();

            pItemQuery.ORListQuery.ListFilter.ORNameFilter.NameFilter.Name.SetValue(itemFullName);
            pItemQuery.ORListQuery.ListFilter.ORNameFilter.NameFilter.MatchCriterion.SetValue(ENMatchCriterion.mcContains);

            pItemQuery.OwnerIDList.Add("0");

            IMsgSetResponse responseMsgSet = session.DoRequests(requestMsgSet);

            // Uncomment the following to see the request and response XML for debugging
            //string rq = requestMsgSet.ToXMLString();
            //string rs = responseMsgSet.ToXMLString();

            //m_application.Messenger.AddInfo("Item Resquest: " + rq);
            //m_application.Messenger.AddInfo("Item Response: " + rs);

            // Interpret the response

            IResponseList rsList = responseMsgSet.ResponseList;

            //  Retrieve the one response corresponding to our single request

            IResponse response = rsList.GetAt(0);

            if (response.StatusCode != 0)
            {
                string msg = "";
                if (response.StatusCode == 1)  //No record found
                {
                    msg = "Item not found: " + itemFullName;
                }
                else
                {
                    msg = "Error getting item.  Status: " + response.StatusCode.ToString() + ", Message: " + response.StatusMessage;
                }

                throw new Exception(msg);
            }

            // We have one or more customers (expect one)

            IORItemRetList orItemRetList = response.Detail as IORItemRetList;

            int itemCount = orItemRetList.Count;

            if (itemCount > 1)
            {
                m_application.Messenger.AddWarning("Multiple items found: " + itemFullName);
            }

            return(orItemRetList.GetAt(0));
        }
示例#10
0
        private void UpdateCustomer(Quickbooks qb, ICustomerRet customer, CheckToWrite r)
        {
            List <String>  account    = new List <string>();
            IMsgSetRequest msgRequest = qb.newRequest();

            msgRequest.Attributes.OnError = ENRqOnError.roeStop;
            ICustomerMod customerMod = msgRequest.AppendCustomerModRq();

            customerMod.ListID.SetValue(customer.ListID.GetValue());
            customerMod.AccountNumber.SetValue(r.RecipientId);
            customerMod.Name.SetValue(r.FullName);
            customerMod.BillAddress.Addr1.SetValue(customerMod.Name.GetValue());
            customerMod.BillAddress.Addr2.SetValue(r.Address1);
            customerMod.BillAddress.Addr3.SetValue(r.Address2);

            customerMod.Contact.SetValue(customerMod.Name.GetValue());
            customerMod.BillAddress.City.SetValue(r.City);
            customerMod.BillAddress.State.SetValue(r.State);
            customerMod.BillAddress.PostalCode.SetValue(r.Zip);
            customerMod.EditSequence.SetValue(customer.EditSequence.GetValue());
            IMsgSetResponse response = qb.performRequest(msgRequest);

            if (response.ResponseList.GetAt(0).StatusCode != 0)
            {
                throw new Exception("Unable to update customer " + response.ResponseList.GetAt(0).StatusMessage);
            }
        }
示例#11
0
        private ICustomerRet addCustomer(Quickbooks qb, CheckToWrite r)
        {
            IMsgSetRequest msgRequest = qb.newRequest();

            msgRequest.Attributes.OnError = ENRqOnError.roeStop;

            ICustomerAdd addCustomer = msgRequest.AppendCustomerAddRq();

            addCustomer.AccountNumber.SetValue(r.RecipientId);
            addCustomer.Name.SetValue(r.FullName);
            addCustomer.BillAddress.Addr1.SetValue(addCustomer.Name.GetValue());
            addCustomer.BillAddress.Addr2.SetValue(r.Address1);
            addCustomer.BillAddress.Addr3.SetValue(r.Address2);
            addCustomer.Contact.SetValue(addCustomer.Name.GetValue());
            addCustomer.BillAddress.City.SetValue(r.City);
            addCustomer.BillAddress.State.SetValue(r.State);
            addCustomer.BillAddress.PostalCode.SetValue(r.Zip);

            IMsgSetResponse response = qb.performRequest(msgRequest);

            if (response.ResponseList.GetAt(0).StatusCode == 0)
            {
                ICustomerRet result = (ICustomerRet)response.ResponseList.GetAt(0).Detail;
                return(result);
            }
            else
            {
                throw new Exception("Unable to add customer " + response.ResponseList.GetAt(0).StatusMessage);
            }
        }
示例#12
0
        private void WalkInvoiceAddRs(IMsgSetResponse responseMsgSet)
        {
            if (responseMsgSet == null)
            {
                return;
            }
            IResponseList responseList = responseMsgSet.ResponseList;

            if (responseList == null)
            {
                return;
            }
            for (int i = 0; i < responseList.Count; i++)
            {
                IResponse response = responseList.GetAt(i);
                if (response.StatusCode >= 0)
                {
                    if (response.Detail != null)
                    {
                        ENResponseType responseType = (ENResponseType)response.Type.GetValue();
                        if (responseType == ENResponseType.rtInvoiceAddRs)
                        {
                            IInvoiceRet invoiceRet = (IInvoiceRet)response.Detail;
                            WalkInvoiceRet(invoiceRet);
                        }
                    }
                }
            }
            Console.WriteLine(responseMsgSet.ToXMLString());
        }
示例#13
0
        public void vendorAdd(string name)
        {
            //open session to add vendor
            QBSessionManager sessionManager = new QBSessionManager();

            sessionManager.OpenConnection("appID", "Create Vendor");
            sessionManager.BeginSession("", ENOpenMode.omDontCare);
            IMsgSetRequest messageSet = sessionManager.CreateMsgSetRequest("US", 13, 0);

            IVendorAdd vendorAddRequest = messageSet.AppendVendorAddRq();

            vendorAddRequest.Name.SetValue(name); //add vendor
                                                  // name is the string passed from the list containing the vendors that need to be added to quickbooks

            IMsgSetResponse responseSet = sessionManager.DoRequests(messageSet);

            sessionManager.EndSession();
            sessionManager.CloseConnection();

            for (int i = 0; i < responseSet.ResponseList.Count; i++)
            {
                IResponse response = responseSet.ResponseList.GetAt(i);
                var       code     = response.StatusCode;
                string    code2    = code.ToString();
                string    code3    = response.StatusMessage;
                if (response.StatusCode > 0)
                {
                }
                // MessageBox.Show(code3);
            }
        }
示例#14
0
    public List <string> QueryEmployeeNames()
    {
        try
        {
            IMsgSetRequest requestSet = SessionManager.Instance.CreateMsgSetRequest();
            requestSet.Attributes.OnError = ENRqOnError.roeStop;
            IEmployeeQuery employeeQuery = requestSet.AppendEmployeeQueryRq();

            IMsgSetResponse responeSet   = SessionManager.Instance.DoRequests(requestSet);
            IResponseList   responseList = responeSet.ResponseList;

            List <string> employeeNames = new List <string>();

            for (int i = 0; i < responseList.Count; i++)
            {
                IResponse response = responseList.GetAt(i);
                if (response.StatusCode == 0)
                {
                    IEmployeeRetList employeeList = (IEmployeeRetList)response.Detail;
                    for (int j = 0; j < employeeList.Count; j++)
                    {
                        IEmployeeRet employee = employeeList.GetAt(j);
                        employeeNames.Add(employee.Name.GetValue());
                    }
                }
            }

            return(employeeNames);
        }
        catch (Exception ex)
        {
            // Handle exception
        }
    }
示例#15
0
 ///<summary>Runs the request that has been built.  QB connection must be open before calling this method.</summary>
 private static void DoRequests()
 {
     if (!ConnectionOpen)
     {
         return;
     }
     ResponseMsgSet = SessionManager.DoRequests(RequestMsgSet);
 }
示例#16
0
        public IResponseList LoadQBItemInventoryList(int maxRecords, QBSessionManager sessionManager)
        {
            // IMsgSetRequest requestMsgSet = null;
            QBSession     QBMgr        = null;
            IResponseList responseList = null;

            try
            {
                QBMgr = new QBSession();
                if (sessionManager == null)
                {
                    QBMgr.CreateQBSession(out sessionManager);
                }

                if (sessionManager != null)
                {
                    // Get the RequestMsgSet based on the correct QB Version
                    IMsgSetRequest requestSet = QBMgr.getLatestMsgSetRequest(sessionManager);

                    if (requestSet != null)
                    {
                        // Initialize the message set request object
                        requestSet.Attributes.OnError = ENRqOnError.roeStop;

                        IItemInventoryQuery itemInventory = requestSet.AppendItemInventoryQueryRq();

                        //Set field value for metaData
                        itemInventory.metaData.SetValue(ENmetaData.mdMetaDataAndResponseData); //"IQBENmetaDataType"

                        // Optionally, you can put filter on it.
                        if (maxRecords != 0)
                        {
                            itemInventory.ORListQueryWithOwnerIDAndClass.ListWithClassFilter.MaxReturned.SetValue(maxRecords);
                        }

                        // Do the request and get the response message set object
                        IMsgSetResponse responseMsgSet = sessionManager.DoRequests(requestSet);

                        //IItemInventoryRetList itemInventoryRetList = null;
                        if (responseMsgSet == null)
                        {
                            return(null);
                        }
                        responseList = responseMsgSet.ResponseList;
                        if (responseList == null)
                        {
                            return(null);
                        }

                        // string responseXML = responseMsgSet.ToXMLString();
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(responseList);
        }
        /// <inheritdoc/>
        public async Task <ObservableCollection <InventoryItem> > GetInventoryFromQBFC()
        {
            IMsgSetRequest request = CreateRequest();

            request.AppendItemQueryRq();
            IMsgSetResponse queryResponse = await MakeRequestAsync(request).ConfigureAwait(false);

            return(await ProcessItemQuery(queryResponse));
        }
        /// <summary>
        /// Requests and sets the latest quickbooks sdk version.
        /// </summary>
        /// <param name="queryResponse"></param>
        private void ProcessSDkQuery(IMsgSetResponse queryResponse)
        {
            IResponse response     = queryResponse.ResponseList.GetAt(0);
            IHostRet  HostResponse = (IHostRet)response.Detail;

            IBSTRList supportedVersions = HostResponse.SupportedQBXMLVersionList;

            ParseSDK(supportedVersions);
        }
示例#19
0
        public IResponse GetMessageResponse(ref QBSessionManager sessionManager, ref IMsgSetRequest requestMsgSet)
        {
            // Send Request Get Responce
            //Send the request and get the response from QuickBooks
            IMsgSetResponse responseMsgSet = sessionManager.DoRequests(requestMsgSet);
            IResponse       response       = responseMsgSet.ResponseList.GetAt(0);

            return(response);
        }
示例#20
0
        public void DoAccountQuery()
        {
            bool             sessionBegun   = false;
            bool             connectionOpen = false;
            QBSessionManager sessionManager = null;
            QBSessionMgr     QBMgr          = null;

            try
            {
                //Create the session Manager object
                QBMgr = new QBSessionMgr();
                QBMgr.CreateQBSession(out sessionManager);

                // Get the RequestMsgSet based on the correct QB Version
                IMsgSetRequest requestMsgSet = QBMgr.getLatestMsgSetRequest(sessionManager);

                requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;

                // BuildAccountQueryRq(requestMsgSet);

                IAccountQuery AccountQueryRq = requestMsgSet.AppendAccountQueryRq();

                // Uncomment the following to view and save the request and response XML
                // string requestXML = requestSet.ToXMLString();
                // MessageBox.Show(requestXML);

                //Send the request and get the response from QuickBooks
                IMsgSetResponse responseMsgSet = sessionManager.DoRequests(requestMsgSet);

                string responseXML = responseMsgSet.ToXMLString();
                //MessageBox.Show(responseXML);

                WalkAccountQueryRs(responseMsgSet);

                //End the session and close the connection to QuickBooks
                //Close the session and connection with QuickBooks
                QBMgr.CloseQBConnection(sessionManager);
            }
            catch (Exception ex)
            {
                // MessageBox.Show(e.Message, "Error");
                // MessageBox.Show(ex.Message.ToString() + "\nStack Trace: \n" + ex.StackTrace + "\nExiting the application");
                if (sessionBegun)
                {
                    sessionManager.EndSession();
                }
                if (connectionOpen)
                {
                    sessionManager.CloseConnection();
                }
            }
            finally
            {
                QBMgr.CloseQBConnection(sessionManager);
            }
        }
        private List <Customer> loadCustomers()
        {
            string          request        = "CustomerQueryRq";
            int             count          = getCount(request);
            IMsgSetResponse responseMsgSet = processRequestFromQB(buildCustomerQueryRq(new string[] { "FullName" }, null));
            //string[] customerList = parseCustomerQueryRs(responseMsgSet, 200);// count);
            var customerList = parseCustomerQueryRs2(responseMsgSet, 200);// count);

            return(customerList);
        }
        private string[] parseInvoiceAddRs(IMsgSetResponse responseMsgSet)
        {
            string[]  retVal   = new string[3];
            IResponse response = responseMsgSet.ResponseList.GetAt(0);

            retVal[0] = response.StatusCode.ToString();
            retVal[1] = response.StatusSeverity;
            retVal[2] = response.StatusMessage;
            return(retVal);
        }
示例#23
0
        private SalesReceiptRet GetQBSalesReceipt(SalesReceipt salesreceipt, IMsgSetRequest SalesReceiptRequestMsgSet, SalesReceiptViewModel SalesReceiptVM)
        {
            BeginSession();

            IMsgSetResponse SalesReceiptResponseMsgSet = sessionManager.DoRequests(SalesReceiptRequestMsgSet);

            CloseSession();

            return(SalesReceiptVM.WalkSalesReceiptAddRs(SalesReceiptResponseMsgSet, salesreceipt));
        }
        /// <summary>
        /// Determines the most recent version supported by
        /// the quickbooks instance to which we are connecting.
        /// We should always use the latest version supported
        /// by the target instance.
        /// </summary>
        private async Task GetSDKVersionAsync()
        {
            IMsgSetRequest request = _manager.CreateMsgSetRequest(_country, 1, 0);

            request.AppendHostQueryRq();

            IMsgSetResponse queryResponse = await MakeRequestAsync(request).ConfigureAwait(false);

            ProcessSDkQuery(queryResponse);
        }
        private IInvoiceRetList QueryInvoices(QBSessionManager session)
        {
            // Create Message Set request

            IMsgSetRequest requestMsgSet = getLatestMsgSetRequest(session);

            requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;

            // Create the query object needed to perform InvoiceQueryRq

            IInvoiceQuery  pInvQuery  = requestMsgSet.AppendInvoiceQueryRq();
            IInvoiceFilter pInvFilter = pInvQuery.ORInvoiceQuery.InvoiceFilter;

            // set the date range to the current schedule date selected in ArcLogistics

            pInvFilter.ORDateRangeFilter.TxnDateRangeFilter.ORTxnDateRangeFilter.TxnDateFilter.FromTxnDate.SetValue(m_application.CurrentDate);
            pInvFilter.ORDateRangeFilter.TxnDateRangeFilter.ORTxnDateRangeFilter.TxnDateFilter.ToTxnDate.SetValue(m_application.CurrentDate);

            pInvQuery.IncludeLineItems.SetValue(true);

            // Do the request
            IMsgSetResponse responseMsgSet = session.DoRequests(requestMsgSet);

            // Uncomment the following to see the request and response XML for debugging
            //string rq = requestMsgSet.ToXMLString();
            //string rs = responseMsgSet.ToXMLString();

            //m_application.Messenger.AddInfo("Resquest: " + rq);
            //m_application.Messenger.AddInfo("Response: " + rs);

            // Interpret the response

            IResponseList rsList = responseMsgSet.ResponseList;

            //  Retrieve the one response corresponding to our single request

            IResponse response = rsList.GetAt(0);

            if (response.StatusCode != 0)
            {
                string msg = "";
                if (response.StatusCode == 1)  //No record found
                {
                    msg = "No invoices found for " + m_application.CurrentDate.ToShortDateString();
                }
                else
                {
                    msg = "Error getting invoices.  Status: " + response.StatusCode.ToString() + ", Message: " + response.StatusMessage;
                }

                throw new Exception(msg);
            }

            return(response.Detail as IInvoiceRetList);
        }
示例#26
0
        public static QBResult AddSalesReceipt(SalesReceipt salesreceipt, string QBCompanyFile)
        {
            bool             sessionBegun   = false;
            bool             connectionOpen = false;
            QBSessionManager sessionManager = null;

            try
            {
                //Create the session Manager object
                sessionManager = new QBSessionManager();

                //Create the message set request object to hold our request
                IMsgSetRequest requestMsgSet = sessionManager.CreateMsgSetRequest("US", 3, 0);
                requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;

                BuildSalesReceiptAddRq(requestMsgSet);

                //Connect to QuickBooks and begin a session
                sessionManager.OpenConnection("", "Sample Code from OSR");
                connectionOpen = true;
                sessionManager.BeginSession("", ENOpenMode.omDontCare);
                sessionBegun = true;

                //Send the request and get the response from QuickBooks
                IMsgSetResponse responseMsgSet = sessionManager.DoRequests(requestMsgSet);

                //End the session and close the connection to QuickBooks
                sessionManager.EndSession();
                sessionBegun = false;
                sessionManager.CloseConnection();
                connectionOpen = false;

                WalkSalesReceiptAddRs(responseMsgSet);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Error");
                if (sessionBegun)
                {
                    sessionManager.EndSession();
                }
                if (connectionOpen)
                {
                    sessionManager.CloseConnection();
                }
            }
            //var saleXml = SalesReceiptViewModel.BuildSalesReceiptAddRq(salesreceipt);
            //if (saleXml != null)
            //{
            //    var responseXml = QBPosContext.ProcessXML(saleXml.OuterXml, QBCompanyFile);

            //    return GetQBResult(responseXml);
            //}
            //return null;
        }
示例#27
0
        public IResponseList GetPreferences(QBSessionManager sessionManager)
        {
            IMsgSetRequest requestMsgSet = null;
            QBSession      QBMgr         = null;
            IResponseList  responseList  = null;

            try
            {
                QBMgr = new QBSession();
                if (sessionManager == null)
                {
                    QBMgr.CreateQBSession(out sessionManager);
                }

                if (sessionManager != null)
                {
                    // Get the RequestMsgSet based on the correct QB Version
                    IMsgSetRequest requestSet = QBMgr.getLatestMsgSetRequest(sessionManager);

                    if (requestSet != null)
                    {
                        // Initialize the message set request object
                        requestSet.Attributes.OnError = ENRqOnError.roeStop;

                        BuildPreferencesQueryRq(requestSet);

                        // Do the request and get the response message set object
                        IMsgSetResponse responseMsgSet = sessionManager.DoRequests(requestSet);

                        if (responseMsgSet == null)
                        {
                            return(null);
                        }
                        responseList = responseMsgSet.ResponseList;
                        if (responseList == null)
                        {
                            return(null);
                        }

                        //WalkPreferencesQueryRs(responseSet);

                        //Close the session and connection with QuickBooks
                        //QBMgr.CloseQBConnection(sessionManager);
                    }
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
            }
            return(responseList);
        }
        public static string[,] extractCustomerAddResponse(String response, Session sess)
        {
            string[,] customers;
            QBSessionManager sessionManager = new QBSessionManager();
            IMsgSetResponse  responseSet    = sessionManager.ToMsgSetResponse(response, sess.getCountry(), sess.getMajorVers(), sess.getMinorVers());
            int count = responseSet.ResponseList.Count;

            customers = new string[count, 3];
            customers = getCustomers(responseSet, count);
            return(customers);
        }
    public static string[,] extractSalesReceiptAddResponse(String response, Session sess)
    {
        string[,] sales;
        QBSessionManager sessionManager = new QBSessionManager();
        IMsgSetResponse  responseSet    = sessionManager.ToMsgSetResponse(response, sess.getCountry(), sess.getMajorVers(), sess.getMinorVers());
        int count = responseSet.ResponseList.Count;

        sales = new string[count, 2];
        sales = getSalesReceipts(responseSet, count);
        return(sales);
    }
示例#30
0
        public IResponseList GetQBAccountInfo(QBSessionManager sessionManager)
        {
            //bool sessionBegun = false;
            //bool connectionOpen = false;
            QBSession     QBMgr        = null;
            IResponseList responseList = null;

            try
            {
                QBMgr = new QBSession();
                if (sessionManager == null)
                {
                    //Create the session Manager object
                    QBMgr.CreateQBSession(out sessionManager);
                }

                // Get the RequestMsgSet based on the correct QB Version
                IMsgSetRequest requestMsgSet = QBMgr.getLatestMsgSetRequest(sessionManager);

                requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;

                // BuildAccountQueryRq(requestMsgSet);

                IAccountQuery AccountQueryRq = requestMsgSet.AppendAccountQueryRq();

                //Send the request and get the response from QuickBooks
                IMsgSetResponse responseMsgSet = sessionManager.DoRequests(requestMsgSet);

                if (responseMsgSet == null)
                {
                    return(null);
                }
                responseList = responseMsgSet.ResponseList;
                if (responseList == null)
                {
                    return(null);
                }


                //WalkAccountQueryRs(responseMsgSet);

                //End the session and close the connection to QuickBooks
                //Close the session and connection with QuickBooks
                //QBMgr.CloseQBConnection(sessionManager);
            }
            catch (Exception ex)
            {
            }
            finally
            {
            }
            return(responseList);
        }
示例#31
0
		///<summary>Simplest connection test to QB.  Users have to connect to their QB company file with OD and QB running at the same time the first time they connect.  This is just a simple tool to let them get this connection out of the way.  QB will prompt the user to set permissions / access rights for OD and then from there on QB does not need to be open in the background.</summary>
		public static string TestConnection(string companyPath) {
			try {
				OpenConnection(1,0,companyPath);
				//Send the empty request and get the response from QuickBooks.
				ResponseMsgSet=SessionManager.DoRequests(RequestMsgSet);
				CloseConnection();
				return "Connection to QuickBooks was successful.";
			}
			catch(Exception e) {
				if(SessionBegun) {
					SessionManager.EndSession();
				}
				if(ConnectionOpen) {
					SessionManager.CloseConnection();
				}
				return "Error: "+e.Message;
			}
		}
示例#32
0
 private string[] parseInvoiceAddRs(IMsgSetResponse responseMsgSet)
 {
     string[] retVal = new string[3];
     IResponse response = responseMsgSet.ResponseList.GetAt(0);
     retVal[0] = response.StatusCode.ToString();
     retVal[1] = response.StatusSeverity;
     retVal[2] = response.StatusMessage;
     return retVal;
 }
        void WalkInvoiceAddRs(IMsgSetResponse responseMsgSet)
        {
            if (responseMsgSet == null) return;

            IResponseList responseList = responseMsgSet.ResponseList;
            if (responseList == null) return;

            //if we sent only one request, there is only one response, we'll walk the list for this sample
            for (int i = 0; i < responseList.Count; i++)
            {
                IResponse response = responseList.GetAt(i);
                //check the status code of the response, 0=ok, >0 is warning
                if (response.StatusCode >= 0)//0 means it was successfully transacted
                {
                    qbTranasctionResponse = response.StatusCode;
                    qbTransactionResponseDetail = response.StatusMessage;

                    //the request-specific response is in the details, make sure we have some
                    if (response.Detail != null)
                    {
                        //make sure the response is the type we're expecting
                        ENResponseType responseType = (ENResponseType)response.Type.GetValue();
                        if (responseType == ENResponseType.rtInvoiceAddRs)         ////you will get to here even if the status is 0 (ok)
                        {
                            //upcast to more specific type here, this is safe because we checked with response.Type check above
                            IInvoiceRet InvoiceRet = (IInvoiceRet)response.Detail;
                            WalkInvoiceRet(InvoiceRet);
                        }
                    }
                }
            }
        }
示例#34
0
		///<summary>Runs the request that has been built.  QB connection must be open before calling this method.</summary>
		private static void DoRequests() {
			if(!ConnectionOpen) {
				return;
			}
			ResponseMsgSet=SessionManager.DoRequests(RequestMsgSet);
		}