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

154 lines
5.5 KiB

using KGIS.Framework.DBOperator;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.Helper;
using System;
using System.Collections.ObjectModel;
using System.Data;
using System.Windows;
namespace Kingo.Plugin.DataDictionary.Views
{
/// <summary>
/// DicHelpTree.xaml 的交互逻辑
/// </summary>
public partial class DicHelpTree : BaseWindow
{
/// <summary>
/// 委托函数
/// </summary>
/// <param name="sName">名称</param>
/// <param name="sID">ID</param>
public delegate void DelegateGetValue(string sName, string sID);
/// <summary>
/// 获取返回值事件
/// </summary>
public event DelegateGetValue GetValueHandler;
/// <summary>
/// 父级ID
/// </summary>
public string OWNERDIC { get; set; }
//编辑时使用,排除自己的数据显示
public string MINEID { get; set; }
public DicHelpTree()
{
InitializeComponent();
}
//取消按钮
private void btnCancel_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
//清空事件
private void btnClean_Click(object sender, RoutedEventArgs e)
{
if (GetValueHandler != null)
{
GetValueHandler("", "");
}
this.Close();
}
private void btnSave_Click(object sender, RoutedEventArgs e)
{
if (GetValueHandler != null)
{
TreeNode item = this.tvHelpTree.SelectedItem as TreeNode;
if (item != null && item.Data != null)
{
DataRowView drv = item.Data as DataRowView;
string sID = drv["ID"].ToString();
GetValueHandler(item.Name, sID);
}
}
this.Close();
}
//加载
private void BaseWindow_Loaded(object sender, RoutedEventArgs e)
{
//tvHelpTree
IRDBHelper rdbHelper = null;
try
{
string connStr = SysConfigsOprator.GetDBConnectionByName("MDBOledbConnection");
connStr = string.Format(connStr, SysAppPath.GetCurrentAppPath() + @"DataBase\System.mdb"); ;
rdbHelper = RDBFactory.CreateDbHelper(connStr, DatabaseType.MSAccess);
DataTable dtDict = rdbHelper.ExecuteDatatable("Sys_DicDetail", "select * from Sys_DicDetail", false);
ObservableCollection<TreeNode> itemList = new ObservableCollection<TreeNode>();
DataView dvDict = dtDict.DefaultView;
dvDict.RowFilter = " OWNERDIC='" + OWNERDIC + "' and (PID is null or PID='')";
if (dvDict.Count > 0)
{
foreach (DataRowView view in dvDict)
{
int id = Convert.ToInt32(view["ID"].ToString());
string name = view["NAME"].ToString() + "[" + view["CODE"].ToString() + "]";
if (MINEID == view["OBJECTID"].ToString())
{
continue;
}
TreeNode childNodeItem = new TreeNode()
{
Name = name,
Icon = "pack://application:,,,/KGIS.PlatformPlugin;component/Resources/zrz.png",
IsExpanded = false,
Data = view
};
ForeachPropertyNode(childNodeItem, id, dtDict);
itemList.Add(childNodeItem);
}
}
//ForeachPropertyNode(node, id);
//itemList.Add(node);
this.tvHelpTree.ItemsSource = itemList;
}
catch (Exception ex)
{
MessageHelper.ShowError("数据加载异常!" + ex.Message);
LogAPI.Debug(ex);
}
finally
{
if (rdbHelper != null)
{
rdbHelper.DisConnect();
}
}
}
//无限极增加子节点
private void ForeachPropertyNode(TreeNode node, int pid, DataTable dtDict)
{
DataView dvDict = dtDict.DefaultView;
dvDict.RowFilter = " PID='" + pid.ToString() + "'";
if (dvDict.Count > 0)
{
node.Nodes = new System.Collections.ObjectModel.ObservableCollection<TreeNode>();
foreach (DataRowView view in dvDict)
{
int id = Convert.ToInt32(view["ID"].ToString());
string name = view["NAME"].ToString() + "[" + view["CODE"].ToString() + "]"; ;
int parentId = Convert.ToInt32(view["PID"].ToString());
if (MINEID == view["ID"].ToString())
{
continue;
}
TreeNode childNodeItem = new TreeNode()
{
Name = name,
Icon = "pack://application:,,,/KGIS.PlatformPlugin;component/Resources/zrz.png",
IsExpanded = false,
Data = view
};
ForeachPropertyNode(childNodeItem, id, dtDict);
node.Nodes.Add(childNodeItem);
}
}
}
}
}