This commit is contained in:
@@ -67,7 +67,7 @@ namespace AyaNovaQBI
|
||||
|
||||
}
|
||||
|
||||
private void linkSelectedItemsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
private async void linkSelectedItemsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
bool IsAyaGrid = false;
|
||||
if (gridAya.SelectedRows.Count == 0 && gridQB.SelectedRows.Count == 0) return;
|
||||
@@ -89,76 +89,71 @@ namespace AyaNovaQBI
|
||||
s.Dispose();
|
||||
var selectedAyaNovaIds = new List<long>();
|
||||
StringBuilder selectedAyaNovaNames = new StringBuilder();
|
||||
|
||||
|
||||
foreach (DataGridViewRow r in gridAya.SelectedRows)
|
||||
{
|
||||
selectedAyaNovaNames.AppendLine(r.Cells[0].Value.ToString());
|
||||
selectedAyaNovaIds.Add((long)r.Cells[1].Value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//#################################
|
||||
//LINKING
|
||||
|
||||
LinkAyaObjectToQBConfirm d = new LinkAyaObjectToQBConfirm();
|
||||
d.QBItem = QBItemName;
|
||||
d.QBItem = QBItemName;
|
||||
d.AyaItems = selectedAyaNovaNames.ToString();
|
||||
if (d.ShowDialog() != DialogResult.OK)
|
||||
if (d.ShowDialog() != DialogResult.OK)
|
||||
return;
|
||||
|
||||
|
||||
|
||||
////ok, link away...
|
||||
//foreach (object o in moveData.Rows)
|
||||
//{
|
||||
// //qb listid
|
||||
// string dropID = rowdrop.Cells["ID"].Value.ToString();
|
||||
// string dropName = rowdrop.Cells["Name"].Value.ToString();
|
||||
// IntegrationMap m = null;
|
||||
// //Is AyaNova object already mapped?
|
||||
// if (Util.QBI.Maps.Contains(((AyaNameID)o).ID))
|
||||
// {
|
||||
// //Get the mapping
|
||||
// m = Util.QBI.Maps[((AyaNameID)o).ID];
|
||||
|
||||
// //Is it already linked to the selected qb object?
|
||||
|
||||
// //Yes so do nothing and continue on to the next object
|
||||
// if (m.ForeignID == dropID)
|
||||
// continue;
|
||||
// else
|
||||
// {
|
||||
|
||||
// //No, AyaNova object was mapped elsewhere, prompt user if this is ok
|
||||
// if (MessageBox.Show(
|
||||
// "AyaNova object: " + ((AyaNameID)o).Name + "\r\n" +
|
||||
// "Is already linked to QuickBooks object: " + m.Name + "\r\n" +
|
||||
// "Do you really want to change the link to the QuickBooks object: " + dropName + "\r\n",
|
||||
// "Change link?", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
|
||||
// == DialogResult.No) continue;
|
||||
|
||||
// }
|
||||
|
||||
// //If we're here it's because the object is already mapped
|
||||
// //but the users has signified they want to change the map to another object so...
|
||||
// m.ForeignID = dropID;
|
||||
// m.Name = rowdrop.Cells["Name"].Value.ToString();
|
||||
// m.LastSync = System.DateTime.Now;
|
||||
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// //not already present, so add it, easy peasy...
|
||||
// m = Util.QBI.Maps.Add(Util.QBI);
|
||||
// m.RootObjectID = ((AyaNameID)o).ID;
|
||||
// m.RootObjectType = _Type;
|
||||
// m.ForeignID = dropID;
|
||||
// m.Name = dropName;
|
||||
// m.LastSync = System.DateTime.Now;
|
||||
// }
|
||||
//}
|
||||
foreach (DataGridViewRow r in gridAya.SelectedRows)
|
||||
{
|
||||
string AyaName = r.Cells[0].Value.ToString();
|
||||
long AyaId = (long)r.Cells[1].Value;
|
||||
|
||||
|
||||
//Util.QBI = (Integration)Util.QBI.Save();
|
||||
|
||||
//Is AyaNova object already mapped?
|
||||
IntegrationItem m = util.QBIntegration.Items.FirstOrDefault(z => z.Id == AyaId && z.AType == _Type);
|
||||
if (m != null)
|
||||
{
|
||||
|
||||
|
||||
//Is it already linked to the selected qb object?
|
||||
|
||||
//Yes so do nothing and continue on to the next object
|
||||
if (m.IntegrationItemId == QBItemId)
|
||||
continue;
|
||||
else
|
||||
{
|
||||
|
||||
//No, AyaNova object was mapped elsewhere, prompt user if this is ok
|
||||
if (MessageBox.Show(
|
||||
$"AyaNova object: {AyaName}\r\nIs already linked to QuickBooks object: {m.IntegrationItemName}\r\nDo you really want to change the link to the QuickBooks object: {QBItemName}\r\n",
|
||||
"Change link?", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
|
||||
== DialogResult.No) continue;
|
||||
|
||||
}
|
||||
|
||||
//If we're here it's because the object is already mapped
|
||||
//but the users has signified they want to change the map to another object so...
|
||||
m.IntegrationItemId = QBItemId;
|
||||
m.IntegrationItemName = QBItemName;
|
||||
m.LastSync = System.DateTime.Now;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//not already present, so add it, easy peasy...
|
||||
m = new IntegrationItem { AType = _Type, IntegrationItemName = QBItemName, IntegrationItemId = QBItemId, LastSync = System.DateTime.Now, ObjectId = AyaId };
|
||||
util.QBIntegration.Items.Add(m);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
await util.SaveIntegrationObject();
|
||||
Initialize();
|
||||
|
||||
//#################################
|
||||
|
||||
Reference in New Issue
Block a user