Newer
Older
EMS_REFACTOR / FrmGBJCresult.cs
nn-203 on 26 Jul 2017 5 KB first commit
using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using GeoScene.Data;
using GeoScene.Globe;

namespace Cyberpipe
{
    public partial class FrmGBJCresult : Office2007Form
    {
        DataTable dt;
        GSOGlobeControl globeControl1;
        GSOGlobeControl globeControl2;

        public FrmGBJCresult(GSOGlobeControl _golbeControl1, GSOGlobeControl _golbeControl2, DataTable _dt)
        {
            globeControl1=_golbeControl1;
            globeControl2 = _golbeControl2;
            dt = _dt;
            InitializeComponent();
            labelX1.Text = DoublePanelAnalysis.strLabel;
        }

        void intalDatagridView()
        {
            dataGridViewX1.DataSource = dt;
            dataGridViewX1.Columns[0].Width = 80;
            dataGridViewX1.Columns[1].Width = 130;
            dataGridViewX1.Columns[2].Width = 80;
            dataGridViewX1.Columns[3].Width = 130;
            dataGridViewX1.Columns[4].Width = 70;
            dataGridViewX1.Columns[5].Width = 80;
            dataGridViewX1.Columns[6].Width = 70;
            dataGridViewX1.Columns[7].Width = 80;
        }

        private void FrmGBJCresult_Load(object sender, EventArgs e)
        {
            intalDatagridView();
        }

        private void dataGridViewX1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0 || e.ColumnIndex < 0)
                return;
            globeControl1.Globe.MemoryLayer.RemoveAllFeature();
            globeControl2.Globe.MemoryLayer.RemoveAllFeature();

            //获取globeControl1飞行目标
            string scLayer = dataGridViewX1.Rows[e.RowIndex].Cells["实测图层"].Value.ToString();
            string scFeatureName = dataGridViewX1.Rows[e.RowIndex].Cells["实测管段"].Value.ToString();
            GSOLayer scgsoLayer = globeControl1.Globe.Layers.GetLayerByCaption(scLayer);
            GSOFeatures scgsoFeatures = scgsoLayer.GetFeatureByName(scFeatureName, false);
            GSOFeature scgsoFeature = scgsoFeatures[0];

            //获取globeControl2飞行目标
            string sgLayer = dataGridViewX1.Rows[e.RowIndex].Cells["施工图层"].Value.ToString();
            string sgFeatureName = dataGridViewX1.Rows[e.RowIndex].Cells["施工管段"].Value.ToString();
            GSOLayer sggsoLayer = globeControl1.Globe.Layers.GetLayerByCaption(sgLayer);
            GSOFeatures sggsoFeatures = sggsoLayer.GetFeatureByName(sgFeatureName, false);
            GSOFeature sggsoFeature = sggsoFeatures[0];

            addLabelAndFlyToPosition(scgsoFeature, sggsoFeature);
        }

        void addLabelAndFlyToPosition(GSOFeature scFeature, GSOFeature sgFeature)
        {
            AddPolygon(scFeature);

            ClassSearchAnalysis.AddMakerToLineFeature(globeControl1, scFeature);
            if (sgFeature != null)
                ClassSearchAnalysis.AddMakerToLineFeature(globeControl2, sgFeature);
            else
            {
                globeControl2.Globe.MemoryLayer.RemoveAllFeature();
                GSOGeoPolyline3D scLine = scFeature.Geometry as GSOGeoPolyline3D;
                if (scLine[0].Count <= 1) return;
                GSOGeoPoint3D pt = new GSOGeoPoint3D();
                GSOPoint3d point3d = scLine.GeoCenterPoint;
                pt.X = point3d.X;
                pt.Y = point3d.Y;
                pt.Z = point3d.Z;
                globeControl2.Globe.JumpToPosition(point3d, EnumAltitudeMode.Absolute, 200);
            }
        }

        private void AddPolygon(GSOFeature scFeature)
        {
            GSOFeature new_feat= new GSOFeature();

            GSOGeoPolyline3D line = scFeature.Geometry as GSOGeoPolyline3D;
            GSOGeoPolygon3D resPolygon = new GSOGeoPolygon3D();
            resPolygon = line.CreateBuffer(DoublePanelAnalysis.bufferWidth, true, 0, false, false);
            resPolygon.AltitudeMode = EnumAltitudeMode.RelativeToGround;

            new_feat.Geometry = resPolygon;

            globeControl1.Globe.MemoryLayer.AddFeature(new_feat);
            globeControl2.Globe.MemoryLayer.AddFeature(new_feat);
            globeControl1.Refresh();
            globeControl2.Refresh();
        }

        private void FrmGBJCresult_FormClosing(object sender, FormClosingEventArgs e)
        {
            globeControl1.Globe.MemoryLayer.RemoveAllFeature();
            globeControl2.Globe.MemoryLayer.RemoveAllFeature();
            globeControl1.Refresh();
            globeControl2.Refresh();
        }

        private void buttonEXPexcel_Click(object sender, EventArgs e)
        {
            try 
            {
                string saveFileName = "";
                SaveFileDialog saf = new SaveFileDialog();
                saf.Filter = "Excel files (*.xlsx)|*.xlsx";
                saf.FilterIndex = 0;
                saf.RestoreDirectory = true;
                saf.Title = "保存为Excel文件";
                saf.FileName = "国标检测" + "-" + DateTime.Now.ToString("yyyyMMdd") + ".xlsx";

                if (saf.ShowDialog() == DialogResult.OK)
                    saveFileName = saf.FileName;
                ExpEXCEL.ExpToExcel(dataGridViewX1, saveFileName, "检测结果");
                MessageBox.Show("导出成功!", "提示");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

    }
}