Ejemplo n.º 1
0
        /// <summary>
        /// Obtain a list of all QuickBooks accounts.
        /// </summary>
        /// <returns>a list of quickbooks accounts</returns>
        private List <QuickbooksAccount> getAccounts(ENAccountType type)
        {
            List <QuickbooksAccount> account    = new List <QuickbooksAccount>();
            IMsgSetRequest           msgRequest = qbMgr.CreateMsgSetRequest("US", 4, 0);

            msgRequest.Attributes.OnError = ENRqOnError.roeStop;
            IAccountQuery query = msgRequest.AppendAccountQueryRq();

            query.ORAccountListQuery.AccountListFilter.AccountTypeList.Add(type);
            IMsgSetResponse response   = qbMgr.DoRequests(msgRequest);
            IAccountRetList qbAccounts = (IAccountRetList)response.ResponseList.GetAt(0).Detail;


            for (int i = 0; qbAccounts != null && i < qbAccounts.Count; i++)
            {
                account.Add(new QuickbooksAccount()
                {
                    Name = qbAccounts.GetAt(i).FullName.GetValue()
                });
            }

            return(account);
        }
Ejemplo n.º 2
0
        void WalkAccountRet(IAccountRet AccountRet)
        {
            if (AccountRet == null)
            {
                return;
            }
            //Go through all the elements of IAccountRetList
            //Get value of ListID
            string ListID436 = (string)AccountRet.ListID.GetValue();
            // Get value of TimeCreated
            DateTime TimeCreated437 = (DateTime)AccountRet.TimeCreated.GetValue();
            //Get value of TimeModified
            DateTime TimeModified438 = (DateTime)AccountRet.TimeModified.GetValue();
            //Get value of EditSequence
            string EditSequence439 = (string)AccountRet.EditSequence.GetValue();
            //Get value of Name
            string Name440 = (string)AccountRet.Name.GetValue();
            // Get value of FullName
            string FullName441 = (string)AccountRet.FullName.GetValue();

            // Get value of IsActive
            if (AccountRet.IsActive != null)
            {
                bool IsActive442 = (bool)AccountRet.IsActive.GetValue();
            }
            if (AccountRet.ParentRef != null)
            {
                //  Get value of ListID
                if (AccountRet.ParentRef.ListID != null)
                {
                    string ListID443 = (string)AccountRet.ParentRef.ListID.GetValue();
                }
                //  Get value of FullName
                if (AccountRet.ParentRef.FullName != null)
                {
                    string FullName444 = (string)AccountRet.ParentRef.FullName.GetValue();
                }
            }
            // Get value of Sublevel
            int Sublevel445 = (int)AccountRet.Sublevel.GetValue();
            // Get value of AccountType
            ENAccountType AccountType446 = (ENAccountType)AccountRet.AccountType.GetValue();

            // Get value of SpecialAccountType
            if (AccountRet.SpecialAccountType != null)
            {
                ENSpecialAccountType SpecialAccountType447 = (ENSpecialAccountType)AccountRet.SpecialAccountType.GetValue();
            }
            // Get value of IsTaxAccount
            if (AccountRet.IsTaxAccount != null)
            {
                bool IsTaxAccount448 = (bool)AccountRet.IsTaxAccount.GetValue();
            }
            // Get value of AccountNumber
            if (AccountRet.AccountNumber != null)
            {
                string AccountNumber449 = (string)AccountRet.AccountNumber.GetValue();
            }
            // Get value of BankNumber
            if (AccountRet.BankNumber != null)
            {
                string BankNumber450 = (string)AccountRet.BankNumber.GetValue();
            }
            // Get value of Desc
            if (AccountRet.Desc != null)
            {
                string Desc451 = (string)AccountRet.Desc.GetValue();
            }
            // Get value of Balance
            if (AccountRet.Balance != null)
            {
                double Balance452 = (double)AccountRet.Balance.GetValue();
            }
            // Get value of TotalBalance
            if (AccountRet.TotalBalance != null)
            {
                double TotalBalance453 = (double)AccountRet.TotalBalance.GetValue();
            }
            if (AccountRet.SalesTaxCodeRef != null)
            {
                // Get value of ListID
                if (AccountRet.SalesTaxCodeRef.ListID != null)
                {
                    string ListID454 = (string)AccountRet.SalesTaxCodeRef.ListID.GetValue();
                }
                // Get value of FullName
                if (AccountRet.SalesTaxCodeRef.FullName != null)
                {
                    string FullName455 = (string)AccountRet.SalesTaxCodeRef.FullName.GetValue();
                }
            }
            if (AccountRet.TaxLineInfoRet != null)
            {
                // Get value of TaxLineID
                int TaxLineID456 = (int)AccountRet.TaxLineInfoRet.TaxLineID.GetValue();
                //Get value of TaxLineName
                if (AccountRet.TaxLineInfoRet.TaxLineName != null)
                {
                    string TaxLineName457 = (string)AccountRet.TaxLineInfoRet.TaxLineName.GetValue();
                }
            }
            //Get value of CashFlowClassification
            if (AccountRet.CashFlowClassification != null)
            {
                ENCashFlowClassification CashFlowClassification458 = (ENCashFlowClassification)AccountRet.CashFlowClassification.GetValue();
            }
            if (AccountRet.CurrencyRef != null)
            {
                // Get value of ListID
                if (AccountRet.CurrencyRef.ListID != null)
                {
                    string ListID459 = (string)AccountRet.CurrencyRef.ListID.GetValue();
                }
                // Get value of FullName
                if (AccountRet.CurrencyRef.FullName != null)
                {
                    string FullName460 = (string)AccountRet.CurrencyRef.FullName.GetValue();
                }
            }
            if (AccountRet.DataExtRetList != null)
            {
                /*for (int i461 = 0; i461 < AccountRet.DataExtRetList.Count; i461++)
                 * {
                 *  IDataExtRet DataExtRet = AccountRet.DataExtRetList.GetAt(i461);
                 *  Get value of OwnerID
                 *  if (DataExtRet.OwnerID != null)
                 *  {
                 *      string OwnerID462 = (string)DataExtRet.OwnerID.GetValue();
                 *  }
                 *  Get value of DataExtName
                 *  string DataExtName463 = (string)DataExtRet.DataExtName.GetValue();
                 *  Get value of DataExtType
                 *  ENDataExtType DataExtType464 = (ENDataExtType)DataExtRet.DataExtType.GetValue();
                 *  Get value of DataExtValue
                 *  string DataExtValue465 = (string)DataExtRet.DataExtValue.GetValue();
                 * }*/
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Obtain a list of all QuickBooks accounts.
        /// </summary>
        /// <returns>a list of quickbooks accounts</returns>
        private List<QuickbooksAccount> getAccounts(ENAccountType type)
        {
            List<QuickbooksAccount> account = new List<QuickbooksAccount>();
            IMsgSetRequest msgRequest = qbMgr.CreateMsgSetRequest("US", 4, 0);
            msgRequest.Attributes.OnError = ENRqOnError.roeStop;
            IAccountQuery query = msgRequest.AppendAccountQueryRq();
            query.ORAccountListQuery.AccountListFilter.AccountTypeList.Add(type);
            IMsgSetResponse response = qbMgr.DoRequests(msgRequest);
            IAccountRetList qbAccounts = (IAccountRetList)response.ResponseList.GetAt(0).Detail;

            for (int i = 0; qbAccounts != null && i < qbAccounts.Count; i++)
                account.Add(new QuickbooksAccount() { Name = qbAccounts.GetAt(i).FullName.GetValue() });

            return account;
        }
Ejemplo n.º 4
0
        public static IAccountRetList QBGetChartOfAccountAccount(ENAccountType enAccountType)
        {
            bool boolSessionBegun = false;
            QBSessionManager sessionManager = new QBSessionManager();
            IAccountRetList accountRetList;
            try
            {
                IMsgSetRequest requestMsgSet;
                IMsgSetResponse responseMsgSet;
                sessionManager.OpenConnection("", _appName);
                sessionManager.BeginSession(qdbpath, ENOpenMode.omDontCare);
                boolSessionBegun = true;
                requestMsgSet = GetLatestMsgSetRequest(sessionManager);
                requestMsgSet.Attributes.OnError = ENRqOnError.roeStop;
                
                IAccountQuery accQ = requestMsgSet.AppendAccountQueryRq();
                accQ.ORAccountListQuery.AccountListFilter.AccountTypeList.Add(enAccountType);
                responseMsgSet = sessionManager.DoRequests(requestMsgSet);

                IResponse response = responseMsgSet.ResponseList.GetAt(0);
                accountRetList = response.Detail as IAccountRetList;
                
                sessionManager.EndSession();
                boolSessionBegun = false;
                sessionManager.CloseConnection();
            }
            catch (Exception ex)
            {
                if (boolSessionBegun)
                {
                    sessionManager.EndSession();
                    sessionManager.CloseConnection();
                }
                string error = (ex.Message.ToString() + "\nStack Trace: \n" + ex.StackTrace + "\nExiting the application");
                Log(error);
                int attemp = 0;
                if (ex.Message.Contains("Object reference not set to an instance of an object") && attemp < 3)
                {
                    QBGetChartOfAccountAccount(enAccountType);
                    attemp++;
                }
                else
                {
                    MessageBox.Show(ex.Message);
                }
                return null;

            }
            return accountRetList;
        }
Ejemplo n.º 5
0
        internal static IAccountRet QBAddAccount(string accountName, bool isActive, ENAccountType accountType, string accountNumber)
        {
            bool boolSessionBegun = false;
            QBSessionManager sessionManager = new QBSessionManager();
            try
            {
                IMsgSetRequest requestMsgSet;
                IMsgSetResponse responseMsgSet;
                sessionManager.OpenConnection("", _appName);
                sessionManager.BeginSession(qdbpath, ENOpenMode.omDontCare);
                boolSessionBegun = true;
                requestMsgSet = GetLatestMsgSetRequest(sessionManager);
                requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;

                string errecid = "{" + Guid.NewGuid().ToString() + "}";
                sessionManager.ErrorRecoveryID.SetValue(errecid);

                sessionManager.EnableErrorRecovery = true;

                sessionManager.SaveAllMsgSetRequestInfo = true;

                #region error recovery

                if (sessionManager.IsErrorRecoveryInfo())
                {
                    IMsgSetRequest reqMsgSet = null;
                    IMsgSetResponse resMsgSet = null;
                    resMsgSet = sessionManager.GetErrorRecoveryStatus();
                    if (resMsgSet.Attributes.MessageSetStatusCode.Equals("600"))
                    {
                        MessageBox.Show(
                            "The oldMessageSetID does not match any stored IDs, and no newMessageSetID is provided.");
                    }
                    else if (resMsgSet.Attributes.MessageSetStatusCode.Equals("9001"))
                    {
                        MessageBox.Show(
                            "Invalid checksum. The newMessageSetID specified, matches the currently stored ID, but checksum fails.");
                    }
                    else if (resMsgSet.Attributes.MessageSetStatusCode.Equals("9002"))
                    {
                        MessageBox.Show("No stored response was found.");
                    }
                    else if (resMsgSet.Attributes.MessageSetStatusCode.Equals("9004"))
                    {
                        MessageBox.Show("Invalid MessageSetID, greater than 24 character was given.");
                    }
                    else if (resMsgSet.Attributes.MessageSetStatusCode.Equals("9005"))
                    {
                        MessageBox.Show("Unable to store response.");
                    }
                    else
                    {
                        IResponse res = resMsgSet.ResponseList.GetAt(0);
                        int sCode = res.StatusCode;
                        if (sCode == 0)
                        {
                            MessageBox.Show("Last request was processed and customer was added successfully!");
                        }
                        else if (sCode > 0)
                        {
                            MessageBox.Show("There was a warning but last request was processed successfully!");
                        }
                        else
                        {
                            MessageBox.Show("It seems that there was an error in processing last request");
                            reqMsgSet = sessionManager.GetSavedMsgSetRequest();
                            resMsgSet = sessionManager.DoRequests(reqMsgSet);
                            IResponse resp = resMsgSet.ResponseList.GetAt(0);
                            int statCode = resp.StatusCode;
                            if (statCode == 0)
                            {
                                string resStr = null;
                                ICustomerRet custRet = resp.Detail as ICustomerRet;
                                resStr = resStr + "Following customer has been successfully submitted to QuickBooks:\n\n\n";
                                if (custRet.ListID != null)
                                {
                                    resStr = resStr + "ListID Number = " + Convert.ToString(custRet.ListID.GetValue()) +
                                             "\n";
                                }
                                Log(QBCRUDEAction.ErrorRecovery, "SalesReceipt", (custRet == null ? "" : custRet.FullName.GetValue()), resp);
                            }
                        }
                    }

                    sessionManager.ClearErrorRecovery();
                    //MessageBox.Show("Proceeding with current transaction.");
                }

                #endregion

                IAccountRet existingQB = GetAccountByNameFilter(accountName);
                IAccountRet accountRet = null;
                if (existingQB == null)
                {
                    IAccountAdd accountAddRq = requestMsgSet.AppendAccountAddRq();
                    accountAddRq.Name.SetValue(accountName);
                    accountAddRq.AccountType.SetValue(accountType);
                    accountAddRq.AccountNumber.SetValue(accountNumber);
                    accountAddRq.IsActive.SetValue(isActive);

                    responseMsgSet = sessionManager.DoRequests(requestMsgSet);
                    IResponse response = responseMsgSet.ResponseList.GetAt(0);
                    int statusCode = response.StatusCode;

                    accountRet = response.Detail as IAccountRet;
                    if (statusCode == 0)
                    {
                        Console.WriteLine("Success");
                    }
                    else if (statusCode == 3100)
                    {
                        MessageBox.Show("Account with same name exists");
                    }
                    Log(QBCRUDEAction.Add, "Account", (accountRet == null ? "" : accountRet.FullName.GetValue()), response);
                    return accountRet;
                }
                else
                {
                    IAccountMod customerModRq = requestMsgSet.AppendAccountModRq();
                    customerModRq.Name.SetValue(accountName);
                    customerModRq.IsActive.SetValue(isActive);
                    customerModRq.AccountType.SetValue(accountType);
                    customerModRq.AccountNumber.SetValue(accountNumber);
                    customerModRq.ListID.SetValue(existingQB.ListID.GetValue());
                    customerModRq.EditSequence.SetValue(existingQB.EditSequence.GetValue());
                    responseMsgSet = sessionManager.DoRequests(requestMsgSet);
                    IResponse response = responseMsgSet.ResponseList.GetAt(0);
                    int statusCode = response.StatusCode;
                    accountRet = response.Detail as IAccountRet;
                    if (statusCode == 0)
                    {
                        Console.WriteLine("Success");
                    }
                    Log(QBCRUDEAction.Update, "Account", (accountRet == null ? "" : accountRet.FullName.GetValue()), response);
                }

                sessionManager.ClearErrorRecovery();
                sessionManager.EndSession();
                boolSessionBegun = false;
                sessionManager.CloseConnection();
                return accountRet;
            }
            catch (Exception ex)
            {

                if (boolSessionBegun)
                {
                    sessionManager.EndSession();
                    sessionManager.CloseConnection();
                }
                string error = (ex.Message.ToString() + "\nStack Trace: \n" + ex.StackTrace + "\nExiting the application");
                Log(error);
                MessageBox.Show(error);
              //  throw new Exception(ex.Message);

            }
            return null;
        }