Newer
Older
GHFX_REFACTOR / Backup / Forms / FrmProject.cs
wxn on 2 Nov 2016 3 KB 提交
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;

namespace Cyberpipe.Forms
{
    public partial class FrmProject : Office2007Form
    {
        public FrmProject()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 经纬度坐标转换为平面坐标
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnLatlon2Coord_Click(object sender, EventArgs e)
        {
            int id = GeoScene.Data.GSOProjectManager.AddProject(Utility.projectStr);
            
            //  GeoScene.Data.GSOProjectManager.SetCurProject(id);
            if (txtLong.Text == "" || txtLat.Text == "")
            {
                MessageBox.Show("请输入要转化的经纬度坐标!");
                return;
            }
            double x = Convert.ToDouble(txtLong.Text);
            double y = Convert.ToDouble(txtLat.Text);
            if (x > 180)
            { 
                MessageBox.Show("经度不能超过180!!","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
            }
            if (y > 90)
            {
                MessageBox.Show("纬度不能超过90!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            GeoScene.Data.GSOPoint2d pt2d = new GeoScene.Data.GSOPoint2d(x, y);
            GeoScene.Data.GSOPoint2d result = GeoScene.Data.GSOProjectManager.Forward(pt2d, id);
            txtX.Text = result.X.ToString();
            txtY.Text = result.Y.ToString();
        }
        /// <summary>
        /// 平面坐标转换为经纬度坐标
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCoord2Latlon_Click(object sender, EventArgs e)
        {
            int id = GeoScene.Data.GSOProjectManager.AddProject(Utility.projectStr);
            //  GeoScene.Data.GSOProjectManager.SetCurProject(id);
            if (txtX.Text == "" || txtY.Text == "")
            {
                MessageBox.Show("请输入要转化的横轴和竖轴的值!");
                return;
            }
            double x = Convert.ToDouble(txtX.Text);
            double y = Convert.ToDouble(txtY.Text);
            GeoScene.Data.GSOPoint2d pt2d = new GeoScene.Data.GSOPoint2d(x, y);
            GeoScene.Data.GSOPoint2d result = GeoScene.Data.GSOProjectManager.Inverse(pt2d, id);
            txtLong.Text = result.X.ToString();
            txtLat.Text = result.Y.ToString();
        }
        /// <summary>
        /// 键盘按钮按下事件处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtLong_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextBox text = sender as TextBox;
            if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar != 8) && (int)e.KeyChar != 46)
            {
                e.Handled = true;
            }
            if ((int)e.KeyChar == 46)                           //小数点
            {
                if (text.Text.Length <= 0)
                    e.Handled = true;   //小数点不能在第一位
                else                                             //处理不规则的小数点
                {
                    float f;
                    float oldf;
                    bool b1 = false, b2 = false;
                    b1 = float.TryParse(text.Text, out oldf);
                    b2 = float.TryParse(text.Text + e.KeyChar.ToString(), out f);
                    if (b2 == false)
                    {
                        if (b1 == true)
                            e.Handled = true;
                        else
                            e.Handled = false;
                    }
                }
            }
        }
    }
}