public override void SetValue(object component, object value) { esEntity obj = component as esEntity; if (obj == null) { return; } if (_trueDescriptor != null) { _trueDescriptor.SetValue(component, value); } else { if (obj != null) { if (m_setDelegate != null) { m_setDelegate(obj, value); } else { obj.currentValues[this.Name] = value; obj.OnPropertyChanged(this.Name); } } } }
private SortedList GetSortedListOfProperties(esEntity entity, esEntityCollectionBase baseCollection) { SortedList list = new SortedList(); esEntityCollectionBase theBaseCollection = baseCollection != null ? baseCollection : entity.Collection; if (theBaseCollection != null) { if (theBaseCollection.selectedColumns != null) { foreach (KeyValuePair <string, int> selectedColumn in theBaseCollection.selectedColumns) { list.Add(selectedColumn.Value, selectedColumn.Key); } } if (theBaseCollection.extraColumnMetadata != null) { foreach (KeyValuePair <string, esColumnMetadata> extraColumn in theBaseCollection.extraColumnMetadata) { list.Add(extraColumn.Value.Ordinal, extraColumn.Key); } } } return(list); }
bool IEnumerator.MoveNext() { bool moved = false; while (true) { if (enumerator.MoveNext()) { IEnumerator e = this as IEnumerator; esEntity obj = e.Current as esEntity; if (obj.rowState != esDataRowState.Deleted) { moved = true; break; } } else { break; } } return(moved); }
public esPropertyDescriptor(esEntity entity, string name, Type propertyType, esEntity containedEntity) : base(name, null) { this._entity = entity; this.m_propertyType = propertyType; this._containedEntity = containedEntity; }
void IList.Remove(object value) { #if (TRACE) Console.WriteLine("void IList.Remove(object value)"); #endif esEntity entity = value as esEntity; entities.Remove((T)entity); if (entity.RowState != esDataRowState.Deleted && entity.RowState != esDataRowState.Added) { entity.MarkAsDeleted(); } if (entitiesFilterBackup != null) { IList i = entitiesFilterBackup as IList; i.Remove(entity); } if (updateViewNotification != null) { OnUpdateViewNotification(this, ListChangedType.ItemDeleted, entity); } }
int IComparer <T> .Compare(T obj1, T obj2) { esEntity obj = obj1 as esEntity; esColumnMetadata esColumn = obj.es.Meta.Columns.FindByPropertyName(sortProperty.Name); return(obj1.OnSort(obj2, esColumn, sortProperty.Name)); }
/// <summary> /// Fills the object. /// </summary> /// <param name="objectToPopulate">The object to populate.</param> /// <param name="fields">The fields.</param> /// <param name="entityPrefix">The entity prefix.</param> public static void FillObject(esEntity objectToPopulate, TextFieldCollection fields, string entityPrefix) { // Qualified property name string qualifiedProperty = ""; // Iterate over the properties of the type List <PropertyInfo> objectProperties = GetPropertyInfo(objectToPopulate.GetType()); foreach (PropertyInfo objectProperty in objectProperties) { // Build the qualified name qualifiedProperty = ((string.IsNullOrEmpty(entityPrefix)) ? "" : entityPrefix + ".") + objectProperty.Name; // See if we can write to the property if (objectProperty.CanWrite) { // See if it's a complex type if (objectProperty.PropertyType.IsSubclassOf(typeof(esEntity))) { // It's a complext type FillObject( (esEntity)objectProperty.GetValue(objectToPopulate, null), fields, qualifiedProperty); } else if (null != fields[qualifiedProperty]) { // See if the property is in the text fields collection objectProperty.SetValue( objectToPopulate, Convert.ChangeType(fields[qualifiedProperty].Value, objectProperty.PropertyType), null); } } } }
public override object GetValue(object component) { esEntity obj = component as esEntity; if (obj == null) { return(null); } if (_trueDescriptor != null) { return(this._trueDescriptor.GetValue(component)); } else { object o = null; if (m_getDelegate != null) { o = m_getDelegate(component); } else { obj.currentValues.TryGetValue(this.Name, out o); } return(o); } }
static public jsColumn[] PopulateColumns(esEntity entity) { List<jsColumn> cols = new List<jsColumn>(); // we just put some fake data in the footer section for the demo decimal footer = 100M; List<string> columns = entity.GetCurrentListOfColumns(); foreach (string column in columns) { esColumnMetadata esCol = entity.es.Meta.Columns.FindByColumnName(column); jsColumn c = new jsColumn(); footer += 2M; if (esCol != null) { c.isVisible = true; c.displayName = esCol.PropertyName; c.dataType = esCol.Type.ToString(); c.columnName = esCol.Name; c.propertyName = esCol.PropertyName; c.ordinal = esCol.Ordinal; c.numericPrecision = esCol.NumericPrecision; c.numericScale = esCol.NumericScale; c.characterMaxLength = esCol.CharacterMaxLength; c.defaultValue = esCol.Default; c.hasDefault = esCol.HasDefault; c.isInPrimaryKey = esCol.IsInPrimaryKey; c.isAutoIncrement = esCol.IsAutoIncrement; c.isNullable = esCol.IsNullable; c.isConcurrency = esCol.IsConcurrency || esCol.IsEntitySpacesConcurrency; c.isSortable = true; c.footerValue = "$" + Convert.ToString(footer); } else { object o = entity.GetColumn(column); if (o != DBNull.Value && o != null) { c.dataType = o.GetType().ToString(); } c.isVisible = true; c.displayName = column; c.columnName = column; c.propertyName = column; c.isSortable = false; c.footerValue = "$" + Convert.ToString(footer); } cols.Add(c); } return cols.ToArray(); }
static public jsColumn[] PopulateColumns(esEntity entity) { List <jsColumn> cols = new List <jsColumn>(); // we just put some fake data in the footer section for the demo decimal footer = 100M; List <string> columns = entity.GetCurrentListOfColumns(); foreach (string column in columns) { esColumnMetadata esCol = entity.es.Meta.Columns.FindByColumnName(column); jsColumn c = new jsColumn(); footer += 2M; if (esCol != null) { c.isVisible = true; c.displayName = esCol.PropertyName; c.dataType = esCol.Type.ToString(); c.columnName = esCol.Name; c.propertyName = esCol.PropertyName; c.ordinal = esCol.Ordinal; c.numericPrecision = esCol.NumericPrecision; c.numericScale = esCol.NumericScale; c.characterMaxLength = esCol.CharacterMaxLength; c.defaultValue = esCol.Default; c.hasDefault = esCol.HasDefault; c.isInPrimaryKey = esCol.IsInPrimaryKey; c.isAutoIncrement = esCol.IsAutoIncrement; c.isNullable = esCol.IsNullable; c.isConcurrency = esCol.IsConcurrency || esCol.IsEntitySpacesConcurrency; c.isSortable = true; c.footerValue = "$" + Convert.ToString(footer); } else { object o = entity.GetColumn(column); if (o != DBNull.Value && o != null) { c.dataType = o.GetType().ToString(); } c.isVisible = true; c.displayName = column; c.columnName = column; c.propertyName = column; c.isSortable = false; c.footerValue = "$" + Convert.ToString(footer); } cols.Add(c); } return(cols.ToArray()); }
internal void HrydateFromEntity(esEntity entity) { if (entity != null) { this.currentValues = entity.currentValues; this.originalValues = entity.originalValues; this.rowState = entity.rowState; this.m_modifiedColumns = entity.m_modifiedColumns; } }
public esColumnMetadataCollection GetColumns(esEntityCollectionBase collection) { collection.EnableHierarchicalBinding = false; PropertyDescriptorCollection props = null; try { MethodInfo GetEntity = collection.GetType().GetMethod("CreateEntity", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); esEntity entity = GetEntity.Invoke(collection, null) as esEntity; MethodInfo GetProperties = collection.GetType().GetMethod("GetProperties", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); props = GetProperties.Invoke(collection, new object[] { entity }) as PropertyDescriptorCollection; } catch { } MethodInfo get_Meta = collection.GetType().GetMethod("get_Meta", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); IMetadata meta = get_Meta.Invoke(collection, null) as IMetadata; esColumnMetadataCollection esColumns = meta.Columns; esColumnMetadataCollection esCollection = new esColumnMetadataCollection(); try { foreach (esColumnMetadata col in esColumns) { esCollection.Add(col); } } catch { } try { if (props != null) { esExtendedPropertyAttribute att = new esExtendedPropertyAttribute(); foreach (PropertyDescriptor prop in props) { if (esColumns.FindByPropertyName(prop.Name) == null) { if (prop.Attributes.Contains(att)) { esColumnMetadata col = new esColumnMetadata(prop.Name, 1000, prop.PropertyType); col.PropertyName = prop.Name; esCollection.Add(col); } } } } } catch { } return(esCollection); }
public override object Deserialize(IDictionary <string, object> dictionary, Type type, JavaScriptSerializer serializer) { esEntity entity = Activator.CreateInstance(type) as esEntity; if (entity != null) { List <string> propertyNames = (from esColumnMetadata c in entity.es.Meta.Columns select c.PropertyName).ToList(); var properties = dictionary.Where(e => propertyNames.Contains(e.Key)).ToDictionary(e => e.Key, e => e.Value); var extraColumns = dictionary.Where(e => !propertyNames.Contains(e.Key)).ToDictionary(e => e.Key, e => e.Value); entity.SetProperties(properties); entity.SetExtraColumns(extraColumns); } return(entity); }
void IList.RemoveAt(int index) { #if (TRACE) Console.WriteLine("void IList.RemoveAt(int index)"); #endif esEntity entity = ((IList)entities)[index] as esEntity; entities.Remove((T)entity); entity.MarkAsDeleted(); if (entitiesFilterBackup != null) { IList i = entitiesFilterBackup as IList; i.Remove(entity); } }
void IList.Remove(object value) { #if (TRACE) Console.WriteLine("void IList.Remove(object value)"); #endif esEntity entity = value as esEntity; entities.Remove((T)entity); entity.MarkAsDeleted(); if (entitiesFilterBackup != null) { IList i = entitiesFilterBackup as IList; i.Remove(entity); } }
void IList.RemoveAt(int index) { #if (TRACE) Console.WriteLine("void IList.RemoveAt(int index)"); #endif esEntity entity = ((IList)entities)[index] as esEntity; entities.Remove((T)entity); entity.MarkAsDeleted(); if (entitiesFilterBackup != null) { IList i = entitiesFilterBackup as IList; i.Remove(entity); } if (updateViewNotification != null) { OnUpdateViewNotification(this, ListChangedType.ItemDeleted, entity); } }
bool ICollection <T> .Remove(T item) { #if (TRACE) Console.WriteLine("bool ICollection<T>.Remove(T item)"); #endif esEntity entity = item as esEntity; IList list = this as IList; bool removed = list.Contains(item); entities.Remove((T)entity); entity.MarkAsDeleted(); if (entitiesFilterBackup != null) { IList i = entitiesFilterBackup as IList; i.Remove(entity); } return(removed); }
bool ICollection <T> .Remove(T item) { #if (TRACE) Console.WriteLine("bool ICollection<T>.Remove(T item)"); #endif esEntity entity = item as esEntity; bool removed = entities.Remove((T)entity); entity.MarkAsDeleted(); if (entitiesFilterBackup != null) { IList i = entitiesFilterBackup as IList; i.Remove(entity); } if (updateViewNotification != null) { OnUpdateViewNotification(this, ListChangedType.ItemDeleted, entity); } return(removed); }
internal virtual PropertyDescriptorCollection GetProperties(esEntity entity, esEntityCollectionBase baseCollection) { return null; }
internal virtual void OnUpdateViewNotification(object sender, ListChangedType changeType, esEntity obj) { }
internal override PropertyDescriptorCollection GetProperties(esEntity entity, esEntityCollectionBase baseCollection) { bool weHaveData = false; int lastOrdinal = 0; esColumnMetadataCollection esMetaCols = entity.es.Meta.Columns; esEntityCollectionBase theBaseCollection = baseCollection != null ? baseCollection : entity.Collection; bool enableHierarchcialBinding = theBaseCollection != null ? theBaseCollection.EnableHierarchicalBinding : true; if (theBaseCollection != null) { if (theBaseCollection.GetList() != null) { // Do we have any entities? weHaveData = theBaseCollection.GetList().Count > 0; if (weHaveData == false) { // If selectedColumns has data then they attempted a load and we know the columns based on thier select statement weHaveData = theBaseCollection.selectedColumns != null && theBaseCollection.selectedColumns.Keys.Count > 0; } } } //------------------------------------------------------------ // First we deal with Properties from the DataTable.Columns // or from the esColumnMetadataCollection. //------------------------------------------------------------ ArrayList collNested = new ArrayList(); SortedList <int, PropertyDescriptor> coll = new SortedList <int, PropertyDescriptor>(); PropertyDescriptorCollection props = TypeDescriptor.GetProperties(entity, true); // Note, we check for selectedColumns because we might be a deserialized collection in which // case there will not be any selectedColumns if (weHaveData && theBaseCollection.selectedColumns != null) { SortedList list = GetSortedListOfProperties(entity, baseCollection); for (int i = 0; i < list.Count; i++) { string column = (string)list.GetByIndex(i); if (column == "ESRN") { continue; } esColumnMetadata esCol = entity.es.Meta.Columns.FindByColumnName(column); if (esCol != null) { PropertyDescriptor prop = props[esCol.PropertyName]; if (prop != null) { coll.Add(lastOrdinal++, prop); } } else { esCol = theBaseCollection.extraColumnMetadata[column]; if (esCol != null) { // Extra or Extended Properties esPropertyDescriptor dpd = new esPropertyDescriptor ( typeof(T), column, esCol != null ? esCol.Type : typeof(string), delegate(object p) { return(((esEntity)p).currentValues[column]); }, delegate(object p, object data) { ((esEntity)p).currentValues[column] = data; ((esEntity)p).OnPropertyChanged(column); } ); coll.Add(lastOrdinal++, dpd); } } } } else { foreach (esColumnMetadata esCol in esMetaCols) { coll.Add(lastOrdinal++, props[esCol.PropertyName]); } } //------------------------------------------------------------ // Now we deal with extended properties that are using the // esExtendedPropertyAttribute technique //------------------------------------------------------------ foreach (PropertyDescriptor prop in props) { if (prop.Attributes.Contains(esEntityCollection <T> .extendedPropertyAttribute)) { coll.Add(lastOrdinal++, prop); } } //------------------------------------------------------------ // Now we deal with any local properties. Local properties are // properties that users may want to bind with that are // NOT backed by data in the DataTable //------------------------------------------------------------ List <esPropertyDescriptor> localProps = entity.GetLocalBindingProperties(); if (localProps != null) { foreach (esPropertyDescriptor esProp in localProps) { // We check this incase they add a local based property for a DataColumn // based property, they would do this so it appears in design time, and // we don't want to add a duplicate bool exists = coll.ContainsValue(props[esProp.Name]); if (!exists) { if (props[esProp.Name] != null) { coll.Add(lastOrdinal++, props[esProp.Name]); } else { coll.Add(lastOrdinal++, esProp); } } } } ArrayList tempColl = new ArrayList(); if (enableHierarchcialBinding) { List <esPropertyDescriptor> hierProps = entity.GetHierarchicalProperties(); if (hierProps != null) { foreach (esPropertyDescriptor esProp in hierProps) { esProp.TrueDescriptor = props[esProp.Name]; // coll.Add(lastOrdinal++, esProp); tempColl.Add(esProp); } } } // Create the collection foreach (PropertyDescriptor p in coll.Values) { tempColl.Add(p); } tempColl.AddRange(collNested); PropertyDescriptorCollection theProps = new PropertyDescriptorCollection((PropertyDescriptor[])tempColl.ToArray(typeof(PropertyDescriptor))); return(theProps); }
PropertyDescriptorCollection ITypedList.GetItemProperties(PropertyDescriptor[] listAccessors) { // We are binding so we turn this on ... entities.RaiseListChangedEvents = true; PropertyDescriptorCollection props = null; Type type = null; if (listAccessors == null || listAccessors.Length == 0) { esEntity e = null; // It wants "this" object and so we can use this technique if (this.Count > 0) { e = entities[0] as esEntity; } else { e = new T(); } type = e.GetType(); //------------------------------------ // Check to see if it's in the cached //------------------------------------ if (this.BindingPropertyCache.ContainsKey(type)) { return(this.BindingPropertyCache[type]); } props = this.GetProperties(e, this); this.BindingPropertyCache[type] = props; } else { if (this.EnableHierarchicalBinding == false) { return(null); } // We should not enter this else statement if hierarchical binding is false PropertyDescriptor prop = listAccessors[listAccessors.Length - 1]; //------------------------------------ // Check to see if it's in the cached //------------------------------------ if (this.BindingPropertyCache.ContainsKey(prop.PropertyType)) { return(this.BindingPropertyCache[prop.PropertyType]); } esPropertyDescriptor esProp = prop as esPropertyDescriptor; if (esProp != null) { // Nope, not in the cache, let's get the info props = this.GetProperties(esProp.ContainedEntity, null); } else { // I give up, go get the raw properties props = TypeDescriptor.GetProperties(prop.PropertyType); } this.BindingPropertyCache[prop.PropertyType] = props; } return(props); }
static public void Map(esEntity src, esSmartDto dst) { dst.HrydateFromEntity(src); }
public override void Delete(System.Collections.IDictionary keys, System.Collections.IDictionary oldValues, DataSourceViewOperationCallback callback) { esDataSourceDeleteEventArgs e = null; try { if (keys != null && keys.Count > 0) { e = new esDataSourceDeleteEventArgs(); e.Keys = keys; e.OldValues = oldValues; this.OnPreDelete(e); if (e.Cancel) { return; } // Find the proper esEntity and set it's values object[] pks = new object[keys.Count]; int index = 0; foreach (object value in keys.Values) { pks[index++] = value; } esDataSourceCreateEntityEventArgs ce = new esDataSourceCreateEntityEventArgs(); ce.PrimaryKeys = pks; this.OnCreateEntity(ce); esEntity entity = ce.Entity; e.Entity = entity; //this.OnPreDelete(e); e.EventWasHandled = false; this.OnDelete(e); if (!e.EventWasHandled) { entity.MarkAsDeleted(); entity.Save(); this.OnDataSourceViewChanged(EventArgs.Empty); } this.OnPostDelete(e); } } catch (Exception ex) { esDataSourceExceptionEventArgs exArgs = new esDataSourceExceptionEventArgs(ex); exArgs.EventType = esDataSourceEventType.Delete; exArgs.DeleteArgs = e; try { this.OnException(exArgs); } catch { } if (!exArgs.ExceptionWasHandled) { throw; } } finally { callback(1, null); } }
virtual internal PropertyDescriptorCollection GetProperties(esEntity entity, esEntityCollectionBase baseCollection) { return(null); }
public void OnUpdateViewEventHandler(object sender, ListChangedType changeType, esEntity entity) { bool orginal = this.entities.RaiseListChangedEvents; this.entities.RaiseListChangedEvents = collection.RaiseListChangeEventsEnabled; switch (changeType) { case ListChangedType.ItemDeleted: { IList coll = this as IList; coll.Remove(entity); if (entitiesFilterBackup != null) { IBindingList i = entitiesFilterBackup as IBindingList; i.Remove(entity); } } break; case ListChangedType.ItemAdded: { IList coll = this as IList; coll.Add(entity); if (entitiesFilterBackup != null) { IBindingList i = entitiesFilterBackup as IBindingList; i.Add(entity); } } break; case ListChangedType.Reset: { entities.Clear(); // We want to initially populate from the original list if there is an ongoing filer .. BindingList <T> list = (collection.entitiesFilterBackup == null) ? baseEntityList : collection.entitiesFilterBackup; foreach (T obj in list) { entities.Add(obj); } if (entitiesFilterBackup != null) { entitiesFilterBackup = null; } } break; } this.entities.RaiseListChangedEvents = orginal; }
public esDynamic(esEntity entity) { _entity = entity; }
virtual internal void OnUpdateViewNotification(object sender, ListChangedType changeType, esEntity obj) { }
internal virtual void AddEntityToDeletedList(esEntity entity) { }
public esPropertyDescriptor(esEntity entity, string name, Type propertyType) : base(name, null) { this._entity = entity; this.m_propertyType = propertyType; }
internal virtual void RemoveEntity(esEntity entity) { }
static public void Map(esSmartDto src, esEntity dst) { dst.HrydateFromDto(src); }
virtual internal void AddEntityToDeletedList(esEntity entity) { }
public override void Insert(System.Collections.IDictionary values, DataSourceViewOperationCallback callback) { esDataSourceInsertEventArgs e = null; try { e = new esDataSourceInsertEventArgs(); e.Values = values; this.OnPreInsert(e); if (e.Cancel) { return; } esDataSourceCreateEntityEventArgs ce = new esDataSourceCreateEntityEventArgs(); this.OnCreateEntity(ce); esEntity entity = ce.Entity; e.Entity = entity; if (entity != null) { entity.SetProperties(values); } //this.OnPreInsert(e); e.EventWasHandled = false; this.OnInsert(e); if (!e.EventWasHandled) { entity.Save(); this.OnDataSourceViewChanged(EventArgs.Empty); } e.EventWasHandled = false; this.OnPostInsert(e); } catch (Exception ex) { esDataSourceExceptionEventArgs exArgs = new esDataSourceExceptionEventArgs(ex); exArgs.EventType = esDataSourceEventType.Insert; exArgs.InsertArgs = e; try { this.OnException(exArgs); } catch { } if (!exArgs.ExceptionWasHandled) { throw; } } finally { callback(1, null); } }