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);
            }
        }
        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.º 6
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.º 7
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);
        }
Exemplo n.º 8
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.º 9
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.º 10
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.º 11
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.º 12
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.º 13
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.º 14
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);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 15
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 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);
        }
        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.º 19
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.º 22
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);
        }
        public string GetCompanyName()
        {
            ICompanyQuery CompanyQueryRq = requestMsgSet.AppendCompanyQueryRq();

            responseMsgSet = sessionManager.DoRequests(requestMsgSet);
            ICompanyRet CompanyRet = null;

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

            if (responseList == null)
            {
                return(null);
            }
            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.rtCompanyQueryRs)
                        {
                            CompanyRet = (ICompanyRet)response.Detail;
                        }
                    }
                }
            }

            return((string)CompanyRet.CompanyName.GetValue());
        }
Exemplo n.º 24
0
        public static void Main()
        {
            QBSessionManager sessionManager = new QBSessionManager();

            try
            {
                IMsgSetRequest requestMsgSet = sessionManager.CreateMsgSetRequest("US", 13, 0);
                sessionManager.OpenConnection("", "TEST");
                sessionManager.BeginSession("", ENOpenMode.omDontCare);
                requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;
                IItemInventoryQuery ItemInventoryQueryRq = requestMsgSet.AppendItemInventoryQueryRq();
                IMsgSetResponse     responseMsgSet       = sessionManager.DoRequests(requestMsgSet);
                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.rtItemInventoryQueryRs)
                            {
                                IItemInventoryRetList ItemInventoryRet = (IItemInventoryRetList)response.Detail;
                                for (int j = 0; j < ItemInventoryRet.Count; j++)
                                {
                                    if (ItemInventoryRet.GetAt(j).UnitOfMeasureSetRef != null)
                                    {
                                        string itemListId   = ItemInventoryRet.GetAt(j).ListID.GetValue();
                                        string itemFullName = ItemInventoryRet.GetAt(j).FullName.GetValue();
                                        short  ItemType     = ItemInventoryRet.GetAt(j).Type.GetValue();
                                        string unitOfMeasurementRefListId   = ItemInventoryRet.GetAt(j).UnitOfMeasureSetRef.ListID.GetValue();
                                        string unitOfMeasurementRefFullName = ItemInventoryRet.GetAt(j).UnitOfMeasureSetRef.FullName.GetValue();
                                        short  unitOfMeasurementRefType     = ItemInventoryRet.GetAt(j).UnitOfMeasureSetRef.Type.GetValue();
                                        Console.WriteLine($"Item Id: {itemListId}\r\nItem Full Name: {itemFullName}\r\n{ItemType}\r\nUnit of Measurement List Id: {unitOfMeasurementRefListId}\r\nUnit of Measurement Full Name: {unitOfMeasurementRefFullName}\r\nUnit of Measurement Type: {unitOfMeasurementRefType}\r\n");
                                        IMsgSetRequest         uomRequestMsgSet        = sessionManager.CreateMsgSetRequest("US", 13, 0);
                                        IUnitOfMeasureSetQuery UnitOfMeasureSetQueryRq = uomRequestMsgSet.AppendUnitOfMeasureSetQueryRq();
                                        UnitOfMeasureSetQueryRq.ORListQuery.ListIDList.Add(ItemInventoryRet.GetAt(j).UnitOfMeasureSetRef.ListID.GetValue());
                                        IMsgSetResponse unitOfMeaurementResponseMsgSet = sessionManager.DoRequests(uomRequestMsgSet);
                                        WalkUnitOfMeasureSetQueryRs(unitOfMeaurementResponseMsgSet);
                                    }
                                }
                            }
                        }
                    }
                }
                sessionManager.EndSession();
                sessionManager.CloseConnection();
                Console.ReadLine();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message, "Error");
                sessionManager.EndSession();
                sessionManager.CloseConnection();
                Console.ReadLine();
            }
        }
Exemplo n.º 25
0
        static void WalkUnitOfMeasureSetQueryRs(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.rtUnitOfMeasureSetQueryRs)
                        {
                            IUnitOfMeasureSetRetList UnitOfMeasureSetRet = (IUnitOfMeasureSetRetList)response.Detail;
                            for (int j = 0; j < UnitOfMeasureSetRet.Count; j++)
                            {
                                if (UnitOfMeasureSetRet != null)
                                {
                                    if (UnitOfMeasureSetRet.GetAt(j).BaseUnit != null)
                                    {
                                        if (UnitOfMeasureSetRet.GetAt(j).BaseUnit.Abbreviation != null)
                                        {
                                            string baseUnitAbbreviation = UnitOfMeasureSetRet.GetAt(j).BaseUnit.Abbreviation.GetValue();
                                            Console.WriteLine($"Base Unit Abbreviation: {baseUnitAbbreviation}");
                                        }
                                        if (UnitOfMeasureSetRet.GetAt(j).BaseUnit.Name != null)
                                        {
                                            string baseUnitName = UnitOfMeasureSetRet.GetAt(j).BaseUnit.Name.GetValue();
                                            Console.WriteLine($"Base Unit Name: {baseUnitName}");
                                        }
                                        if (UnitOfMeasureSetRet.GetAt(j).BaseUnit.Type != null)
                                        {
                                            short baseUnitType = UnitOfMeasureSetRet.GetAt(j).BaseUnit.Type.GetValue();
                                            Console.WriteLine($"Base Unit Type: {baseUnitType}");
                                        }
                                    }
                                    if (UnitOfMeasureSetRet.GetAt(j).DefaultUnitList != null)
                                    {
                                        for (int i22940 = 0; i22940 < UnitOfMeasureSetRet.GetAt(j).DefaultUnitList.Count; i22940++)
                                        {
                                            if (UnitOfMeasureSetRet.GetAt(j).DefaultUnitList.GetAt(i22940) != null)
                                            {
                                                IDefaultUnit DefaultUnit = UnitOfMeasureSetRet.GetAt(j).DefaultUnitList.GetAt(i22940);
                                                if (DefaultUnit.UnitUsedFor != null)
                                                {
                                                    ENUnitUsedFor UnitUsedFor22941 = DefaultUnit.UnitUsedFor.GetValue();
                                                    Console.WriteLine($"Unit used for: {UnitUsedFor22941}");
                                                }
                                                if (DefaultUnit.Unit != null)
                                                {
                                                    string Unit22942 = DefaultUnit.Unit.GetValue();
                                                    Console.WriteLine($"Default Unit: {Unit22942}");
                                                }
                                            }
                                        }
                                    }
                                    if (UnitOfMeasureSetRet.GetAt(j).EditSequence != null)
                                    {
                                        string editSequence = UnitOfMeasureSetRet.GetAt(j).EditSequence.GetValue();
                                        Console.WriteLine($"Edit sequence: {editSequence}");
                                    }
                                    if (UnitOfMeasureSetRet.GetAt(j).IsActive != null)
                                    {
                                        bool isActive = UnitOfMeasureSetRet.GetAt(j).IsActive.GetValue();
                                        Console.WriteLine($"Is active: {isActive}");
                                    }
                                    if (UnitOfMeasureSetRet.GetAt(j).ListID != null)
                                    {
                                        string listId = UnitOfMeasureSetRet.GetAt(j).ListID.GetValue();
                                        Console.WriteLine($"List Id: {listId}");
                                    }
                                    if (UnitOfMeasureSetRet.GetAt(j).Name != null)
                                    {
                                        string name = UnitOfMeasureSetRet.GetAt(j).Name.GetValue();
                                        Console.WriteLine($"Name: {name}");
                                    }
                                    if (UnitOfMeasureSetRet.GetAt(j).RelatedUnitList != null)
                                    {
                                        for (int i22936 = 0; i22936 < UnitOfMeasureSetRet.GetAt(j).RelatedUnitList.Count; i22936++)
                                        {
                                            if (UnitOfMeasureSetRet.GetAt(j).RelatedUnitList.GetAt(i22936) != null)
                                            {
                                                IRelatedUnit RelatedUnit = UnitOfMeasureSetRet.GetAt(j).RelatedUnitList.GetAt(i22936);
                                                if (RelatedUnit.Name != null)
                                                {
                                                    string Name22937 = RelatedUnit.Name.GetValue();
                                                    Console.WriteLine($"Related Unit: {Name22937}");
                                                }
                                                if (RelatedUnit.Abbreviation != null)
                                                {
                                                    string Abbreviation22938 = RelatedUnit.Abbreviation.GetValue();
                                                    Console.WriteLine($"Related Unit Abbreviation: {Abbreviation22938}");
                                                }
                                                if (RelatedUnit.ConversionRatio != null)
                                                {
                                                    double ConversionRatio22939 = RelatedUnit.ConversionRatio.GetValue();
                                                    Console.WriteLine($"Conversion Ratio: {ConversionRatio22939}");
                                                }
                                            }
                                        }
                                    }
                                    if (UnitOfMeasureSetRet.GetAt(j).TimeCreated != null)
                                    {
                                        DateTime timeCreated = UnitOfMeasureSetRet.GetAt(j).TimeCreated.GetValue();
                                        Console.WriteLine($"Time created: {timeCreated}");
                                    }
                                    if (UnitOfMeasureSetRet.GetAt(j).TimeModified != null)
                                    {
                                        DateTime timeModified = UnitOfMeasureSetRet.GetAt(j).TimeModified.GetValue();
                                        Console.WriteLine($"Time modified: {timeModified}");
                                    }
                                    if (UnitOfMeasureSetRet.GetAt(j).Type != null)
                                    {
                                        short type = UnitOfMeasureSetRet.GetAt(j).Type.GetValue();
                                        Console.WriteLine($"Type: {type}");
                                    }
                                    if (UnitOfMeasureSetRet.GetAt(j).UnitOfMeasureType != null)
                                    {
                                        ENUnitOfMeasureType unitOfMeasurementType = UnitOfMeasureSetRet.GetAt(j).UnitOfMeasureType.GetValue();
                                        Console.WriteLine($"Unit of Measure Type: {unitOfMeasurementType}\r\n");
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        public List <InventoryItem> getAllItems()
        {
            try
            {
                //Item Request
                IMsgSetRequest itemRequestset = _MySessionManager.CreateMsgSetRequest("US", 13, 0);

                IItemQuery itemQuery = itemRequestset.AppendItemQueryRq();

                itemQuery.OwnerIDList.Add("0");

                ////Get item codes from sales order and add to item request
                //for (int i = 0; i < SalesOrderItems.Count; ++i)
                //{
                //    IORSalesOrderLineRet SalesOrderItem = SalesOrderItems.GetAt(i);
                //    itemQuery.ORListQuery.FullNameList.Add(SalesOrderItem.SalesOrderLineRet.ItemRef.FullName.GetValue());
                //}

                //itemQuery.ORListQuery.FullNameList.Add("17531");
                //itemQuery.ORListQuery.FullNameList.Add("17534");
                //itemQuery.ORListQuery.FullNameList.Add("17535");
                //itemQuery.ORListQuery.FullNameList.Add("17536");
                //itemQuery.ORListQuery.FullNameList.Add("17537");
                //itemQuery.ORListQuery.FullNameList.Add("17538");
                //itemQuery.ORListQuery.FullNameList.Add("62231");
                //itemQuery.ORListQuery.FullNameList.Add("12061");

                IMsgSetResponse responseItemRq = _MySessionManager.DoRequests(itemRequestset);

                IResponseList itemResponseList = responseItemRq.ResponseList;

                IResponse itemResponse = itemResponseList.GetAt(0);

                ENResponseType responseType = (ENResponseType)itemResponse.Type.GetValue();
                IORItemRetList QBItemList   = (IORItemRetList)itemResponse.Detail;

                for (int i = 0; i <= QBItemList.Count - 1; i++)
                {
                    InventoryItem   item = new InventoryItem();
                    IDataExtRetList customFieldsList;

                    if (QBItemList.GetAt(i).ItemNonInventoryRet != null)
                    {
                        IItemNonInventoryRet inventoryItem = QBItemList.GetAt(i).ItemNonInventoryRet;
                        customFieldsList = QBItemList.GetAt(i).ItemNonInventoryRet.DataExtRetList;

                        item.ListID = inventoryItem.ListID != null?inventoryItem.ListID.GetValue() : "";

                        item.ItemCode = inventoryItem.Name != null?inventoryItem.Name.GetValue() : "";

                        item.Description = inventoryItem.FullName.GetValue() != null?inventoryItem.FullName.GetValue() : "";

                        item.MPN = inventoryItem.ManufacturerPartNumber != null?inventoryItem.ManufacturerPartNumber.GetValue() : "";
                    }
                    else if (QBItemList.GetAt(i).ItemInventoryRet != null)
                    {
                        IItemInventoryRet inventoryItem = QBItemList.GetAt(i).ItemInventoryRet;
                        customFieldsList = QBItemList.GetAt(i).ItemInventoryRet.DataExtRetList;

                        item.ListID = inventoryItem.ListID != null?inventoryItem.ListID.GetValue() : "";

                        item.ItemCode = inventoryItem.Name != null?inventoryItem.Name.GetValue() : "";

                        item.Description = inventoryItem.SalesDesc != null?inventoryItem.SalesDesc.GetValue() : "";

                        item.MPN = inventoryItem.ManufacturerPartNumber != null?inventoryItem.ManufacturerPartNumber.GetValue() : "";

                        item.Price = inventoryItem.SalesPrice.GetValue();
                    }
                    else if (QBItemList.GetAt(i).ItemInventoryAssemblyRet != null)
                    {
                        IItemInventoryAssemblyRet inventoryItem = QBItemList.GetAt(i).ItemInventoryAssemblyRet;
                        customFieldsList = QBItemList.GetAt(i).ItemInventoryAssemblyRet.DataExtRetList;

                        item.ListID = inventoryItem.ListID != null?inventoryItem.ListID.GetValue() : "";

                        item.ItemCode = inventoryItem.Name != null?inventoryItem.Name.GetValue() : "";

                        item.Description = inventoryItem.SalesDesc.GetValue() != null?inventoryItem.SalesDesc.GetValue() : "";

                        item.MPN = inventoryItem.ManufacturerPartNumber != null?inventoryItem.ManufacturerPartNumber.GetValue() : "";
                    }
                    else
                    {
                        customFieldsList = null;
                    }

                    //get item external data (custom fields)
                    if (customFieldsList != null)
                    {
                        for (int iCustomField = 0; iCustomField <= customFieldsList.Count - 1; iCustomField++)
                        {
                            string fieldName  = customFieldsList.GetAt(iCustomField).DataExtName.GetValue();
                            string fieldValue = customFieldsList.GetAt(iCustomField).DataExtValue.GetValue();

                            if (fieldName == "Inner")
                            {
                                item.Inner = fieldValue;
                            }

                            if (fieldName == "Case")
                            {
                                item.Case = fieldValue;
                            }

                            if (fieldName == "Price2")
                            {
                                item.Price2 = Convert.ToDouble(fieldValue);
                            }

                            if (fieldName == "Volume")
                            {
                                item.Volume = fieldValue;
                            }

                            if (fieldName == "Price3")
                            {
                                item.Price3 = Convert.ToDouble(fieldValue);
                            }
                        }
                    }

                    if (item.ItemCode != null)
                    {
                        _inventoryItems.Add(item);
                    }
                }

                return(_inventoryItems);
            }
            catch (Exception)
            {
                throw new Exception("Failed to read Items from QuickBooks.");
            }
        }
        public SalesOrder Populate(string salesOrderNumber)
        {
            IMsgSetRequest requestMsgSet = _MySessionManager.CreateMsgSetRequest("US", 13, 0);

            ISalesOrderQuery soQuery = requestMsgSet.AppendSalesOrderQueryRq();

            soQuery.ORTxnNoAccountQuery.RefNumberList.Add(salesOrderNumber);

            soQuery.IncludeLineItems.SetValue(true);

            IMsgSetResponse responseMsgSet = _MySessionManager.DoRequests(requestMsgSet);

            IResponseList rsList = responseMsgSet.ResponseList;

            IResponse response = rsList.GetAt(0);

            ISalesOrderRetList SalesOrderList = (ISalesOrderRetList)response.Detail;

            if (SalesOrderList == null)
            {
                throw new Exception("Sales order not found.");
            }

            try
            {
                ISalesOrderRet QBSalesOrder = SalesOrderList.GetAt(0);

                _salesOrder          = new SalesOrder();
                _salesOrder.Number   = QBSalesOrder.RefNumber.GetValue();
                _salesOrder.Date     = QBSalesOrder.TxnDate.GetValue();
                _salesOrder.ShipDate = QBSalesOrder.ShipDate.GetValue();
                _salesOrder.Total    = QBSalesOrder.TotalAmount.GetAsString();

                _salesOrder.CustomerFullName = QBSalesOrder.CustomerRef.FullName.GetValue();

                Address address = new Address();
                _salesOrder.BillingAddress  = address.getAddress(QBSalesOrder.BillAddress);
                _salesOrder.ShippingAddress = address.getAddress(QBSalesOrder.ShipAddress);

                IORSalesOrderLineRetList SalesOrderItems = QBSalesOrder.ORSalesOrderLineRetList;

                if (SalesOrderItems != null)
                {
                    for (int i = 0; i <= SalesOrderItems.Count - 1; i++)
                    {
                        IORSalesOrderLineRet SalesOrderItem = SalesOrderItems.GetAt(i);

                        if (SalesOrderItem.ortype == ENORSalesOrderLineRet.orsolrSalesOrderLineRet)
                        {
                            InventoryItem inventoryItem = new InventoryItem();

                            inventoryItem.ItemCode = SalesOrderItem.SalesOrderLineRet.ItemRef.FullName.GetValue();

                            inventoryItem.Description = SalesOrderItem.SalesOrderLineRet.Desc.GetValue();

                            if (SalesOrderItem.SalesOrderLineRet.Quantity != null)
                            {
                                _salesOrder.TotalQty  += SalesOrderItem.SalesOrderLineRet.Quantity.GetValue();
                                inventoryItem.Quantity = SalesOrderItem.SalesOrderLineRet.Quantity.GetAsString();
                            }
                            else
                            {
                                inventoryItem.Quantity = "";
                            }

                            inventoryItem.Price  = SalesOrderItem.SalesOrderLineRet.ORRate.Rate.GetValue();
                            inventoryItem.Amount = SalesOrderItem.SalesOrderLineRet.Amount.GetAsString();
                            _salesOrder.InventoryItems.Add(inventoryItem);
                        }
                    }

                    //Update the items UPC and List in the sales order from itemsWithUPC list
                    //The reason is that the salesOrder items don't have these properties
                    //So we make another request to QB to get items with all properties
                    InventoryHelper inventoryHelper = new InventoryHelper(_MySessionManager);
                    _salesOrder.InventoryItems = inventoryHelper.UpdateItemUPCAndListID(_salesOrder.InventoryItems);
                }

                return(_salesOrder);
            }
            catch (Exception)
            {
                throw new Exception("Failed to read Sales Order from QuickBooks.");
            }
        }
Exemplo n.º 28
0
        ///<summary>Returns list of all active accounts.</summary>
        public static List <string> GetListOfAccounts()
        {
            List <string> accountList = new List <string>();

            try {
                OpenConnection(8, 0, PrefC.GetString(PrefName.QuickBooksCompanyFile));
                QueryListOfAccounts();
                DoRequests();
                CloseConnection();
            }
            catch (Exception e) {
                if (SessionBegun)
                {
                    SessionManager.EndSession();
                }
                if (ConnectionOpen)
                {
                    SessionManager.CloseConnection();
                }
                throw e;
            }
            if (ResponseMsgSet == null)
            {
                return(accountList);
            }
            IResponseList responseList = ResponseMsgSet.ResponseList;

            if (responseList == null)
            {
                return(accountList);
            }
            //Loop through the list to pick out the AccountQueryRs section.
            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.
                            IAccountRetList AccountRetList = (IAccountRetList)response.Detail;
                            for (int j = 0; j < AccountRetList.Count; j++)
                            {
                                IAccountRet AccountRet = AccountRetList.GetAt(j);
                                if (AccountRet.FullName != null)
                                {
                                    accountList.Add(AccountRet.FullName.GetValue());
                                }
                            }
                        }
                    }
                }
            }
            return(accountList);
        }
Exemplo n.º 29
0
    /// <summary>
    /// The GetVendorsData.
    /// </summary>
    /// <param name="logsFile">The logsFile<see cref="StreamWriter"/>.</param>
    /// <returns>The <see cref="List{dynamic}"/>.</returns>
    public List <dynamic> GetVendorsData(StreamWriter logsFile)
    {
        IMsgSetRequest requestSet = SessionManager.Instance.CreateMsgSetRequest();

        requestSet.Attributes.OnError = ENRqOnError.roeStop;
        IVendorQuery    VendorQueryRq  = requestSet.AppendVendorQueryRq();
        IMsgSetResponse responeSet     = SessionManager.Instance.DoRequests(requestSet, logsFile);
        IResponseList   responseList   = responeSet.ResponseList;
        List <dynamic>  vendorsArray   = new List <dynamic>();
        var             vendor_name    = "";
        var             vendor_balance = "";
        var             account_number = "";

        try
        {
            for (int i = 0; i < responseList.Count; i++)
            {
                IResponse response = responseList.GetAt(i);
                if (response.StatusCode == 0)
                {
                    IVendorRetList vendorsList = (IVendorRetList)response.Detail;
                    Console.WriteLine("Number Of Records Being Fetched Are:\t" + vendorsList.Count + "\n");
                    for (int j = 0; j < vendorsList.Count; j++)
                    {
                        IVendorRet vendor = vendorsList.GetAt(j);
                        if (vendor.Name != null)
                        {
                            vendor_name = vendor.Name.GetValue();
                        }
                        else
                        {
                            vendor_name = "Name Not Defined...";
                        }
                        if (vendor.Balance != null)
                        {
                            vendor_balance = vendor.Balance.GetValue().ToString();
                        }
                        else
                        {
                            vendor_balance = "Balance Not Defined...";
                        }
                        if (vendor.AccountNumber != null)
                        {
                            account_number = vendor.AccountNumber.GetValue();
                        }
                        else
                        {
                            account_number = "Account Number Not Defined...";
                        }
                        vendorsArray.Add(new string[] { vendor_name, account_number, vendor_balance });
                    }
                }
            }
        }
        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(vendorsArray);
    }
Exemplo n.º 30
0
        protected Dictionary <string, string> QuickBooksExcuet(IMsgSetRequest requestMsgSet, string externalId = null)
        {
            try
            {
                SessionManager.OpenConnection("QuickBooks Application", "QuickBooks Application");
                ConnectionOpen = true;

                SessionManager.BeginSession("", ENOpenMode.omDontCare);
                SessionBegun = true;

                IMsgSetResponse responseMsgSet = SessionManager.DoRequests(requestMsgSet);
                SessionManager.EndSession();
                SessionBegun = false;

                SessionManager.CloseConnection();
                ConnectionOpen = false;

                if (responseMsgSet != null)
                {
                    IResponseList responseList = responseMsgSet.ResponseList;
                    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)
                        {
                            var result = new Dictionary <string, string>();
                            result.Add("StatusCode", response.StatusCode + "");
                            //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.rtCustomerAddRs)
                                {
                                    //upcast to more specific type here, this is safe because we checked with response.Type check above
                                    ICustomerRet customerRet = (ICustomerRet)response.Detail;
                                    if (customerRet != null)
                                    {
                                        string newId = customerRet.ListID.GetValue();
                                        result.Add("Message", "Customer has been Added successfully");
                                        result.Add("ListID", newId);
                                        return(result);
                                    }
                                }
                                if (responseType == ENResponseType.rtCustomerModRs)
                                {
                                    ICustomerRet ItemInventoryRet = (ICustomerRet)response.Detail;
                                    if (ItemInventoryRet != null)
                                    {
                                        string newId = ItemInventoryRet.ListID.GetValue();
                                        result.Add("Message", $"Customer with Id {newId} has been updated Successfully");
                                        return(result);
                                    }
                                }
                                if (responseType == ENResponseType.rtListDelRs)
                                {
                                    IQBENListDelTypeType ListDelType = (IQBENListDelTypeType)response.Detail;
                                    result.Add("Message", $"Customer with Id {externalId} has been deleted Successfully");
                                    return(result);
                                }
                                if (responseType == ENResponseType.rtAccountQueryRs)
                                {
                                    IAccountRetList AccountRet = (IAccountRetList)response.Detail;
                                    for (int j = 0; j < AccountRet.Count; j++)
                                    {
                                        var    acc      = AccountRet.GetAt(j);
                                        string FullName = (string)acc.FullName.GetValue();
                                        result.Add("Name", FullName);
                                    }
                                }
                            }
                            else
                            {
                                result.Add("Error", response.StatusMessage);
                                return(result);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (SessionBegun)
                {
                    SessionManager.EndSession();
                }
                if (ConnectionOpen)
                {
                    SessionManager.CloseConnection();
                }
                return(new Dictionary <string, string>()
                {
                    { "Error", ex.Message }
                });
            }

            return(new Dictionary <string, string>());
        }