public EditTernaryRelationship(RelationshipShape relationship) { InitializeComponent(); Relationship = new RelationshipShape(relationship.sName, new Point(panelDoubleBuffered1.Width / 2, panelDoubleBuffered1.Height / 2), relationship.type); SelectedEntity1 = new EntityShape(relationship.cardinalities[0].Entity.sName, new Point(panelDoubleBuffered1.Width / 2, ThongSo.ShapeH / 2), relationship.cardinalities[0].Entity.type); SelectedEntity2 = new EntityShape(relationship.cardinalities[1].Entity.sName, new Point(panelDoubleBuffered1.Width / 2 - ThongSo.ShapeW * 3/2, panelDoubleBuffered1.Height - ThongSo.ShapeH/2), relationship.cardinalities[1].Entity.type); SelectedEntity3 = new EntityShape(relationship.cardinalities[2].Entity.sName, new Point(panelDoubleBuffered1.Width / 2 + ThongSo.ShapeW * 3/2, panelDoubleBuffered1.Height - ThongSo.ShapeH/2), relationship.cardinalities[2].Entity.type); cardi1 = Relationship.CreateCardinality(SelectedEntity1, relationship.cardinalities[0].MinCardinality, relationship.cardinalities[0].MaxCardinality); cardi2 = Relationship.CreateCardinality(SelectedEntity2, relationship.cardinalities[1].MinCardinality, relationship.cardinalities[1].MaxCardinality); cardi3 = Relationship.CreateCardinality(SelectedEntity3, relationship.cardinalities[2].MinCardinality, relationship.cardinalities[2].MaxCardinality); panelDoubleBuffered1.Controls.Add(Relationship); panelDoubleBuffered1.Controls.Add(SelectedEntity1); panelDoubleBuffered1.Controls.Add(SelectedEntity2); panelDoubleBuffered1.Controls.Add(SelectedEntity3); panelDoubleBuffered1.Refresh(); int min1, max1, min2, max2, min3, max3; min1 = Relationship.cardinalities[0].MinCardinality; max1 = Relationship.cardinalities[0].MaxCardinality; min2 = Relationship.cardinalities[1].MinCardinality; max2 = Relationship.cardinalities[1].MaxCardinality; min3 = Relationship.cardinalities[2].MinCardinality; max3 = Relationship.cardinalities[2].MaxCardinality; setCardinality(min1, max1, imageComboBoxEdit1); setCardinality(min2, max2, imageComboBoxEdit2); setCardinality(min3, max3, imageComboBoxEdit3); showText(); }
//Đ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 override ShapeBase Clone() { CardinalityShape cardi = new CardinalityShape(); cardi.Entity = Entity; cardi.MinCardinality = MinCardinality; cardi.MaxCardinality = MaxCardinality; cardi._relationship = _relationship; return (ShapeBase)cardi; }
public override ShapeBase Clone() { CardinalityShape cardi = new CardinalityShape(); cardi.Entity = Entity; cardi.MinCardinality = MinCardinality; cardi.MaxCardinality = MaxCardinality; cardi._relationship = _relationship; return((ShapeBase)cardi); }
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); } } } } } } } }
public void getCardiPosition(CardinalityShape cardi, ref int direction, ref int index) { for (int i = 0; i < 4; i++) { for (int j = 0; j < cardiplaces[i].Count; j++) { if (cardi == cardiplaces[i][j]) { direction = i + 1; index = j; } } } }
public CardinalityShape CreateCardinality(EntityShape en, int min, int max) { CardinalityShape cardi = new CardinalityShape(en); cardi.setValue(min, max); cardinalities.Add(cardi); cardi.Relationship = this; en.AddCardiPlace(cardi); this.AddCardiPlace(cardi); cardi.Disposed += new EventHandler(cardi_Disposed); return(cardi); }
public AddCardinality(RelationshipShape relationship) { InitializeComponent(); Relationship = new RelationshipShape(relationship.sName, new Point(panelDoubleBuffered1.Width / 2, panelDoubleBuffered1.Height / 2), relationship.type); SelectedEntity1 = new EntityShape(relationship.cardinalities[0].Entity.sName, new Point(panelDoubleBuffered1.Width / 2 - ThongSo.ShapeW * 3/2, panelDoubleBuffered1.Height / 2), relationship.cardinalities[0].Entity.type); SelectedEntity2 = new EntityShape(relationship.cardinalities[1].Entity.sName, new Point(panelDoubleBuffered1.Width / 2 + ThongSo.ShapeW * 3/2, panelDoubleBuffered1.Height / 2), relationship.cardinalities[1].Entity.type); cardi1 = Relationship.CreateCardinality(SelectedEntity1, relationship.cardinalities[0].MinCardinality, relationship.cardinalities[0].MaxCardinality); cardi2 = Relationship.CreateCardinality(SelectedEntity2, relationship.cardinalities[1].MinCardinality, relationship.cardinalities[1].MaxCardinality); panelDoubleBuffered1.Controls.Add(Relationship); panelDoubleBuffered1.Controls.Add(SelectedEntity1); panelDoubleBuffered1.Controls.Add(SelectedEntity2); panelDoubleBuffered1.Refresh(); int min1, max1, min2, max2; min1 = Relationship.cardinalities[0].MinCardinality; max1 = Relationship.cardinalities[0].MaxCardinality; min2 = Relationship.cardinalities[1].MinCardinality; max2 = Relationship.cardinalities[1].MaxCardinality; if (min1 == 0 && max1 == 1) imageComboBoxEdit1.SelectedIndex = 0; if (min1 == 1 && max1 == 1) imageComboBoxEdit1.SelectedIndex = 1; if (min1 == 0 && max1 == -1) imageComboBoxEdit1.SelectedIndex = 2; if (min1 == 1 && max1 == -1) imageComboBoxEdit1.SelectedIndex = 3; if (min2 == 0 && max2 == 1) imageComboBoxEdit2.SelectedIndex = 0; if (min2 == 1 && max2 == 1) imageComboBoxEdit2.SelectedIndex = 1; if (min2 == 0 && max2 == -1) imageComboBoxEdit2.SelectedIndex = 2; if (min2 == 1 && max2 == -1) imageComboBoxEdit2.SelectedIndex = 3; showText(); }
public override ShapeBase Clone() { RelationshipShape rel = new RelationshipShape(); rel.sName = sName; rel.type = type; rel.Size = this.Size; rel.Location = Location; foreach (AttributeShape att in attributes) { rel.addAttribute((AttributeShape)att.Clone()); } foreach (CardinalityShape cardi in cardinalities) { CardinalityShape newcardi = (CardinalityShape)cardi.Clone(); rel.CreateCardinality(newcardi.Entity, newcardi.MinCardinality, newcardi.MaxCardinality); } return((ShapeBase)rel); }
private int CalculateCardiPosition(CardinalityShape cardi, int newEdgeCardiPlace) { int index = 0; foreach (CardinalityShape cardiInRel in this.cardiplaces[newEdgeCardiPlace - 1]) { if (newEdgeCardiPlace == 1 || newEdgeCardiPlace == 3) //Up hoặc down thì so sánh x { if (cardi.Entity.Location.X > cardiInRel.Entity.Location.X) { index++; } } else //right hoặc left thì so sánh y { if (cardi.Entity.Location.Y > cardiInRel.Entity.Location.Y) { index++; } } } return(index); }
void SetLocationTree(EntityShape entity, int degree, int line) { entity.Location = new Point(this.Width / 2 - entity.Width / 2, 150 * line); int stepX = this.Width / (degree + 1); for (int i = 0; i < 4; i++) { for (int j = 0; j < entity.cardinalities[i].Count; j++) { CardinalityShape cardi = new CardinalityShape(); foreach (CardinalityShape cardi2 in entity.cardinalities[i][j].Relationship.cardinalities) { if (cardi2 != entity.cardinalities[i][j]) cardi = cardi2; } EntityShape entity2 = cardi.Entity; entity2.Location = new Point(stepX, 150 * (line + 1)); stepX += this.Width / (degree + 1); Point centerEntity1 = new Point(entity.Location.X + entity.Width / 2, entity.Location.Y + entity.Height / 2); Point centerEntity2 = new Point(entity2.Location.X + entity2.Width / 2, entity2.Location.Y + entity2.Height / 2); Point center = new Point(Math.Abs(centerEntity1.X + centerEntity2.X) / 2, Math.Abs(centerEntity1.Y + centerEntity2.Y) / 2); cardi.Relationship.Location = new Point(center.X - cardi.Relationship.Width / 2, center.Y - cardi.Relationship.Height / 2); } } }
private int CalculateCardiPosition(CardinalityShape cardi, int newEdgeCardiPlace) { int index = 0; foreach (CardinalityShape cardiInEntity in this.cardinalities[newEdgeCardiPlace - 1]) { if (newEdgeCardiPlace == 1 || newEdgeCardiPlace == 3) //Up hoặc down thì so sánh x { if (cardi.Relationship.Location.X > cardiInEntity.Relationship.Location.X) index++; } else //right hoặc left thì so sánh y { if (cardi.Relationship.Location.Y > cardiInEntity.Relationship.Location.Y) index++; } } return index; }
//Đ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.Relationship); int index = CalculateCardiPosition(cardi, EdgeCardiPlace); cardinalities[EdgeCardiPlace - 1].Insert(index, cardi); cardi.Disposed += new EventHandler(cardi_Disposed); }
public void getCardiPosition(CardinalityShape cardi, ref int direction, ref int index) { for (int i = 0; i < 4; i++) for (int j = 0; j < cardiplaces[i].Count; j++) { if (cardi == cardiplaces[i][j]) { direction = i + 1; index = j; } } }
public CardinalityShape CreateCardinality(EntityShape en, int min, int max) { CardinalityShape cardi = new CardinalityShape(en); cardi.setValue(min, max); cardinalities.Add(cardi); cardi.Relationship = this; en.AddCardiPlace(cardi); this.AddCardiPlace(cardi); cardi.Disposed += new EventHandler(cardi_Disposed); return cardi; }
private static Bitmap GetCardinalitiesShape(CardinalityShape cardi, int edgeCardiPlace, Color backgroundColor) { Bitmap carshape = new Bitmap(20, 20); Graphics gimage = Graphics.FromImage(carshape); if (cardi.MaxCardinality == -1) { gimage.DrawLine(ThongSo.ConectiveLinePen, new Point(10, 8), new Point(3, 20)); gimage.DrawLine(ThongSo.ConectiveLinePen, new Point(10, 8), new Point(17, 20)); gimage.DrawLine(ThongSo.ConectiveLinePen, new Point(10, 0), new Point(10, 20)); if (cardi.MinCardinality == 0) { gimage.FillEllipse(new SolidBrush(backgroundColor), 7, 0, 6, 6); gimage.DrawEllipse(ThongSo.ConectiveLinePen, 7, 0, 6, 6); } else gimage.DrawLine(ThongSo.ConectiveLinePen, new Point(3, 5), new Point(17, 5)); } else { gimage.DrawLine(ThongSo.ConectiveLinePen, new Point(3, 13), new Point(17, 13)); gimage.DrawLine(ThongSo.ConectiveLinePen, new Point(10, 0), new Point(10, 20)); if (cardi.MinCardinality == 0) { gimage.FillEllipse(new SolidBrush(backgroundColor), 7, 3, 6, 6); gimage.DrawEllipse(ThongSo.ConectiveLinePen, 7, 3, 6, 6); } else gimage.DrawLine(ThongSo.ConectiveLinePen, new Point(3, 8), new Point(17, 8)); } switch (edgeCardiPlace) { case 1: break; case 2: carshape.RotateFlip(RotateFlipType.Rotate90FlipNone); break; case 3: carshape.RotateFlip(RotateFlipType.Rotate180FlipNone); break; case 4: carshape.RotateFlip(RotateFlipType.Rotate270FlipNone); break; } return carshape; }
public static void DrawCardinalitiesLine(Graphics g, CardinalityShape cardi, int EntityEdgeCardiPlace, int pos, int numCardi, Color backgroundColor) { EntityShape entity = cardi.Entity; RelationshipShape rel = cardi.Relationship; //debug //g.DrawLine(new Pen(Color.Red, 1), entity.CenterPoint, rel.CenterPoint); Point centerRelationship = rel.CenterPoint; Point centerEntity = entity.CenterPoint; Point TopLeft = entity.Location; Point BottomRight = new Point(entity.Location.X + entity.Width, entity.Location.Y + entity.Height); int stepX = pos * entity.Width / (numCardi + 1); int stepY = pos * entity.Height / (numCardi + 1); Bitmap myCardi = GetCardinalitiesShape(cardi, EntityEdgeCardiPlace, backgroundColor); Point EntityStartPos = getStartPos(EntityEdgeCardiPlace, (ShapeBase)entity, TopLeft, BottomRight, stepX, stepY, myCardi); Point EntityCardiPos = getCardiPos(EntityEdgeCardiPlace, (ShapeBase)entity, TopLeft, BottomRight, stepX, stepY, myCardi); if (rel.type != RelationshipType.AssociativeEntity) { g.DrawImage(myCardi, EntityCardiPos); g.DrawLine(ThongSo.ConectiveLinePen, EntityStartPos, centerRelationship); } else //nếu relationship là Associative Entity { Point TopLeftRel = rel.Location; Point BottomRightRel = new Point(rel.Location.X + rel.Width, rel.Location.Y + rel.Height); int AssEdgeCardiPlace = 0, index = 0; rel.getCardiPosition(cardi, ref AssEdgeCardiPlace, ref index); int stepXRel = (index + 1) * rel.Width / (rel.cardiplaces[AssEdgeCardiPlace - 1].Count + 1); int stepYRel = (index + 1) * rel.Height / (rel.cardiplaces[AssEdgeCardiPlace - 1].Count + 1); //cardi 1, 1 CardinalityShape cardi1 = new CardinalityShape(); cardi1.setValue(1, 1); //lấy cardi của đầu bên kia Relationship CardinalityShape cardi2 = new CardinalityShape(); foreach (CardinalityShape card in cardi.Relationship.cardinalities) { if (card != cardi) cardi2 = card; } Bitmap CardiAtEn = GetCardinalitiesShape(cardi1, EntityEdgeCardiPlace, backgroundColor); Bitmap CardiAtRel = GetCardinalitiesShape(cardi2, AssEdgeCardiPlace, backgroundColor); Point AssStartPos = getStartPos(AssEdgeCardiPlace, (ShapeBase)rel, TopLeftRel, BottomRightRel, stepXRel, stepYRel, CardiAtRel); Point AssCardiPos = getCardiPos(AssEdgeCardiPlace, (ShapeBase)rel, TopLeftRel, BottomRightRel, stepXRel, stepYRel, CardiAtRel); g.DrawImage(CardiAtEn, EntityCardiPos); g.DrawImage(CardiAtRel, AssCardiPos); g.DrawLine(ThongSo.ConectiveLinePen, EntityStartPos, AssStartPos); } }
private void RenderPreview(ComboBoxEdit imageComboBox, CardinalityShape cardi) { switch (imageComboBox.EditValue.ToString()) { case "0, 1": cardi.setValue(0, 1); break; case "1, 1": cardi.setValue(1, 1); break; case "0, n": cardi.setValue(0, -1); break; case "1, n": cardi.setValue(1, -1); break; } panelDoubleBuffered1.Refresh(); }