/// <summary> /// Ritorna un valore accessorio ripreso dalla query di caricamento lista. /// Utile per ricerche che ritornano dati aggiuntivi rispetto agli oggetti stessi /// </summary> /// <param name="index"></param> /// <param name="columnName"></param> /// <returns></returns> public object GetExtraValue(int index, string columnName) { if (index < 0 || index >= this.Count) { throw new ObjectException(Resources.ObjectMessages.Base_IndexOutOfBounds, this.GetType().Name, index); } InnerDataListItem item = this.mInnerList[index]; if (item.ExtraData == null) { throw new ObjectException("ExtraValue non presenti", this.GetType().Name, index); } object oRet = null; if (!item.ExtraData.TryGetValue(columnName, out oRet)) { throw new ObjectException(Resources.ObjectMessages.List_UnknownColumn, this.GetType().Name, columnName); } return(oRet); }
internal protected void setItem(int index, DataObjectBase value) { var oOldInnerList = this.mInnerList[index]; //Se trattasi dello stesso oggetto non fa nulla if (object.ReferenceEquals(oOldInnerList.Object, value)) { return; } //Imposta nuovo elemento per evitare che tutte le eventuali sottoliste ereditino la modifica (sara' giusto???) var oNewInnerItem = new InnerDataListItem() { Object = value, PkValues = this.mObjSchema.PrimaryKey.GetValues(value), PkHashCode = value.GetHashBaseString() }; //Lo imposta this.mInnerList[index] = oNewInnerItem; this.fireListChanged(ListChangedType.ItemChanged, index); }
/// <summary> /// Riempie la lista interna da reader /// </summary> /// <param name="reader"></param> internal protected void fillListFromReader(DbDataReader reader) { int iFieldCount = (this.IsPaged) ? reader.FieldCount - 1 : reader.FieldCount; while (reader.Read()) { //Imposta totale records da ultima colonna della query. Se non oertinente allora imposta -1 if (this.IsPaged && this.Pager.TotRecords == 0) { var oTotRecs = reader[reader.FieldCount - 1]; if (oTotRecs is Int32) { this.Pager.TotRecords = (Int32)oTotRecs; } else { this.Pager.TotRecords = -1; } } InnerDataListItem oItem = new InnerDataListItem(); oItem.PkValues = new object[this.mObjSchema.PrimaryKey.Properties.Count]; for (int i = 0; i < this.mObjSchema.PrimaryKey.Properties.Count; i++) { if (reader.IsDBNull(i)) { oItem.PkValues[i] = null; } else { oItem.PkValues[i] = reader.GetValue(i); } } //Se presenti valori oltre la pk li salva (se non prefetch) if (!this.mIsSearch && iFieldCount > this.mObjSchema.PrimaryKey.Properties.Count) { oItem.ExtraData = new Dictionary <string, object>(); for (int i = this.mObjSchema.PrimaryKey.Properties.Count; i < iFieldCount; i++) { oItem.ExtraData.Add(reader.GetName(i), reader[i]); } } //Se attivo LoadObjects allora prova a caricare il singolo oggetto dal reader e lo imposta nell'Item if (this.mLoadFullObjects && this.mIsSearch) { //Cerca in LT if (this.Slot.LiveTrackingEnabled) { oItem.PkHashCode = ObjectHelper.GetObjectHashString(this.Slot, this.mObjSchema, oItem.PkValues); oItem.Object = this.Slot.liveTrackingGet(oItem.PkHashCode); } //Se non trovato if (oItem.Object == null) { //Crea oggetto vuoto oItem.Object = this.Slot.CreateObjectByType(this.mObjSchema.OriginalType); //Carica dati oItem.Object.FillObjectFromReader(reader, false); oItem.PkValues = oItem.Object.mClassSchema.PrimaryKey.GetValues(oItem.Object); //Prova ad inserire nelle cache this.Slot.CacheSetAny(oItem.Object); } } //Aggiunge a lista this.mInnerList.Add(oItem); } //Se presente un resultset aggiuntivo allora assume che sia il numero di record if (reader.NextResult()) { if (reader.Read()) { this.Pager.TotRecords = reader.GetInt32(0); } } }