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.
		
		
		
		
		
			
		
			
				
					
					
						
							241 lines
						
					
					
						
							7.3 KiB
						
					
					
				
			
		
		
	
	
							241 lines
						
					
					
						
							7.3 KiB
						
					
					
				using KGIS.Framework.Platform; | 
						|
using KGIS.Framework.Utils; | 
						|
using KGIS.Framework.Utils.Helper; | 
						|
using System; | 
						|
using System.Collections.Generic; | 
						|
using System.Windows; | 
						|
using System.Windows.Controls; | 
						|
using System.Windows.Input; | 
						|
using System.Windows.Media; | 
						|
 | 
						|
namespace Kingo.Plugin.MapView.Views | 
						|
{ | 
						|
    /// <summary> | 
						|
    /// FrmSelectQS.xaml 的交互逻辑 | 
						|
    /// </summary> | 
						|
    public partial class FrmSelectQS : UserControl | 
						|
    { | 
						|
        public event EditDicHandler EditDic; | 
						|
        public Action<DataDicTionary> SelectedItemChanged; | 
						|
        private int SelectedLength = 0; | 
						|
        public FrmSelectQS(int pSelectedLength) | 
						|
        { | 
						|
            InitializeComponent(); | 
						|
            this.SelectedLength = pSelectedLength; | 
						|
            Init(); | 
						|
        } | 
						|
        private void TreeViewItem_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e) | 
						|
        { | 
						|
            var treeViewItem = VisualUpwardSearch<TreeViewItem>(e.OriginalSource as DependencyObject) as TreeViewItem; | 
						|
            if (treeViewItem != null) | 
						|
            { | 
						|
                treeViewItem.Focus(); | 
						|
                e.Handled = true; | 
						|
            } | 
						|
        } | 
						|
 | 
						|
        DependencyObject VisualUpwardSearch<T>(DependencyObject source) | 
						|
        { | 
						|
            while (source != null && source.GetType() != typeof(T)) | 
						|
                source = VisualTreeHelper.GetParent(source); | 
						|
 | 
						|
            return source; | 
						|
        } | 
						|
 | 
						|
        public void Init() | 
						|
        { | 
						|
            try | 
						|
            { | 
						|
                //List<DataDicTionary> dicList = DicAPI.GetDic(Enum.DicTypeEnum.QSDM, true); | 
						|
                //if (dicList == null) | 
						|
                //    return; | 
						|
                //List<TreeNode> treeList = GetTree(dicList); | 
						|
                //this.tvXZQ.ItemsSource = treeList; | 
						|
            } | 
						|
            catch (Exception ex) | 
						|
            { | 
						|
                LogAPI.Debug("加载数据字典失败  时异常,异常信息如下:"); | 
						|
                LogAPI.Debug(ex); | 
						|
                LogAPI.Debug("加载数据字典失败  时异常信息结束"); | 
						|
 | 
						|
                MessageHelper.ShowTips("加载数据字典失败!"); | 
						|
                //LogAPI.Debug("【按行政区划归】加载数据字典异常:" + ex); | 
						|
            } | 
						|
        } | 
						|
 | 
						|
        private List<TreeNode> GetTree(List<DataDicTionary> dicList) | 
						|
        { | 
						|
            try | 
						|
            { | 
						|
                if (dicList == null) | 
						|
                    return null; | 
						|
                List<TreeNode> result = new List<TreeNode>(); | 
						|
                foreach (DataDicTionary dic in dicList) | 
						|
                { | 
						|
                    var n1 = new TreeNode(); | 
						|
                    n1.Name = dic.NAME; | 
						|
                    n1.Data = dic; | 
						|
                    n1.Icon = "pack://application:,,,/KGIS.PlatformPlugin;component/Resources/zrz.png"; | 
						|
                    if (dic.CODE.Length > 6) | 
						|
                        n1.IsExpanded = false; | 
						|
                    else | 
						|
                        n1.IsExpanded = true; | 
						|
                    //n1.cMenu = "RouterMenu"; | 
						|
                    result.Add(n1); | 
						|
                    if (dic.SubDic != null && dic.SubDic.Count > 0) | 
						|
                    { | 
						|
                        n1.Nodes = GetTree(dic.SubDic); | 
						|
                    } | 
						|
                } | 
						|
                return result; | 
						|
            } | 
						|
            catch (Exception ex) | 
						|
            { | 
						|
                LogAPI.Debug("选择所要划归的行政区期间 获取信息树 时异常,异常信息如下:"); | 
						|
                LogAPI.Debug(ex); | 
						|
                LogAPI.Debug("选择所要划归的行政区期间 获取信息树 时异常信息结束"); | 
						|
 | 
						|
                throw ex; | 
						|
            } | 
						|
        } | 
						|
 | 
						|
        public object GetSelectedItem() | 
						|
        { | 
						|
            return tvXZQ.SelectedItem; | 
						|
        } | 
						|
 | 
						|
        private void tvXZQ_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e) | 
						|
        { | 
						|
            if (tvXZQ.SelectedItem != null && tvXZQ.SelectedItem is TreeNode) | 
						|
            { | 
						|
                TreeNode node = tvXZQ.SelectedItem as TreeNode; | 
						|
                if (node != null && node.Data is DataDicTionary) | 
						|
                { | 
						|
                    labXZQCode.Content = (node.Data as DataDicTionary).DisplayName; | 
						|
                } | 
						|
            } | 
						|
        } | 
						|
 | 
						|
        private void btnEditDic_Click(object sender, RoutedEventArgs e) | 
						|
        { | 
						|
            if (EditDic != null) | 
						|
            { | 
						|
                EditDic(this); | 
						|
                Init(); | 
						|
            } | 
						|
        } | 
						|
 | 
						|
        private void btnOK_Click(object sender, RoutedEventArgs e) | 
						|
        { | 
						|
            if (tvXZQ.SelectedItem != null && tvXZQ.SelectedItem is TreeNode) | 
						|
            { | 
						|
                TreeNode node = tvXZQ.SelectedItem as TreeNode; | 
						|
                if (node != null && node.Data is DataDicTionary) | 
						|
                { | 
						|
                    if ((node.Data as DataDicTionary).CODE.Length == SelectedLength) | 
						|
                    { | 
						|
                        if (SelectedItemChanged != null) | 
						|
                        { | 
						|
                            SelectedItemChanged(node.Data as DataDicTionary); | 
						|
                        } | 
						|
                        //this.Close(); | 
						|
                    } | 
						|
                    else | 
						|
                    { | 
						|
                        //if (SelectedLength == 19) | 
						|
                        //{ | 
						|
                        //    MessageBox.Show("请选择正确的权属单位!"); | 
						|
                        //} | 
						|
                        //else if (SelectedLength == 12) | 
						|
                        //{ | 
						|
                        //    MessageBox.Show("请选择村级行政区选项!"); | 
						|
                        //} | 
						|
                    } | 
						|
                } | 
						|
            } | 
						|
        } | 
						|
 | 
						|
        private void btnCancel_Click(object sender, RoutedEventArgs e) | 
						|
        { | 
						|
            //this.Close(); | 
						|
        } | 
						|
 | 
						|
    } | 
						|
 | 
						|
    public class TreeNode | 
						|
    { | 
						|
        #region Property | 
						|
 | 
						|
        private string _Text; | 
						|
        /// <summary> | 
						|
        /// 显示的文本值 | 
						|
        /// </summary> | 
						|
        public string Name | 
						|
        { | 
						|
            get { return this._Text; } | 
						|
            set { this._Text = value; } | 
						|
        } | 
						|
        private ContextMenu _cMenu; | 
						|
        public ContextMenu cMenu | 
						|
        { | 
						|
            get { return this._cMenu; } | 
						|
            set { this._cMenu = value; } | 
						|
        } | 
						|
        private bool? _Checked; | 
						|
        /// <summary> | 
						|
        /// 是否选中 | 
						|
        /// </summary> | 
						|
        public bool? Checked | 
						|
        { | 
						|
            get { return this._Checked; } | 
						|
            set { this._Checked = value; } | 
						|
        } | 
						|
 | 
						|
        private bool _IsExpanded; | 
						|
        /// <summary> | 
						|
        /// 是否展开 | 
						|
        /// </summary> | 
						|
        public bool IsExpanded | 
						|
        { | 
						|
            get { return this._IsExpanded; } | 
						|
            set { this._IsExpanded = value; } | 
						|
        } | 
						|
 | 
						|
        /// <summary> | 
						|
        /// 节点图标:相对路径 | 
						|
        /// </summary> | 
						|
        public string Icon { get; set; } | 
						|
 | 
						|
        /// <summary> | 
						|
        /// 子节点,默认null | 
						|
        /// </summary> | 
						|
        public IList<TreeNode> Nodes { get; set; } | 
						|
 | 
						|
        /// <summary> | 
						|
        /// 该节点数据项,默认null | 
						|
        /// </summary> | 
						|
        public virtual object Data { get; set; } | 
						|
 | 
						|
        public virtual bool IsOpenEdit { get; set; } | 
						|
        public object Paixu { get; internal set; } | 
						|
        public bool IsParent { get; internal set; } | 
						|
 | 
						|
        #endregion | 
						|
 | 
						|
        #region NodeX-构造函数(初始化) | 
						|
 | 
						|
        /// <summary> | 
						|
        ///  NodeX-构造函数(初始化) | 
						|
        /// </summary> | 
						|
        public TreeNode() | 
						|
        { | 
						|
            this.Name = string.Empty; | 
						|
            this.Icon = string.Empty; | 
						|
            this.Checked = false; | 
						|
 | 
						|
        } | 
						|
 | 
						|
        #endregion | 
						|
    } | 
						|
 | 
						|
}
 | 
						|
 |