首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Visio和C#编程

Visio和C#编程
EN

Stack Overflow用户
提问于 2013-11-11 00:12:08
回答 1查看 2.3K关注 0票数 2

我有一个Visio ER关系图,并希望从实体中读取数据库属性(列、主键、外键、数据类型)信息。还希望找到相关的父表和子表。我如何使用C#以编程方式实现它?

我正在使用Interop Visio库,可以从ER图表中读取页面和形状,但不知道Visio interop中的哪些函数或方法可以让我从形状中获取属性信息。

下面是我正在使用的代码,我没有使用它获得任何属性。我的ER图只有两个实体,一个父表和一个子表。

代码语言:javascript
复制
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Office.Interop.Visio;


namespace Visio_POC
{
public partial class Load_Visio : Form
{
    static string strProperties = "";
    public Load_Visio()
    {
        InitializeComponent();
        string strFileName = "\\Visio_POC\\POC_Visio.vsd";
        Microsoft.Office.Interop.Visio.Application vsApp = new   Microsoft.Office.Interop.Visio.Application();
        Microsoft.Office.Interop.Visio.Document docVisio = vsApp.Documents.Add(strFileName);
        Page pgVisio = docVisio.Pages[1];
        Shapes shpVisio = pgVisio.Shapes;
        int intCnt = shpVisio.Count;
        string[] strShapeText = new string[intCnt];

        printProperties(pgVisio.Shapes);
        txtProperties.Text = strProperties;
    }

   public static void printProperties(Shapes shapes)
    {
        // Look at each shape in the collection.
        foreach (Shape shape in shapes)
        {               
            // Use this index to look at each row in the properties 
            // section.
            short iRow = (short) VisRowIndices.visRowFirst;

            // While there are stil rows to look at.
            while (shape.get_CellsSRCExists(
                (short) VisSectionIndices.visSectionProp, 
                iRow, 
                (short) VisCellIndices.visCustPropsValue,
                (short) 0) != 0)
            {
                // Get the label and value of the current property.
                string label = shape.get_CellsSRC(
                        (short) VisSectionIndices.visSectionProp, 
                        iRow,
                        (short) VisCellIndices.visCustPropsLabel
                    ).get_ResultStr(VisUnitCodes.visNoCast);

                string value = shape.get_CellsSRC(
                        (short) VisSectionIndices.visSectionProp, 
                        iRow,
                        (short) VisCellIndices.visCustPropsValue
                    ).get_ResultStr(VisUnitCodes.visNoCast);

                // Print the results.
                //Console.WriteLine(string.Format(
                //    "Shape={0} Label={1} Value={2}",
                //    shape.Name, label, value));

                strProperties = strProperties + shape.Name + " - " + label + " - " + value;

                // Move to the next row in the properties section.
                iRow++;
            }

            // Now look at child shapes in the collection.
            if (shape.Master == null && shape.Shapes.Count > 0)
                printProperties(shape.Shapes);
        }
    }
}    
}
EN

回答 1

Stack Overflow用户

发布于 2016-02-10 03:59:44

数据库逆向工程是一个封闭的解决方案。有一本由Terry Halpin写的书“数据库建模”就介绍了这一点。或者,您可以仔细阅读我在http://blog.bvisual.net/2014/03/26/creating-a-schema-from-visio-external-data-record-sets/上的文章,了解如何自己做这件事。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19891923

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档