How to import/export kml and display in gmap.net - c#

I want to create a simple database viewer using Microsoft Visual Studio and GMaps.NET which can (1) do a specific search and update the list, (2) export the list as KML, and (3) upload the KML file to be viewed in the embedded gmap. Step 1 is already resolved but I cannot find reference to proceed with steps 2 and 3. Any help will be highly appreciated!
Here is my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using GMap.NET;
using GMap.NET.WindowsForms;
using GMap.NET.WindowsForms.Markers;
using GMap.NET.MapProviders;
//if these GMap statements are not enabled, these will have to be typed with the namespaces e.g. GMap.Net.MapProviders.GoogleMap
namespace KDMI_DBViewer_v1._0
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void existingPermitsBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
this.Validate();
this.existingPermitsBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.permits_2016DataSet);
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'permits_2016DataSet.ExistingPermits' table. You can move, or remove it, as needed.
this.existingPermitsTableAdapter.Fill(this.permits_2016DataSet.ExistingPermits);
}
private void gMapControl1_Load(object sender, EventArgs e)
{
gMapControl1.MapProvider = GMapProviders.GoogleTerrainMap;
//gMapControl1.ShowCenter = false; if enabled, this will remove the red cross
gMapControl1.Position = new PointLatLng(12.0725555, 122.895494);
gMapControl1.DragButton = MouseButtons.Left;
gMapControl1.Zoom = 5;
gMapControl1.MinZoom = 5;
gMapControl1.MaxZoom = 12;
}
private void specificSearchToolStripButton_Click(object sender, EventArgs e)
{
try
{
this.existingPermitsTableAdapter.SpecificSearch(this.permits_2016DataSet.ExistingPermits, provinceToolStripTextBox.Text, municipalityToolStripTextBox.Text, typeToolStripTextBox.Text);
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}

Unfortunetly, no KML parser yet implemented as the creator of GMap.Net said gmap.net issues.
But instead you can create the import \ export KML\KMZ methods yourself using a library called SharpKML
SharpKML is an implementation of the Open Geospatial Consortium (OGC)
KML 2.2 standard developed in C#, able to read/write both KML files
and KMZ files.
Getting Started:
The easiest way to use the library is to install the SharpKml.Core
NuGet package, however, you can also download the binaries/source code
from this project page.

Related

How can I search through an Excel sheet in a C# GUI?

I have this code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TabeleExcel
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void cboSheet_SelectedIndexChanged(object sender, EventArgs e)
{
DataTable dt = tableCollection[cboSheet.SelectedItem.ToString()];
dataGridView1.DataSource = dt;
}
DataTableCollection tableCollection;
private void btnBrowse_Click(object sender, EventArgs e)
{
using(OpenFileDialog openFileDialog=new OpenFileDialog() { Filter="Excel|*.xls|Excel|*.xlsx" })
{
if(openFileDialog.ShowDialog()==DialogResult.OK)
{
txtFilename.Text = openFileDialog.FileName;
using(var stream=File.Open(openFileDialog.FileName, FileMode.Open, FileAccess.Read))
{
using (IExcelDataReader reader = ExcelReaderFactory.CreateReader(stream))
{
DataSet result = reader.AsDataSet(new ExcelDataSetConfiguration()
{
ConfigureDataTable=(_)=>new ExcelDataTableConfiguration() { UseHeaderRow=true }
});
tableCollection = result.Tables;
cboSheet.Items.Clear();
foreach (DataTable table in tableCollection)
cboSheet.Items.Add(table.TableName);
}
}
}
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
}
}
The code makes a GUI in .NET framework and it lets you upload an .xls or .xlsx, the Excel file will be shown as a DataGrid view. I implemented a new textbox ( the textBox1_TextChanged(object sender, EventArgs e) method), and based on the user's input, I want to it to display only the rows that correspond with the input. How am I supposed to do that? Thanks in advance!
You have 3 options for working with office formats:
if you only need to support the new formats (.xslx) you can use the OpenXML SDK, any of the wrappers people wrote for it. Or even the ZipArchive and XMLReader classes. It is well known and easily processed
If you need to support the old format as well (.xls) you have to use the (t)rusty Office COM interop. That one has the usualy issues of COM interop, plus some unique problems. Like requiring a Interactive Session due to poor design choices.
For any given problem, any given file format, any given GUI technology there might be another way. But those are far and few in between
My standing advice is to use the OpenXML way and learn to live without the old formats altogether. They are way more trouble to support then it is worth.

Awesomium "LoadingFrameComplete" is firing too many times

Just recently began tinkering with Awesomium, it's very cool and much better than the stock webBrowser for WinForms.
However, when I use the _LoadingFrameComplete method to determine if the page has loaded, it seems to be firing 10+ times (when used on Facebook, 2 times when navigating to google.com)
I am trying to get the comparable method of webBrowser1_DocumentCompleted (which only fires one time, after the document has completed).
Is this a 'me' problem, or am I using the wrong methods to check whether the website has finished loading completely.
I'm using Visual C# 2010 Edition
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 Debugging_Problems
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string searchURL = textBox1.Text;
webControl1.Source = new Uri(searchURL);
}
private void Awesomium_Windows_Forms_WebControl_LoadingFrameComplete(object sender, Awesomium.Core.FrameEventArgs e)
{
richTextBox1.AppendText("Completed.\n");
}
}
}
You need to use IsMainFrame
private void Awesomium_Windows_Forms_WebControl_LoadingFrameComplete(object sender, Awesomium.Core.FrameEventArgs e)
{
if (e.IsMainFrame)
{
richTextBox1.AppendText("Completed.\n");
}
}
Try putting if(e.IsMainFrame) { .... } inside your LoadingFrameComplete event handler and only put your code in there. – Jon
That was the answer. Thank you.

C# , pull sites from TXT, pull datafrom website, output data to lists and CSV

Good morning guys I'm new to this place and have been having a lot of issues getting any of the findings to work.
I'm currently using C# inside visual studio community and was using a you tube video as reference but I'm stuck getting it to work efficiently (i think its in a loop) and to do other actions.
Im trying to get a list of urls from a text file in desktop or by user inputting it to a field:
EG: program opens HE puts IP in one text box and hits submit program runs and iots done.
or if it pulls a list of IP's from Desktop C: then it will add it to the website while using a loop?
eg:
my current code is similar to this as follows:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace HTTPcollect_Windows_Form_App
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
List<string> IPs = new List<string>();
WebClient web = new WebClient();
String html = web.DownloadString("http://www.ipvoid.com/scan/8.8.8.8/");
MatchCollection m1 = Regex.Matches(html, #"IP Address.*<strong>(.+?) <\/strong>", RegexOptions.Singleline);
foreach (Match m in m1)
{
string IP = m.Groups[1].Value;
IPs.Add(IP);
}
listBox1.DataSource = IPs;
}
private void label1_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
}

How to structure speech recognition code in an executable c# WinForms App?

link to original code - please look at it first.
I'm not sure how to write this code so that it runs properly. So far my attempt:
The code in the website is using System Speech Recognition from Microsoft to record audio from microphone and turn it into text. Except, I don't know how to format that code on the website properly. The below certainly does not work. I get red underlines everywhere. I'm also not sure how 'event-handler' code is supposed to look like.
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.Speech.Recognition;
namespace SystemSpeechRecognition_winForms
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
SpeechRecognitionEngine _speechRecognitionEngine = new SpeechRecognitionEngine();
_speechRecognitionEngine.SetInputToDefaultAudioDevice();
DictationGrammar _dictationGrammar = new DictationGrammar();
_speechRecognitionEngine.LoadGrammar(_dictationGrammar);
_speechRecognitionEngine.RecognizeAsync(RecognizeMode.Multiple);
ERROR for the four lines
This is the error:
.
"delegate System.EventHandler"
"Represents the method that will handle an event that has no event data"
"Error: No overload for 'SpeechRecognized' matches delegate 'System.EventHanndler'
_speechRecognitionEngine.SpeechRecognized -= new EventHandler(SpeechRecognized);
_speechRecognitionEngine.SpeechHypothesized -= new EventHandler(SpeechHypothesizing);
_speechRecognitionEngine.SpeechRecognized += new EventHandler(SpeechRecognized);
_speechRecognitionEngine.SpeechHypothesized += new EventHandler(SpeechHypothesizing);
}
private void SpeechHypothesizing(object sender, SpeechHypothesizedEventArgs e)
{
///real-time results from the engine
string realTimeResults = e.Result.Text;
}
private void SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
///final answer from the engine
string finalAnswer = e.Result.Text;
}
}
You're having compilation issues because - to take one of the events as an example - the SpeechRecognized event is of type EventHandler<SpeechRecognizedEventArgs> and you are attempting to assign it an instance of the non-generic EventHandler class.
_speechRecognitionEngine.SpeechRecognized -= new EventHandler<SpeechRecognizedEventArgs>(SpeechRecognized);

C# bound table adapter not updating until called twice

New to C# from vb.net and I am just making some mock bound applications for now. I have problems with the following code. If I pic an image and exit the application, there is no change. Even if I move a row. However if I upload an image, move to another row, then add another image. After exiting the application the first image will be there but not the second.
In short I have to attempt to upload to another record before the record I actually want updating will do so.
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.IO;
namespace DBUserManagement
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'dsUsers.Users' table. You can move, or remove it, as needed.
this.usersTableAdapter.Fill(this.dsUsers.Users);
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
if (DialogResult.OK == ofd.ShowDialog())
{
imgUser.SizeMode = PictureBoxSizeMode.StretchImage;
imgUser.Image = new Bitmap(ofd.OpenFile());
//update bound field.
usersTableAdapter.Update(dsUsers);
}
}
}
}
Any ideas on what I am missing or not understand correctly? Any help appreciated.
/P
The answer was I needed to call the BindingSource's .EndEdit(); method.
So I am guessing it was down to the binding source still having hold of something.
Seems like I'm on the right track anyhow, I looked up the details on MSDN :)

Categories

Resources