Newer
Older
GHFX_REFACTOR / FrmYJSHTC.cs
wxn on 2 Nov 2016 6 KB 提交
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 DevComponents.DotNetBar;
using GeoScene.Data;
using GeoScene.Engine;
using GeoScene.Globe;

namespace Cyberpipe
{
    public partial class FrmYJSHTC : Office2007Form
    {

        public GSOLayer rukuLayer = null;
        GSOGlobeControl ctl2 = null;
        GSOGlobeControl ctl1 = null;
        GSODataSource youDS = null;
        string selectLayerName = null;
        GSODataSource dataset = null;
        TreeView layerTree;

        public FrmYJSHTC(GSOGlobeControl _ctl1,GSOGlobeControl _ctl2,TreeView _layerTree)
        {
            InitializeComponent();
            this.ctl2 = _ctl2;
            this.ctl1 = _ctl1;
            this.layerTree = _layerTree;
        }

        public FrmYJSHTC()
        {
            InitializeComponent();
        }

        private void FrmYJSHTC_Load(object sender, EventArgs e)
        {
            AddData("");
        }

        private void AddData(string str)
        {
            try
            {
                DataTable dt = new DataTable();
                dt.Columns.Add("图层名称");
                dt.Columns.Add("审核");
                dt.Columns.Add("操作");

                youDS = ctl2.Globe.DataManager.OpenOracleDataSource(Utility.sgdbip + "/" + Utility.sgdbname, "", "", Utility.sgdbuser, Utility.sgdbpwd);
                if (youDS.DatasetCount == 0)
                {
                    return;
                }
                else
                {
                    for (int i = youDS.DatasetCount - 1; i > -1; i--)
                    {
                        GSODataset dataset = youDS.GetDatasetAt(i);
                        if (dataset != null)
                        {
                            if (dataset.Caption.Contains("SH"))
                            {
                                if (str == "")
                                {
                                    DataRow row = dt.NewRow();
                                    row[0] = dataset.Name;
                                    row[1] = "审核";
                                    row[2] = "删除";

                                    dt.Rows.Add(row);
                                }
                                else
                                {
                                    if (dataset.Caption.Contains(str))
                                    {
                                        DataRow row = dt.NewRow();
                                        row[0] = dataset.Name;
                                        row[1] = "审核";
                                        row[2] = "删除";

                                        dt.Rows.Add(row);
                                    }
                                }
                            }
                        }
                    }
                    dataGridViewX1.DataSource = dt;
                }

            }
            catch (Exception ex)
            {

            }
        }

        private void FrmYJSHTC_FormClosing(object sender, FormClosingEventArgs e)
        {
            //youDS.Close();
        }

        private void textBoxCode_TextChanged(object sender, EventArgs e)
        {
            AddData(textBoxCode.Text.ToString());
        }

        private void dataGridViewX1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex != -1 && e.ColumnIndex != -1)
            {
                string strLayerName = dataGridViewX1.Rows[e.RowIndex].Cells["图层名称"].Value.ToString();

                if (dataGridViewX1.Columns[e.ColumnIndex].HeaderText == "审核")
                {
                    ShenHe(strLayerName);
                }
                else
                    if (dataGridViewX1.Columns[e.ColumnIndex].HeaderText == "操作")
                    {
                        deleteLayer(strLayerName);
                        AddData("");
                    }
            }
        }

        private void ShenHe(string strLayerName)
        {

            selectLayerName = strLayerName;

            dataset = ctl1.Globe.DataManager.OpenOracleDataSource(Utility.sgdbip.Trim() + "/" + Utility.sgdbname.Trim(), "",
                       "", Utility.sgdbuser, Utility.sgdbpwd);

            GSODataset dt = dataset.GetDatasetByName(selectLayerName);
            GSOFeatureDataset layer = dt as GSOFeatureDataset;

            GSOLayer sourceLayer2 = ctl1.Globe.Layers.GetLayerByCaption(selectLayerName);

            if (sourceLayer2 != null)
            {
                ctl1.Globe.Layers.Remove(sourceLayer2);
            }

            layer.Caption = layer.Name;

            GSOLayer layerRuku = ctl1.Globe.Layers.Add(layer);

            rukuLayer = layerRuku;
            //重新调整模型位置,这样可以保证新入库的管线也能通过调节透明度隐现
            ctl1.Globe.Layers.MoveTo(0, ctl1.Globe.Layers.Count - 1);
            ctl1.Globe.Refresh();

            this.DialogResult = DialogResult.OK;

        }

        private void deleteLayer(string str)
        {
            if (MessageBox.Show("确定要删除所有选中的图层吗 ?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                if (dataset == null)
                {
                    dataset = ctl1.Globe.DataManager.OpenOracleDataSource(Utility.sgdbip.Trim() + "/" + Utility.sgdbname.Trim(), "",
                           "", Utility.sgdbuser, Utility.sgdbpwd);
                }
                dataset.DeleteDatasetByName(str);

                for (int i = ctl1.Globe.Layers.Count - 1; i >= 0; i--)
                {
                    if (ctl1.Globe.Layers[i].Caption == str)
                    {
                        ctl1.Globe.Layers.Remove(ctl1.Globe.Layers[i]);
                    }
                }

                foreach (TreeNode n in layerTree.Nodes)
                {
                    if (n.Text == "临时图层")
                    {
                        for (int i = 0; i < n.Nodes.Count; i++)
                        {
                            if (n.Nodes[i].Text == str)
                            {
                                n.Nodes[i].Remove();
                            }
                        }
                    }
                }

                string sql = "delete from casic_audit_result where SH_LAYER = '" + str + "'";

                OledbHelper.sqlExecuteNonQuery(sql);

            }
        }


    }
}