From 5daab676b5988d18896341f740cff92f9ca611c1 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Mon, 4 Jul 2022 00:12:42 +0000 Subject: [PATCH] --- AyaNovaQBI/Map.cs | 148 ++++++++++++++++++++++++++++++++++++++++++++- AyaNovaQBI/util.cs | 30 ++++++++- 2 files changed, 174 insertions(+), 4 deletions(-) diff --git a/AyaNovaQBI/Map.cs b/AyaNovaQBI/Map.cs index 10bc438..94a8205 100644 --- a/AyaNovaQBI/Map.cs +++ b/AyaNovaQBI/Map.cs @@ -69,10 +69,154 @@ namespace AyaNovaQBI #endregion import #region AUTOMATIC LINK - private void autoLinkToolStripMenuItem_Click(object sender, EventArgs e) + private async void autoLinkToolStripMenuItem_Click(object sender, EventArgs e) { + //Loop through the current AyaNova list + //foreach unlinked item + // loop through the qb current list and if any names match then + // Link the two + bool SaveIntegration = false; + + Waiting w = new Waiting(); + w.Show(); + w.Ops = "Autolinking matching items..."; + try + { + + switch (_Type) + { + + case AyaType.Customer: + foreach (var i in util.AyaClientList) + { + if (i.Active) + { + IntegrationItem m = util.QBIntegration.Items.FirstOrDefault(z => z.ObjectId == i.Id && z.AType == _Type); + if (m == null) + { + foreach (DataRow dr in util.QBClients.Rows) + { + if (i.Name == dr["FullName"].ToString()) + { + w.Step = i.Name; + m = new IntegrationItem { AType = _Type, IntegrationItemName = i.Name, IntegrationItemId = dr["ID"].ToString(), LastSync = System.DateTime.Now, ObjectId = i.Id }; + util.QBIntegration.Items.Add(m); + SaveIntegration = true; + } + } + } + } + } + break; + case AyaType.Vendor: + foreach (var i in util.AyaVendorList) + { + if (i.Active) + { + IntegrationItem m = util.QBIntegration.Items.FirstOrDefault(z => z.ObjectId == i.Id && z.AType == _Type); + if (m == null) + { + foreach (DataRow dr in util.QBVendors.Rows) + { + if (i.Name == dr["FullName"].ToString()) + { + w.Step = i.Name; + m = new IntegrationItem { AType = _Type, IntegrationItemName = i.Name, IntegrationItemId = dr["ID"].ToString(), LastSync = System.DateTime.Now, ObjectId = i.Id }; + util.QBIntegration.Items.Add(m); + SaveIntegration = true; + } + } + } + } + } + break; + case AyaType.ServiceRate: + foreach (var i in util.AyaServiceRateList) + { + if (i.Active) + { + IntegrationItem m = util.QBIntegration.Items.FirstOrDefault(z => z.ObjectId == i.Id && z.AType == _Type); + if (m == null) + { + foreach (DataRow dr in util.QBItems.Rows) + { + if (i.Name == dr["FullName"].ToString()) + { + w.Step = i.Name; + m = new IntegrationItem { AType = _Type, IntegrationItemName = i.Name, IntegrationItemId = dr["ID"].ToString(), LastSync = System.DateTime.Now, ObjectId = i.Id }; + util.QBIntegration.Items.Add(m); + SaveIntegration = true; + } + } + } + } + } + break; + case AyaType.TravelRate: + foreach (var i in util.AyaServiceRateList) + { + if (i.Active) + { + IntegrationItem m = util.QBIntegration.Items.FirstOrDefault(z => z.ObjectId == i.Id && z.AType == _Type); + if (m == null) + { + foreach (DataRow dr in util.QBItems.Rows) + { + if (i.Name == dr["FullName"].ToString()) + { + w.Step = i.Name; + m = new IntegrationItem { AType = _Type, IntegrationItemName = i.Name, IntegrationItemId = dr["ID"].ToString(), LastSync = System.DateTime.Now, ObjectId = i.Id }; + util.QBIntegration.Items.Add(m); + SaveIntegration = true; + } + } + } + } + } + break; + case AyaType.Part: + foreach (var i in util.AyaPartList) + { + if (i.Active) + { + IntegrationItem m = util.QBIntegration.Items.FirstOrDefault(z => z.ObjectId == i.Id && z.AType == _Type); + if (m == null) + { + foreach (DataRow dr in util.QBItems.Rows) + { + if (i.Name == dr["FullName"].ToString()) + { + w.Step = i.Name; + m = new IntegrationItem { AType = _Type, IntegrationItemName = i.Name, IntegrationItemId = dr["ID"].ToString(), LastSync = System.DateTime.Now, ObjectId = i.Id }; + util.QBIntegration.Items.Add(m); + SaveIntegration = true; + } + } + } + } + } + break; + + } + w.Visible = false; + if (SaveIntegration) + { + await util.SaveIntegrationObject(); + Initialize(); + } + } + catch (Exception ex) + { + w.Visible = false; + await util.CrackDisplayAndIntegrationLogException(ex, "QBI:Map:AutoLink");//case 3717 + } + finally + { + w.Close(); + } } + #endregion auto link #region LINK MANUALLY @@ -582,6 +726,6 @@ namespace AyaNovaQBI #endregion utility stuff - + } } diff --git a/AyaNovaQBI/util.cs b/AyaNovaQBI/util.cs index 2d493a8..e0dcd7f 100644 --- a/AyaNovaQBI/util.cs +++ b/AyaNovaQBI/util.cs @@ -3171,7 +3171,7 @@ namespace AyaNovaQBI public static async Task PopulateAyaClientList() { - var a = await PostAsync("pick-list/list/", $"{{\"ayaType\":{(int)AyaType.Customer}}}"); + var a = await GetAsync("customer/accounting-list"); _clientlist = a.ObjectResponse["data"].ToObject>(); } @@ -3193,7 +3193,7 @@ namespace AyaNovaQBI public static async Task PopulateAyaVendorList() { - var a = await PostAsync("pick-list/list/", $"{{\"ayaType\":{(int)AyaType.Vendor}}}"); + var a = await GetAsync("vendor/accounting-list"); _vendorlist = a.ObjectResponse["data"].ToObject>(); } @@ -3314,6 +3314,32 @@ namespace AyaNovaQBI #endregion ayanova cached lists + #region Exception helper + + public static string CrackException(Exception ex) + { + while (ex.InnerException != null) + { + ex = ex.InnerException; + } + return ex.Message + "\r\n-------TRACE------\r\n" + ex.StackTrace; + } + + + //case 3717 + public static async Task CrackDisplayAndIntegrationLogException(Exception ex, string methodText = "n/a", string extraText = "n/a") + { + + string message = "Exception error\r\nMethod: " + methodText + "\r\nExtra: " + extraText + "\r\n Error:" + CrackException(ex); + //Log it so we have it forever in the log + await IntegrationLog(message); + //display it to the user + CopyableMessageBox cb = new CopyableMessageBox(message); + cb.ShowDialog(); + } + + #endregion exception helper + #endregion qb specific non-api stuff