예제 #1
0
        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);
        }
        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();
        }
        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();
        }
예제 #4
0
        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);
            }
        }
예제 #5
0
        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();
        }