/// <summary> /// Gets a new allocation for this ID group. /// </summary> /// <param name="announce">Should the allocation be announced to the user?</param> /// <returns>Information about the allocated range.</returns> internal IdPacket GetAllocation(bool announce) { IdPacket result = null; IDataServer ds = EditingController.Current.DataServer; if (ds == null) { throw new ApplicationException("Database not available"); } ds.RunTransaction(delegate { // May be best to remove this from IIdGroup! -- DO want to be able to retrieve the value // currently stored in the database. int oldMaxUsedId = m_MaxAllocatedId; int newMaxUsedId = (oldMaxUsedId == 0 ? LowestId + PacketSize - 1 : oldMaxUsedId + PacketSize); /* * // The following should be covered by the implementation of the ID server (for a personal ID server, * // there should be nothing to do). * string sql = String.Format("UPDATE [ced].[IdGroups] SET [MaxUsedId]={0} WHERE [GroupId]={1} AND [MaxUsedId]={2}", * newMaxUsedId, Id, oldMaxUsedId); * int nRows = ds.ExecuteNonQuery(sql); * * if (nRows != 1) * throw new ApplicationException("Allocation failed"); */ // Remember the allocation as as part of this group IdAllocation alloc = new IdAllocation() { GroupId = this.Id, LowestId = newMaxUsedId - PacketSize + 1, HighestId = newMaxUsedId, }; result = AddIdPacket(alloc); m_MaxAllocatedId = newMaxUsedId; // Write event data for the allocation CadastralMapModel.Current.WorkingSession.AddAllocation(alloc); EditingController.Current.Project.WriteChange(alloc); }); // If the user should be informed, list out any ranges we created. if (announce && result != null) { string announcement = String.Format("Allocating extra IDs: {0}-{1}", result.Min, result.Max); MessageBox.Show(announcement); } return(result); }
/// <summary> /// Attaches miscellaneous attribute data to the features that have been loaded. /// </summary> /// <param name="keyIds">Index of the IDs to look for (indexed by formatted key)</param> /// <returns>The number of rows that were found (-1 if no database tables have /// been associated with Backsight)</returns> static int Load(Dictionary <string, FeatureId> keyIds) { // Locate information about the tables associated with Backsight ITable[] tables = EnvironmentContainer.Current.Tables; if (tables.Length == 0) { return(-1); } IDataServer ds = EditingController.Current.DataServer; if (ds == null) { return(-1); } // Copy the required keys into a temp table Trace.WriteLine(String.Format("Locating attributes for {0} feature IDs in {1} tables", keyIds.Count, tables.Length)); int nFound = 0; ds.RunTransaction(delegate { IConnection ic = ds.GetConnection(); const string KEYS_TABLE_NAME = "#Ids"; CopyKeysToTable(ic, keyIds, KEYS_TABLE_NAME); foreach (ITable t in tables) { string sql = String.Format("SELECT * FROM {0} WHERE [{1}] IN (SELECT [FeatureId] FROM [{2}])", t.TableName, t.IdColumnName, KEYS_TABLE_NAME); DataTable tab = ds.ExecuteSelect(sql); tab.TableName = t.TableName; int featureIdIndex = tab.Columns[t.IdColumnName].Ordinal; Debug.Assert(featureIdIndex >= 0); foreach (DataRow row in tab.Select()) { string key = row[featureIdIndex].ToString().TrimEnd(); FeatureId fid; if (keyIds.TryGetValue(key, out fid)) { // Don't create a row if the ID is already associated with the // table (this is meant to cover situations where the edit has actively // formed the attributes, and is calling this method only to cover the // fact that further attributes may be involved). if (!fid.RefersToTable(t)) { Row r = new Row(fid, t, row); nFound++; } } else { string msg = String.Format("Cannot find '{0}' in dictionary", key); throw new Exception(msg); } } } }); return(nFound); }