This commit is contained in:
2022-06-24 19:43:01 +00:00
parent 976b551c43
commit 55ba8ac9ff

View File

@@ -491,8 +491,8 @@ namespace AyaNovaQBI
public static async Task<bool> InitializeQBI(StringBuilder initErrors) public static async Task<bool> InitializeQBI(StringBuilder initErrors)
{ {
//LOGIN to v8 first //LOGIN to v8 first
auth d = new auth(); auth d = new auth();
if (d.ShowDialog() == System.Windows.Forms.DialogResult.Cancel) if (d.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)
@@ -540,16 +540,16 @@ namespace AyaNovaQBI
//QB CONNECTION validation and setup //QB CONNECTION validation and setup
try try
{ {
if(await QBValidate() == pfstat.Cancel) if (await QBValidate() == pfstat.Cancel)
{ {
await IntegrationLog("PFC: Unable to validate QuickBooks connection, user selected cancel"); await IntegrationLog("PFC: Unable to validate QuickBooks connection, user selected cancel");
return false; return false;
} }
else else
{ {
await IntegrationLog($"PFC: QB Company name= {QCompanyName}, QB Country version={QCountry}, QBVersion={QVersion}, Companyfile={QCompanyFile}"); await IntegrationLog($"PFC: QB Company name= {QCompanyName}, QB Country version={QCountry}, QBVersion={QVersion}, Companyfile={QCompanyFile}");
//PFC - PopulateQBListCache() await PopulateQBListCache();
//PFC - PopulateAyaListCache() //PFC - PopulateAyaListCache()
@@ -560,13 +560,13 @@ namespace AyaNovaQBI
//DONE //DONE
} }
} }
catch(Exception ex) catch (Exception ex)
{ {
initErrors.AppendLine($"QuickBooks connection validation failed before connecting\r\n{ex.Message}"); initErrors.AppendLine($"QuickBooks connection validation failed before connecting\r\n{ex.Message}");
return false; return false;
} }
return true; return true;
@@ -766,7 +766,7 @@ namespace AyaNovaQBI
QCompanyName = ProcessQBString(cl.CompanyName); QCompanyName = ProcessQBString(cl.CompanyName);
requestSet.ClearRequests(); requestSet.ClearRequests();
//---------------- //----------------
// Close the session and connection with QuickBooks // Close the session and connection with QuickBooks
sessionManager.EndSession(); sessionManager.EndSession();
@@ -896,7 +896,14 @@ namespace AyaNovaQBI
/// <summary> /// <summary>
/// Populate or repopulate the list of /// Populate or repopulate the list of
/// </summary> /// </summary>
public static void PopulateQBListCache()
#endregion qb specific utils
#region QB API helper methods/ attributes/cached lists
/// <summary>
/// Populate or repopulate the list of
/// </summary>
public static async Task PopulateQBListCache()
{ {
//Get the cached QB data //Get the cached QB data
Waiting w = new Waiting(); Waiting w = new Waiting();
@@ -915,7 +922,7 @@ namespace AyaNovaQBI
PopulateQBClientCache(); PopulateQBClientCache();
w.Step = "Items"; w.Step = "Items";
PopulateQBItemCache(); await PopulateQBItemCache();
if (!(QVersion < 3))//qbXML 3.0 or higher (QB 2004 any country or newer) 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 /// Given a QB Item ID, return the
/// AyaNova Vendor ID linked to that items /// AyaNova Vendor ID linked to that items
/// QB preferred Vendor ID or /// QB preferred Vendor ID or
/// Guid empty on any problem or not found /// 0 on any problem or not found
/// </summary> /// </summary>
/// <param name="QBItemID"></param> /// <param name="QBItemID"></param>
/// <returns></returns> /// <returns></returns>
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); 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()); 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 //Ok we have a matching vendor in the list, return the id of it
return QBI.Maps[drVendor["ID"].ToString(), RootObjectTypes.Vendor].RootObjectID; return item.Id;
} }
@@ -987,7 +995,7 @@ namespace AyaNovaQBI
/// Populate the cached qb data /// Populate the cached qb data
/// billable /// billable
/// </summary> /// </summary>
private static void PopulateQBItemCache() private async static Task PopulateQBItemCache()
{ {
if (_dtQBItems == null) 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 //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) 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) catch (Exception ex)
{ {
await IntegrationLog( "PopulateQBItems: Failed with exception:" + ex.Message); await IntegrationLog("PopulateQBItems: Failed with exception:" + ex.Message);
if (booSessionBegun) if (booSessionBegun)
{ {
sessionManager.EndSession(); sessionManager.EndSession();
@@ -1372,7 +1380,7 @@ namespace AyaNovaQBI
#endregion quickbooks items #endregion quickbooks items
#region QuickBooks "Transactionclasses" #region QuickBooks "Transactionclasses"
public static string TRANSACTION_CLASS_NO_CLASS_SELECTED = "<GZNOCLASS>";
private static DataTable _dtQBClasses = null; private static DataTable _dtQBClasses = null;
@@ -1489,7 +1497,7 @@ namespace AyaNovaQBI
} }
catch (Exception ex) catch (Exception ex)
{ {
await IntegrationLog( "PopulateQBClasses: Failed with exception:" + ex.Message); await IntegrationLog("PopulateQBClasses: Failed with exception:" + ex.Message);
if (booSessionBegun) if (booSessionBegun)
{ {
sessionManager.EndSession(); sessionManager.EndSession();
@@ -1632,7 +1640,7 @@ namespace AyaNovaQBI
catch (Exception ex) catch (Exception ex)
{ {
await IntegrationLog( "PopulateQBInvoiceTemplates: Failed with exception:" + ex.Message); await IntegrationLog("PopulateQBInvoiceTemplates: Failed with exception:" + ex.Message);
if (booSessionBegun) if (booSessionBegun)
{ {
sessionManager.EndSession(); sessionManager.EndSession();
@@ -1723,7 +1731,7 @@ namespace AyaNovaQBI
} }
catch (Exception ex) catch (Exception ex)
{ {
await IntegrationLog( "GetClientEditSequence: Failed with exception:" + ex.Message); await IntegrationLog("GetClientEditSequence: Failed with exception:" + ex.Message);
if (booSessionBegun) if (booSessionBegun)
{ {
sessionManager.EndSession(); sessionManager.EndSession();
@@ -1906,7 +1914,7 @@ namespace AyaNovaQBI
} }
catch (Exception ex) catch (Exception ex)
{ {
await IntegrationLog( "PopulateQBClients: Failed with exception:" + ex.Message); await IntegrationLog("PopulateQBClients: Failed with exception:" + ex.Message);
if (booSessionBegun) if (booSessionBegun)
{ {
sessionManager.EndSession(); sessionManager.EndSession();
@@ -1973,16 +1981,7 @@ namespace AyaNovaQBI
return b; return b;
} }
/// <summary>
/// Handle null qb string types with "aplomb" :)
/// </summary>
/// <param name="qs"></param>
/// <returns></returns>
private static string ProcessQBString(IQBStringType qs)
{
if (qs == null) return "";
return qs.GetValue();
}
#endregion quickbooks transaction Clients #endregion quickbooks transaction Clients
@@ -2135,7 +2134,7 @@ namespace AyaNovaQBI
} }
catch (Exception ex) catch (Exception ex)
{ {
await IntegrationLog( "PopulateQBVendors: Failed with exception:" + ex.Message); await IntegrationLog("PopulateQBVendors: Failed with exception:" + ex.Message);
if (booSessionBegun) if (booSessionBegun)
{ {
sessionManager.EndSession(); sessionManager.EndSession();
@@ -2268,7 +2267,7 @@ namespace AyaNovaQBI
} }
catch (Exception ex) catch (Exception ex)
{ {
await IntegrationLog( "PopulateQBAccounts: Failed with exception:" + ex.Message); await IntegrationLog("PopulateQBAccounts: Failed with exception:" + ex.Message);
if (booSessionBegun) if (booSessionBegun)
{ {
sessionManager.EndSession(); sessionManager.EndSession();
@@ -2398,7 +2397,7 @@ namespace AyaNovaQBI
} }
catch (Exception ex) catch (Exception ex)
{ {
await IntegrationLog( "PopulateQBTerms: Failed with exception:" + ex.Message); await IntegrationLog("PopulateQBTerms: Failed with exception:" + ex.Message);
if (booSessionBegun) if (booSessionBegun)
{ {
sessionManager.EndSession(); sessionManager.EndSession();