Hi,
I have developed a c sharp application which will execute an sql Query and get corresponding Coordinates(latitude, longitude) of a location. Once the program executes the sql query it will get the Location Coordinates.
Now after getting the coordinates from 1st form, It will go to second form and there in that form a webbrowser control is embedded. So it should open a google Map with the location from coordinates.
But unfortunately, when i pass the values from first form to 2nd form. The values are passing to 2nd form successfully.
But the webpage is not displaying at all. Only white screen is coming.
But when i call the 2nd form directly from main Program then it is trying to open the Webpage and returning the error that Google Maps is not supported in the browser. So i need a new browser like chrome or firefox embedded in the form to implement.
Main Program:-
namespace LocationFinder
{
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new LocationMap());
}
}
}
Form1:-
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using Microsoft.Office;
using Microsoft.Office.Interop.Excel;
using Excel = Microsoft.Office.Interop.Excel;
namespace LocationFinder
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
public void MainForm_Load(object sender, EventArgs e)
{
string old_value = "";
while (true)
{
String connetionString = null;
SqlConnection conn;
SqlCommand cmd;
String sql = null;
SqlDataReader reader;
connetionString = "server=(local);database=modelDb;user id=sa;pwd=123456";
sql = "DECLARE @var varchar(1000) = (SELECT TOP 1 Text FROM Alarms WHERE AlarmDefinitionId=139 ORDER BY EventTime DESC) DECLARE @start_position int, @end_position int SELECT @start_position = PATINDEX('% at%', @var) SELECT @end_position = PATINDEX('%kilometers%', @var) DECLARE @VALUE VARCHAR(10) = (Select SUBSTRING(@var, @start_position+5,5)) Select Top 1 @VALUE,RouteTable.Latitude,Routetable.Longitude,Alarms.ApplicationTime,RouteTable.StationName,RouteTable.SectionName FROM Alarms INNER JOIN Routetable ON Routetable.Location BETWEEN FLOOR(@VALUE)-1 AND CEILING(@VALUE)+1 WHERE AlarmDefinitionId=139 ORDER BY EventTime DESC";
conn = new SqlConnection(connetionString);
try
{
conn.Open();
cmd = new SqlCommand(sql, conn);
reader = cmd.ExecuteReader();
while (reader.Read())
{
if (old_value.ToString() != reader.GetValue(0).ToString())
{
MessageBox.Show("Location:-" + " " + reader.GetValue(0) + Environment.NewLine + "Latitude:-" + " " + reader.GetValue(1) + Environment.NewLine + "Longitude:-" + " " + reader.GetValue(2) + Environment.NewLine + "Leak Occured Time:-" + " " + reader.GetValue(3) + Environment.NewLine + "Station Name:-" + " " + reader.GetValue(4) + Environment.NewLine + "Section Name:-" + " " + reader.GetValue(5));
old_value = reader.GetValue(0).ToString();
string lat = reader.GetValue(1).ToString();
string lon = reader.GetValue(2).ToString();
LocationMap form1 = new LocationMap(lat, lon);
form1.Show();
}
else
{
}
}
reader.Close();
cmd.Dispose();
conn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
System.Threading.Thread.Sleep(5 * 1000);
}
}
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
About_LocationFinder formhelp = new About_LocationFinder();
formhelp.Show();
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
Form2:-
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace LocationFinder
{
public partial class LocationMap : Form
{
public LocationMap(string lati, string longi)
{
InitializeComponent();
textBox2.Text = longi.ToString();
textBox1.Text = lati.ToString();
}
private void LocationMap_Load(object sender, EventArgs e)
{
string Latitude = textBox1.Text;
string Longitude = textBox2.Text;
try
{
string address = "https://www.google.co.in/maps/place/";
if (Latitude != string.Empty && Longitude != string.Empty)
{
string address = address + Latitude + "," + Longitude;
webBrowser1.Navigate(address);
}
else
{
webBrowser1.Navigate(address);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
}
The Error When i call 2nd form directly from the main program is in the below link:-
http://s29.postimg.org/xw4661hav/Error.jpg[
^]