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 HZZYKJ.IDRMIS.CORE;
using SuperMap.Mapping;
using SuperMap.UI;
using SuperMap.Data;
using HZZYKJ.IDRMIS.EDIM.Tools;
using HZZYKJ.IDRMIS.EDIM.toolClass; namespace HZZYKJ.IDRMIS.EDIM
{
public partial class AttributeTreeForm : Form
{
private MapControl mapControl;
private List<Layer> layers = new List<Layer>();
public static AttributeTreeForm _AttributeTreeForm = null; public AttributeTreeForm()
{
InitializeComponent();
mapControl = AppContext.MapControl as MapControl;
} private void AttributeTreeForm_Load(object sender, EventArgs e)
{
Layers layers = mapControl.Map.Layers;
foreach (Layer item in layers)
{
this.layers.Add(item); }
Layer layer = this.layers[LayerForm._layerform.comboBox1.SelectedIndex];
Selection selection = layer.Selection;
Recordset recordset = selection.ToRecordset(); TreeNode TN_Layer_Father = new TreeNode(layer.Name);
treeView1.Nodes.Add(TN_Layer_Father); for (int i = ; i < recordset.RecordCount; i++)
{
string name = recordset.GetFieldValue().ToString();
TreeNode TN_Fild_Child = new TreeNode(name);
TN_Layer_Father.Nodes.Add(TN_Fild_Child);
recordset.MoveNext();
}
this.treeView1.SelectedNode = this.treeView1.Nodes[].Nodes[];
treeView1.ExpandAll(); } private void AttributeTreeForm_FormClosed(object sender, FormClosedEventArgs e)
{
_AttributeTreeForm = null;
} private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{ } private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
BindingList<FieldInfoName> GridBindingList = new BindingList<FieldInfoName>();
// List<FieldInfoName> GridList = new List<FieldInfoName>();
if (this.treeView1.SelectedNode.Parent != null)
{
Layers layers = mapControl.Map.Layers;
foreach (Layer item in layers)
{
this.layers.Add(item); }
Layer layer = this.layers[LayerForm._layerform.comboBox1.SelectedIndex];
Selection selection = layer.Selection;
Recordset recordset = selection.ToRecordset(); FieldInfos fieldinfos = recordset.GetFieldInfos(); for (int i = ; i < recordset.RecordCount; i++)
{
if (this.treeView1.SelectedNode.Text == recordset.GetFieldValue().ToString())
{
for (int j = ; j < recordset.FieldCount; j++)
{ if (this.checkBox1.Checked == false)
{
string x = fieldinfos[j].Name;
string y = null;
if (recordset.GetFieldValue(j).ToString() == null)
{
y = null;
}
else
{
y = recordset.GetFieldValue(j).ToString();//总是出错
}
FieldInfoName FIN = new FieldInfoName(x, y);
GridBindingList.Add(FIN);
}
else
{
if (fieldinfos[j].IsSystemField == false)
{
string x = fieldinfos[j].Name;
string y = recordset.GetFieldValue(j).ToString();
FieldInfoName FIN = new FieldInfoName(x, y);
GridBindingList.Add(FIN);
}
}
}
}
recordset.MoveNext();
} this.dataGridView1.DataSource = GridBindingList;
}
else
{
MessageBox.Show("请选择子节点");
} } private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{ } private void btn_Ok_Click(object sender, EventArgs e)
{
Layers layers = mapControl.Map.Layers;
foreach (Layer item in layers)
{
this.layers.Add(item); }
Layer layer = this.layers[LayerForm._layerform.comboBox1.SelectedIndex];
Selection selection = layer.Selection;
Recordset recordset = selection.ToRecordset();
FieldInfos fieldinfos = recordset.GetFieldInfos(); for (int i = ; i < recordset.RecordCount; i++)
{
if (this.treeView1.SelectedNode.Text == recordset.GetFieldValue().ToString())
{
for (int j = ; j < recordset.FieldCount; j++)
{
if (fieldinfos[j].IsSystemField == false)
{
recordset.Edit();
string a = this.dataGridView1.Rows[j].Cells[].Value.ToString();
recordset.SetFieldValue(j, a);
recordset.Update();
}
}
}
recordset.MoveNext();
} MessageBox.Show("属性值修改成功");
} private void checkBox1_CheckedChanged(object sender, EventArgs e)
{ } }
}