public static void AddContactAttributeToContacts(int contactId, List <Int64> APartnerKeys, List <int> attributeCode, List <int> attributeDetailCode) { TDBTransaction Transaction = new TDBTransaction(); bool SubmissionOK = false; DBAccess.WriteTransaction( ref Transaction, ref SubmissionOK, delegate { PPartnerContactAttributeTable attributes = new PPartnerContactAttributeTable(); for (int i = 0; i < APartnerKeys.Count; i++) { PPartnerContactAttributeRow row = attributes.NewRowTyped(); row.ContactId = contactId; } PPartnerContactAttributeAccess.SubmitChanges(attributes, Transaction); SubmissionOK = true; }); }
public static void AddContactAttributeToContacts(int contactId, List <Int64> APartnerKeys, List <int> attributeCode, List <int> attributeDetailCode) { Boolean NewTransaction; TDBTransaction WriteTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.Serializable, TEnforceIsolationLevel.eilMinimum, out NewTransaction); try { PPartnerContactAttributeTable attributes = new PPartnerContactAttributeTable(); for (int i = 0; i < APartnerKeys.Count; i++) { PPartnerContactAttributeRow row = attributes.NewRowTyped(); row.ContactId = contactId; } PPartnerContactAttributeAccess.SubmitChanges(attributes, WriteTransaction); if (NewTransaction) { DBAccess.GDBAccessObj.CommitTransaction(); } } catch (Exception Exc) { TLogging.Log("An Exception occured while associating a Contact with a ContactAttribute:" + Environment.NewLine + Exc.ToString()); if (NewTransaction) { DBAccess.GDBAccessObj.RollbackTransaction(); } throw; } }
private Boolean PerformContactAttributeAddOrRemoval(DataRow AChangingRow, out Boolean AIsRemoval) { Boolean ReturnValue = false; AIsRemoval = false; try { String AttributeCode = AChangingRow["AttributeCode"].ToString(); String AttributeDetailCode = AChangingRow["AttributeDetailCode"].ToString(); DataRow ExistingDataRow = FSelectedContactAttributeTable.Rows.Find(new object[] { FContactID, AttributeCode, AttributeDetailCode }); if (ExistingDataRow == null) { /* * Add Contact Attribute */ DataRow DeletedRow = null; // check that this contact attribute hasn't previously been deleted foreach (DataRow Row in FSelectedContactAttributeTable.Rows) { if ((Row.RowState == DataRowState.Deleted) && (Convert.ToInt64(Row[PPartnerContactAttributeTable.GetContactIdDBName(), DataRowVersion.Original]) == FContactID) && (Row[PPartnerContactAttributeTable.GetContactAttributeCodeDBName(), DataRowVersion.Original].ToString() == AttributeCode) && (Row[PPartnerContactAttributeTable.GetContactAttrDetailCodeDBName(), DataRowVersion.Original].ToString() == AttributeDetailCode)) { DeletedRow = Row; } } if (DeletedRow != null) { // undelete the previously deleted row DeletedRow.RejectChanges(); } else { // Check: is this Contact Attribute assignable PContactAttributeRow ContactAttribute = (PContactAttributeRow)FContactAttributeTableDV.Table.Rows.Find(new Object[] { AttributeCode }); PContactAttributeDetailRow ContactAttributeDetail = (PContactAttributeDetailRow)FContactAttributeDetailTableDV.Table.Rows.Find(new Object[] { AttributeCode, AttributeDetailCode }); // -1 means this is being used in a find screen and we can select inactive attributes if ((FContactID != -1) && (!ContactAttribute.Active || !ContactAttributeDetail.Active)) { MessageBox.Show( string.Format(Catalog.GetString("This Contact Attribute is inactive and cannot be added to this Contact Log."), AttributeCode), Catalog.GetString("Inactive Contact Attribute"), MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } // add new row to PartnerType table PPartnerContactAttributeRow TheNewRow = FSelectedContactAttributeTable.NewRowTyped(); TheNewRow.ContactId = FContactID; TheNewRow.ContactAttributeCode = AttributeCode; TheNewRow.ContactAttrDetailCode = AttributeDetailCode; FSelectedContactAttributeTable.Rows.Add(TheNewRow); } ReturnValue = true; AIsRemoval = false; } else { /* * Remove Special Type */ // Delete row if (ExistingDataRow.RowState == DataRowState.Added) { FAddedAttributeDeleted = true; } ExistingDataRow.Delete(); ReturnValue = true; AIsRemoval = true; } } catch (Exception E) { MessageBox.Show(E.ToString()); ReturnValue = false; } return(ReturnValue); }