Пример #1
0
        public List <InputFields> GetFieldValues(List <R_FieldInf> fieldInfs, FieldMapping vitalFields, string path)
        {
            List <InputFields> result  = new List <InputFields>();
            string             dbfpath = path;
            IntPtr             hDbf    = ShapeLib.DBFOpen(dbfpath, "rb+");

            int FieldCount = fieldInfs.Count();
            int PointCount = ShapeLib.DBFGetRecordCount(hDbf);

            for (int pi = 0; pi < PointCount; pi++)
            {
                InputFields point = new InputFields();
                string      other = "{";
                for (int i = 0; i < FieldCount; i++)
                {
                    if (fieldInfs[i].FieldName == vitalFields.ID)
                    {
                        IntPtr FieldvaluePtr = ShapeLib.DBFReadStringAttribute(hDbf, pi, i);
                        string FieldValue    = Marshal.PtrToStringAnsi(FieldvaluePtr, 255).Replace("\0", "");
                        point.ID = FieldValue;
                    }
                    else
                    {
                        if (fieldInfs[i].FieldName == vitalFields.Name)
                        {
                            IntPtr FieldvaluePtr = ShapeLib.DBFReadStringAttribute(hDbf, pi, i);
                            string FieldValue    = Marshal.PtrToStringAnsi(FieldvaluePtr, 255).Replace("\0", "");
                            point.Name = FieldValue;
                        }
                        else
                        {
                            if (fieldInfs[i].FieldName == vitalFields.Address)
                            {
                                IntPtr FieldvaluePtr = ShapeLib.DBFReadStringAttribute(hDbf, pi, i);
                                string FieldValue    = Marshal.PtrToStringAnsi(FieldvaluePtr, 255).Replace("\0", "");
                                point.Addresss = FieldValue;
                            }
                            else
                            {
                                if (fieldInfs[i].FieldName == vitalFields.Xcoordinate)
                                {
                                    IntPtr FieldvaluePtr = ShapeLib.DBFReadStringAttribute(hDbf, pi, i);
                                    string FieldValue    = Marshal.PtrToStringAnsi(FieldvaluePtr, 255).Replace("\0", "");
                                    point.X = FieldValue;
                                }
                                else
                                {
                                    if (fieldInfs[i].FieldName == vitalFields.Ycoordinate)
                                    {
                                        IntPtr FieldvaluePtr = ShapeLib.DBFReadStringAttribute(hDbf, pi, i);
                                        string FieldValue    = Marshal.PtrToStringAnsi(FieldvaluePtr, 255).Replace("\0", "");
                                        point.Y = FieldValue;
                                    }
                                    else
                                    {
                                        if (fieldInfs[i].FieldType == "text")
                                        {
                                            IntPtr FieldvaluePtr = ShapeLib.DBFReadStringAttribute(hDbf, pi, i);
                                            string FieldValue    = Marshal.PtrToStringAnsi(FieldvaluePtr, 255).Replace("\0", "");
                                            other += "\"" + fieldInfs[i].FieldName + "\":\"" + FieldValue + "\",";
                                        }
                                        else
                                        {
                                            if (fieldInfs[i].FieldType == "integer")
                                            {
                                                int FieldValue = ShapeLib.DBFReadIntegerAttribute(hDbf, pi, i);
                                                other += "\"" + fieldInfs[i].FieldName + "\":" + FieldValue + ",";
                                            }
                                            else
                                            {
                                                double FieldValue = ShapeLib.DBFReadDoubleAttribute(hDbf, pi, i);
                                                other += "\"" + fieldInfs[i].FieldName + "\":" + FieldValue + ",";
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                other       = other.Substring(0, other.Length - 1) + "}";
                point.Other = other;
                result.Add(point);
            }
            ShapeLib.DBFClose(hDbf);
            return(result);
        }