Newer
Older
GHFX_REFACTOR / Forms / FrmShLayers.cs
wxn on 9 Nov 2016 4 KB 冗余代码整理
using System;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using GeoScene.Data;
using GeoScene.Engine;
using GeoScene.Globe;

namespace Cyberpipe.Forms
{
    public partial class FrmShLayers : Office2007Form
    {  
        public static GSODataSource ds;
        GSOGlobeControl globeControl2;

        public FrmShLayers(GSOGlobeControl _glb,GSODataSource _ds)
        {
            ds = _ds;
            globeControl2 = _glb;

            InitializeComponent();
        }


        private void FrmShLayers_Load(object sender, EventArgs e)
        {
            string pipelinetype = Utility.pipelinetype;
            string[] pipelinetypes = pipelinetype.Split(',');
            pipelineTypeCbo.Items.Clear();
            pipelineTypeCbo.Items.Add("全部");
            for (int i = 0; i < pipelinetypes.Length; i++)
            {
                pipelineTypeCbo.Items.Add(pipelinetypes[i]);
            }

            pipelineTypeCbo.Text = "全部";
            ////////////////////////////////////
            listBox1.Items.Clear();
            for (int i = 0; i < ds.DatasetCount; i++)
            {
                GSODataset dataset = ds.GetDatasetAt(i);
                if (dataset.Name.ToLower().Contains("network"))
                {
                    continue;
                }
                listBox1.Items.Add(dataset.Name);
            }
            buttonX1.Enabled = true;
        }
        /// <summary>
        /// 修改类型改变图层
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void pipelineTypeCbo_SelectedIndexChanged(object sender, EventArgs e)
        { 
            string pipelinetype =pipelineTypeCbo.Text;
            listBox1.Items.Clear();

            if (pipelinetype != "全部")
            {

                for (int i = 0; i < ds.DatasetCount; i++)
                {
                    GSODataset dataset = ds.GetDatasetAt(i);

                    if (dataset.Name.ToLower().Contains("network"))
                    {
                        continue;
                    }
                    if (!dataset.Name.Contains(pipelinetype))
                    {
                        continue;
                    }

                    listBox1.Items.Add(dataset.Name);
                }
            }
            else {
                for (int i = 0; i < ds.DatasetCount; i++)
                {
                    GSODataset dataset = ds.GetDatasetAt(i);
                    if (dataset.Name.ToLower().Contains("network"))
                    {
                        continue;
                    }
                    listBox1.Items.Add(dataset.Name);
                }
            }
            buttonX1.Enabled = true;
        }
        /// <summary>
        /// 添加进场景
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonX1_Click(object sender, EventArgs e)
        {
            //没连的话,直接连接审核库; //审核库配置读配置文件
            string dbIp = Utility.sgdbip;
            string database = Utility.sgdbname;
            string user = Utility.sgdbuser;
            string pass = Utility.sgdbpwd;

            //重新连接
            if (ds == null)
            {
                /*
                if (!Utility.isNetworkConnectionSuccess(dbIp.Trim()))
                {
                    MessageBox.Show("网络连接失败!", "提示");
                    return;
                }
                */

                ds = globeControl2.Globe.DataManager.OpenOracleDataSource(dbIp + "/" + database, "", "", user, pass);
                if (ds == null)
                {
                    MessageBox.Show("数据库连接失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            else {
                ds = globeControl2.Globe.DataManager.OpenOracleDataSource(dbIp + "/" + database, "", "", user, pass); 
            }

            if (listBox1.SelectedItems.Count > 0)
            {
                GSODataset dataset = ds.GetDatasetByName(listBox1.Text);
                GSOLayer layer = globeControl2.Globe.Layers.Add(dataset);

                if (layer != null)
                {
                    globeControl2.Globe.JumpToFeature(layer.GetFeatureByID(0), 100);
                    double x = layer.LatLonBounds.Center.X;
                    double y = layer.LatLonBounds.Center.Y;
                    globeControl2.Globe.JumpToPosition(new GSOPoint3d(x, y, 0), EnumAltitudeMode.Absolute,100);
                }
            }
            else {  
                MessageBox.Show("请选择要加入的图层!");
            }
        }
         

    }
}