using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.Controls; using ESRI.ArcGIS.esriSystem; using ESRI.ArcGIS.Geodatabase; using KGIS.Framework.DBOperator; using KGIS.Framework.Maps; using KGIS.Framework.Platform; using KGIS.Framework.Utils; using KGIS.Framework.Utils.Helper; using KGIS.Framework.Views; using Kingo.PluginServiceInterface; using Kingo.PluginServiceInterface.Enums; using Kingo.PluginServiceInterface.Model; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Linq; using System.Reflection; using System.Windows; using System.Windows.Controls; using DicTypeEnum = KGIS.Framework.Platform.DicTypeEnum; namespace Kingo.Plugin.General.View { /// /// 内业预处理结果 /// public partial class UCNYProcessingResults : UserControl, IElementInfo, INotifyPropertyChanged { private List ListYPDLData { get; set; } private NYYSInfo NYYSInfo { get; set; } private TaskPackage taskPackage { get; set; } public bool IsReadOnly { get; set; } private IEngineEditor engineEditor = new EngineEditorClass(); public bool showDetail { get; set; } private int m_DataIndex { get; set; } private int m_DataCount { get; set; } #region 接口实现 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 event EventHandler CloseViewHandler; public event PropertyChangedEventHandler PropertyChanged; private void OnPropertyChanged(string propertyName) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } public bool IsShowInMap { get; set; } public bool IsShow { get; set; } public int ShowIndex { get; set; } public bool ResetSize { get; set; } public bool AllowEdit { get; set; } #endregion public UCNYProcessingResults() { InitializeComponent(); DevExpress.Xpf.Core.ThemeManager.SetTheme(this, DevExpress.Xpf.Core.Theme.Office2013LightGray); this.Title = "内业预处理结果"; List listSF = new List() { new KeyValue(){ CodeInt=1, Name="是"}, new KeyValue(){ CodeInt=0, Name="否"} }; this.comBoxSF.ItemsSource = listSF; this.Loaded += (s, e) => { ListYPDLData = Platform.Instance.DicHelper.GetNoGroupDic(DicTypeEnum.DLBM); if (ListYPDLData == null) return; ListYPDLData.Insert(1, new DataDicTionary() { CODE = "12", NAME = "其他土地", DisplayName = "12-其他土地" }); ListYPDLData.Insert(1, new DataDicTionary() { CODE = "11", NAME = "水域及水利设施用地", DisplayName = "11-水域及水利设施用地" }); ListYPDLData.Insert(1, new DataDicTionary() { CODE = "10", NAME = "交通运输用地", DisplayName = "10-交通运输用地" }); ListYPDLData.Insert(1, new DataDicTionary() { CODE = "20", NAME = "建设用地", DisplayName = "20-建设用地" }); ListYPDLData.Insert(1, new DataDicTionary() { CODE = "04", NAME = "草地", DisplayName = "04-草地" }); ListYPDLData.Insert(1, new DataDicTionary() { CODE = "03", NAME = "林地", DisplayName = "03-林地" }); ListYPDLData.Insert(1, new DataDicTionary() { CODE = "02", NAME = "种植园用地", DisplayName = "02-种植园用地" }); ListYPDLData.Insert(1, new DataDicTionary() { CODE = "01", NAME = "耕地", DisplayName = "01-耕地" }); ListYPDLData.Insert(1, new DataDicTionary() { CODE = "00", NAME = "湿地", DisplayName = "00-湿地" }); ListYPDLData.Add(new DataDicTionary() { CODE = "1301", NAME = "临时用地", DisplayName = "1301-临时用地" }); ListYPDLData.Add(new DataDicTionary() { CODE = "1302", NAME = "光伏板区", DisplayName = "1302-光伏板区" }); ListYPDLData.Add(new DataDicTionary() { CODE = "1303", NAME = "推土区", DisplayName = "1303-推土区" }); ListYPDLData.Add(new DataDicTionary() { CODE = "1304", NAME = "拆除未尽区", DisplayName = "1304-拆除未尽区" }); txt_Box.ItemsSource = ListYPDLData; }; } public void ShowPanel() { showDetail = true; Platform.Instance.OpenView(this, false); } public void ClosePanel() { showDetail = false; Platform.Instance.CloseView(this); } public void ClosePanelInvoke() { CloseViewHandler?.Invoke(this, null); } private void TxtYPSM_GotFocus(object sender, RoutedEventArgs e) { if ((MapsManager.Instance.CurrProjectInfo as ProjectInfo) != null) { (MapsManager.Instance.CurrProjectInfo as ProjectInfo).EnableShortcut = false; } } private void TxtYPSM_LostFocus(object sender, RoutedEventArgs e) { if ((MapsManager.Instance.CurrProjectInfo as ProjectInfo) != null) { (MapsManager.Instance.CurrProjectInfo as ProjectInfo).EnableShortcut = true; } } public void BindData(object obj) { IRDBHelper rdbHelper = null; try { NYYSInfo nYYSInfo = obj as NYYSInfo; if (nYYSInfo != null) { this.NYYSInfo = nYYSInfo; this.taskPackage = nYYSInfo.TaskPackages; if (nYYSInfo.BingDataType == DTBDataTypeEnum.NYYCL) { //nYYSInfo.IsReadOnly = false; txt_Box.IsReadOnly = false; comBoxSF.IsReadOnly = false; txtYPSM.IsReadOnly = false; } else if (nYYSInfo.BingDataType == DTBDataTypeEnum.DTBSL) { this.DataContext = null; this.DataContext = this.NYYSInfo; } else { if (taskPackage == null || string.IsNullOrWhiteSpace(taskPackage.PackageTempPath) || !System.IO.File.Exists(taskPackage.PackageTempPath)) { this.DataContext = null; return; } nYYSInfo.IsReadOnly = true; txt_Box.IsReadOnly = true; comBoxSF.IsReadOnly = true; txtYPSM.IsReadOnly = true; rdbHelper = RDBFactory.CreateDbHelper($"{taskPackage.PackageTempPath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite); if (!rdbHelper.TableIsExist("nyysresult")) { this.DataContext = this.NYYSInfo; return; } DataTable dataTable = rdbHelper.ExecuteDatatable("nyysresult", $"select * from nyysresult where tbbsm='{NYYSInfo.WYRWTB.TBBSM}'", true); this.NYYSInfo.NYYSResult = new NYYSResult(); if (dataTable != null && dataTable.Rows.Count > 0) { this.NYYSInfo.NYYSResult = KGIS.Framework.Utils.Utility.TBToList.ConvertEntity(dataTable.Rows[0]); } else { this.NYYSInfo.NYYSResult = new NYYSResult() { TBBSM = this.NYYSInfo.WYRWTB.TBBSM, YPRY = (MapsManager.Instance.CurrProjectInfo as ProjectInfo).UserName, YPSJ = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), SFXYWY = 1 }; } } } this.DataContext = this.NYYSInfo; } catch (Exception ex) { LogAPI.Debug($"{ex.Message}"); LogAPI.Debug($"{ex.Source}"); } finally { if (rdbHelper != null) { rdbHelper.DisConnect(); } } } public void SaveEdit() { IRDBHelper rdbHelper = null; try { if (taskPackage == null) return; if (NYYSInfo.BingDataType != DTBDataTypeEnum.NYYCL) return; //if (engineEditor == null) //{ // engineEditor = new EngineEditorClass(); //} //if (engineEditor.EditState != esriEngineEditState.esriEngineStateNotEditing) //{ // if (engineEditor.HasEdits()) // { // engineEditor.StopEditing(true); // //throw new Exception("当前地图编辑未保存,请先保存编辑!"); // } //} //if (string.IsNullOrWhiteSpace((MapsManager.Instance.CurrProjectInfo as ProjectInfo).UserName)) //{ // throw new Exception("未获取到当前用户信息,请先进行用户信息设置!"); //} if (this.NYYSInfo.NYYSResult.SFXYWY != 0 && this.NYYSInfo.NYYSResult.SFXYWY != 1) { throw new Exception("请选择是否需要外业!"); } if (!string.IsNullOrWhiteSpace(this.NYYSInfo.NYYSResult.NYYPDL) && ListYPDLData.FirstOrDefault(X => X.DisplayName.Equals(this.NYYSInfo.NYYSResult.NYYPDL)) == null) { throw new Exception("预判地类输入不正确!"); } if (this.NYYSInfo.NYYSResult.SFXYWY == 0) { if (this.NYYSInfo.NYYSResult.NYYPDL == null) { throw new Exception("“是否外业”选择为“否”时,“预判地类”必须选择!"); } if (this.NYYSInfo.NYYSResult.NYYPDL != "09" && this.NYYSInfo.NYYSResult.NYYPDL.Length < 4) { throw new Exception("“是否外业”选择为“否”时,“预判地类”不能选择一级类!"); } } if (string.IsNullOrWhiteSpace(this.NYYSInfo.NYYSResult.YPRY)) { this.NYYSInfo.NYYSResult.YPRY = (MapsManager.Instance.CurrProjectInfo as ProjectInfo).UserName ?? "建库人员"; } if (this.NYYSInfo.WYSketch != null) { foreach (var item in this.NYYSInfo.WYSketch) { if (string.IsNullOrWhiteSpace(item.BZMS)) { throw new Exception("标注描述不能为空,无法保存!"); } } } // 内业预审信息保存 rdbHelper = RDBFactory.CreateDbHelper($"{taskPackage.PackageTempPath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite); rdbHelper.BeginTransaction(); //内业预审结果保存 if (NYYSInfo.WYRWTB != null) { rdbHelper.ExecuteNonQueryWithException("delete from NYYSResult where TBBSM='" + NYYSInfo.WYRWTB.TBBSM + "'", CommandType.Text); string excuteSQL = string.Format("INSERT INTO NYYSResult (TBBSM, NYYPDL, SFXYWY, YPSM, YPRY, YPSJ) VALUES('{0}', '{1}', {2}, '{3}', '{4}', '{5}');", this.NYYSInfo.WYRWTB.TBBSM, this.NYYSInfo.NYYSResult.NYYPDL, this.NYYSInfo.NYYSResult.SFXYWY, this.NYYSInfo.NYYSResult.YPSM, (MapsManager.Instance.CurrProjectInfo as ProjectInfo).UserName, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); rdbHelper.ExecuteNonQueryWithException(excuteSQL, CommandType.Text); rdbHelper.Commit(); } if (NYYSInfo.WYRWTB != null) { IFeatureLayer featureL = MapsManager.Instance.MapService.GetFeatureLayerByName("ZZTB"); int NYYPDL_Index = featureL.FeatureClass.FindField("NYYPDL"); int SFXYWY_Index = featureL.FeatureClass.FindField("SFXYWY"); int YPSM_Index = featureL.FeatureClass.FindField("YPSM"); int YPRY_Index = featureL.FeatureClass.FindField("YPRY"); int YPSJ_Index = featureL.FeatureClass.FindField("YPSJ"); if (NYYPDL_Index == -1 || YPRY_Index == -1 || YPSM_Index == -1) return; IQueryFilter queryFilter = new QueryFilterClass() { WhereClause = "TBBSM='" + NYYSInfo.WYRWTB.TBBSM + "'", }; IFeatureCursor featureCursor = featureL.FeatureClass.Update(queryFilter, false); IFeature ZZTBF = featureCursor.NextFeature(); if (ZZTBF == null) return; ZZTBF.Value[NYYPDL_Index] = NYYSInfo.NYYSResult.NYYPDL; ZZTBF.Value[SFXYWY_Index] = NYYSInfo.NYYSResult.SFXYWY; ZZTBF.Value[YPSM_Index] = NYYSInfo.NYYSResult.YPSM; ZZTBF.Value[YPRY_Index] = NYYSInfo.NYYSResult.YPRY; ZZTBF.Value[YPSJ_Index] = NYYSInfo.NYYSResult.YPSJ; featureCursor.UpdateFeature(ZZTBF); System.Runtime.InteropServices.Marshal.ReleaseComObject(featureCursor); } } catch (Exception ex) { LogAPI.Debug("预处理外业信息填写保存异常:" + ex); if (rdbHelper != null) { rdbHelper.Rollback(); rdbHelper.ExecuteNonQueryWithException("delete from NYYSResult where TBBSM='" + NYYSInfo.WYRWTB.TBBSM + "'", CommandType.Text); } throw ex; } finally { if (rdbHelper != null) rdbHelper.DisConnect(); } } private void LayoutControl_LostFocus(object sender, RoutedEventArgs e) { if ((MapsManager.Instance.CurrProjectInfo as ProjectInfo) != null) { (MapsManager.Instance.CurrProjectInfo as ProjectInfo).EnableShortcut = true; } } private void LayoutControl_GotFocus(object sender, RoutedEventArgs e) { if ((MapsManager.Instance.CurrProjectInfo as ProjectInfo) != null) { (MapsManager.Instance.CurrProjectInfo as ProjectInfo).EnableShortcut = false; } } } public class KeyValue { public string Code { get; set; } public int CodeInt { get; set; } public string Name { get; set; } } }