簡體   English   中英

Visio和C#編程

[英]Visio & C# Programming

我有一個Visio ER圖,想從實體讀取數據庫屬性(列,主鍵,外鍵,數據類型)信息。 還想找到關聯的父表和子表。 如何使用C#以編程方式實現它?

我正在使用Interop Visio庫,可以從ER圖中讀取頁面和形狀,但是不知道Visio interop中的哪些函數或方法會讓我從Shape中獲取屬性信息。

下面是我正在使用的代碼,但我沒有使用它的任何屬性。 我的ER圖只有兩個實體,一個父表和一個子表。

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);
        }
    }
}    
}

數據庫逆向工程是一個封閉的解決方案。 特里·哈爾平(Terry Halpin)有一本書“數據庫建模”對此進行了介紹。 另外,您可以在http://blog.bvisual.net/2014/03/26/creating-a-schema-from-visio-external-data-record-sets/閱讀我的文章,以了解如何做你自己

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM