public WindowShapefiles() { InitializeComponent(); if (Settings.Settings.ApplicationRunning) { _listData = new ObservableCollection <ShapeFileInfo>(); var sfls = Settings.Settings.Default.GetShapeFileItems(); foreach (var si in sfls) { try { if (!string.IsNullOrEmpty(si.FileName) && System.IO.File.Exists(si.FileName)) { var sf = new ShapeFileInfo(); sf.Enabled = si.Enabled != 0; sf.Filename = si.FileName; sf.TableName = si.TableName; sf.TCoord = si.CoordType; sf.TArea = si.AreaType; sf.Prefix = si.NamePrefix; sf.Encoding = si.Encoding; using (ShapeFile s = new ShapeFile(sf.Filename)) { sf.TableNames = s.GetFields().ToList(); } sf.TAreas = Enum.GetNames(typeof(AreaType)).ToList(); sf.TCoords = Enum.GetNames(typeof(ShapeFile.CoordType)).ToList(); sf.TEncodings = new List <string>() { "utf-8", "ISO-8859-1" }; _listData.Add(sf); } } catch { } } DataContext = this; dataGrid.ItemsSource = _listData; } }
private void Button_Click(object sender, RoutedEventArgs e) { Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.FileName = ""; // Default file name dlg.DefaultExt = ".shp"; // Default file extension dlg.Filter = "Shapefile (.shp)|*.shp"; // Filter files by extension // Show open file dialog box Nullable <bool> result = dlg.ShowDialog(); // Process open file dialog box results if (result == true) { var sf = new ShapeFileInfo(); sf.Enabled = true; sf.Filename = dlg.FileName; sf.TableName = ""; sf.TCoord = ShapeFile.CoordType.WGS84.ToString(); sf.TArea = AreaType.Other.ToString(); sf.Prefix = ""; sf.Encoding = "utf-8"; sf.TEncodings = new List <string>() { "utf-8", "ISO-8859-1" }; using (ShapeFile s = new ShapeFile(sf.Filename)) { sf.TableNames = s.GetFields().ToList(); } sf.TAreas = Enum.GetNames(typeof(AreaType)).ToList(); sf.TCoords = Enum.GetNames(typeof(ShapeFile.CoordType)).ToList(); _listData.Add(sf); } }