Beispiel #1
0
        public static List <VectorLayer> GetVectorLayerBySearchConditions(string dbName, SearchConditions sc)
        {
            if (String.IsNullOrEmpty(dbName) || sc == null)
            {
                return(null);
            }

            List <VectorLayer> VLs = new List <VectorLayer>();

            OracleConnection oraRasterConn;
            OracleCommand    oraCMD;
            OracleDataReader oraDataReader;

            oraRasterConn = DBCon.OraConOpen();;

            StringBuilder sql;

            sql = new StringBuilder("SELECT * FROM VECTOR_LAYERS WHERE 1=1 AND DBNAME='" + dbName + "' ");

            if (sc.area.Count > 0)
            {
                sql.Append("AND ( ");
                foreach (string s in sc.area)
                {
                    sql.Append(" AND REGION LIKE '" + s + "' OR ");
                }
                sql.Append("1<>1 )");
            }

            if (sc.datasource.Count > 0)
            {
                sql.Append("AND ( ");
                foreach (string s in sc.datasource)
                {
                    sql.Append(" AND DATASOURCES='" + s + "' OR ");
                }
                sql.Append("1<>1 )");
            }

            if (sc.scale.Count > 0 && sc.scale.Count == 2)
            {
                sql.Append(" AND SCALE BETWEEN " + sc.scale[0] + " AND " + sc.scale[1]);
            }

            if (!String.IsNullOrEmpty(sc.keywords))
            {
                sql.Append(" AND (LAYERNAME LIKE '" + sc.keywords + "%' OR DESCRIPTION LIKE '%" + sc.keywords + "%')");
            }

            oraCMD = new OracleCommand(sql.ToString(), oraRasterConn);


            try { oraDataReader = oraCMD.ExecuteReader(); }
            catch { return(null); }

            if (!oraDataReader.HasRows)
            {
                return(null);
            }

            VectorLayer VL;

            while (oraDataReader.Read())
            {
                int fieldCount = oraDataReader.FieldCount;
                VL = new VectorLayer();
                for (int i = 0; i < fieldCount; i++)
                {
                    string fieldName = oraDataReader.GetName(i).ToString();
                    if (fieldName.Equals("XMLFILE"))
                    {
                        try
                        {
                            byte[] data = (byte[])oraDataReader["XMLFILE"];

                            UTF8Encoding enc = new UTF8Encoding(true, true);//如果blob数据原本为utf8编码
                            VL.XMLFILE = System.Text.Encoding.UTF8.GetString(data);
                        }
                        catch
                        {
                            VL.XMLFILE = "";
                        }
                    }
                    else
                    {
                        VL = InitVectorData(VL, oraDataReader[fieldName], fieldName);
                    }
                }

                VLs.Add(VL);
            }
            oraRasterConn.Close();
            oraCMD.Dispose();

            return(VLs);
        }
Beispiel #2
0
        private static VectorLayer InitVectorData(VectorLayer VL, object obj, string fieldName)
        {
            try
            {
                switch (fieldName)
                {
                case "LAYERID": VL.LAYERID = Convert.ToString(obj); break;

                case "AUTHOR": VL.AUTHOR = Convert.ToString(obj); break;

                case "CREATETIME": VL.CREATETIME = Convert.ToString(obj); break;

                case "DATATYPE": VL.DATATYPE = Convert.ToString(obj); break;

                case "DBNAME": VL.DBNAME = Convert.ToString(obj); break;

                case "DESCRIPTION": VL.DESCRIPTION = Convert.ToString(obj); break;

                case "ISVISIBLE": VL.ISVISIBLE = Convert.ToBoolean(Convert.ToInt32(obj)); break;

                case "LAYERSIZE": VL.LAYERSIZE = Convert.ToInt64(obj); break;

                case "ISEXIST": VL.ISEXIST = Convert.ToBoolean(Convert.ToInt32(obj)); break;

                case "LAYERNAME": VL.LAYERNAME = Convert.ToString(obj); break;

                case "MAPNUM": VL.MAPNUM = Convert.ToString(obj); break;

                case "MAXX": VL.MAXX = Convert.ToSingle(obj); break;

                case "MAXY": VL.MAXY = Convert.ToSingle(obj); break;

                case "MINX": VL.MINX = Convert.ToSingle(obj); break;

                case "MINY": VL.MINY = Convert.ToSingle(obj); break;

                case "PROJECTION": VL.PROJECTION = Convert.ToString(obj); break;

                case "SCALE": VL.SCALE = Convert.ToInt64(obj); break;

                case "URI": VL.URI = Convert.ToString(obj); break;

                case "SHAPE": VL.SHAPE = Convert.ToString(obj); break;

                case "QUERYGRADER": VL.QUERYGRADER = Convert.ToInt32(obj); break;

                case "GETGRADER": VL.GETGRADER = Convert.ToInt32(obj); break;

                case "REGION": VL.REGION = Convert.ToString(obj); break;

                case "DATAGETDATE": VL.DATAGETDATE = Convert.ToDateTime(obj); break;

                case "DATAFORMAT": VL.DATAFORMAT = Convert.ToString(obj); break;

                case "DATASOURCES": VL.DATASOURCES = Convert.ToString(obj); break;

                default: break;
                }
            }
            catch
            {
                errMSG = fieldName + ";";
            }

            return(VL);
        }