|
|
|
|
using DevExpress.XtraEditors;
|
|
|
|
|
using ESRI.ArcGIS.Carto;
|
|
|
|
|
using ESRI.ArcGIS.Geodatabase;
|
|
|
|
|
using KGIS.Framework.Utils.Helper;
|
|
|
|
|
using KGIS.Plugin.LayerProperty.Helper;
|
|
|
|
|
using KGIS.Plugin.LayerProperty.Interface;
|
|
|
|
|
using KGIS.Plugin.LayerProperty.Utils;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace KGIS.Plugin.LayerProperty.View.UC_Controls
|
|
|
|
|
{
|
|
|
|
|
public partial class UCFieldsPropertyPage : XtraUserControl, IUCPropertyPageEx, IPropertyPage
|
|
|
|
|
{
|
|
|
|
|
private string m_DisplayField;
|
|
|
|
|
private ILayer m_Layer;
|
|
|
|
|
private UCFieldsList m_ucFieldsList;
|
|
|
|
|
private bool isDirty;
|
|
|
|
|
public event System.EventHandler EditorChanged;
|
|
|
|
|
public bool IsPageDirty
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return this.isDirty;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
this.isDirty = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public int Priority
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("The method or operation is not implemented.");
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("The method or operation is not implemented.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public string Title
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("The method or operation is not implemented.");
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("The method or operation is not implemented.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void ucFieldsCombox1_SelectedFieldChanged(IField field)
|
|
|
|
|
{
|
|
|
|
|
if (field != null)
|
|
|
|
|
{
|
|
|
|
|
this.m_DisplayField = field.Name;
|
|
|
|
|
}
|
|
|
|
|
this.InvokeEditValueChanged(null, null);
|
|
|
|
|
}
|
|
|
|
|
void btnExport_Click(object sender, System.EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (Fields != null && Fields.FieldCount > 0)
|
|
|
|
|
{
|
|
|
|
|
List<DataColumnEx> lstDataColumnEx = new List<DataColumnEx>();
|
|
|
|
|
DataTable dataTable = this.CreateDataTable(lstDataColumnEx);
|
|
|
|
|
for (int i = 0; i < Fields.FieldCount; i++)
|
|
|
|
|
{
|
|
|
|
|
IField field = Fields.get_Field(i);
|
|
|
|
|
this.CreateDataRow(field, dataTable);
|
|
|
|
|
}
|
|
|
|
|
System.Windows.Forms.SaveFileDialog sfd = new System.Windows.Forms.SaveFileDialog();
|
|
|
|
|
sfd.Filter = "Excel(*.xlsx)|*.xlsx";
|
|
|
|
|
sfd.FilterIndex = 1;
|
|
|
|
|
if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
ExportExcel.CreateAndAddTitle(sfd.FileName, "字段信息", lstDataColumnEx, dataTable);
|
|
|
|
|
MessageHelper.ShowTips("导出成功!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageHelper.ShowTips("没有字段可以导出!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
//RdbUtil.AddException(ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private DataTable CreateDataTable(List<DataColumnEx> lstDataColumnEx)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
DataTable dataTable = new DataTable();
|
|
|
|
|
DataColumn dataColumn = new DataColumn("name", Type.GetType("System.String"));
|
|
|
|
|
dataColumn.Caption = "名称";
|
|
|
|
|
dataTable.Columns.Add(dataColumn);
|
|
|
|
|
lstDataColumnEx.Add(new DataColumnEx() { ColumnName = "name", ChineseName = "名称", Type = esriFieldType.esriFieldTypeString });
|
|
|
|
|
dataColumn = new DataColumn("alias", Type.GetType("System.String"));
|
|
|
|
|
dataColumn.Caption = "别名";
|
|
|
|
|
dataTable.Columns.Add(dataColumn);
|
|
|
|
|
lstDataColumnEx.Add(new DataColumnEx() { ColumnName = "alias", ChineseName = "别名", Type = esriFieldType.esriFieldTypeString });
|
|
|
|
|
dataColumn = new DataColumn("datatype", Type.GetType("System.String"));
|
|
|
|
|
dataColumn.Caption = "类型";
|
|
|
|
|
dataTable.Columns.Add(dataColumn);
|
|
|
|
|
lstDataColumnEx.Add(new DataColumnEx() { ColumnName = "datatype", ChineseName = "类型", Type = esriFieldType.esriFieldTypeString });
|
|
|
|
|
dataColumn = new DataColumn("length", Type.GetType("System.Int32"));
|
|
|
|
|
dataColumn.Caption = "长度";
|
|
|
|
|
dataTable.Columns.Add(dataColumn);
|
|
|
|
|
lstDataColumnEx.Add(new DataColumnEx() { ColumnName = "length", ChineseName = "长度", Type = esriFieldType.esriFieldTypeInteger });
|
|
|
|
|
dataColumn = new DataColumn("precision", Type.GetType("System.Int32"));
|
|
|
|
|
dataColumn.Caption = "精度";
|
|
|
|
|
dataTable.Columns.Add(dataColumn);
|
|
|
|
|
lstDataColumnEx.Add(new DataColumnEx() { ColumnName = "precision", ChineseName = "精度", Type = esriFieldType.esriFieldTypeInteger });
|
|
|
|
|
dataColumn = new DataColumn("scale", Type.GetType("System.Int32"));
|
|
|
|
|
dataColumn.Caption = "数值范围";
|
|
|
|
|
dataTable.Columns.Add(dataColumn);
|
|
|
|
|
lstDataColumnEx.Add(new DataColumnEx() { ColumnName = "scale", ChineseName = "数值范围", Type = esriFieldType.esriFieldTypeInteger });
|
|
|
|
|
dataColumn = new DataColumn("numberformat", Type.GetType("System.String"));
|
|
|
|
|
dataColumn.Caption = "数字格式";
|
|
|
|
|
dataTable.Columns.Add(dataColumn);
|
|
|
|
|
lstDataColumnEx.Add(new DataColumnEx() { ColumnName = "numberformat", ChineseName = "数字格式", Type = esriFieldType.esriFieldTypeString });
|
|
|
|
|
return dataTable;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
//RdbUtil.AddException(ex);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
private void CreateDataRow(IField field, DataTable dt)
|
|
|
|
|
{
|
|
|
|
|
DataRow dataRow = dt.NewRow();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
dataRow["name"] = field.Name;
|
|
|
|
|
dataRow["alias"] = field.AliasName;
|
|
|
|
|
string value = field.Type.ToString().Substring(13);
|
|
|
|
|
dataRow["datatype"] = value;
|
|
|
|
|
dataRow["length"] = field.Length;
|
|
|
|
|
dataRow["precision"] = field.Precision;
|
|
|
|
|
dataRow["scale"] = field.Scale;
|
|
|
|
|
dt.Rows.Add(dataRow);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
//RdbUtil.AddException(ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public UCFieldsPropertyPage()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
this.m_ucFieldsList = new UCFieldsList();
|
|
|
|
|
this.m_ucFieldsList.Dock = DockStyle.Fill;
|
|
|
|
|
groupControl1.Controls.Add(this.m_ucFieldsList);
|
|
|
|
|
}
|
|
|
|
|
public bool CanWrite2Prop()
|
|
|
|
|
{
|
|
|
|
|
return this.isDirty;
|
|
|
|
|
}
|
|
|
|
|
private void InvokeEditValueChanged(object sender, System.EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (this.EditorChanged != null)
|
|
|
|
|
{
|
|
|
|
|
this.EditorChanged(sender, e);
|
|
|
|
|
}
|
|
|
|
|
this.isDirty = true;
|
|
|
|
|
}
|
|
|
|
|
public void SetDefaultValue(object value)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IFields Fields = null;
|
|
|
|
|
public void InitUC(object layerProperty)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
this.m_Layer = (layerProperty as ILayer);
|
|
|
|
|
this.m_ucFieldsList.InitUC(null);
|
|
|
|
|
this.ucFieldsCombox1.InitFieldList(null, "");
|
|
|
|
|
if (layerProperty is IFeatureLayer)
|
|
|
|
|
{
|
|
|
|
|
IFeatureLayer featureLayer = layerProperty as IFeatureLayer;
|
|
|
|
|
if (featureLayer != null)
|
|
|
|
|
{
|
|
|
|
|
this.ucFieldsCombox1.InitFieldList(featureLayer.FeatureClass.Fields, featureLayer.DisplayField, false, false, true);
|
|
|
|
|
this.m_DisplayField = featureLayer.DisplayField;
|
|
|
|
|
this.m_ucFieldsList.InitUC(featureLayer.FeatureClass.Fields);
|
|
|
|
|
Fields = featureLayer.FeatureClass.Fields;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (layerProperty is IRasterLayer)
|
|
|
|
|
{
|
|
|
|
|
IAttributeTable attributeTable = layerProperty as IAttributeTable;
|
|
|
|
|
if (attributeTable.AttributeTable != null)
|
|
|
|
|
{
|
|
|
|
|
IRasterLayer rasterLayer = layerProperty as IRasterLayer;
|
|
|
|
|
if (rasterLayer != null)
|
|
|
|
|
{
|
|
|
|
|
int num = rasterLayer.PrimaryField;
|
|
|
|
|
if (num == -1)
|
|
|
|
|
{
|
|
|
|
|
num = 1;
|
|
|
|
|
}
|
|
|
|
|
this.ucFieldsCombox1.InitFieldList(attributeTable.AttributeTable.Fields, attributeTable.AttributeTable.Fields.get_Field(num).Name, false, false, true);
|
|
|
|
|
this.m_DisplayField = attributeTable.AttributeTable.Fields.get_Field(num).Name;
|
|
|
|
|
this.m_ucFieldsList.InitUC(attributeTable.AttributeTable.Fields);
|
|
|
|
|
Fields = attributeTable.AttributeTable.Fields;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (layerProperty is IRasterCatalogLayer)
|
|
|
|
|
{
|
|
|
|
|
IAttributeTable attributeTable2 = layerProperty as IAttributeTable;
|
|
|
|
|
IRasterCatalogLayer rasterCatalogLayer = layerProperty as IRasterCatalogLayer;
|
|
|
|
|
if (rasterCatalogLayer != null)
|
|
|
|
|
{
|
|
|
|
|
int num2 = rasterCatalogLayer.PrimaryField;
|
|
|
|
|
if (num2 == -1)
|
|
|
|
|
{
|
|
|
|
|
num2 = 1;
|
|
|
|
|
}
|
|
|
|
|
this.ucFieldsCombox1.InitFieldList(attributeTable2.AttributeTable.Fields, attributeTable2.AttributeTable.Fields.get_Field(num2).Name, false, false, true);
|
|
|
|
|
this.m_DisplayField = attributeTable2.AttributeTable.Fields.get_Field(num2).Name;
|
|
|
|
|
this.m_ucFieldsList.InitUC(attributeTable2.AttributeTable.Fields);
|
|
|
|
|
Fields = attributeTable2.AttributeTable.Fields;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
//RdbUtil.AddException(ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void InitFields(IFields fields)
|
|
|
|
|
{
|
|
|
|
|
this.m_ucFieldsList.InitUC(fields);
|
|
|
|
|
}
|
|
|
|
|
public void Write2Prop()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (this.m_Layer is IFeatureLayer)
|
|
|
|
|
{
|
|
|
|
|
IFeatureLayer featureLayer = this.m_Layer as IFeatureLayer;
|
|
|
|
|
if (featureLayer != null)
|
|
|
|
|
{
|
|
|
|
|
featureLayer.DisplayField = this.m_DisplayField;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (this.m_Layer is IRasterLayer)
|
|
|
|
|
{
|
|
|
|
|
IAttributeTable attributeTable = this.m_Layer as IAttributeTable;
|
|
|
|
|
IRasterLayer rasterLayer = this.m_Layer as IRasterLayer;
|
|
|
|
|
if (rasterLayer != null)
|
|
|
|
|
{
|
|
|
|
|
rasterLayer.PrimaryField = attributeTable.AttributeTable.FindField(this.m_DisplayField);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (this.m_Layer is IRasterCatalogLayer)
|
|
|
|
|
{
|
|
|
|
|
IAttributeTable attributeTable2 = this.m_Layer as IAttributeTable;
|
|
|
|
|
IRasterCatalogLayer rasterCatalogLayer = this.m_Layer as IRasterCatalogLayer;
|
|
|
|
|
if (rasterCatalogLayer != null)
|
|
|
|
|
{
|
|
|
|
|
rasterCatalogLayer.PrimaryField = attributeTable2.AttributeTable.FindField(this.m_DisplayField);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this.isDirty = false;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
//RdbUtil.AddException(ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public int Activate()
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("The method or operation is not implemented.");
|
|
|
|
|
}
|
|
|
|
|
public void Deactivate()
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("The method or operation is not implemented.");
|
|
|
|
|
}
|
|
|
|
|
public void Cancel()
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("The method or operation is not implemented.");
|
|
|
|
|
}
|
|
|
|
|
//private void ucFieldsCombox1_SelectedFieldChanged(IField field)
|
|
|
|
|
//{
|
|
|
|
|
// if (field != null)
|
|
|
|
|
// {
|
|
|
|
|
// this.m_DisplayField = field.Name;
|
|
|
|
|
// }
|
|
|
|
|
// this.InvokeEditValueChanged(null, null);
|
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|
}
|