Exemplo n.º 1
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
        }
    }
Exemplo n.º 2
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());
        }
        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));
        }
Exemplo n.º 4
0
        //public void searchbyCustomerName(string customerName) {

        //    requestMsgSet.ClearRequests();
        //    IInvoiceQuery InvoiceQueryRq = requestMsgSet.AppendInvoiceQueryRq();
        //    //All Open Invoices
        //    InvoiceQueryRq.ORInvoiceQuery.InvoiceFilter.PaidStatus.SetValue(ENPaidStatus.psNotPaidOnly);

        //    InvoiceQueryRq.IncludeLineItems.SetValue(true);
        //    //InvoiceQueryRq.IncludeLinkedTxns.SetValue(true);
        //    responseMsgSet = sessionManager.DoRequests(requestMsgSet);
        //   // return walkInvoice(responseMsgSet);
        //}

        #region Update Invoices

        public string UpdateInvoice(Invoice invoice)
        {
            try
            {
                requestMsgSet.ClearRequests();



                responseMsgSet = sessionManager.DoRequests(requestMsgSet);
                IResponseList responseList = responseMsgSet.ResponseList;
                IResponse     response     = responseList.GetAt(0);
                //check the status code of the response, 0=ok, >0 is warning
                if (response.StatusCode == 0)
                {
                    return(response.StatusMessage);
                }
                else
                {
                    throw new QBException(response.StatusCode, response.StatusMessage.ToString(), requestMsgSet.ToXMLString());
                }
            }
            catch (Exception ex) {
                return(ex.Message);
            }
        }
        public DataExt CreateDataExt(DataExt dataExt)
        {
            requestMsgSet.ClearRequests();
            requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;
            IDataExtDefAdd DataDef = requestMsgSet.AppendDataExtDefAddRq();

            DataDef.OwnerID.SetValue("0");
            DataDef.DataExtName.SetValue(VaultID);
            DataDef.DataExtType.SetValue(ENDataExtType.detSTR255TYPE);
            DataDef.AssignToObjectList.Add(ENAssignToObject.atoCustomer);
            IDataExtAdd DataExtAddRq = requestMsgSet.AppendDataExtAddRq();

            DataExtAddRq.OwnerID.SetValue("0");
            DataExtAddRq.DataExtName.SetValue(VaultID);
            DataExtAddRq.ORListTxnWithMacro.ListDataExt.ListDataExtType.SetValue(ENListDataExtType.ldetCustomer);
            DataExtAddRq.ORListTxnWithMacro.ListDataExt.ListObjRef.ListID.SetValue(dataExt.ListID);
            //DataExtAddRq.ORListTxnWithMacro.ListDataExt.ListObjRef.FullName.SetValue("ab");
            //Set field value for DataExtValue
            DataExtAddRq.DataExtValue.SetValue(dataExt.DataExtValue);

            responseMsgSet = sessionManager.DoRequests(requestMsgSet);
            IResponseList responseList = responseMsgSet.ResponseList;
            IResponse     response     = responseMsgSet.ResponseList.GetAt(0);

            if (response.StatusCode == 0)
            {
                //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.rtDataExtDefAddRs)
                    {
                        IDataExtDefRet DataExtRet = (IDataExtDefRet)response.Detail;
                        if (DataExtRet == null)
                        {
                            return(null);
                        }


                        if (DataExtRet.OwnerID != null)
                        {
                            dataExt.OwnerID = (string)DataExtRet.OwnerID.GetValue();
                        }
                        //Get value of DataExtName
                        dataExt.DataExtName = (string)DataExtRet.DataExtName.GetValue();
                        //Get value of DataExtValue
                        //dataExt.DataExtValue = (string)DataExtRet. .DataExtValue.GetValue();
                    }
                }
            }
            else
            {
                throw new QBException(response.StatusCode, response.StatusMessage.ToString(), requestMsgSet.ToXMLString());
            }

            return(dataExt);
        }
Exemplo n.º 6
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);
        }
        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);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
0
 public ProductsRepository(
     ApplicationDbContext context,
     IResponse <string> response,
     IResponse <ProductModel> responseObj,
     IResponseList <ProductModel> responseList
     )
 {
     _context      = context;
     _response     = response;
     _responseObj  = responseObj;
     _responseList = responseList;
 }
Exemplo n.º 11
0
        public static IQBBase DoProcessRequest(IMsgSetRequest requestMsgSet)
        {
            try
            {
                SessionManager.OpenConnection("QuickBooks Application", "QuickBooks Application");
                ConnectionOpen = true;
                SessionManager.BeginSession("", ENOpenMode.omDontCare);
                SessionBegun = true;

                IMsgSetResponse responseMsgSet = SessionManager.DoRequests(requestMsgSet);
                IResponseList   responseList   = responseMsgSet?.ResponseList;
                if (responseList == null)
                {
                    return(null);
                }

                if (responseList.Count > 0)
                {
                    IResponse response = responseList.GetAt(0);
                    if (response.StatusCode != 0)
                    {
                        ErrorMessage = response.StatusMessage;
                        return(null);
                    }

                    if (response.Detail != null)
                    {
                        return(response.Detail);
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorMessage = ex.Message;
                return(null);
            }
            finally
            {
                if (SessionBegun)
                {
                    SessionManager?.EndSession();
                }
                if (ConnectionOpen)
                {
                    SessionManager?.CloseConnection();
                }
                SessionManager = null;
            }
            return(null);
        }
Exemplo n.º 12
0
        private IItemInventoryRet GetInventoryItem(string fullName)
        {
            IItemInventoryRetList itemInventoryRetList = null;
            IItemInventoryRet     InventoryItem        = null;

            try
            {
                QBItemInventory _QBItemInventory = new QBItemInventory();
                IResponseList   responseList     = _QBItemInventory.GetItemInventor(fullName, sessionManager);

                //if we sent only one request, there is only one response.
                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)
                    {
                        //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.rtItemInventoryQueryRs)
                            {
                                //upcast to more specific type here, this is safe because we checked with response.Type check above
                                itemInventoryRetList = (IItemInventoryRetList)response.Detail;
                                if (itemInventoryRetList != null && itemInventoryRetList.Count > 0)
                                {
                                    for (int j = 0; j < itemInventoryRetList.Count; j++)
                                    {
                                        InventoryItem = itemInventoryRetList.GetAt(j);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        int    statusCode     = response.StatusCode;
                        string statusMessage  = response.StatusMessage;
                        string statusSeverity = response.StatusSeverity;
                    }
                }
            }
            catch (Exception e)
            {
            }
            return(InventoryItem);
        }
        public DataExt UpdateDataExt(DataExt dataExt)
        {
            requestMsgSet.ClearRequests();
            requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;
            IDataExtMod DataExtMod = requestMsgSet.AppendDataExtModRq();


            DataExtMod.DataExtName.SetValue(VaultID);
            DataExtMod.DataExtValue.SetValue(dataExt.DataExtValue);
            DataExtMod.OwnerID.SetValue("0");
            DataExtMod.ORListTxn.ListDataExt.ListDataExtType.SetValue(ENListDataExtType.ldetCustomer);
            DataExtMod.ORListTxn.ListDataExt.ListObjRef.ListID.SetValue(dataExt.ListID);

            responseMsgSet = sessionManager.DoRequests(requestMsgSet);
            IResponseList responseList = responseMsgSet.ResponseList;
            IResponse     response     = responseMsgSet.ResponseList.GetAt(0);

            if (response.StatusCode == 0)
            {
                //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.rtDataExtModRs)
                    {
                        //IDataExtMod DataExtRet = (IDataExtMod)response.Detail;
                        //if (DataExtRet == null) return null;


                        //if (DataExtRet.OwnerID != null)
                        //{
                        //    dataExt.OwnerID = (string)DataExtRet.OwnerID.GetValue();
                        //}
                        ////Get value of DataExtName
                        //dataExt.DataExtName = (string)DataExtRet.DataExtName.GetValue();
                        ////Get value of DataExtValue
                        ////dataExt.DataExtValue = (string)DataExtRet. .DataExtValue.GetValue();
                    }
                }
            }
            else
            {
                throw new QBException(response.StatusCode, response.StatusMessage.ToString(), requestMsgSet.ToXMLString());
            }

            return(dataExt);
        }
Exemplo n.º 14
0
        private IAccountRetList GetQBAccountDetails()
        {
            IAccountRetList AccountList = null;

            try
            {
                if (sessionManager != null)
                {
                    QBAccount _qbAccount = new QBAccount();

                    IResponseList responseList = _qbAccount.GetQBAccountInfo(sessionManager);
                    if (responseList == null)
                    {
                        return(null);
                    }

                    //if we sent only one request, there is only one response.
                    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)
                        {
                            //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.rtAccountQueryRs)
                                {
                                    //upcast to more specific type here, this is safe because we checked with response.Type check above
                                    AccountList = (IAccountRetList)response.Detail;
                                }
                            }
                        }
                        else
                        {
                            //*** Error Handling.
                        }
                    }
                }
            }
            catch (Exception e)
            {
            }
            return(AccountList);
        }
Exemplo n.º 15
0
        private List <Invoice> walkInvoice(IMsgSetResponse responseMsgSet)
        {
            if (responseMsgSet == null)
            {
                return(null);
            }

            IResponseList responseList = responseMsgSet.ResponseList;

            if (responseList == null)
            {
                return(null);
            }

            IResponse response = responseList.GetAt(0);

            //check the status code of the response, 0=ok, >0 is warning
            if (response.StatusCode == 0)
            {
                //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.rtInvoiceQueryRs)
                    {
                        //upcast to more specific type here, this is safe because we checked with response.Type check above
                        IInvoiceRetList InvoiceRet = (IInvoiceRetList)response.Detail;
                        int             count      = InvoiceRet.Count;
                        if (count > 0)
                        {
                            InvoiceList = new List <Invoice>();
                        }
                        for (int a = 0; a < count; a++)
                        {
                            InvoiceList.Add(WalkInvoiceSearchRet(InvoiceRet.GetAt(a)));
                        }
                    }
                }
            }
            else
            {
                throw new QBException(response.StatusCode, response.StatusMessage.ToString(), requestMsgSet.ToXMLString());
            }

            return(InvoiceList);
        }
Exemplo n.º 16
0
    /// <summary>
    /// The GetQBAccounts.
    /// </summary>
    /// <param name="logsFile">The logsFile<see cref="StreamWriter"/>.</param>
    /// <returns>The <see cref="List{dynamic}"/>.</returns>
    public List <dynamic> GetQBAccounts(StreamWriter logsFile)
    {
        IMsgSetRequest requestSet = SessionManager.Instance.CreateMsgSetRequest();

        requestSet.Attributes.OnError = ENRqOnError.roeStop;
        requestSet.AppendAccountQueryRq();
        IMsgSetResponse responeSet     = SessionManager.Instance.DoRequests(requestSet, logsFile);
        IResponseList   responseList   = responeSet.ResponseList;
        List <dynamic>  accountsArray  = new List <dynamic>();
        var             account_number = "";

        try
        {
            for (int i = 0; i < responseList.Count; i++)
            {
                IResponse response = responseList.GetAt(i);

                if (response.StatusCode == 0)
                {
                    IAccountRetList AccountRet = (IAccountRetList)response.Detail;
                    Console.WriteLine("Number Of Records Being Fetched Are:\t" + AccountRet.Count + "\n");
                    for (int j = 0; j < AccountRet.Count; j++)
                    {
                        IAccountRet account = AccountRet.GetAt(j);
                        if (account.AccountNumber != null)
                        {
                            account_number = account.AccountNumber.GetValue();
                        }
                        else
                        {
                            account_number = "Account Number Not Defined...";
                        }
                        accountsArray.Add(new string[] { account.Name.GetValue().ToString(), account_number, account.AccountType.GetValue().ToString(), account.TotalBalance.GetValue().ToString() });
                    }
                }
            }
        }
        catch (Exception ex)
        {
            logsFile.WriteLine(DateTime.Now + "\tERROR\tError Message:\t" + ex.Message);
            logsFile.WriteLine();
            logsFile.WriteLine(DateTime.Now + "\tERROR\tError Message:\tStack Trace:\t" + ex.StackTrace);
            logsFile.WriteLine();
        }

        return(accountsArray);
    }
Exemplo n.º 17
0
        private void WriteList(Utf8JsonWriter writer, IResponseList list)
        {
            if (list?.Items == null)
            {
                writer.WriteNullValue();
            }
            else
            {
                writer.WriteStartArray();
                foreach (var item in list.Items)
                {
                    this.WriteResponseItem(writer, item);
                }

                writer.WriteEndArray();
            }
        }
Exemplo n.º 18
0
    public void GetCreditMemoData()
    {
        // open connection and begin session before data fetch - intentionally skipped this code
        IMsgSetRequest   msgset          = null;
        ICreditMemoQuery creditMemoQuery = null;

        try
        {
            // during data fetch
            msgset          = sessionMgr.CreateMsgSetRequest("US", 13, 0);
            creditMemoQuery = msgset.AppendCreditMemoQueryRq();
            creditMemoQuery.ORTxnQuery.TxnFilter.ORDateRangeFilter.ModifiedDateRangeFilter.FromModifiedDate.SetValue(new DateTime(2012, 3, 31), false);     // you can apply filters too
            IMsgSetResponse msgRes       = sessionMgr.DoRequests(msgset);
            IResponseList   responseList = msgRes.ResponseList;
            if (responseList.Count > 0)
            {
                IResponse          response       = responseList.GetAt(0);
                ICreditMemoRetList creditMemoList = response.Detail as ICreditMemoRetList;
                if (creditMemoList == null)
                {
                    return;
                }
                for (int i = 0; i <= creditMemoList.Count - 1; i++)
                {
                    ICreditMemoRet qbCreditMemo = creditMemoList.GetAt(i);
                    Console.WriteLine("Credit no.:" + qbCreditMemo.TxnNumber.GetValue() + " Customer:" + qbCreditMemo.CustomerRef.FullName.GetValue() + " Total:" + qbCreditMemo.TotalAmount.GetValue());
                }
            }
        }
        catch (Exception ex)
        {
            //handle exception here
        }
        finally
        {
            if (msgset != null)
            {
                Marshal.FinalReleaseComObject(msgset);
            }
            if (creditMemoQuery != null)
            {
                Marshal.FinalReleaseComObject(creditMemoQuery);
            }
        }
        // end session and close connection after data fetch - intentionally skipped this code
    }
Exemplo n.º 19
0
        private QBResponceItem WalkInventoryAdjustmentAddRs(IMsgSetResponse responseMsgSet)
        {
            QBResponceItem _qbResponceItem = null;

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

            if (responseList == null)
            {
                return(null);
            }
            //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++)
            {
                _qbResponceItem = new QBResponceItem();
                IResponse response = responseList.GetAt(i);

                _qbResponceItem.StatusCode     = response.StatusCode;
                _qbResponceItem.StatusMessage  = response.StatusMessage;
                _qbResponceItem.StatusSeverity = response.StatusSeverity;


                //check the status code of the response, 0=ok, >0 is warning
                if (response.StatusCode >= 0)
                {
                    //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.rtInventoryAdjustmentAddRs)
                        {
                            //upcast to more specific type here, this is safe because we checked with response.Type check above
                            IInventoryAdjustmentRet InventoryAdjustmentRet = (IInventoryAdjustmentRet)response.Detail;

                            _qbResponceItem.InventoryItemAdjustment = InventoryAdjustmentRet;
                        }
                    }
                }
            }
            return(_qbResponceItem);
        }
Exemplo n.º 20
0
    public void ImportTimesheets(List <Timesheet> tmList)
    {
        try
        {
            IMsgSetRequest requestSet = SessionManager.Instance.CreateMsgSetRequest();
            requestSet.Attributes.OnError = ENRqOnError.roeStop;
            ITimeTrackingAdd timeTrackingAdd;

            foreach (Timesheet tm in tmList)
            {
                timeTrackingAdd = requestSet.AppendTimeTrackingAddRq();

                timeTrackingAdd.CustomerRef.FullName.SetValue(tm.CustomerJob);
                timeTrackingAdd.Duration.SetValue(tm.Hours);
                timeTrackingAdd.BillableStatus.SetValue(ENBillableStatus.bsBillable);
                timeTrackingAdd.EntityRef.FullName.SetValue(tm.EmployeeName);
                timeTrackingAdd.ItemServiceRef.FullName.SetValue(tm.ServiceItem);
                timeTrackingAdd.PayrollItemWageRef.FullName.SetValue(tm.PayrollItem);
                timeTrackingAdd.TxnDate.SetValue(tm.TransactionDate);
                timeTrackingAdd.Notes.SetValue(tm.Notes);
            }

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

            if (responseList.Count > 0)
            {
                for (int i = 0; i < responseList.Count; i++)
                {
                    IResponse response = responseList.GetAt(i);
                    if (response.StatusCode == 0)
                    {
                        Console.WriteLine("Successfully imported timesheets");
                    }
                    else
                    {
                        Console.WriteLine("Response status message: " + response.StatusMessage);
                        Console.WriteLine("Response status code: " + response.StatusCode);
                    }
                }
            }
        }
    }
Exemplo n.º 21
0
        void WalkAccountQueryRs(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)
                {
                    //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.rtAccountQueryRs)
                        {
                            // var vs = response.Detail.GetType();
                            //upcast to more specific type here, this is safe because we checked with response.Type check above
                            IAccountRetList AccountRet = (IAccountRetList)response.Detail;
                            for (int j = 0; j < AccountRet.Count; j++)
                            {
                                IAccountRet accountInfo = AccountRet.GetAt(j);
                                if (accountInfo != null)
                                {
                                    WalkAccountRet(accountInfo);
                                }
                            }
                        }
                    }
                }
            }
        }
        private IList <Customer> WalkCustomerQuery(IMsgSetResponse responseMsgSet)
        {
            if (responseMsgSet == null)
            {
                return(null);
            }

            IResponseList responseList = responseMsgSet.ResponseList;

            if (responseList == null)
            {
                return(null);
            }

            int count = responseList.Count;

            //if we sent only one request, there is only one response, we'll walk the list for this sample
            for (int i = 0; i < count; i++)
            {
                IResponse response = responseList.GetAt(i);

                if (response.StatusCode == 0)
                {
                    if (response.Detail != null)
                    {
                        ENResponseType responseType = (ENResponseType)response.Type.GetValue();
                        if (responseType == ENResponseType.rtCustomerQueryRs)
                        {
                            ICustomerRetList CustomerRet = (ICustomerRetList)response.Detail;
                            return(WalkCustomers(CustomerRet));
                        }
                    }
                }
                else
                {
                    throw new QBException(response.StatusCode, response.StatusMessage, requestMsgSet.ToXMLString());
                }
            }

            return(null);
        }
Exemplo n.º 23
0
        string WalkInvoiceAddRs(IMsgSetResponse responseMsgSet)
        {
            if (responseMsgSet == null)
            {
                return(null);
            }

            IResponseList responseList = responseMsgSet.ResponseList;

            if (responseList == null)
            {
                return(null);
            }

            //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)
                {
                    //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)
                        {
                            //upcast to more specific type here, this is safe because we checked with response.Type check above
                            IInvoiceRet InvoiceRet = (IInvoiceRet)response.Detail;
                            return(WalkInvoiceRet(InvoiceRet));
                        }
                    }
                }
                else
                {
                    throw new QBException(response.StatusCode, response.StatusMessage, requestMsgSet.ToXMLString());
                }
            }
            return(null);
        }
        private void editCustomer_Click(object sender, EventArgs e)
        {
            _MySessionManager = SessionManager.NewQBSession();

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

            ICustomerQuery Query = requestMsgSet.AppendCustomerQueryRq();

            IMsgSetResponse responseMsgSet = _MySessionManager.DoRequests(requestMsgSet);

            IResponseList rsList = responseMsgSet.ResponseList;

            IResponse response = rsList.GetAt(0);

            ICustomerRetList CustomerList = (ICustomerRetList)response.Detail;

            if (CustomerList == null)
            {
                throw new Exception("Sorry, no customers found.");
            }

            for (int i = 0; i <= CustomerList.Count - 1; i++)
            {
                ICustomerRet QBCustomer = CustomerList.GetAt(i);

                //string CustomerName = QBCustomer.Name.GetValue().ToString();
                //string listID = QBCustomer.ListID.GetValue();
                //string editSequence = QBCustomer.EditSequence.GetValue();
                if (QBCustomer.Email != null)
                {
                    string email = QBCustomer.Email.GetValue();

                    if (_emailsToDelete.Contains(email))
                    {
                        modifyCustomer(QBCustomer);
                    }
                }
            }
        }
        void WalkPaymentMethodQueryRs(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++)
            {
                MethodList = new List <PaymentMethod>();
                IResponse response = responseList.GetAt(i);
                //check the status code of the response, 0=ok, >0 is warning
                if (response.StatusCode >= 0)
                {
                    //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.rtPaymentMethodQueryRs)
                        {
                            //upcast to more specific type here, this is safe because we checked with response.Type check above
                            IPaymentMethodRetList PaymentMethodRet = (IPaymentMethodRetList)response.Detail;
                            int count = PaymentMethodRet.Count;
                            for (int a = 0; a < count; a++)
                            {
                                MethodList.Add(WalkPaymentMethodRet(PaymentMethodRet.GetAt(a)));
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 26
0
        void RequestNonInventory()
        {
            requestMsgSet.ClearRequests();
            IItemNonInventoryQuery Inventory = requestMsgSet.AppendItemNonInventoryQueryRq();

            //Inventory.IsActive.SetValue(true);
            responseMsgSet = sessionManager.DoRequests(requestMsgSet);
            IResponseList responseList = responseMsgSet.ResponseList;
            IResponse     response     = responseMsgSet.ResponseList.GetAt(0);

            if (response.StatusCode >= 0)
            {
                //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.rtItemNonInventoryQueryRs)
                    {
                        //upcast to more specific type here, this is safe because we checked with response.Type check above
                        IItemNonInventoryRetList ItemNonInventoryRetList = (IItemNonInventoryRetList)response.Detail;
                        int count = ItemNonInventoryRetList.Count;
                        if (count > 0)
                        {
                            ItemList = new List <Items>();
                        }
                        for (int a = 0; a < count; a++)
                        {
                            ItemList.Add(WalkNonInventoryItem(ItemNonInventoryRetList.GetAt(a)));
                        }
                    }
                }
            }
            else
            {
                throw new QBException(response.StatusCode, response.StatusMessage.ToString(), requestMsgSet.ToXMLString());
            }
        }
Exemplo n.º 27
0
        ///<summary>Checks if the status code for the deposit is "ok".</summary>
        private static void ValidateDepositAddRs()
        {
            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)
                {
                    throw new Exception(response.StatusMessage);
                }
            }
        }
        public TrackableCollection <ItemInventoryRet> WalkItemInventoryQueryRs(IMsgSetResponse responseMsgSet)
        {
            if (responseMsgSet == null)
            {
                return(null);
            }

            IResponseList responseList = responseMsgSet.ResponseList;

            if (responseList == null)
            {
                return(null);
            }

            //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)
                {
                    //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.rtItemInventoryQueryRs)
                        {
                            //upcast to more specific type here, this is safe because we checked with response.Type check above
                            IItemInventoryRetList ItemInventoryRet = (IItemInventoryRetList)response.Detail;
                            return(WalkItemInventoryRet(ItemInventoryRet));
                        }
                    }
                }
            }
            return(null);
        }
        public void WalkSalesReceiptQueryRs(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)
                {
                    //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.rtSalesReceiptQueryRs)
                        {
                            //upcast to more specific type here, this is safe because we checked with response.Type check above
                            ISalesReceiptRetList SalesReceiptRet = (ISalesReceiptRetList)response.Detail;
                            SaveToDataBase(WalkSalesReceiptRet(SalesReceiptRet));
                        }
                    }
                }
            }
        }
Exemplo n.º 30
0
        public List <Customer> getAllCustomers()
        {
            //Item Request
            IMsgSetRequest customerRequestset = _MySessionManager.CreateMsgSetRequest("US", 13, 0);

            ICustomerQuery customerQuery = customerRequestset.AppendCustomerQueryRq();

            IMsgSetResponse responseCustomerRq = _MySessionManager.DoRequests(customerRequestset);

            IResponseList customerResponseList = responseCustomerRq.ResponseList;

            IResponse customerResponse = customerResponseList.GetAt(0);

            //ENResponseType responseType = (ENResponseType)customerResponse.Type.GetValue();
            ICustomerRetList customerList = (ICustomerRetList)customerResponse.Detail;

            for (int i = 0; i <= customerList.Count - 1; i++)
            {
                ICustomerRet qbCustomer = customerList.GetAt(i);

                Address address = new Address();

                Customer customer = new Customer();
                customer.AccountNumber = qbCustomer.AccountNumber != null?qbCustomer.AccountNumber.GetValue() : null;

                customer.Name    = qbCustomer.Name.GetValue();
                customer.Address = address.getAddress(qbCustomer.BillAddress);
                customer.Email   = qbCustomer.Email != null?qbCustomer.Email.GetValue() : null;

                customer.Phone = qbCustomer.Phone != null?qbCustomer.Phone.GetValue() : null;

                _customers.Add(customer);
            }

            return(_customers);
        }