This commit is contained in:
2022-07-04 00:12:42 +00:00
parent 21bb11e68a
commit 5daab676b5
2 changed files with 174 additions and 4 deletions

View File

@@ -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

View File

@@ -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<List<NameIdActiveItem>>();
}
@@ -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<List<NameIdActiveItem>>();
}
@@ -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