|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using ESRI.ArcGIS.Geodatabase;
|
|
|
|
|
|
|
|
|
|
namespace Kingo.RuleCheck.AEHelper
|
|
|
|
|
{
|
|
|
|
|
public class TableAPI : ITableAPI
|
|
|
|
|
{
|
|
|
|
|
private ITable _CurrentTable;
|
|
|
|
|
public TableAPI(ITable pTable)
|
|
|
|
|
{
|
|
|
|
|
this._CurrentTable = pTable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ITable ITable
|
|
|
|
|
{
|
|
|
|
|
get { return _CurrentTable; }
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 关闭当前对象
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void CloseTable()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (this.ITable != null)
|
|
|
|
|
{
|
|
|
|
|
while (Marshal.ReleaseComObject(this.ITable) > 0) { }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw ex;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public object AddRows(DataTable pTable)
|
|
|
|
|
{
|
|
|
|
|
bool result = false;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (this._CurrentTable != null && pTable != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (DataRow row in pTable.Rows)
|
|
|
|
|
{
|
|
|
|
|
IRow newRow = this._CurrentTable.CreateRow();
|
|
|
|
|
for (int i = 0; i < newRow.Fields.FieldCount; i++)
|
|
|
|
|
{
|
|
|
|
|
IField field = newRow.Fields.get_Field(i);
|
|
|
|
|
if (field.Name.ToUpper() == "SHAPE")
|
|
|
|
|
continue;
|
|
|
|
|
//int index = pFeature.Fields.FindField(field.Name);
|
|
|
|
|
if (!pTable.Columns.Contains(field.Name))
|
|
|
|
|
continue;
|
|
|
|
|
//if (pFeature.Fields.get_Field(index).Type == field.Type)
|
|
|
|
|
//{
|
|
|
|
|
if (field.Editable)
|
|
|
|
|
{
|
|
|
|
|
newRow.set_Value(i, row[field.Name]);
|
|
|
|
|
}
|
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|
newRow.Store();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw ex;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public object AddRow(Dictionary<string, object> pDic)
|
|
|
|
|
{
|
|
|
|
|
ICursor cursor = null;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (this._CurrentTable != null && pDic != null && pDic.Keys != null)
|
|
|
|
|
{
|
|
|
|
|
IRowBuffer buffer = this._CurrentTable.CreateRowBuffer();
|
|
|
|
|
for (int i = 0; i < buffer.Fields.FieldCount; i++)
|
|
|
|
|
{
|
|
|
|
|
IField field = buffer.Fields.get_Field(i);
|
|
|
|
|
if (!field.Editable)
|
|
|
|
|
continue;
|
|
|
|
|
if (field.Name.ToUpper() == "SHAPE")
|
|
|
|
|
continue;
|
|
|
|
|
if (!pDic.Keys.Contains(field.Name))
|
|
|
|
|
continue;
|
|
|
|
|
//if (pFeature.Fields.get_Field(index).Type == field.Type)
|
|
|
|
|
//{
|
|
|
|
|
if (field.Type == esriFieldType.esriFieldTypeString)
|
|
|
|
|
{
|
|
|
|
|
if (!(pDic[field.Name] is string))
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
else if (field.Type == esriFieldType.esriFieldTypeDate)
|
|
|
|
|
{
|
|
|
|
|
if (!(pDic[field.Name] is DateTime))
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
else if (field.Type == esriFieldType.esriFieldTypeDouble)
|
|
|
|
|
{
|
|
|
|
|
if (!(pDic[field.Name] is Double) && !(pDic[field.Name] is Decimal))
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
else if (field.Type == esriFieldType.esriFieldTypeInteger)
|
|
|
|
|
{
|
|
|
|
|
if (!(pDic[field.Name] is long))
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
else if (field.Type == esriFieldType.esriFieldTypeSmallInteger)
|
|
|
|
|
{
|
|
|
|
|
if (!(pDic[field.Name] is int))
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
buffer.set_Value(i, pDic[field.Name]);
|
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|
cursor = this._CurrentTable.Insert(true);
|
|
|
|
|
object OID = cursor.InsertRow(buffer);
|
|
|
|
|
cursor.Flush();
|
|
|
|
|
//newRow.Store();
|
|
|
|
|
|
|
|
|
|
return OID;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw ex;
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
if (cursor != null)
|
|
|
|
|
{
|
|
|
|
|
Marshal.ReleaseComObject(cursor);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 从当前表中删除指定的行对象
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="OID">OID</param>
|
|
|
|
|
public bool DelRow(int OID)
|
|
|
|
|
{
|
|
|
|
|
bool result = false;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (this._CurrentTable != null)
|
|
|
|
|
{
|
|
|
|
|
IRow row = this._CurrentTable.GetRow(OID);
|
|
|
|
|
row.Delete();
|
|
|
|
|
row.Store();
|
|
|
|
|
result = true;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw ex;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|