From 55ba8ac9ff03a1c8b6bac318ad58f1c3277d11ed Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Fri, 24 Jun 2022 19:43:01 +0000 Subject: [PATCH] --- AyaNovaQBI/util.cs | 79 +++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 40 deletions(-) diff --git a/AyaNovaQBI/util.cs b/AyaNovaQBI/util.cs index 45f32d7..f6b1240 100644 --- a/AyaNovaQBI/util.cs +++ b/AyaNovaQBI/util.cs @@ -491,8 +491,8 @@ namespace AyaNovaQBI public static async Task InitializeQBI(StringBuilder initErrors) - { - + { + //LOGIN to v8 first auth d = new auth(); if (d.ShowDialog() == System.Windows.Forms.DialogResult.Cancel) @@ -540,16 +540,16 @@ namespace AyaNovaQBI //QB CONNECTION validation and setup try - { - if(await QBValidate() == pfstat.Cancel) + { + if (await QBValidate() == pfstat.Cancel) { await IntegrationLog("PFC: Unable to validate QuickBooks connection, user selected cancel"); return false; } else { - await IntegrationLog($"PFC: QB Company name= {QCompanyName}, QB Country version={QCountry}, QBVersion={QVersion}, Companyfile={QCompanyFile}"); - //PFC - PopulateQBListCache() + await IntegrationLog($"PFC: QB Company name= {QCompanyName}, QB Country version={QCountry}, QBVersion={QVersion}, Companyfile={QCompanyFile}"); + await PopulateQBListCache(); //PFC - PopulateAyaListCache() @@ -560,13 +560,13 @@ namespace AyaNovaQBI //DONE } } - catch(Exception ex) + catch (Exception ex) { initErrors.AppendLine($"QuickBooks connection validation failed before connecting\r\n{ex.Message}"); return false; } - + return true; @@ -766,7 +766,7 @@ namespace AyaNovaQBI QCompanyName = ProcessQBString(cl.CompanyName); requestSet.ClearRequests(); //---------------- - + // Close the session and connection with QuickBooks sessionManager.EndSession(); @@ -896,7 +896,14 @@ namespace AyaNovaQBI /// /// Populate or repopulate the list of /// - public static void PopulateQBListCache() + + #endregion qb specific utils + + #region QB API helper methods/ attributes/cached lists + /// + /// Populate or repopulate the list of + /// + public static async Task PopulateQBListCache() { //Get the cached QB data Waiting w = new Waiting(); @@ -915,7 +922,7 @@ namespace AyaNovaQBI PopulateQBClientCache(); w.Step = "Items"; - PopulateQBItemCache(); + await PopulateQBItemCache(); if (!(QVersion < 3))//qbXML 3.0 or higher (QB 2004 any country or newer) { @@ -963,23 +970,24 @@ namespace AyaNovaQBI /// Given a QB Item ID, return the /// AyaNova Vendor ID linked to that items /// QB preferred Vendor ID or - /// Guid empty on any problem or not found + /// 0 on any problem or not found /// /// /// - public static Guid AyaVendorForQBItem(string QBItemID) + public static long AyaVendorForQBItem(string QBItemID) { - if (QBItemID == null || QBItemID == "") return Guid.Empty; + if (string.IsNullOrWhiteSpace(QBItemID)) return 0; DataRow dr = _dtQBItems.Rows.Find(QBItemID); - if (dr == null || dr["VendorID"] == null || dr["VendorID"].ToString() == "") return Guid.Empty; + if (dr == null || dr["VendorID"] == null || dr["VendorID"].ToString() == "") return 0; DataRow drVendor = _dtQBVendors.Rows.Find(dr["VendorID"].ToString()); - if (drVendor == null) return Guid.Empty; + if (drVendor == null) return 0; - if (!QBI.Maps.Contains(drVendor["ID"].ToString(), RootObjectTypes.Vendor)) return Guid.Empty; + var item = QBIntegration.Items.FirstOrDefault(z => z.IntegrationItemId == drVendor["ID"].ToString()); + if (item == null) return 0; - //Ok we have a matching vendor in the list, return the guid of it - return QBI.Maps[drVendor["ID"].ToString(), RootObjectTypes.Vendor].RootObjectID; + //Ok we have a matching vendor in the list, return the id of it + return item.Id; } @@ -987,7 +995,7 @@ namespace AyaNovaQBI /// Populate the cached qb data /// billable /// - private static void PopulateQBItemCache() + private async static Task PopulateQBItemCache() { if (_dtQBItems == null) { @@ -1059,7 +1067,7 @@ namespace AyaNovaQBI //Added: 21-June-2006 nonzero status codes 500 and higher are serious errors, less than 500 could just mean no matching items in list if (response.StatusCode > 499) { - throw new ApplicationException(response.StatusMessage + " Code: " + response.StatusCode); + throw new ApplicationException($"{response.StatusMessage} Code: {response.StatusCode}"); } @@ -1187,7 +1195,7 @@ namespace AyaNovaQBI } catch (Exception ex) { - await IntegrationLog( "PopulateQBItems: Failed with exception:" + ex.Message); + await IntegrationLog("PopulateQBItems: Failed with exception:" + ex.Message); if (booSessionBegun) { sessionManager.EndSession(); @@ -1372,7 +1380,7 @@ namespace AyaNovaQBI #endregion quickbooks items #region QuickBooks "Transactionclasses" - + public static string TRANSACTION_CLASS_NO_CLASS_SELECTED = ""; private static DataTable _dtQBClasses = null; @@ -1489,7 +1497,7 @@ namespace AyaNovaQBI } catch (Exception ex) { - await IntegrationLog( "PopulateQBClasses: Failed with exception:" + ex.Message); + await IntegrationLog("PopulateQBClasses: Failed with exception:" + ex.Message); if (booSessionBegun) { sessionManager.EndSession(); @@ -1632,7 +1640,7 @@ namespace AyaNovaQBI catch (Exception ex) { - await IntegrationLog( "PopulateQBInvoiceTemplates: Failed with exception:" + ex.Message); + await IntegrationLog("PopulateQBInvoiceTemplates: Failed with exception:" + ex.Message); if (booSessionBegun) { sessionManager.EndSession(); @@ -1723,7 +1731,7 @@ namespace AyaNovaQBI } catch (Exception ex) { - await IntegrationLog( "GetClientEditSequence: Failed with exception:" + ex.Message); + await IntegrationLog("GetClientEditSequence: Failed with exception:" + ex.Message); if (booSessionBegun) { sessionManager.EndSession(); @@ -1906,7 +1914,7 @@ namespace AyaNovaQBI } catch (Exception ex) { - await IntegrationLog( "PopulateQBClients: Failed with exception:" + ex.Message); + await IntegrationLog("PopulateQBClients: Failed with exception:" + ex.Message); if (booSessionBegun) { sessionManager.EndSession(); @@ -1973,16 +1981,7 @@ namespace AyaNovaQBI return b; } - /// - /// Handle null qb string types with "aplomb" :) - /// - /// - /// - private static string ProcessQBString(IQBStringType qs) - { - if (qs == null) return ""; - return qs.GetValue(); - } + #endregion quickbooks transaction Clients @@ -2135,7 +2134,7 @@ namespace AyaNovaQBI } catch (Exception ex) { - await IntegrationLog( "PopulateQBVendors: Failed with exception:" + ex.Message); + await IntegrationLog("PopulateQBVendors: Failed with exception:" + ex.Message); if (booSessionBegun) { sessionManager.EndSession(); @@ -2268,7 +2267,7 @@ namespace AyaNovaQBI } catch (Exception ex) { - await IntegrationLog( "PopulateQBAccounts: Failed with exception:" + ex.Message); + await IntegrationLog("PopulateQBAccounts: Failed with exception:" + ex.Message); if (booSessionBegun) { sessionManager.EndSession(); @@ -2398,7 +2397,7 @@ namespace AyaNovaQBI } catch (Exception ex) { - await IntegrationLog( "PopulateQBTerms: Failed with exception:" + ex.Message); + await IntegrationLog("PopulateQBTerms: Failed with exception:" + ex.Message); if (booSessionBegun) { sessionManager.EndSession();