public atriumDB.ContactRow SwapBySIN(atriumDB.ContactRow pr, string SIN) { if (pr.RowState == DataRowState.Added) { //load exisiting party row LoadBySIN(SIN); myA.RaiseWarning(WarningLevel.Display, Properties.Resources.ExistingPartyFound, myA.AtMng.AppMan.AppName); var ps = from p in myPersonDT where !p.IsSINNull() && p.SIN == SIN && pr.ContactId != p.ContactId select p; atriumDB.ContactRow existingPerson = ps.Single(); int currentContactId = pr.ContactId; //replace party row in related fields ACEngine ace = myA.CurrentActivityProcess.CurrentACE; if (ace.relTables.ContainsKey("Party0")) { DataView dv = new DataView(myPersonDT, "ContactId=" + existingPerson.ContactId.ToString(), "", DataViewRowState.CurrentRows); ace.relTables["Party0"].RowFilter = dv.RowFilter; } //swap address if (ace.relTables.ContainsKey("Address0") && !existingPerson.IsAddressCurrentIDNull()) { myA.DB.Address.FindByAddressId(pr.AddressCurrentID).Delete(); myA.GetAddress().Load(existingPerson.AddressCurrentID); DataView dv = new DataView(myA.DB.Address, "AddressId=" + existingPerson.AddressCurrentID.ToString(), "", DataViewRowState.CurrentRows); ace.relTables["Address0"].RowFilter = dv.RowFilter; } else if (ace.relTables.ContainsKey("Address0") && existingPerson.IsAddressCurrentIDNull()) { atriumDB.AddressRow adr = myA.DB.Address.FindByAddressId(pr.AddressCurrentID); adr.ContactId = existingPerson.ContactId; existingPerson.AddressCurrentID = adr.AddressId; } //change contact id on filecontact var fcs = from fc in myA.DB.FileContact where !fc.IsNull("ContactId") && fc.ContactId == currentContactId select fc; if (fcs.Count() == 1) { atriumDB.FileContactRow fcr = fcs.Single(); fcr.ContactId = existingPerson.ContactId; } pr.Delete(); // pr.AcceptChanges(); return(existingPerson); } else { return(pr); } }