protected void AddItem(ChildBusinessObject item, int index) { if (item.IsNew && item.ID.ToInt32 == 0) { _autoKey--; ChildBusinessObject.Factory.SetID(item, new ID(_autoKey)); } ID keyID = GetKeyID(item); int curIndex; if (_hashtable.Contains(keyID)) { curIndex = (int)_hashtable[keyID]; InnerList[curIndex] = item; } else { InnerList.Insert(index, item); _hashtable.Add(keyID, index); // Update Index for (int i = index; i < InnerList.Count; i++) { ChildBusinessObject mc = (ChildBusinessObject)InnerList[i]; _hashtable[GetKeyID(mc)] = i; } } }
protected virtual void RemoveItem(ChildBusinessObject item) { if (item != null) { item.SetParent(null); if (!item.IsNew) { _removedItems.Add(item); } } InnerList.Remove(item); }
protected void SetItem(int index, ChildBusinessObject item) { if (InnerList[index] != null) { ((ChildBusinessObject)InnerList[index]).SetParent(null); } if (item != null) { item.SetParent(_parent); } InnerList[index] = item; }
protected void Swap(ChildBusinessObject obj1, ChildBusinessObject obj2) { int nIndex1 = this.GetIndex(obj1.ID); int nIndex2 = this.GetIndex(obj2.ID); this.RemoveItem(obj1); this.RemoveItem(obj2); if (this.Count < nIndex1) { this.AddItem(obj2); this.AddItem(obj1); } else { this.AddItem(obj2, nIndex1); this.AddItem(obj1, nIndex2); } }
protected override void RemoveItem(ChildBusinessObject item) { ID key = GetKeyID(item); if (_hashtable.Contains(key)) { int index = (int)_hashtable[key]; _hashtable.Remove(key); base.RemoveItem(item); // Update Index for (int i = index; i < InnerList.Count; i++) { ChildBusinessObject child = (ChildBusinessObject)InnerList[i]; _hashtable[GetKeyID(child)] = i; } } }
protected override int AddItem(ChildBusinessObject item) { if (item.IsNew && item.ID.ToInt32 == 0) { _autoKey--; BusinessObject.Factory.SetID(item, new ID(_autoKey)); } ID keyID = GetKeyID(item); int index; if (_hashtable.Contains(keyID)) { index = (int)_hashtable[keyID]; base.SetItem(index, item); } else { index = base.AddItem(item); _hashtable.Add(keyID, index); } return(index); }
protected virtual ID GetKeyID(ChildBusinessObject item) { return(item.ID); }
protected virtual int AddItem(ChildBusinessObject item) { item.SetParent(_parent); return(InnerList.Add(item)); }