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.
1237 lines
43 KiB
1237 lines
43 KiB
using System; |
|
using System.Collections.Generic; |
|
using System.Linq; |
|
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 DevExpress.Xpf.Editors.Settings; |
|
using DevExpress.Xpf.Grid; |
|
using ESRI.ArcGIS.Carto; |
|
using ESRI.ArcGIS.Controls; |
|
using ESRI.ArcGIS.Geodatabase; |
|
using DevExpress.Xpf.Core.Native; |
|
using System.Windows.Threading; |
|
using KGIS.Framework.Utils.Interface; |
|
using KGIS.Framework.Views; |
|
using KGIS.Framework.Utils; |
|
using KGIS.Framework.Platform; |
|
using KGIS.Framework.Maps; |
|
using System.Data; |
|
using System.ComponentModel; |
|
using KGIS.Framework.Utils.Helper; |
|
using KGIS.Framework.Utils.Model; |
|
using System.IO; |
|
using KGIS.Framework.Utils.ExtensionMethod; |
|
using Kingo.PluginServiceInterface; |
|
|
|
namespace Kingo.Plugin.NYYP.View |
|
{ |
|
/// <summary> |
|
/// UCJCTBYPList.xaml 的交互逻辑 |
|
/// </summary> |
|
public partial class UCJCTBYPList : UserControl, IDockPanel2, INotifyPropertyChanged |
|
{ |
|
public IHookHelper m_hookHelper |
|
{ |
|
get; |
|
set; |
|
} |
|
/// <summary> |
|
/// 记录属性表是否正在刷新状态 |
|
/// </summary> |
|
private bool IsLoading = false; |
|
/// <summary> |
|
/// 当前图斑 |
|
/// </summary> |
|
private IFeatureClass SourceFeature |
|
{ |
|
get; |
|
set; |
|
} |
|
|
|
private IFeatureLayer pJCTBFeatureLayer = null; |
|
|
|
|
|
/// <summary> |
|
/// 当前图层 |
|
/// </summary> |
|
private IFeatureClass pSourceFeature{ get; set;} |
|
|
|
private DataTable _SourceData; |
|
/// <summary> |
|
/// 数据源集合 |
|
/// </summary> |
|
public DataTable SourceData |
|
{ |
|
get { return _SourceData; } |
|
set { _SourceData = value; } |
|
} |
|
|
|
/// <summary> |
|
/// 主键字段名称 |
|
/// </summary> |
|
private string KeyIDName = "OBJECTID"; |
|
|
|
private int _PageSize; |
|
public int PageSize |
|
{ |
|
get { return _PageSize; } |
|
set { _PageSize= value; } |
|
} |
|
|
|
private ICursor _Cursor = null; |
|
|
|
private int _Count; |
|
/// <summary> |
|
/// 总数 |
|
/// </summary> |
|
public int Count |
|
{ |
|
get { return _Count;} |
|
set { _Count = value; } } |
|
|
|
private int _ShowNum; |
|
/// <summary> |
|
/// 当前显示数 |
|
/// </summary> |
|
public int ShowNum |
|
{ |
|
get { return _ShowNum;} |
|
set { _ShowNum = value; } |
|
} |
|
|
|
|
|
private int searchNum; |
|
/// <summary> |
|
/// 搜素总条数 |
|
/// </summary> |
|
public int SearchNum |
|
{ |
|
get { return searchNum;} |
|
set { searchNum=value; } |
|
} |
|
|
|
private int _CurrentIndex = -1; |
|
public int CurrentIndex |
|
{ |
|
get { return _CurrentIndex; } |
|
set { _CurrentIndex=value; } |
|
} |
|
|
|
private DataRow _CurrentItem = null; |
|
public DataRow CurrentItem |
|
{ |
|
get { return _CurrentItem;} |
|
set { _CurrentItem=value; } |
|
} |
|
|
|
private string queryWhere = string.Empty; |
|
/// <summary> |
|
/// 查询条件 |
|
/// </summary> |
|
public string QueryWhere |
|
{ |
|
get { return queryWhere; } |
|
set { queryWhere = value; } |
|
} |
|
|
|
|
|
private string _SearchKey; |
|
/// <summary> |
|
/// 搜索关键字 |
|
/// </summary> |
|
public string SearchKey |
|
{ |
|
get |
|
{ |
|
return _SearchKey; |
|
} |
|
set |
|
{ |
|
_SearchKey=value; |
|
} |
|
} |
|
|
|
private SelectedField _JCTBField; |
|
public SelectedField JCTBField |
|
{ |
|
get |
|
{ |
|
return _JCTBField; |
|
} |
|
set |
|
{ |
|
_JCTBField = value; |
|
} |
|
} |
|
|
|
private List<SelectedField> _FieldList; |
|
public List<SelectedField> FieldList |
|
{ |
|
get { return _FieldList; } |
|
set |
|
{ |
|
_FieldList = value; |
|
} |
|
} |
|
|
|
private CustomSelect _tbypResult; |
|
public CustomSelect tbypResult |
|
{ |
|
get |
|
{ |
|
return _tbypResult; |
|
} |
|
set |
|
{ |
|
_tbypResult = value; |
|
} |
|
} |
|
private List<CustomSelect> _TBYPRestlt = null; |
|
public List<CustomSelect> TBYPResult |
|
{ |
|
get |
|
{ |
|
if (_TBYPRestlt == null) |
|
{ |
|
_TBYPRestlt = new List<CustomSelect>(); |
|
GetNYPYResult(); |
|
} |
|
return _TBYPRestlt; |
|
} |
|
set |
|
{ |
|
_TBYPRestlt = value; |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 数据行总个数 |
|
/// </summary> |
|
public int RowCount; |
|
/// <summary> |
|
/// 当前选中行索引 |
|
/// </summary> |
|
public int RowHandle; |
|
|
|
public int RowIndex; |
|
|
|
|
|
public UCJCTBYPList() |
|
{ |
|
InitializeComponent(); |
|
|
|
} |
|
|
|
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 bool IsShowInMap { get; set; } |
|
|
|
public event EventHandler CloseViewHandler; |
|
public event PropertyChangedEventHandler PropertyChanged; |
|
private void OnPropertyChanged(string propertyName) |
|
{ |
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); |
|
} |
|
public UCJCTBYPList(IHookHelper hookHelper, string searchWhere = null) |
|
{ |
|
try |
|
{ |
|
InitializeComponent(); |
|
this.m_hookHelper = hookHelper; |
|
Init( searchWhere); |
|
|
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("初始化监测图斑判读失败:" + ex.Message); |
|
throw ex; |
|
} |
|
} |
|
|
|
public void Init( string searchWhere = null) |
|
{ |
|
try |
|
{ |
|
DevExpress.Xpf.Core.ThemeManager.SetTheme(this, DevExpress.Xpf.Core.Theme.Office2013LightGray); |
|
this.DockAreas = DockStyle.DockBottom; |
|
this.FloatSize = new System.Drawing.Size(600, 340); |
|
this.DefaultArea = DockStyle.DockBottom; |
|
this.ShowCloseButton = true; |
|
this.ShowAutoHideButton = true; |
|
this.DockHeight = 340; |
|
this.IsShowInMap = true; |
|
this.Title = "监测图斑判读"; |
|
|
|
PageSize = 200; |
|
Platform.Instance.NotifyMsgEven2 += Instance_NotifyMsgEven2; |
|
|
|
pJCTBFeatureLayer = MapsManager.Instance.MapService.GetFeatureLayerByName("JCTB"); |
|
|
|
if (pJCTBFeatureLayer == null || pJCTBFeatureLayer.FeatureClass == null) |
|
{ |
|
MessageHelper.ShowTips("未找到监测图斑图层!"); |
|
throw new Exception("未找到监测图斑图层"); |
|
} |
|
pSourceFeature = pJCTBFeatureLayer.FeatureClass; |
|
|
|
if (SourceData == null) |
|
{ |
|
SourceData = new DataTable(); |
|
ConstructColumn(pSourceFeature.Fields); |
|
RefreshProgress();//刷新进度条 |
|
} |
|
MapsManager.Instance.MapService.OnSelectionChanged += MapsService_OnSelectionChanged; |
|
var cfg = ReadConfig(); |
|
|
|
LoadData(null, false, cfg.ShowIndex); |
|
GetFields(); |
|
JCTBField = FieldList[0]; |
|
this.DataContext = this; |
|
this.dgCtrl.SelectedItem = CurrentItem; |
|
this.dgCtrl.SelectedIndex = CurrentIndex; |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug(ex); |
|
throw ex; |
|
} |
|
} |
|
private void Instance_NotifyMsgEven2(NotifyMsgPackage msg) |
|
{ |
|
//接收来自内业会审详情视图的消息 |
|
if (msg.MsgType == "JCTBDetailView") |
|
{ |
|
switch (msg.Content.ToString()) |
|
{ |
|
case "NextData": |
|
//下一条 |
|
if (CurrentIndex == -1) |
|
{ |
|
CurrentIndex = RowIndex; |
|
} |
|
|
|
if (CurrentIndex < SourceData.Rows.Count) |
|
CurrentIndex++; |
|
RefreshProgress(); |
|
this.dgCtrl.SelectedIndex = CurrentIndex; |
|
|
|
break; |
|
case "PrevData": |
|
//上一条 |
|
if (CurrentIndex == -1) |
|
{ |
|
CurrentIndex = RowIndex; |
|
} |
|
if (CurrentIndex > 0) |
|
CurrentIndex--; |
|
RefreshProgress(); |
|
this.dgCtrl.SelectedIndex = CurrentIndex; |
|
break; |
|
case "SaveData": |
|
RefreshProgress(); |
|
this.dgCtrl.SelectedIndex = CurrentIndex; |
|
break; |
|
default: |
|
break; |
|
} |
|
} |
|
} |
|
|
|
|
|
private void GetNYPYResult() |
|
{ |
|
try |
|
{ |
|
string[] pyjgArr = new string[] { "需外业举证", "不需要外业举证", "未预判", "全部" }; |
|
|
|
for (int i = 0; i < pyjgArr.Length; i++) |
|
{ |
|
CustomSelect combypjg = new CustomSelect(); |
|
combypjg.Index = i; |
|
combypjg.Name = pyjgArr[i]; |
|
TBYPResult.Add(combypjg); |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("获取内业预判结果失败:" + ex); |
|
} |
|
} |
|
|
|
private void GetFields() |
|
{ |
|
try |
|
{ |
|
FieldList = new List<SelectedField>(); |
|
for (int i = 0; i < pJCTBFeatureLayer.FeatureClass.Fields.FieldCount; i++) |
|
{ |
|
IField field = pJCTBFeatureLayer.FeatureClass.Fields.Field[i]; |
|
if (field.Name.ToUpper().Contains("SHAPE")) |
|
continue; |
|
SelectedField combfield = new SelectedField(); |
|
combfield.Name = field.Name; |
|
combfield.AliasName = field.AliasName; |
|
combfield.Field = field; |
|
combfield.Index = i; |
|
FieldList.Add(combfield); |
|
} |
|
SelectedField allfield = new SelectedField(); |
|
allfield.Name = "所有字段"; |
|
allfield.AliasName = "所有字段"; |
|
FieldList.Add(allfield); |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("获取监测图斑字段失败:" + ex); |
|
} |
|
} |
|
|
|
private void RefreshProgress() |
|
{ |
|
try |
|
{ |
|
IFeatureClass pCurrentFeatureClass = pJCTBFeatureLayer.FeatureClass; |
|
int fieldIndex = pCurrentFeatureClass.FindField("SFJZ"); |
|
if (fieldIndex > -1) |
|
{ |
|
IQueryFilter filter = new QueryFilterClass(); |
|
filter.WhereClause = " (SFJZ = '1' or SFJZ ='0')"; |
|
int doCount = pCurrentFeatureClass.FeatureCount(filter); |
|
int maxCount = pCurrentFeatureClass.FeatureCount(null); |
|
this.pro_Progress.Maximum = maxCount; |
|
decimal value = 0; |
|
string content = string.Empty; |
|
if (0 != maxCount) |
|
{ |
|
value = Math.Round(((decimal)doCount / maxCount), 4); |
|
content = string.Format("{0}/{1} {2}", doCount, maxCount, value.ToString("P2")); |
|
} |
|
this.pro_Progress.Content = content; |
|
this.pro_Progress.EditValue = doCount; |
|
} |
|
|
|
} |
|
catch (Exception ex) |
|
{ |
|
throw ex; |
|
} |
|
} |
|
|
|
private void MapsService_OnSelectionChanged(object sender, EventArgs e) |
|
{ |
|
ISelectionSet pSelectionSet = (pJCTBFeatureLayer as IFeatureSelection).SelectionSet; |
|
IEnumIDs ids = pSelectionSet.IDs; |
|
ids.Reset(); |
|
int oid = ids.Next(); |
|
if (oid > -1) |
|
{ |
|
DataRow[] drs = SourceData.Select(string.Format(" OBJECTID={0}", oid)); |
|
if (drs.Length > 0) |
|
{ |
|
CurrentItem = drs[0]; |
|
CurrentIndex = SourceData.Rows.IndexOf(CurrentItem); |
|
} |
|
} |
|
|
|
} |
|
|
|
/// <summary> |
|
/// 读取配置 |
|
/// </summary> |
|
/// <returns></returns> |
|
private ConfigModel ReadConfig() |
|
{ |
|
ConfigModel cfg = null; |
|
ProjectInfo prj = MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo; |
|
string cfgPath = System.IO.Path.Combine(prj.ProjDir, "DbSetting.cfg"); |
|
if (!File.Exists(cfgPath)) |
|
{ |
|
cfg = new ConfigModel() |
|
{ |
|
IsExtractVectorFromDB = true, //IsInherentAttribute = true, |
|
YXFWPath = "PhotoResult", |
|
ZPFWPath = "PhotoInfo", |
|
CacheNum = 10, |
|
ShowIndex = 1 |
|
}; |
|
} |
|
else |
|
{ |
|
string strData = string.Empty; |
|
//读取文件内容到字节数组 |
|
using (System.IO.FileStream stream = new System.IO.FileStream(cfgPath, FileMode.Open)) |
|
{ |
|
byte[] bytes = new byte[stream.Length]; |
|
stream.Read(bytes, 0, bytes.Length); |
|
stream.Close(); |
|
strData = Encoding.UTF8.GetString(bytes); |
|
} |
|
if (!string.IsNullOrWhiteSpace(strData)) |
|
{ |
|
cfg = SerializeAPI.DeserializeToObject<ConfigModel>(strData); |
|
if (cfg == null) |
|
{ |
|
cfg = SerializeAPI.DeserializeToObject<ConfigModel>(strData.Substring(1)); |
|
} |
|
} |
|
} |
|
return cfg; |
|
} |
|
|
|
/// <summary> |
|
/// 保存当前查看位置 |
|
/// </summary> |
|
public void SaveCurrentItemIndex() |
|
{ |
|
try |
|
{ |
|
if (CurrentItem == null) return; |
|
//读取配置 |
|
ConfigModel cfg = null; |
|
ProjectInfo prj = MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo; |
|
if (prj != null) |
|
{ |
|
cfg = ReadConfig(); |
|
//修改并且保存配置 |
|
if (CurrentItem.Table.Rows.Count > 0) |
|
{ |
|
var intex = CurrentItem["OBJECTID"].ToInt(); |
|
cfg.ShowIndex = intex; |
|
cfg.Save(prj); |
|
} |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("保存当前查看位置失败:" + ex); |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 构造列获取记录条数 |
|
/// </summary> |
|
/// <param name="Data"></param> |
|
/// <param name="fields"></param> |
|
private void ConstructColumn(IFields fields) |
|
{ |
|
if (fields != null) |
|
{ |
|
for (int i = 0; i < fields.FieldCount; i++) |
|
{ |
|
IField field = fields.get_Field(i); |
|
if (field.Name.ToUpper().StartsWith("SHAPE") || field.Name.ToUpper() == "TBFW" || field.Name.ToUpper() == "BGZT" || field.Name.ToUpper() == "ONLYZLBG" || field.Name.ToUpper() == "JCZT" || field.Name.ToUpper() == "JCJG") |
|
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;//编辑状态启用默认是否可以编辑 |
|
SourceData.Columns.Add(col); |
|
System.Runtime.InteropServices.Marshal.ReleaseComObject(field); |
|
} |
|
} |
|
} |
|
|
|
public void LoadData(IQueryFilter pFilter = null, bool isSearch = false, int showindex = -1) |
|
{ |
|
if (pJCTBFeatureLayer == null) |
|
return; |
|
try |
|
{ |
|
SourceData.Rows.Clear(); |
|
using (ESRI.ArcGIS.ADF.ComReleaser com = new ESRI.ArcGIS.ADF.ComReleaser()) |
|
{ |
|
var index = 0; |
|
IFeatureClass pCurrentFeatureClass = pJCTBFeatureLayer.FeatureClass; |
|
_Cursor = (pCurrentFeatureClass as ITable).Search(pFilter, true); |
|
Count = pCurrentFeatureClass.FeatureCount(pFilter); |
|
this.lblCount.Content = Count; |
|
if (Count < PageSize) |
|
{ |
|
com.ManageLifetime(_Cursor); |
|
} |
|
IRow feature = null; |
|
while ((feature = _Cursor.NextRow()) != null) |
|
{ |
|
DataRow dr = SourceData.NewRow(); |
|
for (int i = 0; i < SourceData.Columns.Count; i++) |
|
{ |
|
object col = SourceData.Columns[i].ExtendedProperties["index"]; |
|
if (col == null) |
|
{ |
|
continue; |
|
} |
|
int colIndex = int.Parse(col.ToString()); |
|
object obj = feature.get_Value(colIndex); |
|
if (obj == null) |
|
{ |
|
continue; |
|
} |
|
else |
|
{ |
|
if ((obj.ToString()).Contains("1899/12/30 0:00:00")) |
|
{ |
|
obj = System.DBNull.Value; |
|
} |
|
} |
|
//字符串时,去空格,对应bug10473 |
|
if (obj is string) |
|
{ |
|
obj = obj.ToString().Trim(); |
|
} |
|
dr[i] = obj; |
|
} |
|
|
|
System.Runtime.InteropServices.Marshal.ReleaseComObject(feature); |
|
index++; |
|
if (PageSize != -1) |
|
{ |
|
if (index > PageSize) |
|
break; |
|
} |
|
CurrentIndex = 0; |
|
SourceData.Rows.Add(dr); |
|
} |
|
if (isSearch) |
|
{ |
|
SearchNum = Count; |
|
} |
|
ShowNum = SourceData.Rows.Count; |
|
this.lblCurrentCount.Content = ShowNum; |
|
ShowLabContent(SourceData.Rows.Count); |
|
RowCount = SourceData.Rows.Count; |
|
if (RowCount > 0) |
|
{ |
|
RowHandle++;//初始化,默认第一行 |
|
List<int> oids = new List<int>(); |
|
|
|
if (showindex > -1) |
|
{ |
|
if (showindex == 1) |
|
{ |
|
IQueryFilter queryfilter = new QueryFilterClass(); |
|
queryfilter.WhereClause = string.Format("OBJECTID={0}", showindex); |
|
int num = pCurrentFeatureClass.FeatureCount(queryfilter); |
|
if (num == 0) |
|
{ |
|
oids.Add(Int32.Parse(SourceData.Rows[0]["OBJECTID"].ToString()));//默认第一条 |
|
} |
|
else |
|
{ |
|
RowHandle = showindex; |
|
oids.Add(showindex); |
|
} |
|
|
|
} |
|
else |
|
{ |
|
RowHandle = showindex; |
|
oids.Add(showindex); |
|
} |
|
} |
|
else |
|
{ |
|
oids.Add(Int32.Parse(SourceData.Rows[0]["OBJECTID"].ToString()));//默认第一条 |
|
} |
|
|
|
ISelectionSet pSelectionSet = (pJCTBFeatureLayer as IFeatureSelection).SelectionSet; |
|
if (pSelectionSet.Count > 0 && m_hookHelper != null)//兼容空值 肖芮 2020-09-25 |
|
{ |
|
m_hookHelper.FocusMap.ClearSelection(); |
|
} |
|
|
|
pSelectionSet.AddList(oids.Count, ref oids.ToArray()[0]); |
|
IMapControlDefault mapcontrol = MapsManager.Instance.MapService.Hook as IMapControlDefault; |
|
mapcontrol.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, mapcontrol.ActiveView.Extent); |
|
|
|
|
|
MapsManager.Instance.MapService.SelectFeature("JC_DLTB", String.Join(",", oids)); |
|
} |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("监测图斑列表数据加载失败:" + ex.Message); |
|
//throw ex; |
|
} |
|
finally |
|
{ |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 显示查询数据量LabContent |
|
/// </summary> |
|
/// <param name="CurrentFindCount">当前查询到的数据量</param> |
|
private void ShowLabContent(int CurrentFindCount) |
|
{ |
|
try |
|
{ |
|
IQueryFilter pQueryFilter = new QueryFilterClass() |
|
{ |
|
WhereClause = "1=1", |
|
SubFields = KeyIDName |
|
}; |
|
if (this.SourceFeature != null) |
|
{ |
|
Count = (this.SourceFeature as ITable).RowCount(pQueryFilter); |
|
} |
|
else if (pJCTBFeatureLayer.FeatureClass is ITable) |
|
{ |
|
Count = (pJCTBFeatureLayer.FeatureClass as ITable).RowCount(pQueryFilter); |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug(ex.Message.ToString()); |
|
MessageHelper.ShowError(ex.Message.ToString()); |
|
} |
|
} |
|
|
|
|
|
UCJCTBYPDetails ucJCTBYPDetails = null; |
|
bool showDetail { get; set; } |
|
|
|
public void ShowDetailView() |
|
{ |
|
|
|
if (ucJCTBYPDetails == null) |
|
{ |
|
ucJCTBYPDetails = new UCJCTBYPDetails(); |
|
ucJCTBYPDetails.CloseViewHandler += UCJCTBYPDetails_CloseViewHandler; |
|
} |
|
showDetail = ucJCTBYPDetails.showDetail; |
|
ucJCTBYPDetails.ShowPanel(); |
|
} |
|
|
|
private void UCJCTBYPDetails_CloseViewHandler(object sender, EventArgs e) |
|
{ |
|
if (ucJCTBYPDetails != null) |
|
{ |
|
ucJCTBYPDetails.DataContext = null; |
|
ucJCTBYPDetails.showDetail = false; |
|
ucJCTBYPDetails = null; |
|
} |
|
|
|
} |
|
public void CloseDetailView() |
|
{ |
|
Platform.Instance.NotifyMsgEven2 -= Instance_NotifyMsgEven2; |
|
if (ucJCTBYPDetails != null) |
|
{ |
|
ucJCTBYPDetails.ClosePanel(); |
|
} |
|
ClearSelection(true); |
|
} |
|
|
|
/// <summary> |
|
/// 设置详情页面数据 |
|
/// </summary> |
|
/// <param name="pTBYBH">图斑预编号</param> |
|
private void SetDetailViewData(object pData) |
|
{ |
|
if (ucJCTBYPDetails == null && showDetail == true) |
|
ShowDetailView(); |
|
if (ucJCTBYPDetails != null) |
|
{ |
|
RowIndex = CurrentIndex; |
|
ucJCTBYPDetails.BindData(pData as DataRow, CurrentIndex + 1, RowCount); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
private void DgCtrl_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e) |
|
{ |
|
DataGrid dataGrid = (sender as System.Windows.Controls.DataGrid); |
|
if (dataGrid == null || dataGrid.ItemsSource == null || (dataGrid.ItemsSource as System.Data.DataView) == null) |
|
{ |
|
return; |
|
} |
|
DataTable table = (dataGrid.ItemsSource as System.Data.DataView).Table; |
|
if (table == null) |
|
{ |
|
return; |
|
} |
|
|
|
string colName = e.PropertyName; |
|
if (table.Columns.Contains(colName)) |
|
{ |
|
string caption = table.Columns[colName].Caption; |
|
if (!string.IsNullOrWhiteSpace(caption)) |
|
{ |
|
e.Column.Header = caption; |
|
} |
|
} |
|
} |
|
|
|
public void ShowPanel() |
|
{ |
|
ShowDetailView(); |
|
Platform.Instance.OpenView(this, false); |
|
} |
|
|
|
public void ClosePanel() |
|
{ |
|
SaveCurrentItemIndex(); |
|
showDetail = false; |
|
Platform.Instance.CloseView(this); |
|
} |
|
|
|
public void ClosePanelInvoke() |
|
{ |
|
SaveCurrentItemIndex(); |
|
CloseDetailView(); |
|
showDetail = false; |
|
CloseViewHandler?.Invoke(this, null); |
|
} |
|
|
|
private void DgCtrl_SelectionChanged(object sender, SelectionChangedEventArgs e) |
|
{ |
|
if (this.dgCtrl.SelectedItem != null) |
|
{ |
|
DataRowView dataview = this.dgCtrl.SelectedItem as DataRowView; |
|
this.CurrentItem = dataview.Row; |
|
this.CurrentIndex = this.dgCtrl.SelectedIndex; |
|
} |
|
GridControlCurrentItemChanged(); |
|
} |
|
|
|
public void GridControlCurrentItemChanged() |
|
{ |
|
try |
|
{ |
|
if (CurrentItem == null) |
|
{ |
|
return; |
|
} |
|
if (!CurrentItem.Table.Columns.Contains(KeyIDName)) |
|
return; |
|
ClearSelection(false); |
|
|
|
List<int> oids = new List<int>(); |
|
int oid = -1; |
|
if (CurrentItem.Table.Columns.Contains(KeyIDName)) |
|
{ |
|
if (int.TryParse(CurrentItem[KeyIDName].ToString(), out oid)) |
|
{ |
|
//修改人:李忠盼 修改时间:20180930 外部图层FID从0开始 |
|
if (oid < 0) |
|
return; |
|
if (oids.Contains(oid)) |
|
return; |
|
oids.Add(oid); |
|
RowHandle = oid; |
|
} |
|
} |
|
else if (CurrentItem.Table.Columns.Contains(KeyIDName)) |
|
{ |
|
if (int.TryParse(CurrentItem[KeyIDName].ToString(), out oid)) |
|
{ |
|
if (oid <= 0) |
|
return; |
|
if (oids.Contains(oid)) |
|
return; |
|
oids.Add(oid); |
|
RowHandle = oid; |
|
} |
|
} |
|
ISelectionSet pSelectionSet = (pJCTBFeatureLayer as IFeatureSelection).SelectionSet; |
|
if (pSelectionSet == null) |
|
{ |
|
return; |
|
} |
|
if (pSelectionSet.Count > 10000) |
|
{ |
|
m_hookHelper.FocusMap.ClearSelection(); |
|
} |
|
if (pSelectionSet.Count > 0 || oids.Count > 0) |
|
{ |
|
List<int> listRemoveObjectID = new List<int>(); |
|
IEnumIDs enumIDs = pSelectionSet.IDs; |
|
enumIDs.Reset(); |
|
int objectid = 0; |
|
while ((objectid = enumIDs.Next()) >= 0) |
|
{ |
|
if (oids.Contains(objectid)) |
|
{ |
|
oids.Remove(objectid); |
|
continue; |
|
} |
|
listRemoveObjectID.Add(objectid); |
|
} |
|
if (listRemoveObjectID.Count > 0) |
|
{ |
|
pSelectionSet.RemoveList(listRemoveObjectID.Count, ref listRemoveObjectID.ToArray()[0]); |
|
} |
|
} |
|
if (oids.Count > 0) |
|
{ |
|
pSelectionSet.AddList(oids.Count, ref oids.ToArray()[0]); |
|
} |
|
SetDetailViewData(CurrentItem); |
|
IMapControlDefault mapcontrol = MapsManager.Instance.MapService.Hook as IMapControlDefault; |
|
mapcontrol.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, mapcontrol.ActiveView.Extent); |
|
ControlsZoomToSelectedCommandClass zoom = new ControlsZoomToSelectedCommandClass(); |
|
zoom.OnCreate(m_hookHelper.Hook); |
|
zoom.OnClick(); |
|
|
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug(ex); |
|
} |
|
} |
|
|
|
|
|
private void ClearSelection(bool isClose) |
|
{ |
|
try |
|
{ |
|
IFeatureLayer pFeatureLayer = null; |
|
|
|
if (isClose) |
|
{ |
|
pFeatureLayer = pJCTBFeatureLayer; |
|
} |
|
else |
|
{ |
|
pFeatureLayer = MapsManager.Instance.MapService.GetFeatureLayerByName("JC_DLTB"); |
|
} |
|
|
|
if (pFeatureLayer != null) |
|
{ |
|
ISelectionSet pSelectionSet = (pFeatureLayer as IFeatureSelection).SelectionSet; |
|
if (pSelectionSet == null) |
|
{ |
|
return; |
|
} |
|
|
|
if (pSelectionSet.Count > 0) |
|
{ |
|
List<int> listRemoveObjectID = new List<int>(); |
|
IEnumIDs enumIDs = pSelectionSet.IDs; |
|
enumIDs.Reset(); |
|
int objectid = 0; |
|
while ((objectid = enumIDs.Next()) >= 0) |
|
{ |
|
|
|
listRemoveObjectID.Add(objectid); |
|
} |
|
if (listRemoveObjectID.Count > 0) |
|
{ |
|
pSelectionSet.RemoveList(listRemoveObjectID.Count, ref listRemoveObjectID.ToArray()[0]); |
|
|
|
} |
|
|
|
if (m_hookHelper != null) |
|
{ |
|
IGraphicsContainer graphics = m_hookHelper.ActiveView.GraphicsContainer; |
|
if (graphics == null) |
|
{ |
|
return; |
|
} |
|
graphics.DeleteAllElements(); |
|
} |
|
|
|
IMapControlDefault mapcontrol = MapsManager.Instance.MapService.Hook as IMapControlDefault; |
|
mapcontrol.Refresh(); |
|
} |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug(ex.Message.ToString()); |
|
MessageHelper.ShowError(ex.Message.ToString()); |
|
} |
|
} |
|
|
|
private void GcNYYP_FilterChanged(object sender, RoutedEventArgs e) |
|
{ |
|
ShowNum = (e.Source as GridControl).DataController.GetAllFilteredAndSortedRows().Count; |
|
} |
|
|
|
|
|
private void GcNYYP_EndSorting(object sender, RoutedEventArgs e) |
|
{ |
|
try |
|
{ |
|
GridSortInfo sortInfo = (e.OriginalSource as GridControl).SortInfo[0]; |
|
DataColumn column = SourceData.Columns[sortInfo.FieldName]; |
|
if (column == null) |
|
{ |
|
throw new Exception("未获取到列!"); |
|
} |
|
string sort = " ASC"; |
|
if (sortInfo.SortOrder.ToString() == "Ascending") |
|
{ |
|
sort = " ASC"; |
|
} |
|
else |
|
{ |
|
sort = " DESC"; |
|
} |
|
SourceData.Select("1=1", sortInfo.FieldName + sort); |
|
e.Handled = false; |
|
return; |
|
} |
|
catch (Exception ex) |
|
{ |
|
MessageHelper.ShowError("数据排序失败:" + ex.Message); |
|
LogAPI.Debug(ex); |
|
} |
|
} |
|
|
|
private void GcNYYP_AutoGeneratedColumns(object sender, RoutedEventArgs e) |
|
{ |
|
|
|
var grid = e.Source as GridControl; |
|
DataTable table = grid.ItemsSource as DataTable; |
|
if (table == null) |
|
return; |
|
foreach (GridColumn column in grid.Columns) |
|
{ |
|
if (table.Columns.Contains(column.FieldName)) |
|
{ |
|
string caption = table.Columns[column.FieldName].Caption; |
|
if (caption != null) |
|
{ |
|
column.EditSettings = new TextEditSettings() { HorizontalContentAlignment = EditSettingsHorizontalAlignment.Left }; |
|
column.Header = caption; |
|
} |
|
} |
|
} |
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
/// 显示全部数据 |
|
/// </summary> |
|
/// <param name="sender"></param> |
|
/// <param name="e"></param> |
|
private void LoadAllData_Click(object sender, RoutedEventArgs e) |
|
{ |
|
try |
|
{ |
|
PageSize = -1; |
|
IsLoading = true; |
|
queryWhere = " 1=1 "; |
|
IFeatureLayerDefinition pFeatureLayerDefinition = pJCTBFeatureLayer as IFeatureLayerDefinition; |
|
if (pFeatureLayerDefinition != null && !string.IsNullOrWhiteSpace(pFeatureLayerDefinition.DefinitionExpression)) |
|
{ |
|
queryWhere += " and " + pFeatureLayerDefinition.DefinitionExpression; |
|
System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatureLayerDefinition); |
|
} |
|
LoadData(null); |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("加载全部数据失败:" + ex); |
|
MessageHelper.Show("加载全部数据失败:" + ex); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
private void Search_Click(object sender, RoutedEventArgs e) |
|
{ |
|
try |
|
{ |
|
string sql = string.Empty; |
|
if (JCTBField != null) |
|
{ |
|
if (JCTBField.AliasName == "所有字段" || JCTBField.Name == "所有字段") |
|
{ |
|
for (int i = 0; i < pJCTBFeatureLayer.FeatureClass.Fields.FieldCount; i++) |
|
{ |
|
IField field = pJCTBFeatureLayer.FeatureClass.Fields.Field[i]; |
|
sql += GetSearchSQL(field); |
|
} |
|
} |
|
else |
|
{ |
|
IField field = JCTBField.Field; |
|
sql = GetSearchSQL(field); |
|
} |
|
} |
|
else |
|
{ |
|
for (int i = 0; i < pJCTBFeatureLayer.FeatureClass.Fields.FieldCount; i++) |
|
{ |
|
IField field = pJCTBFeatureLayer.FeatureClass.Fields.Field[i]; |
|
sql += GetSearchSQL(field); |
|
} |
|
} |
|
|
|
if (tbypResult != null) |
|
{ |
|
if (tbypResult.Name == "需外业举证") |
|
{ |
|
sql += string.Format(" SFJZ='1' or"); |
|
} |
|
else if (tbypResult.Name == "不需要外业举证") |
|
{ |
|
sql += string.Format(" SFJZ='0' or"); |
|
} |
|
else if (tbypResult.Name == "未预判") |
|
{ |
|
sql += string.Format("( SFJZ='' or SFJZ is null) or"); |
|
} |
|
|
|
} |
|
IQueryFilter queryFilter = null; |
|
if (!string.IsNullOrWhiteSpace(sql)) |
|
{ |
|
queryFilter = new QueryFilterClass(); |
|
queryFilter.WhereClause = sql.Substring(0, sql.Length - 3) ; |
|
} |
|
else |
|
{ |
|
queryFilter = new QueryFilterClass(); |
|
|
|
} |
|
|
|
LoadData(queryFilter); |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("搜索失败:" + ex); |
|
MessageHelper.Show("搜索失败:" + ex); |
|
} |
|
} |
|
|
|
|
|
private string GetSearchSQL(IField field) |
|
{ |
|
string sql = string.Empty; |
|
try |
|
{ |
|
int value = 0; |
|
double dvalue = 0; |
|
switch (field.Type) |
|
{ |
|
case esriFieldType.esriFieldTypeSmallInteger: |
|
if (!int.TryParse(SearchKey, out value)) |
|
{ |
|
return sql; |
|
} |
|
sql += "cast(" + field.Name + " as varchar(200))" + " like '%" + value + "%' or "; |
|
break; |
|
case esriFieldType.esriFieldTypeInteger: |
|
if (!int.TryParse(SearchKey, out value)) |
|
{ |
|
return sql; |
|
} |
|
sql += "cast(" + field.Name + " as varchar(200))" + " like '%" + value + "%' or "; |
|
break; |
|
case esriFieldType.esriFieldTypeSingle: |
|
break; |
|
case esriFieldType.esriFieldTypeDouble: |
|
if (!double.TryParse(SearchKey, out dvalue)) |
|
{ |
|
return sql; |
|
} |
|
sql += "cast(" + field.Name + " as varchar(200))" + " like '%" + dvalue + "%' or "; |
|
break; |
|
case esriFieldType.esriFieldTypeString: |
|
sql += field.Name + " like '%" + SearchKey + "%' or "; |
|
break; |
|
case esriFieldType.esriFieldTypeDate: |
|
DateTime dateTime; |
|
if (!DateTime.TryParse(SearchKey, out dateTime)) |
|
{ |
|
return sql; |
|
} |
|
sql += field.Name + " like '%" + dateTime + "%' or "; |
|
break; |
|
case esriFieldType.esriFieldTypeOID: |
|
if (!int.TryParse(SearchKey, out value)) |
|
{ |
|
return sql; |
|
} |
|
sql += field.Name + " = " + value + " or "; |
|
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; |
|
} |
|
return sql; |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug(ex); |
|
return sql; |
|
} |
|
} |
|
|
|
|
|
} |
|
}
|
|
|