/// <summary> /// Deletes areas from area and other associtated tables /// </summary> /// <param name="areaNIds"></param> public void DeleteAreas(string areaNIds) { DataTable TempDT = null; DataTable AreaTable = null; string LayerNids = string.Empty; string TableName = string.Empty; MetaDataBuilder MetadataBuilderObject; MapBuilder MapBuilderObj = new MapBuilder(this.DBConnection, this.DBQueries); try { LayerNids = DIConnection.GetDelimitedValuesFromDataTable(this.DBConnection.ExecuteDataTable(this.DBQueries.Area.GetAreaMapByAreaNIds(areaNIds, true)), Area_Map.LayerNId); // Step 1: Delete records from area table foreach (DataRow Row in this.DBConnection.DILanguages(this.DBQueries.DataPrefix).Rows) { TableName = this.DBQueries.DataPrefix + AreaTableName + "_" + Row[Language.LanguageCode].ToString(); this.DBConnection.ExecuteNonQuery(DevInfo.Lib.DI_LibDAL.Queries.Area.Delete.DeleteArea(TableName, areaNIds)); } // Step2: delete metadata MetadataBuilderObject = new MetaDataBuilder(this.DBConnection, this.DBQueries); MetadataBuilderObject.DeleteMetadata(areaNIds, MetadataElementType.Area); if (!string.IsNullOrEmpty(LayerNids)) { //-- Remove Associated Table Records MapBuilderObj.DeleteMap(LayerNids); } // -- STEP 3: Delete All First Level Child of this Area TempDT = this.DBConnection.ExecuteDataTable(this.DBQueries.Area.GetArea(FilterFieldType.ParentNId, areaNIds)); foreach (DataRow row in TempDT.Rows) { this.DeleteAreas(row[Area.AreaNId].ToString()); } // -- step 4 delete from data table new DIDatabase(this.DBConnection, this.DBQueries).DeleteByAreaNIds(areaNIds); } catch (Exception ex) { throw new ApplicationException(ex.ToString()); } }
private void RemoveAreaMapAssociations(int areaNId, List<int> NewAddedLayerNidList, bool removeFeaturesAlso) { string LayerNIds = string.Empty; string LayerNIds1 = string.Empty; DataTable Table; // -- Area_Map : DELETE Area from Area_Map - This will remove all it's features as well // -- STEP 1 - Get all Layer_NIds from Area_Map which are not associated with any other Area _ // to delete the Layers from Area_Map_Layer // -- since 1 Area can have features associated, therefore there will be multiple Layers associated with the single Area if (removeFeaturesAlso) { // -- Get All Layers for this Area Table = this.DBConnection.ExecuteDataTable(this.DBQueries.Area.GetAreaMapByAreaNIds(areaNId.ToString(), true)); } else { // -- Get Layer for this Area only. This Area might have features. In this case Layers associated with those features will not be retrieved Table = this.DBConnection.ExecuteDataTable(this.DBQueries.Area.GetAreaMapByAreaNIds(areaNId.ToString(), false)); } foreach (DataRow Row in Table.Rows) { if (!NewAddedLayerNidList.Contains(Convert.ToInt32(Row[Area_Map_Layer.LayerNId]))) { LayerNIds += "," + Row[Area_Map_Layer.LayerNId].ToString(); } } Table.Dispose(); Table = null; if (LayerNIds.Length > 0) { LayerNIds1 = LayerNIds + ","; LayerNIds = Strings.Mid(LayerNIds, 2); // -- Get Those Layer NIDs which do not have reference to any other areas using (DataTable Table1 = this.DBConnection.ExecuteDataTable(this.DBQueries.Area.GetLayerNIDsExcludeArea(areaNId, LayerNIds))) { if (Table1.Rows.Count > 0) { foreach (DataRow Row in Table1.Rows) { LayerNIds1 = Microsoft.VisualBasic.Strings.Replace(LayerNIds1, "," + Row[Area_Map_Layer.LayerNId].ToString() + ",", ",", 1, -1, CompareMethod.Binary).ToString(); } if (Strings.Mid(LayerNIds1, 1, 1) == ",") { LayerNIds = Strings.Mid(LayerNIds1, 2); } if (LayerNIds.Length > 0) { if (Strings.Mid(LayerNIds, LayerNIds.Length - 1, 1) == ",") LayerNIds = Strings.Mid(LayerNIds, 1, LayerNIds.Length - 1); } } } } if (LayerNIds.Length > 0) { // -- STEP 2 - Delete Area from Area_Map // -- STEP 3 - Delete Layers from Area_Map_Layer // -- STEP 4 - Delete Layers from Area_Map_Metadata MapBuilder oMapBuilder = new MapBuilder(this.DBConnection, this.DBQueries); oMapBuilder.DeleteMap(LayerNIds); } }