Nevron Forum

Database Table Shapes and Mapping

https://www.nevron.com/Forum/Topic2900.aspx

By Montford Chelliah - Thursday, January 14, 2010

Hi,

 

I have a tree control and that contains two databases with tables as tree nodes. I have a requirement to drag couple of tables from these databases (from tree) and drop on them as Nevron shape on Nevron canvas. What is the recommended shape you suggest? (I need to display table columns and data type and PK/FK relation text)

 

After drag and drop of these tables, I need to visually map the fields between tables using Nevron connectors, what type of connector shape can I use?

 

After mapping the fields visually, I need to identify the mapping relationship (which field is mapped with which field between table shapes) by .NET code in the diagram.  How can I do this?

 

Please suggest me the recommended shapes and methodology. I have tried couple of shapes (NErmShape and NTableShape) I could not find out the mapping relationship.

 

Thanks in advance.

 

 

Regards

Montford Anslum

By Pavel Vladov - Thursday, January 14, 2010

Hi Montford,

If you use the database schema importer it will automatically create diagram shapes (of type NErmShape) for the tables and connect them based on their relationships. For an example of how to use the database schema importer take a look at this online example.

Questions or comments, please let me know.


Best Regards,
Pavel Vladov

By Montford Chelliah - Friday, January 15, 2010

Hi Pavel,

Thanks for the reply. I saw that sample on you web site but I don't want to generate the ER diagram dynamically rather user go and manually do the drag and drop the tables on the Nevron canvas and maps the fields individually.

For example,

Database A has Patient table (fields such as Id, Firstname, Lastname, Address1, Address2) and Database B also has PatientDemographic table (fields such as PatientId, Firstname, Surname, AddressOne, AddressTwo) with different field names. I need to transfer the records from Patient (Database A) table to PatientDemographic (Database B) table. So using Nevron, user needs to visually drag Patient table from Database A and PatientDemographic from Database B, then map field by field using Nevron connectors (say Patient.Id is mapped with PatientDemographic.PatientId, Patient.Firstname is mapped with PatientDemographic.Firstname, Patient.Lastname is mapped with PatientDemographic.Surname ct.). After finished the mapping, user will click save button, I need to programatically go through the Nevron shapes and find out which field is mapped which field then save the results into database.

So this is my requirement. Please give a right direction.

 

Regards

Montford Anslum

 

By Pavel Vladov - Tuesday, January 19, 2010

Hi Montford,

I understood your requirement. What you have to do is to manually create custom ERM shape for each table, when the user drags it into the drawing view. You can easily do this by using code similar to:

NErmShape shape = new NErmShape(0, 0, 10, 10);
shape.CreateFromTable(dataTable);


Where dataTable is the table that the user has dragged into the drawing view. Next you can provide the user with the ability to connect the tables using Erm connectors.

Best Regards,
Pavel Vladov
By Montford Chelliah - Wednesday, January 20, 2010

Hi Pavel,

Could you please provide the sample code of NErmshape object. I could not found any sample application in your product samples (with the Nevron product installation). I have tried the way you suggest, I have following problems.

(1) How do I enable the Erm connector on drawing space? I have found only single connector to connect multiple shapes (like NDWFR.TooltipConnectToPort)

view.Controller.Tools.SingleEnableTool(NDWFR.TooltipConnectToPort)

(2) How do I resize the NErmshape object after populate the table object. It does not resize according to the text.

Dim shape As New NErmShape(0, 0, 10, 10)

' Populate the data table......

shape.SizeToContent()

(3) How do I include the data type column next to field column in NErmShape

Thanks

Regards

Montford Anslum

 

By Pavel Vladov - Wednesday, January 20, 2010

Hi Montford,
regarding your questions:

1. The code to activate the erm connector tool is:

NCreateConnectorTool tool = (view.Controller.Tools.GetToolByName(NDWFR.ToolCreateConnector) as NCreateConnectorTool);
if (tool == null)
return;

tool.ConnectorType = ConnectorType.ErmConnector;
view.Controller.Tools.SingleEnableTool(NDWFR.ToolCreateConnector);


Unfortunatelly, I've discovered that there's a bug when activating this tool, but I've fixed it, and it will work fine in the upcoming service pack (it is going to be released today or tomorrow) of our component.

2. In order to work properly, the SizeToContent() method of the erm shape should be called after the shape is added to the drawing document.

3. The erm shapes does not support adding such information. If you need to show more details than just the name of the column and its relation type (i.e. PK = private key or FK = foreign key), I suggest you take a look at the table shape and the UML shape examples.

Best Regards,
Pavel
By Montford Chelliah - Wednesday, January 20, 2010

Hi Pavel,

Thanks for the idea, I have tried with NTableShape object and the sample is attached herewith. Using NTableShape object I am facing a problem to identify the mappings ports and plugs. Please review my sample and identify the fault.

Thanks

Regards

Montford Anslum

By Pavel Vladov - Thursday, January 21, 2010

Hi Montford,

I've examined your code and I've attached the working solution. Some important thigs I would like to bring to your attention are:

1. When you are setting the content of table shapes use the BeginUpdate and EndUpdate method of the table shape. This will greatly improve the performance. Take a look at this topic for more information.

2. To find out the relations all you have to do is to loop through the 1D shapes of the document's active layer. For example:

    NNodeList links = document.ActiveLayer.Children(NFilters.Shape1D);
    int linkCount = links.Count;
    for (int i = 0; i < linkCount; i++)
    {
        NBezierCurveShape link = links[i] as NBezierCurveShape;
        if (link != null)
        {
            // Display a meassage for the current relation
            DisplayMessage(link);
        }
    }

3. Please, take advantage of the Name property of the NShape class and set the table names to this property, so that you can easily retrieve it later. This eliminates the need to use dictionaries in your data object adapter class.

If you have any other questions, I'll be glad to help.

Best Regards,
Pavel
By Montford Chelliah - Thursday, January 21, 2010

Hi Pavel,

Thanks so much for the help and direction. I am going to add more functionality on that code. If I face any problem I will send you the details on the this thread.

Thanks

Regards

Montford Anslum

By Montford Chelliah - Thursday, February 11, 2010

Hi Pavel,

I am using Microsoft Smart Client Software Factory. I have different work spaces. One workspace I am loading by tree with tables nodes (one user control) and the other workspace I am loading Nevron drawing view (another user control) dynamically.

I have a requirement to validate the mapping between NTableShape shapes when using connectors. I am using NDrawingView's NodeSelecting event for validating the items are selected. Unfortunately this event is not raising when I select any of shapes in NDrawingView object.

Same validation I have done without using the Microsoft Smart Client Software Factory (put everything on a single Win Form object) then the NodeSelecting event is raising successfully.

Please give me your thoughts.

Thanks

Regards

Montford Anslum

 

 

By Pavel Vladov - Friday, February 12, 2010

Hi Montford,
I'm not familiar with the Microsoft Smart Client Factory and as it has nothing to do with our components I cannot provide any support for it. Please, explain in more details only the problem that you have with our component and I'll help you solve it.

Best Regards,
Pavel Vladov

By Montford Chelliah - Monday, February 15, 2010

Hi Pavel,

Thanks for the reply. I could manage to solve the problem. I have manually registered the event at the load method now the event is raising.

I am facing a problem to save and loading the Nevron diagram. here is my implementation.

Saving Procedure

string fileFullPath = "C:\Test\f6ece328-8157-412c-9c41-95aade80c1fe.ndb"

NPersistencyManager persistManager = new NPersistencyManager();

persistManager.SaveDrawingToFile(document, fileFullPath);

Loading Procedure

string filePath = "C:\Test\f6ece328-8157-412c-9c41-95aade80c1fe.ndb"

NPersistencyManager persistencyManager = new NPersistencyManager();

NDrawingDocument tempDocument = persistencyManager.LoadDrawingFromFile(filePath);   

if (tempDocument != null) {

    view.Document = tempDocument;

    this.document = tempDocument;

}

Code is running without exception, but the object "tempDocument " is getting null value when I load the diagram (which is highlighted with green). I checked the file in the file system, the file is there. What could be the reason?

Thanks

Best Regards

Montford Anslum

By Pavel Vladov - Tuesday, March 2, 2010

Hi Montford,
if the document after loading is null this means that the drawing document was not loaded successfully. Take a look at the trace in debug mode to see what causes the problem. You can also try saving in XML or Custom XML format.

Best Regards,
Pavel Vladov