Hola estoy trabajando en la parte de como hacer un organigrama en VISIO pero con programación C#, ademas tomar los datos de una base de datos SQL Server.
Hasta Ahorita solo llevo crear documentos, y rectángulos. Gracias.
Este código abre un documento de Visio (Office)
using Microsoft.Office.Interop.Visio;
private void button1_Click(object sender, EventArgs e)
{
string strFileName = "C:\\carpeta\\carpeta\\carpeta\\testOrg.vsdx";
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;
}
El siguiente código crea un Shape (Rectángulo) (shape.Text, es un Label)
using Microsoft.Office.Interop.Visio;
private void button2_Click(object sender, EventArgs e)
{
Microsoft.Office.Interop.Visio.Application visapp = new Microsoft.Office.Interop.Visio.Application();
Microsoft.Office.Interop.Visio.Document doc = visapp.Documents.Add("");
Microsoft.Office.Interop.Visio.Page page = visapp.ActivePage;
Microsoft.Office.Interop.Visio.Shape shape = page.DrawRectangle(1, 1, 5, 4);
//shape = visapp.ActivePage.DropConnected()
//page.ConnectionsAdded
shape.Text = "Hello World";
}
El siguiente Link tiene algo a lo que busco, pero aun no lo puedo generar. https://www.codeproject.com/Articles/109558/Creating-VISIO-Organigrams-using-C
Comparto también el código de mi conexión a Base de Datos
class Conexion
{
static string conectionString = "Server=MISERVER;Database=MIDATABASE;Uid=USER;Pwd=PASS;";
protected SqlConnection sqlcon = new SqlConnection(conectionString);
/// <summary>
/// Busca los datos dependiendo del parent id
/// </summary>
/// <param name="parentId">Es la relacion el ID</param>
/// <returns>DataTable con la informacion</returns>
public DataTable getParentIDs(int parentId)
{
SqlCommand cmmd = new SqlCommand();
DataTable dt = new DataTable();
SqlDataAdapter adapter = new SqlDataAdapter();
try
{
this.sqlcon.Open();
cmmd.Connection = this.sqlcon;
cmmd.CommandText = "select * from tabla_a (nolock) where parentid = @parentid";
cmmd.Parameters.Add("@parentid", SqlDbType.Int).Value = parentId;
adapter.SelectCommand = cmmd;
adapter.Fill(dt);
this.sqlcon.Close();
return dt;
}catch(Exception ex)
{
Console.WriteLine("Aviso: " + ex.Message);
return dt;
}
}
}