Hi guys I'm quite new to programming and this is actually my first time here.
I'm creating a C# sharp web form for displaying route information by reading from MySQL database. I want to create a method which draws the lines on the map between the connecting points. The code I have so far only draws the points and their names but does not link them.
private void DrawLines()
{
int start1;
int start2;
int end1;
int end2;
Graphics g = this.CreateGraphics();
Pen white = new Pen(Color.White, 1);
Pen blackW = new Pen(Color.Black, 3);
Pen goldW = new Pen(Color.Gold, 3);
Pen redW = new Pen(Color.Red, 3);
Pen blueW = new Pen(Color.Blue, 3);
g.FillRectangle(white.Brush, new Rectangle(0, 0, 800, 600));
for (int i = 0; i < lineCount; i++)
{
for (int j = 1; j < stationCount; j++)
{
int stationID1 = stationNumber[i, j];
int stationID2 = stationNumber[i, j + 1];
if (stationID2 > 0)
{
start1 = 0;
start2 = 0;
end1 = 0;
end2 = 0;
for (int s = 0; s < stationCount; s++)
{
if (stationID1 == stationID[s])
{
start1 = stationX[s];
start2 = stationY[s];
}
if (stationID2 == stationID[s])
{
end1 = stationX[s];
end2 = stationY[s];
}
}
if (lineName[i] == "Northen")
g.DrawLine(blackW, start1, start2, end1, end2);
if (lineName[i] == "Central")
g.DrawLine(redW, start1, start2, end1, end2);
if (lineName[i] == "Victoria")
g.DrawLine(blueW, start1, start2, end1, end2);
if (lineName[i] == "Circle")
g.DrawLine(goldW, start1, start2, end1, end2);
}
}
}
}
And here is the MYSQL statement
private void GetLines()
{
try
{
dbtry.Open();
MySqlCommand cmdLines = new MySqlCommand();
cmdLines.Connection = dbtry;
cmdLines.CommandText = "SELECT TrainLines.ID, TrainLines.LineName, TrainStations.ID, TrainStations.StationName, StationsAndLines.ID, StationsAndLines.TrainLines_ID, StationsAndLines.TrainStations_ID, StationsAndLines.Position, StationsAndLines.Distance FROM TrainStations, TrainLines, StationsAndLines WHERE StationsAndLines.TrainLines_ID = TrainLines.ID AND StationsAndLines.TrainStations_ID = TrainStations.ID ORDER BY TrainLines.LineName ASC, StationsAndLines.Position ASC"; // get all the line IDs
MySqlDataReader drLines = cmdLines.ExecuteReader(); //create an adapter with the Line IDs
// drLines.Fill(dsLines); //create dataset of lines IDs
while (drLines.Read())
{
miStations.Add(drLines["StationName"].ToString());
miStations.Add(drLines["Distance"].ToString());
miStations.Add(drLines["LineName"].ToString());
miStations.Add(drLines["Position"].ToString());
}
what i'm kind of trying to get