Hello,
I'm a beginner in programming, C#, WPF, everything really and I'm learning by creating an application where you can draw out a drainage network, and carry out a bunch of calculations on that network.
I'm using WPF and drawing lines and nodes on a canvas.
My initial plan was, when a node is placed on the canvas, an entry into an SQLite database is created as a convenient way to store the data, query it, and modify it at a later stage.
It's also convenient that the database can be saved and loaded making the whole file open/save element really straight forward.
I plan to also use the data in the database to redraw to the canvas in the event of a pan of zoom (not built in yet).
The problem is I also have to create an instance of the class "Node" in order to place it on the Canvas.
This would be ok, until the user wants to edit the network, which is the next bit I want to work on.
It's easy enough to find the node in the database when the user clicks in the vicinity of the node.
But then how would also also modify the class for that node shown on screen?
I could clear the canvas and redraw everything form the database but that seems very inefficient.
I assume I could create a list of all the instances of the node class, and then use LinQ to find that node instance, and modify it, but then I'm having to do the query twice which again doesn't seem very efficient.
I'm also unclear how I would access that class since they all effectively have the same name `node`.
So my questions are:
1. Should I avoid using the database and rely solely on the node class to query, modify etc?
2. Regardless of the answer to question 1, how do I modify a specific instance of "node"?
Many thanks.
What I have tried:
Here is my method to create a new node:
private void AddNode(MouseButtonEventArgs e)
{
Node node = new Node();
CadCanvas.Children.Add(node.DrawNode(currentMousePoint.X, currentMousePoint.Y));
database.AddNode("test", currentMousePoint.X, currentMousePoint.Y);
}
and here is my node class that creates the graphic for the canvas:
public class Node
{
public int id;
public string refernce;
public Ellipse DrawNode(double x, double y)
{
Ellipse e = new Ellipse();
e.Height = 20;
e.Width = 20;
e.Fill = Brushes.Blue;
double left = x - (20 / 2);
double top = y - (20 / 2);
e.Margin = new Thickness(left, top, 0, 0);
return e;
}
}