Example #1
0
        /// <summary>
        /// 查询数据,将查询到的结果放到新建的 temp 类中
        /// </summary>
        /// <param name="className">要查询的类的名字</param>
        /// <param name="search">查询语句</param>
        /// <param name="tempClass">要创建的临时类</param>
        /// <returns></returns>
        public static bool SearchData(string className, string search, string tempClass)
        {
            //定义变量
            IVectorCls VectorCls = new SFeatureCls();
            //打开简单要素类
            bool rtn = VectorCls.Open("GDBP://MapGisLocal/Templates/sfcls/" + className);

            if (!rtn)
            {
                PUMessageBox.ShowDialog("简单要素类 " + className + " 打开失败", "失败");
                return(false);
            }

            QueryDef def = new QueryDef();

            //设置属性查询条件
            def.Filter = search;
            //查询要素
            RecordSet recordSet = VectorCls.Select(def);

            if (recordSet != null)
            {
                int num = recordSet.Count;
            }
            else
            {
                return(false);
            }

            Server svr = new Server();

            //连接数据源
            svr.Connect("MapGISLocal", "", "");
            DataBase    GDB      = svr.OpenGDB("templates");
            SFeatureCls tmpSFCls = new SFeatureCls(GDB);
            int         id       = tmpSFCls.Create(tempClass, GeomType.Pnt, 0, 0, null);

            if (id == 0)
            {
                bool temp = SFeatureCls.Remove(GDB, tempClass);
                id = tmpSFCls.Create(tempClass, GeomType.Pnt, 0, 0, null);
                if (id == 0)
                {
                    PUMessageBox.ShowDialog("无法操作简单要素类,请检查是否有其他进程正在使用 " + tempClass, "失败");
                    return(false);
                }
            }

            rtn = tmpSFCls.CopySet(recordSet);
            if (rtn == false)
            {
                tmpSFCls.Close();
                SFeatureCls.Remove(GDB, id);
            }
            //关闭类
            VectorCls.Close();
            return(true);
        }