Pessoal,
Conforme dúvida postada anteriormente, estou enviando o código para
ajuda. São duas (pelo menos por agora - rs):
1) Ao clicar na layer, o object_id está null. Acho que estou fazendo
alguma coisa errada no momento de carregar a layer (é um achismo).
2) Quando clico na layer seleciono o registro da tabela
(TeCa_Mapa_onDblClick()). O problema é que como não consegui
selecionar o id do polígono,
estou buscando usando as coordenadas, o que nem sempre da certo (pelo
menos da maneira que implementei - serviu de paliativo). Penso que,
pelo fato de não ter conseguido o valor o object_id, não encontrei
outro forma de fazer.
Alguem teria uma solução?
Como estou começando a usar o TCom, estou como base o código
disponibilizado no site.
Grato,
Maurício
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data.OleDb;
using System.IO;
namespace GeoIrrigacao
{
public partial class frmTubulacao : Form
{
public static ADODB.Connection _conn;
public static ADODB.Recordset _rs;
public static bool _normal;
// último object_id selecionad0
public static string objIdSelecionado;
public static string nomeTabelaGeometrias;
public frmTubulacao()
{
InitializeComponent();
}
private void btnProximo_Click(object sender, EventArgs e)
{
string ConnectionStr =
@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:
\TerraLIB_VS2010\Database\canvas.mdb;Persist Security
Info=True";
try
{
_conn = new ADODB.Connection();
_conn.Open(ConnectionStr, "", "");
_rs = new ADODB.Recordset();
TeCa_Mapa.connectionString = ConnectionStr;
TeCa_Mapa.openConnection();
TeCa_Mapa.connection = _conn;
TeCa_Mapa.setProjection("UTM");
TeCa_Mapa.setCurrentLayer("municip07");
TeCa_Mapa.addLayerToSelect("municip07");
nomeTabelaGeometrias =
getGeometryLayerName("municip07", "Polygons");
TeCa_Mapa.plotView();
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message);
}
try
{
municip07TableAdapter.Connection.ConnectionString =
ConnectionStr;
}
catch (System.Exception excep)
{
mensagemOkAborta("008 - Não realiza conexão inicial
com o banco de dados.\n" + excep.Message);
}
setNormal(true);
}
private string getGeometryLayerName(string nomeLayer, string
tipoGeometria)
{
string nomeLayerGeometria = "";
try
{
string sql;
sql = "SELECT layer_id FROM te_layer WHERE name = '"
+ nomeLayer + "'";
_rs.Open(sql, _conn,
ADODB.CursorTypeEnum.adOpenKeyset,
ADODB.LockTypeEnum.adLockOptimistic, -1);
nomeLayerGeometria = tipoGeometria +
Convert.ToString(_rs.Fields[0].Value);
_rs.Close();
}
catch
{
mensagemOkAborta("003 - Não encontra o layer de
polígonos");
}
return nomeLayerGeometria;
}
private void mensagemOkAborta(string mensagem)
{
MessageBox.Show(mensagem, "Saindo da Aplicação",
MessageBoxButtons.OK);
System.Windows.Forms.Application.Exit();
}
private void btnAnterior_Click(object sender, EventArgs e)
{
if (getNormal())
{
setNormal(false);
TeCa_Mapa.zoomArea();
}
}
private void btnZoomInicial_Click(object sender, EventArgs e)
{
if (getNormal())
TeCa_Mapa.recompose();
}
private void btnNavegar_Click(object sender, EventArgs e)
{
if (getNormal())
TeCa_Mapa.pan();
}
private void TeCa_Mapa_onDblClick(object sender,
AxTECOMCANVASLib._ITeCanvasEvents_onDblClickEvent e)
{
string _coord_x;
string _coord_y;
string sql;
try
{
_coord_x = tbIdAreaX.Text.Replace(",", ".");
_coord_y = tbIdAreaY.Text.Replace(",", ".");
sql = "SELECT * FROM municip07, Polygons1" +
" WHERE municip07.object_id_1 =
Polygons1.object_id" +
" AND lower_x <= " + _coord_x + " AND upper_x
>= " + _coord_x +
" AND lower_y <= " + _coord_y + " AND upper_y
>= " + _coord_y;
_rs.Open(sql, _conn,
ADODB.CursorTypeEnum.adOpenKeyset,
ADODB.LockTypeEnum.adLockOptimistic, -1);
if (_rs.RecordCount == 0)
MessageBox.Show("Nenhum registro encontrado.");
else
{
localiza(Convert.ToString(_rs.Fields[2].Value));
addPoint("municip07");
}
_rs.Close();
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message);
}
}
private void TeCa_Mapa_onMouseMove(object sender,
AxTECOMCANVASLib._ITeCanvasEvents_onMouseMoveEvent e)
{
tbIdAreaX.Text = e.x.ToString("N");
tbIdAreaY.Text = e.y.ToString("N");
}
private void btnZoomMais_Click(object sender, EventArgs e)
{
// Aproxima
TeCa_Mapa.zoomIn((float)0.3);
}
private void btnZoomMenos_Click(object sender, EventArgs e)
{
// Afasta
TeCa_Mapa.zoomOut((float)0.3);
}
private void addPoint(string _layer)
{
// Define o plano de edição
TeCa_Mapa.setCurrentLayer(_layer);
// Limpa todos os itens selecionados em memória
TeCa_Mapa.clearSelectItens(0);
// Adiciona pontos ao plano definido como edição
TeCa_Mapa.drawPoint();
}
private void TeCa_Mapa_onKeyPress(object sender,
AxTECOMCANVASLib._ITeCanvasEvents_onKeyPressEvent e)
{
if (e.key == 27)
{
setNormal(true);
}
else
{
//
}
}
private void setNormal(bool _set)
{
if (_set == true)
TeCa_Mapa.normal();
_normal = _set;
}
private bool getNormal()
{
return _normal == true;
}
private void frmTubulacao_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the
'canvasDataSet1.municip07' table. You can move, or remove it, as
needed.
this.municip07TableAdapter.Fill(this.canvasDataSet1.municip07);
// TODO: This line of code loads data into the
'canvasDataSet1.municip07' table. You can move, or remove it, as
needed.
//
this.municip07TableAdapter.Fill(this.canvasDataSet1.municip07);
}
private void dgvMunicipio_MouseClick(object sender,
MouseEventArgs e)
{
int i;
// Obtem a linha corrente selecionada no datagridview da
espécie
DataGridViewRow linhaAtual = dgvMunicipio.CurrentRow;
// Obter a linha que foi selecionada, começando em zero
i = linhaAtual.Index;
// obter o id_praca da linha que está selecionada
object theValue = this.dgvMunicipio[0, i].Value;
TeCa_Mapa.getSelectGeoId(0, 4);
addPoint("municip07");
MessageBox.Show(i.ToString());
}
private void btnPesquisa_Click(object sender, EventArgs e)
{
localiza(tbPesquisa.Text);
}
private void localiza(string _valor)
{
int i;
for (i = 0; i < this.dgvMunicipio.Rows.Count - 1; i++)
{
if (this.dgvMunicipio[2, i].Value.ToString() ==
_valor)
{
this.dgvMunicipio.CurrentCell =
this.dgvMunicipio.Rows[i].Cells[0];
break;
}
}
}
private void TeCa_Mapa_onMouseDown(object sender,
AxTECOMCANVASLib._ITeCanvasEvents_onMouseDownEvent e)
{
objIdSelecionado = TeCa_Mapa.object_id;
MessageBox.Show(objIdSelecionado);
}
}
}
On 14 mar, 08:59, Luiz Maurício de Oliveira Monteiro