- Main Page
- Packages
- Classes
- Files

- File List
- File Members

# C:/Documents and Settings/student/My Documents/Visual Studio 2008/projects/UtmConvert/UtmConvert/UtmConvertMainForm.cs

Go to the documentation of this file.

    00001 ﻿using System;
    00002 using System.Collections.Generic;
    00003 using System.ComponentModel;
    00004 using System.Data;
    00005 using System.Drawing;
    00006 using System.Linq;
    00007 using System.Text;
    00008 using System.Windows.Forms;
    00009
    00010 namespace UtmConvert {
    00011     public partial class UtmConvertMainForm : Form {
    00012
    00013         ConvertLatLonUtm con;
    00014
    00015         public UtmConvertMainForm() {
    00016             InitializeComponent();
    00017             con = new ConvertLatLonUtm();
    00018             foreach (Datum d in Datums.datumList)
    00019                 datumsListBox.Items.Add(d.Name);
    00020             datumsListBox.SelectedIndex = 0;
    00021             northSouthComboBox.SelectedIndex = 0;
    00022             eastWestComboBox.SelectedIndex = 1;
    00023             convertLatLonToUtm();
    00024         }
    00025
    00026         private void datumsListBox_SelectedIndexChanged(object sender, EventArgs e) {
    00027             foreach (Datum d in Datums.datumList) {
    00028                 if (d.Name == datumsListBox.SelectedItem.ToString()) {
    00029                     datumPropertyGrid.SelectedObject = d;
    00030                     con.Datum = d;
    00031                 }
    00032             }
    00033         }
    00034
    00035
    00036         private void convertButton_Click(object sender, EventArgs e) {
    00037             if (latLonToUtmRadioButton.Checked)
    00038                 convertLatLonToUtm();
    00039             else
    00040                 convertUtmToLatLon();
    00041          }
    00042
    00043         private void convertLatLonToUtm() {
    00044             double lat = 0, lon = 0;
    00045             bool nS = (northSouthComboBox.SelectedIndex != 0);
    00046             bool eW = (eastWestComboBox.SelectedIndex != 0);
    00047             if (latDegTextBox.Text != "" && latMinTextBox.Text != "" && latSecTextBox.Text != "")
    00048                 lat = ConvertDegRad.getRadians(latDegTextBox.Text, latMinTextBox.Text, latSecTextBox.Text, nS);
    00049             else if (latDegTextBox.Text != "" && latMinTextBox.Text != "")
    00050                 lat = ConvertDegRad.getRadians(latDegTextBox.Text, latMinTextBox.Text, nS);
    00051             else if (latDegTextBox.Text != "")
    00052                 lat = ConvertDegRad.getRadians(latDegTextBox.Text, nS);
    00053             latInRad.Text = Math.Round(lat, 4).ToString();
    00054             if (lonDegTextBox.Text != "" && lonMinTextBox.Text != "" && lonSecTextBox.Text != "")
    00055                 lon = ConvertDegRad.getRadians(lonDegTextBox.Text, lonMinTextBox.Text, lonSecTextBox.Text, eW);
    00056             else if (lonDegTextBox.Text != "" && lonMinTextBox.Text != "")
    00057                 lon = ConvertDegRad.getRadians(lonDegTextBox.Text, lonMinTextBox.Text, eW);
    00058             else if (lonDegTextBox.Text != "")
    00059                 lon = ConvertDegRad.getRadians(lonDegTextBox.Text, eW);
    00060             lonInRad.Text = Math.Round(lon, 4).ToString();
    00061             con.convertLatLonToUtm(lat, lon);
    00062             eastingTextBox.Text = Math.Round(con.Easting, 2).ToString();
    00063             northingTextBox.Text = Math.Round(con.Northing, 2).ToString();
    00064             zoneTextBox.Text = con.Zone;
    00065             latToolStripStatusLabel.Text = ConvertDegRad.getDegrees(Math.Abs(lat)).ToString()
    00066                 + " " + northSouthComboBox.SelectedItem.ToString() + ", ";
    00067             lonToolStripStatusLabel.Text = ConvertDegRad.getDegrees(Math.Abs(lon)).ToString()
    00068                  + " " + eastWestComboBox.SelectedItem.ToString() + ", ";
    00069         }
    00070
    00071         private void convertUtmToLatLon() {
    00072             if (eastingTextBox.Text != "" || northingTextBox.Text != "") {
    00073                 double e = 0, n = 0;
    00074                 double.TryParse(eastingTextBox.Text, out e);
    00075                 double.TryParse(northingTextBox.Text, out n);
    00076                 con.convertUtmToLatLon(e, n);
    00077                 if (con.Latitude > 0)
    00078                     northSouthComboBox.SelectedIndex = 0;
    00079                 else
    00080                     northSouthComboBox.SelectedIndex = 1;
    00081                 latDegTextBox.Text = ConvertDegRad.getDegrees(Math.Abs(con.Latitude)).ToString();
    00082                 latMinTextBox.Clear();
    00083                 latSecTextBox.Clear();
    00084                 if (con.Longitude > 0)
    00085                     eastWestComboBox.SelectedIndex = 0;
    00086                 else
    00087                     eastWestComboBox.SelectedIndex = 1;
    00088                 lonDegTextBox.Text = ConvertDegRad.getDegrees(Math.Abs(con.Longitude)).ToString();
    00089                 lonMinTextBox.Clear();
    00090                 lonSecTextBox.Clear();
    00091             }
    00092         }
    00093
    00094         private void convertingUTMToLatitudeLongitudepdfToolStripMenuItem_Click(object sender, EventArgs e) {
    00095             DocViewer dv = new DocViewer();
    00096             dv.Show();
    00097             ToolStripMenuItem t = (ToolStripMenuItem)sender;
    00098             dv.viewDocument(t.Text);
    00099         }
    00100
    00101         private void theUniversalTransverseMercatorSystempdfToolStripMenuItem_Click(object sender, EventArgs e) {
    00102             DocViewer dv = new DocViewer();
    00103             dv.Show();
    00104             ToolStripMenuItem t = (ToolStripMenuItem)sender;
    00105             dv.viewDocument(t.Text);
    00106         }
    00107
    00108         private void utmzonesjpgToolStripMenuItem_Click(object sender, EventArgs e) {
    00109             DocViewer dv = new DocViewer();
    00110             dv.Show();
    00111             ToolStripMenuItem t = (ToolStripMenuItem)sender;
    00112             dv.viewDocument(t.Text);
    00113         }
    00114
    00115         private void uTMConversions1xlsToolStripMenuItem_Click(object sender, EventArgs e) {
    00116             DocViewer dv = new DocViewer();
    00117             dv.Show();
    00118             ToolStripMenuItem t = (ToolStripMenuItem)sender;
    00119             dv.viewDocument(t.Text);
    00120         }
    00121
    00122         private void zoneCentralMeridianspdfToolStripMenuItem_Click(object sender, EventArgs e) {
    00123             DocViewer dv = new DocViewer();
    00124             dv.Show();
    00125             ToolStripMenuItem t = (ToolStripMenuItem)sender;
    00126             dv.viewDocument(t.Text);
    00127         }
    00128
    00129         private void exitToolStripMenuItem_Click(object sender, EventArgs e) {
    00130             this.Dispose();
    00131         }
    00132
    00133         private void sourceCodeToolStripMenuItem_Click(object sender, EventArgs e) {
    00134             DocViewer dv = new DocViewer();
    00135             dv.Show();
    00136             dv.viewDocument(".\\html\\index.html");
    00137         }
    00138
    00139         private void aboutUtmConvertToolStripMenuItem_Click(object sender, EventArgs e) {
    00140             AboutBoxMainForm a = new AboutBoxMainForm();
    00141             a.Show();
    00142         }
    00143
    00144         private void openToolStripMenuItem_Click(object sender, EventArgs e) {
    00145             xmlOpenFileDialog.ShowDialog();
    00146         }
    00147
    00148         private void xmlOpenFileDialog_FileOk(object sender, CancelEventArgs e) {
    00149             XmlParser p = new XmlParser();
    00150             p.readFile(xmlOpenFileDialog.FileName);
    00151             inputXmlTextBox.Text = p.FileString;
    00152             p.Parse();
    00153             parserToolStripStatusLabel.Text = "Batch convert: " + p.Status + ", ";
    00154             utmPointsTextBox.Clear();
    00155             foreach (Point pt in p.Points) {
    00156                 utmPointsTextBox.AppendText("x: " + pt.X + ", y: " + pt.Y + "\r\n");
    00157             }
    00158         }
    00159     }
    00160 }