/// <summary> /// Maps the given <paramref name="dbRecord"/> to <paramref name="properties"/>. /// </summary> /// <param name="context">The <see cref="IMansionContext"/>.</param> /// <param name="dbRecord">The <see cref="DbRecord"/> which to map.</param> /// <param name="properties">The <see cref="IPropertyBag"/> in which to store the mapped result.</param> protected override void DoMap(IMansionContext context, DbRecord dbRecord, IPropertyBag properties) { // field indices var idIndex = dbRecord.GetOrdinal("id"); var parentPointerIndex = dbRecord.GetOrdinal("parentPointer"); var nameIndex = dbRecord.GetOrdinal("name"); var parentPathIndex = dbRecord.GetOrdinal("parentPath"); var typeIndex = dbRecord.GetOrdinal("type"); var parentStructureIndex = dbRecord.GetOrdinal("parentStructure"); // assemble the node pointer var pointer = (dbRecord.IsDBNull(parentPointerIndex) ? string.Empty : dbRecord.GetString(parentPointerIndex) + NodePointer.PointerSeparator) + dbRecord.GetInt32(idIndex); var structure = (dbRecord.IsDBNull(parentStructureIndex) ? string.Empty : dbRecord.GetString(parentStructureIndex) + NodePointer.StructureSeparator) + dbRecord.GetString(typeIndex); var path = (dbRecord.IsDBNull(parentPathIndex) ? string.Empty : dbRecord.GetString(parentPathIndex) + NodePointer.PathSeparator) + dbRecord.GetString(nameIndex); var nodePointer = NodePointer.Parse(pointer, structure, path); // set the pointer properties.Set("pointer", nodePointer); properties.Set("path", nodePointer.PathString); properties.Set("structure", nodePointer.StructureString); properties.Set("depth", nodePointer.Depth); properties.Set("name", nodePointer.Name); properties.Set("type", nodePointer.Type); if (nodePointer.HasParent) { properties.Set("parentPointer", nodePointer.Parent); properties.Set("parentId", nodePointer.Parent.Id); } }
/// <summary> /// Maps the given <paramref name="dbRecord"/> to <paramref name="properties"/>. /// </summary> /// <param name="context">The <see cref="IMansionContext"/>.</param> /// <param name="dbRecord">The <see cref="DbRecord"/> which to map.</param> /// <param name="properties">The <see cref="IPropertyBag"/> in which to store the mapped result.</param> protected override void DoMap(IMansionContext context, DbRecord dbRecord, IPropertyBag properties) { // field indices var idIndex = dbRecord.GetOrdinal("id"); // set the pointer properties.Set("id", dbRecord.GetInt32(idIndex)); }
/// <summary> /// Maps the given <paramref name="dbRecord"/> to <paramref name="properties"/>. /// </summary> /// <param name="context">The <see cref="IMansionContext"/>.</param> /// <param name="dbRecord">The <see cref="DbRecord"/> which to map.</param> /// <param name="properties">The <see cref="IPropertyBag"/> in which to store the mapped result.</param> /// <exception cref="ArgumentNullException">Thrown if one of the parameters is null.</exception> public void Map(IMansionContext context, DbRecord dbRecord, IPropertyBag properties) { // validate arguments if (context == null) throw new ArgumentNullException("context"); if (dbRecord == null) throw new ArgumentNullException("dbRecord"); if (properties == null) throw new ArgumentNullException("properties"); // invoke template method DoMap(context, dbRecord, properties); }
/// <summary> /// Maps the given <paramref name="dbRecord"/> to <paramref name="properties"/>. /// </summary> /// <param name="context">The <see cref="IMansionContext"/>.</param> /// <param name="dbRecord">The <see cref="DbRecord"/> which to map.</param> /// <param name="properties">The <see cref="IPropertyBag"/> in which to store the mapped result.</param> protected override void DoMap(IMansionContext context, DbRecord dbRecord, IPropertyBag properties) { // set all the column values as properties foreach (var ordinals in dbRecord.GetUnreadOrdinals()) { // if the column is empty remove the value from the properties, otherwise set the value from the column if (dbRecord.IsDBNull(ordinals)) { object obj; properties.TryGetAndRemove(context, dbRecord.GetName(ordinals), out obj); } else properties.Set(dbRecord.GetName(ordinals), dbRecord.GetValue(ordinals)); } }
/// <summary> /// Maps the given <paramref name="dbRecord"/> to <paramref name="properties"/>. /// </summary> /// <param name="context">The <see cref="IMansionContext"/>.</param> /// <param name="dbRecord">The <see cref="DbRecord"/> which to map.</param> /// <param name="properties">The <see cref="IPropertyBag"/> in which to store the mapped result.</param> protected override void DoMap(IMansionContext context, DbRecord dbRecord, IPropertyBag properties) { // get the index of the column var extendedPropertiesIndex = dbRecord.GetOrdinal("extendedProperties"); // check if there are no extended properties if (dbRecord.IsDBNull(extendedPropertiesIndex)) return; // get the extended properties var extendedPropertiesLength = dbRecord.GetBytes(extendedPropertiesIndex, 0, null, 0, 0); var serializedProperties = new byte[extendedPropertiesLength]; dbRecord.GetBytes(extendedPropertiesIndex, 0, serializedProperties, 0, serializedProperties.Length); // deserialize var deserializedProperties = conversionService.Convert<IPropertyBag>(context, serializedProperties); // merge the deserialized properties properties.Merge(deserializedProperties); }
public UpdateMessageCommand(DbBase db, DbRecord record) { dbAccess = db; rec = record; }
/// <summary> /// Maps the given <paramref name="dbRecord"/> to <paramref name="properties"/>. /// </summary> /// <param name="context">The <see cref="IMansionContext"/>.</param> /// <param name="dbRecord">The <see cref="DbRecord"/> which to map.</param> /// <param name="properties">The <see cref="IPropertyBag"/> in which to store the mapped result.</param> protected abstract void DoMap(IMansionContext context, DbRecord dbRecord, IPropertyBag properties);
/// <summary> /// Shows a form that allows a user to associate selected database records with another record. /// </summary> /// <param name="Owner">Window that is the owner of the form that is shown</param> /// <param name="Title">Text to show in the form's title bar and a caption label</param> /// <param name="OwningRecord">Instance of a DbRecord that has a one-to-many relationship with other records</param> /// <param name="PropertyName">Name of the property that holds the set of associated records (must be of type HasMany<T>)</param> public static void SelectRecords(IWin32Window Owner, String Title, DbRecord OwningRecord, String PropertyName) { String Name = OwningRecord.GetType().Name + "." + PropertyName; using (var form = new HasManyEditForm()) { // Important for FormData.LoadFormData and FormData.SaveFormData form.Name = Name; form.Text = Title; form.lblText.Text = Title; form.OwningRecord = OwningRecord; form.PropertyName = PropertyName; if (Owner == null) form.ShowInTaskbar = true; form.ShowDialog(Owner); } }
/// <summary> /// Adds a specific record to the given list view. /// </summary> /// <param name="Record">The record to add to the list view.</param> /// <param name="List">The list view to add the record to.</param> /// <returns>The newly created list view item.</returns> /// <exception cref="System.ArgumentNullException">Thrown when one of the input parameters is null.</exception> protected ListViewItem AddRecordToListView(DbRecord Record, ListView List) { if (Record == null) throw new ArgumentNullException("Record"); if (List == null) throw new ArgumentNullException("List"); ListViewItem item = new ListViewItem(); if (Record is IEditableDbRecord) item.Text = ((IEditableDbRecord)Record).Name; else item.Text = Record.ToString(); item.Tag = Record; return List.Items.Add(item); }