Esempio n. 1
0
        //still work needs to be done
        public static void SDFReadSpecific(string SDFFile, string col)
        {
            try
            {
                //this is to read a specific value
                IConnection con = SDFHelper.SDFConnection(SDFFile);
                con.Open();
                using (con)
                {
                    using (osgeo_command.Feature.ISelect get_data = con.CreateCommand(osgeo_command.CommandType.CommandType_Select) as osgeo_command.Feature.ISelect)
                    {
                        //set target schema
                        get_data.SetFeatureClassName("Civil_schema:Pipes");

                        //filter data
                        var filter = "(Name='R-1P1')";
                        get_data.SetFilter(filter);

                        //execute the select command
                        using (IFeatureReader reader = get_data.Execute())
                        {
                            //get class defninition
                            ClassDefinition cdef = reader.GetClassDefinition();

                            //print the column name
                            foreach (PropertyDefinition def in cdef.Properties)
                            {
                                if (def is DataPropertyDefinition)
                                {
                                    if (def.Name == col)
                                    {
                                        //get only data properties
                                        var    p     = (DataPropertyDefinition)def;
                                        string value = "";
                                        //value = reader.GetString(p.Name).ToString();
                                        //ed.WriteMessage("\nValue: " + value);

                                        /*depending upon the datatype use appropriate get method.
                                         * switch (p.DataType)
                                         * {
                                         *  case OSGeo.FDO.Schema.DataType.DataType_String:
                                         *      value = reader.IsNull(p.Name) ? "" : reader.GetString(p.Name).ToString();
                                         *      break;
                                         * }
                                         * ed.WriteMessage(value);
                                         */
                                    }
                                    //ed.WriteMessage("\nColumn name : " + def.Name);
                                }
                            }
                            //get the value
                            while (reader.ReadNext())
                            {
                                //for each property print value
                                foreach (PropertyDefinition def in cdef.Properties)
                                {
                                    //only data properties
                                    if (!(def is DataPropertyDefinition))
                                    {
                                        continue;
                                    }
                                    var    p     = (DataPropertyDefinition)def;
                                    string value = "";

                                    //depending upon the data type, use the approriate "GET"
                                    //method on the reader
                                    switch (p.DataType)
                                    {
                                    case OSGeo.FDO.Schema.DataType.DataType_Boolean:
                                        value = reader.IsNull(p.Name) ? "" : reader.GetBoolean(p.Name).ToString();
                                        break;

                                    case OSGeo.FDO.Schema.DataType.DataType_String:
                                        value = reader.IsNull(p.Name) ? "" : reader.GetString(p.Name).ToString();
                                        break;
                                    }
                                    Debug.Write("\nvalue == " + value);
                                }
                            }
                            reader.Close();
                        }
                    }
                }
            }
            catch (OSGeo.FDO.Common.Exception ge)
            {
                bool ok = ge.Message.Contains("read-only");
                Debug.Write(ge.ToString());
            }
            catch (SystemException ex)
            {
                bool ok = ex.Message.Contains("read-only");
                Debug.Write(ex.ToString());
            }
        }
Esempio n. 2
0
        public static void SDFRead(string SDFFile, string schemaName, string filter_value)
        {
            //this is to read value of a property
            //ZSharpLogger.DebugHelper.printVSConsole("SDFH", "Read Data module running...", true);
            //ed.WriteMessage("\nRead Data module running...");
            try
            {
                IConnection con = SDFHelper.SDFConnection(SDFFile);
                con.Open();
                using (con)
                {
                    using (osgeo_command.Feature.ISelect get_data = con.CreateCommand(osgeo_command.CommandType.CommandType_Select) as osgeo_command.Feature.ISelect)
                    {
                        //set target schema
                        get_data.SetFeatureClassName("Civil_schema:Pipes");
                        var filter = "(Name='R-1P1')";
                        //var filter = "(" + filter_value + ")";
                        get_data.SetFilter(filter);
                        //get_data.Filter.

                        //count the number of rowms
                        int count = 0;

                        //execute the select command
                        using (IFeatureReader reader = get_data.Execute())
                        {
                            //get class definition
                            ClassDefinition cdef = reader.GetClassDefinition();
                            //ZSharpLogger.DebugHelper.printVSConsole("SDFH", "Class definition: " + cdef.Name, true);
                            //ed.WriteMessage("\nClass definition: " + cdef.Name);

                            //string array to print each row
                            ArrayList row = new ArrayList();

                            //print the column name
                            foreach (PropertyDefinition def in cdef.Properties)
                            {
                                if (def is DataPropertyDefinition)
                                {
                                    var p = (DataPropertyDefinition)def;
                                    row.Add(def.Name);
                                    //ZSharpLogger.DebugHelper.printVSConsole("SDFH", "Property Header Name: " + def.Name, true);
                                    //ed.WriteMessage("\nProperty Header Name: " + def.Name);
                                }
                                // Print the header row (property names)
                                //ed.WriteMessage(string.Join("\t", row.ToArray()));
                            }
                            while (reader.ReadNext())
                            {
                                row.Clear();
                                try
                                {
                                    //for each property print value
                                    foreach (PropertyDefinition def in cdef.Properties)
                                    {
                                        try
                                        {
                                            //only data properties
                                            if (!(def is DataPropertyDefinition))
                                            {
                                                continue;
                                            }
                                            var    p     = (DataPropertyDefinition)def;
                                            string value = "";
                                            value = FDODataHelper.expressionToString(FDODataHelper.ParseByDataType(reader.ToString(), p.DataType));
                                            //ZSharpLogger.DebugHelper.printVSConsole("SDFH", "Value: " + value, true);
                                            //depending upon the data type, use the approriate "GET"
                                            //method on the reader
                                            switch (p.DataType)
                                            {
                                            case OSGeo.FDO.Schema.DataType.DataType_Boolean:
                                                value = reader.IsNull(p.Name) ? "" : reader.GetBoolean(p.Name).ToString();
                                                break;

                                            case OSGeo.FDO.Schema.DataType.DataType_String:
                                                value = reader.IsNull(p.Name) ? "" : reader.GetString(p.Name).ToString();
                                                break;
                                            }
                                            row.Add(value);
                                            //ZSharpLogger.DebugHelper.printVSConsole("SDFH", "Value: " + value, true);
                                            //ed.WriteMessage("\nvalue == " + value);
                                        }
                                        catch (System.Exception ex)
                                        {
                                            //ZSharpLogger.DebugHelper.printVSConsole("SDFH", "Exception: " + ex, true);
                                            //System.Windows.MessageBox.Show(ex.Message);
                                        }
                                    }
                                }
                                catch (System.Exception ex)
                                {
                                    //ZSharpLogger.DebugHelper.printVSConsole("SDFH", "Exception: " + ex, true);
                                    //System.Windows.MessageBox.Show(ex.Message);
                                }

                                //ed.WriteMessage(string.Join("\t", row.ToArray()));
                                count++;
                            }
                            reader.Close();
                        }
                        //ed.WriteMessage("{0} rows.", count);
                    }
                    con.Close();
                }
            }
            catch (OSGeo.FDO.Common.Exception ex)
            {
                //ZSharpLogger.DebugHelper.printVSConsole("SDFH", "Exception: " + ex, true);
                //ed.WriteMessage("\nException:" + ge.Message);
                //bool ok = ge.Message.Contains("read-only");

                //ed.WriteMessage("no read-only for the schema", ok);
            }
        }