/// <summary> /// Click event handler of the addMSSQLSpatialLayerToolStripMenuItem control. /// </summary> /// <param name="sender">The source object of this event.</param> /// <param name="e">The event parameters.</param> private void addMSSQLSpatialLayerToolStripMenuItem_Click(object sender, EventArgs e) { TreeNode source = CurrentTree.SelectedNode; if (source != null && source.Tag != null) RaiseItemSelect((MapObjectHolder)source.Tag); int numlayers = map.numlayers; SqlConnectionDialog form = new SqlConnectionDialog(); if (form.ShowDialog(this) == DialogResult.OK) { layerObj layer = null; try { // trying to open the layer MapUtils.TestMSSQLConnection(form.GetConnectionString(), form.GetDataString()); layer = CreateNewLayer(); layer.connectiontype = MS_CONNECTION_TYPE.MS_PLUGIN; layer.plugin_library = layer.plugin_library_original = "msplugin_mssql2008.dll"; layer.connection = form.GetConnectionString(); layer.data = form.GetDataString(); switch (form.GeometryType) { case "Point": case "MultiPoint": layer.type = MS_LAYER_TYPE.MS_LAYER_POINT; break; case "LineString": case "MultiLineString": layer.type = MS_LAYER_TYPE.MS_LAYER_LINE; break; case "Polygon": case "MultiPolygon": layer.type = MS_LAYER_TYPE.MS_LAYER_POLYGON; break; default: layer.type = MS_LAYER_TYPE.MS_LAYER_LINE; break; } MapUtils.CreateRandomClass(layer); MapUtils.InitializeDefaultLabel(layer); layer.name = MapUtils.GetUniqueLayerName(map, form.TableName, 0); string projName; string proj4text; int epsg; if (form.GetProj4Text() != null) { projName = MapUtils.FindProjection(form.GetProj4Text(), out proj4text, out epsg); layer.setProjection(form.GetProj4Text()); layer.setMetaData("coordsys_name", projName); } else if (form.GetSRText() != null && form.GetSRText() != "") { SpatialReference srs = new SpatialReference(form.GetSRText()); string proj4; srs.ExportToProj4(out proj4); if (proj4 != null || proj4 != "") { projName = MapUtils.FindProjection(proj4, out proj4text, out epsg); //Steph: looks like there was a copy and paste error, I have replaced form.GetProj4Text() with proj4text layer.setProjection(proj4text); layer.setMetaData("coordsys_name", projName); } } else layer.setProjection("AUTO"); layer.status = mapscript.MS_ON; // setting up the selected layer selected = new MapObjectHolder(layer, target.GetParent()); } catch (Exception ex) { MessageBox.Show("Unable to open layer, " + ex.Message, "MapManager", MessageBoxButtons.OK, MessageBoxIcon.Error); if (layer != null) { if (layer.map != null) layer.map.removeLayer(layer.index); layer = null; } return; } // if this is the first layer or the map projection hasn't been set zoom to this extent if (map.numlayers == 1 || map.getProjection().Trim().Length == 0) { ZoomToLayerExtent(layer); if (InitialExtentSet != null) InitialExtentSet(this, null); // setting the projection of the map according to the layer projection string proj = layer.getProjection().Trim(); if (proj.Length > 0 && proj != "+AUTO") { map.setProjection(proj); // setting up the default unit if (proj.Contains("+proj=longlat")) map.units = MS_UNITS.MS_DD; else map.units = MS_UNITS.MS_METERS; } } if (target != null) target.RaisePropertyChanged(this); RefreshView(); TreeNode src = CurrentTree.SelectedNode; if (src != null && src.Tag != null) RaiseItemSelect((MapObjectHolder)src.Tag); UpdateToolbar(); } }
/// <summary> /// Click event handler of the buttonData control. /// </summary> /// <param name="sender">The source object of this event.</param> /// <param name="e">The event parameters.</param> private void buttonData_Click(object sender, EventArgs e) { if (comboBoxPlugin.SelectedItem != null && comboBoxPlugin.SelectedItem.ToString() == "msplugin_mssql2008.dll") { SqlConnectionDialog cd = new SqlConnectionDialog(); if (textBoxConnection.Text.Trim() != "") cd.SetConnectionString(textBoxConnection.Text.Trim()); if (textBoxData.Text.Trim() != "") cd.SetDataString(textBoxData.Text.Trim()); if (cd.ShowDialog(this) == DialogResult.OK) { try { MapUtils.TestMSSQLConnection(cd.GetConnectionString(), cd.GetDataString()); textBoxConnection.Text = cd.GetConnectionString(); string data = cd.GetDataString(); if (data != null) textBoxData.Text = data; SetDirty(true); } catch (Exception ex) { MessageBox.Show("Unable to open layer, " + ex.Message, "MapManager", MessageBoxButtons.OK, MessageBoxIcon.Error); } } return; } if (layer.map != null) openFileDialog.InitialDirectory = layer.map.shapepath; openFileDialog.Filter = null; if (openFileDialog.ShowDialog(this) == DialogResult.OK) { textBoxData.Text = openFileDialog.FileName; SetDirty(true); } }