/// <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); }
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 <ChartOfAccount> WalkChartOfAccount(IAccountRetList Account) { if (Account == null) { return(null); } ChartOfAccountList = new List <ChartOfAccount>(); ChartOfAccount BankAccount; for (int a = 0; a < Account.Count; a++) { IAccountRet AccountRet = Account.GetAt(a); BankAccount = new ChartOfAccount(); //BankAccount.Name = (string)AccountRet.Name.GetValue(); BankAccount.FullName = (string)AccountRet.FullName.GetValue(); BankAccount.ListID = AccountRet.ListID.GetValue().ToString(); ChartOfAccountList.Add(BankAccount); } return(ChartOfAccountList); }
/// <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); }
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>()); }
///<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); }