private bool DeleteRowManual(PContactLogRow ARowToDelete, ref String ACompletionMessage) { foreach (DataRowView ContactLogRow in grdDetails.SelectedDataRows) { DataView PartnerContactLogs = new DataView(FMainDS.PPartnerContact); PartnerContactLogs.RowFilter = String.Format("{0} = {1} AND {2} = {3}", PPartnerContactTable.GetPartnerKeyDBName(), FMainDS.PPartner[0].PartnerKey, PPartnerContactTable.GetContactLogIdDBName(), ContactLogRow.Row[PContactLogTable.ColumnContactLogIdId]); // Delete the PartnerContact records foreach (DataRowView row in PartnerContactLogs) { row.Delete(); } // Actually delete the ContactLog if it's the last if (!TRemote.MPartner.Partner.WebConnectors.IsContactLogAssociatedWithMoreThanOnePartner((long)ContactLogRow.Row[PContactLogTable. ColumnContactLogIdId ])) { // make sure to delete any contact attributes existing for this contact DataView PartnerContactAttribute = new DataView(FMainDS.PPartnerContactAttribute); PartnerContactAttribute.RowFilter = String.Format("{0} = {1}", PPartnerContactAttributeTable.GetContactIdDBName(), ContactLogRow.Row[PContactLogTable.ColumnContactLogIdId]); // Delete the Contact Attribute records foreach (DataRowView attributeRow in PartnerContactAttribute) { attributeRow.Delete(); } ContactLogRow.Row.Delete(); } } grdDetails.Refresh(); return(true); }
/// <summary> /// Display data in control based on data from ARow /// </summary> /// <param name="ARow"></param> public void ShowDetails(PContactLogRow ARow) { FInitializationRunning = true; FContactDR = ARow; ShowData(ARow); // if this is the first row to be showing then we need to set up the grid if ((FGridTableDV == null) && (FMainDS.PPartnerContactAttribute != null) && (FMainDS.PPartnerContactAttribute.Count > 0)) { ContactAttributesLogic.SetupContactAttributesGrid(ref grdSelectedAttributes, FMainDS.PPartnerContactAttribute, true, FContactDR.ContactLogId); } if (FGridTableDV != null) { FGridTableDV.RowFilter = PPartnerContactAttributeTable.GetContactIdDBName() + " = " + ARow.ContactLogId; } FInitializationRunning = false; }
/// <summary> /// Setups the contact attributes grid (used on the following screens: Contact Log tab, Contacts with Partners and Extract by Contact Log. /// </summary> /// <param name="AGrid">Grid to be set up</param> /// <param name="AAttributes">Attributes to be included in the grid</param> /// <param name="AIncludeDescription">Include columns that display the attribute descriptions</param> /// <param name="AContactLogIDFilter">Filter grid to only show rows for given contact log if</param> public static DataView SetupContactAttributesGrid(ref TSgrdDataGridPaged AGrid, DataTable AAttributes, bool AIncludeDescription, Int64 AContactLogIDFilter = -1) { DataView ContactAttributeTableDV = TDataCache.TMPartner.GetCacheableMailingTable(TCacheableMailingTablesEnum.ContactAttributeList).DefaultView; ContactAttributeTableDV.Sort = PContactAttributeTable.GetContactAttributeCodeDBName() + " ASC"; DataView ContactAttributeDetailTableDV = TDataCache.TMPartner.GetCacheableMailingTable(TCacheableMailingTablesEnum.ContactAttributeDetailList).DefaultView; ContactAttributeDetailTableDV.Sort = PContactAttributeDetailTable.GetContactAttributeCodeDBName() + " ASC, " + PContactAttributeDetailTable.GetContactAttrDetailCodeDBName() + " ASC"; DataTable DT = new PPartnerContactAttributeTable(); if ((AAttributes != null) && (AAttributes.Rows.Count > 0)) { DT = AAttributes.Copy(); } if (AIncludeDescription) { DT.Columns.Add("AttributeDescription", System.Type.GetType("System.String")); DT.Columns.Add("AttributeDetailDescription", System.Type.GetType("System.String")); // add descriptions to new table foreach (DataRow Row in DT.Rows) { if (Row.RowState != DataRowState.Deleted) { Row["AttributeDescription"] = GetContactAttributeDesciption( Row[PPartnerContactAttributeTable.GetContactAttributeCodeDBName()].ToString(), ContactAttributeTableDV); Row["AttributeDetailDescription"] = GetContactAttributeDetailDesciption( Row[PPartnerContactAttributeTable.GetContactAttributeCodeDBName()].ToString(), Row[PPartnerContactAttributeTable.GetContactAttrDetailCodeDBName()].ToString(), ContactAttributeDetailTableDV); } } } AGrid.Columns.Clear(); AGrid.AddTextColumn("Attribute Code", DT.Columns[PPartnerContactAttributeTable.GetContactAttributeCodeDBName()]); if (AIncludeDescription) { AGrid.AddTextColumn("Description", DT.Columns["AttributeDescription"]); } AGrid.AddTextColumn("Detail Code", DT.Columns[PPartnerContactAttributeTable.GetContactAttrDetailCodeDBName()]); if (AIncludeDescription) { AGrid.AddTextColumn("Description", DT.Columns["AttributeDetailDescription"]); } DataView GridTableDV = DT.DefaultView; GridTableDV.AllowNew = false; GridTableDV.AllowEdit = false; GridTableDV.AllowDelete = false; if (AContactLogIDFilter != -1) { GridTableDV.RowFilter = PPartnerContactAttributeTable.GetContactIdDBName() + " = " + AContactLogIDFilter; } // DataBind the DataGrid AGrid.DataSource = new DevAge.ComponentModel.BoundDataView(GridTableDV); AGrid.AutoResizeGrid(); return(GridTableDV); }
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); }