年度变更建库软件5.0版本
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.
 
 

1437 lines
48 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>
/// UCAllTBYPList.xaml 的交互逻辑
/// </summary>
public partial class UCAllTBYPList : UserControl, IDockPanel2, INotifyPropertyChanged
{
// public UCNYYPZZBGListViewModel ViewModel = null;
public IHookHelper m_hookHelper
{
get;
set;
}
/// <summary>
/// 记录属性表是否正在刷新状态
/// </summary>
private bool IsLoading = false;
/// <summary>
/// 当前图斑
/// </summary>
private IFeatureClass SourceFeature
{
get;
set;
}
private IFeatureLayer pJCDLTBFeatureLayer = 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 _JCDLTBField;
public SelectedField JCDLTBField
{
get
{
return _JCDLTBField;
}
set
{
_JCDLTBField=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 UCAllTBYPList()
{
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 UCAllTBYPList(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;
pJCDLTBFeatureLayer = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("地类图斑");
if (pJCDLTBFeatureLayer == null || pJCDLTBFeatureLayer.FeatureClass == null)
{
MessageHelper.ShowTips("未找到基础地类图层!");
throw new Exception("未找到基础地类图层");
}
pSourceFeature = pJCDLTBFeatureLayer.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();
JCDLTBField = 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 == "JCDLTBDetailView")
{
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 < pJCDLTBFeatureLayer.FeatureClass.Fields.FieldCount; i++)
{
IField field = pJCDLTBFeatureLayer.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 = pJCDLTBFeatureLayer.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 = (pJCDLTBFeatureLayer 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)
{
if (CurrentItem.Table.Columns.Contains(KeyIDName))
{
var intex = CurrentItem[KeyIDName].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 (pJCDLTBFeatureLayer == null)
return;
try
{
SourceData.Rows.Clear();
using (ESRI.ArcGIS.ADF.ComReleaser com = new ESRI.ArcGIS.ADF.ComReleaser())
{
var index = 0;
IFeatureClass pCurrentFeatureClass = pJCDLTBFeatureLayer.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 = (pJCDLTBFeatureLayer 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("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 (pJCDLTBFeatureLayer.FeatureClass is ITable)
{
Count = (pJCDLTBFeatureLayer.FeatureClass as ITable).RowCount(pQueryFilter);
}
}
catch (Exception ex)
{
LogAPI.Debug(ex.Message.ToString());
MessageHelper.ShowError(ex.Message.ToString());
}
}
UCAllTBYPDetails ucAllTBYPDetails = null;
bool showDetail { get; set; }
public void ShowDetailView()
{
if (ucAllTBYPDetails == null)
{
ucAllTBYPDetails = new UCAllTBYPDetails();
ucAllTBYPDetails.CloseViewHandler += UCAllTBYPDetails_CloseViewHandler;
}
showDetail = ucAllTBYPDetails.showDetail;
ucAllTBYPDetails.ShowPanel();
}
private void UCAllTBYPDetails_CloseViewHandler(object sender, EventArgs e)
{
if (ucAllTBYPDetails != null)
{
ucAllTBYPDetails.DataContext = null;
ucAllTBYPDetails.showDetail = false;
ucAllTBYPDetails = null;
}
}
public void CloseDetailView()
{
Platform.Instance.NotifyMsgEven2 -= Instance_NotifyMsgEven2;
if (ucAllTBYPDetails != null)
{
ucAllTBYPDetails.ClosePanel();
}
ClearSelection(true);
}
/// <summary>
/// 设置详情页面数据
/// </summary>
/// <param name="pTBYBH">图斑预编号</param>
private void SetDetailViewData(object pData)
{
if (ucAllTBYPDetails == null && showDetail == true)
ShowDetailView();
if (ucAllTBYPDetails != null)
{
RowIndex = CurrentIndex;
ucAllTBYPDetails.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 = (pJCDLTBFeatureLayer 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 = pJCDLTBFeatureLayer;
}
else
{
pFeatureLayer = MapsManager.Instance.MapService.GetFeatureLayerByName("地类图斑");
}
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)
{
PageSize = -1;
IsLoading = true;
queryWhere = " 1=1 ";
IFeatureLayerDefinition pFeatureLayerDefinition = pJCDLTBFeatureLayer as IFeatureLayerDefinition;
if (pFeatureLayerDefinition != null && !string.IsNullOrWhiteSpace(pFeatureLayerDefinition.DefinitionExpression))
{
queryWhere += " and " + pFeatureLayerDefinition.DefinitionExpression;
System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatureLayerDefinition);
}
LoadData(null);
}
private void Search_Click(object sender, RoutedEventArgs e)
{
try
{
string sql = string.Empty;
if (JCDLTBField != null)
{
if (JCDLTBField.AliasName == "所有字段" || JCDLTBField.Name == "所有字段")
{
for (int i = 0; i < pJCDLTBFeatureLayer.FeatureClass.Fields.FieldCount; i++)
{
IField field = pJCDLTBFeatureLayer.FeatureClass.Fields.Field[i];
sql += GetSearchSQL(field);
}
}
else
{
IField field = JCDLTBField.Field;
sql = GetSearchSQL(field);
}
}
else
{
for (int i = 0; i < pJCDLTBFeatureLayer.FeatureClass.Fields.FieldCount; i++)
{
IField field = pJCDLTBFeatureLayer.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;
}
}
}
public class SelectedField
{
public int Index { get; set; }
public string Name { get; set; }
public string AliasName { get; set; }
public IField Field { get; set; }
}
public enum BCFS
{
Cover,
Add
}
public class ConfigModel : INotifyPropertyChanged
{
private string _DbPath;
private string _shpPath;
private string _yXFWPath;
private string _zPFWPath;
private bool _isExtractVectorFromDB;
private bool _isExtractVectorFromFile;
private bool _isExtractVectorFromExcelFile;
private bool _isInherentAttribute;
private BCFS _bcfs;
public int ShowIndex { get; set; }
public string DbPath
{
get
{
return _DbPath;
}
set
{
_DbPath = value;
OnPropertyChanged("DbPath");
}
}
public string ShpPath
{
get
{
return _shpPath;
}
set
{
_shpPath = value;
OnPropertyChanged("ShpPath");
}
}
private string _excelPath;
public string ExcelPath
{
get
{
return _excelPath;
}
set
{
_excelPath = value;
OnPropertyChanged("ExcelPath");
}
}
public string YXFWPath
{
get
{
return _yXFWPath;
}
set
{
_yXFWPath = value;
OnPropertyChanged("YXFWPath");
}
}
public string ZPFWPath
{
get
{
return _zPFWPath;
}
set
{
_zPFWPath = value;
OnPropertyChanged("ZPFWPath");
}
}
public bool IsExtractVectorFromDB
{
get
{
return _isExtractVectorFromDB;
}
set
{
if (value)
IsExtractVectorFromFile = !value;
_isExtractVectorFromDB = value;
OnPropertyChanged("IsExtractVectorFromDB");
}
}
public bool IsExtractVectorFromFile
{
get
{
return _isExtractVectorFromFile;
}
set
{
if (value)
IsExtractVectorFromDB = !value;
_isExtractVectorFromFile = value;
OnPropertyChanged("IsExtractVectorFromFile");
}
}
public bool IsExtractVectorFromExcelFile
{
get
{
return _isExtractVectorFromExcelFile;
}
set
{
if (value)
IsExtractVectorFromDB = !value;
_isExtractVectorFromExcelFile = value;
OnPropertyChanged("IsExtractVectorFromExcelFile");
}
}
public BCFS bcfs
{
get
{
return _bcfs;
}
set
{
_bcfs = value;
OnPropertyChanged("bcfs");
}
}
public bool IsInherentAttribute
{
get
{
return _isInherentAttribute;
}
set
{
_isInherentAttribute = value;
OnPropertyChanged("IsInherentAttribute");
}
}
public int CacheNum { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public bool Save(ProjectInfo prj)
{
try
{
if (prj == null) return false;
if (string.IsNullOrWhiteSpace(prj.ProjDir))
{
return false;
}
//将对象序列化成字符串
string Str = SerializeAPI.SerializeToXML<ConfigModel>(this);
Byte[] bytearr = Encoding.UTF8.GetBytes(Str);
//对字符串进行加密
//Byte[] resultArray = AesEncrypt(Str, "58ef12f9891a4cd89fa7bdd181ef13a7");
//修改人:李进营 修改时间 增加using引用
using (Stream stream = new System.IO.FileStream(prj.ProjDir + "\\" + "DbSetting.cfg", FileMode.Create, FileAccess.Write, FileShare.None))
{
stream.Write(bytearr, 0, bytearr.Length);
stream.Close();
}
return true;
}
catch (Exception ex)
{
LogAPI.Debug(ex);
return false;
}
}
}
public class CustomSelect
{
public int Index { get; set; }
public string Name { get; set; }
}
}