Newer
Older
GHFX_REFACTOR / FeatureTools.cs
xiaowei on 25 Nov 2016 3 KB 合并1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GeoScene.Data;
using GeoScene.Globe;

namespace Cyberpipe
{
    class FeatureTools
    {
        /// <summary>
        /// 清除地球上所有高亮的要素
        /// </summary>
        /// <param name="glb"></param>
        public static void ClearAllFeatureHighLight(GSOGlobeControl glb)
        {
            for (int i = 0; i < glb.Globe.Layers.Count; i++)
            {
                GSOLayer layer = glb.Globe.Layers[i];
                if (!(layer is GSOFeatureLayer)) continue;
                GSOFeatures feats = layer.GetAllFeatures();
                for (int j = 0; j < feats.Length; j++)
                {
                    feats[j].HighLight = false;
                }
            }
        }

        public static bool DeleteFeature(GSOFeature feature)
        {
            try
            {
                string layerName = feature.Dataset.Caption;

                //编号为空,为了限制删除的仅是用户自己添加的feature
                string bh = feature.GetFieldAsString("编号");
                if (bh == null) return false;
                if (!bh.EndsWith("TMP"))
                {
                    return false;
                }
                feature.Delete();//地球上删除该feature
                string sql = "delete from " + layerName + " where LSSYS_ID =" + feature.ID + " and (编号 is null or substr(编号,length(编号)-2)='TMP')";
                OledbHelper.sqlExecuteNonQuery(sql);//目前无法取到LSSYS_ID,所以这个判断条件不太合适,会导致把该类所有新建的都删除了
            }
            catch (Exception)
            {
                return false;
            }
            return true;
        }

        /// <summary>
        /// 根据编码,获取要素的种类描述
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public static string GetFeatureTypeByCode(string code)
        {
            if (code == null || code.Trim().Equals("")) return "";
            string result = "";
            foreach (PipelineType pipelineType in Utility.listPipelineType)
            {
                if (pipelineType == null || pipelineType.code.Trim() != code.Trim()) continue;
                result = pipelineType.type;
                if (!pipelineType.type.Equals(pipelineType.name))
                {
                    result += "   " + pipelineType.name;  
                }
                break;
            }
            return result;
        }

        public static string GetFieldValueByName(GSOFeature feature, string fieldName)
        {
            if (fieldName.Equals("图片编码"))
            {
                return null;
            }
            if (fieldName.Equals("模型路径"))
            {
                return null;
            }
            GSOFieldDefn field = feature.GetFieldDefn(fieldName);
            string value = "";
            if (field.Type == EnumFieldType.Text)
            {
                value = feature.GetFieldAsString(fieldName);
            }
            else if (field.Type == EnumFieldType.Date)
            {
                DateTime dd = Convert.ToDateTime(feature.GetFieldAsDataTime(fieldName));
                value = dd.Year <= 1 ? "" : dd.ToShortDateString();
            }
            else if (field.Type == EnumFieldType.Double)
            {
                double dl1 = feature.GetFieldAsDouble(fieldName);
                value = dl1.ToString("0.00");
            }
            else if (!feature.IsFieldValueNull(fieldName))
            {
                value = feature.GetValue(fieldName).ToString();
            }
            return value;
        }
    }
}