Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Data.SqlClient;
- using System.Globalization;
- using System.IO;
- using System.Text;
- using System.Threading;
- using System.Windows.Forms;
- namespace GeoDisplay
- {
- public partial class Form1 : Form
- {
- public StringBuilder tekst; //StringBuilder zawierający kod strony HTML do wyświetlenia
- string tempTable; //nazwa tymczasowej tabeli na ID
- public Form1(string[] args)
- {
- WebBrowserHelper.FixBrowserVersion(); //wymuszenie, aby przeglądarka korzystała z IE 9.0+
- InitializeComponent();
- webBrowser1.ScriptErrorsSuppressed = true; //wyłączenie obsługi błędów w przeglądarce
- Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US"); //wymuszenie korzystania z kropek zamiast przecinków przy zmiennych rzeczywistych
- string server; //nazwa serwera
- string database; //nazwa bazy danych
- string username; //nazwa użytkownika
- string pwd; //hasło
- if (args.Length < 6) //przypisanie wartości domyślnych
- {
- server = "F-HV-64\\SQL2008R2";
- database = "KOSZALIN_17_01_2017";
- username = "sa";
- pwd = "haslo";
- tempTable = "t_dane_geolok_pozycje";
- }
- else
- {
- server = args[1];
- database = args[2];
- username = args[3];
- pwd = args[4];
- tempTable = args[5];
- }
- // utworzenie połączenia z bazą danych
- SqlConnection conn = new SqlConnection("user id=" + username + ";password="+pwd+";server="+server+";Trusted_Connection=no;database="+database+";Connect Timeout=10");
- var adresy = GetDatabase(conn); //pobranie potrzebnej zawartości
- //wpisanie pierwszej połowy strony
- tekst = new StringBuilder("<html><head><style>#map {height: 100 %;} html, body {font-family: Arial, Helvetica, sans-serif;height: 100%;margin: 0;padding: 0;} .content {color: #303030;text-align: center;}</style></head><body><div class=\"content\"><h1 id = \"lattitude\"></h1></div><div id=\"map\"></div><script>function initMap(){var icons =[];icons[0] = 'http://icons.iconarchive.com/icons/robinweatherall/recycling/16/bin-small-icon.png';icons[1] = 'http://iconshow.me/media/images/Application/Map-Markers-icons/png/32/MapMarker_Flag4_Right_Chartreuse.png';icons[2] = 'http://icons.veryicon.com/32/System/Eicodesign/Recycle%20bin%20green.png';icons[3] = 'http://icons.veryicon.com/32/System/Just%20Bins/bin%20white%20full.png';markers=[];");
- foreach (var adres in adresy) //Wpisanie markerów
- {
- tekst.Append("var marker = new google.maps.Marker({position: new google.maps.LatLng(");
- tekst.Append(adres["X"]);
- tekst.Append(",");
- tekst.Append(adres["Y"]);
- tekst.Append("),icon: icons[");
- tekst.Append(adres["icon"]);
- tekst.Append("],map: map,visible: true,title: '"+adres["adres"]+"'});markers.push(marker);google.maps.event.addListener(marker, 'click', function() {new google.maps.InfoWindow({content: '<div id=\"content\"><h2 id=\"firstHeading\" class=\"firstHeading\">");
- tekst.Append(adres["adres"]);
- tekst.Append("</h2></div>'}).open(map,this);}); ");
- }
- var dir = Directory.GetCurrentDirectory(); //pobranie aktualnej ścieżki
- //dopisanie reszty strony
- tekst.Append("var map = new google.maps.Map(document.getElementById('map'), {zoom: (markers.length>0?12:7),center: (markers.length>0?markers[0].position:{lat:52.5,lng:19.5}),mapTypeId: google.maps.MapTypeId.ROADMAP});map.setOptions({styles: [{featureType: \"poi\",elementType: \"labels\",stylers: [{ visibility: \"off\" }]}]});var clusterStyles = [{textColor: 'black',url: 'https://image.ibb.co/cy8LHv/m1.png',height: 30,width: 30},{textColor: 'white',url: 'https://image.ibb.co/mh3WPa/m2.png',height: 30,width: 30},{textColor: 'white',url: 'https://image.ibb.co/eve5ja/m3.png',height: 30,width: 30}];var mcOptions = {gridSize: 50,styles: clusterStyles,maxZoom: 15,minimumClusterSize: 5};var markerCluster = new MarkerClusterer(map, markers, mcOptions, {imagePath: 'm'});}</script><script src=\"file:///" + dir+"\\markerclusterer.js\"></script><script type=\"text/javascript\" src=\"http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/src/infobox.js\"></script><script src=\"https://maps.googleapis.com/maps/api/js?key=AIzaSyB8YetP-YQHuW1P6wQKem7fX4UXLgkv5PY&callback=initMap\" async defer></script></body></html>");
- //wyświetlanie strony
- DisplayHtml(tekst.ToString());
- }
- /// <summary>
- /// funkcja pobiera potrzebne dane z bazy
- /// </summary>
- /// <param name="conn">Obiekt połącz</param>
- /// <returns>Lista wierszy</returns>
- private List<Dictionary<string, string>> GetDatabase(SqlConnection conn)
- {
- List<Dictionary<string, string>> Addresses = new List<Dictionary<string, string>>();
- try {
- conn.Open();
- SqlCommand myCommand = new SqlCommand("SELECT t_d.cit_nazwa,t_d.str_nazwa,t_d.nr_domu,t_d.latitude,t_d.longitude,t_d.icon from t_dane_geolok as t_d INNER JOIN (SELECT MAX(CAST(ROWID as varchar(MAX))) as ROWID, latitude,longitude from t_dane_geolok GROUP BY latitude,longitude) tbl ON tbl.ROWID=t_d.ROWID INNER JOIN " + tempTable + " ON " + tempTable + ".id_$=t_d.id_$ WHERE t_d.latitude IS NOT NULL;", conn);
- var mr = myCommand.ExecuteReader();
- if (mr.HasRows)
- while (mr.Read())
- {
- var adres = CultureInfo.CurrentCulture.TextInfo.ToTitleCase((mr["cit_nazwa"] + ", " + mr["str_nazwa"] + " " + mr["nr_domu"]).ToLower());
- var dict = new Dictionary<string, string>();
- dict.Add("adres", adres);
- dict.Add("X", mr["latitude"].ToString());
- dict.Add("Y", mr["longitude"].ToString());
- dict.Add("icon", mr["icon"].ToString());
- Addresses.Add(dict);
- }
- mr.Close();
- myCommand = new SqlCommand("DROP TABLE " + tempTable + ";", conn);
- myCommand.ExecuteNonQuery();
- } catch (Exception e)
- {
- MessageBox.Show("Wystąpił błąd: " + e.Message);
- }
- finally
- {
- conn.Close();
- }
- return Addresses;
- }
- /// <summary>
- /// Wyswietla kod HTML w przeglądarce
- /// </summary>
- /// <param name="html">Kod HTML</param>
- private void DisplayHtml(string html)
- {
- webBrowser1.Navigate("about:blank");
- if (webBrowser1.Document != null)
- {
- webBrowser1.Document.Write(string.Empty);
- }
- webBrowser1.DocumentText=html;
- }
- /// <summary>
- /// Wyłączono nawigację na stronie
- /// </summary>
- private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
- {
- if (e.Url.ToString() != "about:blank")
- e.Cancel = true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement