private void XML_Export_Btn_Click(object sender, RoutedEventArgs e) { myModel = createModel(); XElement elements = Tools.Utils.ModelToXML(myModel); elements.Save(@"C:\Visio\" + myModel.serverName + ".xml"); }
private void Button_Click_1(object sender, RoutedEventArgs e) { myModel = dbConn.BuildModel(DBList.SelectedItem.ToString(), (bool)WithHistory.IsChecked); VisioDrawer.DrawModel(myModel, (bool)ViewsCheckbox.IsChecked, (bool)ShowVisio.IsChecked, OutputFolder.Text, (bool)physNames.IsChecked, (bool)AllFieldsCheckbox.IsChecked); }
public static void DrawModel(Model.DBModel model, bool withViews, bool showVisio, string path, bool physNames, bool allFields) { if (!System.IO.File.Exists(path + @"Files\SLModel.VSDX")) { System.Windows.MessageBox.Show("Das Template SLModel.vsdx wurde nicht unter " + path + @"Files\ gefunden. Bitte die README-Datei lesen."); return; } try { var x = -5; var y = 11; var breite = (int)Math.Sqrt(model.TablesList.Count); var hoehe = 0; var counter = 0; application = new Visio.Application(); application.Visible = showVisio; if (!System.IO.Directory.Exists(path)) { System.IO.Directory.CreateDirectory(path); } doc = application.Documents.Open(path + @"Files\SLModel.VSDX"); //doc = application.Documents.Open(Environment.CurrentDirectory + @"\Files\SLModel.VSDX"); doc.SaveAs(path + model.serverName + ".vsdx"); doc.Creator = @"Hicham Ait Ayad"; doc.Title = model.serverName; page = doc.Pages[1]; page.Name = @"Scopeland DB Model Builder"; page.AutoSize = true; visioEntityMaster = doc.Masters.get_ItemU(@"Entity"); visioAttributeMaster = doc.Masters.get_ItemU(@"Attribute"); visioConnectorMaster = doc.Masters.get_ItemU(@"Relationship"); foreach (Model.Table table in model.TablesList) { if (withViews || !table.KindOfObject.Trim().Equals("View")) { if (counter++ % breite == 0) { y -= hoehe / 2; hoehe = 0; x = -5; } Visio.Shape entity = page.Drop(visioEntityMaster, x += 5, y); if (allFields && table.Fields.Count > hoehe) { hoehe = table.Fields.Count; } else if (!allFields) { foreach (Model.Field field in table.Fields) { hoehe += model.FieldList.Contains(field) ? 1 : 0; } } Array members = entity.ContainerProperties.GetListMembers(); foreach (int member in members) { entity.Shapes.ItemFromID[member].Delete(); } //tablesID.Add(table.Name, entity.ID); //printProperties(entity.Shapes); entity.Text = physNames ? table.Name : table.NameD; int i = 1; foreach (Model.Field field in table.Fields) { if (allFields || model.FieldList.Contains(field)) { Visio.Shape attribute = page.Drop(visioAttributeMaster, 0, 0); field.ShapeID = attribute.UniqueID[(short)Visio.VisUniqueIDArgs.visGetOrMakeGUID]; //fieldsID.Add(field.Table.Name + "_" + field.Name, attribute.ID); attribute.Text = physNames ? field.Name : field.NameD; entity.ContainerProperties.InsertListMember(attribute, i++); //entity.ContainerProperties.AddMember(visioAttributeMaster, Visio.VisMemberAddOptions.visMemberAddUseResizeSetting); } } } } page.CreateSelection(Visio.VisSelectionTypes.visSelTypeAll).Layout(); foreach (Model.Relation relation in model.RelationsList) { if (relation.FromField.ShapeID != null && relation.ToField.ShapeID != null && relation.TypeFrom != null && relation.TypeTo != null) { int index; if ((relation.TypeFrom.Substring(3).Equals(">>") && relation.TypeTo.Substring(3).Equals("->")) || (relation.TypeFrom.Substring(3).Equals("->") && relation.TypeTo.Substring(3).Equals(">>"))) { fromField = relation.TypeFrom.Substring(3).Equals(">>") ? page.Shapes.ItemFromUniqueID[relation.ToField.ShapeID] : page.Shapes.ItemFromUniqueID[relation.FromField.ShapeID]; toField = relation.TypeFrom.Substring(3).Equals(">>") ? page.Shapes.ItemFromUniqueID[relation.FromField.ShapeID] : page.Shapes.ItemFromUniqueID[relation.ToField.ShapeID]; index = 0; } else { if (relation.TypeFrom.Substring(3).Equals(">>") && relation.TypeTo.Substring(3).Equals(">>")) { fromField = page.Shapes.ItemFromUniqueID[relation.FromField.ShapeID]; toField = page.Shapes.ItemFromUniqueID[relation.ToField.ShapeID]; index = 2; } else { fromField = page.Shapes.ItemFromUniqueID[relation.FromField.ShapeID]; toField = page.Shapes.ItemFromUniqueID[relation.ToField.ShapeID]; index = 1; } } ConnectWithDynamicGlueAndConnector(fromField, toField, index); } } page.AutoSizeDrawing(); } catch (Exception e) { System.Windows.MessageBox.Show(e.Message); } finally { doc.Save(); if (showVisio) { application.Quit(); } } System.Windows.MessageBox.Show("All done!"); }