//Đoạn này nhìn vậy thực ra kiếm cả ngày mới ra //Ý tưởng: trên Draw Board, khi user delete 1 Attribute bất kỳ //Phải kiểm tra xem Attribute đó thuộc Entity/Relationship nào để remove nó trong //list Attributes của Entity/Relationship đó đi //Vấn đề 1: từ Entity/Relationship biết Attribute, nhưng từ Attribute không biết được Entity // -> Tạo biến parent giữ Entity/Relationship --> code dài, phụ thuộc nhiều quá, chưa tính Relationship //Vấn đề 2: wá nhiều Entity, wá nhiều Attribute để kiểm tra // -> Mong muốn khi xóa Attribute thì những reference tới Attribute đó cũng xóa theo // -> Trong C dùng con trỏ là Ok rồi //--> Final Solution: Event + Callback Function, wá ngắn //www.msdner.com //Key: Can I dispose of instances without explicitly removing all references to them? public void AddCardiPlace(CardinalityShape cardi) { int EdgeCardiPlace = DrawingSupport.CalculateCardiDirection(this, cardi.Entity); int index = CalculateCardiPosition(cardi, EdgeCardiPlace); cardiplaces[EdgeCardiPlace - 1].Insert(index, cardi); cardi.Disposed += new EventHandler(cardiplace_Disposed); }
public void UpdateCardinalityPosition() { if (this.type == RelationshipType.AssociativeEntity) { for (int i = 0; i < 4; i++) { //update all cardinality of this relationship for (int j = 0; j < this.cardiplaces[i].Count; j++) { CardinalityShape cardi = this.cardiplaces[i][j]; EntityShape entity = cardi.Entity; int oldEdgeCardiPlace = i + 1; int newEdgeCardiPlace = DrawingSupport.CalculateCardiDirection(this, entity); //Chổ này làm kỹ, không thôi nó giựt wài ghét lắm //Nếu vị trí mới tính được khác vị trí cũ if (oldEdgeCardiPlace != newEdgeCardiPlace) { //remove old and add new this.cardiplaces[oldEdgeCardiPlace - 1].Remove(cardi); int index = CalculateCardiPosition(cardi, newEdgeCardiPlace); this.cardiplaces[newEdgeCardiPlace - 1].Insert(index, cardi); } else //Nếu vẫn là vị trí cũ, thì tính lại thứ tự trong vị trí đó { //just update the position for (int k = 0; k < this.cardiplaces[oldEdgeCardiPlace - 1].Count - 1; k++) { if (oldEdgeCardiPlace == 1 || oldEdgeCardiPlace == 3) //Up hoặc down thì so sánh x { if (this.cardiplaces[oldEdgeCardiPlace - 1][k].Relationship.Location.X > this.cardiplaces[oldEdgeCardiPlace - 1][k + 1].Relationship.Location.X) { this.cardiplaces[oldEdgeCardiPlace - 1].Reverse(k, 2); } } else //right hoặc left thì so sánh y { if (this.cardiplaces[oldEdgeCardiPlace - 1][k].Relationship.Location.Y > this.cardiplaces[oldEdgeCardiPlace - 1][k + 1].Relationship.Location.Y) { this.cardiplaces[oldEdgeCardiPlace - 1].Reverse(k, 2); } } } } } } } }