You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
524 lines
21 KiB
524 lines
21 KiB
using ESRI.ArcGIS.Carto; |
|
using ESRI.ArcGIS.Geodatabase; |
|
using KGIS.Framework.Maps; |
|
using KGIS.Framework.Platform; |
|
using KGIS.Framework.Utils; |
|
using KGIS.Framework.Utils.Helper; |
|
using KGIS.Framework.Views; |
|
using System; |
|
using System.Collections.Generic; |
|
using System.ComponentModel; |
|
using System.Data; |
|
using System.Drawing; |
|
using System.Linq; |
|
using System.Runtime.InteropServices; |
|
using System.Text; |
|
using System.Threading.Tasks; |
|
using System.Windows.Forms; |
|
|
|
namespace Kingo.Plugin.BHTB_Extract.View |
|
{ |
|
public partial class UcZYQManager : UserControl, IDockPanel3 |
|
{ |
|
private IFeatureLayer _Layer = null; |
|
private DataTable _Data = new DataTable(); |
|
private string queryWhere = string.Empty; |
|
public UcZYQManager() |
|
{ |
|
InitializeComponent(); |
|
this.DockAreas = KGIS.Framework.Views.DockStyle.DockLeft | KGIS.Framework.Views.DockStyle.Float; |
|
this.FloatSize = new System.Drawing.Size(230, 160); |
|
this.DefaultArea = KGIS.Framework.Views.DockStyle.DockLeft; |
|
this.ShowCloseButton = true; |
|
this.ShowAutoHideButton = true; |
|
this.Title = "作业区管理"; |
|
this.IsShowInMap = false; |
|
this.DockHeight = 160; |
|
this.DockWidth = 230; |
|
this.IsDockToPanel = true; |
|
this.DockToPanelStyle = KGIS.Framework.Views.DockStyle.DockLeft; |
|
this.cbSearchType.SelectedIndex = 0; |
|
_Layer = MapsManager.Instance.MapService.GetFeatureLayerByName("ZYQ"); |
|
} |
|
|
|
DataTable dtData; |
|
public void Init(string type) |
|
{ |
|
try |
|
{ |
|
//绑定数据 |
|
tvDirectory.Nodes.Clear(); |
|
|
|
InitTreeViewJD(dtData); |
|
} |
|
catch (Exception ex) |
|
{ |
|
MessageHelper.ShowError(ex.Message); |
|
} |
|
finally |
|
{ |
|
//if (irdbHelper != null) |
|
//{ |
|
// irdbHelper.DisConnect(); |
|
//} |
|
} |
|
} |
|
public void Clear() |
|
{ |
|
tvDirectory.Nodes.Clear(); |
|
} |
|
private void ConstructColumn(IFields fields) |
|
{ |
|
if (fields != null) |
|
{ |
|
_Data.Clear(); |
|
_Data.PrimaryKey = null; |
|
_Data.Columns.Clear(); |
|
|
|
AddInitFieldData(fields); |
|
string oidField = "OBJECTID"; |
|
if (!_Data.Columns.Contains(oidField) && _Data.Columns.Contains("FID")) |
|
{ |
|
oidField = "FID"; |
|
} |
|
_Data.PrimaryKey = new DataColumn[] { _Data.Columns[oidField] }; |
|
} |
|
} |
|
private void AddInitFieldData(IFields fields) |
|
{ |
|
try |
|
{ |
|
for (int i = 0; i < fields.FieldCount; i++) |
|
{ |
|
IField field = fields.get_Field(i); |
|
if (field.Name.ToUpper().EndsWith("SHAPE")) |
|
continue; |
|
DataColumn col = new DataColumn(); |
|
col.ExtendedProperties.Add("index", i); |
|
col.ColumnName = field.Name; |
|
col.Caption = field.AliasName; |
|
switch (field.Type) |
|
{ |
|
case esriFieldType.esriFieldTypeSmallInteger: |
|
col.DataType = typeof(short); |
|
break; |
|
case esriFieldType.esriFieldTypeInteger: |
|
col.DataType = typeof(int); |
|
break; |
|
case esriFieldType.esriFieldTypeSingle: |
|
break; |
|
case esriFieldType.esriFieldTypeDouble: |
|
col.DataType = typeof(double); |
|
break; |
|
case esriFieldType.esriFieldTypeString: |
|
col.DataType = typeof(string); |
|
break; |
|
case esriFieldType.esriFieldTypeDate: |
|
col.DataType = typeof(DateTime); |
|
break; |
|
case esriFieldType.esriFieldTypeOID: |
|
col.DataType = typeof(Int32); |
|
break; |
|
case esriFieldType.esriFieldTypeGeometry: |
|
break; |
|
case esriFieldType.esriFieldTypeBlob: |
|
break; |
|
case esriFieldType.esriFieldTypeRaster: |
|
break; |
|
case esriFieldType.esriFieldTypeGUID: |
|
break; |
|
case esriFieldType.esriFieldTypeGlobalID: |
|
break; |
|
case esriFieldType.esriFieldTypeXML: |
|
break; |
|
default: |
|
break; |
|
} |
|
col.ReadOnly = !field.Editable;//编辑状态启用默认是否可以编辑 |
|
if (_Data.Columns.Contains(col.ColumnName) == false)//不存在则添加 |
|
{ |
|
_Data.Columns.Add(col); |
|
} |
|
Marshal.ReleaseComObject(field); |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("加载表格数据失败!" + ex); |
|
return; |
|
} |
|
|
|
} |
|
private void AddInitDictionaryData(Dictionary<int, string> fieldIndex_NameDic, IFields fields) |
|
{ |
|
try |
|
{ |
|
if (fields == null || fields.FieldCount == 0) return; |
|
foreach (var item in fieldIndex_NameDic) |
|
{ |
|
int itemIndex = fields.FindField(item.Value); |
|
if (itemIndex == -1) continue; |
|
IField field = fields.get_Field(itemIndex); |
|
if (field.Name.ToUpper().EndsWith("SHAPE")) |
|
continue; |
|
DataColumn col = new DataColumn(); |
|
col.ExtendedProperties.Add("index", item.Key); |
|
col.ColumnName = field.Name; |
|
col.Caption = field.AliasName; |
|
switch (field.Type) |
|
{ |
|
case esriFieldType.esriFieldTypeSmallInteger: |
|
col.DataType = typeof(short); |
|
break; |
|
case esriFieldType.esriFieldTypeInteger: |
|
col.DataType = typeof(int); |
|
break; |
|
case esriFieldType.esriFieldTypeSingle: |
|
break; |
|
case esriFieldType.esriFieldTypeDouble: |
|
col.DataType = typeof(double); |
|
break; |
|
case esriFieldType.esriFieldTypeString: |
|
col.DataType = typeof(string); |
|
break; |
|
case esriFieldType.esriFieldTypeDate: |
|
col.DataType = typeof(DateTime); |
|
break; |
|
case esriFieldType.esriFieldTypeOID: |
|
col.DataType = typeof(Int32); |
|
break; |
|
case esriFieldType.esriFieldTypeGeometry: |
|
break; |
|
case esriFieldType.esriFieldTypeBlob: |
|
break; |
|
case esriFieldType.esriFieldTypeRaster: |
|
break; |
|
case esriFieldType.esriFieldTypeGUID: |
|
break; |
|
case esriFieldType.esriFieldTypeGlobalID: |
|
break; |
|
case esriFieldType.esriFieldTypeXML: |
|
break; |
|
default: |
|
break; |
|
} |
|
col.ReadOnly = !field.Editable;//编辑状态启用默认是否可以编辑 |
|
if (_Data.Columns.Contains(col.ColumnName) == false)//不存在则添加 |
|
{ |
|
_Data.Columns.Add(col); |
|
} |
|
Marshal.ReleaseComObject(field); |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("加载表格数据失败!" + ex); |
|
return; |
|
} |
|
} |
|
|
|
private void InitTreeViewJD(DataTable dtData) |
|
{ |
|
try |
|
{ |
|
if (_Layer == null) return; |
|
ConstructColumn(this._Layer.FeatureClass.Fields); |
|
|
|
IAttributeTable AttrTable = _Layer as IAttributeTable; |
|
IQueryFilter queryfilter = new QueryFilterClass |
|
{ |
|
WhereClause = queryWhere |
|
}; |
|
//ITable table = SourceFeature as ITable; |
|
ICursor cursor = AttrTable.AttributeTable.Search(queryfilter, true); |
|
|
|
int count = AttrTable.AttributeTable.RowCount(queryfilter); |
|
IRow row = null; |
|
DataTable tempDt = _Data.Copy(); |
|
tempDt.Rows.Clear(); |
|
bool isExitFeatureXML = false;// JudgeExistsCurrentFeatureXML(); |
|
int columnCount = 0; |
|
int fieldIndex = 0; |
|
while ((row = cursor.NextRow()) != null) |
|
{ |
|
DataRow dr = tempDt.NewRow(); |
|
if (isExitFeatureXML) columnCount = tempDt.Columns.Count - 1; |
|
else columnCount = tempDt.Columns.Count; |
|
for (int i = 0; i < columnCount; i++) |
|
{ |
|
if (isExitFeatureXML) |
|
fieldIndex = (int)tempDt.Columns[row.Fields.FindField(tempDt.Columns[i].ColumnName)].ExtendedProperties["index"]; |
|
else |
|
fieldIndex = (int)tempDt.Columns[i].ExtendedProperties["index"]; |
|
object obj = row.get_Value(fieldIndex); |
|
if (obj == null) |
|
{ |
|
continue; |
|
} |
|
else |
|
{ |
|
if (obj.ToString().Contains("1899/12/30 0:00:00")) |
|
{ |
|
obj = DBNull.Value; |
|
} |
|
} |
|
dr[i] = obj; |
|
} |
|
tempDt.Rows.Add(dr); |
|
if (tempDt.Rows.Count == 10000) |
|
{ |
|
|
|
} |
|
} |
|
_Data = tempDt.Copy(); |
|
Marshal.ReleaseComObject(AttrTable); |
|
Marshal.ReleaseComObject(_Layer); |
|
this.Invoke((Action)delegate () |
|
{ |
|
_Data = tempDt.Copy(); |
|
TreeNode node = new TreeNode(); |
|
node.Text = "图幅"; |
|
foreach (DataRow _dr in _Data.Rows) |
|
{ |
|
TreeNode subNode = new TreeNode(); |
|
subNode.Text = _dr["ZYQBH"] is DBNull ? "" : _dr["ZYQBH"].ToString(); |
|
subNode.Tag = _dr["OBJECTID"]; |
|
node.Nodes.Add(subNode); |
|
} |
|
tvDirectory.Nodes.Add(node); |
|
|
|
//gridControl1.DataSource = null; |
|
//gridView1.Columns.Clear(); |
|
//gridControl1.DataSource = Data; |
|
////OpaqueLayerHelper.HideOpaqueLayer(); |
|
//UpdateViewState(); |
|
////OpaqueLayerHelper.ShowOpaqueLayer(this, 50, true); |
|
////barEditItem3.EditValue = "(" + gridView1.GetSelectedRows().Length + "/" + Data.Rows.Count + "已选择)"; |
|
}); |
|
|
|
//string strConn = Config.SysConfigsOprator.GetDBConnectionByName("MDBOledbConnection"); |
|
//strConn = string.Format(strConn, Env.Instance.Project.GetProjMDBPath()); |
|
//helper = RDBFactory.CreateDbHelper(strConn, DatabaseType.MSAccess); |
|
//string strSQL = string.Format("select objectid,图幅编号 from {0}", "JHTB"); |
|
//dtData = helper.ExecuteDatatable("dtData", strSQL, true); |
|
//helper.DisConnect(); |
|
//if (dtData != null) |
|
//{ |
|
// TreeNode node = new TreeNode(); |
|
// node.Text = "图幅"; |
|
// foreach (DataRow row in dtData.Rows) |
|
// { |
|
// TreeNode subNode = new TreeNode(); |
|
// subNode.Text = row["图幅编号"] is DBNull ? "" : row["图幅编号"].ToString(); |
|
// subNode.Tag = row["OBJECTID"]; |
|
// node.Nodes.Add(subNode); |
|
// } |
|
// tvDirectory.Nodes.Add(node); |
|
//} |
|
} |
|
catch (Exception ex) |
|
{ |
|
|
|
throw ex; |
|
} |
|
} |
|
|
|
int selectIndex = -1; |
|
string preSearchText = string.Empty; |
|
DataRow[] drSearchs; |
|
int index = 0; |
|
private void btnSearch_Click(object sender, EventArgs e) |
|
{ |
|
if (dtData != null && this.cbSearchType.SelectedIndex != -1 && !string.IsNullOrEmpty(this.txtSearchText.Text.Trim())) |
|
{ |
|
if (selectIndex != this.cbSearchType.SelectedIndex || preSearchText != this.txtSearchText.Text.Trim()) |
|
{ |
|
selectIndex = this.cbSearchType.SelectedIndex; |
|
preSearchText = this.txtSearchText.Text.Trim(); |
|
if (this.cbSearchType.SelectedIndex == 0) |
|
{ |
|
if (dtData.Columns.Contains("ORDERDM")) |
|
{ |
|
drSearchs = dtData.Select("ORDERDM like '%" + this.txtSearchText.Text.Trim() + "%'", "ORDERNO ASC"); |
|
} |
|
else |
|
{ |
|
drSearchs = dtData.Select("XZQDM like '%" + this.txtSearchText.Text.Trim() + "%'", "XZQDM ASC"); |
|
} |
|
} |
|
else |
|
{ |
|
drSearchs = dtData.Select("XZQMC like '%" + this.txtSearchText.Text.Trim() + "%'", "XZQDM ASC"); |
|
} |
|
index = 0; |
|
} |
|
|
|
if (drSearchs != null && drSearchs.Length > 0) |
|
{ |
|
if (index >= drSearchs.Length) |
|
{ |
|
index = 0; |
|
} |
|
SelectNode(drSearchs[index]); |
|
index++; |
|
} |
|
} |
|
else |
|
{ |
|
MessageHelper.ShowTips("搜索之前请确保有数据,并且输入了搜索条件!"); |
|
} |
|
} |
|
|
|
private void SelectNode(DataRow dr) |
|
{ |
|
//foreach (TreeNode node in tvDirectory.Nodes) |
|
//{ |
|
// if (node.Tag != null) |
|
// { |
|
// XZQEntity xzq = node.Tag as XZQEntity; |
|
// if (dr["XZQDM"].ToString() == xzq.XZQDM) |
|
// { |
|
// this.tvDirectory.Focus(); |
|
// tvDirectory.SelectedNode = node; |
|
// } |
|
// } |
|
// else |
|
// { |
|
// foreach (TreeNode subNode in node.Nodes) |
|
// { |
|
// if (subNode.Tag != null) |
|
// { |
|
// XZQEntity xzq = subNode.Tag as XZQEntity; |
|
// if (dr["XZQDM"].ToString() == xzq.XZQDM) |
|
// { |
|
// this.tvDirectory.Focus(); |
|
// tvDirectory.SelectedNode = subNode; |
|
// } |
|
// } |
|
// else |
|
// { |
|
// foreach (TreeNode subSubNode in subNode.Nodes) |
|
// { |
|
// if (subSubNode.Tag == null) |
|
// continue; |
|
// XZQEntity xzq = subSubNode.Tag as XZQEntity; |
|
// if (dr["XZQDM"].ToString() == xzq.XZQDM) |
|
// { |
|
// this.tvDirectory.Focus(); |
|
// subSubNode.Checked = true; |
|
// tvDirectory.SelectedNode = subSubNode; |
|
// } |
|
// else |
|
// { |
|
// subSubNode.Checked = false; |
|
// } |
|
// IsZoom = true; |
|
// } |
|
// } |
|
// } |
|
// } |
|
//} |
|
} |
|
|
|
private void tvDirectory_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) |
|
{ |
|
|
|
} |
|
|
|
private void tvDirectory_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) |
|
{ |
|
//if (e.Button == System.Windows.Forms.MouseButtons.Left && e.Node != null && e.Node.Tag != null) |
|
//{ |
|
// XZQEntity xzq = e.Node.Tag as XZQEntity; |
|
// if (xzq != null) |
|
// { |
|
// Common.Utility.CommonAPI.MoveToCenterBySelectFeature(Map as IMapControlDefault, "XZQ", xzq.OBJECTID); |
|
// } |
|
//} |
|
} |
|
bool IsZoom = false; |
|
|
|
public event EventHandler CloseViewHandler; |
|
|
|
public bool IsDockToPanel { get ; set ; } |
|
public KGIS.Framework.Views.DockStyle DockToPanelStyle { get ; set ; } |
|
public bool IsShowInMap { get ; set ; } |
|
public Guid ID { get ; set ; } |
|
public KGIS.Framework.Views.DockStyle DockAreas { get ; set ; } |
|
public Size FloatSize { get ; set ; } |
|
public int DockWidth { get ; set ; } |
|
public int DockHeight { get ; set ; } |
|
public KGIS.Framework.Views.DockStyle DefaultArea { get ; set ; } |
|
public bool ShowCloseButton { get ; set ; } |
|
public bool ShowAutoHideButton { get ; set ; } |
|
public string Title { get ; set ; } |
|
|
|
private void tvDirectory_AfterCheck(object sender, TreeViewEventArgs e) |
|
{ |
|
//if (e.Action != TreeViewAction.ByMouse && e.Node.Nodes.Count == 0 && !IsZoom) |
|
// return; |
|
//if (e.Node.Checked) |
|
//{ |
|
// IsZoom = false; |
|
//} |
|
//XZQEntity xzq = e.Node.Tag as XZQEntity; |
|
//if (xzq != null) |
|
//{ |
|
// if (e.Node.Checked) |
|
// { |
|
// xzq.Element = CommonAPI.ZoomAndDrawGraph(Env.Instance.DefaultValue.XZQ_TableName, xzq.OBJECTID); |
|
// Env.Instance.SelectXZQByCatalog.Add(xzq); |
|
// } |
|
// else |
|
// { |
|
// if (xzq.Element != null) |
|
// { |
|
// CommonAPI.ClearGraph(xzq.Element as IElement); |
|
// Env.Instance.SelectXZQByCatalog.Remove(xzq); |
|
// xzq.Element = null; |
|
// } |
|
// } |
|
//} |
|
//if (e.Node.Nodes != null) |
|
//{ |
|
// foreach (TreeNode item in e.Node.Nodes) |
|
// { |
|
// item.Checked = e.Node.Checked; |
|
// xzq = item.Tag as XZQEntity; |
|
// if (xzq != null) |
|
// { |
|
// if (item.Checked) |
|
// { |
|
// xzq.Element = CommonAPI.ZoomAndDrawGraph(Env.Instance.DefaultValue.XZQ_TableName, xzq.OBJECTID); |
|
// Env.Instance.SelectXZQByCatalog.Add(xzq); |
|
// } |
|
// else |
|
// { |
|
// if (xzq.Element != null) |
|
// { |
|
// CommonAPI.ClearGraph(xzq.Element as IElement); |
|
// Env.Instance.SelectXZQByCatalog.Remove(xzq); |
|
// xzq.Element = null; |
|
// } |
|
// } |
|
// } |
|
// } |
|
//} |
|
} |
|
|
|
public void ShowPanel() |
|
{ |
|
Platform.Instance.OpenView(this, false); |
|
} |
|
|
|
public void ClosePanel() |
|
{ |
|
|
|
} |
|
|
|
public void ClosePanelInvoke() |
|
{ |
|
|
|
} |
|
} |
|
}
|
|
|