using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using KGIS.Framework.Maps;
using KGIS.Framework.Platform;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.ExtensionMethod;
using KGIS.Framework.Views;
using Kingo.PluginServiceInterface;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using UIShell.OSGi;
namespace Kingo.Plugin.BHTB_Extract.View
{
///
/// UcZYQMagr.xaml 的交互逻辑
///
public partial class UcZYQMagr : UserControl, IDockPanel3
{
private IFeatureLayer _Layer = null;
private DataTable _Data = new DataTable();
private string queryWhere = string.Empty;
public event EventHandler CloseViewHandler;
public bool IsDockToPanel { get; set; }
public DockStyle DockToPanelStyle { get; set; }
public bool IsShowInMap { get; set; }
public Guid ID { get; set; }
public DockStyle DockAreas { get; set; }
public System.Drawing.Size FloatSize { get; set; }
public int DockWidth { get; set; }
public int DockHeight { get; set; }
public DockStyle DefaultArea { get; set; }
public bool ShowCloseButton { get; set; }
public bool ShowAutoHideButton { get; set; }
public string Title { get; set; }
public string packUri { get { return @"/KUI;component/Themes/Generic"; } }
private static UcZYQMagr instance;
public static UcZYQMagr Instance
{
get
{
if (instance == null)
{
instance = new UcZYQMagr();
}
return instance;
}
}
private UcZYQMagr()
{
InitializeComponent();
//System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFrom("KUI.dll");
//System.Windows.ResourceDictionary myResourceDictionary = System.Windows.Application.LoadComponent(new Uri(packUri + ".xaml", UriKind.Relative)) as System.Windows.ResourceDictionary;
//this.Resources.MergedDictionaries.Add(myResourceDictionary);
this.DockAreas = KGIS.Framework.Views.DockStyle.DockLeft;
this.FloatSize = new System.Drawing.Size(230, 160);
this.DefaultArea = KGIS.Framework.Views.DockStyle.DockLeft;
this.ShowCloseButton = false;
this.ShowAutoHideButton = true;
this.Title = "作业区管理";
this.IsShowInMap = false;
this.DockHeight = 160;
this.DockWidth = 230;
this.IsDockToPanel = false;
this.DockToPanelStyle = KGIS.Framework.Views.DockStyle.DockLeft | KGIS.Framework.Views.DockStyle.Document;
_Layer = MapsManager.Instance.MapService.GetFeatureLayerByName("ZYQ");
}
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;
}
}
public TreeNode node = null;
public void InitTreeView()
{
try
{
_Layer = MapsManager.Instance.MapService.GetFeatureLayerByName("ZYQ");
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);
_Data = tempDt.Copy();
ObservableCollection itemList = new ObservableCollection();
node = new TreeNode()
{
Name = "作业区列表",
Paixu = 0,
IsExpanded = true,
Icon = "/Kingo.Plugin.BHTB_Extract;component/Resources/标记.png",
IsParent = true,
Data = null
};
node.Nodes = new ObservableCollection();
foreach (DataRow _dr in _Data.Rows)
{
TreeNode zyqNode = new TreeNode()
{
Name = _dr["ZYQBH"] is DBNull ? _dr["ZYQMC"].ToTrim() : _dr["ZYQBH"].ToString(),
Paixu = 0,
IsExpanded = true,
Icon = "pack://application:,,,/Kingo.Plugin.DataDictionary;component/Resources/zrz.png",
IsParent = true,
Data = _dr["OBJECTID"]
};
switch (_dr["ZYQZT"].ToTrim())
{
case "0":
zyqNode.Icon = "/Kingo.Plugin.BHTB_Extract;component/Resources/未完成.png";
break;
case "1":
zyqNode.Icon = "/Kingo.Plugin.BHTB_Extract;component/Resources/进行中.png";
break;
case "2":
zyqNode.Icon = "/Kingo.Plugin.BHTB_Extract;component/Resources/已完成.png";
break;
}
zyqNode.cMenu = new ContextMenu();
MenuItem tmpitem = new MenuItem();
tmpitem.Tag = zyqNode;
tmpitem.Header = "已完成";
tmpitem.Click += (s, e) =>
{
MenuItem item = s as MenuItem;
if (item.Tag == null) return;
TreeNode tempNode = item.Tag as TreeNode;
int idx = _Layer.FeatureClass.FindField("ZYQZT");
if (idx == -1) return;
IFeature f = _Layer.FeatureClass.GetFeature(tempNode.Data.ToInt());
f.Value[idx] = 2;
f.Store();
tempNode.Icon = "/Kingo.Plugin.BHTB_Extract;component/Resources/已完成.png";
Marshal.ReleaseComObject(f);
};
zyqNode.cMenu.Items.Add(tmpitem);
tmpitem = new MenuItem();
tmpitem.Tag = zyqNode;
tmpitem.Header = "进行中";
tmpitem.Click += (s, e) =>
{
MenuItem item = s as MenuItem;
if (item.Tag == null) return;
TreeNode tempNode = item.Tag as TreeNode;
int idx = _Layer.FeatureClass.FindField("ZYQZT");
if (idx == -1) return;
IFeature f = _Layer.FeatureClass.GetFeature(tempNode.Data.ToInt());
f.Value[idx] = 1;
f.Store();
tempNode.Icon = "/Kingo.Plugin.BHTB_Extract;component/Resources/进行中.png";
Marshal.ReleaseComObject(f);
};
zyqNode.cMenu.Items.Add(tmpitem);
tmpitem = new MenuItem();
tmpitem.Tag = zyqNode;
tmpitem.Header = "未开始";
tmpitem.Click += (s, e) =>
{
MenuItem item = s as MenuItem;
if (item.Tag == null) return;
TreeNode tempNode = item.Tag as TreeNode;
int idx = _Layer.FeatureClass.FindField("ZYQZT");
if (idx == -1) return;
IFeature f = _Layer.FeatureClass.GetFeature(tempNode.Data.ToInt());
f.Value[idx] = 0;
f.Store();
tempNode.Icon = "/Kingo.Plugin.BHTB_Extract;component/Resources/未完成.png";
Marshal.ReleaseComObject(f);
};
zyqNode.cMenu.Items.Add(tmpitem);
node.Nodes.Add(zyqNode);
//TreeNode subNode = new TreeNode();
//subNode.Text = _dr["ZYQBH"] is DBNull ? "" : _dr["ZYQBH"].ToString();
//subNode.Tag = _dr["OBJECTID"];
//node.Nodes.Add(subNode);
}
itemList.Add(node);
this.tvTypes.ItemsSource = null;
tvTypes.ItemsSource = itemList;
//tvDirectory.Nodes.Add(node);
if (node.Nodes.Count != 0)
node.Nodes[0].Checked = true;
}
catch (Exception ex)
{
LogAPI.Debug("初始化作业区列表时发生异常,异常信息如下:" + ex);
return;
}
}
private bool isUpdatingSelection = false;
private void tvTypes_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs