Ejemplo n.º 1
0
        protected override void FillColumnsTable(DiagramTableItem item, Dictionary <int, Box> colNameBoxes, TableBox table)
        {
            var fkColsIndexes = GetFkColIndexes(item.Table);
            int fldindex      = 0;

            foreach (var col in item.Table.Columns)
            {
                var row = table.AddRow();
                if (item.Table.GetKeyWithColumn <IPrimaryKey>(col) != null)
                {
                    row.AddCell(CoreIcons.primary_key);
                }
                else if (fkColsIndexes.ContainsKey(col.ColumnName))
                {
                    row.AddCell(CoreIcons.foreign_key);
                }
                else
                {
                    row.AddCell(new FixedBox {
                        FixedSize = new Size(16, 16)
                    });
                }
                var cname = row.AddCell(col.ColumnName, col.IsNullable ? ColumnRegular : ColumnBold, Brushes.Black);
                if (colNameBoxes != null)
                {
                    colNameBoxes[fldindex] = cname;
                }
                row.AddCell(item.GetFullTypeName(col), ColumnRegular, Brushes.Black);
                fldindex++;
            }
        }
Ejemplo n.º 2
0
        private static void DrawPolygonalFk(Graphics g, DiagramPainter dp, DiagramTableItem fromTable, DiagramTableItem toTable, int srccolindex, int dstcolindex, ReferenceStyle style)
        {
            Pen pen   = dp.GetPen(style.LineColor, style.LineWidth);
            int extwi = style.PolygonalHorDistance;

            var possibilities = new List <_Tmp>();

            possibilities.Add(new _Tmp {
                xsrc = fromTable.Left, dirsrc = -1, xdst = toTable.Left, dirdst = -1
            });
            possibilities.Add(new _Tmp {
                xsrc = fromTable.Left, dirsrc = -1, xdst = toTable.Right, dirdst = 1
            });
            possibilities.Add(new _Tmp {
                xsrc = fromTable.Right, dirsrc = 1, xdst = toTable.Left, dirdst = -1
            });
            possibilities.Add(new _Tmp {
                xsrc = fromTable.Right, dirsrc = 1, xdst = toTable.Right, dirdst = 1
            });

            _Tmp minpos = possibilities.MinKey(p => Math.Abs(p.xsrc - p.xdst));

            Point src = new Point(minpos.xsrc, fromTable.Y + fromTable.GetColumnJoinY(srccolindex));
            Point dst = new Point(minpos.xdst, toTable.Y + toTable.GetColumnJoinY(dstcolindex));

            g.DrawLine(pen, src.X, src.Y, src.X + extwi * minpos.dirsrc, src.Y);
            g.DrawLine(pen, src.X + extwi * minpos.dirsrc, src.Y, dst.X + extwi * minpos.dirdst, dst.Y);
            g.DrawLine(pen, dst.X + extwi * minpos.dirdst, dst.Y, dst.X, dst.Y);

            DrawArrow(dp, g, dst.X + extwi * minpos.dirdst, dst.Y, dst.X, dst.Y, style.Arrow);
        }
Ejemplo n.º 3
0
        public static void DrawReferences(Diagram diagram, Graphics g, DiagramPainter dp, ReferenceStyle style)
        {
            var oldmode = g.SmoothingMode;

            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            if (style.LineWay == LineWayType.Rectangular || style.LineWay == LineWayType.Direct)
            {
                DrawPointReferences(diagram, g, dp, style);
            }
            else if (style.LineWay == LineWayType.Polygonal)
            {
                foreach (DiagramTableItem fromTable in diagram.Tables)
                {
                    foreach (ForeignKey fk in fromTable.Table.GetConstraints <ForeignKey>())
                    {
                        DiagramTableItem toTable = diagram.FindTable(fk.PrimaryKeyTable);
                        if (toTable != null)
                        {
                            int srccolindex = fromTable.Table.Columns.GetIndex(fk.Columns[0].ColumnName);
                            int dstcolindex = toTable.Table.Columns.GetIndex(fk.PrimaryKeyColumns[0].ColumnName);
                            if (srccolindex < 0 || dstcolindex < 0)
                            {
                                continue;                                     // broken foreign key
                            }
                            DrawPolygonalFk(g, dp, fromTable, toTable, srccolindex, dstcolindex, style);
                        }
                    }
                }
            }
            g.SmoothingMode = oldmode;
        }
Ejemplo n.º 4
0
        public void AddTable(NameWithSchema table, Point?pt)
        {
            if (m_diagram.FindTable(table) != null)
            {
                return;
            }
            DiagramTableItem item = new DiagramTableItem(m_diagram);

            if (pt == null)
            {
                item.MustBePlaced = true;
            }
            else
            {
                item.X = pt.Value.X;
                item.Y = pt.Value.Y;
            }
            try
            {
                m_denyDraw = true;
                m_conn.ClearCaches();
                item.Table = (TableStructure)m_conn.GetTable(table).InvokeLoadStructure(TableStructureMembers.AllNoRefs);
            }
            finally
            {
                m_denyDraw = false;
            }
            m_diagram.Tables.Add(item);
            m_modified = true;
            drawPanel.Invalidate();
            labDragAndDrop.Visible = m_diagram.Tables.Count == 0;
            Usage.AddSub("add_table", table.ToString());
        }
Ejemplo n.º 5
0
 private Table AddTable(DiagramTableItem table)
 {
     if (!tables.ContainsKey(table))
     {
         tables[table] = new Table();
     }
     tables[table].Item = table;
     return(tables[table]);
 }
Ejemplo n.º 6
0
        protected override void FillColumnsTable(DiagramTableItem item, Dictionary <int, Box> colNameBoxes, TableBox table)
        {
            var fkColsIndexes = GetFkColIndexes(item.Table);

            IPrimaryKey pk       = item.Table.FindConstraint <IPrimaryKey>();
            int         fldindex = 0;

            table.ColumnDelimiter = new FixedBox {
                BackgroundBrush = Brushes.Black, FixedSize = new Size(1, 1)
            };

            if (pk != null)
            {
                foreach (IColumnStructure col in item.Table.Columns)
                {
                    if (pk.Columns.IndexOfIf(cr => cr.ColumnName == col.ColumnName) >= 0)
                    {
                        var row = table.AddRow();
                        row.AddCell("PK", ColumnBold, Brushes.Black);
                        var cname = row.AddCell(col.ColumnName, col.IsNullable ? ColumnRegular : ColumnBold, Brushes.Black);
                        if (colNameBoxes != null)
                        {
                            colNameBoxes[fldindex] = cname;
                        }
                    }
                    fldindex++;
                }
                table.RowDelimiterOverrides[pk.Columns.Count] = new FixedBox {
                    BackgroundBrush = Brushes.Black, FixedSize = new Size(1, 1), MarginTop = 2, MarginBottom = 2
                };
            }

            foreach (IColumnStructure col in item.Table.Columns)
            {
                if (pk == null || pk.Columns.IndexOfIf(cr => cr.ColumnName == col.ColumnName) < 0)
                {
                    var row = table.AddRow();
                    if (fkColsIndexes.ContainsKey(col.ColumnName))
                    {
                        row.AddCell("FK" + (fkColsIndexes[col.ColumnName] + 1).ToString(), ColumnRegular, Brushes.Black);
                    }
                    else
                    {
                        row.AddCell(new FixedBox {
                            FixedSize = new Size(16, 16)
                        });
                    }
                    var cname = row.AddCell(col.ColumnName, col.IsNullable ? ColumnRegular : ColumnBold, Brushes.Black);
                    if (colNameBoxes != null)
                    {
                        colNameBoxes[fldindex] = cname;
                    }
                }
                fldindex++;
            }
        }
Ejemplo n.º 7
0
 private void DeleteTable(DiagramTableItem table)
 {
     if (table != null)
     {
         m_diagram.Tables.Remove(table);
         m_selectedTables.Remove(table);
         drawPanel.Invalidate();
     }
     labDragAndDrop.Visible = m_diagram.Tables.Count == 0;
     UpdateEnabling();
 }
Ejemplo n.º 8
0
        private void AddReference(DiagramTableItem fromTable, DiagramTableItem toTable, ForeignKey fk, ItemSide src, ItemSide dst)
        {
            Table     from   = AddTable(fromTable);
            Table     to     = AddTable(toTable);
            Reference newref = AddReference(fk, from, to);

            if (!newref.IsMultiple)
            {
                from.AddReference(src, newref);
                to.AddReference(dst, newref);
            }
        }
Ejemplo n.º 9
0
        private void PlaceTable(DiagramTableItem table)
        {
            int ymax;

            try
            {
                ymax = (from t in m_diagram.Tables where !t.MustBePlaced select t.Bottom).Max();
            }
            catch
            {
                ymax = 0;
            }
            int y1;

            try
            {
                y1 = (from t in m_diagram.Tables where t.Bottom == ymax && !t.MustBePlaced select t.Top).Max();
            }
            catch
            {
                y1 = m_diagram.Style.Placement.MinVerticalDistance;
            }
            Interval yint    = new Interval(y1, y1 + table.Size.Height);
            int      hspace  = m_diagram.Style.Placement.MinHorizontalDistance;
            int      newleft = hspace;
            int      maxwi   = m_diagram.Style.Placement.MaxDiagramWidth;

            if (maxwi < 0)
            {
                maxwi = drawPanelContainer.Width;
            }
            foreach (var t in m_diagram.Tables)
            {
                if (t.MustBePlaced)
                {
                    continue;
                }
                if (!Interval.Intersection(t.VerInterv, yint).IsEmpty)
                {
                    newleft = Math.Max(newleft, t.Right + hspace);
                }
            }
            if (newleft + table.Size.Width > maxwi)
            {
                table.X = hspace;
                table.Y = ymax + m_diagram.Style.Placement.MinVerticalDistance;
            }
            else
            {
                table.X = newleft;
                table.Y = y1;
            }
        }
Ejemplo n.º 10
0
 private void RenameTable(DiagramTableItem table)
 {
     if (table != null)
     {
         string newname = InputBox.Run("s_new_table_name", table.Table.FullName.ToString());
         if (newname != null)
         {
             var tbl = m_conn.GetTable(table.Table.FullName);
             tbl.RenameTable(newname);
             DbObjectNameTool.RenameTable(table.Table, from t in m_diagram.Tables select t.Table, new NameWithSchema(newname));
             drawPanel.Invalidate();
         }
     }
 }
Ejemplo n.º 11
0
        public virtual Box GetEntityBox(DiagramTableItem item, Dictionary <int, Box> colNameBoxes)
        {
            var panel = new PanelBox {
                Orientation = Orientation.Vertical
            };

            panel.BorderAllBrush = Brushes.Black;
            var header = new StringBox {
                Text = item.Table.Name, Font = GetHeaderFont(), Brush = Brushes.Black
            };

            panel.Boxes.Add(header);
            var table = new TableBox();

            table.HAlign = BoxModelAlignement.Fill;
            FillColumnsTable(item, colNameBoxes, table);
            panel.Boxes.Add(table);
            header.BorderBottom = 1;
            header.PadLeft      = header.PadRight = 3;
            FillHeader(header);
            panel.BorderAll       = 1;
            panel.BorderAllBrush  = Brushes.Black;
            panel.BackgroundBrush = Brushes.White;
            var es = item.GetCurrentEntityStyle();

            if (es.IsDefinedHeader)
            {
                header.Gradient = es.HeaderBg;
                table.Gradient  = es.BodyBg;
            }
            else
            {
                panel.Gradient = es.BodyBg;
            }

            return(panel);
        }
Ejemplo n.º 12
0
 void FillFromDiagram(Diagram diagram)
 {
     // nejdrive vybereme zdrojovou a cilovou stranu
     foreach (DiagramTableItem fromTable in diagram.Tables)
     {
         foreach (ForeignKey fk in TableStructureExtension.GetConstraints <ForeignKey, ForeignKey>(fromTable.Table))
         {
             DiagramTableItem toTable = diagram.FindTable(fk.PrimaryKeyTable);
             if (toTable != null)
             {
                 Interval fromx = fromTable.HorInterv, tox = toTable.HorInterv;
                 Interval fromy = fromTable.VerInterv, toy = toTable.VerInterv;
                 ItemSide src = ItemSide.None, dst = ItemSide.None;
                 if (fromx.Intersection(tox).Size > 0)
                 {
                     if (fromy <= toy)
                     {
                         src = ItemSide.Bottom;
                         dst = ItemSide.Top;
                     }
                     if (toy <= fromy)
                     {
                         src = ItemSide.Top;
                         dst = ItemSide.Bottom;
                     }
                     // prekryv pres oba rozmery - caru nebudeme kreslit
                 }
                 else if (fromy.Intersection(toy).Size > 0)
                 {
                     if (fromx <= tox)
                     {
                         src = ItemSide.Right;
                         dst = ItemSide.Left;
                     }
                     if (tox <= fromx)
                     {
                         src = ItemSide.Left;
                         dst = ItemSide.Right;
                     }
                 }
                 else //neni prekryv ani v jedne souradnici
                 {
                     if (fromx <= tox && fromy <= toy)
                     {
                         src = ItemSide.Right;
                         dst = ItemSide.Top;
                     }
                     if (fromx >= tox && fromy <= toy)
                     {
                         src = ItemSide.Left;
                         dst = ItemSide.Top;
                     }
                     if (fromx <= tox && fromy >= toy)
                     {
                         src = ItemSide.Right;
                         dst = ItemSide.Bottom;
                     }
                     if (fromx >= tox && fromy >= toy)
                     {
                         src = ItemSide.Left;
                         dst = ItemSide.Bottom;
                     }
                 }
                 AddReference(fromTable, toTable, fk, src, dst);
             }
         }
     }
 }
Ejemplo n.º 13
0
 protected virtual void FillColumnsTable(DiagramTableItem item, Dictionary <int, Box> colNameBoxes, TableBox table)
 {
 }