public static void DeleteContacts( DataTable AContactLogs) { TDBTransaction Transaction = new TDBTransaction(); bool SubmissionOK = false; DBAccess.WriteTransaction( ref Transaction, ref SubmissionOK, delegate { Boolean LastPartnerForThisContactLog = true; foreach (DataRow contactLogRow in AContactLogs.Rows) { Int64 ContactLogId = Convert.ToInt64(contactLogRow["p_contact_log_id_i"]); Int64 PartnerKey = Convert.ToInt64(contactLogRow["p_partner_key_n"]); LastPartnerForThisContactLog = true; if (IsContactLogAssociatedWithMoreThanOnePartner(ContactLogId, Transaction)) { LastPartnerForThisContactLog = false; } PPartnerContactTable contactLogs = PPartnerContactAccess.LoadByPrimaryKey( PartnerKey, ContactLogId, Transaction); contactLogs[0].Delete(); PPartnerContactAccess.SubmitChanges(contactLogs, Transaction); if (LastPartnerForThisContactLog) { // now we also need to delete the contact attributes (linked with this contact log) PPartnerContactAttributeRow template = new PPartnerContactAttributeTable().NewRowTyped(false); template.ContactId = ContactLogId; if (PPartnerContactAttributeAccess.CountUsingTemplate(template, null, Transaction) > 0) { PPartnerContactAttributeAccess.DeleteUsingTemplate(template, null, Transaction); } // and the contact log itself needs to be deleted (if no other partner refers to it) PContactLogAccess.DeleteByPrimaryKey(ContactLogId, Transaction); } SubmissionOK = true; } }); }
public static void AddContactLog(List <Int64> APartnerKeys, DateTime AContactDate, string AContactor, string AMethodOfContact, string AComment, string AModuleID, string AMailingCode) { TDBTransaction Transaction = new TDBTransaction(); bool SubmissionOK = false; DBAccess.WriteTransaction( ref Transaction, ref SubmissionOK, delegate { PContactLogTable contacts = new PContactLogTable(); PContactLogRow contact = contacts.NewRowTyped(); contact.ContactLogId = Transaction.DataBaseObj.GetNextSequenceValue("seq_contact", Transaction); contact.ContactDate = new DateTime(AContactDate.Year, AContactDate.Month, AContactDate.Day); //contact.ContactTime = AContactDate.Hour * 60 + AContactDate.Minute; contact.ContactCode = AMethodOfContact; contact.ContactComment = AComment; contact.ModuleId = AModuleID; contact.Contactor = AContactor; contact.UserId = UserInfo.GetUserInfo().UserID; contacts.Rows.Add(contact); if (AMailingCode.Length > 0) { contact.MailingCode = AMailingCode; } // TODO: restrictions implemented via p_restricted_l or s_user_id_c PPartnerContactTable partnerContacts = new PPartnerContactTable(); APartnerKeys.ForEach(partnerKey => { PPartnerContactRow partnerContact = partnerContacts.NewRowTyped(); partnerContact.ContactLogId = contact.ContactLogId; partnerContact.PartnerKey = partnerKey; partnerContacts.Rows.Add(partnerContact); }); PContactLogAccess.SubmitChanges(contacts, Transaction); PPartnerContactAccess.SubmitChanges(partnerContacts, Transaction); SubmissionOK = true; }); }
public static void AddContactLog(int ExtractId, ref PContactLogTable ContactLogTable) { Boolean NewTransaction; TDBTransaction WriteTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.Serializable, TEnforceIsolationLevel.eilMinimum, out NewTransaction); try { var extractTable = MExtractAccess.LoadViaMExtractMaster(ExtractId, WriteTransaction).AsEnumerable(); var partnerKeys = extractTable.Select(e => e.ItemArray[MExtractTable.ColumnPartnerKeyId]); long ContactLogId = DBAccess.GDBAccessObj.GetNextSequenceValue("seq_contact", WriteTransaction); ContactLogTable.Rows[0][PContactLogTable.ColumnContactLogIdId] = ContactLogId; PPartnerContactTable partnerContacts = new PPartnerContactTable(); partnerKeys.ToList().ForEach(partnerKey => { PPartnerContactRow partnerContact = partnerContacts.NewRowTyped(); partnerContact.ContactLogId = ContactLogId; partnerContact.PartnerKey = (long)partnerKey; partnerContacts.Rows.Add(partnerContact); }); PContactLogAccess.SubmitChanges(ContactLogTable, WriteTransaction); PPartnerContactAccess.SubmitChanges(partnerContacts, WriteTransaction); if (NewTransaction) { DBAccess.GDBAccessObj.CommitTransaction(); } } catch (Exception e) { TLogging.Log( "An Exception occured during the adding of a Contact to Partners in an Extract:" + Environment.NewLine + e.ToString()); if (NewTransaction) { DBAccess.GDBAccessObj.RollbackTransaction(); } throw; } }
public static void DeleteContacts( PContactLogTable AContactLogs) { Boolean NewTransaction; TDBTransaction WriteTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.Serializable, TEnforceIsolationLevel.eilMinimum, out NewTransaction); try { foreach (PContactLogRow contactLogRow in AContactLogs.Rows) { var contactLogs = PPartnerContactAccess.LoadViaPContactLog((long)contactLogRow[PContactLogTable.ColumnContactLogIdId], WriteTransaction); foreach (PPartnerContactRow partnerContactRow in contactLogs.Rows) { partnerContactRow.Delete(); } PPartnerContactAccess.SubmitChanges(contactLogs, WriteTransaction); contactLogRow.Delete(); } PContactLogAccess.SubmitChanges(AContactLogs, WriteTransaction); if (NewTransaction) { DBAccess.GDBAccessObj.CommitTransaction(); } } catch (Exception Exc) { TLogging.Log("An Exception occured during the deletion of Contact Logs:" + Environment.NewLine + Exc.ToString()); if (NewTransaction) { DBAccess.GDBAccessObj.RollbackTransaction(); } throw; } }
public static void AddContactLog(int AExtractId, PContactLogTable AContactLogTable, PPartnerContactAttributeTable APartnerContactAttributeTable) { TDBTransaction WriteTransaction = null; bool SubmissionOK = false; DBAccess.GDBAccessObj.GetNewOrExistingAutoTransaction(IsolationLevel.Serializable, TEnforceIsolationLevel.eilMinimum, ref WriteTransaction, ref SubmissionOK, delegate { var extractTable = MExtractAccess.LoadViaMExtractMaster(AExtractId, WriteTransaction).AsEnumerable(); var partnerKeys = extractTable.Select(e => e.ItemArray[MExtractTable.ColumnPartnerKeyId]); long ContactLogId = DBAccess.GDBAccessObj.GetNextSequenceValue("seq_contact", WriteTransaction); AContactLogTable.Rows[0][PContactLogTable.ColumnContactLogIdId] = ContactLogId; PPartnerContactTable partnerContacts = new PPartnerContactTable(); partnerKeys.ToList().ForEach(partnerKey => { PPartnerContactRow partnerContact = partnerContacts.NewRowTyped(); partnerContact.ContactLogId = ContactLogId; partnerContact.PartnerKey = (long)partnerKey; partnerContacts.Rows.Add(partnerContact); }); foreach (PPartnerContactAttributeRow Row in APartnerContactAttributeTable.Rows) { Row.ContactId = ContactLogId; } PContactLogAccess.SubmitChanges(AContactLogTable, WriteTransaction); PPartnerContactAccess.SubmitChanges(partnerContacts, WriteTransaction); PPartnerContactAttributeAccess.SubmitChanges(APartnerContactAttributeTable, WriteTransaction); SubmissionOK = true; }); }
public static void DeleteContacts( DataTable AContactLogs) { TDBTransaction Transaction = null; bool SubmissionOK = false; DBAccess.GDBAccessObj.GetNewOrExistingAutoTransaction(IsolationLevel.Serializable, ref Transaction, ref SubmissionOK, delegate { foreach (DataRow contactLogRow in AContactLogs.Rows) { PPartnerContactTable contactLogs = PPartnerContactAccess.LoadByPrimaryKey( Convert.ToInt64(contactLogRow["p_partner_key_n"]), Convert.ToInt64(contactLogRow["p_contact_log_id_i"]), Transaction); contactLogs[0].Delete(); PPartnerContactAccess.SubmitChanges(contactLogs, Transaction); SubmissionOK = true; } }); }
public static void AddContactLog(List <Int64> APartnerKeys, DateTime AContactDate, string AContactor, string AMethodOfContact, string AComment, string AModuleID, string AMailingCode) { Boolean NewTransaction; TDBTransaction WriteTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.Serializable, TEnforceIsolationLevel.eilMinimum, out NewTransaction); try { PContactLogTable contacts = new PContactLogTable(); PContactLogRow contact = contacts.NewRowTyped(); contact.ContactLogId = DBAccess.GDBAccessObj.GetNextSequenceValue("seq_contact", WriteTransaction); contact.ContactDate = new DateTime(AContactDate.Year, AContactDate.Month, AContactDate.Day); //contact.ContactTime = AContactDate.Hour * 60 + AContactDate.Minute; contact.ContactCode = AMethodOfContact; contact.ContactComment = AComment; contact.ModuleId = AModuleID; contact.Contactor = AContactor; contact.UserId = UserInfo.GUserInfo.UserID; contacts.Rows.Add(contact); if (AMailingCode.Length > 0) { contact.MailingCode = AMailingCode; } // TODO: restrictions implemented via p_restricted_l or s_user_id_c PPartnerContactTable partnerContacts = new PPartnerContactTable(); APartnerKeys.ForEach(partnerKey => { PPartnerContactRow partnerContact = partnerContacts.NewRowTyped(); partnerContact.ContactLogId = contact.ContactLogId; partnerContact.PartnerKey = partnerKey; partnerContacts.Rows.Add(partnerContact); }); PContactLogAccess.SubmitChanges(contacts, WriteTransaction); PPartnerContactAccess.SubmitChanges(partnerContacts, WriteTransaction); if (NewTransaction) { DBAccess.GDBAccessObj.CommitTransaction(); } } catch (Exception Exc) { TLogging.Log("An Exception occured during the adding of a Contact:" + Environment.NewLine + Exc.ToString()); if (NewTransaction) { DBAccess.GDBAccessObj.RollbackTransaction(); } throw; } }