Esempio n. 1
0
 private string FieldValueToSqlExp(Type fieldType, object fieldValue)
 {
     if (fieldType.Equals(typeof(string)))
     {
         return("'" + (fieldValue != null ? fieldValue.ToString() : string.Empty) + "'");
     }
     else if (fieldType.Equals(typeof(DateTime)))
     {
         return(_adapter.DateTimeToSql((DateTime)fieldValue));
     }
     else if (fieldType.Equals(typeof(Int16)) || fieldType.Equals(typeof(Int32)) || fieldType.Equals(typeof(Int64)) || fieldType.Equals(typeof(Byte)))
     {
         return(fieldValue.ToString());
     }
     else if (fieldType.Equals(typeof(enumShapeType)))
     {
         return("'" + fieldValue.ToString() + "'");
     }
     else if (fieldType.Equals(typeof(Envelope)))
     {
         Envelope evp = fieldValue as Envelope;
         if (evp != null)
         {
             return(_adapter.GeometryToSQL(evp.ToPolygon(), 4326)); //fdc+fixed
         }
     }
     throw new NotSupportedException("不支持的字段类型\"" + fieldType.ToString() + "\"。");
 }
Esempio n. 2
0
        private void InsertFeatures(IDbCommand cmd, Feature[] features, string[] fieldTypes, string tablename, IProgressTracker tracker, int span, string anntable, string[] annfields)
        {
            string flds = string.Empty;

            for (int i = 0; i < fieldTypes.Length; i++)
            {
                flds += (fieldTypes[i].Split(' ')[0] + ",");
            }
            flds = flds.Substring(0, flds.Length - 1);
            int ret = 0;
            int idx = -1;

            foreach (Feature fet in features)
            {
                idx++;
                int n = (idx / span);
                if (idx % span == 0 && tracker != null)
                {
                    tracker.Tracking("正在导入要素(" + (n * span).ToString() + "/" + features.Length.ToString() + ")...", n);
                }
                if (fet.Geometry == null)
                {
                    continue;
                }
                string sql = "insert into " + tablename + "(" + flds + ") values(" +
                             fet.OID.ToString() + ",";
                for (int i = 1; i < fieldTypes.Length - 1; i++)
                {
                    sql += ("'" + fet.GetFieldValue(i - 1) + "',");
                }
                //sql += _adapter.GeometryToSQL(fet.Geometry) + ")";
                sql += _adapter.GeometryToSQLByPara(fet.Geometry) + ")";
                IDbDataParameter ps = GetShapePara(fet.Geometry);
                cmd.Parameters.Add(ps);
                cmd.CommandText = sql;
                ret             = cmd.ExecuteNonQuery();
                //insert anno
                if (anntable != null && fet.Annotations != null && fet.Annotations.Length > 0)
                {
                    for (int annI = 0; annI < fet.Annotations.Length; annI++)
                    {
                        sql = "insert into " + anntable + "(" + _adapter.GetAnnonIDFieldNameSQLString() + "OID,ANGLE,SHAPE) values(" +
                              _adapter.GetAnnonIDFieldValueSQLString(annId) +
                              fet.OID.ToString() + "," + fet.Annotations[annI].Angle.ToString() + "," + _adapter.GeometryToSQL(fet.Annotations[annI].Location, SpatialRefToSRID()) + ")";
                        cmd.Parameters.Clear();
                        cmd.CommandText = sql;
                        ret             = cmd.ExecuteNonQuery();
                        annId++;
                    }
                }
                else
                {
                    cmd.Parameters.Clear();
                }
            }
        }