您的位置:首页 > 其它

在ArcGlobe三维环境中进行数据查询(.net)

2012-07-26 17:16 211 查看
/// <summary>
/// 查询功能
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BtnOK_Click(object sender, EventArgs e)
{
try
{
//图层名称
String LayerName = this.CbxLayer.Text;
        //查询条件
String SearchText = this.TbxName.Text;
if (SearchText == String.Empty)
{

MessageBox.Show("查询条件不允许为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
TbxName.Focus();
//清空数据列表
this.dg1.DataSource = null;
//跳出查询
return;
}
        //当前视图
IScene scene = this.axGlobeControl1.Globe.GlobeDisplay.Scene;
        //查询器
IQueryFilter pQueryFilter = new QueryFilterClass();
IActiveView pActiveView;
pActiveView = (IActiveView)scene;
//清空当前视图
scene.ClearSelection();

IFeatureLayer pFeatureLayer;

pFeatureLayer = (IFeatureLayer)scene.get_Layer(GetLayerId(LayerName, scene));
//判断要查询的图层
if (LayerName == "堤防")
{
//查询条件
pQueryFilter.WhereClause = "XMMC like '%" + SearchText + "%'";

}
else if (LayerName == "险工险段")
{
//查询条件
pQueryFilter.WhereClause = "BZ like '%" + SearchText + "%'";

}
......

IFeatureCursor pFeatureCursor;
//查询
pFeatureCursor = pFeatureLayer.FeatureClass.Search(pQueryFilter, false);
IFeature pFeature;
pFeature = pFeatureCursor.NextFeature();
IFields pFields = pFeatureCursor.Fields;

int fieldIndex = 0;
int fieldIndexName = 0;
if (LayerName == "堤防")
{
fieldIndex = pFields.FindField("NAME");
fieldIndexName = pFields.FindField("XMMC");

}
else if (LayerName == "险工险段")
{
fieldIndex = pFields.FindField("NAME");
fieldIndexName = pFields.FindField("BZ");

}
......
pfeat = pFeature;

if (pFeature == null)
{
MessageBox.Show("您所查询的结果不存在!");
TbxName.Select();
TbxName.Focus();
this.dg1.DataSource = null;
return;
}
//绑定DataTable
DataTable dt = new DataTable();
DataColumn dc1 = new DataColumn();
dc1.ColumnName = "工程代码";
DataColumn dc2 = new DataColumn();
dc2.ColumnName = "工程名称";

dt.Columns.Add(dc1);
dt.Columns.Add(dc2);

string Code = String.Empty;
string Name = String.Empty;
while (pFeature != null)
{
//scene.SelectFeature(pFeatureLayer, pFeature);

Code = pFeature.get_Value(fieldIndex) as string;
Name = pFeature.get_Value(fieldIndexName) as string;
DataRow dr = dt.NewRow();
dr[0] = Code;
dr[1] = Name;

dt.Rows.Add(dr);
pFeature = pFeatureCursor.NextFeature();
}
//绑定列表
this.dg1.DataSource = dt.DefaultView;
}
catch
{
MessageBox.Show("异常!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
this.dg1.DataSource = null;

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐