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

501 lines
17 KiB

using KGIS.Framework.Views;
using Kingo.Plugin.NYYP.Common;
using System;
using System.Collections.Generic;
using System.Drawing;
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 KGIS.Framework.Platform;
using System.ComponentModel;
using System.Data;
using KGIS.Framework.Utils.Interface;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Controls;
using KGIS.Framework.Maps;
using ESRI.ArcGIS.Carto;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.Helper;
using KGIS.Framework.DBOperator;
using KGIS.Framework.Utils.Utility;
using Kingo.PluginServiceInterface;
namespace Kingo.Plugin.NYYP.View
{
/// <summary>
/// UCAllTBYPDetails.xaml 的交互逻辑
/// </summary>
public partial class UCAllTBYPDetails : UserControl, IDockPanel2, INotifyPropertyChanged
{
public bool showDetail { get; set; }
private int m_DataIndex { get; set; }
private int m_DataCount { get; set; }
public List<TreeData> Items { get; set; }
public List<Dic> m_dic = null;
public List<KeyValueData> VirtualTree { 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; }
#endregion
public UCAllTBYPDetails()
{
DevExpress.Xpf.Core.ThemeManager.SetTheme(this, DevExpress.Xpf.Core.Theme.Office2013LightGray);
InitializeComponent();
this.DockAreas = KGIS.Framework.Views.DockStyle.DockRight;
this.FloatSize = new System.Drawing.Size(390, 800);
this.DefaultArea = KGIS.Framework.Views.DockStyle.DockRight;
this.ShowCloseButton = true;
this.ShowAutoHideButton = true;
this.Title = "图斑详情(全图斑判读)";
this.DockWidth = 390;
showDetail = true;
GetDic();
Items = GetDatas();
VirtualTree = new List<KeyValueData>();
foreach (var node in Items)
{
if (node.Items != null)
{
VirtualTree.Add(new KeyValueData() { NodeID = node.ID, NodeName = node.Name });
CreateVirtualTree(node);
}
}
this.cmbCtr.ItemsSource = VirtualTree;
}
public void CreateVirtualTree(TreeData node)
{
node.Items.ForEach(it =>
{
var newname = it.Name;
if (node.Name.StartsWith("--"))
{
var jc = node.Name.Count(x => x == '-') + 1;
for (int i = 0; i < jc; i++)
{
newname = "-" + newname;
}
}
else
{
newname = "--" + newname;
}
VirtualTree.Add(new KeyValueData() { NodeID = it.ID, NodeName = " " + newname });
CreateVirtualTree(it);
});
}
private void GetDic()
{
try
{
IRDBHelper rdbHelper = null;
m_dic = new List<Dic>();
try
{
string connStr = string.Format(SysConfigsOprator.GetDBConnectionByName("MDBOledbConnection"), (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).GetDicDataPath());
rdbHelper = RDBFactory.CreateDbHelper(connStr, DatabaseType.MSAccess);
if (rdbHelper == null)
{
throw new Exception("数据库连接打开失败:" + connStr);
}
DataTable dt = rdbHelper.ExecuteDatatable("dt", "SELECT * FROM Sys_DicManage where ALIASNAME='" + "DLBM" + "'", true);
if (dt != null && dt.Rows.Count > 0)
{
DataTable dt2 = rdbHelper.ExecuteDatatable("dt2", "SELECT * FROM Sys_DicDetail where OWNERDIC='" + dt.Rows[0]["ID"] + "'", true);
dt2.DefaultView.Sort = "CODE ASC";
dt2 = dt2.DefaultView.ToTable();
Dic d1 = new Dic();
d1.ID = "";
d1.PID = "";
d1.CODE = "";
d1.NAME = "";
m_dic.Add(d1);
foreach (DataRow item in dt2.Rows)
{
Dic d = new Dic();
d.ID = item["ID"].ToString();
d.PID = item["PID"].ToString();
d.CODE = item["CODE"].ToString();
d.NAME = item["CODE"].ToString() + "-" + item["NAME"].ToString();
m_dic.Add(d);
}
}
}
catch (Exception ex)
{
LogAPI.Debug("查询字典失败:" + ex);
}
finally
{
if (rdbHelper != null)
{
rdbHelper.DisConnect();
}
}
}
catch (Exception ex)
{
LogAPI.Debug("查询字典失败:" + ex);
}
}
private List<TreeData> GetDatas(string parentId = "")
{
List<TreeData> dataList = null;
try
{
dataList = new List<TreeData>();
for (int i = 0; i < m_dic.Count; i++)
{
TreeData data = new TreeData();
if (parentId == "")
{
if (false == string.IsNullOrEmpty(m_dic[i].PID))
{
continue;
}
else if (string.IsNullOrEmpty(m_dic[i].PID) && string.IsNullOrEmpty(m_dic[i].ID))
{
data.ID = "";
data.Name = "";
data.Items = null;
dataList.Add(data);
}
else
{
data.ID = m_dic[i].CODE;
data.Name = m_dic[i].NAME;
data.Items = GetDatas(m_dic[i].ID);
dataList.Add(data);
}
}
else
{
if (parentId.Trim().Equals(m_dic[i].PID.Trim()))
{
data.ID = m_dic[i].CODE;
data.Name = m_dic[i].NAME;
data.Items = GetDatas(m_dic[i].ID);
dataList.Add(data);
}
}
}
}
catch (Exception ex)
{
throw ex;
}
return dataList;
}
/// <summary>
/// 绑定“图斑变更信息”数据
/// </summary>
public void BindData(DataRow data, int pDataIndex, int pDataCount)
{
m_DataIndex = pDataIndex;
m_DataCount = pDataCount;
if (data.Table.Columns.Contains("SFJZ"))
{
string sfjz = data["SFJZ"].ToString();
if (!string.IsNullOrWhiteSpace(sfjz))
{
if(sfjz == "1")
{
rbtnWYTrue.IsChecked = true;
}
else
{
rbtnWYFalse.IsChecked = true;
}
}
else
{
rbtnWYTrue.IsChecked = false;
rbtnWYFalse.IsChecked = false;
}
}
else
{
rbtnWYTrue.IsChecked = false;
rbtnWYFalse.IsChecked = false;
}
if (data.Table.Columns.Contains("NYYPDL"))
{
string nyypdl = data["NYYPDL"].ToString();
if (VirtualTree != null)
{
var selectnode = VirtualTree.Find(p => p.NodeID == nyypdl);
if (selectnode != null)
{
this.cmbCtr.SelectedItem= selectnode as KeyValueData;
}
else
{
this.cmbCtr.SelectedItem = null;
}
}
}
JCDLTBInfo.DataContext = data;
}
private void BtnSave_Click(object sender, RoutedEventArgs e)
{
if (SaveData() == false)
{
return;
}
if (m_DataIndex == m_DataCount)
{
MessageHelper.Show("当前为最后一条数据!");
return;
}
//通知举证图斑列表显示下一条数据
Platform.Instance.SendMsg(new NotifyMsgPackage() { Content = "NextData", MsgType = "JCDLTBDetailView" });
}
private void BtnPrev_Click(object sender, RoutedEventArgs e)
{
if (SaveData()==false)
{
return;
}
if (m_DataIndex == 1)
{
MessageHelper.Show("当前为第一条数据!");
return;
}
//通知举证图斑列表显示上一条数据
Platform.Instance.SendMsg(new NotifyMsgPackage() { Content = "PrevData", MsgType = "JCDLTBDetailView" });
}
private void BtnNext_Click(object sender, RoutedEventArgs e)
{
if (SaveData() == false)
{
return;
}
if (m_DataIndex == m_DataCount)
{
MessageHelper.Show("当前为最后一条数据!");
return;
}
//通知举证图斑列表显示下一条数据
Platform.Instance.SendMsg(new NotifyMsgPackage() { Content = "NextData", MsgType = "JCDLTBDetailView" });
}
private bool SaveData()
{
IFeatureCursor jcdltbFeatureCursor = null;
try
{
if (rbtnWYTrue.IsChecked == false && rbtnWYFalse.IsChecked == false)
{
MessageHelper.ShowWarning("请选择是否外业");
return false;
}
IFeature feature = null;
IFeatureClass jcdltbFC = MapsManager.Instance.MapService.GetFeatureLayerByLayerName("地类图斑").FeatureClass;
if (JCDLTBInfo.DataContext is DataRow)
{
DataRow dataRow = JCDLTBInfo.DataContext as DataRow;
int obj = Convert.ToInt32(dataRow["OBJECTID"]);
IQueryFilter queryFilter = new QueryFilterClass();
queryFilter.WhereClause = string.Format(" OBJECTID = {0}", obj);
jcdltbFeatureCursor = jcdltbFC.Update(queryFilter, true);
feature = jcdltbFeatureCursor.NextFeature();
if (feature == null)
return false;
int index = jcdltbFC.FindField("SFJZ");
if (index == -1)
{
IField pField = new FieldClass();
IFieldEdit pFieldEdit = pField as IFieldEdit;
pFieldEdit.Name_2 = "SFJZ";
pFieldEdit.AliasName_2 = "是否举证";
pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
pFieldEdit.Length_2 = 1;
jcdltbFC.AddField(pField);
index = jcdltbFC.FindField("SFJZ");
}
if (!dataRow.Table.Columns.Contains("SFJZ"))
{
DataColumn col = new DataColumn();
col.ColumnName = "SFJZ";
col.Caption = "是否举证";
col.MaxLength = 1;
dataRow.Table.Columns.Add(col);
}
if (rbtnWYTrue.IsChecked == true)
{
feature.Value[index] = "1";
dataRow["SFJZ"] = "1";
}
else if (rbtnWYFalse.IsChecked == true)
{
feature.Value[index] = "0";
dataRow["SFJZ"] = "0";
}
index = jcdltbFC.FindField("NYYPDL");
if (index == -1)
{
IField pField = new FieldClass();
IFieldEdit pFieldEdit = pField as IFieldEdit;
pFieldEdit.Name_2 = "NYYPDL";
pFieldEdit.AliasName_2 = "内业预判地类";
pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
pFieldEdit.Length_2 = 10;
jcdltbFC.AddField(pField);
index = jcdltbFC.FindField("NYYPDL");
}
if (this.cmbCtr.SelectedItem != null)
{
KeyValueData selectnyypdl = this.cmbCtr.SelectedItem as KeyValueData;
if (selectnyypdl != null)
{
if (dataRow.Table.Columns.Contains("NYYPDL"))
{
dataRow["NYYPDL"] = selectnyypdl.NodeID;
}
feature.Value[index] = selectnyypdl.NodeID;
}
}
index = jcdltbFC.FindField("NYJY");
if (index == -1)
{
IField pField = new FieldClass();
IFieldEdit pFieldEdit = pField as IFieldEdit;
pFieldEdit.Name_2 = "NYJY";
pFieldEdit.AliasName_2 = "内业建议";
pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
pFieldEdit.Length_2 = 500;
jcdltbFC.AddField(pField);
index = jcdltbFC.FindField("NYJY");
}
if (dataRow.Table.Columns.Contains("NYJY"))
{
feature.Value[index] = dataRow["NYJY"];
}
jcdltbFeatureCursor.UpdateFeature(feature);
jcdltbFeatureCursor.Flush();
return true;
}
}
catch (Exception ex)
{
LogAPI.Debug("基础信息保存失败:" + ex.Message);
return false;
}
finally
{
if (jcdltbFeatureCursor != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(jcdltbFeatureCursor);
}
}
return true;
}
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);
}
}
public class Dic
{
public string NAME { get; set; }
public string CODE { get; set; }
public string ID { get; set; }
public string PID { get; set; }
}
}