Newer
Older
GHFX_REFACTOR / FrmAddWellShp.cs
xiaowei on 7 Nov 2016 8 KB 完成入库程序测试和修改
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Collections;
using GeoScene.Data;
using System.Text.RegularExpressions;
using GeoScene.Engine;
using GeoScene.Globe;
using System.Xml;
using DevComponents.DotNetBar;

namespace Cyberpipe
{
    public partial class FrmAddWellShp : Office2007Form
    {
        GeoScene.Globe.GSOGlobeControl globeControl1;
        GSODataSource ds;
        private Hashtable gj_cns = new Hashtable();
        private Hashtable gj_types = new Hashtable();
        public GSOLayer rukuLayer = null;

        public FrmAddWellShp(GeoScene.Globe.GSOGlobeControl _globeControl1, GSODataSource _ds)
        {
            globeControl1 = _globeControl1;
            ds = _ds;
            InitializeComponent();
        }

        private ArrayList files =new ArrayList ();
        private ArrayList modeltypes = new ArrayList(); //井的型号
        private ArrayList deeps = new ArrayList();

        private bool invalidate()
        {
            if (comboBoxLayer.SelectedItem.ToString().Trim() == "")
            {
                MessageBox.Show("请选择一个图层文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return false;
            }
            if (txtLayerName.Text.ToString().Trim() == "")
            {
                MessageBox.Show("图层名称为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return false;
            }
            Regex reg = new Regex("^[0-9]");
            if (reg.Match(txtLayerName.Text.Trim()).Success)
            {
                MessageBox.Show("图层名称不能以数字开头!", "警告");
                return false;
            }
            return true;
        }
        /// <summary>
        /// 确定按钮事件处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button3_Click(object sender, EventArgs e)
        {
            if (invalidate() == false)
                return;
            try
            {
                ModelBuilder pointBuilder = new PointBuilder(ds);

                GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(Path.GetFileNameWithoutExtension(comboBoxLayer.Text.ToString()));

                PointParam pointParam = new PointParam();
                pointParam.layerName = txtLayerName.Text.ToString();
                pointParam.uniqueIdFieldName = comboBoxCode.Text.ToString();
                pointParam.upGround = Convert.ToDouble(txtUpGround.Text.ToString());
                pointParam.attachNameFieldName = combModelName.Text.ToString();
                pointParam.pointEncodingFieldName = combCode.Text.ToString();
                pointParam.wellDepthFiledName = combDeep.Text.ToString();
                pointParam.altitudeFieldName = comboBoxGC.Text.ToString();
                pointParam.z = comboBoxZ.Text.ToString();

                pointBuilder.build(layer, checkBoxAdd.Checked ? EnumUpdateMode.Append : EnumUpdateMode.Update,
                    checkBoxDeep.Checked ? EnumBuildMode.Depth : EnumBuildMode.Alititude, pointParam);

                MessageBox.Show("入库完成!", "提示");
            }
            catch (Exception ex)
            {
                LogError.PublishError(ex);
                LogHelper.WriteLog(typeof(FrmAddWellShp), ex.Message);
            }
        }
        /// <summary>
        /// 窗体初始化事件处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FrmAddWellShp_Load(object sender, EventArgs e)
        {
            //填充SHP数据列表
            comboBoxLayer.Items.Clear();

            if (globeControl1 != null)
            {
                for (int i = 0; i < globeControl1.Globe.Layers.Count; i++)
                {
                    GSOLayer layer = globeControl1.Globe.Layers[i];
                    if (layer != null && layer.Name.ToLower().EndsWith(".shp"))
                    {
                        comboBoxLayer.Items.Add(layer.Name.Trim());
                    }
                }
            }
        }

        private void FrmAddWellShp_FormClosing(object sender, FormClosingEventArgs e)
        {
            globeControl1.Globe.Refresh();
        }

        private void clearComboboxParam()
        {            
            comboBoxCode.Enabled = true;
            combModelName.Enabled = true;
            combCode.Enabled = true;
            combDeep.Enabled = true;
            comboBoxGC.Enabled = true;
            comboBoxZ.Enabled = true;

            txtLayerName.Text = "";
            comboBoxCode.Items.Clear();
            combModelName.Items.Clear();
            combCode.Items.Clear();
            combDeep.Items.Clear();
            comboBoxGC.Items.Clear();
            comboBoxZ.Items.Clear();

        }

        private void addComboboxParam(string strParam)
        {
            comboBoxCode.Items.Add(strParam);
            combModelName.Items.Add(strParam);
            combCode.Items.Add(strParam);
            combDeep.Items.Add(strParam);
            comboBoxGC.Items.Add(strParam);
            comboBoxZ.Items.Add(strParam);
        }

        private void initComboboxPraram(GSOFeature feature)
        {
            if (ExitFiled(feature, "管点编码")) //特征管点
            {
                comboBoxCode.SelectedItem = "编号";
                combModelName.SelectedItem = "管点特征";
                combCode.SelectedItem = "管点编码";
                comboBoxGC.SelectedItem = "地面高程";
                comboBoxZ.SelectedItem = "Z坐标";
                combDeep.Enabled = false;
            }
            else if (ExitFiled(feature, "附属物编码")) //附属物
            {
                comboBoxCode.SelectedItem = "编号";
                combModelName.SelectedItem = "附属物名称";
                combCode.SelectedItem = "附属物编码";
                combDeep.SelectedItem = "井深";
                comboBoxGC.SelectedItem = "地面高程";
                comboBoxZ.Enabled = false;
            }
            else
            {
                comboBoxCode.SelectedItem = "编号";
                combModelName.Enabled = false;
                combCode.SelectedItem = "图层编号";
                combDeep.SelectedItem = "标识器埋深";
                comboBoxGC.SelectedItem = "地面高程";
                comboBoxZ.Enabled = false; 
            }
        }

        private bool ExitFiled(GSOFeature feature, string filedName)
        {
            GSOFeatureDataset featDataSet = feature.Dataset as GSOFeatureDataset;
            for (int i = 0; i < featDataSet.FieldCount; i++)
            {
                if (featDataSet.GetField(i).Name == filedName)
                    return true;
            }
            return false;
        }
        private void comboBoxLayer_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBoxLayer.SelectedIndex == -1)
                return;
            string layerName=Path.GetFileNameWithoutExtension(comboBoxLayer.Text.ToString());

            GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(layerName);

            GSOFeatures features = layer.GetAllFeatures();
            if (features.Length == 0)
                return;

            clearComboboxParam();
            txtLayerName.Text = layerName;

            for (int i = 0; i < features[0].GetFieldCount(); i++)
            {
                GeoScene.Data.GSOFieldDefn fielddef = (GeoScene.Data.GSOFieldDefn)(features[0].GetFieldDefn(i));
                addComboboxParam(fielddef.Name);
            }

            initComboboxPraram(features[0]);

        }

        private void checkBoxAdd_CheckedChanged(object sender, EventArgs e)
        {
            checkBoxReset.Checked = !checkBoxAdd.Checked;
        }

        private void checkBoxReset_CheckedChanged(object sender, EventArgs e)
        {
            checkBoxAdd.Checked = !checkBoxReset.Checked;
        }

        private void checkBoxDeep_CheckedChanged(object sender, EventArgs e)
        {
            checkBoxH.Checked = !checkBoxDeep.Checked;
        }

        private void checkBoxH_CheckedChanged(object sender, EventArgs e)
        {
            checkBoxDeep.Checked = !checkBoxH.Checked;
        }




    }
}