private void btnAddValid_Click(object sender, RoutedEventArgs e) { if (txtOGC.Text.Length > 0) { foreach (string geomText in txtOGC.Text.Split('\n')) { if (geomText.Length > 0) { try { SqlGeometry g = SqlGeometry.Parse(geomText); if (!g.STIsValid()) { g = g.MakeValid(); } GeometryInfo gi = new GeometryInfo(); gi.Id = Guid.NewGuid().ToString(); gi.Data = g; lines.Add(gi); } catch (Exception) { } } } } }
private void btnAdd_Click(object sender, RoutedEventArgs e) { foreach (string geomText in txtOGC.Text.Split('\n')) { if (geomText.Length > 0) { GeometryInfo gi = new GeometryInfo(); gi.Id = Guid.NewGuid().ToString(); gi.Data = SqlGeometry.Parse(txtOGC.Text); lines.Add(gi); } } }
private void btnAddSQL_Click(object sender, RoutedEventArgs e) { try { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { cmd.CommandType = CommandType.Text; cmd.CommandText = txtSQL.Text; try { using (SqlDataReader rdr = cmd.ExecuteReader()) { rdr.Read(); int geomCol = 0; int idCol = -1; if (rdr.FieldCount > 2) { txtStatus.Text = "Error: the result cannot contain more than two columns."; return; } if (rdr.FieldCount == 2) { geomCol = 1; idCol = 0; } if (!(rdr[geomCol] is SqlGeometry)) { txtStatus.Text = "Error: the result set is not a geometry collection."; return; } int count = 0; do { if (rdr[geomCol] != DBNull.Value) { GeometryInfo gi = new GeometryInfo(); gi.Id = (idCol == 0 ? rdr[idCol].ToString() : count.ToString()); gi.Data = (SqlGeometry)rdr[geomCol]; lines.Add(gi); count++; } } while (rdr.Read()); txtStatus.Text = string.Format("Fetched {0} records.", count); } } catch (SqlException ex) { txtStatus.Text = string.Format("Could not execute SQL. The error returned was: {0}", ex.Message); } } conn.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }